Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / scsi / qla4xxx / ql4_os.c
blob7cd8626bc9c3ebf1e4a2360b9e397ef49001b378
1 /*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7 #include <linux/moduleparam.h>
9 #include <scsi/scsi_tcq.h>
10 #include <scsi/scsicam.h>
12 #include "ql4_def.h"
13 #include "ql4_version.h"
14 #include "ql4_glbl.h"
15 #include "ql4_dbg.h"
16 #include "ql4_inline.h"
19 * Driver version
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);
78 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
79 =======
80 static void qla4xxx_scan_start(struct Scsi_Host *shost);
81 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
83 static struct scsi_host_template qla4xxx_driver_template = {
84 .module = THIS_MODULE,
85 .name = DRIVER_NAME,
86 .proc_name = DRIVER_NAME,
87 .queuecommand = qla4xxx_queuecommand,
89 .eh_device_reset_handler = qla4xxx_eh_device_reset,
90 .eh_host_reset_handler = qla4xxx_eh_host_reset,
92 .slave_configure = qla4xxx_slave_configure,
93 .slave_alloc = qla4xxx_slave_alloc,
94 .slave_destroy = qla4xxx_slave_destroy,
96 .scan_finished = iscsi_scan_finished,
97 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
98 =======
99 .scan_start = qla4xxx_scan_start,
100 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
102 .this_id = -1,
103 .cmd_per_lun = 3,
104 .use_clustering = ENABLE_CLUSTERING,
105 .sg_tablesize = SG_ALL,
107 .max_sectors = 0xFFFF,
110 static struct iscsi_transport qla4xxx_iscsi_transport = {
111 .owner = THIS_MODULE,
112 .name = DRIVER_NAME,
113 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
114 CAP_DATA_PATH_OFFLOAD,
115 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
116 ISCSI_TARGET_NAME | ISCSI_TPGT,
117 .host_param_mask = ISCSI_HOST_HWADDRESS |
118 ISCSI_HOST_IPADDRESS |
119 ISCSI_HOST_INITIATOR_NAME,
120 .sessiondata_size = sizeof(struct ddb_entry),
121 .host_template = &qla4xxx_driver_template,
123 .tgt_dscvr = qla4xxx_tgt_dscvr,
124 .get_conn_param = qla4xxx_conn_get_param,
125 .get_session_param = qla4xxx_sess_get_param,
126 .get_host_param = qla4xxx_host_get_param,
127 .session_recovery_timedout = qla4xxx_recovery_timedout,
130 static struct scsi_transport_template *qla4xxx_scsi_transport;
132 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
134 struct ddb_entry *ddb_entry = session->dd_data;
135 struct scsi_qla_host *ha = ddb_entry->ha;
137 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
138 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
140 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
141 "of (%d) secs exhausted, marking device DEAD.\n",
142 ha->host_no, __func__, ddb_entry->fw_ddb_index,
143 ha->port_down_retry_count));
145 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
146 "flags = 0x%lx\n",
147 ha->host_no, __func__, ha->dpc_flags));
148 queue_work(ha->dpc_thread, &ha->dpc_work);
152 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
153 enum iscsi_host_param param, char *buf)
155 struct scsi_qla_host *ha = to_qla_host(shost);
156 int len;
158 switch (param) {
159 case ISCSI_HOST_PARAM_HWADDRESS:
160 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
161 break;
162 case ISCSI_HOST_PARAM_IPADDRESS:
163 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
164 ha->ip_address[1], ha->ip_address[2],
165 ha->ip_address[3]);
166 break;
167 case ISCSI_HOST_PARAM_INITIATOR_NAME:
168 len = sprintf(buf, "%s\n", ha->name_string);
169 break;
170 default:
171 return -ENOSYS;
174 return len;
177 static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
178 enum iscsi_param param, char *buf)
180 struct ddb_entry *ddb_entry = sess->dd_data;
181 int len;
183 switch (param) {
184 case ISCSI_PARAM_TARGET_NAME:
185 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
186 ddb_entry->iscsi_name);
187 break;
188 case ISCSI_PARAM_TPGT:
189 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
190 break;
191 default:
192 return -ENOSYS;
195 return len;
198 static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
199 enum iscsi_param param, char *buf)
201 struct iscsi_cls_session *session;
202 struct ddb_entry *ddb_entry;
203 int len;
205 session = iscsi_dev_to_session(conn->dev.parent);
206 ddb_entry = session->dd_data;
208 switch (param) {
209 case ISCSI_PARAM_CONN_PORT:
210 len = sprintf(buf, "%hu\n", ddb_entry->port);
211 break;
212 case ISCSI_PARAM_CONN_ADDRESS:
213 /* TODO: what are the ipv6 bits */
214 len = sprintf(buf, "%u.%u.%u.%u\n",
215 NIPQUAD(ddb_entry->ip_addr));
216 break;
217 default:
218 return -ENOSYS;
221 return len;
224 static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
225 enum iscsi_tgt_dscvr type, uint32_t enable,
226 struct sockaddr *dst_addr)
228 struct scsi_qla_host *ha;
229 struct sockaddr_in *addr;
230 struct sockaddr_in6 *addr6;
231 int ret = 0;
233 ha = (struct scsi_qla_host *) shost->hostdata;
235 switch (type) {
236 case ISCSI_TGT_DSCVR_SEND_TARGETS:
237 if (dst_addr->sa_family == AF_INET) {
238 addr = (struct sockaddr_in *)dst_addr;
239 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
240 addr->sin_port) != QLA_SUCCESS)
241 ret = -EIO;
242 } else if (dst_addr->sa_family == AF_INET6) {
244 * TODO: fix qla4xxx_send_tgts
246 addr6 = (struct sockaddr_in6 *)dst_addr;
247 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
248 addr6->sin6_port) != QLA_SUCCESS)
249 ret = -EIO;
250 } else
251 ret = -ENOSYS;
252 break;
253 default:
254 ret = -ENOSYS;
256 return ret;
259 void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
261 if (!ddb_entry->sess)
262 return;
264 if (ddb_entry->conn) {
265 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
266 iscsi_remove_session(ddb_entry->sess);
268 iscsi_free_session(ddb_entry->sess);
271 int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
273 int err;
275 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
276 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
277 if (err) {
278 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
279 return err;
282 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0);
283 if (!ddb_entry->conn) {
284 iscsi_remove_session(ddb_entry->sess);
285 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
286 return -ENOMEM;
289 /* finally ready to go */
290 iscsi_unblock_session(ddb_entry->sess);
291 return 0;
294 struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
296 struct ddb_entry *ddb_entry;
297 struct iscsi_cls_session *sess;
299 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport);
300 if (!sess)
301 return NULL;
303 ddb_entry = sess->dd_data;
304 memset(ddb_entry, 0, sizeof(*ddb_entry));
305 ddb_entry->ha = ha;
306 ddb_entry->sess = sess;
307 return ddb_entry;
310 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
311 =======
312 static void qla4xxx_scan_start(struct Scsi_Host *shost)
314 struct scsi_qla_host *ha = shost_priv(shost);
315 struct ddb_entry *ddb_entry, *ddbtemp;
317 /* finish setup of sessions that were already setup in firmware */
318 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
319 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
320 qla4xxx_add_sess(ddb_entry);
324 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
326 * Timer routines
329 static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
330 unsigned long interval)
332 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
333 __func__, ha->host->host_no));
334 init_timer(&ha->timer);
335 ha->timer.expires = jiffies + interval * HZ;
336 ha->timer.data = (unsigned long)ha;
337 ha->timer.function = (void (*)(unsigned long))func;
338 add_timer(&ha->timer);
339 ha->timer_active = 1;
342 static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
344 del_timer_sync(&ha->timer);
345 ha->timer_active = 0;
348 /***
349 * qla4xxx_mark_device_missing - mark a device as missing.
350 * @ha: Pointer to host adapter structure.
351 * @ddb_entry: Pointer to device database entry
353 * This routine marks a device missing and resets the relogin retry count.
355 void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
356 struct ddb_entry *ddb_entry)
358 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
359 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
360 ha->host_no, ddb_entry->bus, ddb_entry->target,
361 ddb_entry->fw_ddb_index));
362 iscsi_block_session(ddb_entry->sess);
363 iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
366 static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
367 struct ddb_entry *ddb_entry,
368 struct scsi_cmnd *cmd,
369 void (*done)(struct scsi_cmnd *))
371 struct srb *srb;
373 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
374 if (!srb)
375 return srb;
377 atomic_set(&srb->ref_count, 1);
378 srb->ha = ha;
379 srb->ddb = ddb_entry;
380 srb->cmd = cmd;
381 srb->flags = 0;
382 cmd->SCp.ptr = (void *)srb;
383 cmd->scsi_done = done;
385 return srb;
388 static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
390 struct scsi_cmnd *cmd = srb->cmd;
392 if (srb->flags & SRB_DMA_VALID) {
393 scsi_dma_unmap(cmd);
394 srb->flags &= ~SRB_DMA_VALID;
396 cmd->SCp.ptr = NULL;
399 void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
401 struct scsi_cmnd *cmd = srb->cmd;
403 qla4xxx_srb_free_dma(ha, srb);
405 mempool_free(srb, ha->srb_mempool);
407 cmd->scsi_done(cmd);
411 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
412 * @cmd: Pointer to Linux's SCSI command structure
413 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
414 * that the command has been processed.
416 * Remarks:
417 * This routine is invoked by Linux to send a SCSI command to the driver.
418 * The mid-level driver tries to ensure that queuecommand never gets
419 * invoked concurrently with itself or the interrupt handler (although
420 * the interrupt handler may call this routine as part of request-
421 * completion handling). Unfortunely, it sometimes calls the scheduler
422 * in interrupt context which is a big NO! NO!.
424 static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
425 void (*done)(struct scsi_cmnd *))
427 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
428 struct ddb_entry *ddb_entry = cmd->device->hostdata;
429 struct iscsi_cls_session *sess = ddb_entry->sess;
430 struct srb *srb;
431 int rval;
433 if (!sess) {
434 cmd->result = DID_IMM_RETRY << 16;
435 goto qc_fail_command;
438 rval = iscsi_session_chkready(sess);
439 if (rval) {
440 cmd->result = rval;
441 goto qc_fail_command;
444 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
445 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
446 cmd->result = DID_NO_CONNECT << 16;
447 goto qc_fail_command;
449 goto qc_host_busy;
452 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
453 goto qc_host_busy;
455 spin_unlock_irq(ha->host->host_lock);
457 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
458 if (!srb)
459 goto qc_host_busy_lock;
461 rval = qla4xxx_send_command_to_isp(ha, srb);
462 if (rval != QLA_SUCCESS)
463 goto qc_host_busy_free_sp;
465 spin_lock_irq(ha->host->host_lock);
466 return 0;
468 qc_host_busy_free_sp:
469 qla4xxx_srb_free_dma(ha, srb);
470 mempool_free(srb, ha->srb_mempool);
472 qc_host_busy_lock:
473 spin_lock_irq(ha->host->host_lock);
475 qc_host_busy:
476 return SCSI_MLQUEUE_HOST_BUSY;
478 qc_fail_command:
479 done(cmd);
481 return 0;
485 * qla4xxx_mem_free - frees memory allocated to adapter
486 * @ha: Pointer to host adapter structure.
488 * Frees memory previously allocated by qla4xxx_mem_alloc
490 static void qla4xxx_mem_free(struct scsi_qla_host *ha)
492 if (ha->queues)
493 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
494 ha->queues_dma);
496 ha->queues_len = 0;
497 ha->queues = NULL;
498 ha->queues_dma = 0;
499 ha->request_ring = NULL;
500 ha->request_dma = 0;
501 ha->response_ring = NULL;
502 ha->response_dma = 0;
503 ha->shadow_regs = NULL;
504 ha->shadow_regs_dma = 0;
506 /* Free srb pool. */
507 if (ha->srb_mempool)
508 mempool_destroy(ha->srb_mempool);
510 ha->srb_mempool = NULL;
512 /* release io space registers */
513 if (ha->reg)
514 iounmap(ha->reg);
515 pci_release_regions(ha->pdev);
519 * qla4xxx_mem_alloc - allocates memory for use by adapter.
520 * @ha: Pointer to host adapter structure
522 * Allocates DMA memory for request and response queues. Also allocates memory
523 * for srbs.
525 static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
527 unsigned long align;
529 /* Allocate contiguous block of DMA memory for queues. */
530 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
531 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
532 sizeof(struct shadow_regs) +
533 MEM_ALIGN_VALUE +
534 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
535 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
536 &ha->queues_dma, GFP_KERNEL);
537 if (ha->queues == NULL) {
538 dev_warn(&ha->pdev->dev,
539 "Memory Allocation failed - queues.\n");
541 goto mem_alloc_error_exit;
543 memset(ha->queues, 0, ha->queues_len);
546 * As per RISC alignment requirements -- the bus-address must be a
547 * multiple of the request-ring size (in bytes).
549 align = 0;
550 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
551 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
552 (MEM_ALIGN_VALUE - 1));
554 /* Update request and response queue pointers. */
555 ha->request_dma = ha->queues_dma + align;
556 ha->request_ring = (struct queue_entry *) (ha->queues + align);
557 ha->response_dma = ha->queues_dma + align +
558 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
559 ha->response_ring = (struct queue_entry *) (ha->queues + align +
560 (REQUEST_QUEUE_DEPTH *
561 QUEUE_SIZE));
562 ha->shadow_regs_dma = ha->queues_dma + align +
563 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
564 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
565 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
566 (REQUEST_QUEUE_DEPTH *
567 QUEUE_SIZE) +
568 (RESPONSE_QUEUE_DEPTH *
569 QUEUE_SIZE));
571 /* Allocate memory for srb pool. */
572 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
573 mempool_free_slab, srb_cachep);
574 if (ha->srb_mempool == NULL) {
575 dev_warn(&ha->pdev->dev,
576 "Memory Allocation failed - SRB Pool.\n");
578 goto mem_alloc_error_exit;
581 return QLA_SUCCESS;
583 mem_alloc_error_exit:
584 qla4xxx_mem_free(ha);
585 return QLA_ERROR;
589 * qla4xxx_timer - checks every second for work to do.
590 * @ha: Pointer to host adapter structure.
592 static void qla4xxx_timer(struct scsi_qla_host *ha)
594 struct ddb_entry *ddb_entry, *dtemp;
595 int start_dpc = 0;
597 /* Search for relogin's to time-out and port down retry. */
598 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
599 /* Count down time between sending relogins */
600 if (adapter_up(ha) &&
601 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
602 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
603 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
604 INVALID_ENTRY) {
605 if (atomic_read(&ddb_entry->retry_relogin_timer)
606 == 0) {
607 atomic_set(&ddb_entry->
608 retry_relogin_timer,
609 INVALID_ENTRY);
610 set_bit(DPC_RELOGIN_DEVICE,
611 &ha->dpc_flags);
612 set_bit(DF_RELOGIN, &ddb_entry->flags);
613 DEBUG2(printk("scsi%ld: %s: index [%d]"
614 " login device\n",
615 ha->host_no, __func__,
616 ddb_entry->fw_ddb_index));
617 } else
618 atomic_dec(&ddb_entry->
619 retry_relogin_timer);
623 /* Wait for relogin to timeout */
624 if (atomic_read(&ddb_entry->relogin_timer) &&
625 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
627 * If the relogin times out and the device is
628 * still NOT ONLINE then try and relogin again.
630 if (atomic_read(&ddb_entry->state) !=
631 DDB_STATE_ONLINE &&
632 ddb_entry->fw_ddb_device_state ==
633 DDB_DS_SESSION_FAILED) {
634 /* Reset retry relogin timer */
635 atomic_inc(&ddb_entry->relogin_retry_count);
636 DEBUG2(printk("scsi%ld: index[%d] relogin"
637 " timed out-retrying"
638 " relogin (%d)\n",
639 ha->host_no,
640 ddb_entry->fw_ddb_index,
641 atomic_read(&ddb_entry->
642 relogin_retry_count))
644 start_dpc++;
645 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
646 "initate relogin after"
647 " %d seconds\n",
648 ha->host_no, ddb_entry->bus,
649 ddb_entry->target,
650 ddb_entry->fw_ddb_index,
651 ddb_entry->default_time2wait + 4)
654 atomic_set(&ddb_entry->retry_relogin_timer,
655 ddb_entry->default_time2wait + 4);
660 /* Check for heartbeat interval. */
661 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
662 ha->heartbeat_interval != 0) {
663 ha->seconds_since_last_heartbeat++;
664 if (ha->seconds_since_last_heartbeat >
665 ha->heartbeat_interval + 2)
666 set_bit(DPC_RESET_HA, &ha->dpc_flags);
670 /* Wakeup the dpc routine for this adapter, if needed. */
671 if ((start_dpc ||
672 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
673 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
674 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
675 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
676 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
677 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
678 test_bit(DPC_AEN, &ha->dpc_flags)) &&
679 ha->dpc_thread) {
680 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
681 " - dpc flags = 0x%lx\n",
682 ha->host_no, __func__, ha->dpc_flags));
683 queue_work(ha->dpc_thread, &ha->dpc_work);
686 /* Reschedule timer thread to call us back in one second */
687 mod_timer(&ha->timer, jiffies + HZ);
689 DEBUG2(ha->seconds_since_last_intr++);
693 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
694 * @ha: Pointer to host adapter structure.
696 * This routine stalls the driver until all outstanding commands are returned.
697 * Caller must release the Hardware Lock prior to calling this routine.
699 static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
701 uint32_t index = 0;
702 int stat = QLA_SUCCESS;
703 unsigned long flags;
704 struct scsi_cmnd *cmd;
705 int wait_cnt = WAIT_CMD_TOV; /*
706 * Initialized for 30 seconds as we
707 * expect all commands to retuned
708 * ASAP.
711 while (wait_cnt) {
712 spin_lock_irqsave(&ha->hardware_lock, flags);
713 /* Find a command that hasn't completed. */
714 for (index = 0; index < ha->host->can_queue; index++) {
715 cmd = scsi_host_find_tag(ha->host, index);
716 if (cmd != NULL)
717 break;
719 spin_unlock_irqrestore(&ha->hardware_lock, flags);
721 /* If No Commands are pending, wait is complete */
722 if (index == ha->host->can_queue) {
723 break;
726 /* If we timed out on waiting for commands to come back
727 * return ERROR.
729 wait_cnt--;
730 if (wait_cnt == 0)
731 stat = QLA_ERROR;
732 else {
733 msleep(1000);
735 } /* End of While (wait_cnt) */
737 return stat;
740 void qla4xxx_hw_reset(struct scsi_qla_host *ha)
742 uint32_t ctrl_status;
743 unsigned long flags = 0;
745 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
747 spin_lock_irqsave(&ha->hardware_lock, flags);
750 * If the SCSI Reset Interrupt bit is set, clear it.
751 * Otherwise, the Soft Reset won't work.
753 ctrl_status = readw(&ha->reg->ctrl_status);
754 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
755 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
757 /* Issue Soft Reset */
758 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
759 readl(&ha->reg->ctrl_status);
761 spin_unlock_irqrestore(&ha->hardware_lock, flags);
765 * qla4xxx_soft_reset - performs soft reset.
766 * @ha: Pointer to host adapter structure.
768 int qla4xxx_soft_reset(struct scsi_qla_host *ha)
770 uint32_t max_wait_time;
771 unsigned long flags = 0;
772 int status = QLA_ERROR;
773 uint32_t ctrl_status;
775 qla4xxx_hw_reset(ha);
777 /* Wait until the Network Reset Intr bit is cleared */
778 max_wait_time = RESET_INTR_TOV;
779 do {
780 spin_lock_irqsave(&ha->hardware_lock, flags);
781 ctrl_status = readw(&ha->reg->ctrl_status);
782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
784 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
785 break;
787 msleep(1000);
788 } while ((--max_wait_time));
790 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
791 DEBUG2(printk(KERN_WARNING
792 "scsi%ld: Network Reset Intr not cleared by "
793 "Network function, clearing it now!\n",
794 ha->host_no));
795 spin_lock_irqsave(&ha->hardware_lock, flags);
796 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
797 readl(&ha->reg->ctrl_status);
798 spin_unlock_irqrestore(&ha->hardware_lock, flags);
801 /* Wait until the firmware tells us the Soft Reset is done */
802 max_wait_time = SOFT_RESET_TOV;
803 do {
804 spin_lock_irqsave(&ha->hardware_lock, flags);
805 ctrl_status = readw(&ha->reg->ctrl_status);
806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
808 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
809 status = QLA_SUCCESS;
810 break;
813 msleep(1000);
814 } while ((--max_wait_time));
817 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
818 * after the soft reset has taken place.
820 spin_lock_irqsave(&ha->hardware_lock, flags);
821 ctrl_status = readw(&ha->reg->ctrl_status);
822 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
823 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
824 readl(&ha->reg->ctrl_status);
826 spin_unlock_irqrestore(&ha->hardware_lock, flags);
828 /* If soft reset fails then most probably the bios on other
829 * function is also enabled.
830 * Since the initialization is sequential the other fn
831 * wont be able to acknowledge the soft reset.
832 * Issue a force soft reset to workaround this scenario.
834 if (max_wait_time == 0) {
835 /* Issue Force Soft Reset */
836 spin_lock_irqsave(&ha->hardware_lock, flags);
837 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
838 readl(&ha->reg->ctrl_status);
839 spin_unlock_irqrestore(&ha->hardware_lock, flags);
840 /* Wait until the firmware tells us the Soft Reset is done */
841 max_wait_time = SOFT_RESET_TOV;
842 do {
843 spin_lock_irqsave(&ha->hardware_lock, flags);
844 ctrl_status = readw(&ha->reg->ctrl_status);
845 spin_unlock_irqrestore(&ha->hardware_lock, flags);
847 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
848 status = QLA_SUCCESS;
849 break;
852 msleep(1000);
853 } while ((--max_wait_time));
856 return status;
860 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
861 * @ha: Pointer to host adapter structure.
863 * This routine is called just prior to a HARD RESET to return all
864 * outstanding commands back to the Operating System.
865 * Caller should make sure that the following locks are released
866 * before this calling routine: Hardware lock, and io_request_lock.
868 static void qla4xxx_flush_active_srbs(struct scsi_qla_host *ha)
870 struct srb *srb;
871 int i;
872 unsigned long flags;
874 spin_lock_irqsave(&ha->hardware_lock, flags);
875 for (i = 0; i < ha->host->can_queue; i++) {
876 srb = qla4xxx_del_from_active_array(ha, i);
877 if (srb != NULL) {
878 srb->cmd->result = DID_RESET << 16;
879 qla4xxx_srb_compl(ha, srb);
882 spin_unlock_irqrestore(&ha->hardware_lock, flags);
887 * qla4xxx_recover_adapter - recovers adapter after a fatal error
888 * @ha: Pointer to host adapter structure.
889 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
890 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
891 * after adapter recovery has completed.
892 * 0=preserve ddb list, 1=destroy and rebuild ddb list
893 =======
895 * renew_ddb_list value can be 0=preserve ddb list, 1=destroy and rebuild
896 * ddb list.
897 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
899 static int qla4xxx_recover_adapter(struct scsi_qla_host *ha,
900 uint8_t renew_ddb_list)
902 int status;
904 /* Stall incoming I/O until we are done */
905 clear_bit(AF_ONLINE, &ha->flags);
906 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
907 =======
909 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
910 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
911 __func__));
913 /* Wait for outstanding commands to complete.
914 * Stalls the driver for max 30 secs
916 status = qla4xxx_cmd_wait(ha);
918 qla4xxx_disable_intrs(ha);
920 /* Flush any pending ddb changed AENs */
921 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
923 /* Reset the firmware. If successful, function
924 * returns with ISP interrupts enabled.
926 if (status == QLA_SUCCESS) {
927 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
928 ha->host_no, __func__));
929 qla4xxx_flush_active_srbs(ha);
930 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
931 status = qla4xxx_soft_reset(ha);
932 else
933 status = QLA_ERROR;
936 /* Flush any pending ddb changed AENs */
937 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
939 /* Re-initialize firmware. If successful, function returns
940 * with ISP interrupts enabled */
941 if (status == QLA_SUCCESS) {
942 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
943 ha->host_no, __func__));
945 /* If successful, AF_ONLINE flag set in
946 * qla4xxx_initialize_adapter */
947 status = qla4xxx_initialize_adapter(ha, renew_ddb_list);
950 /* Failed adapter initialization?
951 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
952 if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
953 (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
954 /* Adapter initialization failed, see if we can retry
955 * resetting the ha */
956 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
957 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
958 DEBUG2(printk("scsi%ld: recover adapter - retrying "
959 "(%d) more times\n", ha->host_no,
960 ha->retry_reset_ha_cnt));
961 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
962 status = QLA_ERROR;
963 } else {
964 if (ha->retry_reset_ha_cnt > 0) {
965 /* Schedule another Reset HA--DPC will retry */
966 ha->retry_reset_ha_cnt--;
967 DEBUG2(printk("scsi%ld: recover adapter - "
968 "retry remaining %d\n",
969 ha->host_no,
970 ha->retry_reset_ha_cnt));
971 status = QLA_ERROR;
974 if (ha->retry_reset_ha_cnt == 0) {
975 /* Recover adapter retries have been exhausted.
976 * Adapter DEAD */
977 DEBUG2(printk("scsi%ld: recover adapter "
978 "failed - board disabled\n",
979 ha->host_no));
980 qla4xxx_flush_active_srbs(ha);
981 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
982 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
983 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST,
984 &ha->dpc_flags);
985 status = QLA_ERROR;
988 } else {
989 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
990 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags);
991 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
994 ha->adapter_error_count++;
996 if (status == QLA_SUCCESS)
997 qla4xxx_enable_intrs(ha);
999 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha->host_no));
1000 return status;
1004 * qla4xxx_do_dpc - dpc routine
1005 * @data: in our case pointer to adapter structure
1007 * This routine is a task that is schedule by the interrupt handler
1008 * to perform the background processing for interrupts. We put it
1009 * on a task queue that is consumed whenever the scheduler runs; that's
1010 * so you can do anything (i.e. put the process to sleep etc). In fact,
1011 * the mid-level tries to sleep when it reaches the driver threshold
1012 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1014 static void qla4xxx_do_dpc(struct work_struct *work)
1016 struct scsi_qla_host *ha =
1017 container_of(work, struct scsi_qla_host, dpc_work);
1018 struct ddb_entry *ddb_entry, *dtemp;
1019 int status = QLA_ERROR;
1021 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
1022 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
1023 ha->host_no, __func__, ha->flags, ha->dpc_flags,
1024 readw(&ha->reg->ctrl_status)));
1026 /* Initialization not yet finished. Don't do anything yet. */
1027 if (!test_bit(AF_INIT_DONE, &ha->flags))
1028 return;
1030 if (adapter_up(ha) ||
1031 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1032 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1033 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
1034 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1035 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1036 qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST);
1038 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1039 uint8_t wait_time = RESET_INTR_TOV;
1041 while ((readw(&ha->reg->ctrl_status) &
1042 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1043 if (--wait_time == 0)
1044 break;
1045 msleep(1000);
1047 if (wait_time == 0)
1048 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1049 "bit not cleared-- resetting\n",
1050 ha->host_no, __func__));
1051 qla4xxx_flush_active_srbs(ha);
1052 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1053 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1054 status = qla4xxx_initialize_adapter(ha,
1055 PRESERVE_DDB_LIST);
1057 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1058 if (status == QLA_SUCCESS)
1059 qla4xxx_enable_intrs(ha);
1063 /* ---- process AEN? --- */
1064 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1065 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1067 /* ---- Get DHCP IP Address? --- */
1068 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1069 qla4xxx_get_dhcp_ip_address(ha);
1071 /* ---- relogin device? --- */
1072 if (adapter_up(ha) &&
1073 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1074 list_for_each_entry_safe(ddb_entry, dtemp,
1075 &ha->ddb_list, list) {
1076 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1077 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1078 qla4xxx_relogin_device(ha, ddb_entry);
1081 * If mbx cmd times out there is no point
1082 * in continuing further.
1083 * With large no of targets this can hang
1084 * the system.
1086 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1087 printk(KERN_WARNING "scsi%ld: %s: "
1088 "need to reset hba\n",
1089 ha->host_no, __func__);
1090 break;
1097 * qla4xxx_free_adapter - release the adapter
1098 * @ha: pointer to adapter structure
1100 static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1103 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1104 /* Turn-off interrupts on the card. */
1105 qla4xxx_disable_intrs(ha);
1108 /* Kill the kernel thread for this host */
1109 if (ha->dpc_thread)
1110 destroy_workqueue(ha->dpc_thread);
1112 /* Issue Soft Reset to put firmware in unknown state */
1113 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
1114 qla4xxx_hw_reset(ha);
1116 /* Remove timer thread, if present */
1117 if (ha->timer_active)
1118 qla4xxx_stop_timer(ha);
1120 /* Detach interrupts */
1121 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1122 free_irq(ha->pdev->irq, ha);
1124 /* free extra memory */
1125 qla4xxx_mem_free(ha);
1127 pci_disable_device(ha->pdev);
1131 /***
1132 * qla4xxx_iospace_config - maps registers
1133 * @ha: pointer to adapter structure
1135 * This routines maps HBA's registers from the pci address space
1136 * into the kernel virtual address space for memory mapped i/o.
1138 static int qla4xxx_iospace_config(struct scsi_qla_host *ha)
1140 unsigned long pio, pio_len, pio_flags;
1141 unsigned long mmio, mmio_len, mmio_flags;
1143 pio = pci_resource_start(ha->pdev, 0);
1144 pio_len = pci_resource_len(ha->pdev, 0);
1145 pio_flags = pci_resource_flags(ha->pdev, 0);
1146 if (pio_flags & IORESOURCE_IO) {
1147 if (pio_len < MIN_IOBASE_LEN) {
1148 dev_warn(&ha->pdev->dev,
1149 "Invalid PCI I/O region size\n");
1150 pio = 0;
1152 } else {
1153 dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
1154 pio = 0;
1157 /* Use MMIO operations for all accesses. */
1158 mmio = pci_resource_start(ha->pdev, 1);
1159 mmio_len = pci_resource_len(ha->pdev, 1);
1160 mmio_flags = pci_resource_flags(ha->pdev, 1);
1162 if (!(mmio_flags & IORESOURCE_MEM)) {
1163 dev_err(&ha->pdev->dev,
1164 "region #0 not an MMIO resource, aborting\n");
1166 goto iospace_error_exit;
1168 if (mmio_len < MIN_IOBASE_LEN) {
1169 dev_err(&ha->pdev->dev,
1170 "Invalid PCI mem region size, aborting\n");
1171 goto iospace_error_exit;
1174 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
1175 dev_warn(&ha->pdev->dev,
1176 "Failed to reserve PIO/MMIO regions\n");
1178 goto iospace_error_exit;
1181 ha->pio_address = pio;
1182 ha->pio_length = pio_len;
1183 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1184 if (!ha->reg) {
1185 dev_err(&ha->pdev->dev,
1186 "cannot remap MMIO, aborting\n");
1188 goto iospace_error_exit;
1191 return 0;
1193 iospace_error_exit:
1194 return -ENOMEM;
1198 * qla4xxx_probe_adapter - callback function to probe HBA
1199 * @pdev: pointer to pci_dev structure
1200 * @pci_device_id: pointer to pci_device entry
1202 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1203 * It returns zero if successful. It also initializes all data necessary for
1204 * the driver.
1206 static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1207 const struct pci_device_id *ent)
1209 int ret = -ENODEV, status;
1210 struct Scsi_Host *host;
1211 struct scsi_qla_host *ha;
1212 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
1213 struct ddb_entry *ddb_entry, *ddbtemp;
1214 =======
1215 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
1216 uint8_t init_retry_count = 0;
1217 char buf[34];
1219 if (pci_enable_device(pdev))
1220 return -1;
1222 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1223 if (host == NULL) {
1224 printk(KERN_WARNING
1225 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1226 goto probe_disable_device;
1229 /* Clear our data area */
1230 ha = (struct scsi_qla_host *) host->hostdata;
1231 memset(ha, 0, sizeof(*ha));
1233 /* Save the information from PCI BIOS. */
1234 ha->pdev = pdev;
1235 ha->host = host;
1236 ha->host_no = host->host_no;
1238 /* Configure PCI I/O space. */
1239 ret = qla4xxx_iospace_config(ha);
1240 if (ret)
1241 goto probe_failed;
1243 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1244 pdev->device, pdev->irq, ha->reg);
1246 qla4xxx_config_dma_addressing(ha);
1248 /* Initialize lists and spinlocks. */
1249 INIT_LIST_HEAD(&ha->ddb_list);
1250 INIT_LIST_HEAD(&ha->free_srb_q);
1252 mutex_init(&ha->mbox_sem);
1254 spin_lock_init(&ha->hardware_lock);
1256 /* Allocate dma buffers */
1257 if (qla4xxx_mem_alloc(ha)) {
1258 dev_warn(&ha->pdev->dev,
1259 "[ERROR] Failed to allocate memory for adapter\n");
1261 ret = -ENOMEM;
1262 goto probe_failed;
1266 * Initialize the Host adapter request/response queues and
1267 * firmware
1268 * NOTE: interrupts enabled upon successful completion
1270 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1271 while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
1272 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1273 "(%d)\n", __func__, init_retry_count));
1274 qla4xxx_soft_reset(ha);
1275 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1277 if (status == QLA_ERROR) {
1278 dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
1280 ret = -ENODEV;
1281 goto probe_failed;
1284 host->cmd_per_lun = 3;
1285 host->max_channel = 0;
1286 host->max_lun = MAX_LUNS - 1;
1287 host->max_id = MAX_TARGETS;
1288 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1289 host->can_queue = MAX_SRBS ;
1290 host->transportt = qla4xxx_scsi_transport;
1292 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1293 if (ret) {
1294 dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
1295 goto probe_failed;
1298 /* Startup the kernel thread for this host adapter. */
1299 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1300 "qla4xxx_dpc\n", __func__));
1301 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1302 ha->dpc_thread = create_singlethread_workqueue(buf);
1303 if (!ha->dpc_thread) {
1304 dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
1305 ret = -ENODEV;
1306 goto probe_failed;
1308 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
1310 ret = request_irq(pdev->irq, qla4xxx_intr_handler,
1311 IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
1312 if (ret) {
1313 dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
1314 " already in use.\n", pdev->irq);
1315 goto probe_failed;
1317 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1318 host->irq = pdev->irq;
1319 DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
1321 qla4xxx_enable_intrs(ha);
1323 /* Start timer thread. */
1324 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1326 set_bit(AF_INIT_DONE, &ha->flags);
1328 pci_set_drvdata(pdev, ha);
1330 ret = scsi_add_host(host, &pdev->dev);
1331 if (ret)
1332 goto probe_failed;
1334 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
1335 /* Update transport device information for all devices. */
1336 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
1337 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
1338 if (qla4xxx_add_sess(ddb_entry))
1339 goto remove_host;
1342 =======
1343 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
1344 printk(KERN_INFO
1345 " QLogic iSCSI HBA Driver version: %s\n"
1346 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1347 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1348 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1349 ha->patch_number, ha->build_number);
1350 scsi_scan_host(host);
1351 return 0;
1353 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
1354 remove_host:
1355 qla4xxx_free_ddb_list(ha);
1356 scsi_remove_host(host);
1358 =======
1359 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
1360 probe_failed:
1361 qla4xxx_free_adapter(ha);
1362 scsi_host_put(ha->host);
1364 probe_disable_device:
1365 pci_disable_device(pdev);
1367 return ret;
1371 * qla4xxx_remove_adapter - calback function to remove adapter.
1372 * @pci_dev: PCI device pointer
1374 static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1376 struct scsi_qla_host *ha;
1378 ha = pci_get_drvdata(pdev);
1380 qla4xxx_disable_intrs(ha);
1382 while (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
1383 ssleep(1);
1385 /* remove devs from iscsi_sessions to scsi_devices */
1386 qla4xxx_free_ddb_list(ha);
1388 scsi_remove_host(ha->host);
1390 qla4xxx_free_adapter(ha);
1392 scsi_host_put(ha->host);
1394 pci_set_drvdata(pdev, NULL);
1398 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1399 * @ha: HA context
1401 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1402 * supported addressing method.
1404 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
1406 int retval;
1408 /* Update our PCI device dma_mask for full 64 bit mask */
1409 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1410 if (pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1411 dev_dbg(&ha->pdev->dev,
1412 "Failed to set 64 bit PCI consistent mask; "
1413 "using 32 bit.\n");
1414 retval = pci_set_consistent_dma_mask(ha->pdev,
1415 DMA_32BIT_MASK);
1417 } else
1418 retval = pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1421 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1423 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1424 struct ddb_entry *ddb = sess->dd_data;
1426 sdev->hostdata = ddb;
1427 sdev->tagged_supported = 1;
1428 scsi_activate_tcq(sdev, sdev->host->can_queue);
1429 return 0;
1432 static int qla4xxx_slave_configure(struct scsi_device *sdev)
1434 sdev->tagged_supported = 1;
1435 return 0;
1438 static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1440 scsi_deactivate_tcq(sdev, 1);
1444 * qla4xxx_del_from_active_array - returns an active srb
1445 * @ha: Pointer to host adapter structure.
1446 * @index: index into to the active_array
1448 * This routine removes and returns the srb at the specified index
1450 struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index)
1452 struct srb *srb = NULL;
1453 struct scsi_cmnd *cmd;
1455 if (!(cmd = scsi_host_find_tag(ha->host, index)))
1456 return srb;
1458 if (!(srb = (struct srb *)cmd->host_scribble))
1459 return srb;
1461 /* update counters */
1462 if (srb->flags & SRB_DMA_VALID) {
1463 ha->req_q_count += srb->iocb_cnt;
1464 ha->iocb_cnt -= srb->iocb_cnt;
1465 if (srb->cmd)
1466 srb->cmd->host_scribble = NULL;
1468 return srb;
1472 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1473 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1474 * @cmd: Scsi Command to wait on.
1476 * This routine waits for the command to be returned by the Firmware
1477 * for some max time.
1479 static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1480 struct scsi_cmnd *cmd)
1482 int done = 0;
1483 struct srb *rp;
1484 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1486 do {
1487 /* Checking to see if its returned to OS */
1488 rp = (struct srb *) cmd->SCp.ptr;
1489 if (rp == NULL) {
1490 done++;
1491 break;
1494 msleep(2000);
1495 } while (max_wait_time--);
1497 return done;
1501 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1502 * @ha: Pointer to host adapter structure
1504 static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1506 unsigned long wait_online;
1508 wait_online = jiffies + (30 * HZ);
1509 while (time_before(jiffies, wait_online)) {
1511 if (adapter_up(ha))
1512 return QLA_SUCCESS;
1513 else if (ha->retry_reset_ha_cnt == 0)
1514 return QLA_ERROR;
1516 msleep(2000);
1519 return QLA_ERROR;
1523 * qla4xxx_eh_wait_for_active_target_commands - wait for active cmds to finish.
1524 * @ha: pointer to to HBA
1525 * @t: target id
1526 * @l: lun id
1528 * This function waits for all outstanding commands to a lun to complete. It
1529 * returns 0 if all pending commands are returned and 1 otherwise.
1531 static int qla4xxx_eh_wait_for_active_target_commands(struct scsi_qla_host *ha,
1532 int t, int l)
1534 int cnt;
1535 int status = 0;
1536 struct scsi_cmnd *cmd;
1539 * Waiting for all commands for the designated target in the active
1540 * array
1542 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1543 cmd = scsi_host_find_tag(ha->host, cnt);
1544 if (cmd && cmd->device->id == t && cmd->device->lun == l) {
1545 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1546 status++;
1547 break;
1551 return status;
1555 * qla4xxx_eh_device_reset - callback for target reset.
1556 * @cmd: Pointer to Linux's SCSI command structure
1558 * This routine is called by the Linux OS to reset all luns on the
1559 * specified target.
1561 static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
1563 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1564 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1565 struct srb *sp;
1566 int ret = FAILED, stat;
1568 sp = (struct srb *) cmd->SCp.ptr;
1569 if (!sp || !ddb_entry)
1570 return ret;
1572 dev_info(&ha->pdev->dev,
1573 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
1574 cmd->device->channel, cmd->device->id, cmd->device->lun);
1576 DEBUG2(printk(KERN_INFO
1577 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1578 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
1579 cmd, jiffies, cmd->timeout_per_command / HZ,
1580 ha->dpc_flags, cmd->result, cmd->allowed));
1582 /* FIXME: wait for hba to go online */
1583 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
1584 if (stat != QLA_SUCCESS) {
1585 dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
1586 goto eh_dev_reset_done;
1589 /* Send marker. */
1590 ha->marker_needed = 1;
1593 * If we are coming down the EH path, wait for all commands to complete
1594 * for the device.
1596 if (cmd->device->host->shost_state == SHOST_RECOVERY) {
1597 if (qla4xxx_eh_wait_for_active_target_commands(ha,
1598 cmd->device->id,
1599 cmd->device->lun)){
1600 dev_info(&ha->pdev->dev,
1601 "DEVICE RESET FAILED - waiting for "
1602 "commands.\n");
1603 goto eh_dev_reset_done;
1607 dev_info(&ha->pdev->dev,
1608 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1609 ha->host_no, cmd->device->channel, cmd->device->id,
1610 cmd->device->lun);
1612 ret = SUCCESS;
1614 eh_dev_reset_done:
1616 return ret;
1620 * qla4xxx_eh_host_reset - kernel callback
1621 * @cmd: Pointer to Linux's SCSI command structure
1623 * This routine is invoked by the Linux kernel to perform fatal error
1624 * recovery on the specified adapter.
1626 static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
1628 int return_status = FAILED;
1629 struct scsi_qla_host *ha;
1631 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
1633 dev_info(&ha->pdev->dev,
1634 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no,
1635 cmd->device->channel, cmd->device->id, cmd->device->lun);
1637 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
1638 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1639 "DEAD.\n", ha->host_no, cmd->device->channel,
1640 __func__));
1642 return FAILED;
1645 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
1646 if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS) {
1647 =======
1648 /* make sure the dpc thread is stopped while we reset the hba */
1649 clear_bit(AF_ONLINE, &ha->flags);
1650 flush_workqueue(ha->dpc_thread);
1652 if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS)
1653 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
1654 return_status = SUCCESS;
1655 <<<<<<< HEAD:drivers/scsi/qla4xxx/ql4_os.c
1657 =======
1658 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/scsi/qla4xxx/ql4_os.c
1660 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
1661 return_status == FAILED ? "FAILED" : "SUCCEDED");
1663 return return_status;
1667 static struct pci_device_id qla4xxx_pci_tbl[] = {
1669 .vendor = PCI_VENDOR_ID_QLOGIC,
1670 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
1671 .subvendor = PCI_ANY_ID,
1672 .subdevice = PCI_ANY_ID,
1675 .vendor = PCI_VENDOR_ID_QLOGIC,
1676 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
1677 .subvendor = PCI_ANY_ID,
1678 .subdevice = PCI_ANY_ID,
1681 .vendor = PCI_VENDOR_ID_QLOGIC,
1682 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
1683 .subvendor = PCI_ANY_ID,
1684 .subdevice = PCI_ANY_ID,
1686 {0, 0},
1688 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
1690 static struct pci_driver qla4xxx_pci_driver = {
1691 .name = DRIVER_NAME,
1692 .id_table = qla4xxx_pci_tbl,
1693 .probe = qla4xxx_probe_adapter,
1694 .remove = qla4xxx_remove_adapter,
1697 static int __init qla4xxx_module_init(void)
1699 int ret;
1701 /* Allocate cache for SRBs. */
1702 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
1703 SLAB_HWCACHE_ALIGN, NULL);
1704 if (srb_cachep == NULL) {
1705 printk(KERN_ERR
1706 "%s: Unable to allocate SRB cache..."
1707 "Failing load!\n", DRIVER_NAME);
1708 ret = -ENOMEM;
1709 goto no_srp_cache;
1712 /* Derive version string. */
1713 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
1714 if (ql4xextended_error_logging)
1715 strcat(qla4xxx_version_str, "-debug");
1717 qla4xxx_scsi_transport =
1718 iscsi_register_transport(&qla4xxx_iscsi_transport);
1719 if (!qla4xxx_scsi_transport){
1720 ret = -ENODEV;
1721 goto release_srb_cache;
1724 ret = pci_register_driver(&qla4xxx_pci_driver);
1725 if (ret)
1726 goto unregister_transport;
1728 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
1729 return 0;
1731 unregister_transport:
1732 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1733 release_srb_cache:
1734 kmem_cache_destroy(srb_cachep);
1735 no_srp_cache:
1736 return ret;
1739 static void __exit qla4xxx_module_exit(void)
1741 ql4_mod_unload = 1;
1742 pci_unregister_driver(&qla4xxx_pci_driver);
1743 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1744 kmem_cache_destroy(srb_cachep);
1747 module_init(qla4xxx_module_init);
1748 module_exit(qla4xxx_module_exit);
1750 MODULE_AUTHOR("QLogic Corporation");
1751 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1752 MODULE_LICENSE("GPL");
1753 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);