2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
10 #include <scsi/scsi_tcq.h>
11 #include <scsi/scsicam.h>
14 #include "ql4_version.h"
17 #include "ql4_inline.h"
22 static char qla4xxx_version_str
[40];
25 * SRB allocation cache
27 static struct kmem_cache
*srb_cachep
;
30 * Module parameter information and variables
32 int ql4xdiscoverywait
= 60;
33 module_param(ql4xdiscoverywait
, int, S_IRUGO
| S_IWUSR
);
34 MODULE_PARM_DESC(ql4xdiscoverywait
, "Discovery wait time");
36 int ql4xdontresethba
= 0;
37 module_param(ql4xdontresethba
, int, S_IRUGO
| S_IWUSR
);
38 MODULE_PARM_DESC(ql4xdontresethba
,
39 "Don't reset the HBA for driver recovery \n"
40 " 0 - It will reset HBA (Default)\n"
41 " 1 - It will NOT reset HBA");
43 int ql4xextended_error_logging
= 0; /* 0 = off, 1 = log errors */
44 module_param(ql4xextended_error_logging
, int, S_IRUGO
| S_IWUSR
);
45 MODULE_PARM_DESC(ql4xextended_error_logging
,
46 "Option to enable extended error logging, "
47 "Default is 0 - no logging, 1 - debug logging");
49 int ql4xenablemsix
= 1;
50 module_param(ql4xenablemsix
, int, S_IRUGO
|S_IWUSR
);
51 MODULE_PARM_DESC(ql4xenablemsix
,
52 "Set to enable MSI or MSI-X interrupt mechanism.\n"
53 " 0 = enable INTx interrupt mechanism.\n"
54 " 1 = enable MSI-X interrupt mechanism (Default).\n"
55 " 2 = enable MSI interrupt mechanism.");
57 #define QL4_DEF_QDEPTH 32
60 * SCSI host template entry points
62 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
65 * iSCSI template entry points
67 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
68 enum iscsi_tgt_dscvr type
, uint32_t enable
,
69 struct sockaddr
*dst_addr
);
70 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
71 enum iscsi_param param
, char *buf
);
72 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
73 enum iscsi_param param
, char *buf
);
74 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
75 enum iscsi_host_param param
, char *buf
);
76 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
);
77 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
);
80 * SCSI host template entry points
82 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
83 void (*done
) (struct scsi_cmnd
*));
84 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
);
85 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
86 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
);
87 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
88 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
89 static int qla4xxx_slave_configure(struct scsi_device
*device
);
90 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
91 static void qla4xxx_scan_start(struct Scsi_Host
*shost
);
93 static struct qla4_8xxx_legacy_intr_set legacy_intr
[] =
94 QLA82XX_LEGACY_INTR_CONFIG
;
96 static struct scsi_host_template qla4xxx_driver_template
= {
97 .module
= THIS_MODULE
,
99 .proc_name
= DRIVER_NAME
,
100 .queuecommand
= qla4xxx_queuecommand
,
102 .eh_abort_handler
= qla4xxx_eh_abort
,
103 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
104 .eh_target_reset_handler
= qla4xxx_eh_target_reset
,
105 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
106 .eh_timed_out
= qla4xxx_eh_cmd_timed_out
,
108 .slave_configure
= qla4xxx_slave_configure
,
109 .slave_alloc
= qla4xxx_slave_alloc
,
110 .slave_destroy
= qla4xxx_slave_destroy
,
112 .scan_finished
= iscsi_scan_finished
,
113 .scan_start
= qla4xxx_scan_start
,
117 .use_clustering
= ENABLE_CLUSTERING
,
118 .sg_tablesize
= SG_ALL
,
120 .max_sectors
= 0xFFFF,
123 static struct iscsi_transport qla4xxx_iscsi_transport
= {
124 .owner
= THIS_MODULE
,
126 .caps
= CAP_FW_DB
| CAP_SENDTARGETS_OFFLOAD
|
127 CAP_DATA_PATH_OFFLOAD
,
128 .param_mask
= ISCSI_CONN_PORT
| ISCSI_CONN_ADDRESS
|
129 ISCSI_TARGET_NAME
| ISCSI_TPGT
|
131 .host_param_mask
= ISCSI_HOST_HWADDRESS
|
132 ISCSI_HOST_IPADDRESS
|
133 ISCSI_HOST_INITIATOR_NAME
,
134 .tgt_dscvr
= qla4xxx_tgt_dscvr
,
135 .get_conn_param
= qla4xxx_conn_get_param
,
136 .get_session_param
= qla4xxx_sess_get_param
,
137 .get_host_param
= qla4xxx_host_get_param
,
138 .session_recovery_timedout
= qla4xxx_recovery_timedout
,
141 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
143 static enum blk_eh_timer_return
qla4xxx_eh_cmd_timed_out(struct scsi_cmnd
*sc
)
145 struct iscsi_cls_session
*session
;
146 struct ddb_entry
*ddb_entry
;
148 session
= starget_to_session(scsi_target(sc
->device
));
149 ddb_entry
= session
->dd_data
;
151 /* if we are not logged in then the LLD is going to clean up the cmd */
152 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
153 return BLK_EH_RESET_TIMER
;
155 return BLK_EH_NOT_HANDLED
;
158 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
)
160 struct ddb_entry
*ddb_entry
= session
->dd_data
;
161 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
163 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
164 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
166 DEBUG2(printk("scsi%ld: %s: ddb [%d] port down retry count "
167 "of (%d) secs exhausted, marking device DEAD.\n",
168 ha
->host_no
, __func__
, ddb_entry
->fw_ddb_index
,
169 ha
->port_down_retry_count
));
171 qla4xxx_wake_dpc(ha
);
175 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
176 enum iscsi_host_param param
, char *buf
)
178 struct scsi_qla_host
*ha
= to_qla_host(shost
);
182 case ISCSI_HOST_PARAM_HWADDRESS
:
183 len
= sysfs_format_mac(buf
, ha
->my_mac
, MAC_ADDR_LEN
);
185 case ISCSI_HOST_PARAM_IPADDRESS
:
186 len
= sprintf(buf
, "%d.%d.%d.%d\n", ha
->ip_address
[0],
187 ha
->ip_address
[1], ha
->ip_address
[2],
190 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
191 len
= sprintf(buf
, "%s\n", ha
->name_string
);
200 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
201 enum iscsi_param param
, char *buf
)
203 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
207 case ISCSI_PARAM_TARGET_NAME
:
208 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
209 ddb_entry
->iscsi_name
);
211 case ISCSI_PARAM_TPGT
:
212 len
= sprintf(buf
, "%u\n", ddb_entry
->tpgt
);
214 case ISCSI_PARAM_TARGET_ALIAS
:
215 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
216 ddb_entry
->iscsi_alias
);
225 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
226 enum iscsi_param param
, char *buf
)
228 struct iscsi_cls_session
*session
;
229 struct ddb_entry
*ddb_entry
;
232 session
= iscsi_dev_to_session(conn
->dev
.parent
);
233 ddb_entry
= session
->dd_data
;
236 case ISCSI_PARAM_CONN_PORT
:
237 len
= sprintf(buf
, "%hu\n", ddb_entry
->port
);
239 case ISCSI_PARAM_CONN_ADDRESS
:
240 /* TODO: what are the ipv6 bits */
241 len
= sprintf(buf
, "%pI4\n", &ddb_entry
->ip_addr
);
250 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
251 enum iscsi_tgt_dscvr type
, uint32_t enable
,
252 struct sockaddr
*dst_addr
)
254 struct scsi_qla_host
*ha
;
255 struct sockaddr_in
*addr
;
256 struct sockaddr_in6
*addr6
;
259 ha
= (struct scsi_qla_host
*) shost
->hostdata
;
262 case ISCSI_TGT_DSCVR_SEND_TARGETS
:
263 if (dst_addr
->sa_family
== AF_INET
) {
264 addr
= (struct sockaddr_in
*)dst_addr
;
265 if (qla4xxx_send_tgts(ha
, (char *)&addr
->sin_addr
,
266 addr
->sin_port
) != QLA_SUCCESS
)
268 } else if (dst_addr
->sa_family
== AF_INET6
) {
270 * TODO: fix qla4xxx_send_tgts
272 addr6
= (struct sockaddr_in6
*)dst_addr
;
273 if (qla4xxx_send_tgts(ha
, (char *)&addr6
->sin6_addr
,
274 addr6
->sin6_port
) != QLA_SUCCESS
)
285 void qla4xxx_destroy_sess(struct ddb_entry
*ddb_entry
)
287 if (!ddb_entry
->sess
)
290 if (ddb_entry
->conn
) {
291 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
292 iscsi_remove_session(ddb_entry
->sess
);
294 iscsi_free_session(ddb_entry
->sess
);
297 int qla4xxx_add_sess(struct ddb_entry
*ddb_entry
)
301 ddb_entry
->sess
->recovery_tmo
= ddb_entry
->ha
->port_down_retry_count
;
302 err
= iscsi_add_session(ddb_entry
->sess
, ddb_entry
->fw_ddb_index
);
304 DEBUG2(printk(KERN_ERR
"Could not add session.\n"));
308 ddb_entry
->conn
= iscsi_create_conn(ddb_entry
->sess
, 0, 0);
309 if (!ddb_entry
->conn
) {
310 iscsi_remove_session(ddb_entry
->sess
);
311 DEBUG2(printk(KERN_ERR
"Could not add connection.\n"));
315 /* finally ready to go */
316 iscsi_unblock_session(ddb_entry
->sess
);
320 struct ddb_entry
*qla4xxx_alloc_sess(struct scsi_qla_host
*ha
)
322 struct ddb_entry
*ddb_entry
;
323 struct iscsi_cls_session
*sess
;
325 sess
= iscsi_alloc_session(ha
->host
, &qla4xxx_iscsi_transport
,
326 sizeof(struct ddb_entry
));
330 ddb_entry
= sess
->dd_data
;
331 memset(ddb_entry
, 0, sizeof(*ddb_entry
));
333 ddb_entry
->sess
= sess
;
337 static void qla4xxx_scan_start(struct Scsi_Host
*shost
)
339 struct scsi_qla_host
*ha
= shost_priv(shost
);
340 struct ddb_entry
*ddb_entry
, *ddbtemp
;
342 /* finish setup of sessions that were already setup in firmware */
343 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
344 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
)
345 qla4xxx_add_sess(ddb_entry
);
353 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
354 unsigned long interval
)
356 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
357 __func__
, ha
->host
->host_no
));
358 init_timer(&ha
->timer
);
359 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
360 ha
->timer
.data
= (unsigned long)ha
;
361 ha
->timer
.function
= (void (*)(unsigned long))func
;
362 add_timer(&ha
->timer
);
363 ha
->timer_active
= 1;
366 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
368 del_timer_sync(&ha
->timer
);
369 ha
->timer_active
= 0;
373 * qla4xxx_mark_device_missing - mark a device as missing.
374 * @ha: Pointer to host adapter structure.
375 * @ddb_entry: Pointer to device database entry
377 * This routine marks a device missing and close connection.
379 void qla4xxx_mark_device_missing(struct scsi_qla_host
*ha
,
380 struct ddb_entry
*ddb_entry
)
382 if ((atomic_read(&ddb_entry
->state
) != DDB_STATE_DEAD
)) {
383 atomic_set(&ddb_entry
->state
, DDB_STATE_MISSING
);
384 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
385 ha
->host_no
, ddb_entry
->fw_ddb_index
));
387 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha
->host_no
,
388 ddb_entry
->fw_ddb_index
))
390 iscsi_block_session(ddb_entry
->sess
);
391 iscsi_conn_error_event(ddb_entry
->conn
, ISCSI_ERR_CONN_FAILED
);
395 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
396 * @ha: Pointer to host adapter structure.
398 * This routine marks a device missing and resets the relogin retry count.
400 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host
*ha
)
402 struct ddb_entry
*ddb_entry
, *ddbtemp
;
403 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
404 qla4xxx_mark_device_missing(ha
, ddb_entry
);
408 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
409 struct ddb_entry
*ddb_entry
,
410 struct scsi_cmnd
*cmd
,
411 void (*done
)(struct scsi_cmnd
*))
415 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
419 kref_init(&srb
->srb_ref
);
421 srb
->ddb
= ddb_entry
;
424 CMD_SP(cmd
) = (void *)srb
;
425 cmd
->scsi_done
= done
;
430 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
432 struct scsi_cmnd
*cmd
= srb
->cmd
;
434 if (srb
->flags
& SRB_DMA_VALID
) {
436 srb
->flags
&= ~SRB_DMA_VALID
;
441 void qla4xxx_srb_compl(struct kref
*ref
)
443 struct srb
*srb
= container_of(ref
, struct srb
, srb_ref
);
444 struct scsi_cmnd
*cmd
= srb
->cmd
;
445 struct scsi_qla_host
*ha
= srb
->ha
;
447 qla4xxx_srb_free_dma(ha
, srb
);
449 mempool_free(srb
, ha
->srb_mempool
);
455 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
456 * @cmd: Pointer to Linux's SCSI command structure
457 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
458 * that the command has been processed.
461 * This routine is invoked by Linux to send a SCSI command to the driver.
462 * The mid-level driver tries to ensure that queuecommand never gets
463 * invoked concurrently with itself or the interrupt handler (although
464 * the interrupt handler may call this routine as part of request-
465 * completion handling). Unfortunely, it sometimes calls the scheduler
466 * in interrupt context which is a big NO! NO!.
468 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
469 void (*done
)(struct scsi_cmnd
*))
471 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
472 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
473 struct iscsi_cls_session
*sess
= ddb_entry
->sess
;
478 cmd
->result
= DID_IMM_RETRY
<< 16;
479 goto qc_fail_command
;
482 rval
= iscsi_session_chkready(sess
);
485 goto qc_fail_command
;
488 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
489 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
) {
490 cmd
->result
= DID_NO_CONNECT
<< 16;
491 goto qc_fail_command
;
493 return SCSI_MLQUEUE_TARGET_BUSY
;
496 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
497 test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) ||
498 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
499 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
500 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
501 !test_bit(AF_ONLINE
, &ha
->flags
) ||
502 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))
505 spin_unlock_irq(ha
->host
->host_lock
);
507 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
, done
);
509 goto qc_host_busy_lock
;
511 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
512 if (rval
!= QLA_SUCCESS
)
513 goto qc_host_busy_free_sp
;
515 spin_lock_irq(ha
->host
->host_lock
);
518 qc_host_busy_free_sp
:
519 qla4xxx_srb_free_dma(ha
, srb
);
520 mempool_free(srb
, ha
->srb_mempool
);
523 spin_lock_irq(ha
->host
->host_lock
);
526 return SCSI_MLQUEUE_HOST_BUSY
;
535 * qla4xxx_mem_free - frees memory allocated to adapter
536 * @ha: Pointer to host adapter structure.
538 * Frees memory previously allocated by qla4xxx_mem_alloc
540 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
543 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
549 ha
->request_ring
= NULL
;
551 ha
->response_ring
= NULL
;
552 ha
->response_dma
= 0;
553 ha
->shadow_regs
= NULL
;
554 ha
->shadow_regs_dma
= 0;
558 mempool_destroy(ha
->srb_mempool
);
560 ha
->srb_mempool
= NULL
;
562 /* release io space registers */
563 if (is_qla8022(ha
)) {
566 (struct device_reg_82xx __iomem
*)ha
->nx_pcibase
);
568 if (ha
->nx_db_wr_ptr
)
570 (struct device_reg_82xx __iomem
*)ha
->nx_db_wr_ptr
);
573 pci_release_regions(ha
->pdev
);
577 * qla4xxx_mem_alloc - allocates memory for use by adapter.
578 * @ha: Pointer to host adapter structure
580 * Allocates DMA memory for request and response queues. Also allocates memory
583 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
587 /* Allocate contiguous block of DMA memory for queues. */
588 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
589 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
590 sizeof(struct shadow_regs
) +
592 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
593 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
594 &ha
->queues_dma
, GFP_KERNEL
);
595 if (ha
->queues
== NULL
) {
596 ql4_printk(KERN_WARNING
, ha
,
597 "Memory Allocation failed - queues.\n");
599 goto mem_alloc_error_exit
;
601 memset(ha
->queues
, 0, ha
->queues_len
);
604 * As per RISC alignment requirements -- the bus-address must be a
605 * multiple of the request-ring size (in bytes).
608 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
609 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
610 (MEM_ALIGN_VALUE
- 1));
612 /* Update request and response queue pointers. */
613 ha
->request_dma
= ha
->queues_dma
+ align
;
614 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
615 ha
->response_dma
= ha
->queues_dma
+ align
+
616 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
617 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
618 (REQUEST_QUEUE_DEPTH
*
620 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
621 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
622 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
623 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
624 (REQUEST_QUEUE_DEPTH
*
626 (RESPONSE_QUEUE_DEPTH
*
629 /* Allocate memory for srb pool. */
630 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
631 mempool_free_slab
, srb_cachep
);
632 if (ha
->srb_mempool
== NULL
) {
633 ql4_printk(KERN_WARNING
, ha
,
634 "Memory Allocation failed - SRB Pool.\n");
636 goto mem_alloc_error_exit
;
641 mem_alloc_error_exit
:
642 qla4xxx_mem_free(ha
);
647 * qla4_8xxx_check_fw_alive - Check firmware health
648 * @ha: Pointer to host adapter structure.
652 static void qla4_8xxx_check_fw_alive(struct scsi_qla_host
*ha
)
654 uint32_t fw_heartbeat_counter
, halt_status
;
656 fw_heartbeat_counter
= qla4_8xxx_rd_32(ha
, QLA82XX_PEG_ALIVE_COUNTER
);
658 if (ha
->fw_heartbeat_counter
== fw_heartbeat_counter
) {
659 ha
->seconds_since_last_heartbeat
++;
660 /* FW not alive after 2 seconds */
661 if (ha
->seconds_since_last_heartbeat
== 2) {
662 ha
->seconds_since_last_heartbeat
= 0;
663 halt_status
= qla4_8xxx_rd_32(ha
,
664 QLA82XX_PEG_HALT_STATUS1
);
665 /* Since we cannot change dev_state in interrupt
666 * context, set appropriate DPC flag then wakeup
668 if (halt_status
& HALT_STATUS_UNRECOVERABLE
)
669 set_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
);
671 printk("scsi%ld: %s: detect abort needed!\n",
672 ha
->host_no
, __func__
);
673 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
675 qla4xxx_wake_dpc(ha
);
678 ha
->fw_heartbeat_counter
= fw_heartbeat_counter
;
682 * qla4_8xxx_watchdog - Poll dev state
683 * @ha: Pointer to host adapter structure.
687 void qla4_8xxx_watchdog(struct scsi_qla_host
*ha
)
691 dev_state
= qla4_8xxx_rd_32(ha
, QLA82XX_CRB_DEV_STATE
);
693 /* don't poll if reset is going on */
694 if (!test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
)) {
695 if (dev_state
== QLA82XX_DEV_NEED_RESET
&&
696 !test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
697 printk("scsi%ld: %s: HW State: NEED RESET!\n",
698 ha
->host_no
, __func__
);
699 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
700 qla4xxx_wake_dpc(ha
);
701 } else if (dev_state
== QLA82XX_DEV_NEED_QUIESCENT
&&
702 !test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
703 printk("scsi%ld: %s: HW State: NEED QUIES!\n",
704 ha
->host_no
, __func__
);
705 set_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
);
706 qla4xxx_wake_dpc(ha
);
708 /* Check firmware health */
709 qla4_8xxx_check_fw_alive(ha
);
715 * qla4xxx_timer - checks every second for work to do.
716 * @ha: Pointer to host adapter structure.
718 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
720 struct ddb_entry
*ddb_entry
, *dtemp
;
723 if (test_bit(AF_HBA_GOING_AWAY
, &ha
->flags
)) {
724 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s exited. HBA GOING AWAY\n",
729 if (is_qla8022(ha
)) {
730 qla4_8xxx_watchdog(ha
);
733 /* Search for relogin's to time-out and port down retry. */
734 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
735 /* Count down time between sending relogins */
736 if (adapter_up(ha
) &&
737 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
738 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
739 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
741 if (atomic_read(&ddb_entry
->retry_relogin_timer
)
743 atomic_set(&ddb_entry
->
746 set_bit(DPC_RELOGIN_DEVICE
,
748 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
749 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
751 ha
->host_no
, __func__
,
752 ddb_entry
->fw_ddb_index
));
754 atomic_dec(&ddb_entry
->
755 retry_relogin_timer
);
759 /* Wait for relogin to timeout */
760 if (atomic_read(&ddb_entry
->relogin_timer
) &&
761 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
763 * If the relogin times out and the device is
764 * still NOT ONLINE then try and relogin again.
766 if (atomic_read(&ddb_entry
->state
) !=
768 ddb_entry
->fw_ddb_device_state
==
769 DDB_DS_SESSION_FAILED
) {
770 /* Reset retry relogin timer */
771 atomic_inc(&ddb_entry
->relogin_retry_count
);
772 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
773 " timed out-retrying"
776 ddb_entry
->fw_ddb_index
,
777 atomic_read(&ddb_entry
->
778 relogin_retry_count
))
781 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
782 "initate relogin after"
784 ha
->host_no
, ddb_entry
->bus
,
786 ddb_entry
->fw_ddb_index
,
787 ddb_entry
->default_time2wait
+ 4)
790 atomic_set(&ddb_entry
->retry_relogin_timer
,
791 ddb_entry
->default_time2wait
+ 4);
796 if (!is_qla8022(ha
)) {
797 /* Check for heartbeat interval. */
798 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
799 ha
->heartbeat_interval
!= 0) {
800 ha
->seconds_since_last_heartbeat
++;
801 if (ha
->seconds_since_last_heartbeat
>
802 ha
->heartbeat_interval
+ 2)
803 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
807 /* Wakeup the dpc routine for this adapter, if needed. */
809 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
810 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
811 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
812 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
813 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
814 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
815 test_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
) ||
816 test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
) ||
817 test_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
) ||
818 test_bit(DPC_AEN
, &ha
->dpc_flags
)) &&
819 !test_bit(AF_DPC_SCHEDULED
, &ha
->flags
) &&
821 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
822 " - dpc flags = 0x%lx\n",
823 ha
->host_no
, __func__
, ha
->dpc_flags
));
824 qla4xxx_wake_dpc(ha
);
827 /* Reschedule timer thread to call us back in one second */
828 mod_timer(&ha
->timer
, jiffies
+ HZ
);
830 DEBUG2(ha
->seconds_since_last_intr
++);
834 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
835 * @ha: Pointer to host adapter structure.
837 * This routine stalls the driver until all outstanding commands are returned.
838 * Caller must release the Hardware Lock prior to calling this routine.
840 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
844 struct scsi_cmnd
*cmd
;
846 unsigned long wtime
= jiffies
+ (WAIT_CMD_TOV
* HZ
);
848 DEBUG2(ql4_printk(KERN_INFO
, ha
, "Wait up to %d seconds for cmds to "
849 "complete\n", WAIT_CMD_TOV
));
851 while (!time_after_eq(jiffies
, wtime
)) {
852 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
853 /* Find a command that hasn't completed. */
854 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
855 cmd
= scsi_host_find_tag(ha
->host
, index
);
859 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
861 /* If No Commands are pending, wait is complete */
862 if (index
== ha
->host
->can_queue
)
867 /* If we timed out on waiting for commands to come back
872 int qla4xxx_hw_reset(struct scsi_qla_host
*ha
)
874 uint32_t ctrl_status
;
875 unsigned long flags
= 0;
877 DEBUG2(printk(KERN_ERR
"scsi%ld: %s\n", ha
->host_no
, __func__
));
879 if (ql4xxx_lock_drvr_wait(ha
) != QLA_SUCCESS
)
882 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
885 * If the SCSI Reset Interrupt bit is set, clear it.
886 * Otherwise, the Soft Reset won't work.
888 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
889 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
890 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
892 /* Issue Soft Reset */
893 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
894 readl(&ha
->reg
->ctrl_status
);
896 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
901 * qla4xxx_soft_reset - performs soft reset.
902 * @ha: Pointer to host adapter structure.
904 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
906 uint32_t max_wait_time
;
907 unsigned long flags
= 0;
908 int status
= QLA_ERROR
;
909 uint32_t ctrl_status
;
911 qla4xxx_hw_reset(ha
);
913 /* Wait until the Network Reset Intr bit is cleared */
914 max_wait_time
= RESET_INTR_TOV
;
916 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
917 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
918 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
920 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
924 } while ((--max_wait_time
));
926 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
927 DEBUG2(printk(KERN_WARNING
928 "scsi%ld: Network Reset Intr not cleared by "
929 "Network function, clearing it now!\n",
931 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
932 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
933 readl(&ha
->reg
->ctrl_status
);
934 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
937 /* Wait until the firmware tells us the Soft Reset is done */
938 max_wait_time
= SOFT_RESET_TOV
;
940 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
941 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
942 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
944 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
945 status
= QLA_SUCCESS
;
950 } while ((--max_wait_time
));
953 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
954 * after the soft reset has taken place.
956 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
957 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
958 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
959 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
960 readl(&ha
->reg
->ctrl_status
);
962 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
964 /* If soft reset fails then most probably the bios on other
965 * function is also enabled.
966 * Since the initialization is sequential the other fn
967 * wont be able to acknowledge the soft reset.
968 * Issue a force soft reset to workaround this scenario.
970 if (max_wait_time
== 0) {
971 /* Issue Force Soft Reset */
972 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
973 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
974 readl(&ha
->reg
->ctrl_status
);
975 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
976 /* Wait until the firmware tells us the Soft Reset is done */
977 max_wait_time
= SOFT_RESET_TOV
;
979 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
980 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
981 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
983 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
984 status
= QLA_SUCCESS
;
989 } while ((--max_wait_time
));
996 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
997 * @ha: Pointer to host adapter structure.
998 * @res: returned scsi status
1000 * This routine is called just prior to a HARD RESET to return all
1001 * outstanding commands back to the Operating System.
1002 * Caller should make sure that the following locks are released
1003 * before this calling routine: Hardware lock, and io_request_lock.
1005 static void qla4xxx_abort_active_cmds(struct scsi_qla_host
*ha
, int res
)
1009 unsigned long flags
;
1011 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1012 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
1013 srb
= qla4xxx_del_from_active_array(ha
, i
);
1015 srb
->cmd
->result
= res
;
1016 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
1019 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1022 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host
*ha
)
1024 clear_bit(AF_ONLINE
, &ha
->flags
);
1026 /* Disable the board */
1027 ql4_printk(KERN_INFO
, ha
, "Disabling the board\n");
1028 set_bit(AF_HBA_GOING_AWAY
, &ha
->flags
);
1030 qla4xxx_abort_active_cmds(ha
, DID_NO_CONNECT
<< 16);
1031 qla4xxx_mark_all_devices_missing(ha
);
1032 clear_bit(AF_INIT_DONE
, &ha
->flags
);
1036 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1037 * @ha: Pointer to host adapter structure.
1039 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
)
1041 int status
= QLA_ERROR
;
1042 uint8_t reset_chip
= 0;
1044 /* Stall incoming I/O until we are done */
1045 scsi_block_requests(ha
->host
);
1046 clear_bit(AF_ONLINE
, &ha
->flags
);
1048 DEBUG2(ql4_printk(KERN_INFO
, ha
, "%s: adapter OFFLINE\n", __func__
));
1050 set_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
1052 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1055 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1056 * do not reset adapter, jump to initialize_adapter */
1057 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1058 status
= QLA_SUCCESS
;
1059 goto recover_ha_init_adapter
;
1062 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1063 * from eh_host_reset or ioctl module */
1064 if (is_qla8022(ha
) && !reset_chip
&&
1065 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
)) {
1067 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1068 "scsi%ld: %s - Performing stop_firmware...\n",
1069 ha
->host_no
, __func__
));
1070 status
= ha
->isp_ops
->reset_firmware(ha
);
1071 if (status
== QLA_SUCCESS
) {
1072 qla4xxx_cmd_wait(ha
);
1073 ha
->isp_ops
->disable_intrs(ha
);
1074 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1075 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1077 /* If the stop_firmware fails then
1078 * reset the entire chip */
1080 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1081 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1085 /* Issue full chip reset if recovering from a catastrophic error,
1086 * or if stop_firmware fails for ISP-82xx.
1087 * This is the default case for ISP-4xxx */
1088 if (!is_qla8022(ha
) || reset_chip
) {
1089 qla4xxx_cmd_wait(ha
);
1090 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1091 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1092 DEBUG2(ql4_printk(KERN_INFO
, ha
,
1093 "scsi%ld: %s - Performing chip reset..\n",
1094 ha
->host_no
, __func__
));
1095 status
= ha
->isp_ops
->reset_chip(ha
);
1098 /* Flush any pending ddb changed AENs */
1099 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1101 recover_ha_init_adapter
:
1102 /* Upon successful firmware/chip reset, re-initialize the adapter */
1103 if (status
== QLA_SUCCESS
) {
1104 /* For ISP-4xxx, force function 1 to always initialize
1105 * before function 3 to prevent both funcions from
1106 * stepping on top of the other */
1107 if (!is_qla8022(ha
) && (ha
->mac_index
== 3))
1110 /* NOTE: AF_ONLINE flag set upon successful completion of
1111 * qla4xxx_initialize_adapter */
1112 status
= qla4xxx_initialize_adapter(ha
, PRESERVE_DDB_LIST
);
1115 /* Retry failed adapter initialization, if necessary
1116 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1117 * case to prevent ping-pong resets between functions */
1118 if (!test_bit(AF_ONLINE
, &ha
->flags
) &&
1119 !test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1120 /* Adapter initialization failed, see if we can retry
1122 * Since we don't want to block the DPC for too long
1123 * with multiple resets in the same thread,
1124 * utilize DPC to retry */
1125 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
1126 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
1127 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1128 "(%d) more times\n", ha
->host_no
,
1129 ha
->retry_reset_ha_cnt
));
1130 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1133 if (ha
->retry_reset_ha_cnt
> 0) {
1134 /* Schedule another Reset HA--DPC will retry */
1135 ha
->retry_reset_ha_cnt
--;
1136 DEBUG2(printk("scsi%ld: recover adapter - "
1137 "retry remaining %d\n",
1139 ha
->retry_reset_ha_cnt
));
1143 if (ha
->retry_reset_ha_cnt
== 0) {
1144 /* Recover adapter retries have been exhausted.
1146 DEBUG2(printk("scsi%ld: recover adapter "
1147 "failed - board disabled\n",
1149 qla4xxx_dead_adapter_cleanup(ha
);
1150 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1151 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1152 clear_bit(DPC_RESET_HA_FW_CONTEXT
,
1158 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1159 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1160 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
1163 ha
->adapter_error_count
++;
1165 if (test_bit(AF_ONLINE
, &ha
->flags
))
1166 ha
->isp_ops
->enable_intrs(ha
);
1168 scsi_unblock_requests(ha
->host
);
1170 clear_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
);
1171 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha
->host_no
,
1172 status
== QLA_ERROR
? "FAILED" : "SUCCEDED"));
1177 void qla4xxx_wake_dpc(struct scsi_qla_host
*ha
)
1179 if (ha
->dpc_thread
&&
1180 !test_bit(AF_DPC_SCHEDULED
, &ha
->flags
)) {
1181 set_bit(AF_DPC_SCHEDULED
, &ha
->flags
);
1182 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
1187 * qla4xxx_do_dpc - dpc routine
1188 * @data: in our case pointer to adapter structure
1190 * This routine is a task that is schedule by the interrupt handler
1191 * to perform the background processing for interrupts. We put it
1192 * on a task queue that is consumed whenever the scheduler runs; that's
1193 * so you can do anything (i.e. put the process to sleep etc). In fact,
1194 * the mid-level tries to sleep when it reaches the driver threshold
1195 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1197 static void qla4xxx_do_dpc(struct work_struct
*work
)
1199 struct scsi_qla_host
*ha
=
1200 container_of(work
, struct scsi_qla_host
, dpc_work
);
1201 struct ddb_entry
*ddb_entry
, *dtemp
;
1202 int status
= QLA_ERROR
;
1204 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
1205 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1206 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
))
1208 /* Initialization not yet finished. Don't do anything yet. */
1209 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
1212 /* HBA is in the process of being permanently disabled.
1213 * Don't process anything */
1214 if (test_bit(AF_HBA_GOING_AWAY
, &ha
->flags
))
1217 if (is_qla8022(ha
)) {
1218 if (test_bit(DPC_HA_UNRECOVERABLE
, &ha
->dpc_flags
)) {
1219 qla4_8xxx_idc_lock(ha
);
1220 qla4_8xxx_wr_32(ha
, QLA82XX_CRB_DEV_STATE
,
1221 QLA82XX_DEV_FAILED
);
1222 qla4_8xxx_idc_unlock(ha
);
1223 ql4_printk(KERN_INFO
, ha
, "HW State: FAILED\n");
1224 qla4_8xxx_device_state_handler(ha
);
1226 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT
, &ha
->dpc_flags
)) {
1227 qla4_8xxx_need_qsnt_handler(ha
);
1231 if (!test_bit(DPC_RESET_ACTIVE
, &ha
->dpc_flags
) &&
1232 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
1233 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
1234 test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
))) {
1235 if (ql4xdontresethba
) {
1236 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1237 ha
->host_no
, __func__
));
1238 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
1239 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1240 clear_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
1241 goto dpc_post_reset_ha
;
1243 if (test_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
) ||
1244 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1245 qla4xxx_recover_adapter(ha
);
1247 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1248 uint8_t wait_time
= RESET_INTR_TOV
;
1250 while ((readw(&ha
->reg
->ctrl_status
) &
1251 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
1252 if (--wait_time
== 0)
1257 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1258 "bit not cleared-- resetting\n",
1259 ha
->host_no
, __func__
));
1260 qla4xxx_abort_active_cmds(ha
, DID_RESET
<< 16);
1261 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
) {
1262 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1263 status
= qla4xxx_recover_adapter(ha
);
1265 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1266 if (status
== QLA_SUCCESS
)
1267 ha
->isp_ops
->enable_intrs(ha
);
1272 /* ---- process AEN? --- */
1273 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1274 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1276 /* ---- Get DHCP IP Address? --- */
1277 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
1278 qla4xxx_get_dhcp_ip_address(ha
);
1280 /* ---- link change? --- */
1281 if (test_and_clear_bit(DPC_LINK_CHANGED
, &ha
->dpc_flags
)) {
1282 if (!test_bit(AF_LINK_UP
, &ha
->flags
)) {
1283 /* ---- link down? --- */
1284 list_for_each_entry_safe(ddb_entry
, dtemp
,
1285 &ha
->ddb_list
, list
) {
1286 if (atomic_read(&ddb_entry
->state
) ==
1288 qla4xxx_mark_device_missing(ha
,
1292 /* ---- link up? --- *
1293 * F/W will auto login to all devices ONLY ONCE after
1294 * link up during driver initialization and runtime
1295 * fatal error recovery. Therefore, the driver must
1296 * manually relogin to devices when recovering from
1297 * connection failures, logouts, expired KATO, etc. */
1299 list_for_each_entry_safe(ddb_entry
, dtemp
,
1300 &ha
->ddb_list
, list
) {
1301 if ((atomic_read(&ddb_entry
->state
) ==
1302 DDB_STATE_MISSING
) ||
1303 (atomic_read(&ddb_entry
->state
) ==
1305 if (ddb_entry
->fw_ddb_device_state
==
1306 DDB_DS_SESSION_ACTIVE
) {
1307 atomic_set(&ddb_entry
->state
,
1309 ql4_printk(KERN_INFO
, ha
,
1310 "scsi%ld: %s: ddb[%d]"
1312 ha
->host_no
, __func__
,
1313 ddb_entry
->fw_ddb_index
);
1315 iscsi_unblock_session(
1318 qla4xxx_relogin_device(
1326 /* ---- relogin device? --- */
1327 if (adapter_up(ha
) &&
1328 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
1329 list_for_each_entry_safe(ddb_entry
, dtemp
,
1330 &ha
->ddb_list
, list
) {
1331 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1332 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
1333 qla4xxx_relogin_device(ha
, ddb_entry
);
1336 * If mbx cmd times out there is no point
1337 * in continuing further.
1338 * With large no of targets this can hang
1341 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1342 printk(KERN_WARNING
"scsi%ld: %s: "
1343 "need to reset hba\n",
1344 ha
->host_no
, __func__
);
1349 clear_bit(AF_DPC_SCHEDULED
, &ha
->flags
);
1353 * qla4xxx_free_adapter - release the adapter
1354 * @ha: pointer to adapter structure
1356 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
1359 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
)) {
1360 /* Turn-off interrupts on the card. */
1361 ha
->isp_ops
->disable_intrs(ha
);
1364 /* Remove timer thread, if present */
1365 if (ha
->timer_active
)
1366 qla4xxx_stop_timer(ha
);
1368 /* Kill the kernel thread for this host */
1370 destroy_workqueue(ha
->dpc_thread
);
1372 /* Put firmware in known state */
1373 ha
->isp_ops
->reset_firmware(ha
);
1375 if (is_qla8022(ha
)) {
1376 qla4_8xxx_idc_lock(ha
);
1377 qla4_8xxx_clear_drv_active(ha
);
1378 qla4_8xxx_idc_unlock(ha
);
1381 /* Detach interrupts */
1382 if (test_and_clear_bit(AF_IRQ_ATTACHED
, &ha
->flags
))
1383 qla4xxx_free_irqs(ha
);
1385 /* free extra memory */
1386 qla4xxx_mem_free(ha
);
1389 int qla4_8xxx_iospace_config(struct scsi_qla_host
*ha
)
1392 uint8_t revision_id
;
1393 unsigned long mem_base
, mem_len
, db_base
, db_len
;
1394 struct pci_dev
*pdev
= ha
->pdev
;
1396 status
= pci_request_regions(pdev
, DRIVER_NAME
);
1399 "scsi(%ld) Failed to reserve PIO regions (%s) "
1400 "status=%d\n", ha
->host_no
, pci_name(pdev
), status
);
1401 goto iospace_error_exit
;
1404 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &revision_id
);
1405 DEBUG2(printk(KERN_INFO
"%s: revision-id=%d\n",
1406 __func__
, revision_id
));
1407 ha
->revision_id
= revision_id
;
1409 /* remap phys address */
1410 mem_base
= pci_resource_start(pdev
, 0); /* 0 is for BAR 0 */
1411 mem_len
= pci_resource_len(pdev
, 0);
1412 DEBUG2(printk(KERN_INFO
"%s: ioremap from %lx a size of %lx\n",
1413 __func__
, mem_base
, mem_len
));
1415 /* mapping of pcibase pointer */
1416 ha
->nx_pcibase
= (unsigned long)ioremap(mem_base
, mem_len
);
1417 if (!ha
->nx_pcibase
) {
1419 "cannot remap MMIO (%s), aborting\n", pci_name(pdev
));
1420 pci_release_regions(ha
->pdev
);
1421 goto iospace_error_exit
;
1424 /* Mapping of IO base pointer, door bell read and write pointer */
1426 /* mapping of IO base pointer */
1428 (struct device_reg_82xx __iomem
*)((uint8_t *)ha
->nx_pcibase
+
1429 0xbc000 + (ha
->pdev
->devfn
<< 11));
1431 db_base
= pci_resource_start(pdev
, 4); /* doorbell is on bar 4 */
1432 db_len
= pci_resource_len(pdev
, 4);
1434 /* mapping of doorbell write pointer */
1435 ha
->nx_db_wr_ptr
= (unsigned long)ioremap(db_base
+
1436 (ha
->pdev
->devfn
<< 12), 4);
1437 if (!ha
->nx_db_wr_ptr
) {
1439 "cannot remap MMIO doorbell-write (%s), aborting\n",
1441 goto iospace_error_exit
;
1443 /* mapping of doorbell read pointer */
1444 ha
->nx_db_rd_ptr
= (uint8_t *) ha
->nx_pcibase
+ (512 * 1024) +
1445 (ha
->pdev
->devfn
* 8);
1446 if (!ha
->nx_db_rd_ptr
)
1448 "cannot remap MMIO doorbell-read (%s), aborting\n",
1457 * qla4xxx_iospace_config - maps registers
1458 * @ha: pointer to adapter structure
1460 * This routines maps HBA's registers from the pci address space
1461 * into the kernel virtual address space for memory mapped i/o.
1463 int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
1465 unsigned long pio
, pio_len
, pio_flags
;
1466 unsigned long mmio
, mmio_len
, mmio_flags
;
1468 pio
= pci_resource_start(ha
->pdev
, 0);
1469 pio_len
= pci_resource_len(ha
->pdev
, 0);
1470 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1471 if (pio_flags
& IORESOURCE_IO
) {
1472 if (pio_len
< MIN_IOBASE_LEN
) {
1473 ql4_printk(KERN_WARNING
, ha
,
1474 "Invalid PCI I/O region size\n");
1478 ql4_printk(KERN_WARNING
, ha
, "region #0 not a PIO resource\n");
1482 /* Use MMIO operations for all accesses. */
1483 mmio
= pci_resource_start(ha
->pdev
, 1);
1484 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1485 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1487 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1488 ql4_printk(KERN_ERR
, ha
,
1489 "region #0 not an MMIO resource, aborting\n");
1491 goto iospace_error_exit
;
1494 if (mmio_len
< MIN_IOBASE_LEN
) {
1495 ql4_printk(KERN_ERR
, ha
,
1496 "Invalid PCI mem region size, aborting\n");
1497 goto iospace_error_exit
;
1500 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
1501 ql4_printk(KERN_WARNING
, ha
,
1502 "Failed to reserve PIO/MMIO regions\n");
1504 goto iospace_error_exit
;
1507 ha
->pio_address
= pio
;
1508 ha
->pio_length
= pio_len
;
1509 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
1511 ql4_printk(KERN_ERR
, ha
,
1512 "cannot remap MMIO, aborting\n");
1514 goto iospace_error_exit
;
1523 static struct isp_operations qla4xxx_isp_ops
= {
1524 .iospace_config
= qla4xxx_iospace_config
,
1525 .pci_config
= qla4xxx_pci_config
,
1526 .disable_intrs
= qla4xxx_disable_intrs
,
1527 .enable_intrs
= qla4xxx_enable_intrs
,
1528 .start_firmware
= qla4xxx_start_firmware
,
1529 .intr_handler
= qla4xxx_intr_handler
,
1530 .interrupt_service_routine
= qla4xxx_interrupt_service_routine
,
1531 .reset_chip
= qla4xxx_soft_reset
,
1532 .reset_firmware
= qla4xxx_hw_reset
,
1533 .queue_iocb
= qla4xxx_queue_iocb
,
1534 .complete_iocb
= qla4xxx_complete_iocb
,
1535 .rd_shdw_req_q_out
= qla4xxx_rd_shdw_req_q_out
,
1536 .rd_shdw_rsp_q_in
= qla4xxx_rd_shdw_rsp_q_in
,
1537 .get_sys_info
= qla4xxx_get_sys_info
,
1540 static struct isp_operations qla4_8xxx_isp_ops
= {
1541 .iospace_config
= qla4_8xxx_iospace_config
,
1542 .pci_config
= qla4_8xxx_pci_config
,
1543 .disable_intrs
= qla4_8xxx_disable_intrs
,
1544 .enable_intrs
= qla4_8xxx_enable_intrs
,
1545 .start_firmware
= qla4_8xxx_load_risc
,
1546 .intr_handler
= qla4_8xxx_intr_handler
,
1547 .interrupt_service_routine
= qla4_8xxx_interrupt_service_routine
,
1548 .reset_chip
= qla4_8xxx_isp_reset
,
1549 .reset_firmware
= qla4_8xxx_stop_firmware
,
1550 .queue_iocb
= qla4_8xxx_queue_iocb
,
1551 .complete_iocb
= qla4_8xxx_complete_iocb
,
1552 .rd_shdw_req_q_out
= qla4_8xxx_rd_shdw_req_q_out
,
1553 .rd_shdw_rsp_q_in
= qla4_8xxx_rd_shdw_rsp_q_in
,
1554 .get_sys_info
= qla4_8xxx_get_sys_info
,
1557 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
1559 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->req_q_out
);
1562 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host
*ha
)
1564 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_8xxx_reg
->req_q_out
));
1567 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
1569 return (uint16_t)le32_to_cpu(ha
->shadow_regs
->rsp_q_in
);
1572 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host
*ha
)
1574 return (uint16_t)le32_to_cpu(readl(&ha
->qla4_8xxx_reg
->rsp_q_in
));
1578 * qla4xxx_probe_adapter - callback function to probe HBA
1579 * @pdev: pointer to pci_dev structure
1580 * @pci_device_id: pointer to pci_device entry
1582 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1583 * It returns zero if successful. It also initializes all data necessary for
1586 static int __devinit
qla4xxx_probe_adapter(struct pci_dev
*pdev
,
1587 const struct pci_device_id
*ent
)
1589 int ret
= -ENODEV
, status
;
1590 struct Scsi_Host
*host
;
1591 struct scsi_qla_host
*ha
;
1592 uint8_t init_retry_count
= 0;
1594 struct qla4_8xxx_legacy_intr_set
*nx_legacy_intr
;
1596 if (pci_enable_device(pdev
))
1599 host
= scsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
));
1602 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1603 goto probe_disable_device
;
1606 /* Clear our data area */
1607 ha
= (struct scsi_qla_host
*) host
->hostdata
;
1608 memset(ha
, 0, sizeof(*ha
));
1610 /* Save the information from PCI BIOS. */
1613 ha
->host_no
= host
->host_no
;
1615 /* Setup Runtime configurable options */
1616 if (is_qla8022(ha
)) {
1617 ha
->isp_ops
= &qla4_8xxx_isp_ops
;
1618 rwlock_init(&ha
->hw_lock
);
1619 ha
->qdr_sn_window
= -1;
1620 ha
->ddr_mn_window
= -1;
1621 ha
->curr_window
= 255;
1622 ha
->func_num
= PCI_FUNC(ha
->pdev
->devfn
);
1623 nx_legacy_intr
= &legacy_intr
[ha
->func_num
];
1624 ha
->nx_legacy_intr
.int_vec_bit
= nx_legacy_intr
->int_vec_bit
;
1625 ha
->nx_legacy_intr
.tgt_status_reg
=
1626 nx_legacy_intr
->tgt_status_reg
;
1627 ha
->nx_legacy_intr
.tgt_mask_reg
= nx_legacy_intr
->tgt_mask_reg
;
1628 ha
->nx_legacy_intr
.pci_int_reg
= nx_legacy_intr
->pci_int_reg
;
1630 ha
->isp_ops
= &qla4xxx_isp_ops
;
1633 /* Configure PCI I/O space. */
1634 ret
= ha
->isp_ops
->iospace_config(ha
);
1636 goto probe_failed_ioconfig
;
1638 ql4_printk(KERN_INFO
, ha
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1639 pdev
->device
, pdev
->irq
, ha
->reg
);
1641 qla4xxx_config_dma_addressing(ha
);
1643 /* Initialize lists and spinlocks. */
1644 INIT_LIST_HEAD(&ha
->ddb_list
);
1645 INIT_LIST_HEAD(&ha
->free_srb_q
);
1647 mutex_init(&ha
->mbox_sem
);
1648 init_completion(&ha
->mbx_intr_comp
);
1650 spin_lock_init(&ha
->hardware_lock
);
1652 /* Allocate dma buffers */
1653 if (qla4xxx_mem_alloc(ha
)) {
1654 ql4_printk(KERN_WARNING
, ha
,
1655 "[ERROR] Failed to allocate memory for adapter\n");
1662 (void) qla4_8xxx_get_flash_info(ha
);
1665 * Initialize the Host adapter request/response queues and
1667 * NOTE: interrupts enabled upon successful completion
1669 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1670 while ((!test_bit(AF_ONLINE
, &ha
->flags
)) &&
1671 init_retry_count
++ < MAX_INIT_RETRIES
) {
1672 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1673 "(%d)\n", __func__
, init_retry_count
));
1675 if (ha
->isp_ops
->reset_chip(ha
) == QLA_ERROR
)
1678 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1681 if (!test_bit(AF_ONLINE
, &ha
->flags
)) {
1682 ql4_printk(KERN_WARNING
, ha
, "Failed to initialize adapter\n");
1688 host
->cmd_per_lun
= 3;
1689 host
->max_channel
= 0;
1690 host
->max_lun
= MAX_LUNS
- 1;
1691 host
->max_id
= MAX_TARGETS
;
1692 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
1693 host
->can_queue
= MAX_SRBS
;
1694 host
->transportt
= qla4xxx_scsi_transport
;
1696 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
1698 ql4_printk(KERN_WARNING
, ha
,
1699 "scsi_init_shared_tag_map failed\n");
1703 /* Startup the kernel thread for this host adapter. */
1704 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1705 "qla4xxx_dpc\n", __func__
));
1706 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
1707 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
1708 if (!ha
->dpc_thread
) {
1709 ql4_printk(KERN_WARNING
, ha
, "Unable to start DPC thread!\n");
1713 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
1715 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
1716 * (which is called indirectly by qla4xxx_initialize_adapter),
1717 * so that irqs will be registered after crbinit but before
1720 if (!is_qla8022(ha
)) {
1721 ret
= qla4xxx_request_irqs(ha
);
1723 ql4_printk(KERN_WARNING
, ha
, "Failed to reserve "
1724 "interrupt %d already in use.\n", pdev
->irq
);
1729 ha
->isp_ops
->enable_intrs(ha
);
1731 /* Start timer thread. */
1732 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
1734 set_bit(AF_INIT_DONE
, &ha
->flags
);
1736 pci_set_drvdata(pdev
, ha
);
1738 ret
= scsi_add_host(host
, &pdev
->dev
);
1743 " QLogic iSCSI HBA Driver version: %s\n"
1744 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1745 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
1746 ha
->host_no
, ha
->firmware_version
[0], ha
->firmware_version
[1],
1747 ha
->patch_number
, ha
->build_number
);
1748 scsi_scan_host(host
);
1752 qla4xxx_free_adapter(ha
);
1754 probe_failed_ioconfig
:
1755 scsi_host_put(ha
->host
);
1757 probe_disable_device
:
1758 pci_disable_device(pdev
);
1764 * qla4xxx_remove_adapter - calback function to remove adapter.
1765 * @pci_dev: PCI device pointer
1767 static void __devexit
qla4xxx_remove_adapter(struct pci_dev
*pdev
)
1769 struct scsi_qla_host
*ha
;
1771 ha
= pci_get_drvdata(pdev
);
1773 set_bit(AF_HBA_GOING_AWAY
, &ha
->flags
);
1775 /* remove devs from iscsi_sessions to scsi_devices */
1776 qla4xxx_free_ddb_list(ha
);
1778 scsi_remove_host(ha
->host
);
1780 qla4xxx_free_adapter(ha
);
1782 scsi_host_put(ha
->host
);
1784 pci_disable_device(pdev
);
1785 pci_set_drvdata(pdev
, NULL
);
1789 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1792 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1793 * supported addressing method.
1795 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
1799 /* Update our PCI device dma_mask for full 64 bit mask */
1800 if (pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(64)) == 0) {
1801 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_BIT_MASK(64))) {
1802 dev_dbg(&ha
->pdev
->dev
,
1803 "Failed to set 64 bit PCI consistent mask; "
1805 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
1809 retval
= pci_set_dma_mask(ha
->pdev
, DMA_BIT_MASK(32));
1812 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
1814 struct iscsi_cls_session
*sess
= starget_to_session(sdev
->sdev_target
);
1815 struct ddb_entry
*ddb
= sess
->dd_data
;
1817 sdev
->hostdata
= ddb
;
1818 sdev
->tagged_supported
= 1;
1819 scsi_activate_tcq(sdev
, QL4_DEF_QDEPTH
);
1823 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
1825 sdev
->tagged_supported
= 1;
1829 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
1831 scsi_deactivate_tcq(sdev
, 1);
1835 * qla4xxx_del_from_active_array - returns an active srb
1836 * @ha: Pointer to host adapter structure.
1837 * @index: index into the active_array
1839 * This routine removes and returns the srb at the specified index
1841 struct srb
*qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
,
1844 struct srb
*srb
= NULL
;
1845 struct scsi_cmnd
*cmd
= NULL
;
1847 cmd
= scsi_host_find_tag(ha
->host
, index
);
1851 srb
= (struct srb
*)CMD_SP(cmd
);
1855 /* update counters */
1856 if (srb
->flags
& SRB_DMA_VALID
) {
1857 ha
->req_q_count
+= srb
->iocb_cnt
;
1858 ha
->iocb_cnt
-= srb
->iocb_cnt
;
1860 srb
->cmd
->host_scribble
=
1861 (unsigned char *)(unsigned long) MAX_SRBS
;
1867 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1868 * @ha: Pointer to host adapter structure.
1869 * @cmd: Scsi Command to wait on.
1871 * This routine waits for the command to be returned by the Firmware
1872 * for some max time.
1874 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
1875 struct scsi_cmnd
*cmd
)
1879 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
1882 /* Checking to see if its returned to OS */
1883 rp
= (struct srb
*) CMD_SP(cmd
);
1890 } while (max_wait_time
--);
1896 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1897 * @ha: Pointer to host adapter structure
1899 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
1901 unsigned long wait_online
;
1903 wait_online
= jiffies
+ (30 * HZ
);
1904 while (time_before(jiffies
, wait_online
)) {
1908 else if (ha
->retry_reset_ha_cnt
== 0)
1918 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
1919 * @ha: pointer to HBA
1923 * This function waits for all outstanding commands to a lun to complete. It
1924 * returns 0 if all pending commands are returned and 1 otherwise.
1926 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host
*ha
,
1927 struct scsi_target
*stgt
,
1928 struct scsi_device
*sdev
)
1932 struct scsi_cmnd
*cmd
;
1935 * Waiting for all commands for the designated target or dev
1936 * in the active array
1938 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
1939 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
1940 if (cmd
&& stgt
== scsi_target(cmd
->device
) &&
1941 (!sdev
|| sdev
== cmd
->device
)) {
1942 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
1952 * qla4xxx_eh_abort - callback for abort task.
1953 * @cmd: Pointer to Linux's SCSI command structure
1955 * This routine is called by the Linux OS to abort the specified
1958 static int qla4xxx_eh_abort(struct scsi_cmnd
*cmd
)
1960 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
1961 unsigned int id
= cmd
->device
->id
;
1962 unsigned int lun
= cmd
->device
->lun
;
1963 unsigned long serial
= cmd
->serial_number
;
1964 struct srb
*srb
= NULL
;
1968 ql4_printk(KERN_INFO
, ha
,
1969 "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n",
1970 ha
->host_no
, id
, lun
, cmd
, serial
);
1972 srb
= (struct srb
*) CMD_SP(cmd
);
1977 kref_get(&srb
->srb_ref
);
1979 if (qla4xxx_abort_task(ha
, srb
) != QLA_SUCCESS
) {
1980 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
1981 ha
->host_no
, id
, lun
));
1984 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
1985 ha
->host_no
, id
, lun
));
1989 kref_put(&srb
->srb_ref
, qla4xxx_srb_compl
);
1991 /* Wait for command to complete */
1993 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
1994 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
1995 ha
->host_no
, id
, lun
));
2000 ql4_printk(KERN_INFO
, ha
,
2001 "scsi%ld:%d:%d: Abort command - %s\n",
2002 ha
->host_no
, id
, lun
, (ret
== SUCCESS
) ? "succeded" : "failed");
2008 * qla4xxx_eh_device_reset - callback for target reset.
2009 * @cmd: Pointer to Linux's SCSI command structure
2011 * This routine is called by the Linux OS to reset all luns on the
2014 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
2016 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
2017 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
2018 int ret
= FAILED
, stat
;
2023 ret
= iscsi_block_scsi_eh(cmd
);
2028 ql4_printk(KERN_INFO
, ha
,
2029 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
2030 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
2032 DEBUG2(printk(KERN_INFO
2033 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2034 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
2035 cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
2036 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
2038 /* FIXME: wait for hba to go online */
2039 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
2040 if (stat
!= QLA_SUCCESS
) {
2041 ql4_printk(KERN_INFO
, ha
, "DEVICE RESET FAILED. %d\n", stat
);
2042 goto eh_dev_reset_done
;
2045 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
2047 ql4_printk(KERN_INFO
, ha
,
2048 "DEVICE RESET FAILED - waiting for "
2050 goto eh_dev_reset_done
;
2054 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
2055 MM_LUN_RESET
) != QLA_SUCCESS
)
2056 goto eh_dev_reset_done
;
2058 ql4_printk(KERN_INFO
, ha
,
2059 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2060 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
2071 * qla4xxx_eh_target_reset - callback for target reset.
2072 * @cmd: Pointer to Linux's SCSI command structure
2074 * This routine is called by the Linux OS to reset the target.
2076 static int qla4xxx_eh_target_reset(struct scsi_cmnd
*cmd
)
2078 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
2079 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
2085 ret
= iscsi_block_scsi_eh(cmd
);
2089 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2090 "WARM TARGET RESET ISSUED.\n");
2092 DEBUG2(printk(KERN_INFO
2093 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2094 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
2095 ha
->host_no
, cmd
, jiffies
, cmd
->request
->timeout
/ HZ
,
2096 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
2098 stat
= qla4xxx_reset_target(ha
, ddb_entry
);
2099 if (stat
!= QLA_SUCCESS
) {
2100 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2101 "WARM TARGET RESET FAILED.\n");
2105 if (qla4xxx_eh_wait_for_commands(ha
, scsi_target(cmd
->device
),
2107 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2108 "WARM TARGET DEVICE RESET FAILED - "
2109 "waiting for commands.\n");
2114 if (qla4xxx_send_marker_iocb(ha
, ddb_entry
, cmd
->device
->lun
,
2115 MM_TGT_WARM_RESET
) != QLA_SUCCESS
) {
2116 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2117 "WARM TARGET DEVICE RESET FAILED - "
2118 "marker iocb failed.\n");
2122 starget_printk(KERN_INFO
, scsi_target(cmd
->device
),
2123 "WARM TARGET RESET SUCCEEDED.\n");
2128 * qla4xxx_eh_host_reset - kernel callback
2129 * @cmd: Pointer to Linux's SCSI command structure
2131 * This routine is invoked by the Linux kernel to perform fatal error
2132 * recovery on the specified adapter.
2134 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
2136 int return_status
= FAILED
;
2137 struct scsi_qla_host
*ha
;
2139 ha
= (struct scsi_qla_host
*) cmd
->device
->host
->hostdata
;
2141 if (ql4xdontresethba
) {
2142 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2143 ha
->host_no
, __func__
));
2147 ql4_printk(KERN_INFO
, ha
,
2148 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha
->host_no
,
2149 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
2151 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
2152 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2153 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
2159 if (!test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
2161 set_bit(DPC_RESET_HA_FW_CONTEXT
, &ha
->dpc_flags
);
2163 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
2166 if (qla4xxx_recover_adapter(ha
) == QLA_SUCCESS
)
2167 return_status
= SUCCESS
;
2169 ql4_printk(KERN_INFO
, ha
, "HOST RESET %s.\n",
2170 return_status
== FAILED
? "FAILED" : "SUCCEDED");
2172 return return_status
;
2175 static struct pci_device_id qla4xxx_pci_tbl
[] = {
2177 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2178 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
2179 .subvendor
= PCI_ANY_ID
,
2180 .subdevice
= PCI_ANY_ID
,
2183 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2184 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
2185 .subvendor
= PCI_ANY_ID
,
2186 .subdevice
= PCI_ANY_ID
,
2189 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2190 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
2191 .subvendor
= PCI_ANY_ID
,
2192 .subdevice
= PCI_ANY_ID
,
2195 .vendor
= PCI_VENDOR_ID_QLOGIC
,
2196 .device
= PCI_DEVICE_ID_QLOGIC_ISP8022
,
2197 .subvendor
= PCI_ANY_ID
,
2198 .subdevice
= PCI_ANY_ID
,
2202 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
2204 static struct pci_driver qla4xxx_pci_driver
= {
2205 .name
= DRIVER_NAME
,
2206 .id_table
= qla4xxx_pci_tbl
,
2207 .probe
= qla4xxx_probe_adapter
,
2208 .remove
= qla4xxx_remove_adapter
,
2211 static int __init
qla4xxx_module_init(void)
2215 /* Allocate cache for SRBs. */
2216 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
2217 SLAB_HWCACHE_ALIGN
, NULL
);
2218 if (srb_cachep
== NULL
) {
2220 "%s: Unable to allocate SRB cache..."
2221 "Failing load!\n", DRIVER_NAME
);
2226 /* Derive version string. */
2227 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
2228 if (ql4xextended_error_logging
)
2229 strcat(qla4xxx_version_str
, "-debug");
2231 qla4xxx_scsi_transport
=
2232 iscsi_register_transport(&qla4xxx_iscsi_transport
);
2233 if (!qla4xxx_scsi_transport
){
2235 goto release_srb_cache
;
2238 ret
= pci_register_driver(&qla4xxx_pci_driver
);
2240 goto unregister_transport
;
2242 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
2245 unregister_transport
:
2246 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
2248 kmem_cache_destroy(srb_cachep
);
2253 static void __exit
qla4xxx_module_exit(void)
2255 pci_unregister_driver(&qla4xxx_pci_driver
);
2256 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
2257 kmem_cache_destroy(srb_cachep
);
2260 module_init(qla4xxx_module_init
);
2261 module_exit(qla4xxx_module_exit
);
2263 MODULE_AUTHOR("QLogic Corporation");
2264 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
2265 MODULE_LICENSE("GPL");
2266 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);