2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
7 #include <linux/moduleparam.h>
9 #include <scsi/scsi_tcq.h>
10 #include <scsi/scsicam.h>
13 #include "ql4_version.h"
16 #include "ql4_inline.h"
21 static char qla4xxx_version_str[40];
24 * SRB allocation cache
26 static struct kmem_cache *srb_cachep;
29 * Module parameter information and variables
31 int ql4xdiscoverywait = 60;
32 module_param(ql4xdiscoverywait, int, S_IRUGO | S_IRUSR);
33 MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
34 int ql4xdontresethba = 0;
35 module_param(ql4xdontresethba, int, S_IRUGO | S_IRUSR);
36 MODULE_PARM_DESC(ql4xdontresethba,
37 "Dont reset the HBA when the driver gets 0x8002 AEN "
38 " default it will reset hba :0"
39 " set to 1 to avoid resetting HBA");
41 int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
42 module_param(ql4xextended_error_logging, int, S_IRUGO | S_IRUSR);
43 MODULE_PARM_DESC(ql4xextended_error_logging,
44 "Option to enable extended error logging, "
45 "Default is 0 - no logging, 1 - debug logging");
47 int ql4_mod_unload = 0;
50 * SCSI host template entry points
52 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
55 * iSCSI template entry points
57 static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
58 enum iscsi_tgt_dscvr type, uint32_t enable,
59 struct sockaddr *dst_addr);
60 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
61 enum iscsi_param param, char *buf);
62 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
63 enum iscsi_param param, char *buf);
64 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
65 enum iscsi_host_param param, char *buf);
66 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
69 * SCSI host template entry points
71 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
72 void (*done) (struct scsi_cmnd *));
73 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
74 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
75 static int qla4xxx_slave_alloc(struct scsi_device *device);
76 static int qla4xxx_slave_configure(struct scsi_device *device);
77 static void qla4xxx_slave_destroy(struct scsi_device *sdev);
79 static struct scsi_host_template qla4xxx_driver_template = {
80 .module = THIS_MODULE,
82 .proc_name = DRIVER_NAME,
83 .queuecommand = qla4xxx_queuecommand,
85 .eh_device_reset_handler = qla4xxx_eh_device_reset,
86 .eh_host_reset_handler = qla4xxx_eh_host_reset,
88 .slave_configure = qla4xxx_slave_configure,
89 .slave_alloc = qla4xxx_slave_alloc,
90 .slave_destroy = qla4xxx_slave_destroy,
94 .use_clustering = ENABLE_CLUSTERING,
95 .sg_tablesize = SG_ALL,
97 .max_sectors = 0xFFFF,
100 static struct iscsi_transport qla4xxx_iscsi_transport = {
101 .owner = THIS_MODULE,
103 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
104 CAP_DATA_PATH_OFFLOAD,
105 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
106 ISCSI_TARGET_NAME | ISCSI_TPGT,
107 .host_param_mask = ISCSI_HOST_HWADDRESS |
108 ISCSI_HOST_IPADDRESS |
109 ISCSI_HOST_INITIATOR_NAME,
110 .sessiondata_size = sizeof(struct ddb_entry),
111 .host_template = &qla4xxx_driver_template,
113 .tgt_dscvr = qla4xxx_tgt_dscvr,
114 .get_conn_param = qla4xxx_conn_get_param,
115 .get_session_param = qla4xxx_sess_get_param,
116 .get_host_param = qla4xxx_host_get_param,
117 .session_recovery_timedout = qla4xxx_recovery_timedout,
120 static struct scsi_transport_template *qla4xxx_scsi_transport;
122 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
124 struct ddb_entry *ddb_entry = session->dd_data;
125 struct scsi_qla_host *ha = ddb_entry->ha;
127 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count of (%d) "
128 "secs exhausted, marking device DEAD.\n", ha->host_no,
129 __func__, ddb_entry->fw_ddb_index,
130 ha->port_down_retry_count));
132 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
134 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
135 "0x%lx\n", ha->host_no, __func__, ha->dpc_flags));
136 queue_work(ha->dpc_thread, &ha->dpc_work);
139 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
140 enum iscsi_host_param param, char *buf)
142 struct scsi_qla_host *ha = to_qla_host(shost);
146 case ISCSI_HOST_PARAM_HWADDRESS:
147 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
149 case ISCSI_HOST_PARAM_IPADDRESS:
150 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
151 ha->ip_address[1], ha->ip_address[2],
154 case ISCSI_HOST_PARAM_INITIATOR_NAME:
155 len = sprintf(buf, "%s\n", ha->name_string);
164 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
165 enum iscsi_param param, char *buf)
167 struct ddb_entry *ddb_entry = sess->dd_data;
171 case ISCSI_PARAM_TARGET_NAME:
172 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
173 ddb_entry->iscsi_name);
175 case ISCSI_PARAM_TPGT:
176 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
185 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
186 enum iscsi_param param, char *buf)
188 struct iscsi_cls_session *session;
189 struct ddb_entry *ddb_entry;
192 session = iscsi_dev_to_session(conn->dev.parent);
193 ddb_entry = session->dd_data;
196 case ISCSI_PARAM_CONN_PORT:
197 len = sprintf(buf, "%hu\n", ddb_entry->port);
199 case ISCSI_PARAM_CONN_ADDRESS:
200 /* TODO: what are the ipv6 bits */
201 len = sprintf(buf, "%u.%u.%u.%u\n",
202 NIPQUAD(ddb_entry->ip_addr));
211 static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
212 enum iscsi_tgt_dscvr type, uint32_t enable,
213 struct sockaddr *dst_addr)
215 struct scsi_qla_host *ha;
216 struct sockaddr_in *addr;
217 struct sockaddr_in6 *addr6;
220 ha = (struct scsi_qla_host *) shost->hostdata;
223 case ISCSI_TGT_DSCVR_SEND_TARGETS:
224 if (dst_addr->sa_family == AF_INET) {
225 addr = (struct sockaddr_in *)dst_addr;
226 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
227 addr->sin_port) != QLA_SUCCESS)
229 } else if (dst_addr->sa_family == AF_INET6) {
231 * TODO: fix qla4xxx_send_tgts
233 addr6 = (struct sockaddr_in6 *)dst_addr;
234 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
235 addr6->sin6_port) != QLA_SUCCESS)
246 void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
248 if (!ddb_entry->sess)
251 if (ddb_entry->conn) {
252 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
253 iscsi_remove_session(ddb_entry->sess);
255 iscsi_free_session(ddb_entry->sess);
258 int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
262 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
263 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
265 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
269 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0);
270 if (!ddb_entry->conn) {
271 iscsi_remove_session(ddb_entry->sess);
272 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
276 /* finally ready to go */
277 iscsi_unblock_session(ddb_entry->sess);
281 struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
283 struct ddb_entry *ddb_entry;
284 struct iscsi_cls_session *sess;
286 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport);
290 ddb_entry = sess->dd_data;
291 memset(ddb_entry, 0, sizeof(*ddb_entry));
293 ddb_entry->sess = sess;
301 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
302 unsigned long interval)
304 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
305 __func__, ha->host->host_no));
306 init_timer(&ha->timer);
307 ha->timer.expires = jiffies + interval * HZ;
308 ha->timer.data = (unsigned long)ha;
309 ha->timer.function = (void (*)(unsigned long))func;
310 add_timer(&ha->timer);
311 ha->timer_active = 1;
314 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
316 del_timer_sync(&ha->timer);
317 ha->timer_active = 0;
321 * qla4xxx_mark_device_missing - mark a device as missing.
322 * @ha: Pointer to host adapter structure.
323 * @ddb_entry: Pointer to device database entry
325 * This routine marks a device missing and resets the relogin retry count.
327 void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
328 struct ddb_entry *ddb_entry)
330 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
331 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
332 ha->host_no, ddb_entry->bus, ddb_entry->target,
333 ddb_entry->fw_ddb_index));
334 iscsi_block_session(ddb_entry->sess);
335 iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
338 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
339 struct ddb_entry *ddb_entry,
340 struct scsi_cmnd *cmd,
341 void (*done)(struct scsi_cmnd *))
345 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
349 atomic_set(&srb->ref_count, 1);
351 srb->ddb = ddb_entry;
354 cmd->SCp.ptr = (void *)srb;
355 cmd->scsi_done = done;
360 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
362 struct scsi_cmnd *cmd = srb->cmd;
364 if (srb->flags & SRB_DMA_VALID) {
366 srb->flags &= ~SRB_DMA_VALID;
371 void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
373 struct scsi_cmnd *cmd = srb->cmd;
375 qla4xxx_srb_free_dma(ha, srb);
377 mempool_free(srb, ha->srb_mempool);
383 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
384 * @cmd: Pointer to Linux's SCSI command structure
385 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
386 * that the command has been processed.
389 * This routine is invoked by Linux to send a SCSI command to the driver.
390 * The mid-level driver tries to ensure that queuecommand never gets
391 * invoked concurrently with itself or the interrupt handler (although
392 * the interrupt handler may call this routine as part of request-
393 * completion handling). Unfortunely, it sometimes calls the scheduler
394 * in interrupt context which is a big NO! NO!.
396 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
397 void (*done)(struct scsi_cmnd *))
399 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
400 struct ddb_entry *ddb_entry = cmd->device->hostdata;
401 struct iscsi_cls_session *sess = ddb_entry->sess;
406 cmd->result = DID_IMM_RETRY << 16;
407 goto qc_fail_command;
410 rval = iscsi_session_chkready(sess);
413 goto qc_fail_command;
416 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
417 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
418 cmd->result = DID_NO_CONNECT << 16;
419 goto qc_fail_command;
424 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
427 spin_unlock_irq(ha->host->host_lock);
429 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
431 goto qc_host_busy_lock;
433 rval = qla4xxx_send_command_to_isp(ha, srb);
434 if (rval != QLA_SUCCESS)
435 goto qc_host_busy_free_sp;
437 spin_lock_irq(ha->host->host_lock);
440 qc_host_busy_free_sp:
441 qla4xxx_srb_free_dma(ha, srb);
442 mempool_free(srb, ha->srb_mempool);
445 spin_lock_irq(ha->host->host_lock);
448 return SCSI_MLQUEUE_HOST_BUSY;
457 * qla4xxx_mem_free - frees memory allocated to adapter
458 * @ha: Pointer to host adapter structure.
460 * Frees memory previously allocated by qla4xxx_mem_alloc
462 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
465 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
471 ha->request_ring = NULL;
473 ha->response_ring = NULL;
474 ha->response_dma = 0;
475 ha->shadow_regs = NULL;
476 ha->shadow_regs_dma = 0;
480 mempool_destroy(ha->srb_mempool);
482 ha->srb_mempool = NULL;
484 /* release io space registers */
487 pci_release_regions(ha->pdev);
491 * qla4xxx_mem_alloc - allocates memory for use by adapter.
492 * @ha: Pointer to host adapter structure
494 * Allocates DMA memory for request and response queues. Also allocates memory
497 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
501 /* Allocate contiguous block of DMA memory for queues. */
502 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
503 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
504 sizeof(struct shadow_regs) +
506 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
507 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
508 &ha->queues_dma, GFP_KERNEL);
509 if (ha->queues == NULL) {
510 dev_warn(&ha->pdev->dev,
511 "Memory Allocation failed - queues.\n");
513 goto mem_alloc_error_exit;
515 memset(ha->queues, 0, ha->queues_len);
518 * As per RISC alignment requirements -- the bus-address must be a
519 * multiple of the request-ring size (in bytes).
522 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
523 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
524 (MEM_ALIGN_VALUE - 1));
526 /* Update request and response queue pointers. */
527 ha->request_dma = ha->queues_dma + align;
528 ha->request_ring = (struct queue_entry *) (ha->queues + align);
529 ha->response_dma = ha->queues_dma + align +
530 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
531 ha->response_ring = (struct queue_entry *) (ha->queues + align +
532 (REQUEST_QUEUE_DEPTH *
534 ha->shadow_regs_dma = ha->queues_dma + align +
535 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
536 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
537 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
538 (REQUEST_QUEUE_DEPTH *
540 (RESPONSE_QUEUE_DEPTH *
543 /* Allocate memory for srb pool. */
544 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
545 mempool_free_slab, srb_cachep);
546 if (ha->srb_mempool == NULL) {
547 dev_warn(&ha->pdev->dev,
548 "Memory Allocation failed - SRB Pool.\n");
550 goto mem_alloc_error_exit;
555 mem_alloc_error_exit:
556 qla4xxx_mem_free(ha);
561 * qla4xxx_timer - checks every second for work to do.
562 * @ha: Pointer to host adapter structure.
564 static void qla4xxx_timer(struct scsi_qla_host *ha)
566 struct ddb_entry *ddb_entry, *dtemp;
569 /* Search for relogin's to time-out and port down retry. */
570 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
571 /* Count down time between sending relogins */
572 if (adapter_up(ha) &&
573 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
574 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
575 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
577 if (atomic_read(&ddb_entry->retry_relogin_timer)
579 atomic_set(&ddb_entry->
582 set_bit(DPC_RELOGIN_DEVICE,
584 set_bit(DF_RELOGIN, &ddb_entry->flags);
585 DEBUG2(printk("scsi%ld: %s: index [%d]"
587 ha->host_no, __func__,
588 ddb_entry->fw_ddb_index));
590 atomic_dec(&ddb_entry->
591 retry_relogin_timer);
595 /* Wait for relogin to timeout */
596 if (atomic_read(&ddb_entry->relogin_timer) &&
597 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
599 * If the relogin times out and the device is
600 * still NOT ONLINE then try and relogin again.
602 if (atomic_read(&ddb_entry->state) !=
604 ddb_entry->fw_ddb_device_state ==
605 DDB_DS_SESSION_FAILED) {
606 /* Reset retry relogin timer */
607 atomic_inc(&ddb_entry->relogin_retry_count);
608 DEBUG2(printk("scsi%ld: index[%d] relogin"
609 " timed out-retrying"
612 ddb_entry->fw_ddb_index,
613 atomic_read(&ddb_entry->
614 relogin_retry_count))
617 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
618 "initate relogin after"
620 ha->host_no, ddb_entry->bus,
622 ddb_entry->fw_ddb_index,
623 ddb_entry->default_time2wait + 4)
626 atomic_set(&ddb_entry->retry_relogin_timer,
627 ddb_entry->default_time2wait + 4);
632 /* Check for heartbeat interval. */
633 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
634 ha->heartbeat_interval != 0) {
635 ha->seconds_since_last_heartbeat++;
636 if (ha->seconds_since_last_heartbeat >
637 ha->heartbeat_interval + 2)
638 set_bit(DPC_RESET_HA, &ha->dpc_flags);
642 /* Wakeup the dpc routine for this adapter, if needed. */
644 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
645 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
646 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
647 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
648 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
649 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
650 test_bit(DPC_AEN, &ha->dpc_flags)) &&
652 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
653 " - dpc flags = 0x%lx\n",
654 ha->host_no, __func__, ha->dpc_flags));
655 queue_work(ha->dpc_thread, &ha->dpc_work);
658 /* Reschedule timer thread to call us back in one second */
659 mod_timer(&ha->timer, jiffies + HZ);
661 DEBUG2(ha->seconds_since_last_intr++);
665 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
666 * @ha: Pointer to host adapter structure.
668 * This routine stalls the driver until all outstanding commands are returned.
669 * Caller must release the Hardware Lock prior to calling this routine.
671 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
674 int stat = QLA_SUCCESS;
676 struct scsi_cmnd *cmd;
677 int wait_cnt = WAIT_CMD_TOV; /*
678 * Initialized for 30 seconds as we
679 * expect all commands to retuned
684 spin_lock_irqsave(&ha->hardware_lock, flags);
685 /* Find a command that hasn't completed. */
686 for (index = 0; index < ha->host->can_queue; index++) {
687 cmd = scsi_host_find_tag(ha->host, index);
691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
693 /* If No Commands are pending, wait is complete */
694 if (index == ha->host->can_queue) {
698 /* If we timed out on waiting for commands to come back
707 } /* End of While (wait_cnt) */
712 void qla4xxx_hw_reset(struct scsi_qla_host *ha)
714 uint32_t ctrl_status;
715 unsigned long flags = 0;
717 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
719 spin_lock_irqsave(&ha->hardware_lock, flags);
722 * If the SCSI Reset Interrupt bit is set, clear it.
723 * Otherwise, the Soft Reset won't work.
725 ctrl_status = readw(&ha->reg->ctrl_status);
726 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
727 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
729 /* Issue Soft Reset */
730 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
731 readl(&ha->reg->ctrl_status);
733 spin_unlock_irqrestore(&ha->hardware_lock, flags);
737 * qla4xxx_soft_reset - performs soft reset.
738 * @ha: Pointer to host adapter structure.
740 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
742 uint32_t max_wait_time;
743 unsigned long flags = 0;
744 int status = QLA_ERROR;
745 uint32_t ctrl_status;
747 qla4xxx_hw_reset(ha);
749 /* Wait until the Network Reset Intr bit is cleared */
750 max_wait_time = RESET_INTR_TOV;
752 spin_lock_irqsave(&ha->hardware_lock, flags);
753 ctrl_status = readw(&ha->reg->ctrl_status);
754 spin_unlock_irqrestore(&ha->hardware_lock, flags);
756 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
760 } while ((--max_wait_time));
762 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
763 DEBUG2(printk(KERN_WARNING
764 "scsi%ld: Network Reset Intr not cleared by "
765 "Network function, clearing it now!\n",
767 spin_lock_irqsave(&ha->hardware_lock, flags);
768 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
769 readl(&ha->reg->ctrl_status);
770 spin_unlock_irqrestore(&ha->hardware_lock, flags);
773 /* Wait until the firmware tells us the Soft Reset is done */
774 max_wait_time = SOFT_RESET_TOV;
776 spin_lock_irqsave(&ha->hardware_lock, flags);
777 ctrl_status = readw(&ha->reg->ctrl_status);
778 spin_unlock_irqrestore(&ha->hardware_lock, flags);
780 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
781 status = QLA_SUCCESS;
786 } while ((--max_wait_time));
789 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
790 * after the soft reset has taken place.
792 spin_lock_irqsave(&ha->hardware_lock, flags);
793 ctrl_status = readw(&ha->reg->ctrl_status);
794 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
795 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
796 readl(&ha->reg->ctrl_status);
798 spin_unlock_irqrestore(&ha->hardware_lock, flags);
800 /* If soft reset fails then most probably the bios on other
801 * function is also enabled.
802 * Since the initialization is sequential the other fn
803 * wont be able to acknowledge the soft reset.
804 * Issue a force soft reset to workaround this scenario.
806 if (max_wait_time == 0) {
807 /* Issue Force Soft Reset */
808 spin_lock_irqsave(&ha->hardware_lock, flags);
809 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
810 readl(&ha->reg->ctrl_status);
811 spin_unlock_irqrestore(&ha->hardware_lock, flags);
812 /* Wait until the firmware tells us the Soft Reset is done */
813 max_wait_time = SOFT_RESET_TOV;
815 spin_lock_irqsave(&ha->hardware_lock, flags);
816 ctrl_status = readw(&ha->reg->ctrl_status);
817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
819 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
820 status = QLA_SUCCESS;
825 } while ((--max_wait_time));
832 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
833 * @ha: Pointer to host adapter structure.
835 * This routine is called just prior to a HARD RESET to return all
836 * outstanding commands back to the Operating System.
837 * Caller should make sure that the following locks are released
838 * before this calling routine: Hardware lock, and io_request_lock.
840 static void qla4xxx_flush_active_srbs(struct scsi_qla_host *ha)
846 spin_lock_irqsave(&ha->hardware_lock, flags);
847 for (i = 0; i < ha->host->can_queue; i++) {
848 srb = qla4xxx_del_from_active_array(ha, i);
850 srb->cmd->result = DID_RESET << 16;
851 qla4xxx_srb_compl(ha, srb);
854 spin_unlock_irqrestore(&ha->hardware_lock, flags);
859 * qla4xxx_recover_adapter - recovers adapter after a fatal error
860 * @ha: Pointer to host adapter structure.
861 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
862 * after adapter recovery has completed.
863 * 0=preserve ddb list, 1=destroy and rebuild ddb list
865 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha,
866 uint8_t renew_ddb_list)
870 /* Stall incoming I/O until we are done */
871 clear_bit(AF_ONLINE, &ha->flags);
872 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
875 /* Wait for outstanding commands to complete.
876 * Stalls the driver for max 30 secs
878 status = qla4xxx_cmd_wait(ha);
880 qla4xxx_disable_intrs(ha);
882 /* Flush any pending ddb changed AENs */
883 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
885 /* Reset the firmware. If successful, function
886 * returns with ISP interrupts enabled.
888 if (status == QLA_SUCCESS) {
889 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
890 ha->host_no, __func__));
891 qla4xxx_flush_active_srbs(ha);
892 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
893 status = qla4xxx_soft_reset(ha);
898 /* Flush any pending ddb changed AENs */
899 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
901 /* Re-initialize firmware. If successful, function returns
902 * with ISP interrupts enabled */
903 if (status == QLA_SUCCESS) {
904 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
905 ha->host_no, __func__));
907 /* If successful, AF_ONLINE flag set in
908 * qla4xxx_initialize_adapter */
909 status = qla4xxx_initialize_adapter(ha, renew_ddb_list);
912 /* Failed adapter initialization?
913 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
914 if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
915 (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
916 /* Adapter initialization failed, see if we can retry
917 * resetting the ha */
918 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
919 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
920 DEBUG2(printk("scsi%ld: recover adapter - retrying "
921 "(%d) more times\n", ha->host_no,
922 ha->retry_reset_ha_cnt));
923 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
926 if (ha->retry_reset_ha_cnt > 0) {
927 /* Schedule another Reset HA--DPC will retry */
928 ha->retry_reset_ha_cnt--;
929 DEBUG2(printk("scsi%ld: recover adapter - "
930 "retry remaining %d\n",
932 ha->retry_reset_ha_cnt));
936 if (ha->retry_reset_ha_cnt == 0) {
937 /* Recover adapter retries have been exhausted.
939 DEBUG2(printk("scsi%ld: recover adapter "
940 "failed - board disabled\n",
942 qla4xxx_flush_active_srbs(ha);
943 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
944 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
945 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST,
951 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
952 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags);
953 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
956 ha->adapter_error_count++;
958 if (status == QLA_SUCCESS)
959 qla4xxx_enable_intrs(ha);
961 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha->host_no));
966 * qla4xxx_do_dpc - dpc routine
967 * @data: in our case pointer to adapter structure
969 * This routine is a task that is schedule by the interrupt handler
970 * to perform the background processing for interrupts. We put it
971 * on a task queue that is consumed whenever the scheduler runs; that's
972 * so you can do anything (i.e. put the process to sleep etc). In fact,
973 * the mid-level tries to sleep when it reaches the driver threshold
974 * "host->can_queue". This can cause a panic if we were in our interrupt code.
976 static void qla4xxx_do_dpc(struct work_struct *work)
978 struct scsi_qla_host *ha =
979 container_of(work, struct scsi_qla_host, dpc_work);
980 struct ddb_entry *ddb_entry, *dtemp;
981 int status = QLA_ERROR;
983 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
984 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
985 ha->host_no, __func__, ha->flags, ha->dpc_flags,
986 readw(&ha->reg->ctrl_status)));
988 /* Initialization not yet finished. Don't do anything yet. */
989 if (!test_bit(AF_INIT_DONE, &ha->flags))
992 if (adapter_up(ha) ||
993 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
994 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
995 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
996 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
997 test_bit(DPC_RESET_HA, &ha->dpc_flags))
998 qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST);
1000 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1001 uint8_t wait_time = RESET_INTR_TOV;
1003 while ((readw(&ha->reg->ctrl_status) &
1004 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1005 if (--wait_time == 0)
1010 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1011 "bit not cleared-- resetting\n",
1012 ha->host_no, __func__));
1013 qla4xxx_flush_active_srbs(ha);
1014 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1015 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1016 status = qla4xxx_initialize_adapter(ha,
1019 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1020 if (status == QLA_SUCCESS)
1021 qla4xxx_enable_intrs(ha);
1025 /* ---- process AEN? --- */
1026 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1027 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1029 /* ---- Get DHCP IP Address? --- */
1030 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1031 qla4xxx_get_dhcp_ip_address(ha);
1033 /* ---- relogin device? --- */
1034 if (adapter_up(ha) &&
1035 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1036 list_for_each_entry_safe(ddb_entry, dtemp,
1037 &ha->ddb_list, list) {
1038 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1039 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1040 qla4xxx_relogin_device(ha, ddb_entry);
1043 * If mbx cmd times out there is no point
1044 * in continuing further.
1045 * With large no of targets this can hang
1048 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1049 printk(KERN_WARNING "scsi%ld: %s: "
1050 "need to reset hba\n",
1051 ha->host_no, __func__);
1059 * qla4xxx_free_adapter - release the adapter
1060 * @ha: pointer to adapter structure
1062 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1065 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1066 /* Turn-off interrupts on the card. */
1067 qla4xxx_disable_intrs(ha);
1070 /* Kill the kernel thread for this host */
1072 destroy_workqueue(ha->dpc_thread);
1074 /* Issue Soft Reset to put firmware in unknown state */
1075 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
1076 qla4xxx_hw_reset(ha);
1078 /* Remove timer thread, if present */
1079 if (ha->timer_active)
1080 qla4xxx_stop_timer(ha);
1082 /* Detach interrupts */
1083 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1084 free_irq(ha->pdev->irq, ha);
1086 /* free extra memory */
1087 qla4xxx_mem_free(ha);
1089 pci_disable_device(ha->pdev);
1094 * qla4xxx_iospace_config - maps registers
1095 * @ha: pointer to adapter structure
1097 * This routines maps HBA's registers from the pci address space
1098 * into the kernel virtual address space for memory mapped i/o.
1100 static int qla4xxx_iospace_config(struct scsi_qla_host *ha)
1102 unsigned long pio, pio_len, pio_flags;
1103 unsigned long mmio, mmio_len, mmio_flags;
1105 pio = pci_resource_start(ha->pdev, 0);
1106 pio_len = pci_resource_len(ha->pdev, 0);
1107 pio_flags = pci_resource_flags(ha->pdev, 0);
1108 if (pio_flags & IORESOURCE_IO) {
1109 if (pio_len < MIN_IOBASE_LEN) {
1110 dev_warn(&ha->pdev->dev,
1111 "Invalid PCI I/O region size\n");
1115 dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
1119 /* Use MMIO operations for all accesses. */
1120 mmio = pci_resource_start(ha->pdev, 1);
1121 mmio_len = pci_resource_len(ha->pdev, 1);
1122 mmio_flags = pci_resource_flags(ha->pdev, 1);
1124 if (!(mmio_flags & IORESOURCE_MEM)) {
1125 dev_err(&ha->pdev->dev,
1126 "region #0 not an MMIO resource, aborting\n");
1128 goto iospace_error_exit;
1130 if (mmio_len < MIN_IOBASE_LEN) {
1131 dev_err(&ha->pdev->dev,
1132 "Invalid PCI mem region size, aborting\n");
1133 goto iospace_error_exit;
1136 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
1137 dev_warn(&ha->pdev->dev,
1138 "Failed to reserve PIO/MMIO regions\n");
1140 goto iospace_error_exit;
1143 ha->pio_address = pio;
1144 ha->pio_length = pio_len;
1145 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1147 dev_err(&ha->pdev->dev,
1148 "cannot remap MMIO, aborting\n");
1150 goto iospace_error_exit;
1160 * qla4xxx_probe_adapter - callback function to probe HBA
1161 * @pdev: pointer to pci_dev structure
1162 * @pci_device_id: pointer to pci_device entry
1164 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1165 * It returns zero if successful. It also initializes all data necessary for
1168 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1169 const struct pci_device_id *ent)
1171 int ret = -ENODEV, status;
1172 struct Scsi_Host *host;
1173 struct scsi_qla_host *ha;
1174 struct ddb_entry *ddb_entry, *ddbtemp;
1175 uint8_t init_retry_count = 0;
1178 if (pci_enable_device(pdev))
1181 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1184 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1185 goto probe_disable_device;
1188 /* Clear our data area */
1189 ha = (struct scsi_qla_host *) host->hostdata;
1190 memset(ha, 0, sizeof(*ha));
1192 /* Save the information from PCI BIOS. */
1195 ha->host_no = host->host_no;
1197 /* Configure PCI I/O space. */
1198 ret = qla4xxx_iospace_config(ha);
1202 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1203 pdev->device, pdev->irq, ha->reg);
1205 qla4xxx_config_dma_addressing(ha);
1207 /* Initialize lists and spinlocks. */
1208 INIT_LIST_HEAD(&ha->ddb_list);
1209 INIT_LIST_HEAD(&ha->free_srb_q);
1211 mutex_init(&ha->mbox_sem);
1213 spin_lock_init(&ha->hardware_lock);
1215 /* Allocate dma buffers */
1216 if (qla4xxx_mem_alloc(ha)) {
1217 dev_warn(&ha->pdev->dev,
1218 "[ERROR] Failed to allocate memory for adapter\n");
1225 * Initialize the Host adapter request/response queues and
1227 * NOTE: interrupts enabled upon successful completion
1229 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1230 while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
1231 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1232 "(%d)\n", __func__, init_retry_count));
1233 qla4xxx_soft_reset(ha);
1234 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1236 if (status == QLA_ERROR) {
1237 dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
1243 host->cmd_per_lun = 3;
1244 host->max_channel = 0;
1245 host->max_lun = MAX_LUNS - 1;
1246 host->max_id = MAX_TARGETS;
1247 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1248 host->can_queue = MAX_SRBS ;
1249 host->transportt = qla4xxx_scsi_transport;
1251 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1253 dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
1257 /* Startup the kernel thread for this host adapter. */
1258 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1259 "qla4xxx_dpc\n", __func__));
1260 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1261 ha->dpc_thread = create_singlethread_workqueue(buf);
1262 if (!ha->dpc_thread) {
1263 dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
1267 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
1269 ret = request_irq(pdev->irq, qla4xxx_intr_handler,
1270 IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
1272 dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
1273 " already in use.\n", pdev->irq);
1276 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1277 host->irq = pdev->irq;
1278 DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
1280 qla4xxx_enable_intrs(ha);
1282 /* Start timer thread. */
1283 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1285 set_bit(AF_INIT_DONE, &ha->flags);
1287 pci_set_drvdata(pdev, ha);
1289 ret = scsi_add_host(host, &pdev->dev);
1293 /* Update transport device information for all devices. */
1294 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
1295 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
1296 if (qla4xxx_add_sess(ddb_entry))
1301 " QLogic iSCSI HBA Driver version: %s\n"
1302 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1303 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1304 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1305 ha->patch_number, ha->build_number);
1310 qla4xxx_free_ddb_list(ha);
1311 scsi_remove_host(host);
1314 qla4xxx_free_adapter(ha);
1315 scsi_host_put(ha->host);
1317 probe_disable_device:
1318 pci_disable_device(pdev);
1324 * qla4xxx_remove_adapter - calback function to remove adapter.
1325 * @pci_dev: PCI device pointer
1327 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1329 struct scsi_qla_host *ha;
1331 ha = pci_get_drvdata(pdev);
1333 qla4xxx_disable_intrs(ha);
1335 while (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
1338 /* remove devs from iscsi_sessions to scsi_devices */
1339 qla4xxx_free_ddb_list(ha);
1341 scsi_remove_host(ha->host);
1343 qla4xxx_free_adapter(ha);
1345 scsi_host_put(ha->host);
1347 pci_set_drvdata(pdev, NULL);
1351 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1354 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1355 * supported addressing method.
1357 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
1361 /* Update our PCI device dma_mask for full 64 bit mask */
1362 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1363 if (pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1364 dev_dbg(&ha->pdev->dev,
1365 "Failed to set 64 bit PCI consistent mask; "
1367 retval = pci_set_consistent_dma_mask(ha->pdev,
1371 retval = pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1374 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1376 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1377 struct ddb_entry *ddb = sess->dd_data;
1379 sdev->hostdata = ddb;
1380 sdev->tagged_supported = 1;
1381 scsi_activate_tcq(sdev, sdev->host->can_queue);
1385 static int qla4xxx_slave_configure(struct scsi_device *sdev)
1387 sdev->tagged_supported = 1;
1391 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1393 scsi_deactivate_tcq(sdev, 1);
1397 * qla4xxx_del_from_active_array - returns an active srb
1398 * @ha: Pointer to host adapter structure.
1399 * @index: index into to the active_array
1401 * This routine removes and returns the srb at the specified index
1403 struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index)
1405 struct srb *srb = NULL;
1406 struct scsi_cmnd *cmd;
1408 if (!(cmd = scsi_host_find_tag(ha->host, index)))
1411 if (!(srb = (struct srb *)cmd->host_scribble))
1414 /* update counters */
1415 if (srb->flags & SRB_DMA_VALID) {
1416 ha->req_q_count += srb->iocb_cnt;
1417 ha->iocb_cnt -= srb->iocb_cnt;
1419 srb->cmd->host_scribble = NULL;
1425 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1426 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1427 * @cmd: Scsi Command to wait on.
1429 * This routine waits for the command to be returned by the Firmware
1430 * for some max time.
1432 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1433 struct scsi_cmnd *cmd)
1437 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1440 /* Checking to see if its returned to OS */
1441 rp = (struct srb *) cmd->SCp.ptr;
1448 } while (max_wait_time--);
1454 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1455 * @ha: Pointer to host adapter structure
1457 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1459 unsigned long wait_online;
1461 wait_online = jiffies + (30 * HZ);
1462 while (time_before(jiffies, wait_online)) {
1466 else if (ha->retry_reset_ha_cnt == 0)
1476 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1477 * @ha: pointer to to HBA
1481 * This function waits for all outstanding commands to a lun to complete. It
1482 * returns 0 if all pending commands are returned and 1 otherwise.
1484 static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host *ha,
1489 struct scsi_cmnd *cmd;
1492 * Waiting for all commands for the designated target in the active
1495 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1496 cmd = scsi_host_find_tag(ha->host, cnt);
1497 if (cmd && cmd->device->id == t && cmd->device->lun == l) {
1498 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1508 * qla4xxx_eh_device_reset - callback for target reset.
1509 * @cmd: Pointer to Linux's SCSI command structure
1511 * This routine is called by the Linux OS to reset all luns on the
1514 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
1516 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1517 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1519 int ret = FAILED, stat;
1521 sp = (struct srb *) cmd->SCp.ptr;
1522 if (!sp || !ddb_entry)
1525 dev_info(&ha->pdev->dev,
1526 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
1527 cmd->device->channel, cmd->device->id, cmd->device->lun);
1529 DEBUG2(printk(KERN_INFO
1530 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1531 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
1532 cmd, jiffies, cmd->timeout_per_command / HZ,
1533 ha->dpc_flags, cmd->result, cmd->allowed));
1535 /* FIXME: wait for hba to go online */
1536 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
1537 if (stat != QLA_SUCCESS) {
1538 dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
1539 goto eh_dev_reset_done;
1543 ha->marker_needed = 1;
1546 * If we are coming down the EH path, wait for all commands to complete
1549 if (cmd->device->host->shost_state == SHOST_RECOVERY) {
1550 if (qla4xxx_eh_wait_for_active_target_commands(ha,
1553 dev_info(&ha->pdev->dev,
1554 "DEVICE RESET FAILED - waiting for "
1556 goto eh_dev_reset_done;
1560 dev_info(&ha->pdev->dev,
1561 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1562 ha->host_no, cmd->device->channel, cmd->device->id,
1573 * qla4xxx_eh_host_reset - kernel callback
1574 * @cmd: Pointer to Linux's SCSI command structure
1576 * This routine is invoked by the Linux kernel to perform fatal error
1577 * recovery on the specified adapter.
1579 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
1581 int return_status = FAILED;
1582 struct scsi_qla_host *ha;
1584 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
1586 dev_info(&ha->pdev->dev,
1587 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no,
1588 cmd->device->channel, cmd->device->id, cmd->device->lun);
1590 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
1591 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1592 "DEAD.\n", ha->host_no, cmd->device->channel,
1598 if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS) {
1599 return_status = SUCCESS;
1602 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
1603 return_status == FAILED ? "FAILED" : "SUCCEDED");
1605 return return_status;
1609 static struct pci_device_id qla4xxx_pci_tbl[] = {
1611 .vendor = PCI_VENDOR_ID_QLOGIC,
1612 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
1613 .subvendor = PCI_ANY_ID,
1614 .subdevice = PCI_ANY_ID,
1617 .vendor = PCI_VENDOR_ID_QLOGIC,
1618 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
1619 .subvendor = PCI_ANY_ID,
1620 .subdevice = PCI_ANY_ID,
1623 .vendor = PCI_VENDOR_ID_QLOGIC,
1624 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
1625 .subvendor = PCI_ANY_ID,
1626 .subdevice = PCI_ANY_ID,
1630 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
1632 static struct pci_driver qla4xxx_pci_driver = {
1633 .name = DRIVER_NAME,
1634 .id_table = qla4xxx_pci_tbl,
1635 .probe = qla4xxx_probe_adapter,
1636 .remove = qla4xxx_remove_adapter,
1639 static int __init qla4xxx_module_init(void)
1643 /* Allocate cache for SRBs. */
1644 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
1645 SLAB_HWCACHE_ALIGN, NULL);
1646 if (srb_cachep == NULL) {
1648 "%s: Unable to allocate SRB cache..."
1649 "Failing load!\n", DRIVER_NAME);
1654 /* Derive version string. */
1655 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
1656 if (ql4xextended_error_logging)
1657 strcat(qla4xxx_version_str, "-debug");
1659 qla4xxx_scsi_transport =
1660 iscsi_register_transport(&qla4xxx_iscsi_transport);
1661 if (!qla4xxx_scsi_transport){
1663 goto release_srb_cache;
1666 ret = pci_register_driver(&qla4xxx_pci_driver);
1668 goto unregister_transport;
1670 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
1673 unregister_transport:
1674 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1676 kmem_cache_destroy(srb_cachep);
1681 static void __exit qla4xxx_module_exit(void)
1684 pci_unregister_driver(&qla4xxx_pci_driver);
1685 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1686 kmem_cache_destroy(srb_cachep);
1689 module_init(qla4xxx_module_init);
1690 module_exit(qla4xxx_module_exit);
1692 MODULE_AUTHOR("QLogic Corporation");
1693 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1694 MODULE_LICENSE("GPL");
1695 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);