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>
9 #include <scsi/scsi_tcq.h>
10 #include <scsi/scsicam.h>
13 #include "ql4_version.h"
16 #include "ql4_inline.h"
21 static char qla4xxx_version_str
[40];
24 * SRB allocation cache
26 static struct kmem_cache
*srb_cachep
;
29 * Module parameter information and variables
31 int ql4xdiscoverywait
= 60;
32 module_param(ql4xdiscoverywait
, int, S_IRUGO
| S_IRUSR
);
33 MODULE_PARM_DESC(ql4xdiscoverywait
, "Discovery wait time");
34 int ql4xdontresethba
= 0;
35 module_param(ql4xdontresethba
, int, S_IRUGO
| S_IRUSR
);
36 MODULE_PARM_DESC(ql4xdontresethba
,
37 "Dont reset the HBA when the driver gets 0x8002 AEN "
38 " default it will reset hba :0"
39 " set to 1 to avoid resetting HBA");
41 int ql4xextended_error_logging
= 0; /* 0 = off, 1 = log errors */
42 module_param(ql4xextended_error_logging
, int, S_IRUGO
| S_IRUSR
);
43 MODULE_PARM_DESC(ql4xextended_error_logging
,
44 "Option to enable extended error logging, "
45 "Default is 0 - no logging, 1 - debug logging");
47 int ql4_mod_unload
= 0;
50 * SCSI host template entry points
52 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
55 * iSCSI template entry points
57 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
58 enum iscsi_tgt_dscvr type
, uint32_t enable
,
59 struct sockaddr
*dst_addr
);
60 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
61 enum iscsi_param param
, char *buf
);
62 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
63 enum iscsi_param param
, char *buf
);
64 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
65 enum iscsi_host_param param
, char *buf
);
66 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
);
69 * SCSI host template entry points
71 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
72 void (*done
) (struct scsi_cmnd
*));
73 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
74 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
75 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
76 static int qla4xxx_slave_configure(struct scsi_device
*device
);
77 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
79 static struct scsi_host_template qla4xxx_driver_template
= {
80 .module
= THIS_MODULE
,
82 .proc_name
= DRIVER_NAME
,
83 .queuecommand
= qla4xxx_queuecommand
,
85 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
86 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
88 .slave_configure
= qla4xxx_slave_configure
,
89 .slave_alloc
= qla4xxx_slave_alloc
,
90 .slave_destroy
= qla4xxx_slave_destroy
,
92 .scan_finished
= iscsi_scan_finished
,
96 .use_clustering
= ENABLE_CLUSTERING
,
97 .sg_tablesize
= SG_ALL
,
99 .max_sectors
= 0xFFFF,
102 static struct iscsi_transport qla4xxx_iscsi_transport
= {
103 .owner
= THIS_MODULE
,
105 .caps
= CAP_FW_DB
| CAP_SENDTARGETS_OFFLOAD
|
106 CAP_DATA_PATH_OFFLOAD
,
107 .param_mask
= ISCSI_CONN_PORT
| ISCSI_CONN_ADDRESS
|
108 ISCSI_TARGET_NAME
| ISCSI_TPGT
,
109 .host_param_mask
= ISCSI_HOST_HWADDRESS
|
110 ISCSI_HOST_IPADDRESS
|
111 ISCSI_HOST_INITIATOR_NAME
,
112 .sessiondata_size
= sizeof(struct ddb_entry
),
113 .host_template
= &qla4xxx_driver_template
,
115 .tgt_dscvr
= qla4xxx_tgt_dscvr
,
116 .get_conn_param
= qla4xxx_conn_get_param
,
117 .get_session_param
= qla4xxx_sess_get_param
,
118 .get_host_param
= qla4xxx_host_get_param
,
119 .session_recovery_timedout
= qla4xxx_recovery_timedout
,
122 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
124 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
)
126 struct ddb_entry
*ddb_entry
= session
->dd_data
;
127 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
129 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
130 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
132 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
133 "of (%d) secs exhausted, marking device DEAD.\n",
134 ha
->host_no
, __func__
, ddb_entry
->fw_ddb_index
,
135 ha
->port_down_retry_count
));
137 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
139 ha
->host_no
, __func__
, ha
->dpc_flags
));
140 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
144 static int qla4xxx_host_get_param(struct Scsi_Host
*shost
,
145 enum iscsi_host_param param
, char *buf
)
147 struct scsi_qla_host
*ha
= to_qla_host(shost
);
151 case ISCSI_HOST_PARAM_HWADDRESS
:
152 len
= sysfs_format_mac(buf
, ha
->my_mac
, MAC_ADDR_LEN
);
154 case ISCSI_HOST_PARAM_IPADDRESS
:
155 len
= sprintf(buf
, "%d.%d.%d.%d\n", ha
->ip_address
[0],
156 ha
->ip_address
[1], ha
->ip_address
[2],
159 case ISCSI_HOST_PARAM_INITIATOR_NAME
:
160 len
= sprintf(buf
, "%s\n", ha
->name_string
);
169 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
170 enum iscsi_param param
, char *buf
)
172 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
176 case ISCSI_PARAM_TARGET_NAME
:
177 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
178 ddb_entry
->iscsi_name
);
180 case ISCSI_PARAM_TPGT
:
181 len
= sprintf(buf
, "%u\n", ddb_entry
->tpgt
);
190 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
191 enum iscsi_param param
, char *buf
)
193 struct iscsi_cls_session
*session
;
194 struct ddb_entry
*ddb_entry
;
197 session
= iscsi_dev_to_session(conn
->dev
.parent
);
198 ddb_entry
= session
->dd_data
;
201 case ISCSI_PARAM_CONN_PORT
:
202 len
= sprintf(buf
, "%hu\n", ddb_entry
->port
);
204 case ISCSI_PARAM_CONN_ADDRESS
:
205 /* TODO: what are the ipv6 bits */
206 len
= sprintf(buf
, "%u.%u.%u.%u\n",
207 NIPQUAD(ddb_entry
->ip_addr
));
216 static int qla4xxx_tgt_dscvr(struct Scsi_Host
*shost
,
217 enum iscsi_tgt_dscvr type
, uint32_t enable
,
218 struct sockaddr
*dst_addr
)
220 struct scsi_qla_host
*ha
;
221 struct sockaddr_in
*addr
;
222 struct sockaddr_in6
*addr6
;
225 ha
= (struct scsi_qla_host
*) shost
->hostdata
;
228 case ISCSI_TGT_DSCVR_SEND_TARGETS
:
229 if (dst_addr
->sa_family
== AF_INET
) {
230 addr
= (struct sockaddr_in
*)dst_addr
;
231 if (qla4xxx_send_tgts(ha
, (char *)&addr
->sin_addr
,
232 addr
->sin_port
) != QLA_SUCCESS
)
234 } else if (dst_addr
->sa_family
== AF_INET6
) {
236 * TODO: fix qla4xxx_send_tgts
238 addr6
= (struct sockaddr_in6
*)dst_addr
;
239 if (qla4xxx_send_tgts(ha
, (char *)&addr6
->sin6_addr
,
240 addr6
->sin6_port
) != QLA_SUCCESS
)
251 void qla4xxx_destroy_sess(struct ddb_entry
*ddb_entry
)
253 if (!ddb_entry
->sess
)
256 if (ddb_entry
->conn
) {
257 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
258 iscsi_remove_session(ddb_entry
->sess
);
260 iscsi_free_session(ddb_entry
->sess
);
263 int qla4xxx_add_sess(struct ddb_entry
*ddb_entry
)
267 ddb_entry
->sess
->recovery_tmo
= ddb_entry
->ha
->port_down_retry_count
;
268 err
= iscsi_add_session(ddb_entry
->sess
, ddb_entry
->fw_ddb_index
);
270 DEBUG2(printk(KERN_ERR
"Could not add session.\n"));
274 ddb_entry
->conn
= iscsi_create_conn(ddb_entry
->sess
, 0);
275 if (!ddb_entry
->conn
) {
276 iscsi_remove_session(ddb_entry
->sess
);
277 DEBUG2(printk(KERN_ERR
"Could not add connection.\n"));
281 /* finally ready to go */
282 iscsi_unblock_session(ddb_entry
->sess
);
286 struct ddb_entry
*qla4xxx_alloc_sess(struct scsi_qla_host
*ha
)
288 struct ddb_entry
*ddb_entry
;
289 struct iscsi_cls_session
*sess
;
291 sess
= iscsi_alloc_session(ha
->host
, &qla4xxx_iscsi_transport
);
295 ddb_entry
= sess
->dd_data
;
296 memset(ddb_entry
, 0, sizeof(*ddb_entry
));
298 ddb_entry
->sess
= sess
;
306 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
307 unsigned long interval
)
309 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
310 __func__
, ha
->host
->host_no
));
311 init_timer(&ha
->timer
);
312 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
313 ha
->timer
.data
= (unsigned long)ha
;
314 ha
->timer
.function
= (void (*)(unsigned long))func
;
315 add_timer(&ha
->timer
);
316 ha
->timer_active
= 1;
319 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
321 del_timer_sync(&ha
->timer
);
322 ha
->timer_active
= 0;
326 * qla4xxx_mark_device_missing - mark a device as missing.
327 * @ha: Pointer to host adapter structure.
328 * @ddb_entry: Pointer to device database entry
330 * This routine marks a device missing and resets the relogin retry count.
332 void qla4xxx_mark_device_missing(struct scsi_qla_host
*ha
,
333 struct ddb_entry
*ddb_entry
)
335 atomic_set(&ddb_entry
->state
, DDB_STATE_MISSING
);
336 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
337 ha
->host_no
, ddb_entry
->bus
, ddb_entry
->target
,
338 ddb_entry
->fw_ddb_index
));
339 iscsi_block_session(ddb_entry
->sess
);
340 iscsi_conn_error(ddb_entry
->conn
, ISCSI_ERR_CONN_FAILED
);
343 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
344 struct ddb_entry
*ddb_entry
,
345 struct scsi_cmnd
*cmd
,
346 void (*done
)(struct scsi_cmnd
*))
350 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
354 atomic_set(&srb
->ref_count
, 1);
356 srb
->ddb
= ddb_entry
;
359 cmd
->SCp
.ptr
= (void *)srb
;
360 cmd
->scsi_done
= done
;
365 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
367 struct scsi_cmnd
*cmd
= srb
->cmd
;
369 if (srb
->flags
& SRB_DMA_VALID
) {
371 srb
->flags
&= ~SRB_DMA_VALID
;
376 void qla4xxx_srb_compl(struct scsi_qla_host
*ha
, struct srb
*srb
)
378 struct scsi_cmnd
*cmd
= srb
->cmd
;
380 qla4xxx_srb_free_dma(ha
, srb
);
382 mempool_free(srb
, ha
->srb_mempool
);
388 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
389 * @cmd: Pointer to Linux's SCSI command structure
390 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
391 * that the command has been processed.
394 * This routine is invoked by Linux to send a SCSI command to the driver.
395 * The mid-level driver tries to ensure that queuecommand never gets
396 * invoked concurrently with itself or the interrupt handler (although
397 * the interrupt handler may call this routine as part of request-
398 * completion handling). Unfortunely, it sometimes calls the scheduler
399 * in interrupt context which is a big NO! NO!.
401 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
402 void (*done
)(struct scsi_cmnd
*))
404 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
405 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
406 struct iscsi_cls_session
*sess
= ddb_entry
->sess
;
411 cmd
->result
= DID_IMM_RETRY
<< 16;
412 goto qc_fail_command
;
415 rval
= iscsi_session_chkready(sess
);
418 goto qc_fail_command
;
421 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
422 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
) {
423 cmd
->result
= DID_NO_CONNECT
<< 16;
424 goto qc_fail_command
;
429 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
))
432 spin_unlock_irq(ha
->host
->host_lock
);
434 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
, done
);
436 goto qc_host_busy_lock
;
438 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
439 if (rval
!= QLA_SUCCESS
)
440 goto qc_host_busy_free_sp
;
442 spin_lock_irq(ha
->host
->host_lock
);
445 qc_host_busy_free_sp
:
446 qla4xxx_srb_free_dma(ha
, srb
);
447 mempool_free(srb
, ha
->srb_mempool
);
450 spin_lock_irq(ha
->host
->host_lock
);
453 return SCSI_MLQUEUE_HOST_BUSY
;
462 * qla4xxx_mem_free - frees memory allocated to adapter
463 * @ha: Pointer to host adapter structure.
465 * Frees memory previously allocated by qla4xxx_mem_alloc
467 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
470 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
476 ha
->request_ring
= NULL
;
478 ha
->response_ring
= NULL
;
479 ha
->response_dma
= 0;
480 ha
->shadow_regs
= NULL
;
481 ha
->shadow_regs_dma
= 0;
485 mempool_destroy(ha
->srb_mempool
);
487 ha
->srb_mempool
= NULL
;
489 /* release io space registers */
492 pci_release_regions(ha
->pdev
);
496 * qla4xxx_mem_alloc - allocates memory for use by adapter.
497 * @ha: Pointer to host adapter structure
499 * Allocates DMA memory for request and response queues. Also allocates memory
502 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
506 /* Allocate contiguous block of DMA memory for queues. */
507 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
508 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
509 sizeof(struct shadow_regs
) +
511 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
512 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
513 &ha
->queues_dma
, GFP_KERNEL
);
514 if (ha
->queues
== NULL
) {
515 dev_warn(&ha
->pdev
->dev
,
516 "Memory Allocation failed - queues.\n");
518 goto mem_alloc_error_exit
;
520 memset(ha
->queues
, 0, ha
->queues_len
);
523 * As per RISC alignment requirements -- the bus-address must be a
524 * multiple of the request-ring size (in bytes).
527 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
528 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
529 (MEM_ALIGN_VALUE
- 1));
531 /* Update request and response queue pointers. */
532 ha
->request_dma
= ha
->queues_dma
+ align
;
533 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
534 ha
->response_dma
= ha
->queues_dma
+ align
+
535 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
536 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
537 (REQUEST_QUEUE_DEPTH
*
539 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
540 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
541 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
542 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
543 (REQUEST_QUEUE_DEPTH
*
545 (RESPONSE_QUEUE_DEPTH
*
548 /* Allocate memory for srb pool. */
549 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
550 mempool_free_slab
, srb_cachep
);
551 if (ha
->srb_mempool
== NULL
) {
552 dev_warn(&ha
->pdev
->dev
,
553 "Memory Allocation failed - SRB Pool.\n");
555 goto mem_alloc_error_exit
;
560 mem_alloc_error_exit
:
561 qla4xxx_mem_free(ha
);
566 * qla4xxx_timer - checks every second for work to do.
567 * @ha: Pointer to host adapter structure.
569 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
571 struct ddb_entry
*ddb_entry
, *dtemp
;
574 /* Search for relogin's to time-out and port down retry. */
575 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
576 /* Count down time between sending relogins */
577 if (adapter_up(ha
) &&
578 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
579 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
580 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
582 if (atomic_read(&ddb_entry
->retry_relogin_timer
)
584 atomic_set(&ddb_entry
->
587 set_bit(DPC_RELOGIN_DEVICE
,
589 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
590 DEBUG2(printk("scsi%ld: %s: index [%d]"
592 ha
->host_no
, __func__
,
593 ddb_entry
->fw_ddb_index
));
595 atomic_dec(&ddb_entry
->
596 retry_relogin_timer
);
600 /* Wait for relogin to timeout */
601 if (atomic_read(&ddb_entry
->relogin_timer
) &&
602 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
604 * If the relogin times out and the device is
605 * still NOT ONLINE then try and relogin again.
607 if (atomic_read(&ddb_entry
->state
) !=
609 ddb_entry
->fw_ddb_device_state
==
610 DDB_DS_SESSION_FAILED
) {
611 /* Reset retry relogin timer */
612 atomic_inc(&ddb_entry
->relogin_retry_count
);
613 DEBUG2(printk("scsi%ld: index[%d] relogin"
614 " timed out-retrying"
617 ddb_entry
->fw_ddb_index
,
618 atomic_read(&ddb_entry
->
619 relogin_retry_count
))
622 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
623 "initate relogin after"
625 ha
->host_no
, ddb_entry
->bus
,
627 ddb_entry
->fw_ddb_index
,
628 ddb_entry
->default_time2wait
+ 4)
631 atomic_set(&ddb_entry
->retry_relogin_timer
,
632 ddb_entry
->default_time2wait
+ 4);
637 /* Check for heartbeat interval. */
638 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
639 ha
->heartbeat_interval
!= 0) {
640 ha
->seconds_since_last_heartbeat
++;
641 if (ha
->seconds_since_last_heartbeat
>
642 ha
->heartbeat_interval
+ 2)
643 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
647 /* Wakeup the dpc routine for this adapter, if needed. */
649 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
650 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
651 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
652 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
653 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
654 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
655 test_bit(DPC_AEN
, &ha
->dpc_flags
)) &&
657 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
658 " - dpc flags = 0x%lx\n",
659 ha
->host_no
, __func__
, ha
->dpc_flags
));
660 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
663 /* Reschedule timer thread to call us back in one second */
664 mod_timer(&ha
->timer
, jiffies
+ HZ
);
666 DEBUG2(ha
->seconds_since_last_intr
++);
670 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
671 * @ha: Pointer to host adapter structure.
673 * This routine stalls the driver until all outstanding commands are returned.
674 * Caller must release the Hardware Lock prior to calling this routine.
676 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
679 int stat
= QLA_SUCCESS
;
681 struct scsi_cmnd
*cmd
;
682 int wait_cnt
= WAIT_CMD_TOV
; /*
683 * Initialized for 30 seconds as we
684 * expect all commands to retuned
689 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
690 /* Find a command that hasn't completed. */
691 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
692 cmd
= scsi_host_find_tag(ha
->host
, index
);
696 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
698 /* If No Commands are pending, wait is complete */
699 if (index
== ha
->host
->can_queue
) {
703 /* If we timed out on waiting for commands to come back
712 } /* End of While (wait_cnt) */
717 void qla4xxx_hw_reset(struct scsi_qla_host
*ha
)
719 uint32_t ctrl_status
;
720 unsigned long flags
= 0;
722 DEBUG2(printk(KERN_ERR
"scsi%ld: %s\n", ha
->host_no
, __func__
));
724 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
727 * If the SCSI Reset Interrupt bit is set, clear it.
728 * Otherwise, the Soft Reset won't work.
730 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
731 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
732 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
734 /* Issue Soft Reset */
735 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
736 readl(&ha
->reg
->ctrl_status
);
738 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
742 * qla4xxx_soft_reset - performs soft reset.
743 * @ha: Pointer to host adapter structure.
745 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
747 uint32_t max_wait_time
;
748 unsigned long flags
= 0;
749 int status
= QLA_ERROR
;
750 uint32_t ctrl_status
;
752 qla4xxx_hw_reset(ha
);
754 /* Wait until the Network Reset Intr bit is cleared */
755 max_wait_time
= RESET_INTR_TOV
;
757 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
758 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
759 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
761 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
765 } while ((--max_wait_time
));
767 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
768 DEBUG2(printk(KERN_WARNING
769 "scsi%ld: Network Reset Intr not cleared by "
770 "Network function, clearing it now!\n",
772 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
773 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
774 readl(&ha
->reg
->ctrl_status
);
775 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
778 /* Wait until the firmware tells us the Soft Reset is done */
779 max_wait_time
= SOFT_RESET_TOV
;
781 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
782 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
783 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
785 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
786 status
= QLA_SUCCESS
;
791 } while ((--max_wait_time
));
794 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
795 * after the soft reset has taken place.
797 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
798 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
799 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
800 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
801 readl(&ha
->reg
->ctrl_status
);
803 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
805 /* If soft reset fails then most probably the bios on other
806 * function is also enabled.
807 * Since the initialization is sequential the other fn
808 * wont be able to acknowledge the soft reset.
809 * Issue a force soft reset to workaround this scenario.
811 if (max_wait_time
== 0) {
812 /* Issue Force Soft Reset */
813 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
814 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
815 readl(&ha
->reg
->ctrl_status
);
816 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
817 /* Wait until the firmware tells us the Soft Reset is done */
818 max_wait_time
= SOFT_RESET_TOV
;
820 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
821 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
822 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
824 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
825 status
= QLA_SUCCESS
;
830 } while ((--max_wait_time
));
837 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
838 * @ha: Pointer to host adapter structure.
840 * This routine is called just prior to a HARD RESET to return all
841 * outstanding commands back to the Operating System.
842 * Caller should make sure that the following locks are released
843 * before this calling routine: Hardware lock, and io_request_lock.
845 static void qla4xxx_flush_active_srbs(struct scsi_qla_host
*ha
)
851 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
852 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
853 srb
= qla4xxx_del_from_active_array(ha
, i
);
855 srb
->cmd
->result
= DID_RESET
<< 16;
856 qla4xxx_srb_compl(ha
, srb
);
859 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
864 * qla4xxx_recover_adapter - recovers adapter after a fatal error
865 * @ha: Pointer to host adapter structure.
866 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
867 * after adapter recovery has completed.
868 * 0=preserve ddb list, 1=destroy and rebuild ddb list
870 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
,
871 uint8_t renew_ddb_list
)
875 /* Stall incoming I/O until we are done */
876 clear_bit(AF_ONLINE
, &ha
->flags
);
877 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha
->host_no
,
880 /* Wait for outstanding commands to complete.
881 * Stalls the driver for max 30 secs
883 status
= qla4xxx_cmd_wait(ha
);
885 qla4xxx_disable_intrs(ha
);
887 /* Flush any pending ddb changed AENs */
888 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
890 /* Reset the firmware. If successful, function
891 * returns with ISP interrupts enabled.
893 if (status
== QLA_SUCCESS
) {
894 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
895 ha
->host_no
, __func__
));
896 qla4xxx_flush_active_srbs(ha
);
897 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
898 status
= qla4xxx_soft_reset(ha
);
903 /* Flush any pending ddb changed AENs */
904 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
906 /* Re-initialize firmware. If successful, function returns
907 * with ISP interrupts enabled */
908 if (status
== QLA_SUCCESS
) {
909 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
910 ha
->host_no
, __func__
));
912 /* If successful, AF_ONLINE flag set in
913 * qla4xxx_initialize_adapter */
914 status
= qla4xxx_initialize_adapter(ha
, renew_ddb_list
);
917 /* Failed adapter initialization?
918 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
919 if ((test_bit(AF_ONLINE
, &ha
->flags
) == 0) &&
920 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))) {
921 /* Adapter initialization failed, see if we can retry
922 * resetting the ha */
923 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
924 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
925 DEBUG2(printk("scsi%ld: recover adapter - retrying "
926 "(%d) more times\n", ha
->host_no
,
927 ha
->retry_reset_ha_cnt
));
928 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
931 if (ha
->retry_reset_ha_cnt
> 0) {
932 /* Schedule another Reset HA--DPC will retry */
933 ha
->retry_reset_ha_cnt
--;
934 DEBUG2(printk("scsi%ld: recover adapter - "
935 "retry remaining %d\n",
937 ha
->retry_reset_ha_cnt
));
941 if (ha
->retry_reset_ha_cnt
== 0) {
942 /* Recover adapter retries have been exhausted.
944 DEBUG2(printk("scsi%ld: recover adapter "
945 "failed - board disabled\n",
947 qla4xxx_flush_active_srbs(ha
);
948 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
949 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
950 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
,
956 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
957 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
);
958 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
961 ha
->adapter_error_count
++;
963 if (status
== QLA_SUCCESS
)
964 qla4xxx_enable_intrs(ha
);
966 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha
->host_no
));
971 * qla4xxx_do_dpc - dpc routine
972 * @data: in our case pointer to adapter structure
974 * This routine is a task that is schedule by the interrupt handler
975 * to perform the background processing for interrupts. We put it
976 * on a task queue that is consumed whenever the scheduler runs; that's
977 * so you can do anything (i.e. put the process to sleep etc). In fact,
978 * the mid-level tries to sleep when it reaches the driver threshold
979 * "host->can_queue". This can cause a panic if we were in our interrupt code.
981 static void qla4xxx_do_dpc(struct work_struct
*work
)
983 struct scsi_qla_host
*ha
=
984 container_of(work
, struct scsi_qla_host
, dpc_work
);
985 struct ddb_entry
*ddb_entry
, *dtemp
;
986 int status
= QLA_ERROR
;
988 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
989 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
990 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
,
991 readw(&ha
->reg
->ctrl_status
)));
993 /* Initialization not yet finished. Don't do anything yet. */
994 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
997 if (adapter_up(ha
) ||
998 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
999 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
1000 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
)) {
1001 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
1002 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1003 qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
);
1005 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1006 uint8_t wait_time
= RESET_INTR_TOV
;
1008 while ((readw(&ha
->reg
->ctrl_status
) &
1009 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
1010 if (--wait_time
== 0)
1015 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1016 "bit not cleared-- resetting\n",
1017 ha
->host_no
, __func__
));
1018 qla4xxx_flush_active_srbs(ha
);
1019 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
) {
1020 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1021 status
= qla4xxx_initialize_adapter(ha
,
1024 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1025 if (status
== QLA_SUCCESS
)
1026 qla4xxx_enable_intrs(ha
);
1030 /* ---- process AEN? --- */
1031 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1032 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1034 /* ---- Get DHCP IP Address? --- */
1035 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
1036 qla4xxx_get_dhcp_ip_address(ha
);
1038 /* ---- relogin device? --- */
1039 if (adapter_up(ha
) &&
1040 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
1041 list_for_each_entry_safe(ddb_entry
, dtemp
,
1042 &ha
->ddb_list
, list
) {
1043 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1044 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
1045 qla4xxx_relogin_device(ha
, ddb_entry
);
1048 * If mbx cmd times out there is no point
1049 * in continuing further.
1050 * With large no of targets this can hang
1053 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1054 printk(KERN_WARNING
"scsi%ld: %s: "
1055 "need to reset hba\n",
1056 ha
->host_no
, __func__
);
1064 * qla4xxx_free_adapter - release the adapter
1065 * @ha: pointer to adapter structure
1067 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
1070 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
)) {
1071 /* Turn-off interrupts on the card. */
1072 qla4xxx_disable_intrs(ha
);
1075 /* Kill the kernel thread for this host */
1077 destroy_workqueue(ha
->dpc_thread
);
1079 /* Issue Soft Reset to put firmware in unknown state */
1080 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
1081 qla4xxx_hw_reset(ha
);
1083 /* Remove timer thread, if present */
1084 if (ha
->timer_active
)
1085 qla4xxx_stop_timer(ha
);
1087 /* Detach interrupts */
1088 if (test_and_clear_bit(AF_IRQ_ATTACHED
, &ha
->flags
))
1089 free_irq(ha
->pdev
->irq
, ha
);
1091 /* free extra memory */
1092 qla4xxx_mem_free(ha
);
1094 pci_disable_device(ha
->pdev
);
1099 * qla4xxx_iospace_config - maps registers
1100 * @ha: pointer to adapter structure
1102 * This routines maps HBA's registers from the pci address space
1103 * into the kernel virtual address space for memory mapped i/o.
1105 static int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
1107 unsigned long pio
, pio_len
, pio_flags
;
1108 unsigned long mmio
, mmio_len
, mmio_flags
;
1110 pio
= pci_resource_start(ha
->pdev
, 0);
1111 pio_len
= pci_resource_len(ha
->pdev
, 0);
1112 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1113 if (pio_flags
& IORESOURCE_IO
) {
1114 if (pio_len
< MIN_IOBASE_LEN
) {
1115 dev_warn(&ha
->pdev
->dev
,
1116 "Invalid PCI I/O region size\n");
1120 dev_warn(&ha
->pdev
->dev
, "region #0 not a PIO resource\n");
1124 /* Use MMIO operations for all accesses. */
1125 mmio
= pci_resource_start(ha
->pdev
, 1);
1126 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1127 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1129 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1130 dev_err(&ha
->pdev
->dev
,
1131 "region #0 not an MMIO resource, aborting\n");
1133 goto iospace_error_exit
;
1135 if (mmio_len
< MIN_IOBASE_LEN
) {
1136 dev_err(&ha
->pdev
->dev
,
1137 "Invalid PCI mem region size, aborting\n");
1138 goto iospace_error_exit
;
1141 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
1142 dev_warn(&ha
->pdev
->dev
,
1143 "Failed to reserve PIO/MMIO regions\n");
1145 goto iospace_error_exit
;
1148 ha
->pio_address
= pio
;
1149 ha
->pio_length
= pio_len
;
1150 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
1152 dev_err(&ha
->pdev
->dev
,
1153 "cannot remap MMIO, aborting\n");
1155 goto iospace_error_exit
;
1165 * qla4xxx_probe_adapter - callback function to probe HBA
1166 * @pdev: pointer to pci_dev structure
1167 * @pci_device_id: pointer to pci_device entry
1169 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1170 * It returns zero if successful. It also initializes all data necessary for
1173 static int __devinit
qla4xxx_probe_adapter(struct pci_dev
*pdev
,
1174 const struct pci_device_id
*ent
)
1176 int ret
= -ENODEV
, status
;
1177 struct Scsi_Host
*host
;
1178 struct scsi_qla_host
*ha
;
1179 struct ddb_entry
*ddb_entry
, *ddbtemp
;
1180 uint8_t init_retry_count
= 0;
1183 if (pci_enable_device(pdev
))
1186 host
= scsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
));
1189 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1190 goto probe_disable_device
;
1193 /* Clear our data area */
1194 ha
= (struct scsi_qla_host
*) host
->hostdata
;
1195 memset(ha
, 0, sizeof(*ha
));
1197 /* Save the information from PCI BIOS. */
1200 ha
->host_no
= host
->host_no
;
1202 /* Configure PCI I/O space. */
1203 ret
= qla4xxx_iospace_config(ha
);
1207 dev_info(&ha
->pdev
->dev
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1208 pdev
->device
, pdev
->irq
, ha
->reg
);
1210 qla4xxx_config_dma_addressing(ha
);
1212 /* Initialize lists and spinlocks. */
1213 INIT_LIST_HEAD(&ha
->ddb_list
);
1214 INIT_LIST_HEAD(&ha
->free_srb_q
);
1216 mutex_init(&ha
->mbox_sem
);
1218 spin_lock_init(&ha
->hardware_lock
);
1220 /* Allocate dma buffers */
1221 if (qla4xxx_mem_alloc(ha
)) {
1222 dev_warn(&ha
->pdev
->dev
,
1223 "[ERROR] Failed to allocate memory for adapter\n");
1230 * Initialize the Host adapter request/response queues and
1232 * NOTE: interrupts enabled upon successful completion
1234 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1235 while (status
== QLA_ERROR
&& init_retry_count
++ < MAX_INIT_RETRIES
) {
1236 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1237 "(%d)\n", __func__
, init_retry_count
));
1238 qla4xxx_soft_reset(ha
);
1239 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1241 if (status
== QLA_ERROR
) {
1242 dev_warn(&ha
->pdev
->dev
, "Failed to initialize adapter\n");
1248 host
->cmd_per_lun
= 3;
1249 host
->max_channel
= 0;
1250 host
->max_lun
= MAX_LUNS
- 1;
1251 host
->max_id
= MAX_TARGETS
;
1252 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
1253 host
->can_queue
= MAX_SRBS
;
1254 host
->transportt
= qla4xxx_scsi_transport
;
1256 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
1258 dev_warn(&ha
->pdev
->dev
, "scsi_init_shared_tag_map failed\n");
1262 /* Startup the kernel thread for this host adapter. */
1263 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1264 "qla4xxx_dpc\n", __func__
));
1265 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
1266 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
1267 if (!ha
->dpc_thread
) {
1268 dev_warn(&ha
->pdev
->dev
, "Unable to start DPC thread!\n");
1272 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
1274 ret
= request_irq(pdev
->irq
, qla4xxx_intr_handler
,
1275 IRQF_DISABLED
| IRQF_SHARED
, "qla4xxx", ha
);
1277 dev_warn(&ha
->pdev
->dev
, "Failed to reserve interrupt %d"
1278 " already in use.\n", pdev
->irq
);
1281 set_bit(AF_IRQ_ATTACHED
, &ha
->flags
);
1282 host
->irq
= pdev
->irq
;
1283 DEBUG(printk("scsi%d: irq %d attached\n", ha
->host_no
, ha
->pdev
->irq
));
1285 qla4xxx_enable_intrs(ha
);
1287 /* Start timer thread. */
1288 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
1290 set_bit(AF_INIT_DONE
, &ha
->flags
);
1292 pci_set_drvdata(pdev
, ha
);
1294 ret
= scsi_add_host(host
, &pdev
->dev
);
1298 /* Update transport device information for all devices. */
1299 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
1300 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
)
1301 if (qla4xxx_add_sess(ddb_entry
))
1306 " QLogic iSCSI HBA Driver version: %s\n"
1307 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1308 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
1309 ha
->host_no
, ha
->firmware_version
[0], ha
->firmware_version
[1],
1310 ha
->patch_number
, ha
->build_number
);
1311 scsi_scan_host(host
);
1315 qla4xxx_free_ddb_list(ha
);
1316 scsi_remove_host(host
);
1319 qla4xxx_free_adapter(ha
);
1320 scsi_host_put(ha
->host
);
1322 probe_disable_device
:
1323 pci_disable_device(pdev
);
1329 * qla4xxx_remove_adapter - calback function to remove adapter.
1330 * @pci_dev: PCI device pointer
1332 static void __devexit
qla4xxx_remove_adapter(struct pci_dev
*pdev
)
1334 struct scsi_qla_host
*ha
;
1336 ha
= pci_get_drvdata(pdev
);
1338 qla4xxx_disable_intrs(ha
);
1340 while (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
))
1343 /* remove devs from iscsi_sessions to scsi_devices */
1344 qla4xxx_free_ddb_list(ha
);
1346 scsi_remove_host(ha
->host
);
1348 qla4xxx_free_adapter(ha
);
1350 scsi_host_put(ha
->host
);
1352 pci_set_drvdata(pdev
, NULL
);
1356 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1359 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1360 * supported addressing method.
1362 static void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
1366 /* Update our PCI device dma_mask for full 64 bit mask */
1367 if (pci_set_dma_mask(ha
->pdev
, DMA_64BIT_MASK
) == 0) {
1368 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1369 dev_dbg(&ha
->pdev
->dev
,
1370 "Failed to set 64 bit PCI consistent mask; "
1372 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
1376 retval
= pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1379 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
1381 struct iscsi_cls_session
*sess
= starget_to_session(sdev
->sdev_target
);
1382 struct ddb_entry
*ddb
= sess
->dd_data
;
1384 sdev
->hostdata
= ddb
;
1385 sdev
->tagged_supported
= 1;
1386 scsi_activate_tcq(sdev
, sdev
->host
->can_queue
);
1390 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
1392 sdev
->tagged_supported
= 1;
1396 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
1398 scsi_deactivate_tcq(sdev
, 1);
1402 * qla4xxx_del_from_active_array - returns an active srb
1403 * @ha: Pointer to host adapter structure.
1404 * @index: index into to the active_array
1406 * This routine removes and returns the srb at the specified index
1408 struct srb
* qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
, uint32_t index
)
1410 struct srb
*srb
= NULL
;
1411 struct scsi_cmnd
*cmd
;
1413 if (!(cmd
= scsi_host_find_tag(ha
->host
, index
)))
1416 if (!(srb
= (struct srb
*)cmd
->host_scribble
))
1419 /* update counters */
1420 if (srb
->flags
& SRB_DMA_VALID
) {
1421 ha
->req_q_count
+= srb
->iocb_cnt
;
1422 ha
->iocb_cnt
-= srb
->iocb_cnt
;
1424 srb
->cmd
->host_scribble
= NULL
;
1430 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1431 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1432 * @cmd: Scsi Command to wait on.
1434 * This routine waits for the command to be returned by the Firmware
1435 * for some max time.
1437 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
1438 struct scsi_cmnd
*cmd
)
1442 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
1445 /* Checking to see if its returned to OS */
1446 rp
= (struct srb
*) cmd
->SCp
.ptr
;
1453 } while (max_wait_time
--);
1459 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1460 * @ha: Pointer to host adapter structure
1462 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
1464 unsigned long wait_online
;
1466 wait_online
= jiffies
+ (30 * HZ
);
1467 while (time_before(jiffies
, wait_online
)) {
1471 else if (ha
->retry_reset_ha_cnt
== 0)
1481 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1482 * @ha: pointer to to HBA
1486 * This function waits for all outstanding commands to a lun to complete. It
1487 * returns 0 if all pending commands are returned and 1 otherwise.
1489 static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host
*ha
,
1494 struct scsi_cmnd
*cmd
;
1497 * Waiting for all commands for the designated target in the active
1500 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
1501 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
1502 if (cmd
&& cmd
->device
->id
== t
&& cmd
->device
->lun
== l
) {
1503 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
1513 * qla4xxx_eh_device_reset - callback for target reset.
1514 * @cmd: Pointer to Linux's SCSI command structure
1516 * This routine is called by the Linux OS to reset all luns on the
1519 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1521 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
1522 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
1524 int ret
= FAILED
, stat
;
1526 sp
= (struct srb
*) cmd
->SCp
.ptr
;
1527 if (!sp
|| !ddb_entry
)
1530 dev_info(&ha
->pdev
->dev
,
1531 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
1532 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1534 DEBUG2(printk(KERN_INFO
1535 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1536 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
1537 cmd
, jiffies
, cmd
->timeout_per_command
/ HZ
,
1538 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
1540 /* FIXME: wait for hba to go online */
1541 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
1542 if (stat
!= QLA_SUCCESS
) {
1543 dev_info(&ha
->pdev
->dev
, "DEVICE RESET FAILED. %d\n", stat
);
1544 goto eh_dev_reset_done
;
1548 ha
->marker_needed
= 1;
1551 * If we are coming down the EH path, wait for all commands to complete
1554 if (cmd
->device
->host
->shost_state
== SHOST_RECOVERY
) {
1555 if (qla4xxx_eh_wait_for_active_target_commands(ha
,
1558 dev_info(&ha
->pdev
->dev
,
1559 "DEVICE RESET FAILED - waiting for "
1561 goto eh_dev_reset_done
;
1565 dev_info(&ha
->pdev
->dev
,
1566 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1567 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
1578 * qla4xxx_eh_host_reset - kernel callback
1579 * @cmd: Pointer to Linux's SCSI command structure
1581 * This routine is invoked by the Linux kernel to perform fatal error
1582 * recovery on the specified adapter.
1584 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1586 int return_status
= FAILED
;
1587 struct scsi_qla_host
*ha
;
1589 ha
= (struct scsi_qla_host
*) cmd
->device
->host
->hostdata
;
1591 dev_info(&ha
->pdev
->dev
,
1592 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
,
1593 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1595 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
1596 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1597 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
1603 if (qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
) == QLA_SUCCESS
) {
1604 return_status
= SUCCESS
;
1607 dev_info(&ha
->pdev
->dev
, "HOST RESET %s.\n",
1608 return_status
== FAILED
? "FAILED" : "SUCCEDED");
1610 return return_status
;
1614 static struct pci_device_id qla4xxx_pci_tbl
[] = {
1616 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1617 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
1618 .subvendor
= PCI_ANY_ID
,
1619 .subdevice
= PCI_ANY_ID
,
1622 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1623 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
1624 .subvendor
= PCI_ANY_ID
,
1625 .subdevice
= PCI_ANY_ID
,
1628 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1629 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
1630 .subvendor
= PCI_ANY_ID
,
1631 .subdevice
= PCI_ANY_ID
,
1635 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
1637 static struct pci_driver qla4xxx_pci_driver
= {
1638 .name
= DRIVER_NAME
,
1639 .id_table
= qla4xxx_pci_tbl
,
1640 .probe
= qla4xxx_probe_adapter
,
1641 .remove
= qla4xxx_remove_adapter
,
1644 static int __init
qla4xxx_module_init(void)
1648 /* Allocate cache for SRBs. */
1649 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
1650 SLAB_HWCACHE_ALIGN
, NULL
);
1651 if (srb_cachep
== NULL
) {
1653 "%s: Unable to allocate SRB cache..."
1654 "Failing load!\n", DRIVER_NAME
);
1659 /* Derive version string. */
1660 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
1661 if (ql4xextended_error_logging
)
1662 strcat(qla4xxx_version_str
, "-debug");
1664 qla4xxx_scsi_transport
=
1665 iscsi_register_transport(&qla4xxx_iscsi_transport
);
1666 if (!qla4xxx_scsi_transport
){
1668 goto release_srb_cache
;
1671 ret
= pci_register_driver(&qla4xxx_pci_driver
);
1673 goto unregister_transport
;
1675 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
1678 unregister_transport
:
1679 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1681 kmem_cache_destroy(srb_cachep
);
1686 static void __exit
qla4xxx_module_exit(void)
1689 pci_unregister_driver(&qla4xxx_pci_driver
);
1690 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1691 kmem_cache_destroy(srb_cachep
);
1694 module_init(qla4xxx_module_init
);
1695 module_exit(qla4xxx_module_exit
);
1697 MODULE_AUTHOR("QLogic Corporation");
1698 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1699 MODULE_LICENSE("GPL");
1700 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);