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>
17 char qla4xxx_version_str
[40];
20 * SRB allocation cache
22 static struct kmem_cache
*srb_cachep
;
25 * Module parameter information and variables
27 int ql4xdiscoverywait
= 60;
28 module_param(ql4xdiscoverywait
, int, S_IRUGO
| S_IRUSR
);
29 MODULE_PARM_DESC(ql4xdiscoverywait
, "Discovery wait time");
30 int ql4xdontresethba
= 0;
31 module_param(ql4xdontresethba
, int, S_IRUGO
| S_IRUSR
);
32 MODULE_PARM_DESC(ql4xdontresethba
,
33 "Dont reset the HBA when the driver gets 0x8002 AEN "
34 " default it will reset hba :0"
35 " set to 1 to avoid resetting HBA");
37 int ql4xextended_error_logging
= 0; /* 0 = off, 1 = log errors */
38 module_param(ql4xextended_error_logging
, int, S_IRUGO
| S_IRUSR
);
39 MODULE_PARM_DESC(ql4xextended_error_logging
,
40 "Option to enable extended error logging, "
41 "Default is 0 - no logging, 1 - debug logging");
43 int ql4_mod_unload
= 0;
46 * SCSI host template entry points
49 void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
52 * iSCSI template entry points
54 static int qla4xxx_tgt_dscvr(enum iscsi_tgt_dscvr type
, uint32_t host_no
,
55 uint32_t enable
, struct sockaddr
*dst_addr
);
56 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
57 enum iscsi_param param
, char *buf
);
58 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
59 enum iscsi_param param
, char *buf
);
60 static void qla4xxx_conn_stop(struct iscsi_cls_conn
*conn
, int flag
);
61 static int qla4xxx_conn_start(struct iscsi_cls_conn
*conn
);
62 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
);
65 * SCSI host template entry points
67 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
68 void (*done
) (struct scsi_cmnd
*));
69 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
70 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
71 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
72 static int qla4xxx_slave_configure(struct scsi_device
*device
);
73 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
75 static struct scsi_host_template qla4xxx_driver_template
= {
76 .module
= THIS_MODULE
,
78 .proc_name
= DRIVER_NAME
,
79 .queuecommand
= qla4xxx_queuecommand
,
81 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
82 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
84 .slave_configure
= qla4xxx_slave_configure
,
85 .slave_alloc
= qla4xxx_slave_alloc
,
86 .slave_destroy
= qla4xxx_slave_destroy
,
90 .use_clustering
= ENABLE_CLUSTERING
,
91 .sg_tablesize
= SG_ALL
,
93 .max_sectors
= 0xFFFF,
96 static struct iscsi_transport qla4xxx_iscsi_transport
= {
99 .param_mask
= ISCSI_CONN_PORT
|
103 .sessiondata_size
= sizeof(struct ddb_entry
),
104 .host_template
= &qla4xxx_driver_template
,
106 .tgt_dscvr
= qla4xxx_tgt_dscvr
,
107 .get_conn_param
= qla4xxx_conn_get_param
,
108 .get_session_param
= qla4xxx_sess_get_param
,
109 .start_conn
= qla4xxx_conn_start
,
110 .stop_conn
= qla4xxx_conn_stop
,
111 .session_recovery_timedout
= qla4xxx_recovery_timedout
,
114 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
116 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
)
118 struct ddb_entry
*ddb_entry
= session
->dd_data
;
119 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
121 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count of (%d) "
122 "secs exhausted, marking device DEAD.\n", ha
->host_no
,
123 __func__
, ddb_entry
->fw_ddb_index
,
124 ha
->port_down_retry_count
));
126 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
128 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
129 "0x%lx\n", ha
->host_no
, __func__
, ha
->dpc_flags
));
130 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
133 static int qla4xxx_conn_start(struct iscsi_cls_conn
*conn
)
135 struct iscsi_cls_session
*session
;
136 struct ddb_entry
*ddb_entry
;
138 session
= iscsi_dev_to_session(conn
->dev
.parent
);
139 ddb_entry
= session
->dd_data
;
141 DEBUG2(printk("scsi%ld: %s: index [%d] starting conn\n",
142 ddb_entry
->ha
->host_no
, __func__
,
143 ddb_entry
->fw_ddb_index
));
144 iscsi_unblock_session(session
);
148 static void qla4xxx_conn_stop(struct iscsi_cls_conn
*conn
, int flag
)
150 struct iscsi_cls_session
*session
;
151 struct ddb_entry
*ddb_entry
;
153 session
= iscsi_dev_to_session(conn
->dev
.parent
);
154 ddb_entry
= session
->dd_data
;
156 DEBUG2(printk("scsi%ld: %s: index [%d] stopping conn\n",
157 ddb_entry
->ha
->host_no
, __func__
,
158 ddb_entry
->fw_ddb_index
));
159 if (flag
== STOP_CONN_RECOVER
)
160 iscsi_block_session(session
);
162 printk(KERN_ERR
"iscsi: invalid stop flag %d\n", flag
);
165 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
166 enum iscsi_param param
, char *buf
)
168 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
172 case ISCSI_PARAM_TARGET_NAME
:
173 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
174 ddb_entry
->iscsi_name
);
176 case ISCSI_PARAM_TPGT
:
177 len
= sprintf(buf
, "%u\n", ddb_entry
->tpgt
);
186 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
187 enum iscsi_param param
, char *buf
)
189 struct iscsi_cls_session
*session
;
190 struct ddb_entry
*ddb_entry
;
193 session
= iscsi_dev_to_session(conn
->dev
.parent
);
194 ddb_entry
= session
->dd_data
;
197 case ISCSI_PARAM_CONN_PORT
:
198 len
= sprintf(buf
, "%hu\n", ddb_entry
->port
);
200 case ISCSI_PARAM_CONN_ADDRESS
:
201 /* TODO: what are the ipv6 bits */
202 len
= sprintf(buf
, "%u.%u.%u.%u\n",
203 NIPQUAD(ddb_entry
->ip_addr
));
212 static int qla4xxx_tgt_dscvr(enum iscsi_tgt_dscvr type
, uint32_t host_no
,
213 uint32_t enable
, struct sockaddr
*dst_addr
)
215 struct scsi_qla_host
*ha
;
216 struct Scsi_Host
*shost
;
217 struct sockaddr_in
*addr
;
218 struct sockaddr_in6
*addr6
;
221 shost
= scsi_host_lookup(host_no
);
223 printk(KERN_ERR
"Could not find host no %u\n", host_no
);
227 ha
= (struct scsi_qla_host
*) shost
->hostdata
;
230 case ISCSI_TGT_DSCVR_SEND_TARGETS
:
231 if (dst_addr
->sa_family
== AF_INET
) {
232 addr
= (struct sockaddr_in
*)dst_addr
;
233 if (qla4xxx_send_tgts(ha
, (char *)&addr
->sin_addr
,
234 addr
->sin_port
) != QLA_SUCCESS
)
236 } else if (dst_addr
->sa_family
== AF_INET6
) {
238 * TODO: fix qla4xxx_send_tgts
240 addr6
= (struct sockaddr_in6
*)dst_addr
;
241 if (qla4xxx_send_tgts(ha
, (char *)&addr6
->sin6_addr
,
242 addr6
->sin6_port
) != QLA_SUCCESS
)
251 scsi_host_put(shost
);
255 void qla4xxx_destroy_sess(struct ddb_entry
*ddb_entry
)
257 if (!ddb_entry
->sess
)
260 if (ddb_entry
->conn
) {
261 iscsi_if_destroy_session_done(ddb_entry
->conn
);
262 iscsi_destroy_conn(ddb_entry
->conn
);
263 iscsi_remove_session(ddb_entry
->sess
);
265 iscsi_free_session(ddb_entry
->sess
);
268 int qla4xxx_add_sess(struct ddb_entry
*ddb_entry
)
272 err
= iscsi_add_session(ddb_entry
->sess
, ddb_entry
->fw_ddb_index
);
274 DEBUG2(printk(KERN_ERR
"Could not add session.\n"));
278 ddb_entry
->conn
= iscsi_create_conn(ddb_entry
->sess
, 0);
279 if (!ddb_entry
->conn
) {
280 iscsi_remove_session(ddb_entry
->sess
);
281 DEBUG2(printk(KERN_ERR
"Could not add connection.\n"));
285 ddb_entry
->sess
->recovery_tmo
= ddb_entry
->ha
->port_down_retry_count
;
286 iscsi_if_create_session_done(ddb_entry
->conn
);
290 struct ddb_entry
*qla4xxx_alloc_sess(struct scsi_qla_host
*ha
)
292 struct ddb_entry
*ddb_entry
;
293 struct iscsi_cls_session
*sess
;
295 sess
= iscsi_alloc_session(ha
->host
, &qla4xxx_iscsi_transport
);
299 ddb_entry
= sess
->dd_data
;
300 memset(ddb_entry
, 0, sizeof(*ddb_entry
));
302 ddb_entry
->sess
= sess
;
310 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
311 unsigned long interval
)
313 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
314 __func__
, ha
->host
->host_no
));
315 init_timer(&ha
->timer
);
316 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
317 ha
->timer
.data
= (unsigned long)ha
;
318 ha
->timer
.function
= (void (*)(unsigned long))func
;
319 add_timer(&ha
->timer
);
320 ha
->timer_active
= 1;
323 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
325 del_timer_sync(&ha
->timer
);
326 ha
->timer_active
= 0;
330 * qla4xxx_mark_device_missing - mark a device as missing.
331 * @ha: Pointer to host adapter structure.
332 * @ddb_entry: Pointer to device database entry
334 * This routine marks a device missing and resets the relogin retry count.
336 void qla4xxx_mark_device_missing(struct scsi_qla_host
*ha
,
337 struct ddb_entry
*ddb_entry
)
339 atomic_set(&ddb_entry
->state
, DDB_STATE_MISSING
);
340 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
341 ha
->host_no
, ddb_entry
->bus
, ddb_entry
->target
,
342 ddb_entry
->fw_ddb_index
));
343 iscsi_conn_error(ddb_entry
->conn
, ISCSI_ERR_CONN_FAILED
);
346 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
347 struct ddb_entry
*ddb_entry
,
348 struct scsi_cmnd
*cmd
,
349 void (*done
)(struct scsi_cmnd
*))
353 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
357 atomic_set(&srb
->ref_count
, 1);
359 srb
->ddb
= ddb_entry
;
362 cmd
->SCp
.ptr
= (void *)srb
;
363 cmd
->scsi_done
= done
;
368 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
370 struct scsi_cmnd
*cmd
= srb
->cmd
;
372 if (srb
->flags
& SRB_DMA_VALID
) {
374 pci_unmap_sg(ha
->pdev
, cmd
->request_buffer
,
375 cmd
->use_sg
, cmd
->sc_data_direction
);
376 } else if (cmd
->request_bufflen
) {
377 pci_unmap_single(ha
->pdev
, srb
->dma_handle
,
378 cmd
->request_bufflen
,
379 cmd
->sc_data_direction
);
381 srb
->flags
&= ~SRB_DMA_VALID
;
386 void qla4xxx_srb_compl(struct scsi_qla_host
*ha
, struct srb
*srb
)
388 struct scsi_cmnd
*cmd
= srb
->cmd
;
390 qla4xxx_srb_free_dma(ha
, srb
);
392 mempool_free(srb
, ha
->srb_mempool
);
398 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
399 * @cmd: Pointer to Linux's SCSI command structure
400 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
401 * that the command has been processed.
404 * This routine is invoked by Linux to send a SCSI command to the driver.
405 * The mid-level driver tries to ensure that queuecommand never gets
406 * invoked concurrently with itself or the interrupt handler (although
407 * the interrupt handler may call this routine as part of request-
408 * completion handling). Unfortunely, it sometimes calls the scheduler
409 * in interrupt context which is a big NO! NO!.
411 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
412 void (*done
)(struct scsi_cmnd
*))
414 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
415 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
419 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
420 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
) {
421 cmd
->result
= DID_NO_CONNECT
<< 16;
422 goto qc_fail_command
;
427 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
))
430 spin_unlock_irq(ha
->host
->host_lock
);
432 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
, done
);
434 goto qc_host_busy_lock
;
436 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
437 if (rval
!= QLA_SUCCESS
)
438 goto qc_host_busy_free_sp
;
440 spin_lock_irq(ha
->host
->host_lock
);
443 qc_host_busy_free_sp
:
444 qla4xxx_srb_free_dma(ha
, srb
);
445 mempool_free(srb
, ha
->srb_mempool
);
448 spin_lock_irq(ha
->host
->host_lock
);
451 return SCSI_MLQUEUE_HOST_BUSY
;
460 * qla4xxx_mem_free - frees memory allocated to adapter
461 * @ha: Pointer to host adapter structure.
463 * Frees memory previously allocated by qla4xxx_mem_alloc
465 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
468 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
474 ha
->request_ring
= NULL
;
476 ha
->response_ring
= NULL
;
477 ha
->response_dma
= 0;
478 ha
->shadow_regs
= NULL
;
479 ha
->shadow_regs_dma
= 0;
483 mempool_destroy(ha
->srb_mempool
);
485 ha
->srb_mempool
= NULL
;
487 /* release io space registers */
490 pci_release_regions(ha
->pdev
);
494 * qla4xxx_mem_alloc - allocates memory for use by adapter.
495 * @ha: Pointer to host adapter structure
497 * Allocates DMA memory for request and response queues. Also allocates memory
500 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
504 /* Allocate contiguous block of DMA memory for queues. */
505 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
506 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
507 sizeof(struct shadow_regs
) +
509 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
510 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
511 &ha
->queues_dma
, GFP_KERNEL
);
512 if (ha
->queues
== NULL
) {
513 dev_warn(&ha
->pdev
->dev
,
514 "Memory Allocation failed - queues.\n");
516 goto mem_alloc_error_exit
;
518 memset(ha
->queues
, 0, ha
->queues_len
);
521 * As per RISC alignment requirements -- the bus-address must be a
522 * multiple of the request-ring size (in bytes).
525 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
526 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
527 (MEM_ALIGN_VALUE
- 1));
529 /* Update request and response queue pointers. */
530 ha
->request_dma
= ha
->queues_dma
+ align
;
531 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
532 ha
->response_dma
= ha
->queues_dma
+ align
+
533 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
534 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
535 (REQUEST_QUEUE_DEPTH
*
537 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
538 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
539 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
540 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
541 (REQUEST_QUEUE_DEPTH
*
543 (RESPONSE_QUEUE_DEPTH
*
546 /* Allocate memory for srb pool. */
547 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
548 mempool_free_slab
, srb_cachep
);
549 if (ha
->srb_mempool
== NULL
) {
550 dev_warn(&ha
->pdev
->dev
,
551 "Memory Allocation failed - SRB Pool.\n");
553 goto mem_alloc_error_exit
;
558 mem_alloc_error_exit
:
559 qla4xxx_mem_free(ha
);
564 * qla4xxx_timer - checks every second for work to do.
565 * @ha: Pointer to host adapter structure.
567 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
569 struct ddb_entry
*ddb_entry
, *dtemp
;
572 /* Search for relogin's to time-out and port down retry. */
573 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
574 /* Count down time between sending relogins */
575 if (adapter_up(ha
) &&
576 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
577 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
578 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
580 if (atomic_read(&ddb_entry
->retry_relogin_timer
)
582 atomic_set(&ddb_entry
->
585 set_bit(DPC_RELOGIN_DEVICE
,
587 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
588 DEBUG2(printk("scsi%ld: %s: index [%d]"
590 ha
->host_no
, __func__
,
591 ddb_entry
->fw_ddb_index
));
593 atomic_dec(&ddb_entry
->
594 retry_relogin_timer
);
598 /* Wait for relogin to timeout */
599 if (atomic_read(&ddb_entry
->relogin_timer
) &&
600 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
602 * If the relogin times out and the device is
603 * still NOT ONLINE then try and relogin again.
605 if (atomic_read(&ddb_entry
->state
) !=
607 ddb_entry
->fw_ddb_device_state
==
608 DDB_DS_SESSION_FAILED
) {
609 /* Reset retry relogin timer */
610 atomic_inc(&ddb_entry
->relogin_retry_count
);
611 DEBUG2(printk("scsi%ld: index[%d] relogin"
612 " timed out-retrying"
615 ddb_entry
->fw_ddb_index
,
616 atomic_read(&ddb_entry
->
617 relogin_retry_count
))
620 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
621 "initate relogin after"
623 ha
->host_no
, ddb_entry
->bus
,
625 ddb_entry
->fw_ddb_index
,
626 ddb_entry
->default_time2wait
+ 4)
629 atomic_set(&ddb_entry
->retry_relogin_timer
,
630 ddb_entry
->default_time2wait
+ 4);
635 /* Check for heartbeat interval. */
636 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
637 ha
->heartbeat_interval
!= 0) {
638 ha
->seconds_since_last_heartbeat
++;
639 if (ha
->seconds_since_last_heartbeat
>
640 ha
->heartbeat_interval
+ 2)
641 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
645 /* Wakeup the dpc routine for this adapter, if needed. */
647 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
648 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
649 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
650 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
651 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
652 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
653 test_bit(DPC_AEN
, &ha
->dpc_flags
)) &&
655 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
656 " - dpc flags = 0x%lx\n",
657 ha
->host_no
, __func__
, ha
->dpc_flags
));
658 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
661 /* Reschedule timer thread to call us back in one second */
662 mod_timer(&ha
->timer
, jiffies
+ HZ
);
664 DEBUG2(ha
->seconds_since_last_intr
++);
668 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
669 * @ha: Pointer to host adapter structure.
671 * This routine stalls the driver until all outstanding commands are returned.
672 * Caller must release the Hardware Lock prior to calling this routine.
674 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
677 int stat
= QLA_SUCCESS
;
679 struct scsi_cmnd
*cmd
;
680 int wait_cnt
= WAIT_CMD_TOV
; /*
681 * Initialized for 30 seconds as we
682 * expect all commands to retuned
687 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
688 /* Find a command that hasn't completed. */
689 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
690 cmd
= scsi_host_find_tag(ha
->host
, index
);
694 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
696 /* If No Commands are pending, wait is complete */
697 if (index
== ha
->host
->can_queue
) {
701 /* If we timed out on waiting for commands to come back
710 } /* End of While (wait_cnt) */
715 static void qla4xxx_hw_reset(struct scsi_qla_host
*ha
)
717 uint32_t ctrl_status
;
718 unsigned long flags
= 0;
720 DEBUG2(printk(KERN_ERR
"scsi%ld: %s\n", ha
->host_no
, __func__
));
722 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
725 * If the SCSI Reset Interrupt bit is set, clear it.
726 * Otherwise, the Soft Reset won't work.
728 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
729 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
730 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
732 /* Issue Soft Reset */
733 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
734 readl(&ha
->reg
->ctrl_status
);
736 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
740 * qla4xxx_soft_reset - performs soft reset.
741 * @ha: Pointer to host adapter structure.
743 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
745 uint32_t max_wait_time
;
746 unsigned long flags
= 0;
747 int status
= QLA_ERROR
;
748 uint32_t ctrl_status
;
750 qla4xxx_hw_reset(ha
);
752 /* Wait until the Network Reset Intr bit is cleared */
753 max_wait_time
= RESET_INTR_TOV
;
755 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
756 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
757 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
759 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
763 } while ((--max_wait_time
));
765 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
766 DEBUG2(printk(KERN_WARNING
767 "scsi%ld: Network Reset Intr not cleared by "
768 "Network function, clearing it now!\n",
770 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
771 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
772 readl(&ha
->reg
->ctrl_status
);
773 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
776 /* Wait until the firmware tells us the Soft Reset is done */
777 max_wait_time
= SOFT_RESET_TOV
;
779 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
780 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
781 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
783 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
784 status
= QLA_SUCCESS
;
789 } while ((--max_wait_time
));
792 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
793 * after the soft reset has taken place.
795 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
796 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
797 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
798 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
799 readl(&ha
->reg
->ctrl_status
);
801 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
803 /* If soft reset fails then most probably the bios on other
804 * function is also enabled.
805 * Since the initialization is sequential the other fn
806 * wont be able to acknowledge the soft reset.
807 * Issue a force soft reset to workaround this scenario.
809 if (max_wait_time
== 0) {
810 /* Issue Force Soft Reset */
811 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
812 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
813 readl(&ha
->reg
->ctrl_status
);
814 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
815 /* Wait until the firmware tells us the Soft Reset is done */
816 max_wait_time
= SOFT_RESET_TOV
;
818 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
819 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
820 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
822 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
823 status
= QLA_SUCCESS
;
828 } while ((--max_wait_time
));
835 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
836 * @ha: Pointer to host adapter structure.
838 * This routine is called just prior to a HARD RESET to return all
839 * outstanding commands back to the Operating System.
840 * Caller should make sure that the following locks are released
841 * before this calling routine: Hardware lock, and io_request_lock.
843 static void qla4xxx_flush_active_srbs(struct scsi_qla_host
*ha
)
849 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
850 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
851 srb
= qla4xxx_del_from_active_array(ha
, i
);
853 srb
->cmd
->result
= DID_RESET
<< 16;
854 qla4xxx_srb_compl(ha
, srb
);
857 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
862 * qla4xxx_recover_adapter - recovers adapter after a fatal error
863 * @ha: Pointer to host adapter structure.
864 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
865 * after adapter recovery has completed.
866 * 0=preserve ddb list, 1=destroy and rebuild ddb list
868 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
,
869 uint8_t renew_ddb_list
)
873 /* Stall incoming I/O until we are done */
874 clear_bit(AF_ONLINE
, &ha
->flags
);
875 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha
->host_no
,
878 /* Wait for outstanding commands to complete.
879 * Stalls the driver for max 30 secs
881 status
= qla4xxx_cmd_wait(ha
);
883 qla4xxx_disable_intrs(ha
);
885 /* Flush any pending ddb changed AENs */
886 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
888 /* Reset the firmware. If successful, function
889 * returns with ISP interrupts enabled.
891 if (status
== QLA_SUCCESS
) {
892 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
893 ha
->host_no
, __func__
));
894 qla4xxx_flush_active_srbs(ha
);
895 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
896 status
= qla4xxx_soft_reset(ha
);
901 /* Flush any pending ddb changed AENs */
902 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
904 /* Re-initialize firmware. If successful, function returns
905 * with ISP interrupts enabled */
906 if (status
== QLA_SUCCESS
) {
907 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
908 ha
->host_no
, __func__
));
910 /* If successful, AF_ONLINE flag set in
911 * qla4xxx_initialize_adapter */
912 status
= qla4xxx_initialize_adapter(ha
, renew_ddb_list
);
915 /* Failed adapter initialization?
916 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
917 if ((test_bit(AF_ONLINE
, &ha
->flags
) == 0) &&
918 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))) {
919 /* Adapter initialization failed, see if we can retry
920 * resetting the ha */
921 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
922 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
923 DEBUG2(printk("scsi%ld: recover adapter - retrying "
924 "(%d) more times\n", ha
->host_no
,
925 ha
->retry_reset_ha_cnt
));
926 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
929 if (ha
->retry_reset_ha_cnt
> 0) {
930 /* Schedule another Reset HA--DPC will retry */
931 ha
->retry_reset_ha_cnt
--;
932 DEBUG2(printk("scsi%ld: recover adapter - "
933 "retry remaining %d\n",
935 ha
->retry_reset_ha_cnt
));
939 if (ha
->retry_reset_ha_cnt
== 0) {
940 /* Recover adapter retries have been exhausted.
942 DEBUG2(printk("scsi%ld: recover adapter "
943 "failed - board disabled\n",
945 qla4xxx_flush_active_srbs(ha
);
946 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
947 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
948 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
,
954 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
955 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
);
956 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
959 ha
->adapter_error_count
++;
961 if (status
== QLA_SUCCESS
)
962 qla4xxx_enable_intrs(ha
);
964 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha
->host_no
));
969 * qla4xxx_do_dpc - dpc routine
970 * @data: in our case pointer to adapter structure
972 * This routine is a task that is schedule by the interrupt handler
973 * to perform the background processing for interrupts. We put it
974 * on a task queue that is consumed whenever the scheduler runs; that's
975 * so you can do anything (i.e. put the process to sleep etc). In fact,
976 * the mid-level tries to sleep when it reaches the driver threshold
977 * "host->can_queue". This can cause a panic if we were in our interrupt code.
979 static void qla4xxx_do_dpc(struct work_struct
*work
)
981 struct scsi_qla_host
*ha
=
982 container_of(work
, struct scsi_qla_host
, dpc_work
);
983 struct ddb_entry
*ddb_entry
, *dtemp
;
984 int status
= QLA_ERROR
;
986 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
987 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
988 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
,
989 readw(&ha
->reg
->ctrl_status
)));
991 /* Initialization not yet finished. Don't do anything yet. */
992 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
995 if (adapter_up(ha
) ||
996 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
997 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
998 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
)) {
999 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
1000 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
1001 qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
);
1003 if (test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
1004 uint8_t wait_time
= RESET_INTR_TOV
;
1006 while ((readw(&ha
->reg
->ctrl_status
) &
1007 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
1008 if (--wait_time
== 0)
1013 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1014 "bit not cleared-- resetting\n",
1015 ha
->host_no
, __func__
));
1016 qla4xxx_flush_active_srbs(ha
);
1017 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
) {
1018 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
1019 status
= qla4xxx_initialize_adapter(ha
,
1022 clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
);
1023 if (status
== QLA_SUCCESS
)
1024 qla4xxx_enable_intrs(ha
);
1028 /* ---- process AEN? --- */
1029 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1030 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1032 /* ---- Get DHCP IP Address? --- */
1033 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
1034 qla4xxx_get_dhcp_ip_address(ha
);
1036 /* ---- relogin device? --- */
1037 if (adapter_up(ha
) &&
1038 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
1039 list_for_each_entry_safe(ddb_entry
, dtemp
,
1040 &ha
->ddb_list
, list
) {
1041 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1042 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
1043 qla4xxx_relogin_device(ha
, ddb_entry
);
1046 * If mbx cmd times out there is no point
1047 * in continuing further.
1048 * With large no of targets this can hang
1051 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1052 printk(KERN_WARNING
"scsi%ld: %s: "
1053 "need to reset hba\n",
1054 ha
->host_no
, __func__
);
1062 * qla4xxx_free_adapter - release the adapter
1063 * @ha: pointer to adapter structure
1065 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
1068 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
)) {
1069 /* Turn-off interrupts on the card. */
1070 qla4xxx_disable_intrs(ha
);
1073 /* Kill the kernel thread for this host */
1075 destroy_workqueue(ha
->dpc_thread
);
1077 /* Issue Soft Reset to put firmware in unknown state */
1078 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
1079 qla4xxx_hw_reset(ha
);
1081 /* Remove timer thread, if present */
1082 if (ha
->timer_active
)
1083 qla4xxx_stop_timer(ha
);
1085 /* free extra memory */
1086 qla4xxx_mem_free(ha
);
1088 /* Detach interrupts */
1089 if (test_and_clear_bit(AF_IRQ_ATTACHED
, &ha
->flags
))
1090 free_irq(ha
->pdev
->irq
, ha
);
1092 pci_disable_device(ha
->pdev
);
1097 * qla4xxx_iospace_config - maps registers
1098 * @ha: pointer to adapter structure
1100 * This routines maps HBA's registers from the pci address space
1101 * into the kernel virtual address space for memory mapped i/o.
1103 static int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
1105 unsigned long pio
, pio_len
, pio_flags
;
1106 unsigned long mmio
, mmio_len
, mmio_flags
;
1108 pio
= pci_resource_start(ha
->pdev
, 0);
1109 pio_len
= pci_resource_len(ha
->pdev
, 0);
1110 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1111 if (pio_flags
& IORESOURCE_IO
) {
1112 if (pio_len
< MIN_IOBASE_LEN
) {
1113 dev_warn(&ha
->pdev
->dev
,
1114 "Invalid PCI I/O region size\n");
1118 dev_warn(&ha
->pdev
->dev
, "region #0 not a PIO resource\n");
1122 /* Use MMIO operations for all accesses. */
1123 mmio
= pci_resource_start(ha
->pdev
, 1);
1124 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1125 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1127 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1128 dev_err(&ha
->pdev
->dev
,
1129 "region #0 not an MMIO resource, aborting\n");
1131 goto iospace_error_exit
;
1133 if (mmio_len
< MIN_IOBASE_LEN
) {
1134 dev_err(&ha
->pdev
->dev
,
1135 "Invalid PCI mem region size, aborting\n");
1136 goto iospace_error_exit
;
1139 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
1140 dev_warn(&ha
->pdev
->dev
,
1141 "Failed to reserve PIO/MMIO regions\n");
1143 goto iospace_error_exit
;
1146 ha
->pio_address
= pio
;
1147 ha
->pio_length
= pio_len
;
1148 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
1150 dev_err(&ha
->pdev
->dev
,
1151 "cannot remap MMIO, aborting\n");
1153 goto iospace_error_exit
;
1163 * qla4xxx_probe_adapter - callback function to probe HBA
1164 * @pdev: pointer to pci_dev structure
1165 * @pci_device_id: pointer to pci_device entry
1167 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1168 * It returns zero if successful. It also initializes all data necessary for
1171 static int __devinit
qla4xxx_probe_adapter(struct pci_dev
*pdev
,
1172 const struct pci_device_id
*ent
)
1174 int ret
= -ENODEV
, status
;
1175 struct Scsi_Host
*host
;
1176 struct scsi_qla_host
*ha
;
1177 struct ddb_entry
*ddb_entry
, *ddbtemp
;
1178 uint8_t init_retry_count
= 0;
1181 if (pci_enable_device(pdev
))
1184 host
= scsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
));
1187 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1188 goto probe_disable_device
;
1191 /* Clear our data area */
1192 ha
= (struct scsi_qla_host
*) host
->hostdata
;
1193 memset(ha
, 0, sizeof(*ha
));
1195 /* Save the information from PCI BIOS. */
1198 ha
->host_no
= host
->host_no
;
1200 /* Configure PCI I/O space. */
1201 ret
= qla4xxx_iospace_config(ha
);
1205 dev_info(&ha
->pdev
->dev
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1206 pdev
->device
, pdev
->irq
, ha
->reg
);
1208 qla4xxx_config_dma_addressing(ha
);
1210 /* Initialize lists and spinlocks. */
1211 INIT_LIST_HEAD(&ha
->ddb_list
);
1212 INIT_LIST_HEAD(&ha
->free_srb_q
);
1214 mutex_init(&ha
->mbox_sem
);
1216 spin_lock_init(&ha
->hardware_lock
);
1218 /* Allocate dma buffers */
1219 if (qla4xxx_mem_alloc(ha
)) {
1220 dev_warn(&ha
->pdev
->dev
,
1221 "[ERROR] Failed to allocate memory for adapter\n");
1228 * Initialize the Host adapter request/response queues and
1230 * NOTE: interrupts enabled upon successful completion
1232 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1233 while (status
== QLA_ERROR
&& init_retry_count
++ < MAX_INIT_RETRIES
) {
1234 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1235 "(%d)\n", __func__
, init_retry_count
));
1236 qla4xxx_soft_reset(ha
);
1237 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1239 if (status
== QLA_ERROR
) {
1240 dev_warn(&ha
->pdev
->dev
, "Failed to initialize adapter\n");
1246 host
->cmd_per_lun
= 3;
1247 host
->max_channel
= 0;
1248 host
->max_lun
= MAX_LUNS
- 1;
1249 host
->max_id
= MAX_TARGETS
;
1250 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
1251 host
->can_queue
= MAX_SRBS
;
1252 host
->transportt
= qla4xxx_scsi_transport
;
1254 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
1256 dev_warn(&ha
->pdev
->dev
, "scsi_init_shared_tag_map failed");
1260 /* Startup the kernel thread for this host adapter. */
1261 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1262 "qla4xxx_dpc\n", __func__
));
1263 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
1264 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
1265 if (!ha
->dpc_thread
) {
1266 dev_warn(&ha
->pdev
->dev
, "Unable to start DPC thread!\n");
1270 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
1272 ret
= request_irq(pdev
->irq
, qla4xxx_intr_handler
,
1273 SA_INTERRUPT
|SA_SHIRQ
, "qla4xxx", ha
);
1275 dev_warn(&ha
->pdev
->dev
, "Failed to reserve interrupt %d"
1276 " already in use.\n", pdev
->irq
);
1279 set_bit(AF_IRQ_ATTACHED
, &ha
->flags
);
1280 host
->irq
= pdev
->irq
;
1281 DEBUG(printk("scsi%d: irq %d attached\n", ha
->host_no
, ha
->pdev
->irq
));
1283 qla4xxx_enable_intrs(ha
);
1285 /* Start timer thread. */
1286 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
1288 set_bit(AF_INIT_DONE
, &ha
->flags
);
1290 pci_set_drvdata(pdev
, ha
);
1292 ret
= scsi_add_host(host
, &pdev
->dev
);
1296 /* Update transport device information for all devices. */
1297 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
1298 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
)
1299 if (qla4xxx_add_sess(ddb_entry
))
1304 " QLogic iSCSI HBA Driver version: %s\n"
1305 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1306 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
1307 ha
->host_no
, ha
->firmware_version
[0], ha
->firmware_version
[1],
1308 ha
->patch_number
, ha
->build_number
);
1313 qla4xxx_free_ddb_list(ha
);
1314 scsi_remove_host(host
);
1317 qla4xxx_free_adapter(ha
);
1318 scsi_host_put(ha
->host
);
1320 probe_disable_device
:
1321 pci_disable_device(pdev
);
1327 * qla4xxx_remove_adapter - calback function to remove adapter.
1328 * @pci_dev: PCI device pointer
1330 static void __devexit
qla4xxx_remove_adapter(struct pci_dev
*pdev
)
1332 struct scsi_qla_host
*ha
;
1334 ha
= pci_get_drvdata(pdev
);
1336 /* remove devs from iscsi_sessions to scsi_devices */
1337 qla4xxx_free_ddb_list(ha
);
1339 scsi_remove_host(ha
->host
);
1341 qla4xxx_free_adapter(ha
);
1343 scsi_host_put(ha
->host
);
1345 pci_set_drvdata(pdev
, NULL
);
1349 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1352 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1353 * supported addressing method.
1355 void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
1359 /* Update our PCI device dma_mask for full 64 bit mask */
1360 if (pci_set_dma_mask(ha
->pdev
, DMA_64BIT_MASK
) == 0) {
1361 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1362 dev_dbg(&ha
->pdev
->dev
,
1363 "Failed to set 64 bit PCI consistent mask; "
1365 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
1369 retval
= pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1372 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
1374 struct iscsi_cls_session
*sess
= starget_to_session(sdev
->sdev_target
);
1375 struct ddb_entry
*ddb
= sess
->dd_data
;
1377 sdev
->hostdata
= ddb
;
1378 sdev
->tagged_supported
= 1;
1379 scsi_activate_tcq(sdev
, sdev
->host
->can_queue
);
1383 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
1385 sdev
->tagged_supported
= 1;
1389 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
1391 scsi_deactivate_tcq(sdev
, 1);
1395 * qla4xxx_del_from_active_array - returns an active srb
1396 * @ha: Pointer to host adapter structure.
1397 * @index: index into to the active_array
1399 * This routine removes and returns the srb at the specified index
1401 struct srb
* qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
, uint32_t index
)
1403 struct srb
*srb
= NULL
;
1404 struct scsi_cmnd
*cmd
;
1406 if (!(cmd
= scsi_host_find_tag(ha
->host
, index
)))
1409 if (!(srb
= (struct srb
*)cmd
->host_scribble
))
1412 /* update counters */
1413 if (srb
->flags
& SRB_DMA_VALID
) {
1414 ha
->req_q_count
+= srb
->iocb_cnt
;
1415 ha
->iocb_cnt
-= srb
->iocb_cnt
;
1417 srb
->cmd
->host_scribble
= NULL
;
1423 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1424 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1425 * @cmd: Scsi Command to wait on.
1427 * This routine waits for the command to be returned by the Firmware
1428 * for some max time.
1430 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
1431 struct scsi_cmnd
*cmd
)
1435 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
1438 /* Checking to see if its returned to OS */
1439 rp
= (struct srb
*) cmd
->SCp
.ptr
;
1446 } while (max_wait_time
--);
1452 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1453 * @ha: Pointer to host adapter structure
1455 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
1457 unsigned long wait_online
;
1459 wait_online
= jiffies
+ (30 * HZ
);
1460 while (time_before(jiffies
, wait_online
)) {
1464 else if (ha
->retry_reset_ha_cnt
== 0)
1474 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1475 * @ha: pointer to to HBA
1479 * This function waits for all outstanding commands to a lun to complete. It
1480 * returns 0 if all pending commands are returned and 1 otherwise.
1482 static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host
*ha
,
1487 struct scsi_cmnd
*cmd
;
1490 * Waiting for all commands for the designated target in the active
1493 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
1494 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
1495 if (cmd
&& cmd
->device
->id
== t
&& cmd
->device
->lun
== l
) {
1496 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
1506 * qla4xxx_eh_device_reset - callback for target reset.
1507 * @cmd: Pointer to Linux's SCSI command structure
1509 * This routine is called by the Linux OS to reset all luns on the
1512 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1514 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
1515 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
1517 int ret
= FAILED
, stat
;
1519 sp
= (struct srb
*) cmd
->SCp
.ptr
;
1520 if (!sp
|| !ddb_entry
)
1523 dev_info(&ha
->pdev
->dev
,
1524 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
1525 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1527 DEBUG2(printk(KERN_INFO
1528 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1529 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
1530 cmd
, jiffies
, cmd
->timeout_per_command
/ HZ
,
1531 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
1533 /* FIXME: wait for hba to go online */
1534 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
1535 if (stat
!= QLA_SUCCESS
) {
1536 dev_info(&ha
->pdev
->dev
, "DEVICE RESET FAILED. %d\n", stat
);
1537 goto eh_dev_reset_done
;
1541 ha
->marker_needed
= 1;
1544 * If we are coming down the EH path, wait for all commands to complete
1547 if (cmd
->device
->host
->shost_state
== SHOST_RECOVERY
) {
1548 if (qla4xxx_eh_wait_for_active_target_commands(ha
,
1551 dev_info(&ha
->pdev
->dev
,
1552 "DEVICE RESET FAILED - waiting for "
1554 goto eh_dev_reset_done
;
1558 dev_info(&ha
->pdev
->dev
,
1559 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1560 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
1571 * qla4xxx_eh_host_reset - kernel callback
1572 * @cmd: Pointer to Linux's SCSI command structure
1574 * This routine is invoked by the Linux kernel to perform fatal error
1575 * recovery on the specified adapter.
1577 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1579 int return_status
= FAILED
;
1580 struct scsi_qla_host
*ha
;
1582 ha
= (struct scsi_qla_host
*) cmd
->device
->host
->hostdata
;
1584 dev_info(&ha
->pdev
->dev
,
1585 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
,
1586 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1588 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
1589 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1590 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
1596 if (qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
) == QLA_SUCCESS
) {
1597 return_status
= SUCCESS
;
1600 dev_info(&ha
->pdev
->dev
, "HOST RESET %s.\n",
1601 return_status
== FAILED
? "FAILED" : "SUCCEDED");
1603 return return_status
;
1607 static struct pci_device_id qla4xxx_pci_tbl
[] = {
1609 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1610 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
1611 .subvendor
= PCI_ANY_ID
,
1612 .subdevice
= PCI_ANY_ID
,
1615 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1616 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
1617 .subvendor
= PCI_ANY_ID
,
1618 .subdevice
= PCI_ANY_ID
,
1621 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1622 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
1623 .subvendor
= PCI_ANY_ID
,
1624 .subdevice
= PCI_ANY_ID
,
1628 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
1630 struct pci_driver qla4xxx_pci_driver
= {
1631 .name
= DRIVER_NAME
,
1632 .id_table
= qla4xxx_pci_tbl
,
1633 .probe
= qla4xxx_probe_adapter
,
1634 .remove
= qla4xxx_remove_adapter
,
1637 static int __init
qla4xxx_module_init(void)
1641 /* Allocate cache for SRBs. */
1642 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
1643 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
1644 if (srb_cachep
== NULL
) {
1646 "%s: Unable to allocate SRB cache..."
1647 "Failing load!\n", DRIVER_NAME
);
1652 /* Derive version string. */
1653 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
1654 if (ql4xextended_error_logging
)
1655 strcat(qla4xxx_version_str
, "-debug");
1657 qla4xxx_scsi_transport
=
1658 iscsi_register_transport(&qla4xxx_iscsi_transport
);
1659 if (!qla4xxx_scsi_transport
){
1661 goto release_srb_cache
;
1664 ret
= pci_register_driver(&qla4xxx_pci_driver
);
1666 goto unregister_transport
;
1668 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
1671 unregister_transport
:
1672 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1674 kmem_cache_destroy(srb_cachep
);
1679 static void __exit
qla4xxx_module_exit(void)
1682 pci_unregister_driver(&qla4xxx_pci_driver
);
1683 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1684 kmem_cache_destroy(srb_cachep
);
1687 module_init(qla4xxx_module_init
);
1688 module_exit(qla4xxx_module_exit
);
1690 MODULE_AUTHOR("QLogic Corporation");
1691 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1692 MODULE_LICENSE("GPL");
1693 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);