2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
8 #include <linux/slab.h>
10 #include <scsi/scsi_tcq.h>
11 #include <scsi/scsicam.h>
14 #include "ql4_version.h"
17 #include "ql4_inline.h"
22 static char qla4xxx_version_str[40];
25 * SRB allocation cache
27 static struct kmem_cache *srb_cachep;
30 * Module parameter information and variables
32 int ql4xdiscoverywait = 60;
33 module_param(ql4xdiscoverywait, int, S_IRUGO | S_IWUSR);
34 MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
36 int ql4xdontresethba = 0;
37 module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
38 MODULE_PARM_DESC(ql4xdontresethba,
39 "Don't reset the HBA for driver recovery \n"
40 " 0 - It will reset HBA (Default)\n"
41 " 1 - It will NOT reset HBA");
43 int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
44 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
45 MODULE_PARM_DESC(ql4xextended_error_logging,
46 "Option to enable extended error logging, "
47 "Default is 0 - no logging, 1 - debug logging");
49 int ql4xenablemsix = 1;
50 module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
51 MODULE_PARM_DESC(ql4xenablemsix,
52 "Set to enable MSI or MSI-X interrupt mechanism.\n"
53 " 0 = enable INTx interrupt mechanism.\n"
54 " 1 = enable MSI-X interrupt mechanism (Default).\n"
55 " 2 = enable MSI interrupt mechanism.");
57 #define QL4_DEF_QDEPTH 32
60 * SCSI host template entry points
62 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
65 * iSCSI template entry points
67 static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
68 enum iscsi_tgt_dscvr type, uint32_t enable,
69 struct sockaddr *dst_addr);
70 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
71 enum iscsi_param param, char *buf);
72 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
73 enum iscsi_param param, char *buf);
74 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
75 enum iscsi_host_param param, char *buf);
76 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
77 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
80 * SCSI host template entry points
82 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
83 void (*done) (struct scsi_cmnd *));
84 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
85 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
86 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
87 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
88 static int qla4xxx_slave_alloc(struct scsi_device *device);
89 static int qla4xxx_slave_configure(struct scsi_device *device);
90 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
91 static void qla4xxx_scan_start(struct Scsi_Host *shost);
93 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
94 QLA82XX_LEGACY_INTR_CONFIG;
96 static struct scsi_host_template qla4xxx_driver_template = {
97 .module = THIS_MODULE,
99 .proc_name = DRIVER_NAME,
100 .queuecommand = qla4xxx_queuecommand,
102 .eh_abort_handler = qla4xxx_eh_abort,
103 .eh_device_reset_handler = qla4xxx_eh_device_reset,
104 .eh_target_reset_handler = qla4xxx_eh_target_reset,
105 .eh_host_reset_handler = qla4xxx_eh_host_reset,
106 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
108 .slave_configure = qla4xxx_slave_configure,
109 .slave_alloc = qla4xxx_slave_alloc,
110 .slave_destroy = qla4xxx_slave_destroy,
112 .scan_finished = iscsi_scan_finished,
113 .scan_start = qla4xxx_scan_start,
117 .use_clustering = ENABLE_CLUSTERING,
118 .sg_tablesize = SG_ALL,
120 .max_sectors = 0xFFFF,
123 static struct iscsi_transport qla4xxx_iscsi_transport = {
124 .owner = THIS_MODULE,
126 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
127 CAP_DATA_PATH_OFFLOAD,
128 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
129 ISCSI_TARGET_NAME | ISCSI_TPGT,
130 .host_param_mask = ISCSI_HOST_HWADDRESS |
131 ISCSI_HOST_IPADDRESS |
132 ISCSI_HOST_INITIATOR_NAME,
133 .tgt_dscvr = qla4xxx_tgt_dscvr,
134 .get_conn_param = qla4xxx_conn_get_param,
135 .get_session_param = qla4xxx_sess_get_param,
136 .get_host_param = qla4xxx_host_get_param,
137 .session_recovery_timedout = qla4xxx_recovery_timedout,
140 static struct scsi_transport_template *qla4xxx_scsi_transport;
142 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
144 struct iscsi_cls_session *session;
145 struct ddb_entry *ddb_entry;
147 session = starget_to_session(scsi_target(sc->device));
148 ddb_entry = session->dd_data;
150 /* if we are not logged in then the LLD is going to clean up the cmd */
151 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
152 return BLK_EH_RESET_TIMER;
154 return BLK_EH_NOT_HANDLED;
157 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
159 struct ddb_entry *ddb_entry = session->dd_data;
160 struct scsi_qla_host *ha = ddb_entry->ha;
162 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
163 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
165 DEBUG2(printk("scsi%ld: %s: ddb [%d] port down retry count "
166 "of (%d) secs exhausted, marking device DEAD.\n",
167 ha->host_no, __func__, ddb_entry->fw_ddb_index,
168 ha->port_down_retry_count));
170 qla4xxx_wake_dpc(ha);
174 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
175 enum iscsi_host_param param, char *buf)
177 struct scsi_qla_host *ha = to_qla_host(shost);
181 case ISCSI_HOST_PARAM_HWADDRESS:
182 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
184 case ISCSI_HOST_PARAM_IPADDRESS:
185 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
186 ha->ip_address[1], ha->ip_address[2],
189 case ISCSI_HOST_PARAM_INITIATOR_NAME:
190 len = sprintf(buf, "%s\n", ha->name_string);
199 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
200 enum iscsi_param param, char *buf)
202 struct ddb_entry *ddb_entry = sess->dd_data;
206 case ISCSI_PARAM_TARGET_NAME:
207 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
208 ddb_entry->iscsi_name);
210 case ISCSI_PARAM_TPGT:
211 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
220 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
221 enum iscsi_param param, char *buf)
223 struct iscsi_cls_session *session;
224 struct ddb_entry *ddb_entry;
227 session = iscsi_dev_to_session(conn->dev.parent);
228 ddb_entry = session->dd_data;
231 case ISCSI_PARAM_CONN_PORT:
232 len = sprintf(buf, "%hu\n", ddb_entry->port);
234 case ISCSI_PARAM_CONN_ADDRESS:
235 /* TODO: what are the ipv6 bits */
236 len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
245 static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
246 enum iscsi_tgt_dscvr type, uint32_t enable,
247 struct sockaddr *dst_addr)
249 struct scsi_qla_host *ha;
250 struct sockaddr_in *addr;
251 struct sockaddr_in6 *addr6;
254 ha = (struct scsi_qla_host *) shost->hostdata;
257 case ISCSI_TGT_DSCVR_SEND_TARGETS:
258 if (dst_addr->sa_family == AF_INET) {
259 addr = (struct sockaddr_in *)dst_addr;
260 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
261 addr->sin_port) != QLA_SUCCESS)
263 } else if (dst_addr->sa_family == AF_INET6) {
265 * TODO: fix qla4xxx_send_tgts
267 addr6 = (struct sockaddr_in6 *)dst_addr;
268 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
269 addr6->sin6_port) != QLA_SUCCESS)
280 void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
282 if (!ddb_entry->sess)
285 if (ddb_entry->conn) {
286 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
287 iscsi_remove_session(ddb_entry->sess);
289 iscsi_free_session(ddb_entry->sess);
292 int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
296 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
297 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
299 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
303 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
304 if (!ddb_entry->conn) {
305 iscsi_remove_session(ddb_entry->sess);
306 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
310 /* finally ready to go */
311 iscsi_unblock_session(ddb_entry->sess);
315 struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
317 struct ddb_entry *ddb_entry;
318 struct iscsi_cls_session *sess;
320 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
321 sizeof(struct ddb_entry));
325 ddb_entry = sess->dd_data;
326 memset(ddb_entry, 0, sizeof(*ddb_entry));
328 ddb_entry->sess = sess;
332 static void qla4xxx_scan_start(struct Scsi_Host *shost)
334 struct scsi_qla_host *ha = shost_priv(shost);
335 struct ddb_entry *ddb_entry, *ddbtemp;
337 /* finish setup of sessions that were already setup in firmware */
338 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
339 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
340 qla4xxx_add_sess(ddb_entry);
348 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
349 unsigned long interval)
351 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
352 __func__, ha->host->host_no));
353 init_timer(&ha->timer);
354 ha->timer.expires = jiffies + interval * HZ;
355 ha->timer.data = (unsigned long)ha;
356 ha->timer.function = (void (*)(unsigned long))func;
357 add_timer(&ha->timer);
358 ha->timer_active = 1;
361 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
363 del_timer_sync(&ha->timer);
364 ha->timer_active = 0;
368 * qla4xxx_mark_device_missing - mark a device as missing.
369 * @ha: Pointer to host adapter structure.
370 * @ddb_entry: Pointer to device database entry
372 * This routine marks a device missing and close connection.
374 void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
375 struct ddb_entry *ddb_entry)
377 if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
378 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
379 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
380 ha->host_no, ddb_entry->fw_ddb_index));
382 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
383 ddb_entry->fw_ddb_index))
385 iscsi_block_session(ddb_entry->sess);
386 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
390 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
391 * @ha: Pointer to host adapter structure.
393 * This routine marks a device missing and resets the relogin retry count.
395 void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
397 struct ddb_entry *ddb_entry, *ddbtemp;
398 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
399 qla4xxx_mark_device_missing(ha, ddb_entry);
403 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
404 struct ddb_entry *ddb_entry,
405 struct scsi_cmnd *cmd,
406 void (*done)(struct scsi_cmnd *))
410 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
414 kref_init(&srb->srb_ref);
416 srb->ddb = ddb_entry;
419 CMD_SP(cmd) = (void *)srb;
420 cmd->scsi_done = done;
425 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
427 struct scsi_cmnd *cmd = srb->cmd;
429 if (srb->flags & SRB_DMA_VALID) {
431 srb->flags &= ~SRB_DMA_VALID;
436 void qla4xxx_srb_compl(struct kref *ref)
438 struct srb *srb = container_of(ref, struct srb, srb_ref);
439 struct scsi_cmnd *cmd = srb->cmd;
440 struct scsi_qla_host *ha = srb->ha;
442 qla4xxx_srb_free_dma(ha, srb);
444 mempool_free(srb, ha->srb_mempool);
450 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
451 * @cmd: Pointer to Linux's SCSI command structure
452 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
453 * that the command has been processed.
456 * This routine is invoked by Linux to send a SCSI command to the driver.
457 * The mid-level driver tries to ensure that queuecommand never gets
458 * invoked concurrently with itself or the interrupt handler (although
459 * the interrupt handler may call this routine as part of request-
460 * completion handling). Unfortunely, it sometimes calls the scheduler
461 * in interrupt context which is a big NO! NO!.
463 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
464 void (*done)(struct scsi_cmnd *))
466 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
467 struct ddb_entry *ddb_entry = cmd->device->hostdata;
468 struct iscsi_cls_session *sess = ddb_entry->sess;
473 cmd->result = DID_IMM_RETRY << 16;
474 goto qc_fail_command;
477 rval = iscsi_session_chkready(sess);
480 goto qc_fail_command;
483 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
484 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
485 cmd->result = DID_NO_CONNECT << 16;
486 goto qc_fail_command;
488 return SCSI_MLQUEUE_TARGET_BUSY;
491 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
492 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
493 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
494 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
495 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
496 !test_bit(AF_ONLINE, &ha->flags) ||
497 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
500 spin_unlock_irq(ha->host->host_lock);
502 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
504 goto qc_host_busy_lock;
506 rval = qla4xxx_send_command_to_isp(ha, srb);
507 if (rval != QLA_SUCCESS)
508 goto qc_host_busy_free_sp;
510 spin_lock_irq(ha->host->host_lock);
513 qc_host_busy_free_sp:
514 qla4xxx_srb_free_dma(ha, srb);
515 mempool_free(srb, ha->srb_mempool);
518 spin_lock_irq(ha->host->host_lock);
521 return SCSI_MLQUEUE_HOST_BUSY;
530 * qla4xxx_mem_free - frees memory allocated to adapter
531 * @ha: Pointer to host adapter structure.
533 * Frees memory previously allocated by qla4xxx_mem_alloc
535 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
538 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
544 ha->request_ring = NULL;
546 ha->response_ring = NULL;
547 ha->response_dma = 0;
548 ha->shadow_regs = NULL;
549 ha->shadow_regs_dma = 0;
553 mempool_destroy(ha->srb_mempool);
555 ha->srb_mempool = NULL;
557 /* release io space registers */
558 if (is_qla8022(ha)) {
561 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
563 if (ha->nx_db_wr_ptr)
565 (struct device_reg_82xx __iomem *)ha->nx_db_wr_ptr);
568 pci_release_regions(ha->pdev);
572 * qla4xxx_mem_alloc - allocates memory for use by adapter.
573 * @ha: Pointer to host adapter structure
575 * Allocates DMA memory for request and response queues. Also allocates memory
578 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
582 /* Allocate contiguous block of DMA memory for queues. */
583 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
584 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
585 sizeof(struct shadow_regs) +
587 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
588 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
589 &ha->queues_dma, GFP_KERNEL);
590 if (ha->queues == NULL) {
591 dev_warn(&ha->pdev->dev,
592 "Memory Allocation failed - queues.\n");
594 goto mem_alloc_error_exit;
596 memset(ha->queues, 0, ha->queues_len);
599 * As per RISC alignment requirements -- the bus-address must be a
600 * multiple of the request-ring size (in bytes).
603 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
604 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
605 (MEM_ALIGN_VALUE - 1));
607 /* Update request and response queue pointers. */
608 ha->request_dma = ha->queues_dma + align;
609 ha->request_ring = (struct queue_entry *) (ha->queues + align);
610 ha->response_dma = ha->queues_dma + align +
611 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
612 ha->response_ring = (struct queue_entry *) (ha->queues + align +
613 (REQUEST_QUEUE_DEPTH *
615 ha->shadow_regs_dma = ha->queues_dma + align +
616 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
617 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
618 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
619 (REQUEST_QUEUE_DEPTH *
621 (RESPONSE_QUEUE_DEPTH *
624 /* Allocate memory for srb pool. */
625 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
626 mempool_free_slab, srb_cachep);
627 if (ha->srb_mempool == NULL) {
628 dev_warn(&ha->pdev->dev,
629 "Memory Allocation failed - SRB Pool.\n");
631 goto mem_alloc_error_exit;
636 mem_alloc_error_exit:
637 qla4xxx_mem_free(ha);
642 * qla4_8xxx_check_fw_alive - Check firmware health
643 * @ha: Pointer to host adapter structure.
647 static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
649 uint32_t fw_heartbeat_counter, halt_status;
651 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
653 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
654 ha->seconds_since_last_heartbeat++;
655 /* FW not alive after 2 seconds */
656 if (ha->seconds_since_last_heartbeat == 2) {
657 ha->seconds_since_last_heartbeat = 0;
658 halt_status = qla4_8xxx_rd_32(ha,
659 QLA82XX_PEG_HALT_STATUS1);
660 /* Since we cannot change dev_state in interrupt
661 * context, set appropriate DPC flag then wakeup
663 if (halt_status & HALT_STATUS_UNRECOVERABLE)
664 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
666 printk("scsi%ld: %s: detect abort needed!\n",
667 ha->host_no, __func__);
668 set_bit(DPC_RESET_HA, &ha->dpc_flags);
670 qla4xxx_wake_dpc(ha);
673 ha->fw_heartbeat_counter = fw_heartbeat_counter;
677 * qla4_8xxx_watchdog - Poll dev state
678 * @ha: Pointer to host adapter structure.
682 void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
686 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
688 /* don't poll if reset is going on */
689 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags)) {
690 if (dev_state == QLA82XX_DEV_NEED_RESET &&
691 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
692 printk("scsi%ld: %s: HW State: NEED RESET!\n",
693 ha->host_no, __func__);
694 set_bit(DPC_RESET_HA, &ha->dpc_flags);
695 qla4xxx_wake_dpc(ha);
696 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
697 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
698 printk("scsi%ld: %s: HW State: NEED QUIES!\n",
699 ha->host_no, __func__);
700 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
701 qla4xxx_wake_dpc(ha);
703 /* Check firmware health */
704 qla4_8xxx_check_fw_alive(ha);
710 * qla4xxx_timer - checks every second for work to do.
711 * @ha: Pointer to host adapter structure.
713 static void qla4xxx_timer(struct scsi_qla_host *ha)
715 struct ddb_entry *ddb_entry, *dtemp;
718 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
719 DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n",
724 if (is_qla8022(ha)) {
725 qla4_8xxx_watchdog(ha);
728 /* Search for relogin's to time-out and port down retry. */
729 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
730 /* Count down time between sending relogins */
731 if (adapter_up(ha) &&
732 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
733 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
734 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
736 if (atomic_read(&ddb_entry->retry_relogin_timer)
738 atomic_set(&ddb_entry->
741 set_bit(DPC_RELOGIN_DEVICE,
743 set_bit(DF_RELOGIN, &ddb_entry->flags);
744 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
746 ha->host_no, __func__,
747 ddb_entry->fw_ddb_index));
749 atomic_dec(&ddb_entry->
750 retry_relogin_timer);
754 /* Wait for relogin to timeout */
755 if (atomic_read(&ddb_entry->relogin_timer) &&
756 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
758 * If the relogin times out and the device is
759 * still NOT ONLINE then try and relogin again.
761 if (atomic_read(&ddb_entry->state) !=
763 ddb_entry->fw_ddb_device_state ==
764 DDB_DS_SESSION_FAILED) {
765 /* Reset retry relogin timer */
766 atomic_inc(&ddb_entry->relogin_retry_count);
767 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
768 " timed out-retrying"
771 ddb_entry->fw_ddb_index,
772 atomic_read(&ddb_entry->
773 relogin_retry_count))
776 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
777 "initate relogin after"
779 ha->host_no, ddb_entry->bus,
781 ddb_entry->fw_ddb_index,
782 ddb_entry->default_time2wait + 4)
785 atomic_set(&ddb_entry->retry_relogin_timer,
786 ddb_entry->default_time2wait + 4);
791 if (!is_qla8022(ha)) {
792 /* Check for heartbeat interval. */
793 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
794 ha->heartbeat_interval != 0) {
795 ha->seconds_since_last_heartbeat++;
796 if (ha->seconds_since_last_heartbeat >
797 ha->heartbeat_interval + 2)
798 set_bit(DPC_RESET_HA, &ha->dpc_flags);
802 /* Wakeup the dpc routine for this adapter, if needed. */
804 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
805 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
806 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
807 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
808 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
809 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
810 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
811 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
812 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
813 test_bit(DPC_AEN, &ha->dpc_flags)) &&
814 !test_bit(AF_DPC_SCHEDULED, &ha->flags) &&
816 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
817 " - dpc flags = 0x%lx\n",
818 ha->host_no, __func__, ha->dpc_flags));
819 qla4xxx_wake_dpc(ha);
822 /* Reschedule timer thread to call us back in one second */
823 mod_timer(&ha->timer, jiffies + HZ);
825 DEBUG2(ha->seconds_since_last_intr++);
829 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
830 * @ha: Pointer to host adapter structure.
832 * This routine stalls the driver until all outstanding commands are returned.
833 * Caller must release the Hardware Lock prior to calling this routine.
835 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
839 struct scsi_cmnd *cmd;
841 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
843 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
844 "complete\n", WAIT_CMD_TOV));
846 while (!time_after_eq(jiffies, wtime)) {
847 spin_lock_irqsave(&ha->hardware_lock, flags);
848 /* Find a command that hasn't completed. */
849 for (index = 0; index < ha->host->can_queue; index++) {
850 cmd = scsi_host_find_tag(ha->host, index);
854 spin_unlock_irqrestore(&ha->hardware_lock, flags);
856 /* If No Commands are pending, wait is complete */
857 if (index == ha->host->can_queue)
862 /* If we timed out on waiting for commands to come back
867 int qla4xxx_hw_reset(struct scsi_qla_host *ha)
869 uint32_t ctrl_status;
870 unsigned long flags = 0;
872 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
874 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
877 spin_lock_irqsave(&ha->hardware_lock, flags);
880 * If the SCSI Reset Interrupt bit is set, clear it.
881 * Otherwise, the Soft Reset won't work.
883 ctrl_status = readw(&ha->reg->ctrl_status);
884 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
885 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
887 /* Issue Soft Reset */
888 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
889 readl(&ha->reg->ctrl_status);
891 spin_unlock_irqrestore(&ha->hardware_lock, flags);
896 * qla4xxx_soft_reset - performs soft reset.
897 * @ha: Pointer to host adapter structure.
899 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
901 uint32_t max_wait_time;
902 unsigned long flags = 0;
903 int status = QLA_ERROR;
904 uint32_t ctrl_status;
906 qla4xxx_hw_reset(ha);
908 /* Wait until the Network Reset Intr bit is cleared */
909 max_wait_time = RESET_INTR_TOV;
911 spin_lock_irqsave(&ha->hardware_lock, flags);
912 ctrl_status = readw(&ha->reg->ctrl_status);
913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
915 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
919 } while ((--max_wait_time));
921 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
922 DEBUG2(printk(KERN_WARNING
923 "scsi%ld: Network Reset Intr not cleared by "
924 "Network function, clearing it now!\n",
926 spin_lock_irqsave(&ha->hardware_lock, flags);
927 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
928 readl(&ha->reg->ctrl_status);
929 spin_unlock_irqrestore(&ha->hardware_lock, flags);
932 /* Wait until the firmware tells us the Soft Reset is done */
933 max_wait_time = SOFT_RESET_TOV;
935 spin_lock_irqsave(&ha->hardware_lock, flags);
936 ctrl_status = readw(&ha->reg->ctrl_status);
937 spin_unlock_irqrestore(&ha->hardware_lock, flags);
939 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
940 status = QLA_SUCCESS;
945 } while ((--max_wait_time));
948 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
949 * after the soft reset has taken place.
951 spin_lock_irqsave(&ha->hardware_lock, flags);
952 ctrl_status = readw(&ha->reg->ctrl_status);
953 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
954 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
955 readl(&ha->reg->ctrl_status);
957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
959 /* If soft reset fails then most probably the bios on other
960 * function is also enabled.
961 * Since the initialization is sequential the other fn
962 * wont be able to acknowledge the soft reset.
963 * Issue a force soft reset to workaround this scenario.
965 if (max_wait_time == 0) {
966 /* Issue Force Soft Reset */
967 spin_lock_irqsave(&ha->hardware_lock, flags);
968 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
969 readl(&ha->reg->ctrl_status);
970 spin_unlock_irqrestore(&ha->hardware_lock, flags);
971 /* Wait until the firmware tells us the Soft Reset is done */
972 max_wait_time = SOFT_RESET_TOV;
974 spin_lock_irqsave(&ha->hardware_lock, flags);
975 ctrl_status = readw(&ha->reg->ctrl_status);
976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
978 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
979 status = QLA_SUCCESS;
984 } while ((--max_wait_time));
991 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
992 * @ha: Pointer to host adapter structure.
993 * @res: returned scsi status
995 * This routine is called just prior to a HARD RESET to return all
996 * outstanding commands back to the Operating System.
997 * Caller should make sure that the following locks are released
998 * before this calling routine: Hardware lock, and io_request_lock.
1000 static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
1004 unsigned long flags;
1006 spin_lock_irqsave(&ha->hardware_lock, flags);
1007 for (i = 0; i < ha->host->can_queue; i++) {
1008 srb = qla4xxx_del_from_active_array(ha, i);
1010 srb->cmd->result = res;
1011 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
1014 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1017 void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
1019 clear_bit(AF_ONLINE, &ha->flags);
1021 /* Disable the board */
1022 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
1023 set_bit(AF_HBA_GOING_AWAY, &ha->flags);
1025 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
1026 qla4xxx_mark_all_devices_missing(ha);
1027 clear_bit(AF_INIT_DONE, &ha->flags);
1031 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1032 * @ha: Pointer to host adapter structure.
1034 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
1036 int status = QLA_ERROR;
1037 uint8_t reset_chip = 0;
1039 /* Stall incoming I/O until we are done */
1040 scsi_block_requests(ha->host);
1041 clear_bit(AF_ONLINE, &ha->flags);
1043 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
1045 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1047 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1050 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1051 * do not reset adapter, jump to initialize_adapter */
1052 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1053 status = QLA_SUCCESS;
1054 goto recover_ha_init_adapter;
1057 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1058 * from eh_host_reset or ioctl module */
1059 if (is_qla8022(ha) && !reset_chip &&
1060 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
1062 DEBUG2(ql4_printk(KERN_INFO, ha,
1063 "scsi%ld: %s - Performing stop_firmware...\n",
1064 ha->host_no, __func__));
1065 status = ha->isp_ops->reset_firmware(ha);
1066 if (status == QLA_SUCCESS) {
1067 qla4xxx_cmd_wait(ha);
1068 ha->isp_ops->disable_intrs(ha);
1069 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1070 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1072 /* If the stop_firmware fails then
1073 * reset the entire chip */
1075 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1076 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1080 /* Issue full chip reset if recovering from a catastrophic error,
1081 * or if stop_firmware fails for ISP-82xx.
1082 * This is the default case for ISP-4xxx */
1083 if (!is_qla8022(ha) || reset_chip) {
1084 qla4xxx_cmd_wait(ha);
1085 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1086 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1087 DEBUG2(ql4_printk(KERN_INFO, ha,
1088 "scsi%ld: %s - Performing chip reset..\n",
1089 ha->host_no, __func__));
1090 status = ha->isp_ops->reset_chip(ha);
1093 /* Flush any pending ddb changed AENs */
1094 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1096 recover_ha_init_adapter:
1097 /* Upon successful firmware/chip reset, re-initialize the adapter */
1098 if (status == QLA_SUCCESS) {
1099 /* For ISP-4xxx, force function 1 to always initialize
1100 * before function 3 to prevent both funcions from
1101 * stepping on top of the other */
1102 if (!is_qla8022(ha) && (ha->mac_index == 3))
1105 /* NOTE: AF_ONLINE flag set upon successful completion of
1106 * qla4xxx_initialize_adapter */
1107 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1110 /* Retry failed adapter initialization, if necessary
1111 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1112 * case to prevent ping-pong resets between functions */
1113 if (!test_bit(AF_ONLINE, &ha->flags) &&
1114 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1115 /* Adapter initialization failed, see if we can retry
1117 * Since we don't want to block the DPC for too long
1118 * with multiple resets in the same thread,
1119 * utilize DPC to retry */
1120 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1121 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1122 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1123 "(%d) more times\n", ha->host_no,
1124 ha->retry_reset_ha_cnt));
1125 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1128 if (ha->retry_reset_ha_cnt > 0) {
1129 /* Schedule another Reset HA--DPC will retry */
1130 ha->retry_reset_ha_cnt--;
1131 DEBUG2(printk("scsi%ld: recover adapter - "
1132 "retry remaining %d\n",
1134 ha->retry_reset_ha_cnt));
1138 if (ha->retry_reset_ha_cnt == 0) {
1139 /* Recover adapter retries have been exhausted.
1141 DEBUG2(printk("scsi%ld: recover adapter "
1142 "failed - board disabled\n",
1144 qla4xxx_dead_adapter_cleanup(ha);
1145 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1146 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1147 clear_bit(DPC_RESET_HA_FW_CONTEXT,
1153 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1154 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1155 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1158 ha->adapter_error_count++;
1160 if (test_bit(AF_ONLINE, &ha->flags))
1161 ha->isp_ops->enable_intrs(ha);
1163 scsi_unblock_requests(ha->host);
1165 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1166 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
1167 status == QLA_ERROR ? "FAILED" : "SUCCEDED"));
1172 void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
1174 if (ha->dpc_thread &&
1175 !test_bit(AF_DPC_SCHEDULED, &ha->flags)) {
1176 set_bit(AF_DPC_SCHEDULED, &ha->flags);
1177 queue_work(ha->dpc_thread, &ha->dpc_work);
1182 * qla4xxx_do_dpc - dpc routine
1183 * @data: in our case pointer to adapter structure
1185 * This routine is a task that is schedule by the interrupt handler
1186 * to perform the background processing for interrupts. We put it
1187 * on a task queue that is consumed whenever the scheduler runs; that's
1188 * so you can do anything (i.e. put the process to sleep etc). In fact,
1189 * the mid-level tries to sleep when it reaches the driver threshold
1190 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1192 static void qla4xxx_do_dpc(struct work_struct *work)
1194 struct scsi_qla_host *ha =
1195 container_of(work, struct scsi_qla_host, dpc_work);
1196 struct ddb_entry *ddb_entry, *dtemp;
1197 int status = QLA_ERROR;
1199 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
1200 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1201 ha->host_no, __func__, ha->flags, ha->dpc_flags))
1203 /* Initialization not yet finished. Don't do anything yet. */
1204 if (!test_bit(AF_INIT_DONE, &ha->flags))
1207 /* HBA is in the process of being permanently disabled.
1208 * Don't process anything */
1209 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags))
1212 if (is_qla8022(ha)) {
1213 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
1214 qla4_8xxx_idc_lock(ha);
1215 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1216 QLA82XX_DEV_FAILED);
1217 qla4_8xxx_idc_unlock(ha);
1218 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
1219 qla4_8xxx_device_state_handler(ha);
1221 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1222 qla4_8xxx_need_qsnt_handler(ha);
1226 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
1227 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1228 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1229 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
1230 if (ql4xdontresethba) {
1231 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1232 ha->host_no, __func__));
1233 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1234 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1235 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1236 goto dpc_post_reset_ha;
1238 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1239 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1240 qla4xxx_recover_adapter(ha);
1242 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1243 uint8_t wait_time = RESET_INTR_TOV;
1245 while ((readw(&ha->reg->ctrl_status) &
1246 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1247 if (--wait_time == 0)
1252 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1253 "bit not cleared-- resetting\n",
1254 ha->host_no, __func__));
1255 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1256 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1257 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1258 status = qla4xxx_recover_adapter(ha);
1260 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1261 if (status == QLA_SUCCESS)
1262 ha->isp_ops->enable_intrs(ha);
1267 /* ---- process AEN? --- */
1268 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1269 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1271 /* ---- Get DHCP IP Address? --- */
1272 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1273 qla4xxx_get_dhcp_ip_address(ha);
1275 /* ---- link change? --- */
1276 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
1277 if (!test_bit(AF_LINK_UP, &ha->flags)) {
1278 /* ---- link down? --- */
1279 list_for_each_entry_safe(ddb_entry, dtemp,
1280 &ha->ddb_list, list) {
1281 if (atomic_read(&ddb_entry->state) ==
1283 qla4xxx_mark_device_missing(ha,
1287 /* ---- link up? --- *
1288 * F/W will auto login to all devices ONLY ONCE after
1289 * link up during driver initialization and runtime
1290 * fatal error recovery. Therefore, the driver must
1291 * manually relogin to devices when recovering from
1292 * connection failures, logouts, expired KATO, etc. */
1294 list_for_each_entry_safe(ddb_entry, dtemp,
1295 &ha->ddb_list, list) {
1296 if ((atomic_read(&ddb_entry->state) ==
1297 DDB_STATE_MISSING) ||
1298 (atomic_read(&ddb_entry->state) ==
1300 if (ddb_entry->fw_ddb_device_state ==
1301 DDB_DS_SESSION_ACTIVE) {
1302 atomic_set(&ddb_entry->state,
1304 dev_info(&ha->pdev->dev,
1305 "scsi%ld: %s: ddb[%d]"
1307 ha->host_no, __func__,
1308 ddb_entry->fw_ddb_index);
1310 iscsi_unblock_session(
1313 qla4xxx_relogin_device(
1321 /* ---- relogin device? --- */
1322 if (adapter_up(ha) &&
1323 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1324 list_for_each_entry_safe(ddb_entry, dtemp,
1325 &ha->ddb_list, list) {
1326 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1327 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1328 qla4xxx_relogin_device(ha, ddb_entry);
1331 * If mbx cmd times out there is no point
1332 * in continuing further.
1333 * With large no of targets this can hang
1336 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1337 printk(KERN_WARNING "scsi%ld: %s: "
1338 "need to reset hba\n",
1339 ha->host_no, __func__);
1344 clear_bit(AF_DPC_SCHEDULED, &ha->flags);
1348 * qla4xxx_free_adapter - release the adapter
1349 * @ha: pointer to adapter structure
1351 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1354 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1355 /* Turn-off interrupts on the card. */
1356 ha->isp_ops->disable_intrs(ha);
1359 /* Remove timer thread, if present */
1360 if (ha->timer_active)
1361 qla4xxx_stop_timer(ha);
1363 /* Kill the kernel thread for this host */
1365 destroy_workqueue(ha->dpc_thread);
1367 /* Put firmware in known state */
1368 ha->isp_ops->reset_firmware(ha);
1370 if (is_qla8022(ha)) {
1371 qla4_8xxx_idc_lock(ha);
1372 qla4_8xxx_clear_drv_active(ha);
1373 qla4_8xxx_idc_unlock(ha);
1376 /* Detach interrupts */
1377 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1378 qla4xxx_free_irqs(ha);
1380 /* free extra memory */
1381 qla4xxx_mem_free(ha);
1384 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1387 uint8_t revision_id;
1388 unsigned long mem_base, mem_len, db_base, db_len;
1389 struct pci_dev *pdev = ha->pdev;
1391 status = pci_request_regions(pdev, DRIVER_NAME);
1394 "scsi(%ld) Failed to reserve PIO regions (%s) "
1395 "status=%d\n", ha->host_no, pci_name(pdev), status);
1396 goto iospace_error_exit;
1399 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
1400 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
1401 __func__, revision_id));
1402 ha->revision_id = revision_id;
1404 /* remap phys address */
1405 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
1406 mem_len = pci_resource_len(pdev, 0);
1407 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
1408 __func__, mem_base, mem_len));
1410 /* mapping of pcibase pointer */
1411 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
1412 if (!ha->nx_pcibase) {
1414 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
1415 pci_release_regions(ha->pdev);
1416 goto iospace_error_exit;
1419 /* Mapping of IO base pointer, door bell read and write pointer */
1421 /* mapping of IO base pointer */
1423 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
1424 0xbc000 + (ha->pdev->devfn << 11));
1426 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
1427 db_len = pci_resource_len(pdev, 4);
1429 /* mapping of doorbell write pointer */
1430 ha->nx_db_wr_ptr = (unsigned long)ioremap(db_base +
1431 (ha->pdev->devfn << 12), 4);
1432 if (!ha->nx_db_wr_ptr) {
1434 "cannot remap MMIO doorbell-write (%s), aborting\n",
1436 goto iospace_error_exit;
1438 /* mapping of doorbell read pointer */
1439 ha->nx_db_rd_ptr = (uint8_t *) ha->nx_pcibase + (512 * 1024) +
1440 (ha->pdev->devfn * 8);
1441 if (!ha->nx_db_rd_ptr)
1443 "cannot remap MMIO doorbell-read (%s), aborting\n",
1452 * qla4xxx_iospace_config - maps registers
1453 * @ha: pointer to adapter structure
1455 * This routines maps HBA's registers from the pci address space
1456 * into the kernel virtual address space for memory mapped i/o.
1458 int qla4xxx_iospace_config(struct scsi_qla_host *ha)
1460 unsigned long pio, pio_len, pio_flags;
1461 unsigned long mmio, mmio_len, mmio_flags;
1463 pio = pci_resource_start(ha->pdev, 0);
1464 pio_len = pci_resource_len(ha->pdev, 0);
1465 pio_flags = pci_resource_flags(ha->pdev, 0);
1466 if (pio_flags & IORESOURCE_IO) {
1467 if (pio_len < MIN_IOBASE_LEN) {
1468 dev_warn(&ha->pdev->dev,
1469 "Invalid PCI I/O region size\n");
1473 dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
1477 /* Use MMIO operations for all accesses. */
1478 mmio = pci_resource_start(ha->pdev, 1);
1479 mmio_len = pci_resource_len(ha->pdev, 1);
1480 mmio_flags = pci_resource_flags(ha->pdev, 1);
1482 if (!(mmio_flags & IORESOURCE_MEM)) {
1483 dev_err(&ha->pdev->dev,
1484 "region #0 not an MMIO resource, aborting\n");
1486 goto iospace_error_exit;
1488 if (mmio_len < MIN_IOBASE_LEN) {
1489 dev_err(&ha->pdev->dev,
1490 "Invalid PCI mem region size, aborting\n");
1491 goto iospace_error_exit;
1494 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
1495 dev_warn(&ha->pdev->dev,
1496 "Failed to reserve PIO/MMIO regions\n");
1498 goto iospace_error_exit;
1501 ha->pio_address = pio;
1502 ha->pio_length = pio_len;
1503 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1505 dev_err(&ha->pdev->dev,
1506 "cannot remap MMIO, aborting\n");
1508 goto iospace_error_exit;
1517 static struct isp_operations qla4xxx_isp_ops = {
1518 .iospace_config = qla4xxx_iospace_config,
1519 .pci_config = qla4xxx_pci_config,
1520 .disable_intrs = qla4xxx_disable_intrs,
1521 .enable_intrs = qla4xxx_enable_intrs,
1522 .start_firmware = qla4xxx_start_firmware,
1523 .intr_handler = qla4xxx_intr_handler,
1524 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
1525 .reset_chip = qla4xxx_soft_reset,
1526 .reset_firmware = qla4xxx_hw_reset,
1527 .queue_iocb = qla4xxx_queue_iocb,
1528 .complete_iocb = qla4xxx_complete_iocb,
1529 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
1530 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
1531 .get_sys_info = qla4xxx_get_sys_info,
1534 static struct isp_operations qla4_8xxx_isp_ops = {
1535 .iospace_config = qla4_8xxx_iospace_config,
1536 .pci_config = qla4_8xxx_pci_config,
1537 .disable_intrs = qla4_8xxx_disable_intrs,
1538 .enable_intrs = qla4_8xxx_enable_intrs,
1539 .start_firmware = qla4_8xxx_load_risc,
1540 .intr_handler = qla4_8xxx_intr_handler,
1541 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
1542 .reset_chip = qla4_8xxx_isp_reset,
1543 .reset_firmware = qla4_8xxx_stop_firmware,
1544 .queue_iocb = qla4_8xxx_queue_iocb,
1545 .complete_iocb = qla4_8xxx_complete_iocb,
1546 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
1547 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
1548 .get_sys_info = qla4_8xxx_get_sys_info,
1551 uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1553 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
1556 uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1558 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
1561 uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1563 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
1566 uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1568 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
1572 * qla4xxx_probe_adapter - callback function to probe HBA
1573 * @pdev: pointer to pci_dev structure
1574 * @pci_device_id: pointer to pci_device entry
1576 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1577 * It returns zero if successful. It also initializes all data necessary for
1580 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1581 const struct pci_device_id *ent)
1583 int ret = -ENODEV, status;
1584 struct Scsi_Host *host;
1585 struct scsi_qla_host *ha;
1586 uint8_t init_retry_count = 0;
1588 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
1590 if (pci_enable_device(pdev))
1593 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1596 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1597 goto probe_disable_device;
1600 /* Clear our data area */
1601 ha = (struct scsi_qla_host *) host->hostdata;
1602 memset(ha, 0, sizeof(*ha));
1604 /* Save the information from PCI BIOS. */
1607 ha->host_no = host->host_no;
1609 /* Setup Runtime configurable options */
1610 if (is_qla8022(ha)) {
1611 ha->isp_ops = &qla4_8xxx_isp_ops;
1612 rwlock_init(&ha->hw_lock);
1613 ha->qdr_sn_window = -1;
1614 ha->ddr_mn_window = -1;
1615 ha->curr_window = 255;
1616 ha->func_num = PCI_FUNC(ha->pdev->devfn);
1617 nx_legacy_intr = &legacy_intr[ha->func_num];
1618 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
1619 ha->nx_legacy_intr.tgt_status_reg =
1620 nx_legacy_intr->tgt_status_reg;
1621 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
1622 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
1624 ha->isp_ops = &qla4xxx_isp_ops;
1627 /* Configure PCI I/O space. */
1628 ret = ha->isp_ops->iospace_config(ha);
1630 goto probe_failed_ioconfig;
1632 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1633 pdev->device, pdev->irq, ha->reg);
1635 qla4xxx_config_dma_addressing(ha);
1637 /* Initialize lists and spinlocks. */
1638 INIT_LIST_HEAD(&ha->ddb_list);
1639 INIT_LIST_HEAD(&ha->free_srb_q);
1641 mutex_init(&ha->mbox_sem);
1642 init_completion(&ha->mbx_intr_comp);
1644 spin_lock_init(&ha->hardware_lock);
1646 /* Allocate dma buffers */
1647 if (qla4xxx_mem_alloc(ha)) {
1648 dev_warn(&ha->pdev->dev,
1649 "[ERROR] Failed to allocate memory for adapter\n");
1656 (void) qla4_8xxx_get_flash_info(ha);
1659 * Initialize the Host adapter request/response queues and
1661 * NOTE: interrupts enabled upon successful completion
1663 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1664 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
1665 init_retry_count++ < MAX_INIT_RETRIES) {
1666 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1667 "(%d)\n", __func__, init_retry_count));
1669 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
1672 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1675 if (!test_bit(AF_ONLINE, &ha->flags)) {
1676 dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
1682 host->cmd_per_lun = 3;
1683 host->max_channel = 0;
1684 host->max_lun = MAX_LUNS - 1;
1685 host->max_id = MAX_TARGETS;
1686 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1687 host->can_queue = MAX_SRBS ;
1688 host->transportt = qla4xxx_scsi_transport;
1690 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1692 dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
1696 /* Startup the kernel thread for this host adapter. */
1697 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1698 "qla4xxx_dpc\n", __func__));
1699 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1700 ha->dpc_thread = create_singlethread_workqueue(buf);
1701 if (!ha->dpc_thread) {
1702 dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
1706 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
1708 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
1709 * (which is called indirectly by qla4xxx_initialize_adapter),
1710 * so that irqs will be registered after crbinit but before
1713 if (!is_qla8022(ha)) {
1714 ret = qla4xxx_request_irqs(ha);
1716 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
1717 "interrupt %d already in use.\n", pdev->irq);
1722 ha->isp_ops->enable_intrs(ha);
1724 /* Start timer thread. */
1725 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1727 set_bit(AF_INIT_DONE, &ha->flags);
1729 pci_set_drvdata(pdev, ha);
1731 ret = scsi_add_host(host, &pdev->dev);
1736 " QLogic iSCSI HBA Driver version: %s\n"
1737 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1738 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1739 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1740 ha->patch_number, ha->build_number);
1741 scsi_scan_host(host);
1745 qla4xxx_free_adapter(ha);
1747 probe_failed_ioconfig:
1748 scsi_host_put(ha->host);
1750 probe_disable_device:
1751 pci_disable_device(pdev);
1757 * qla4xxx_remove_adapter - calback function to remove adapter.
1758 * @pci_dev: PCI device pointer
1760 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1762 struct scsi_qla_host *ha;
1764 ha = pci_get_drvdata(pdev);
1766 set_bit(AF_HBA_GOING_AWAY, &ha->flags);
1768 /* remove devs from iscsi_sessions to scsi_devices */
1769 qla4xxx_free_ddb_list(ha);
1771 scsi_remove_host(ha->host);
1773 qla4xxx_free_adapter(ha);
1775 scsi_host_put(ha->host);
1777 pci_disable_device(pdev);
1778 pci_set_drvdata(pdev, NULL);
1782 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1785 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1786 * supported addressing method.
1788 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
1792 /* Update our PCI device dma_mask for full 64 bit mask */
1793 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
1794 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1795 dev_dbg(&ha->pdev->dev,
1796 "Failed to set 64 bit PCI consistent mask; "
1798 retval = pci_set_consistent_dma_mask(ha->pdev,
1802 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1805 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1807 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1808 struct ddb_entry *ddb = sess->dd_data;
1810 sdev->hostdata = ddb;
1811 sdev->tagged_supported = 1;
1812 scsi_activate_tcq(sdev, QL4_DEF_QDEPTH);
1816 static int qla4xxx_slave_configure(struct scsi_device *sdev)
1818 sdev->tagged_supported = 1;
1822 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1824 scsi_deactivate_tcq(sdev, 1);
1828 * qla4xxx_del_from_active_array - returns an active srb
1829 * @ha: Pointer to host adapter structure.
1830 * @index: index into the active_array
1832 * This routine removes and returns the srb at the specified index
1834 struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
1837 struct srb *srb = NULL;
1838 struct scsi_cmnd *cmd = NULL;
1840 cmd = scsi_host_find_tag(ha->host, index);
1844 srb = (struct srb *)CMD_SP(cmd);
1848 /* update counters */
1849 if (srb->flags & SRB_DMA_VALID) {
1850 ha->req_q_count += srb->iocb_cnt;
1851 ha->iocb_cnt -= srb->iocb_cnt;
1853 srb->cmd->host_scribble =
1854 (unsigned char *)(unsigned long) MAX_SRBS;
1860 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1861 * @ha: Pointer to host adapter structure.
1862 * @cmd: Scsi Command to wait on.
1864 * This routine waits for the command to be returned by the Firmware
1865 * for some max time.
1867 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1868 struct scsi_cmnd *cmd)
1872 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1875 /* Checking to see if its returned to OS */
1876 rp = (struct srb *) CMD_SP(cmd);
1883 } while (max_wait_time--);
1889 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1890 * @ha: Pointer to host adapter structure
1892 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1894 unsigned long wait_online;
1896 wait_online = jiffies + (30 * HZ);
1897 while (time_before(jiffies, wait_online)) {
1901 else if (ha->retry_reset_ha_cnt == 0)
1911 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
1912 * @ha: pointer to HBA
1916 * This function waits for all outstanding commands to a lun to complete. It
1917 * returns 0 if all pending commands are returned and 1 otherwise.
1919 static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
1920 struct scsi_target *stgt,
1921 struct scsi_device *sdev)
1925 struct scsi_cmnd *cmd;
1928 * Waiting for all commands for the designated target or dev
1929 * in the active array
1931 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1932 cmd = scsi_host_find_tag(ha->host, cnt);
1933 if (cmd && stgt == scsi_target(cmd->device) &&
1934 (!sdev || sdev == cmd->device)) {
1935 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1945 * qla4xxx_eh_abort - callback for abort task.
1946 * @cmd: Pointer to Linux's SCSI command structure
1948 * This routine is called by the Linux OS to abort the specified
1951 static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
1953 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1954 unsigned int id = cmd->device->id;
1955 unsigned int lun = cmd->device->lun;
1956 unsigned long serial = cmd->serial_number;
1957 struct srb *srb = NULL;
1961 dev_info(&ha->pdev->dev,
1962 "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n",
1963 ha->host_no, id, lun, cmd, serial);
1965 srb = (struct srb *) CMD_SP(cmd);
1970 kref_get(&srb->srb_ref);
1972 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
1973 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
1974 ha->host_no, id, lun));
1977 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
1978 ha->host_no, id, lun));
1982 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
1984 /* Wait for command to complete */
1986 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1987 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
1988 ha->host_no, id, lun));
1993 dev_info(&ha->pdev->dev,
1994 "scsi%ld:%d:%d: Abort command - %s\n",
1995 ha->host_no, id, lun, (ret == SUCCESS) ? "succeded" : "failed");
2001 * qla4xxx_eh_device_reset - callback for target reset.
2002 * @cmd: Pointer to Linux's SCSI command structure
2004 * This routine is called by the Linux OS to reset all luns on the
2007 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
2009 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2010 struct ddb_entry *ddb_entry = cmd->device->hostdata;
2011 int ret = FAILED, stat;
2016 dev_info(&ha->pdev->dev,
2017 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2018 cmd->device->channel, cmd->device->id, cmd->device->lun);
2020 DEBUG2(printk(KERN_INFO
2021 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2022 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
2023 cmd, jiffies, cmd->request->timeout / HZ,
2024 ha->dpc_flags, cmd->result, cmd->allowed));
2026 /* FIXME: wait for hba to go online */
2027 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
2028 if (stat != QLA_SUCCESS) {
2029 dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
2030 goto eh_dev_reset_done;
2033 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2035 dev_info(&ha->pdev->dev,
2036 "DEVICE RESET FAILED - waiting for "
2038 goto eh_dev_reset_done;
2042 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2043 MM_LUN_RESET) != QLA_SUCCESS)
2044 goto eh_dev_reset_done;
2046 dev_info(&ha->pdev->dev,
2047 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2048 ha->host_no, cmd->device->channel, cmd->device->id,
2059 * qla4xxx_eh_target_reset - callback for target reset.
2060 * @cmd: Pointer to Linux's SCSI command structure
2062 * This routine is called by the Linux OS to reset the target.
2064 static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
2066 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2067 struct ddb_entry *ddb_entry = cmd->device->hostdata;
2073 starget_printk(KERN_INFO, scsi_target(cmd->device),
2074 "WARM TARGET RESET ISSUED.\n");
2076 DEBUG2(printk(KERN_INFO
2077 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2078 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
2079 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
2080 ha->dpc_flags, cmd->result, cmd->allowed));
2082 stat = qla4xxx_reset_target(ha, ddb_entry);
2083 if (stat != QLA_SUCCESS) {
2084 starget_printk(KERN_INFO, scsi_target(cmd->device),
2085 "WARM TARGET RESET FAILED.\n");
2089 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2091 starget_printk(KERN_INFO, scsi_target(cmd->device),
2092 "WARM TARGET DEVICE RESET FAILED - "
2093 "waiting for commands.\n");
2098 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2099 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
2100 starget_printk(KERN_INFO, scsi_target(cmd->device),
2101 "WARM TARGET DEVICE RESET FAILED - "
2102 "marker iocb failed.\n");
2106 starget_printk(KERN_INFO, scsi_target(cmd->device),
2107 "WARM TARGET RESET SUCCEEDED.\n");
2112 * qla4xxx_eh_host_reset - kernel callback
2113 * @cmd: Pointer to Linux's SCSI command structure
2115 * This routine is invoked by the Linux kernel to perform fatal error
2116 * recovery on the specified adapter.
2118 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2120 int return_status = FAILED;
2121 struct scsi_qla_host *ha;
2123 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
2125 if (ql4xdontresethba) {
2126 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2127 ha->host_no, __func__));
2131 dev_info(&ha->pdev->dev,
2132 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
2133 cmd->device->channel, cmd->device->id, cmd->device->lun);
2135 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2136 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2137 "DEAD.\n", ha->host_no, cmd->device->channel,
2143 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2145 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2147 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2150 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
2151 return_status = SUCCESS;
2153 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
2154 return_status == FAILED ? "FAILED" : "SUCCEDED");
2156 return return_status;
2159 static struct pci_device_id qla4xxx_pci_tbl[] = {
2161 .vendor = PCI_VENDOR_ID_QLOGIC,
2162 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
2163 .subvendor = PCI_ANY_ID,
2164 .subdevice = PCI_ANY_ID,
2167 .vendor = PCI_VENDOR_ID_QLOGIC,
2168 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
2169 .subvendor = PCI_ANY_ID,
2170 .subdevice = PCI_ANY_ID,
2173 .vendor = PCI_VENDOR_ID_QLOGIC,
2174 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
2175 .subvendor = PCI_ANY_ID,
2176 .subdevice = PCI_ANY_ID,
2179 .vendor = PCI_VENDOR_ID_QLOGIC,
2180 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
2181 .subvendor = PCI_ANY_ID,
2182 .subdevice = PCI_ANY_ID,
2186 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
2188 static struct pci_driver qla4xxx_pci_driver = {
2189 .name = DRIVER_NAME,
2190 .id_table = qla4xxx_pci_tbl,
2191 .probe = qla4xxx_probe_adapter,
2192 .remove = qla4xxx_remove_adapter,
2195 static int __init qla4xxx_module_init(void)
2199 /* Allocate cache for SRBs. */
2200 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
2201 SLAB_HWCACHE_ALIGN, NULL);
2202 if (srb_cachep == NULL) {
2204 "%s: Unable to allocate SRB cache..."
2205 "Failing load!\n", DRIVER_NAME);
2210 /* Derive version string. */
2211 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
2212 if (ql4xextended_error_logging)
2213 strcat(qla4xxx_version_str, "-debug");
2215 qla4xxx_scsi_transport =
2216 iscsi_register_transport(&qla4xxx_iscsi_transport);
2217 if (!qla4xxx_scsi_transport){
2219 goto release_srb_cache;
2222 ret = pci_register_driver(&qla4xxx_pci_driver);
2224 goto unregister_transport;
2226 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
2229 unregister_transport:
2230 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2232 kmem_cache_destroy(srb_cachep);
2237 static void __exit qla4xxx_module_exit(void)
2239 pci_unregister_driver(&qla4xxx_pci_driver);
2240 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2241 kmem_cache_destroy(srb_cachep);
2244 module_init(qla4xxx_module_init);
2245 module_exit(qla4xxx_module_exit);
2247 MODULE_AUTHOR("QLogic Corporation");
2248 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
2249 MODULE_LICENSE("GPL");
2250 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);