blob: db7ea3bb4e833afb50884b92c74f1b98c4b5d6ec [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
3 * Copyright (c) 2003-2006 QLogic Corporation
4 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7#include <linux/moduleparam.h>
8
9#include <scsi/scsi_tcq.h>
10#include <scsi/scsicam.h>
11
12#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070013#include "ql4_version.h"
14#include "ql4_glbl.h"
15#include "ql4_dbg.h"
16#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070017
18/*
19 * Driver version
20 */
Adrian Bunk47975472007-04-26 00:35:16 -070021static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070022
23/*
24 * SRB allocation cache
25 */
Christoph Lametere18b8902006-12-06 20:33:20 -080026static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070027
28/*
29 * Module parameter information and variables
30 */
31int ql4xdiscoverywait = 60;
32module_param(ql4xdiscoverywait, int, S_IRUGO | S_IRUSR);
33MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
34int ql4xdontresethba = 0;
35module_param(ql4xdontresethba, int, S_IRUGO | S_IRUSR);
36MODULE_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");
40
Andrew Vasquez11010fe2006-10-06 09:54:59 -070041int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
42module_param(ql4xextended_error_logging, int, S_IRUGO | S_IRUSR);
43MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070044 "Option to enable extended error logging, "
45 "Default is 0 - no logging, 1 - debug logging");
46
David C Somayajulu477ffb92007-01-22 12:26:11 -080047int ql4_mod_unload = 0;
48
Mike Christied510d962008-07-11 19:50:33 -050049#define QL4_DEF_QDEPTH 32
50
David Somayajuluafaf5a22006-09-19 10:28:00 -070051/*
52 * SCSI host template entry points
53 */
Adrian Bunk47975472007-04-26 00:35:16 -070054static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070055
56/*
57 * iSCSI template entry points
58 */
Mike Christie2174a042007-05-30 12:57:10 -050059static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
60 enum iscsi_tgt_dscvr type, uint32_t enable,
61 struct sockaddr *dst_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -070062static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
63 enum iscsi_param param, char *buf);
64static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
65 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050066static int qla4xxx_host_get_param(struct Scsi_Host *shost,
67 enum iscsi_host_param param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -070068static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
69
70/*
71 * SCSI host template entry points
72 */
73static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
74 void (*done) (struct scsi_cmnd *));
75static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -060076static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070077static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
78static int qla4xxx_slave_alloc(struct scsi_device *device);
79static int qla4xxx_slave_configure(struct scsi_device *device);
80static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie024f8012008-03-04 13:26:54 -060081static void qla4xxx_scan_start(struct Scsi_Host *shost);
David Somayajuluafaf5a22006-09-19 10:28:00 -070082
83static struct scsi_host_template qla4xxx_driver_template = {
84 .module = THIS_MODULE,
85 .name = DRIVER_NAME,
86 .proc_name = DRIVER_NAME,
87 .queuecommand = qla4xxx_queuecommand,
88
89 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -060090 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -070091 .eh_host_reset_handler = qla4xxx_eh_host_reset,
92
93 .slave_configure = qla4xxx_slave_configure,
94 .slave_alloc = qla4xxx_slave_alloc,
95 .slave_destroy = qla4xxx_slave_destroy,
96
Mike Christie921601b2008-01-31 13:36:49 -060097 .scan_finished = iscsi_scan_finished,
Mike Christie024f8012008-03-04 13:26:54 -060098 .scan_start = qla4xxx_scan_start,
Mike Christie921601b2008-01-31 13:36:49 -060099
David Somayajuluafaf5a22006-09-19 10:28:00 -0700100 .this_id = -1,
101 .cmd_per_lun = 3,
102 .use_clustering = ENABLE_CLUSTERING,
103 .sg_tablesize = SG_ALL,
104
105 .max_sectors = 0xFFFF,
106};
107
108static struct iscsi_transport qla4xxx_iscsi_transport = {
109 .owner = THIS_MODULE,
110 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500111 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
112 CAP_DATA_PATH_OFFLOAD,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500113 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
114 ISCSI_TARGET_NAME | ISCSI_TPGT,
Mike Christie8ad57812007-05-30 12:57:13 -0500115 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christie22236962007-05-30 12:57:24 -0500116 ISCSI_HOST_IPADDRESS |
Mike Christie8ad57812007-05-30 12:57:13 -0500117 ISCSI_HOST_INITIATOR_NAME,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700118 .tgt_dscvr = qla4xxx_tgt_dscvr,
119 .get_conn_param = qla4xxx_conn_get_param,
120 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500121 .get_host_param = qla4xxx_host_get_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700122 .session_recovery_timedout = qla4xxx_recovery_timedout,
123};
124
125static struct scsi_transport_template *qla4xxx_scsi_transport;
126
127static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
128{
129 struct ddb_entry *ddb_entry = session->dd_data;
130 struct scsi_qla_host *ha = ddb_entry->ha;
131
Mike Christie568d3032008-01-31 13:36:47 -0600132 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
133 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134
Mike Christie568d3032008-01-31 13:36:47 -0600135 DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
136 "of (%d) secs exhausted, marking device DEAD.\n",
137 ha->host_no, __func__, ddb_entry->fw_ddb_index,
138 ha->port_down_retry_count));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700139
Mike Christie568d3032008-01-31 13:36:47 -0600140 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
141 "flags = 0x%lx\n",
142 ha->host_no, __func__, ha->dpc_flags));
143 queue_work(ha->dpc_thread, &ha->dpc_work);
144 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700145}
146
Mike Christieaa1e93a2007-05-30 12:57:09 -0500147static int qla4xxx_host_get_param(struct Scsi_Host *shost,
148 enum iscsi_host_param param, char *buf)
149{
150 struct scsi_qla_host *ha = to_qla_host(shost);
151 int len;
152
153 switch (param) {
154 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800155 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500156 break;
Mike Christie22236962007-05-30 12:57:24 -0500157 case ISCSI_HOST_PARAM_IPADDRESS:
158 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
159 ha->ip_address[1], ha->ip_address[2],
160 ha->ip_address[3]);
161 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500162 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500163 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500164 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500165 default:
166 return -ENOSYS;
167 }
168
169 return len;
170}
171
David Somayajuluafaf5a22006-09-19 10:28:00 -0700172static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
173 enum iscsi_param param, char *buf)
174{
175 struct ddb_entry *ddb_entry = sess->dd_data;
176 int len;
177
178 switch (param) {
179 case ISCSI_PARAM_TARGET_NAME:
180 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
181 ddb_entry->iscsi_name);
182 break;
183 case ISCSI_PARAM_TPGT:
184 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
185 break;
186 default:
187 return -ENOSYS;
188 }
189
190 return len;
191}
192
193static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
194 enum iscsi_param param, char *buf)
195{
196 struct iscsi_cls_session *session;
197 struct ddb_entry *ddb_entry;
198 int len;
199
200 session = iscsi_dev_to_session(conn->dev.parent);
201 ddb_entry = session->dd_data;
202
203 switch (param) {
204 case ISCSI_PARAM_CONN_PORT:
205 len = sprintf(buf, "%hu\n", ddb_entry->port);
206 break;
207 case ISCSI_PARAM_CONN_ADDRESS:
208 /* TODO: what are the ipv6 bits */
209 len = sprintf(buf, "%u.%u.%u.%u\n",
210 NIPQUAD(ddb_entry->ip_addr));
211 break;
212 default:
213 return -ENOSYS;
214 }
215
216 return len;
217}
218
Mike Christie2174a042007-05-30 12:57:10 -0500219static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
220 enum iscsi_tgt_dscvr type, uint32_t enable,
221 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700222{
223 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700224 struct sockaddr_in *addr;
225 struct sockaddr_in6 *addr6;
226 int ret = 0;
227
David Somayajuluafaf5a22006-09-19 10:28:00 -0700228 ha = (struct scsi_qla_host *) shost->hostdata;
229
230 switch (type) {
231 case ISCSI_TGT_DSCVR_SEND_TARGETS:
232 if (dst_addr->sa_family == AF_INET) {
233 addr = (struct sockaddr_in *)dst_addr;
234 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
235 addr->sin_port) != QLA_SUCCESS)
236 ret = -EIO;
237 } else if (dst_addr->sa_family == AF_INET6) {
238 /*
239 * TODO: fix qla4xxx_send_tgts
240 */
241 addr6 = (struct sockaddr_in6 *)dst_addr;
242 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
243 addr6->sin6_port) != QLA_SUCCESS)
244 ret = -EIO;
245 } else
246 ret = -ENOSYS;
247 break;
248 default:
249 ret = -ENOSYS;
250 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700251 return ret;
252}
253
254void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
255{
256 if (!ddb_entry->sess)
257 return;
258
259 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600260 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700261 iscsi_remove_session(ddb_entry->sess);
262 }
263 iscsi_free_session(ddb_entry->sess);
264}
265
266int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
267{
268 int err;
269
Mike Christie26974782007-12-13 12:43:29 -0600270 ddb_entry->sess->recovery_tmo = ddb_entry->ha->port_down_retry_count;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700271 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
272 if (err) {
273 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
274 return err;
275 }
276
Mike Christie5d91e202008-05-21 15:54:01 -0500277 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700278 if (!ddb_entry->conn) {
279 iscsi_remove_session(ddb_entry->sess);
280 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
281 return -ENOMEM;
282 }
Mike Christieb6359302008-01-31 13:36:44 -0600283
284 /* finally ready to go */
285 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700286 return 0;
287}
288
289struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
290{
291 struct ddb_entry *ddb_entry;
292 struct iscsi_cls_session *sess;
293
Mike Christie5d91e202008-05-21 15:54:01 -0500294 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
295 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700296 if (!sess)
297 return NULL;
298
299 ddb_entry = sess->dd_data;
300 memset(ddb_entry, 0, sizeof(*ddb_entry));
301 ddb_entry->ha = ha;
302 ddb_entry->sess = sess;
303 return ddb_entry;
304}
305
Mike Christie024f8012008-03-04 13:26:54 -0600306static void qla4xxx_scan_start(struct Scsi_Host *shost)
307{
308 struct scsi_qla_host *ha = shost_priv(shost);
309 struct ddb_entry *ddb_entry, *ddbtemp;
310
311 /* finish setup of sessions that were already setup in firmware */
312 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
313 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
314 qla4xxx_add_sess(ddb_entry);
315 }
316}
317
David Somayajuluafaf5a22006-09-19 10:28:00 -0700318/*
319 * Timer routines
320 */
321
322static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
323 unsigned long interval)
324{
325 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
326 __func__, ha->host->host_no));
327 init_timer(&ha->timer);
328 ha->timer.expires = jiffies + interval * HZ;
329 ha->timer.data = (unsigned long)ha;
330 ha->timer.function = (void (*)(unsigned long))func;
331 add_timer(&ha->timer);
332 ha->timer_active = 1;
333}
334
335static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
336{
337 del_timer_sync(&ha->timer);
338 ha->timer_active = 0;
339}
340
341/***
342 * qla4xxx_mark_device_missing - mark a device as missing.
343 * @ha: Pointer to host adapter structure.
344 * @ddb_entry: Pointer to device database entry
345 *
346 * This routine marks a device missing and resets the relogin retry count.
347 **/
348void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
349 struct ddb_entry *ddb_entry)
350{
351 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
352 DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
353 ha->host_no, ddb_entry->bus, ddb_entry->target,
354 ddb_entry->fw_ddb_index));
Mike Christieb6359302008-01-31 13:36:44 -0600355 iscsi_block_session(ddb_entry->sess);
Mike Christiee5bd7b52008-09-24 11:46:10 -0500356 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700357}
358
359static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
360 struct ddb_entry *ddb_entry,
361 struct scsi_cmnd *cmd,
362 void (*done)(struct scsi_cmnd *))
363{
364 struct srb *srb;
365
366 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
367 if (!srb)
368 return srb;
369
370 atomic_set(&srb->ref_count, 1);
371 srb->ha = ha;
372 srb->ddb = ddb_entry;
373 srb->cmd = cmd;
374 srb->flags = 0;
375 cmd->SCp.ptr = (void *)srb;
376 cmd->scsi_done = done;
377
378 return srb;
379}
380
381static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
382{
383 struct scsi_cmnd *cmd = srb->cmd;
384
385 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900386 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700387 srb->flags &= ~SRB_DMA_VALID;
388 }
389 cmd->SCp.ptr = NULL;
390}
391
392void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb)
393{
394 struct scsi_cmnd *cmd = srb->cmd;
395
396 qla4xxx_srb_free_dma(ha, srb);
397
398 mempool_free(srb, ha->srb_mempool);
399
400 cmd->scsi_done(cmd);
401}
402
403/**
404 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
405 * @cmd: Pointer to Linux's SCSI command structure
406 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
407 * that the command has been processed.
408 *
409 * Remarks:
410 * This routine is invoked by Linux to send a SCSI command to the driver.
411 * The mid-level driver tries to ensure that queuecommand never gets
412 * invoked concurrently with itself or the interrupt handler (although
413 * the interrupt handler may call this routine as part of request-
414 * completion handling). Unfortunely, it sometimes calls the scheduler
415 * in interrupt context which is a big NO! NO!.
416 **/
417static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
418 void (*done)(struct scsi_cmnd *))
419{
420 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
421 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -0600422 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700423 struct srb *srb;
424 int rval;
425
Mike Christie7fb19212008-01-31 13:36:45 -0600426 if (!sess) {
427 cmd->result = DID_IMM_RETRY << 16;
428 goto qc_fail_command;
429 }
430
431 rval = iscsi_session_chkready(sess);
432 if (rval) {
433 cmd->result = rval;
434 goto qc_fail_command;
435 }
436
David Somayajuluafaf5a22006-09-19 10:28:00 -0700437 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
438 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
439 cmd->result = DID_NO_CONNECT << 16;
440 goto qc_fail_command;
441 }
Mike Christiec5e98e92008-08-17 15:24:39 -0500442 return SCSI_MLQUEUE_TARGET_BUSY;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443 }
444
David C Somayajulu477ffb92007-01-22 12:26:11 -0800445 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
446 goto qc_host_busy;
447
David Somayajuluafaf5a22006-09-19 10:28:00 -0700448 spin_unlock_irq(ha->host->host_lock);
449
450 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
451 if (!srb)
452 goto qc_host_busy_lock;
453
454 rval = qla4xxx_send_command_to_isp(ha, srb);
455 if (rval != QLA_SUCCESS)
456 goto qc_host_busy_free_sp;
457
458 spin_lock_irq(ha->host->host_lock);
459 return 0;
460
461qc_host_busy_free_sp:
462 qla4xxx_srb_free_dma(ha, srb);
463 mempool_free(srb, ha->srb_mempool);
464
465qc_host_busy_lock:
466 spin_lock_irq(ha->host->host_lock);
467
468qc_host_busy:
469 return SCSI_MLQUEUE_HOST_BUSY;
470
471qc_fail_command:
472 done(cmd);
473
474 return 0;
475}
476
477/**
478 * qla4xxx_mem_free - frees memory allocated to adapter
479 * @ha: Pointer to host adapter structure.
480 *
481 * Frees memory previously allocated by qla4xxx_mem_alloc
482 **/
483static void qla4xxx_mem_free(struct scsi_qla_host *ha)
484{
485 if (ha->queues)
486 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
487 ha->queues_dma);
488
489 ha->queues_len = 0;
490 ha->queues = NULL;
491 ha->queues_dma = 0;
492 ha->request_ring = NULL;
493 ha->request_dma = 0;
494 ha->response_ring = NULL;
495 ha->response_dma = 0;
496 ha->shadow_regs = NULL;
497 ha->shadow_regs_dma = 0;
498
499 /* Free srb pool. */
500 if (ha->srb_mempool)
501 mempool_destroy(ha->srb_mempool);
502
503 ha->srb_mempool = NULL;
504
505 /* release io space registers */
506 if (ha->reg)
507 iounmap(ha->reg);
508 pci_release_regions(ha->pdev);
509}
510
511/**
512 * qla4xxx_mem_alloc - allocates memory for use by adapter.
513 * @ha: Pointer to host adapter structure
514 *
515 * Allocates DMA memory for request and response queues. Also allocates memory
516 * for srbs.
517 **/
518static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
519{
520 unsigned long align;
521
522 /* Allocate contiguous block of DMA memory for queues. */
523 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
524 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
525 sizeof(struct shadow_regs) +
526 MEM_ALIGN_VALUE +
527 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
528 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
529 &ha->queues_dma, GFP_KERNEL);
530 if (ha->queues == NULL) {
531 dev_warn(&ha->pdev->dev,
532 "Memory Allocation failed - queues.\n");
533
534 goto mem_alloc_error_exit;
535 }
536 memset(ha->queues, 0, ha->queues_len);
537
538 /*
539 * As per RISC alignment requirements -- the bus-address must be a
540 * multiple of the request-ring size (in bytes).
541 */
542 align = 0;
543 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
544 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
545 (MEM_ALIGN_VALUE - 1));
546
547 /* Update request and response queue pointers. */
548 ha->request_dma = ha->queues_dma + align;
549 ha->request_ring = (struct queue_entry *) (ha->queues + align);
550 ha->response_dma = ha->queues_dma + align +
551 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
552 ha->response_ring = (struct queue_entry *) (ha->queues + align +
553 (REQUEST_QUEUE_DEPTH *
554 QUEUE_SIZE));
555 ha->shadow_regs_dma = ha->queues_dma + align +
556 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
557 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
558 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
559 (REQUEST_QUEUE_DEPTH *
560 QUEUE_SIZE) +
561 (RESPONSE_QUEUE_DEPTH *
562 QUEUE_SIZE));
563
564 /* Allocate memory for srb pool. */
565 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
566 mempool_free_slab, srb_cachep);
567 if (ha->srb_mempool == NULL) {
568 dev_warn(&ha->pdev->dev,
569 "Memory Allocation failed - SRB Pool.\n");
570
571 goto mem_alloc_error_exit;
572 }
573
574 return QLA_SUCCESS;
575
576mem_alloc_error_exit:
577 qla4xxx_mem_free(ha);
578 return QLA_ERROR;
579}
580
581/**
582 * qla4xxx_timer - checks every second for work to do.
583 * @ha: Pointer to host adapter structure.
584 **/
585static void qla4xxx_timer(struct scsi_qla_host *ha)
586{
587 struct ddb_entry *ddb_entry, *dtemp;
588 int start_dpc = 0;
589
590 /* Search for relogin's to time-out and port down retry. */
591 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
592 /* Count down time between sending relogins */
593 if (adapter_up(ha) &&
594 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
595 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
596 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
597 INVALID_ENTRY) {
598 if (atomic_read(&ddb_entry->retry_relogin_timer)
599 == 0) {
600 atomic_set(&ddb_entry->
601 retry_relogin_timer,
602 INVALID_ENTRY);
603 set_bit(DPC_RELOGIN_DEVICE,
604 &ha->dpc_flags);
605 set_bit(DF_RELOGIN, &ddb_entry->flags);
606 DEBUG2(printk("scsi%ld: %s: index [%d]"
607 " login device\n",
608 ha->host_no, __func__,
609 ddb_entry->fw_ddb_index));
610 } else
611 atomic_dec(&ddb_entry->
612 retry_relogin_timer);
613 }
614 }
615
616 /* Wait for relogin to timeout */
617 if (atomic_read(&ddb_entry->relogin_timer) &&
618 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
619 /*
620 * If the relogin times out and the device is
621 * still NOT ONLINE then try and relogin again.
622 */
623 if (atomic_read(&ddb_entry->state) !=
624 DDB_STATE_ONLINE &&
625 ddb_entry->fw_ddb_device_state ==
626 DDB_DS_SESSION_FAILED) {
627 /* Reset retry relogin timer */
628 atomic_inc(&ddb_entry->relogin_retry_count);
629 DEBUG2(printk("scsi%ld: index[%d] relogin"
630 " timed out-retrying"
631 " relogin (%d)\n",
632 ha->host_no,
633 ddb_entry->fw_ddb_index,
634 atomic_read(&ddb_entry->
635 relogin_retry_count))
636 );
637 start_dpc++;
638 DEBUG(printk("scsi%ld:%d:%d: index [%d] "
639 "initate relogin after"
640 " %d seconds\n",
641 ha->host_no, ddb_entry->bus,
642 ddb_entry->target,
643 ddb_entry->fw_ddb_index,
644 ddb_entry->default_time2wait + 4)
645 );
646
647 atomic_set(&ddb_entry->retry_relogin_timer,
648 ddb_entry->default_time2wait + 4);
649 }
650 }
651 }
652
653 /* Check for heartbeat interval. */
654 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
655 ha->heartbeat_interval != 0) {
656 ha->seconds_since_last_heartbeat++;
657 if (ha->seconds_since_last_heartbeat >
658 ha->heartbeat_interval + 2)
659 set_bit(DPC_RESET_HA, &ha->dpc_flags);
660 }
661
662
663 /* Wakeup the dpc routine for this adapter, if needed. */
664 if ((start_dpc ||
665 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
666 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
667 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
668 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
669 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
670 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
671 test_bit(DPC_AEN, &ha->dpc_flags)) &&
672 ha->dpc_thread) {
673 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
674 " - dpc flags = 0x%lx\n",
675 ha->host_no, __func__, ha->dpc_flags));
676 queue_work(ha->dpc_thread, &ha->dpc_work);
677 }
678
679 /* Reschedule timer thread to call us back in one second */
680 mod_timer(&ha->timer, jiffies + HZ);
681
682 DEBUG2(ha->seconds_since_last_intr++);
683}
684
685/**
686 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
687 * @ha: Pointer to host adapter structure.
688 *
689 * This routine stalls the driver until all outstanding commands are returned.
690 * Caller must release the Hardware Lock prior to calling this routine.
691 **/
692static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
693{
694 uint32_t index = 0;
695 int stat = QLA_SUCCESS;
696 unsigned long flags;
697 struct scsi_cmnd *cmd;
698 int wait_cnt = WAIT_CMD_TOV; /*
699 * Initialized for 30 seconds as we
700 * expect all commands to retuned
701 * ASAP.
702 */
703
704 while (wait_cnt) {
705 spin_lock_irqsave(&ha->hardware_lock, flags);
706 /* Find a command that hasn't completed. */
707 for (index = 0; index < ha->host->can_queue; index++) {
708 cmd = scsi_host_find_tag(ha->host, index);
709 if (cmd != NULL)
710 break;
711 }
712 spin_unlock_irqrestore(&ha->hardware_lock, flags);
713
714 /* If No Commands are pending, wait is complete */
715 if (index == ha->host->can_queue) {
716 break;
717 }
718
719 /* If we timed out on waiting for commands to come back
720 * return ERROR.
721 */
722 wait_cnt--;
723 if (wait_cnt == 0)
724 stat = QLA_ERROR;
725 else {
726 msleep(1000);
727 }
728 } /* End of While (wait_cnt) */
729
730 return stat;
731}
732
David C Somayajulubee4fe82007-05-23 18:03:32 -0700733void qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700734{
David Somayajuluafaf5a22006-09-19 10:28:00 -0700735 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800736 unsigned long flags = 0;
737
738 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700739
740 spin_lock_irqsave(&ha->hardware_lock, flags);
741
742 /*
743 * If the SCSI Reset Interrupt bit is set, clear it.
744 * Otherwise, the Soft Reset won't work.
745 */
746 ctrl_status = readw(&ha->reg->ctrl_status);
747 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
748 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
749
750 /* Issue Soft Reset */
751 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
752 readl(&ha->reg->ctrl_status);
753
754 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David C Somayajulu477ffb92007-01-22 12:26:11 -0800755}
756
757/**
758 * qla4xxx_soft_reset - performs soft reset.
759 * @ha: Pointer to host adapter structure.
760 **/
761int qla4xxx_soft_reset(struct scsi_qla_host *ha)
762{
763 uint32_t max_wait_time;
764 unsigned long flags = 0;
765 int status = QLA_ERROR;
766 uint32_t ctrl_status;
767
768 qla4xxx_hw_reset(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700769
770 /* Wait until the Network Reset Intr bit is cleared */
771 max_wait_time = RESET_INTR_TOV;
772 do {
773 spin_lock_irqsave(&ha->hardware_lock, flags);
774 ctrl_status = readw(&ha->reg->ctrl_status);
775 spin_unlock_irqrestore(&ha->hardware_lock, flags);
776
777 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
778 break;
779
780 msleep(1000);
781 } while ((--max_wait_time));
782
783 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
784 DEBUG2(printk(KERN_WARNING
785 "scsi%ld: Network Reset Intr not cleared by "
786 "Network function, clearing it now!\n",
787 ha->host_no));
788 spin_lock_irqsave(&ha->hardware_lock, flags);
789 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
790 readl(&ha->reg->ctrl_status);
791 spin_unlock_irqrestore(&ha->hardware_lock, flags);
792 }
793
794 /* Wait until the firmware tells us the Soft Reset is done */
795 max_wait_time = SOFT_RESET_TOV;
796 do {
797 spin_lock_irqsave(&ha->hardware_lock, flags);
798 ctrl_status = readw(&ha->reg->ctrl_status);
799 spin_unlock_irqrestore(&ha->hardware_lock, flags);
800
801 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
802 status = QLA_SUCCESS;
803 break;
804 }
805
806 msleep(1000);
807 } while ((--max_wait_time));
808
809 /*
810 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
811 * after the soft reset has taken place.
812 */
813 spin_lock_irqsave(&ha->hardware_lock, flags);
814 ctrl_status = readw(&ha->reg->ctrl_status);
815 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
816 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
817 readl(&ha->reg->ctrl_status);
818 }
819 spin_unlock_irqrestore(&ha->hardware_lock, flags);
820
821 /* If soft reset fails then most probably the bios on other
822 * function is also enabled.
823 * Since the initialization is sequential the other fn
824 * wont be able to acknowledge the soft reset.
825 * Issue a force soft reset to workaround this scenario.
826 */
827 if (max_wait_time == 0) {
828 /* Issue Force Soft Reset */
829 spin_lock_irqsave(&ha->hardware_lock, flags);
830 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
831 readl(&ha->reg->ctrl_status);
832 spin_unlock_irqrestore(&ha->hardware_lock, flags);
833 /* Wait until the firmware tells us the Soft Reset is done */
834 max_wait_time = SOFT_RESET_TOV;
835 do {
836 spin_lock_irqsave(&ha->hardware_lock, flags);
837 ctrl_status = readw(&ha->reg->ctrl_status);
838 spin_unlock_irqrestore(&ha->hardware_lock, flags);
839
840 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
841 status = QLA_SUCCESS;
842 break;
843 }
844
845 msleep(1000);
846 } while ((--max_wait_time));
847 }
848
849 return status;
850}
851
852/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700853 * qla4xxx_flush_active_srbs - returns all outstanding i/o requests to O.S.
854 * @ha: Pointer to host adapter structure.
855 *
856 * This routine is called just prior to a HARD RESET to return all
857 * outstanding commands back to the Operating System.
858 * Caller should make sure that the following locks are released
859 * before this calling routine: Hardware lock, and io_request_lock.
860 **/
861static void qla4xxx_flush_active_srbs(struct scsi_qla_host *ha)
862{
863 struct srb *srb;
864 int i;
865 unsigned long flags;
866
867 spin_lock_irqsave(&ha->hardware_lock, flags);
868 for (i = 0; i < ha->host->can_queue; i++) {
869 srb = qla4xxx_del_from_active_array(ha, i);
870 if (srb != NULL) {
871 srb->cmd->result = DID_RESET << 16;
872 qla4xxx_srb_compl(ha, srb);
873 }
874 }
875 spin_unlock_irqrestore(&ha->hardware_lock, flags);
876
877}
878
879/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700880 * qla4xxx_recover_adapter - recovers adapter after a fatal error
881 * @ha: Pointer to host adapter structure.
882 * @renew_ddb_list: Indicates what to do with the adapter's ddb list
Mike Christie50a29ae2008-03-04 13:26:53 -0600883 *
884 * renew_ddb_list value can be 0=preserve ddb list, 1=destroy and rebuild
885 * ddb list.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700886 **/
887static int qla4xxx_recover_adapter(struct scsi_qla_host *ha,
888 uint8_t renew_ddb_list)
889{
890 int status;
891
892 /* Stall incoming I/O until we are done */
893 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -0600894
David Somayajuluafaf5a22006-09-19 10:28:00 -0700895 DEBUG2(printk("scsi%ld: %s calling qla4xxx_cmd_wait\n", ha->host_no,
896 __func__));
897
898 /* Wait for outstanding commands to complete.
899 * Stalls the driver for max 30 secs
900 */
901 status = qla4xxx_cmd_wait(ha);
902
903 qla4xxx_disable_intrs(ha);
904
905 /* Flush any pending ddb changed AENs */
906 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
907
908 /* Reset the firmware. If successful, function
909 * returns with ISP interrupts enabled.
910 */
911 if (status == QLA_SUCCESS) {
912 DEBUG2(printk("scsi%ld: %s - Performing soft reset..\n",
913 ha->host_no, __func__));
David C Somayajuluf26b9042006-11-15 16:41:09 -0800914 qla4xxx_flush_active_srbs(ha);
915 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
916 status = qla4xxx_soft_reset(ha);
917 else
918 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700919 }
920
921 /* Flush any pending ddb changed AENs */
922 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
923
924 /* Re-initialize firmware. If successful, function returns
925 * with ISP interrupts enabled */
926 if (status == QLA_SUCCESS) {
927 DEBUG2(printk("scsi%ld: %s - Initializing adapter..\n",
928 ha->host_no, __func__));
929
930 /* If successful, AF_ONLINE flag set in
931 * qla4xxx_initialize_adapter */
932 status = qla4xxx_initialize_adapter(ha, renew_ddb_list);
933 }
934
935 /* Failed adapter initialization?
936 * Retry reset_ha only if invoked via DPC (DPC_RESET_HA) */
937 if ((test_bit(AF_ONLINE, &ha->flags) == 0) &&
938 (test_bit(DPC_RESET_HA, &ha->dpc_flags))) {
939 /* Adapter initialization failed, see if we can retry
940 * resetting the ha */
941 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
942 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
943 DEBUG2(printk("scsi%ld: recover adapter - retrying "
944 "(%d) more times\n", ha->host_no,
945 ha->retry_reset_ha_cnt));
946 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
947 status = QLA_ERROR;
948 } else {
949 if (ha->retry_reset_ha_cnt > 0) {
950 /* Schedule another Reset HA--DPC will retry */
951 ha->retry_reset_ha_cnt--;
952 DEBUG2(printk("scsi%ld: recover adapter - "
953 "retry remaining %d\n",
954 ha->host_no,
955 ha->retry_reset_ha_cnt));
956 status = QLA_ERROR;
957 }
958
959 if (ha->retry_reset_ha_cnt == 0) {
960 /* Recover adapter retries have been exhausted.
961 * Adapter DEAD */
962 DEBUG2(printk("scsi%ld: recover adapter "
963 "failed - board disabled\n",
964 ha->host_no));
965 qla4xxx_flush_active_srbs(ha);
966 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
967 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
968 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST,
969 &ha->dpc_flags);
970 status = QLA_ERROR;
971 }
972 }
973 } else {
974 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
975 clear_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags);
976 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
977 }
978
979 ha->adapter_error_count++;
980
981 if (status == QLA_SUCCESS)
982 qla4xxx_enable_intrs(ha);
983
984 DEBUG2(printk("scsi%ld: recover adapter .. DONE\n", ha->host_no));
985 return status;
986}
987
988/**
989 * qla4xxx_do_dpc - dpc routine
990 * @data: in our case pointer to adapter structure
991 *
992 * This routine is a task that is schedule by the interrupt handler
993 * to perform the background processing for interrupts. We put it
994 * on a task queue that is consumed whenever the scheduler runs; that's
995 * so you can do anything (i.e. put the process to sleep etc). In fact,
996 * the mid-level tries to sleep when it reaches the driver threshold
997 * "host->can_queue". This can cause a panic if we were in our interrupt code.
998 **/
David Howellsc4028952006-11-22 14:57:56 +0000999static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001000{
David Howellsc4028952006-11-22 14:57:56 +00001001 struct scsi_qla_host *ha =
1002 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001003 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001004 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001005
David C Somayajuluf26b9042006-11-15 16:41:09 -08001006 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
David C Somayajulu477ffb92007-01-22 12:26:11 -08001007 "flags = 0x%08lx, dpc_flags = 0x%08lx ctrl_stat = 0x%08x\n",
1008 ha->host_no, __func__, ha->flags, ha->dpc_flags,
1009 readw(&ha->reg->ctrl_status)));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001010
1011 /* Initialization not yet finished. Don't do anything yet. */
1012 if (!test_bit(AF_INIT_DONE, &ha->flags))
1013 return;
1014
1015 if (adapter_up(ha) ||
1016 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1017 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1018 test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags)) {
David C Somayajuluf26b9042006-11-15 16:41:09 -08001019 if (test_bit(DPC_RESET_HA_DESTROY_DDB_LIST, &ha->dpc_flags) ||
1020 test_bit(DPC_RESET_HA, &ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001021 qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST);
1022
David C Somayajulu477ffb92007-01-22 12:26:11 -08001023 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001024 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001025
David Somayajuluafaf5a22006-09-19 10:28:00 -07001026 while ((readw(&ha->reg->ctrl_status) &
1027 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1028 if (--wait_time == 0)
1029 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001030 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001031 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001032 if (wait_time == 0)
1033 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1034 "bit not cleared-- resetting\n",
1035 ha->host_no, __func__));
David C Somayajulu477ffb92007-01-22 12:26:11 -08001036 qla4xxx_flush_active_srbs(ha);
1037 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1038 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1039 status = qla4xxx_initialize_adapter(ha,
1040 PRESERVE_DDB_LIST);
1041 }
1042 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1043 if (status == QLA_SUCCESS)
1044 qla4xxx_enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001045 }
1046 }
1047
1048 /* ---- process AEN? --- */
1049 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1050 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1051
1052 /* ---- Get DHCP IP Address? --- */
1053 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1054 qla4xxx_get_dhcp_ip_address(ha);
1055
1056 /* ---- relogin device? --- */
1057 if (adapter_up(ha) &&
1058 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1059 list_for_each_entry_safe(ddb_entry, dtemp,
1060 &ha->ddb_list, list) {
1061 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1062 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1063 qla4xxx_relogin_device(ha, ddb_entry);
1064
1065 /*
1066 * If mbx cmd times out there is no point
1067 * in continuing further.
1068 * With large no of targets this can hang
1069 * the system.
1070 */
1071 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1072 printk(KERN_WARNING "scsi%ld: %s: "
1073 "need to reset hba\n",
1074 ha->host_no, __func__);
1075 break;
1076 }
1077 }
1078 }
1079}
1080
1081/**
1082 * qla4xxx_free_adapter - release the adapter
1083 * @ha: pointer to adapter structure
1084 **/
1085static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1086{
1087
1088 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1089 /* Turn-off interrupts on the card. */
1090 qla4xxx_disable_intrs(ha);
1091 }
1092
1093 /* Kill the kernel thread for this host */
1094 if (ha->dpc_thread)
1095 destroy_workqueue(ha->dpc_thread);
1096
1097 /* Issue Soft Reset to put firmware in unknown state */
David C Somayajuluf26b9042006-11-15 16:41:09 -08001098 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS)
David C Somayajulu477ffb92007-01-22 12:26:11 -08001099 qla4xxx_hw_reset(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001100
1101 /* Remove timer thread, if present */
1102 if (ha->timer_active)
1103 qla4xxx_stop_timer(ha);
1104
David Somayajuluafaf5a22006-09-19 10:28:00 -07001105 /* Detach interrupts */
1106 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
1107 free_irq(ha->pdev->irq, ha);
1108
David C Somayajulubee4fe82007-05-23 18:03:32 -07001109 /* free extra memory */
1110 qla4xxx_mem_free(ha);
1111
David Somayajuluafaf5a22006-09-19 10:28:00 -07001112 pci_disable_device(ha->pdev);
1113
1114}
1115
1116/***
1117 * qla4xxx_iospace_config - maps registers
1118 * @ha: pointer to adapter structure
1119 *
1120 * This routines maps HBA's registers from the pci address space
1121 * into the kernel virtual address space for memory mapped i/o.
1122 **/
1123static int qla4xxx_iospace_config(struct scsi_qla_host *ha)
1124{
1125 unsigned long pio, pio_len, pio_flags;
1126 unsigned long mmio, mmio_len, mmio_flags;
1127
1128 pio = pci_resource_start(ha->pdev, 0);
1129 pio_len = pci_resource_len(ha->pdev, 0);
1130 pio_flags = pci_resource_flags(ha->pdev, 0);
1131 if (pio_flags & IORESOURCE_IO) {
1132 if (pio_len < MIN_IOBASE_LEN) {
1133 dev_warn(&ha->pdev->dev,
1134 "Invalid PCI I/O region size\n");
1135 pio = 0;
1136 }
1137 } else {
1138 dev_warn(&ha->pdev->dev, "region #0 not a PIO resource\n");
1139 pio = 0;
1140 }
1141
1142 /* Use MMIO operations for all accesses. */
1143 mmio = pci_resource_start(ha->pdev, 1);
1144 mmio_len = pci_resource_len(ha->pdev, 1);
1145 mmio_flags = pci_resource_flags(ha->pdev, 1);
1146
1147 if (!(mmio_flags & IORESOURCE_MEM)) {
1148 dev_err(&ha->pdev->dev,
1149 "region #0 not an MMIO resource, aborting\n");
1150
1151 goto iospace_error_exit;
1152 }
1153 if (mmio_len < MIN_IOBASE_LEN) {
1154 dev_err(&ha->pdev->dev,
1155 "Invalid PCI mem region size, aborting\n");
1156 goto iospace_error_exit;
1157 }
1158
1159 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
1160 dev_warn(&ha->pdev->dev,
1161 "Failed to reserve PIO/MMIO regions\n");
1162
1163 goto iospace_error_exit;
1164 }
1165
1166 ha->pio_address = pio;
1167 ha->pio_length = pio_len;
1168 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1169 if (!ha->reg) {
1170 dev_err(&ha->pdev->dev,
1171 "cannot remap MMIO, aborting\n");
1172
1173 goto iospace_error_exit;
1174 }
1175
1176 return 0;
1177
1178iospace_error_exit:
1179 return -ENOMEM;
1180}
1181
1182/**
1183 * qla4xxx_probe_adapter - callback function to probe HBA
1184 * @pdev: pointer to pci_dev structure
1185 * @pci_device_id: pointer to pci_device entry
1186 *
1187 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1188 * It returns zero if successful. It also initializes all data necessary for
1189 * the driver.
1190 **/
1191static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1192 const struct pci_device_id *ent)
1193{
1194 int ret = -ENODEV, status;
1195 struct Scsi_Host *host;
1196 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001197 uint8_t init_retry_count = 0;
1198 char buf[34];
1199
1200 if (pci_enable_device(pdev))
1201 return -1;
1202
1203 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1204 if (host == NULL) {
1205 printk(KERN_WARNING
1206 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1207 goto probe_disable_device;
1208 }
1209
1210 /* Clear our data area */
1211 ha = (struct scsi_qla_host *) host->hostdata;
1212 memset(ha, 0, sizeof(*ha));
1213
1214 /* Save the information from PCI BIOS. */
1215 ha->pdev = pdev;
1216 ha->host = host;
1217 ha->host_no = host->host_no;
1218
1219 /* Configure PCI I/O space. */
1220 ret = qla4xxx_iospace_config(ha);
1221 if (ret)
1222 goto probe_failed;
1223
1224 dev_info(&ha->pdev->dev, "Found an ISP%04x, irq %d, iobase 0x%p\n",
1225 pdev->device, pdev->irq, ha->reg);
1226
1227 qla4xxx_config_dma_addressing(ha);
1228
1229 /* Initialize lists and spinlocks. */
1230 INIT_LIST_HEAD(&ha->ddb_list);
1231 INIT_LIST_HEAD(&ha->free_srb_q);
1232
1233 mutex_init(&ha->mbox_sem);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001234
1235 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001236
1237 /* Allocate dma buffers */
1238 if (qla4xxx_mem_alloc(ha)) {
1239 dev_warn(&ha->pdev->dev,
1240 "[ERROR] Failed to allocate memory for adapter\n");
1241
1242 ret = -ENOMEM;
1243 goto probe_failed;
1244 }
1245
1246 /*
1247 * Initialize the Host adapter request/response queues and
1248 * firmware
1249 * NOTE: interrupts enabled upon successful completion
1250 */
1251 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1252 while (status == QLA_ERROR && init_retry_count++ < MAX_INIT_RETRIES) {
1253 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1254 "(%d)\n", __func__, init_retry_count));
1255 qla4xxx_soft_reset(ha);
1256 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1257 }
1258 if (status == QLA_ERROR) {
1259 dev_warn(&ha->pdev->dev, "Failed to initialize adapter\n");
1260
1261 ret = -ENODEV;
1262 goto probe_failed;
1263 }
1264
1265 host->cmd_per_lun = 3;
1266 host->max_channel = 0;
1267 host->max_lun = MAX_LUNS - 1;
1268 host->max_id = MAX_TARGETS;
1269 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1270 host->can_queue = MAX_SRBS ;
1271 host->transportt = qla4xxx_scsi_transport;
1272
1273 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1274 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07001275 dev_warn(&ha->pdev->dev, "scsi_init_shared_tag_map failed\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001276 goto probe_failed;
1277 }
1278
1279 /* Startup the kernel thread for this host adapter. */
1280 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1281 "qla4xxx_dpc\n", __func__));
1282 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1283 ha->dpc_thread = create_singlethread_workqueue(buf);
1284 if (!ha->dpc_thread) {
1285 dev_warn(&ha->pdev->dev, "Unable to start DPC thread!\n");
1286 ret = -ENODEV;
1287 goto probe_failed;
1288 }
David Howellsc4028952006-11-22 14:57:56 +00001289 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001290
1291 ret = request_irq(pdev->irq, qla4xxx_intr_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001292 IRQF_DISABLED | IRQF_SHARED, "qla4xxx", ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001293 if (ret) {
1294 dev_warn(&ha->pdev->dev, "Failed to reserve interrupt %d"
1295 " already in use.\n", pdev->irq);
1296 goto probe_failed;
1297 }
1298 set_bit(AF_IRQ_ATTACHED, &ha->flags);
1299 host->irq = pdev->irq;
1300 DEBUG(printk("scsi%d: irq %d attached\n", ha->host_no, ha->pdev->irq));
1301
1302 qla4xxx_enable_intrs(ha);
1303
1304 /* Start timer thread. */
1305 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1306
1307 set_bit(AF_INIT_DONE, &ha->flags);
1308
1309 pci_set_drvdata(pdev, ha);
1310
1311 ret = scsi_add_host(host, &pdev->dev);
1312 if (ret)
1313 goto probe_failed;
1314
David Somayajuluafaf5a22006-09-19 10:28:00 -07001315 printk(KERN_INFO
1316 " QLogic iSCSI HBA Driver version: %s\n"
1317 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1318 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1319 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1320 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06001321 scsi_scan_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001322 return 0;
1323
David Somayajuluafaf5a22006-09-19 10:28:00 -07001324probe_failed:
1325 qla4xxx_free_adapter(ha);
1326 scsi_host_put(ha->host);
1327
1328probe_disable_device:
1329 pci_disable_device(pdev);
1330
1331 return ret;
1332}
1333
1334/**
1335 * qla4xxx_remove_adapter - calback function to remove adapter.
1336 * @pci_dev: PCI device pointer
1337 **/
1338static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1339{
1340 struct scsi_qla_host *ha;
1341
1342 ha = pci_get_drvdata(pdev);
1343
David C Somayajulubee4fe82007-05-23 18:03:32 -07001344 qla4xxx_disable_intrs(ha);
1345
1346 while (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags))
1347 ssleep(1);
1348
David Somayajuluafaf5a22006-09-19 10:28:00 -07001349 /* remove devs from iscsi_sessions to scsi_devices */
1350 qla4xxx_free_ddb_list(ha);
1351
1352 scsi_remove_host(ha->host);
1353
1354 qla4xxx_free_adapter(ha);
1355
1356 scsi_host_put(ha->host);
1357
1358 pci_set_drvdata(pdev, NULL);
1359}
1360
1361/**
1362 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1363 * @ha: HA context
1364 *
1365 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1366 * supported addressing method.
1367 */
Adrian Bunk47975472007-04-26 00:35:16 -07001368static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001369{
1370 int retval;
1371
1372 /* Update our PCI device dma_mask for full 64 bit mask */
1373 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK) == 0) {
1374 if (pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1375 dev_dbg(&ha->pdev->dev,
1376 "Failed to set 64 bit PCI consistent mask; "
1377 "using 32 bit.\n");
1378 retval = pci_set_consistent_dma_mask(ha->pdev,
1379 DMA_32BIT_MASK);
1380 }
1381 } else
1382 retval = pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK);
1383}
1384
1385static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1386{
1387 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1388 struct ddb_entry *ddb = sess->dd_data;
1389
1390 sdev->hostdata = ddb;
1391 sdev->tagged_supported = 1;
Mike Christied510d962008-07-11 19:50:33 -05001392 scsi_activate_tcq(sdev, QL4_DEF_QDEPTH);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001393 return 0;
1394}
1395
1396static int qla4xxx_slave_configure(struct scsi_device *sdev)
1397{
1398 sdev->tagged_supported = 1;
1399 return 0;
1400}
1401
1402static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1403{
1404 scsi_deactivate_tcq(sdev, 1);
1405}
1406
1407/**
1408 * qla4xxx_del_from_active_array - returns an active srb
1409 * @ha: Pointer to host adapter structure.
1410 * @index: index into to the active_array
1411 *
1412 * This routine removes and returns the srb at the specified index
1413 **/
1414struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index)
1415{
1416 struct srb *srb = NULL;
1417 struct scsi_cmnd *cmd;
1418
1419 if (!(cmd = scsi_host_find_tag(ha->host, index)))
1420 return srb;
1421
1422 if (!(srb = (struct srb *)cmd->host_scribble))
1423 return srb;
1424
1425 /* update counters */
1426 if (srb->flags & SRB_DMA_VALID) {
1427 ha->req_q_count += srb->iocb_cnt;
1428 ha->iocb_cnt -= srb->iocb_cnt;
1429 if (srb->cmd)
1430 srb->cmd->host_scribble = NULL;
1431 }
1432 return srb;
1433}
1434
1435/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001436 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
1437 * @ha: actual ha whose done queue will contain the comd returned by firmware.
1438 * @cmd: Scsi Command to wait on.
1439 *
1440 * This routine waits for the command to be returned by the Firmware
1441 * for some max time.
1442 **/
1443static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1444 struct scsi_cmnd *cmd)
1445{
1446 int done = 0;
1447 struct srb *rp;
1448 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1449
1450 do {
1451 /* Checking to see if its returned to OS */
1452 rp = (struct srb *) cmd->SCp.ptr;
1453 if (rp == NULL) {
1454 done++;
1455 break;
1456 }
1457
1458 msleep(2000);
1459 } while (max_wait_time--);
1460
1461 return done;
1462}
1463
1464/**
1465 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1466 * @ha: Pointer to host adapter structure
1467 **/
1468static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1469{
1470 unsigned long wait_online;
1471
1472 wait_online = jiffies + (30 * HZ);
1473 while (time_before(jiffies, wait_online)) {
1474
1475 if (adapter_up(ha))
1476 return QLA_SUCCESS;
1477 else if (ha->retry_reset_ha_cnt == 0)
1478 return QLA_ERROR;
1479
1480 msleep(2000);
1481 }
1482
1483 return QLA_ERROR;
1484}
1485
1486/**
Mike Christiece545032008-02-29 18:25:20 -06001487 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001488 * @ha: pointer to to HBA
1489 * @t: target id
1490 * @l: lun id
1491 *
1492 * This function waits for all outstanding commands to a lun to complete. It
1493 * returns 0 if all pending commands are returned and 1 otherwise.
1494 **/
Mike Christiece545032008-02-29 18:25:20 -06001495static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
1496 struct scsi_target *stgt,
1497 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001498{
1499 int cnt;
1500 int status = 0;
1501 struct scsi_cmnd *cmd;
1502
1503 /*
Mike Christiece545032008-02-29 18:25:20 -06001504 * Waiting for all commands for the designated target or dev
1505 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07001506 */
1507 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1508 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06001509 if (cmd && stgt == scsi_target(cmd->device) &&
1510 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001511 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1512 status++;
1513 break;
1514 }
1515 }
1516 }
1517 return status;
1518}
1519
1520/**
1521 * qla4xxx_eh_device_reset - callback for target reset.
1522 * @cmd: Pointer to Linux's SCSI command structure
1523 *
1524 * This routine is called by the Linux OS to reset all luns on the
1525 * specified target.
1526 **/
1527static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
1528{
1529 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1530 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1531 struct srb *sp;
1532 int ret = FAILED, stat;
1533
1534 sp = (struct srb *) cmd->SCp.ptr;
1535 if (!sp || !ddb_entry)
1536 return ret;
1537
1538 dev_info(&ha->pdev->dev,
1539 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
1540 cmd->device->channel, cmd->device->id, cmd->device->lun);
1541
1542 DEBUG2(printk(KERN_INFO
1543 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
1544 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07001545 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001546 ha->dpc_flags, cmd->result, cmd->allowed));
1547
1548 /* FIXME: wait for hba to go online */
1549 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
1550 if (stat != QLA_SUCCESS) {
1551 dev_info(&ha->pdev->dev, "DEVICE RESET FAILED. %d\n", stat);
1552 goto eh_dev_reset_done;
1553 }
1554
Mike Christiece545032008-02-29 18:25:20 -06001555 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
1556 cmd->device)) {
1557 dev_info(&ha->pdev->dev,
1558 "DEVICE RESET FAILED - waiting for "
1559 "commands.\n");
1560 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001561 }
1562
David C Somayajulu9d562912008-03-19 11:23:03 -07001563 /* Send marker. */
1564 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
1565 MM_LUN_RESET) != QLA_SUCCESS)
1566 goto eh_dev_reset_done;
1567
David Somayajuluafaf5a22006-09-19 10:28:00 -07001568 dev_info(&ha->pdev->dev,
1569 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
1570 ha->host_no, cmd->device->channel, cmd->device->id,
1571 cmd->device->lun);
1572
1573 ret = SUCCESS;
1574
1575eh_dev_reset_done:
1576
1577 return ret;
1578}
1579
1580/**
Mike Christiece545032008-02-29 18:25:20 -06001581 * qla4xxx_eh_target_reset - callback for target reset.
1582 * @cmd: Pointer to Linux's SCSI command structure
1583 *
1584 * This routine is called by the Linux OS to reset the target.
1585 **/
1586static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
1587{
1588 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1589 struct ddb_entry *ddb_entry = cmd->device->hostdata;
1590 int stat;
1591
1592 if (!ddb_entry)
1593 return FAILED;
1594
1595 starget_printk(KERN_INFO, scsi_target(cmd->device),
1596 "WARM TARGET RESET ISSUED.\n");
1597
1598 DEBUG2(printk(KERN_INFO
1599 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
1600 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07001601 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06001602 ha->dpc_flags, cmd->result, cmd->allowed));
1603
1604 stat = qla4xxx_reset_target(ha, ddb_entry);
1605 if (stat != QLA_SUCCESS) {
1606 starget_printk(KERN_INFO, scsi_target(cmd->device),
1607 "WARM TARGET RESET FAILED.\n");
1608 return FAILED;
1609 }
1610
Mike Christiece545032008-02-29 18:25:20 -06001611 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
1612 NULL)) {
1613 starget_printk(KERN_INFO, scsi_target(cmd->device),
1614 "WARM TARGET DEVICE RESET FAILED - "
1615 "waiting for commands.\n");
1616 return FAILED;
1617 }
1618
David C Somayajulu9d562912008-03-19 11:23:03 -07001619 /* Send marker. */
1620 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
1621 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
1622 starget_printk(KERN_INFO, scsi_target(cmd->device),
1623 "WARM TARGET DEVICE RESET FAILED - "
1624 "marker iocb failed.\n");
1625 return FAILED;
1626 }
1627
Mike Christiece545032008-02-29 18:25:20 -06001628 starget_printk(KERN_INFO, scsi_target(cmd->device),
1629 "WARM TARGET RESET SUCCEEDED.\n");
1630 return SUCCESS;
1631}
1632
1633/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001634 * qla4xxx_eh_host_reset - kernel callback
1635 * @cmd: Pointer to Linux's SCSI command structure
1636 *
1637 * This routine is invoked by the Linux kernel to perform fatal error
1638 * recovery on the specified adapter.
1639 **/
1640static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
1641{
1642 int return_status = FAILED;
1643 struct scsi_qla_host *ha;
1644
1645 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
1646
1647 dev_info(&ha->pdev->dev,
1648 "scsi(%ld:%d:%d:%d): ADAPTER RESET ISSUED.\n", ha->host_no,
1649 cmd->device->channel, cmd->device->id, cmd->device->lun);
1650
1651 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
1652 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
1653 "DEAD.\n", ha->host_no, cmd->device->channel,
1654 __func__));
1655
1656 return FAILED;
1657 }
1658
Mike Christie50a29ae2008-03-04 13:26:53 -06001659 /* make sure the dpc thread is stopped while we reset the hba */
1660 clear_bit(AF_ONLINE, &ha->flags);
1661 flush_workqueue(ha->dpc_thread);
1662
1663 if (qla4xxx_recover_adapter(ha, PRESERVE_DDB_LIST) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001664 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001665
1666 dev_info(&ha->pdev->dev, "HOST RESET %s.\n",
1667 return_status == FAILED ? "FAILED" : "SUCCEDED");
1668
1669 return return_status;
1670}
1671
1672
1673static struct pci_device_id qla4xxx_pci_tbl[] = {
1674 {
1675 .vendor = PCI_VENDOR_ID_QLOGIC,
1676 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
1677 .subvendor = PCI_ANY_ID,
1678 .subdevice = PCI_ANY_ID,
1679 },
1680 {
1681 .vendor = PCI_VENDOR_ID_QLOGIC,
1682 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
1683 .subvendor = PCI_ANY_ID,
1684 .subdevice = PCI_ANY_ID,
1685 },
David C Somayajulud9150582006-11-15 17:38:40 -08001686 {
1687 .vendor = PCI_VENDOR_ID_QLOGIC,
1688 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
1689 .subvendor = PCI_ANY_ID,
1690 .subdevice = PCI_ANY_ID,
1691 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07001692 {0, 0},
1693};
1694MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
1695
Adrian Bunk47975472007-04-26 00:35:16 -07001696static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001697 .name = DRIVER_NAME,
1698 .id_table = qla4xxx_pci_tbl,
1699 .probe = qla4xxx_probe_adapter,
1700 .remove = qla4xxx_remove_adapter,
1701};
1702
1703static int __init qla4xxx_module_init(void)
1704{
1705 int ret;
1706
1707 /* Allocate cache for SRBs. */
1708 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09001709 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001710 if (srb_cachep == NULL) {
1711 printk(KERN_ERR
1712 "%s: Unable to allocate SRB cache..."
1713 "Failing load!\n", DRIVER_NAME);
1714 ret = -ENOMEM;
1715 goto no_srp_cache;
1716 }
1717
1718 /* Derive version string. */
1719 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001720 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001721 strcat(qla4xxx_version_str, "-debug");
1722
1723 qla4xxx_scsi_transport =
1724 iscsi_register_transport(&qla4xxx_iscsi_transport);
1725 if (!qla4xxx_scsi_transport){
1726 ret = -ENODEV;
1727 goto release_srb_cache;
1728 }
1729
David Somayajuluafaf5a22006-09-19 10:28:00 -07001730 ret = pci_register_driver(&qla4xxx_pci_driver);
1731 if (ret)
1732 goto unregister_transport;
1733
1734 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
1735 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05001736
David Somayajuluafaf5a22006-09-19 10:28:00 -07001737unregister_transport:
1738 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1739release_srb_cache:
1740 kmem_cache_destroy(srb_cachep);
1741no_srp_cache:
1742 return ret;
1743}
1744
1745static void __exit qla4xxx_module_exit(void)
1746{
David C Somayajulu477ffb92007-01-22 12:26:11 -08001747 ql4_mod_unload = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001748 pci_unregister_driver(&qla4xxx_pci_driver);
1749 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
1750 kmem_cache_destroy(srb_cachep);
1751}
1752
1753module_init(qla4xxx_module_init);
1754module_exit(qla4xxx_module_exit);
1755
1756MODULE_AUTHOR("QLogic Corporation");
1757MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
1758MODULE_LICENSE("GPL");
1759MODULE_VERSION(QLA4XXX_DRIVER_VERSION);