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");
44 * SCSI host template entry points
47 void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
);
50 * iSCSI template entry points
52 static int qla4xxx_tgt_dscvr(enum iscsi_tgt_dscvr type
, uint32_t host_no
,
53 uint32_t enable
, struct sockaddr
*dst_addr
);
54 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
55 enum iscsi_param param
, char *buf
);
56 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
57 enum iscsi_param param
, char *buf
);
58 static void qla4xxx_conn_stop(struct iscsi_cls_conn
*conn
, int flag
);
59 static int qla4xxx_conn_start(struct iscsi_cls_conn
*conn
);
60 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
);
63 * SCSI host template entry points
65 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
66 void (*done
) (struct scsi_cmnd
*));
67 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
);
68 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
);
69 static int qla4xxx_slave_alloc(struct scsi_device
*device
);
70 static int qla4xxx_slave_configure(struct scsi_device
*device
);
71 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
);
73 static struct scsi_host_template qla4xxx_driver_template
= {
74 .module
= THIS_MODULE
,
76 .proc_name
= DRIVER_NAME
,
77 .queuecommand
= qla4xxx_queuecommand
,
79 .eh_device_reset_handler
= qla4xxx_eh_device_reset
,
80 .eh_host_reset_handler
= qla4xxx_eh_host_reset
,
82 .slave_configure
= qla4xxx_slave_configure
,
83 .slave_alloc
= qla4xxx_slave_alloc
,
84 .slave_destroy
= qla4xxx_slave_destroy
,
88 .use_clustering
= ENABLE_CLUSTERING
,
89 .sg_tablesize
= SG_ALL
,
91 .max_sectors
= 0xFFFF,
94 static struct iscsi_transport qla4xxx_iscsi_transport
= {
97 .param_mask
= ISCSI_CONN_PORT
|
101 .sessiondata_size
= sizeof(struct ddb_entry
),
102 .host_template
= &qla4xxx_driver_template
,
104 .tgt_dscvr
= qla4xxx_tgt_dscvr
,
105 .get_conn_param
= qla4xxx_conn_get_param
,
106 .get_session_param
= qla4xxx_sess_get_param
,
107 .start_conn
= qla4xxx_conn_start
,
108 .stop_conn
= qla4xxx_conn_stop
,
109 .session_recovery_timedout
= qla4xxx_recovery_timedout
,
112 static struct scsi_transport_template
*qla4xxx_scsi_transport
;
114 static void qla4xxx_recovery_timedout(struct iscsi_cls_session
*session
)
116 struct ddb_entry
*ddb_entry
= session
->dd_data
;
117 struct scsi_qla_host
*ha
= ddb_entry
->ha
;
119 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count of (%d) "
120 "secs exhausted, marking device DEAD.\n", ha
->host_no
,
121 __func__
, ddb_entry
->fw_ddb_index
,
122 ha
->port_down_retry_count
));
124 atomic_set(&ddb_entry
->state
, DDB_STATE_DEAD
);
126 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
127 "0x%lx\n", ha
->host_no
, __func__
, ha
->dpc_flags
));
128 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
131 static int qla4xxx_conn_start(struct iscsi_cls_conn
*conn
)
133 struct iscsi_cls_session
*session
;
134 struct ddb_entry
*ddb_entry
;
136 session
= iscsi_dev_to_session(conn
->dev
.parent
);
137 ddb_entry
= session
->dd_data
;
139 DEBUG2(printk("scsi%ld: %s: index [%d] starting conn\n",
140 ddb_entry
->ha
->host_no
, __func__
,
141 ddb_entry
->fw_ddb_index
));
142 iscsi_unblock_session(session
);
146 static void qla4xxx_conn_stop(struct iscsi_cls_conn
*conn
, int flag
)
148 struct iscsi_cls_session
*session
;
149 struct ddb_entry
*ddb_entry
;
151 session
= iscsi_dev_to_session(conn
->dev
.parent
);
152 ddb_entry
= session
->dd_data
;
154 DEBUG2(printk("scsi%ld: %s: index [%d] stopping conn\n",
155 ddb_entry
->ha
->host_no
, __func__
,
156 ddb_entry
->fw_ddb_index
));
157 if (flag
== STOP_CONN_RECOVER
)
158 iscsi_block_session(session
);
160 printk(KERN_ERR
"iscsi: invalid stop flag %d\n", flag
);
163 static int qla4xxx_sess_get_param(struct iscsi_cls_session
*sess
,
164 enum iscsi_param param
, char *buf
)
166 struct ddb_entry
*ddb_entry
= sess
->dd_data
;
170 case ISCSI_PARAM_TARGET_NAME
:
171 len
= snprintf(buf
, PAGE_SIZE
- 1, "%s\n",
172 ddb_entry
->iscsi_name
);
174 case ISCSI_PARAM_TPGT
:
175 len
= sprintf(buf
, "%u\n", ddb_entry
->tpgt
);
184 static int qla4xxx_conn_get_param(struct iscsi_cls_conn
*conn
,
185 enum iscsi_param param
, char *buf
)
187 struct iscsi_cls_session
*session
;
188 struct ddb_entry
*ddb_entry
;
191 session
= iscsi_dev_to_session(conn
->dev
.parent
);
192 ddb_entry
= session
->dd_data
;
195 case ISCSI_PARAM_CONN_PORT
:
196 len
= sprintf(buf
, "%hu\n", ddb_entry
->port
);
198 case ISCSI_PARAM_CONN_ADDRESS
:
199 /* TODO: what are the ipv6 bits */
200 len
= sprintf(buf
, "%u.%u.%u.%u\n",
201 NIPQUAD(ddb_entry
->ip_addr
));
210 static int qla4xxx_tgt_dscvr(enum iscsi_tgt_dscvr type
, uint32_t host_no
,
211 uint32_t enable
, struct sockaddr
*dst_addr
)
213 struct scsi_qla_host
*ha
;
214 struct Scsi_Host
*shost
;
215 struct sockaddr_in
*addr
;
216 struct sockaddr_in6
*addr6
;
219 shost
= scsi_host_lookup(host_no
);
221 printk(KERN_ERR
"Could not find host no %u\n", host_no
);
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
)
249 scsi_host_put(shost
);
253 void qla4xxx_destroy_sess(struct ddb_entry
*ddb_entry
)
255 if (!ddb_entry
->sess
)
258 if (ddb_entry
->conn
) {
259 iscsi_if_destroy_session_done(ddb_entry
->conn
);
260 iscsi_destroy_conn(ddb_entry
->conn
);
261 iscsi_remove_session(ddb_entry
->sess
);
263 iscsi_free_session(ddb_entry
->sess
);
266 int qla4xxx_add_sess(struct ddb_entry
*ddb_entry
)
270 err
= iscsi_add_session(ddb_entry
->sess
, ddb_entry
->fw_ddb_index
);
272 DEBUG2(printk(KERN_ERR
"Could not add session.\n"));
276 ddb_entry
->conn
= iscsi_create_conn(ddb_entry
->sess
, 0);
277 if (!ddb_entry
->conn
) {
278 iscsi_remove_session(ddb_entry
->sess
);
279 DEBUG2(printk(KERN_ERR
"Could not add connection.\n"));
283 ddb_entry
->sess
->recovery_tmo
= ddb_entry
->ha
->port_down_retry_count
;
284 iscsi_if_create_session_done(ddb_entry
->conn
);
288 struct ddb_entry
*qla4xxx_alloc_sess(struct scsi_qla_host
*ha
)
290 struct ddb_entry
*ddb_entry
;
291 struct iscsi_cls_session
*sess
;
293 sess
= iscsi_alloc_session(ha
->host
, &qla4xxx_iscsi_transport
);
297 ddb_entry
= sess
->dd_data
;
298 memset(ddb_entry
, 0, sizeof(*ddb_entry
));
300 ddb_entry
->sess
= sess
;
308 static void qla4xxx_start_timer(struct scsi_qla_host
*ha
, void *func
,
309 unsigned long interval
)
311 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
312 __func__
, ha
->host
->host_no
));
313 init_timer(&ha
->timer
);
314 ha
->timer
.expires
= jiffies
+ interval
* HZ
;
315 ha
->timer
.data
= (unsigned long)ha
;
316 ha
->timer
.function
= (void (*)(unsigned long))func
;
317 add_timer(&ha
->timer
);
318 ha
->timer_active
= 1;
321 static void qla4xxx_stop_timer(struct scsi_qla_host
*ha
)
323 del_timer_sync(&ha
->timer
);
324 ha
->timer_active
= 0;
328 * qla4xxx_mark_device_missing - mark a device as missing.
329 * @ha: Pointer to host adapter structure.
330 * @ddb_entry: Pointer to device database entry
332 * This routine marks a device missing and resets the relogin retry count.
334 void qla4xxx_mark_device_missing(struct scsi_qla_host
*ha
,
335 struct ddb_entry
*ddb_entry
)
337 atomic_set(&ddb_entry
->state
, DDB_STATE_MISSING
);
338 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
339 ha
->host_no
, ddb_entry
->bus
, ddb_entry
->target
,
340 ddb_entry
->fw_ddb_index
));
341 iscsi_conn_error(ddb_entry
->conn
, ISCSI_ERR_CONN_FAILED
);
344 static struct srb
* qla4xxx_get_new_srb(struct scsi_qla_host
*ha
,
345 struct ddb_entry
*ddb_entry
,
346 struct scsi_cmnd
*cmd
,
347 void (*done
)(struct scsi_cmnd
*))
351 srb
= mempool_alloc(ha
->srb_mempool
, GFP_ATOMIC
);
355 atomic_set(&srb
->ref_count
, 1);
357 srb
->ddb
= ddb_entry
;
360 cmd
->SCp
.ptr
= (void *)srb
;
361 cmd
->scsi_done
= done
;
366 static void qla4xxx_srb_free_dma(struct scsi_qla_host
*ha
, struct srb
*srb
)
368 struct scsi_cmnd
*cmd
= srb
->cmd
;
370 if (srb
->flags
& SRB_DMA_VALID
) {
372 pci_unmap_sg(ha
->pdev
, cmd
->request_buffer
,
373 cmd
->use_sg
, cmd
->sc_data_direction
);
374 } else if (cmd
->request_bufflen
) {
375 pci_unmap_single(ha
->pdev
, srb
->dma_handle
,
376 cmd
->request_bufflen
,
377 cmd
->sc_data_direction
);
379 srb
->flags
&= ~SRB_DMA_VALID
;
384 void qla4xxx_srb_compl(struct scsi_qla_host
*ha
, struct srb
*srb
)
386 struct scsi_cmnd
*cmd
= srb
->cmd
;
388 qla4xxx_srb_free_dma(ha
, srb
);
390 mempool_free(srb
, ha
->srb_mempool
);
396 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
397 * @cmd: Pointer to Linux's SCSI command structure
398 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
399 * that the command has been processed.
402 * This routine is invoked by Linux to send a SCSI command to the driver.
403 * The mid-level driver tries to ensure that queuecommand never gets
404 * invoked concurrently with itself or the interrupt handler (although
405 * the interrupt handler may call this routine as part of request-
406 * completion handling). Unfortunely, it sometimes calls the scheduler
407 * in interrupt context which is a big NO! NO!.
409 static int qla4xxx_queuecommand(struct scsi_cmnd
*cmd
,
410 void (*done
)(struct scsi_cmnd
*))
412 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
413 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
417 if (atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
418 if (atomic_read(&ddb_entry
->state
) == DDB_STATE_DEAD
) {
419 cmd
->result
= DID_NO_CONNECT
<< 16;
420 goto qc_fail_command
;
425 spin_unlock_irq(ha
->host
->host_lock
);
427 srb
= qla4xxx_get_new_srb(ha
, ddb_entry
, cmd
, done
);
429 goto qc_host_busy_lock
;
431 rval
= qla4xxx_send_command_to_isp(ha
, srb
);
432 if (rval
!= QLA_SUCCESS
)
433 goto qc_host_busy_free_sp
;
435 spin_lock_irq(ha
->host
->host_lock
);
438 qc_host_busy_free_sp
:
439 qla4xxx_srb_free_dma(ha
, srb
);
440 mempool_free(srb
, ha
->srb_mempool
);
443 spin_lock_irq(ha
->host
->host_lock
);
446 return SCSI_MLQUEUE_HOST_BUSY
;
455 * qla4xxx_mem_free - frees memory allocated to adapter
456 * @ha: Pointer to host adapter structure.
458 * Frees memory previously allocated by qla4xxx_mem_alloc
460 static void qla4xxx_mem_free(struct scsi_qla_host
*ha
)
463 dma_free_coherent(&ha
->pdev
->dev
, ha
->queues_len
, ha
->queues
,
469 ha
->request_ring
= NULL
;
471 ha
->response_ring
= NULL
;
472 ha
->response_dma
= 0;
473 ha
->shadow_regs
= NULL
;
474 ha
->shadow_regs_dma
= 0;
478 mempool_destroy(ha
->srb_mempool
);
480 ha
->srb_mempool
= NULL
;
482 /* release io space registers */
485 pci_release_regions(ha
->pdev
);
489 * qla4xxx_mem_alloc - allocates memory for use by adapter.
490 * @ha: Pointer to host adapter structure
492 * Allocates DMA memory for request and response queues. Also allocates memory
495 static int qla4xxx_mem_alloc(struct scsi_qla_host
*ha
)
499 /* Allocate contiguous block of DMA memory for queues. */
500 ha
->queues_len
= ((REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
501 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
) +
502 sizeof(struct shadow_regs
) +
504 (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
505 ha
->queues
= dma_alloc_coherent(&ha
->pdev
->dev
, ha
->queues_len
,
506 &ha
->queues_dma
, GFP_KERNEL
);
507 if (ha
->queues
== NULL
) {
508 dev_warn(&ha
->pdev
->dev
,
509 "Memory Allocation failed - queues.\n");
511 goto mem_alloc_error_exit
;
513 memset(ha
->queues
, 0, ha
->queues_len
);
516 * As per RISC alignment requirements -- the bus-address must be a
517 * multiple of the request-ring size (in bytes).
520 if ((unsigned long)ha
->queues_dma
& (MEM_ALIGN_VALUE
- 1))
521 align
= MEM_ALIGN_VALUE
- ((unsigned long)ha
->queues_dma
&
522 (MEM_ALIGN_VALUE
- 1));
524 /* Update request and response queue pointers. */
525 ha
->request_dma
= ha
->queues_dma
+ align
;
526 ha
->request_ring
= (struct queue_entry
*) (ha
->queues
+ align
);
527 ha
->response_dma
= ha
->queues_dma
+ align
+
528 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
);
529 ha
->response_ring
= (struct queue_entry
*) (ha
->queues
+ align
+
530 (REQUEST_QUEUE_DEPTH
*
532 ha
->shadow_regs_dma
= ha
->queues_dma
+ align
+
533 (REQUEST_QUEUE_DEPTH
* QUEUE_SIZE
) +
534 (RESPONSE_QUEUE_DEPTH
* QUEUE_SIZE
);
535 ha
->shadow_regs
= (struct shadow_regs
*) (ha
->queues
+ align
+
536 (REQUEST_QUEUE_DEPTH
*
538 (RESPONSE_QUEUE_DEPTH
*
541 /* Allocate memory for srb pool. */
542 ha
->srb_mempool
= mempool_create(SRB_MIN_REQ
, mempool_alloc_slab
,
543 mempool_free_slab
, srb_cachep
);
544 if (ha
->srb_mempool
== NULL
) {
545 dev_warn(&ha
->pdev
->dev
,
546 "Memory Allocation failed - SRB Pool.\n");
548 goto mem_alloc_error_exit
;
553 mem_alloc_error_exit
:
554 qla4xxx_mem_free(ha
);
559 * qla4xxx_timer - checks every second for work to do.
560 * @ha: Pointer to host adapter structure.
562 static void qla4xxx_timer(struct scsi_qla_host
*ha
)
564 struct ddb_entry
*ddb_entry
, *dtemp
;
567 /* Search for relogin's to time-out and port down retry. */
568 list_for_each_entry_safe(ddb_entry
, dtemp
, &ha
->ddb_list
, list
) {
569 /* Count down time between sending relogins */
570 if (adapter_up(ha
) &&
571 !test_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
572 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
) {
573 if (atomic_read(&ddb_entry
->retry_relogin_timer
) !=
575 if (atomic_read(&ddb_entry
->retry_relogin_timer
)
577 atomic_set(&ddb_entry
->
580 set_bit(DPC_RELOGIN_DEVICE
,
582 set_bit(DF_RELOGIN
, &ddb_entry
->flags
);
583 DEBUG2(printk("scsi%ld: %s: index [%d]"
585 ha
->host_no
, __func__
,
586 ddb_entry
->fw_ddb_index
));
588 atomic_dec(&ddb_entry
->
589 retry_relogin_timer
);
593 /* Wait for relogin to timeout */
594 if (atomic_read(&ddb_entry
->relogin_timer
) &&
595 (atomic_dec_and_test(&ddb_entry
->relogin_timer
) != 0)) {
597 * If the relogin times out and the device is
598 * still NOT ONLINE then try and relogin again.
600 if (atomic_read(&ddb_entry
->state
) !=
602 ddb_entry
->fw_ddb_device_state
==
603 DDB_DS_SESSION_FAILED
) {
604 /* Reset retry relogin timer */
605 atomic_inc(&ddb_entry
->relogin_retry_count
);
606 DEBUG2(printk("scsi%ld: index[%d] relogin"
607 " timed out-retrying"
610 ddb_entry
->fw_ddb_index
,
611 atomic_read(&ddb_entry
->
612 relogin_retry_count
))
615 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
616 "initate relogin after"
618 ha
->host_no
, ddb_entry
->bus
,
620 ddb_entry
->fw_ddb_index
,
621 ddb_entry
->default_time2wait
+ 4)
624 atomic_set(&ddb_entry
->retry_relogin_timer
,
625 ddb_entry
->default_time2wait
+ 4);
630 /* Check for heartbeat interval. */
631 if (ha
->firmware_options
& FWOPT_HEARTBEAT_ENABLE
&&
632 ha
->heartbeat_interval
!= 0) {
633 ha
->seconds_since_last_heartbeat
++;
634 if (ha
->seconds_since_last_heartbeat
>
635 ha
->heartbeat_interval
+ 2)
636 set_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
640 /* Wakeup the dpc routine for this adapter, if needed. */
642 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
643 test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
) ||
644 test_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
) ||
645 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
646 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
647 test_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
) ||
648 test_bit(DPC_AEN
, &ha
->dpc_flags
)) &&
650 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
651 " - dpc flags = 0x%lx\n",
652 ha
->host_no
, __func__
, ha
->dpc_flags
));
653 queue_work(ha
->dpc_thread
, &ha
->dpc_work
);
656 /* Reschedule timer thread to call us back in one second */
657 mod_timer(&ha
->timer
, jiffies
+ HZ
);
659 DEBUG2(ha
->seconds_since_last_intr
++);
663 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
664 * @ha: Pointer to host adapter structure.
666 * This routine stalls the driver until all outstanding commands are returned.
667 * Caller must release the Hardware Lock prior to calling this routine.
669 static int qla4xxx_cmd_wait(struct scsi_qla_host
*ha
)
672 int stat
= QLA_SUCCESS
;
674 struct scsi_cmnd
*cmd
;
675 int wait_cnt
= WAIT_CMD_TOV
; /*
676 * Initialized for 30 seconds as we
677 * expect all commands to retuned
682 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
683 /* Find a command that hasn't completed. */
684 for (index
= 0; index
< ha
->host
->can_queue
; index
++) {
685 cmd
= scsi_host_find_tag(ha
->host
, index
);
689 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
691 /* If No Commands are pending, wait is complete */
692 if (index
== ha
->host
->can_queue
) {
696 /* If we timed out on waiting for commands to come back
705 } /* End of While (wait_cnt) */
711 * qla4xxx_soft_reset - performs soft reset.
712 * @ha: Pointer to host adapter structure.
714 int qla4xxx_soft_reset(struct scsi_qla_host
*ha
)
716 uint32_t max_wait_time
;
717 unsigned long flags
= 0;
718 int status
= QLA_ERROR
;
719 uint32_t ctrl_status
;
721 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
724 * If the SCSI Reset Interrupt bit is set, clear it.
725 * Otherwise, the Soft Reset won't work.
727 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
728 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0)
729 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
731 /* Issue Soft Reset */
732 writel(set_rmask(CSR_SOFT_RESET
), &ha
->reg
->ctrl_status
);
733 readl(&ha
->reg
->ctrl_status
);
735 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
737 /* Wait until the Network Reset Intr bit is cleared */
738 max_wait_time
= RESET_INTR_TOV
;
740 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
741 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
742 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
744 if ((ctrl_status
& CSR_NET_RESET_INTR
) == 0)
748 } while ((--max_wait_time
));
750 if ((ctrl_status
& CSR_NET_RESET_INTR
) != 0) {
751 DEBUG2(printk(KERN_WARNING
752 "scsi%ld: Network Reset Intr not cleared by "
753 "Network function, clearing it now!\n",
755 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
756 writel(set_rmask(CSR_NET_RESET_INTR
), &ha
->reg
->ctrl_status
);
757 readl(&ha
->reg
->ctrl_status
);
758 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
761 /* Wait until the firmware tells us the Soft Reset is done */
762 max_wait_time
= SOFT_RESET_TOV
;
764 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
765 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
766 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
768 if ((ctrl_status
& CSR_SOFT_RESET
) == 0) {
769 status
= QLA_SUCCESS
;
774 } while ((--max_wait_time
));
777 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
778 * after the soft reset has taken place.
780 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
781 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
782 if ((ctrl_status
& CSR_SCSI_RESET_INTR
) != 0) {
783 writel(set_rmask(CSR_SCSI_RESET_INTR
), &ha
->reg
->ctrl_status
);
784 readl(&ha
->reg
->ctrl_status
);
786 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
788 /* If soft reset fails then most probably the bios on other
789 * function is also enabled.
790 * Since the initialization is sequential the other fn
791 * wont be able to acknowledge the soft reset.
792 * Issue a force soft reset to workaround this scenario.
794 if (max_wait_time
== 0) {
795 /* Issue Force Soft Reset */
796 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
797 writel(set_rmask(CSR_FORCE_SOFT_RESET
), &ha
->reg
->ctrl_status
);
798 readl(&ha
->reg
->ctrl_status
);
799 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
800 /* Wait until the firmware tells us the Soft Reset is done */
801 max_wait_time
= SOFT_RESET_TOV
;
803 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
804 ctrl_status
= readw(&ha
->reg
->ctrl_status
);
805 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
807 if ((ctrl_status
& CSR_FORCE_SOFT_RESET
) == 0) {
808 status
= QLA_SUCCESS
;
813 } while ((--max_wait_time
));
820 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
821 * @ha: Pointer to host adapter structure.
823 * This routine is called just prior to a HARD RESET to return all
824 * outstanding commands back to the Operating System.
825 * Caller should make sure that the following locks are released
826 * before this calling routine: Hardware lock, and io_request_lock.
828 static void qla4xxx_flush_active_srbs(struct scsi_qla_host
*ha
)
834 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
835 for (i
= 0; i
< ha
->host
->can_queue
; i
++) {
836 srb
= qla4xxx_del_from_active_array(ha
, i
);
838 srb
->cmd
->result
= DID_RESET
<< 16;
839 qla4xxx_srb_compl(ha
, srb
);
842 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
847 * qla4xxx_recover_adapter - recovers adapter after a fatal error
848 * @ha: Pointer to host adapter structure.
849 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
850 * after adapter recovery has completed.
851 * 0=preserve ddb list, 1=destroy and rebuild ddb list
853 static int qla4xxx_recover_adapter(struct scsi_qla_host
*ha
,
854 uint8_t renew_ddb_list
)
858 /* Stall incoming I/O until we are done */
859 clear_bit(AF_ONLINE
, &ha
->flags
);
860 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha
->host_no
,
863 /* Wait for outstanding commands to complete.
864 * Stalls the driver for max 30 secs
866 status
= qla4xxx_cmd_wait(ha
);
868 qla4xxx_disable_intrs(ha
);
870 /* Flush any pending ddb changed AENs */
871 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
873 /* Reset the firmware. If successful, function
874 * returns with ISP interrupts enabled.
876 if (status
== QLA_SUCCESS
) {
877 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
878 ha
->host_no
, __func__
));
879 qla4xxx_flush_active_srbs(ha
);
880 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
881 status
= qla4xxx_soft_reset(ha
);
886 /* Flush any pending ddb changed AENs */
887 qla4xxx_process_aen(ha
, FLUSH_DDB_CHANGED_AENS
);
889 /* Re-initialize firmware. If successful, function returns
890 * with ISP interrupts enabled */
891 if (status
== QLA_SUCCESS
) {
892 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
893 ha
->host_no
, __func__
));
895 /* If successful, AF_ONLINE flag set in
896 * qla4xxx_initialize_adapter */
897 status
= qla4xxx_initialize_adapter(ha
, renew_ddb_list
);
900 /* Failed adapter initialization?
901 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
902 if ((test_bit(AF_ONLINE
, &ha
->flags
) == 0) &&
903 (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))) {
904 /* Adapter initialization failed, see if we can retry
905 * resetting the ha */
906 if (!test_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
)) {
907 ha
->retry_reset_ha_cnt
= MAX_RESET_HA_RETRIES
;
908 DEBUG2(printk("scsi%ld: recover adapter - retrying "
909 "(%d) more times\n", ha
->host_no
,
910 ha
->retry_reset_ha_cnt
));
911 set_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
914 if (ha
->retry_reset_ha_cnt
> 0) {
915 /* Schedule another Reset HA--DPC will retry */
916 ha
->retry_reset_ha_cnt
--;
917 DEBUG2(printk("scsi%ld: recover adapter - "
918 "retry remaining %d\n",
920 ha
->retry_reset_ha_cnt
));
924 if (ha
->retry_reset_ha_cnt
== 0) {
925 /* Recover adapter retries have been exhausted.
927 DEBUG2(printk("scsi%ld: recover adapter "
928 "failed - board disabled\n",
930 qla4xxx_flush_active_srbs(ha
);
931 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
932 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
933 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
,
939 clear_bit(DPC_RESET_HA
, &ha
->dpc_flags
);
940 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
);
941 clear_bit(DPC_RETRY_RESET_HA
, &ha
->dpc_flags
);
944 ha
->adapter_error_count
++;
946 if (status
== QLA_SUCCESS
)
947 qla4xxx_enable_intrs(ha
);
949 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha
->host_no
));
954 * qla4xxx_do_dpc - dpc routine
955 * @data: in our case pointer to adapter structure
957 * This routine is a task that is schedule by the interrupt handler
958 * to perform the background processing for interrupts. We put it
959 * on a task queue that is consumed whenever the scheduler runs; that's
960 * so you can do anything (i.e. put the process to sleep etc). In fact,
961 * the mid-level tries to sleep when it reaches the driver threshold
962 * "host->can_queue". This can cause a panic if we were in our interrupt code.
964 static void qla4xxx_do_dpc(struct work_struct
*work
)
966 struct scsi_qla_host
*ha
=
967 container_of(work
, struct scsi_qla_host
, dpc_work
);
968 struct ddb_entry
*ddb_entry
, *dtemp
;
970 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
971 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
972 ha
->host_no
, __func__
, ha
->flags
, ha
->dpc_flags
));
974 /* Initialization not yet finished. Don't do anything yet. */
975 if (!test_bit(AF_INIT_DONE
, &ha
->flags
))
978 if (adapter_up(ha
) ||
979 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
) ||
980 test_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
) ||
981 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
)) {
982 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST
, &ha
->dpc_flags
) ||
983 test_bit(DPC_RESET_HA
, &ha
->dpc_flags
))
984 qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
);
986 if (test_and_clear_bit(DPC_RESET_HA_INTR
, &ha
->dpc_flags
)) {
987 uint8_t wait_time
= RESET_INTR_TOV
;
988 unsigned long flags
= 0;
990 qla4xxx_flush_active_srbs(ha
);
992 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
993 while ((readw(&ha
->reg
->ctrl_status
) &
994 (CSR_SOFT_RESET
| CSR_FORCE_SOFT_RESET
)) != 0) {
995 if (--wait_time
== 0)
998 spin_unlock_irqrestore(&ha
->hardware_lock
,
1003 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1005 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1008 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1009 "bit not cleared-- resetting\n",
1010 ha
->host_no
, __func__
));
1014 /* ---- process AEN? --- */
1015 if (test_and_clear_bit(DPC_AEN
, &ha
->dpc_flags
))
1016 qla4xxx_process_aen(ha
, PROCESS_ALL_AENS
);
1018 /* ---- Get DHCP IP Address? --- */
1019 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR
, &ha
->dpc_flags
))
1020 qla4xxx_get_dhcp_ip_address(ha
);
1022 /* ---- relogin device? --- */
1023 if (adapter_up(ha
) &&
1024 test_and_clear_bit(DPC_RELOGIN_DEVICE
, &ha
->dpc_flags
)) {
1025 list_for_each_entry_safe(ddb_entry
, dtemp
,
1026 &ha
->ddb_list
, list
) {
1027 if (test_and_clear_bit(DF_RELOGIN
, &ddb_entry
->flags
) &&
1028 atomic_read(&ddb_entry
->state
) != DDB_STATE_ONLINE
)
1029 qla4xxx_relogin_device(ha
, ddb_entry
);
1032 * If mbx cmd times out there is no point
1033 * in continuing further.
1034 * With large no of targets this can hang
1037 if (test_bit(DPC_RESET_HA
, &ha
->dpc_flags
)) {
1038 printk(KERN_WARNING
"scsi%ld: %s: "
1039 "need to reset hba\n",
1040 ha
->host_no
, __func__
);
1048 * qla4xxx_free_adapter - release the adapter
1049 * @ha: pointer to adapter structure
1051 static void qla4xxx_free_adapter(struct scsi_qla_host
*ha
)
1054 if (test_bit(AF_INTERRUPTS_ON
, &ha
->flags
)) {
1055 /* Turn-off interrupts on the card. */
1056 qla4xxx_disable_intrs(ha
);
1059 /* Kill the kernel thread for this host */
1061 destroy_workqueue(ha
->dpc_thread
);
1063 /* Issue Soft Reset to put firmware in unknown state */
1064 if (ql4xxx_lock_drvr_wait(ha
) == QLA_SUCCESS
)
1065 qla4xxx_soft_reset(ha
);
1067 /* Remove timer thread, if present */
1068 if (ha
->timer_active
)
1069 qla4xxx_stop_timer(ha
);
1071 /* free extra memory */
1072 qla4xxx_mem_free(ha
);
1074 /* Detach interrupts */
1075 if (test_and_clear_bit(AF_IRQ_ATTACHED
, &ha
->flags
))
1076 free_irq(ha
->pdev
->irq
, ha
);
1078 pci_disable_device(ha
->pdev
);
1083 * qla4xxx_iospace_config - maps registers
1084 * @ha: pointer to adapter structure
1086 * This routines maps HBA's registers from the pci address space
1087 * into the kernel virtual address space for memory mapped i/o.
1089 static int qla4xxx_iospace_config(struct scsi_qla_host
*ha
)
1091 unsigned long pio
, pio_len
, pio_flags
;
1092 unsigned long mmio
, mmio_len
, mmio_flags
;
1094 pio
= pci_resource_start(ha
->pdev
, 0);
1095 pio_len
= pci_resource_len(ha
->pdev
, 0);
1096 pio_flags
= pci_resource_flags(ha
->pdev
, 0);
1097 if (pio_flags
& IORESOURCE_IO
) {
1098 if (pio_len
< MIN_IOBASE_LEN
) {
1099 dev_warn(&ha
->pdev
->dev
,
1100 "Invalid PCI I/O region size\n");
1104 dev_warn(&ha
->pdev
->dev
, "region #0 not a PIO resource\n");
1108 /* Use MMIO operations for all accesses. */
1109 mmio
= pci_resource_start(ha
->pdev
, 1);
1110 mmio_len
= pci_resource_len(ha
->pdev
, 1);
1111 mmio_flags
= pci_resource_flags(ha
->pdev
, 1);
1113 if (!(mmio_flags
& IORESOURCE_MEM
)) {
1114 dev_err(&ha
->pdev
->dev
,
1115 "region #0 not an MMIO resource, aborting\n");
1117 goto iospace_error_exit
;
1119 if (mmio_len
< MIN_IOBASE_LEN
) {
1120 dev_err(&ha
->pdev
->dev
,
1121 "Invalid PCI mem region size, aborting\n");
1122 goto iospace_error_exit
;
1125 if (pci_request_regions(ha
->pdev
, DRIVER_NAME
)) {
1126 dev_warn(&ha
->pdev
->dev
,
1127 "Failed to reserve PIO/MMIO regions\n");
1129 goto iospace_error_exit
;
1132 ha
->pio_address
= pio
;
1133 ha
->pio_length
= pio_len
;
1134 ha
->reg
= ioremap(mmio
, MIN_IOBASE_LEN
);
1136 dev_err(&ha
->pdev
->dev
,
1137 "cannot remap MMIO, aborting\n");
1139 goto iospace_error_exit
;
1149 * qla4xxx_probe_adapter - callback function to probe HBA
1150 * @pdev: pointer to pci_dev structure
1151 * @pci_device_id: pointer to pci_device entry
1153 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1154 * It returns zero if successful. It also initializes all data necessary for
1157 static int __devinit
qla4xxx_probe_adapter(struct pci_dev
*pdev
,
1158 const struct pci_device_id
*ent
)
1160 int ret
= -ENODEV
, status
;
1161 struct Scsi_Host
*host
;
1162 struct scsi_qla_host
*ha
;
1163 struct ddb_entry
*ddb_entry
, *ddbtemp
;
1164 uint8_t init_retry_count
= 0;
1167 if (pci_enable_device(pdev
))
1170 host
= scsi_host_alloc(&qla4xxx_driver_template
, sizeof(*ha
));
1173 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1174 goto probe_disable_device
;
1177 /* Clear our data area */
1178 ha
= (struct scsi_qla_host
*) host
->hostdata
;
1179 memset(ha
, 0, sizeof(*ha
));
1181 /* Save the information from PCI BIOS. */
1184 ha
->host_no
= host
->host_no
;
1186 /* Configure PCI I/O space. */
1187 ret
= qla4xxx_iospace_config(ha
);
1191 dev_info(&ha
->pdev
->dev
, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1192 pdev
->device
, pdev
->irq
, ha
->reg
);
1194 qla4xxx_config_dma_addressing(ha
);
1196 /* Initialize lists and spinlocks. */
1197 INIT_LIST_HEAD(&ha
->ddb_list
);
1198 INIT_LIST_HEAD(&ha
->free_srb_q
);
1200 mutex_init(&ha
->mbox_sem
);
1201 init_waitqueue_head(&ha
->mailbox_wait_queue
);
1203 spin_lock_init(&ha
->hardware_lock
);
1205 /* Allocate dma buffers */
1206 if (qla4xxx_mem_alloc(ha
)) {
1207 dev_warn(&ha
->pdev
->dev
,
1208 "[ERROR] Failed to allocate memory for adapter\n");
1215 * Initialize the Host adapter request/response queues and
1217 * NOTE: interrupts enabled upon successful completion
1219 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1220 while (status
== QLA_ERROR
&& init_retry_count
++ < MAX_INIT_RETRIES
) {
1221 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1222 "(%d)\n", __func__
, init_retry_count
));
1223 qla4xxx_soft_reset(ha
);
1224 status
= qla4xxx_initialize_adapter(ha
, REBUILD_DDB_LIST
);
1226 if (status
== QLA_ERROR
) {
1227 dev_warn(&ha
->pdev
->dev
, "Failed to initialize adapter\n");
1233 host
->cmd_per_lun
= 3;
1234 host
->max_channel
= 0;
1235 host
->max_lun
= MAX_LUNS
- 1;
1236 host
->max_id
= MAX_TARGETS
;
1237 host
->max_cmd_len
= IOCB_MAX_CDB_LEN
;
1238 host
->can_queue
= MAX_SRBS
;
1239 host
->transportt
= qla4xxx_scsi_transport
;
1241 ret
= scsi_init_shared_tag_map(host
, MAX_SRBS
);
1243 dev_warn(&ha
->pdev
->dev
, "scsi_init_shared_tag_map failed");
1247 /* Startup the kernel thread for this host adapter. */
1248 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1249 "qla4xxx_dpc\n", __func__
));
1250 sprintf(buf
, "qla4xxx_%lu_dpc", ha
->host_no
);
1251 ha
->dpc_thread
= create_singlethread_workqueue(buf
);
1252 if (!ha
->dpc_thread
) {
1253 dev_warn(&ha
->pdev
->dev
, "Unable to start DPC thread!\n");
1257 INIT_WORK(&ha
->dpc_work
, qla4xxx_do_dpc
);
1259 ret
= request_irq(pdev
->irq
, qla4xxx_intr_handler
,
1260 SA_INTERRUPT
|SA_SHIRQ
, "qla4xxx", ha
);
1262 dev_warn(&ha
->pdev
->dev
, "Failed to reserve interrupt %d"
1263 " already in use.\n", pdev
->irq
);
1266 set_bit(AF_IRQ_ATTACHED
, &ha
->flags
);
1267 host
->irq
= pdev
->irq
;
1268 DEBUG(printk("scsi%d: irq %d attached\n", ha
->host_no
, ha
->pdev
->irq
));
1270 qla4xxx_enable_intrs(ha
);
1272 /* Start timer thread. */
1273 qla4xxx_start_timer(ha
, qla4xxx_timer
, 1);
1275 set_bit(AF_INIT_DONE
, &ha
->flags
);
1277 pci_set_drvdata(pdev
, ha
);
1279 ret
= scsi_add_host(host
, &pdev
->dev
);
1283 /* Update transport device information for all devices. */
1284 list_for_each_entry_safe(ddb_entry
, ddbtemp
, &ha
->ddb_list
, list
) {
1285 if (ddb_entry
->fw_ddb_device_state
== DDB_DS_SESSION_ACTIVE
)
1286 if (qla4xxx_add_sess(ddb_entry
))
1291 " QLogic iSCSI HBA Driver version: %s\n"
1292 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1293 qla4xxx_version_str
, ha
->pdev
->device
, pci_name(ha
->pdev
),
1294 ha
->host_no
, ha
->firmware_version
[0], ha
->firmware_version
[1],
1295 ha
->patch_number
, ha
->build_number
);
1300 qla4xxx_free_ddb_list(ha
);
1301 scsi_remove_host(host
);
1304 qla4xxx_free_adapter(ha
);
1305 scsi_host_put(ha
->host
);
1307 probe_disable_device
:
1308 pci_disable_device(pdev
);
1314 * qla4xxx_remove_adapter - calback function to remove adapter.
1315 * @pci_dev: PCI device pointer
1317 static void __devexit
qla4xxx_remove_adapter(struct pci_dev
*pdev
)
1319 struct scsi_qla_host
*ha
;
1321 ha
= pci_get_drvdata(pdev
);
1323 /* remove devs from iscsi_sessions to scsi_devices */
1324 qla4xxx_free_ddb_list(ha
);
1326 scsi_remove_host(ha
->host
);
1328 qla4xxx_free_adapter(ha
);
1330 scsi_host_put(ha
->host
);
1332 pci_set_drvdata(pdev
, NULL
);
1336 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1339 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1340 * supported addressing method.
1342 void qla4xxx_config_dma_addressing(struct scsi_qla_host
*ha
)
1346 /* Update our PCI device dma_mask for full 64 bit mask */
1347 if (pci_set_dma_mask(ha
->pdev
, DMA_64BIT_MASK
) == 0) {
1348 if (pci_set_consistent_dma_mask(ha
->pdev
, DMA_64BIT_MASK
)) {
1349 dev_dbg(&ha
->pdev
->dev
,
1350 "Failed to set 64 bit PCI consistent mask; "
1352 retval
= pci_set_consistent_dma_mask(ha
->pdev
,
1356 retval
= pci_set_dma_mask(ha
->pdev
, DMA_32BIT_MASK
);
1359 static int qla4xxx_slave_alloc(struct scsi_device
*sdev
)
1361 struct iscsi_cls_session
*sess
= starget_to_session(sdev
->sdev_target
);
1362 struct ddb_entry
*ddb
= sess
->dd_data
;
1364 sdev
->hostdata
= ddb
;
1365 sdev
->tagged_supported
= 1;
1366 scsi_activate_tcq(sdev
, sdev
->host
->can_queue
);
1370 static int qla4xxx_slave_configure(struct scsi_device
*sdev
)
1372 sdev
->tagged_supported
= 1;
1376 static void qla4xxx_slave_destroy(struct scsi_device
*sdev
)
1378 scsi_deactivate_tcq(sdev
, 1);
1382 * qla4xxx_del_from_active_array - returns an active srb
1383 * @ha: Pointer to host adapter structure.
1384 * @index: index into to the active_array
1386 * This routine removes and returns the srb at the specified index
1388 struct srb
* qla4xxx_del_from_active_array(struct scsi_qla_host
*ha
, uint32_t index
)
1390 struct srb
*srb
= NULL
;
1391 struct scsi_cmnd
*cmd
;
1393 if (!(cmd
= scsi_host_find_tag(ha
->host
, index
)))
1396 if (!(srb
= (struct srb
*)cmd
->host_scribble
))
1399 /* update counters */
1400 if (srb
->flags
& SRB_DMA_VALID
) {
1401 ha
->req_q_count
+= srb
->iocb_cnt
;
1402 ha
->iocb_cnt
-= srb
->iocb_cnt
;
1404 srb
->cmd
->host_scribble
= NULL
;
1410 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1411 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1412 * @cmd: Scsi Command to wait on.
1414 * This routine waits for the command to be returned by the Firmware
1415 * for some max time.
1417 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host
*ha
,
1418 struct scsi_cmnd
*cmd
)
1422 uint32_t max_wait_time
= EH_WAIT_CMD_TOV
;
1425 /* Checking to see if its returned to OS */
1426 rp
= (struct srb
*) cmd
->SCp
.ptr
;
1433 } while (max_wait_time
--);
1439 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1440 * @ha: Pointer to host adapter structure
1442 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host
*ha
)
1444 unsigned long wait_online
;
1446 wait_online
= jiffies
+ (30 * HZ
);
1447 while (time_before(jiffies
, wait_online
)) {
1451 else if (ha
->retry_reset_ha_cnt
== 0)
1461 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1462 * @ha: pointer to to HBA
1466 * This function waits for all outstanding commands to a lun to complete. It
1467 * returns 0 if all pending commands are returned and 1 otherwise.
1469 static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host
*ha
,
1474 struct scsi_cmnd
*cmd
;
1477 * Waiting for all commands for the designated target in the active
1480 for (cnt
= 0; cnt
< ha
->host
->can_queue
; cnt
++) {
1481 cmd
= scsi_host_find_tag(ha
->host
, cnt
);
1482 if (cmd
&& cmd
->device
->id
== t
&& cmd
->device
->lun
== l
) {
1483 if (!qla4xxx_eh_wait_on_command(ha
, cmd
)) {
1493 * qla4xxx_eh_device_reset - callback for target reset.
1494 * @cmd: Pointer to Linux's SCSI command structure
1496 * This routine is called by the Linux OS to reset all luns on the
1499 static int qla4xxx_eh_device_reset(struct scsi_cmnd
*cmd
)
1501 struct scsi_qla_host
*ha
= to_qla_host(cmd
->device
->host
);
1502 struct ddb_entry
*ddb_entry
= cmd
->device
->hostdata
;
1504 int ret
= FAILED
, stat
;
1506 sp
= (struct srb
*) cmd
->SCp
.ptr
;
1507 if (!sp
|| !ddb_entry
)
1510 dev_info(&ha
->pdev
->dev
,
1511 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha
->host_no
,
1512 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1514 DEBUG2(printk(KERN_INFO
1515 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1516 "dpc_flags=%lx, status=%x allowed=%d\n", ha
->host_no
,
1517 cmd
, jiffies
, cmd
->timeout_per_command
/ HZ
,
1518 ha
->dpc_flags
, cmd
->result
, cmd
->allowed
));
1520 /* FIXME: wait for hba to go online */
1521 stat
= qla4xxx_reset_lun(ha
, ddb_entry
, cmd
->device
->lun
);
1522 if (stat
!= QLA_SUCCESS
) {
1523 dev_info(&ha
->pdev
->dev
, "DEVICE RESET FAILED. %d\n", stat
);
1524 goto eh_dev_reset_done
;
1528 ha
->marker_needed
= 1;
1531 * If we are coming down the EH path, wait for all commands to complete
1534 if (cmd
->device
->host
->shost_state
== SHOST_RECOVERY
) {
1535 if (qla4xxx_eh_wait_for_active_target_commands(ha
,
1538 dev_info(&ha
->pdev
->dev
,
1539 "DEVICE RESET FAILED - waiting for "
1541 goto eh_dev_reset_done
;
1545 dev_info(&ha
->pdev
->dev
,
1546 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1547 ha
->host_no
, cmd
->device
->channel
, cmd
->device
->id
,
1558 * qla4xxx_eh_host_reset - kernel callback
1559 * @cmd: Pointer to Linux's SCSI command structure
1561 * This routine is invoked by the Linux kernel to perform fatal error
1562 * recovery on the specified adapter.
1564 static int qla4xxx_eh_host_reset(struct scsi_cmnd
*cmd
)
1566 int return_status
= FAILED
;
1567 struct scsi_qla_host
*ha
;
1569 ha
= (struct scsi_qla_host
*) cmd
->device
->host
->hostdata
;
1571 dev_info(&ha
->pdev
->dev
,
1572 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha
->host_no
,
1573 cmd
->device
->channel
, cmd
->device
->id
, cmd
->device
->lun
);
1575 if (qla4xxx_wait_for_hba_online(ha
) != QLA_SUCCESS
) {
1576 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1577 "DEAD.\n", ha
->host_no
, cmd
->device
->channel
,
1583 if (qla4xxx_recover_adapter(ha
, PRESERVE_DDB_LIST
) == QLA_SUCCESS
) {
1584 return_status
= SUCCESS
;
1587 dev_info(&ha
->pdev
->dev
, "HOST RESET %s.\n",
1588 return_status
== FAILED
? "FAILED" : "SUCCEDED");
1590 return return_status
;
1594 static struct pci_device_id qla4xxx_pci_tbl
[] = {
1596 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1597 .device
= PCI_DEVICE_ID_QLOGIC_ISP4010
,
1598 .subvendor
= PCI_ANY_ID
,
1599 .subdevice
= PCI_ANY_ID
,
1602 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1603 .device
= PCI_DEVICE_ID_QLOGIC_ISP4022
,
1604 .subvendor
= PCI_ANY_ID
,
1605 .subdevice
= PCI_ANY_ID
,
1608 .vendor
= PCI_VENDOR_ID_QLOGIC
,
1609 .device
= PCI_DEVICE_ID_QLOGIC_ISP4032
,
1610 .subvendor
= PCI_ANY_ID
,
1611 .subdevice
= PCI_ANY_ID
,
1615 MODULE_DEVICE_TABLE(pci
, qla4xxx_pci_tbl
);
1617 struct pci_driver qla4xxx_pci_driver
= {
1618 .name
= DRIVER_NAME
,
1619 .id_table
= qla4xxx_pci_tbl
,
1620 .probe
= qla4xxx_probe_adapter
,
1621 .remove
= qla4xxx_remove_adapter
,
1624 static int __init
qla4xxx_module_init(void)
1628 /* Allocate cache for SRBs. */
1629 srb_cachep
= kmem_cache_create("qla4xxx_srbs", sizeof(struct srb
), 0,
1630 SLAB_HWCACHE_ALIGN
, NULL
, NULL
);
1631 if (srb_cachep
== NULL
) {
1633 "%s: Unable to allocate SRB cache..."
1634 "Failing load!\n", DRIVER_NAME
);
1639 /* Derive version string. */
1640 strcpy(qla4xxx_version_str
, QLA4XXX_DRIVER_VERSION
);
1641 if (ql4xextended_error_logging
)
1642 strcat(qla4xxx_version_str
, "-debug");
1644 qla4xxx_scsi_transport
=
1645 iscsi_register_transport(&qla4xxx_iscsi_transport
);
1646 if (!qla4xxx_scsi_transport
){
1648 goto release_srb_cache
;
1651 ret
= pci_register_driver(&qla4xxx_pci_driver
);
1653 goto unregister_transport
;
1655 printk(KERN_INFO
"QLogic iSCSI HBA Driver\n");
1658 unregister_transport
:
1659 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1661 kmem_cache_destroy(srb_cachep
);
1666 static void __exit
qla4xxx_module_exit(void)
1668 pci_unregister_driver(&qla4xxx_pci_driver
);
1669 iscsi_unregister_transport(&qla4xxx_iscsi_transport
);
1670 kmem_cache_destroy(srb_cachep
);
1673 module_init(qla4xxx_module_init
);
1674 module_exit(qla4xxx_module_exit
);
1676 MODULE_AUTHOR("QLogic Corporation");
1677 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1678 MODULE_LICENSE("GPL");
1679 MODULE_VERSION(QLA4XXX_DRIVER_VERSION
);