blob: 2bb362c6e6340d4c79ffed996f84c04f768ee42b [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -07009
10#include <scsi/scsi_tcq.h>
11#include <scsi/scsicam.h>
12
13#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070014#include "ql4_version.h"
15#include "ql4_glbl.h"
16#include "ql4_dbg.h"
17#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070018
19/*
20 * Driver version
21 */
Adrian Bunk47975472007-04-26 00:35:16 -070022static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070023
24/*
25 * SRB allocation cache
26 */
Christoph Lametere18b8902006-12-06 20:33:20 -080027static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070028
29/*
30 * Module parameter information and variables
31 */
32int ql4xdiscoverywait = 60;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053033module_param(ql4xdiscoverywait, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070034MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery wait time");
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053035
David Somayajuluafaf5a22006-09-19 10:28:00 -070036int ql4xdontresethba = 0;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053037module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070038MODULE_PARM_DESC(ql4xdontresethba,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053039 "Don't reset the HBA for driver recovery \n"
40 " 0 - It will reset HBA (Default)\n"
41 " 1 - It will NOT reset HBA");
David Somayajuluafaf5a22006-09-19 10:28:00 -070042
Andrew Vasquez11010fe2006-10-06 09:54:59 -070043int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053044module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070045MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070046 "Option to enable extended error logging, "
47 "Default is 0 - no logging, 1 - debug logging");
48
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053049int ql4xenablemsix = 1;
50module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
51MODULE_PARM_DESC(ql4xenablemsix,
52 "Set to enable MSI or MSI-X interrupt mechanism.\n"
53 " 0 = enable INTx interrupt mechanism.\n"
54 " 1 = enable MSI-X interrupt mechanism (Default).\n"
55 " 2 = enable MSI interrupt mechanism.");
David C Somayajulu477ffb92007-01-22 12:26:11 -080056
Mike Christied510d962008-07-11 19:50:33 -050057#define QL4_DEF_QDEPTH 32
58
David Somayajuluafaf5a22006-09-19 10:28:00 -070059/*
60 * SCSI host template entry points
61 */
Adrian Bunk47975472007-04-26 00:35:16 -070062static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070063
64/*
65 * iSCSI template entry points
66 */
Mike Christie2174a042007-05-30 12:57:10 -050067static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
68 enum iscsi_tgt_dscvr type, uint32_t enable,
69 struct sockaddr *dst_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -070070static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
71 enum iscsi_param param, char *buf);
72static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
73 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050074static int qla4xxx_host_get_param(struct Scsi_Host *shost,
75 enum iscsi_host_param param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -070076static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
Mike Christie5c656af2009-07-15 15:02:59 -050077static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
David Somayajuluafaf5a22006-09-19 10:28:00 -070078
79/*
80 * SCSI host template entry points
81 */
82static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
83 void (*done) (struct scsi_cmnd *));
Vikas Chaudhary09a0f712010-04-28 11:42:24 +053084static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070085static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -060086static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070087static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
88static int qla4xxx_slave_alloc(struct scsi_device *device);
89static int qla4xxx_slave_configure(struct scsi_device *device);
90static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie024f8012008-03-04 13:26:54 -060091static void qla4xxx_scan_start(struct Scsi_Host *shost);
David Somayajuluafaf5a22006-09-19 10:28:00 -070092
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +053093static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
94 QLA82XX_LEGACY_INTR_CONFIG;
95
David Somayajuluafaf5a22006-09-19 10:28:00 -070096static struct scsi_host_template qla4xxx_driver_template = {
97 .module = THIS_MODULE,
98 .name = DRIVER_NAME,
99 .proc_name = DRIVER_NAME,
100 .queuecommand = qla4xxx_queuecommand,
101
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530102 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700103 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600104 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700105 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500106 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700107
108 .slave_configure = qla4xxx_slave_configure,
109 .slave_alloc = qla4xxx_slave_alloc,
110 .slave_destroy = qla4xxx_slave_destroy,
111
Mike Christie921601b2008-01-31 13:36:49 -0600112 .scan_finished = iscsi_scan_finished,
Mike Christie024f8012008-03-04 13:26:54 -0600113 .scan_start = qla4xxx_scan_start,
Mike Christie921601b2008-01-31 13:36:49 -0600114
David Somayajuluafaf5a22006-09-19 10:28:00 -0700115 .this_id = -1,
116 .cmd_per_lun = 3,
117 .use_clustering = ENABLE_CLUSTERING,
118 .sg_tablesize = SG_ALL,
119
120 .max_sectors = 0xFFFF,
121};
122
123static struct iscsi_transport qla4xxx_iscsi_transport = {
124 .owner = THIS_MODULE,
125 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500126 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
127 CAP_DATA_PATH_OFFLOAD,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500128 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530129 ISCSI_TARGET_NAME | ISCSI_TPGT |
130 ISCSI_TARGET_ALIAS,
Mike Christie8ad57812007-05-30 12:57:13 -0500131 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christie22236962007-05-30 12:57:24 -0500132 ISCSI_HOST_IPADDRESS |
Mike Christie8ad57812007-05-30 12:57:13 -0500133 ISCSI_HOST_INITIATOR_NAME,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134 .tgt_dscvr = qla4xxx_tgt_dscvr,
135 .get_conn_param = qla4xxx_conn_get_param,
136 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500137 .get_host_param = qla4xxx_host_get_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700138 .session_recovery_timedout = qla4xxx_recovery_timedout,
139};
140
141static struct scsi_transport_template *qla4xxx_scsi_transport;
142
Mike Christie5c656af2009-07-15 15:02:59 -0500143static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
144{
145 struct iscsi_cls_session *session;
146 struct ddb_entry *ddb_entry;
147
148 session = starget_to_session(scsi_target(sc->device));
149 ddb_entry = session->dd_data;
150
151 /* if we are not logged in then the LLD is going to clean up the cmd */
152 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
153 return BLK_EH_RESET_TIMER;
154 else
155 return BLK_EH_NOT_HANDLED;
156}
157
David Somayajuluafaf5a22006-09-19 10:28:00 -0700158static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
159{
160 struct ddb_entry *ddb_entry = session->dd_data;
161 struct scsi_qla_host *ha = ddb_entry->ha;
162
Mike Christie568d3032008-01-31 13:36:47 -0600163 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
164 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700165
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530166 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
Mike Christie568d3032008-01-31 13:36:47 -0600167 "of (%d) secs exhausted, marking device DEAD.\n",
168 ha->host_no, __func__, ddb_entry->fw_ddb_index,
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530169 QL4_SESS_RECOVERY_TMO));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700170
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530171 qla4xxx_wake_dpc(ha);
Mike Christie568d3032008-01-31 13:36:47 -0600172 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700173}
174
Mike Christieaa1e93a2007-05-30 12:57:09 -0500175static int qla4xxx_host_get_param(struct Scsi_Host *shost,
176 enum iscsi_host_param param, char *buf)
177{
178 struct scsi_qla_host *ha = to_qla_host(shost);
179 int len;
180
181 switch (param) {
182 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800183 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500184 break;
Mike Christie22236962007-05-30 12:57:24 -0500185 case ISCSI_HOST_PARAM_IPADDRESS:
186 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
187 ha->ip_address[1], ha->ip_address[2],
188 ha->ip_address[3]);
189 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500190 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500191 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500192 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500193 default:
194 return -ENOSYS;
195 }
196
197 return len;
198}
199
David Somayajuluafaf5a22006-09-19 10:28:00 -0700200static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
201 enum iscsi_param param, char *buf)
202{
203 struct ddb_entry *ddb_entry = sess->dd_data;
204 int len;
205
206 switch (param) {
207 case ISCSI_PARAM_TARGET_NAME:
208 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
209 ddb_entry->iscsi_name);
210 break;
211 case ISCSI_PARAM_TPGT:
212 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
213 break;
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530214 case ISCSI_PARAM_TARGET_ALIAS:
215 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
216 ddb_entry->iscsi_alias);
217 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700218 default:
219 return -ENOSYS;
220 }
221
222 return len;
223}
224
225static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
226 enum iscsi_param param, char *buf)
227{
228 struct iscsi_cls_session *session;
229 struct ddb_entry *ddb_entry;
230 int len;
231
232 session = iscsi_dev_to_session(conn->dev.parent);
233 ddb_entry = session->dd_data;
234
235 switch (param) {
236 case ISCSI_PARAM_CONN_PORT:
237 len = sprintf(buf, "%hu\n", ddb_entry->port);
238 break;
239 case ISCSI_PARAM_CONN_ADDRESS:
240 /* TODO: what are the ipv6 bits */
Harvey Harrison63779432008-10-31 00:56:00 -0700241 len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700242 break;
243 default:
244 return -ENOSYS;
245 }
246
247 return len;
248}
249
Mike Christie2174a042007-05-30 12:57:10 -0500250static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
251 enum iscsi_tgt_dscvr type, uint32_t enable,
252 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700253{
254 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700255 struct sockaddr_in *addr;
256 struct sockaddr_in6 *addr6;
257 int ret = 0;
258
David Somayajuluafaf5a22006-09-19 10:28:00 -0700259 ha = (struct scsi_qla_host *) shost->hostdata;
260
261 switch (type) {
262 case ISCSI_TGT_DSCVR_SEND_TARGETS:
263 if (dst_addr->sa_family == AF_INET) {
264 addr = (struct sockaddr_in *)dst_addr;
265 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
266 addr->sin_port) != QLA_SUCCESS)
267 ret = -EIO;
268 } else if (dst_addr->sa_family == AF_INET6) {
269 /*
270 * TODO: fix qla4xxx_send_tgts
271 */
272 addr6 = (struct sockaddr_in6 *)dst_addr;
273 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
274 addr6->sin6_port) != QLA_SUCCESS)
275 ret = -EIO;
276 } else
277 ret = -ENOSYS;
278 break;
279 default:
280 ret = -ENOSYS;
281 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700282 return ret;
283}
284
285void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
286{
287 if (!ddb_entry->sess)
288 return;
289
290 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600291 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700292 iscsi_remove_session(ddb_entry->sess);
293 }
294 iscsi_free_session(ddb_entry->sess);
295}
296
297int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
298{
299 int err;
300
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530301 ddb_entry->sess->recovery_tmo = QL4_SESS_RECOVERY_TMO;
302
David Somayajuluafaf5a22006-09-19 10:28:00 -0700303 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
304 if (err) {
305 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
306 return err;
307 }
308
Mike Christie5d91e202008-05-21 15:54:01 -0500309 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700310 if (!ddb_entry->conn) {
311 iscsi_remove_session(ddb_entry->sess);
312 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
313 return -ENOMEM;
314 }
Mike Christieb6359302008-01-31 13:36:44 -0600315
316 /* finally ready to go */
317 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700318 return 0;
319}
320
321struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
322{
323 struct ddb_entry *ddb_entry;
324 struct iscsi_cls_session *sess;
325
Mike Christie5d91e202008-05-21 15:54:01 -0500326 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
327 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700328 if (!sess)
329 return NULL;
330
331 ddb_entry = sess->dd_data;
332 memset(ddb_entry, 0, sizeof(*ddb_entry));
333 ddb_entry->ha = ha;
334 ddb_entry->sess = sess;
335 return ddb_entry;
336}
337
Mike Christie024f8012008-03-04 13:26:54 -0600338static void qla4xxx_scan_start(struct Scsi_Host *shost)
339{
340 struct scsi_qla_host *ha = shost_priv(shost);
341 struct ddb_entry *ddb_entry, *ddbtemp;
342
343 /* finish setup of sessions that were already setup in firmware */
344 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
345 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
346 qla4xxx_add_sess(ddb_entry);
347 }
348}
349
David Somayajuluafaf5a22006-09-19 10:28:00 -0700350/*
351 * Timer routines
352 */
353
354static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
355 unsigned long interval)
356{
357 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
358 __func__, ha->host->host_no));
359 init_timer(&ha->timer);
360 ha->timer.expires = jiffies + interval * HZ;
361 ha->timer.data = (unsigned long)ha;
362 ha->timer.function = (void (*)(unsigned long))func;
363 add_timer(&ha->timer);
364 ha->timer_active = 1;
365}
366
367static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
368{
369 del_timer_sync(&ha->timer);
370 ha->timer_active = 0;
371}
372
373/***
374 * qla4xxx_mark_device_missing - mark a device as missing.
375 * @ha: Pointer to host adapter structure.
376 * @ddb_entry: Pointer to device database entry
377 *
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530378 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700379 **/
380void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
381 struct ddb_entry *ddb_entry)
382{
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530383 if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
384 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
385 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
386 ha->host_no, ddb_entry->fw_ddb_index));
387 } else
388 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
389 ddb_entry->fw_ddb_index))
390
Mike Christieb6359302008-01-31 13:36:44 -0600391 iscsi_block_session(ddb_entry->sess);
Mike Christiee5bd7b52008-09-24 11:46:10 -0500392 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700393}
394
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530395/**
396 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
397 * @ha: Pointer to host adapter structure.
398 *
399 * This routine marks a device missing and resets the relogin retry count.
400 **/
401void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
402{
403 struct ddb_entry *ddb_entry, *ddbtemp;
404 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
405 qla4xxx_mark_device_missing(ha, ddb_entry);
406 }
407}
408
David Somayajuluafaf5a22006-09-19 10:28:00 -0700409static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
410 struct ddb_entry *ddb_entry,
411 struct scsi_cmnd *cmd,
412 void (*done)(struct scsi_cmnd *))
413{
414 struct srb *srb;
415
416 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
417 if (!srb)
418 return srb;
419
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530420 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700421 srb->ha = ha;
422 srb->ddb = ddb_entry;
423 srb->cmd = cmd;
424 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +0530425 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700426 cmd->scsi_done = done;
427
428 return srb;
429}
430
431static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
432{
433 struct scsi_cmnd *cmd = srb->cmd;
434
435 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900436 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700437 srb->flags &= ~SRB_DMA_VALID;
438 }
Vikas Chaudhary53698872010-04-28 11:41:59 +0530439 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700440}
441
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530442void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530444 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700445 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530446 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700447
448 qla4xxx_srb_free_dma(ha, srb);
449
450 mempool_free(srb, ha->srb_mempool);
451
452 cmd->scsi_done(cmd);
453}
454
455/**
456 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
457 * @cmd: Pointer to Linux's SCSI command structure
458 * @done_fn: Function that the driver calls to notify the SCSI mid-layer
459 * that the command has been processed.
460 *
461 * Remarks:
462 * This routine is invoked by Linux to send a SCSI command to the driver.
463 * The mid-level driver tries to ensure that queuecommand never gets
464 * invoked concurrently with itself or the interrupt handler (although
465 * the interrupt handler may call this routine as part of request-
466 * completion handling). Unfortunely, it sometimes calls the scheduler
467 * in interrupt context which is a big NO! NO!.
468 **/
469static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
470 void (*done)(struct scsi_cmnd *))
471{
472 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
473 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -0600474 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700475 struct srb *srb;
476 int rval;
477
Mike Christie7fb19212008-01-31 13:36:45 -0600478 if (!sess) {
479 cmd->result = DID_IMM_RETRY << 16;
480 goto qc_fail_command;
481 }
482
483 rval = iscsi_session_chkready(sess);
484 if (rval) {
485 cmd->result = rval;
486 goto qc_fail_command;
487 }
488
David Somayajuluafaf5a22006-09-19 10:28:00 -0700489 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
490 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
491 cmd->result = DID_NO_CONNECT << 16;
492 goto qc_fail_command;
493 }
Mike Christiec5e98e92008-08-17 15:24:39 -0500494 return SCSI_MLQUEUE_TARGET_BUSY;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700495 }
496
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530497 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
498 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
499 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
500 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
501 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
502 !test_bit(AF_ONLINE, &ha->flags) ||
503 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -0800504 goto qc_host_busy;
505
David Somayajuluafaf5a22006-09-19 10:28:00 -0700506 spin_unlock_irq(ha->host->host_lock);
507
508 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd, done);
509 if (!srb)
510 goto qc_host_busy_lock;
511
512 rval = qla4xxx_send_command_to_isp(ha, srb);
513 if (rval != QLA_SUCCESS)
514 goto qc_host_busy_free_sp;
515
516 spin_lock_irq(ha->host->host_lock);
517 return 0;
518
519qc_host_busy_free_sp:
520 qla4xxx_srb_free_dma(ha, srb);
521 mempool_free(srb, ha->srb_mempool);
522
523qc_host_busy_lock:
524 spin_lock_irq(ha->host->host_lock);
525
526qc_host_busy:
527 return SCSI_MLQUEUE_HOST_BUSY;
528
529qc_fail_command:
530 done(cmd);
531
532 return 0;
533}
534
535/**
536 * qla4xxx_mem_free - frees memory allocated to adapter
537 * @ha: Pointer to host adapter structure.
538 *
539 * Frees memory previously allocated by qla4xxx_mem_alloc
540 **/
541static void qla4xxx_mem_free(struct scsi_qla_host *ha)
542{
543 if (ha->queues)
544 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
545 ha->queues_dma);
546
547 ha->queues_len = 0;
548 ha->queues = NULL;
549 ha->queues_dma = 0;
550 ha->request_ring = NULL;
551 ha->request_dma = 0;
552 ha->response_ring = NULL;
553 ha->response_dma = 0;
554 ha->shadow_regs = NULL;
555 ha->shadow_regs_dma = 0;
556
557 /* Free srb pool. */
558 if (ha->srb_mempool)
559 mempool_destroy(ha->srb_mempool);
560
561 ha->srb_mempool = NULL;
562
563 /* release io space registers */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530564 if (is_qla8022(ha)) {
565 if (ha->nx_pcibase)
566 iounmap(
567 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
568
569 if (ha->nx_db_wr_ptr)
570 iounmap(
571 (struct device_reg_82xx __iomem *)ha->nx_db_wr_ptr);
572 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700573 iounmap(ha->reg);
574 pci_release_regions(ha->pdev);
575}
576
577/**
578 * qla4xxx_mem_alloc - allocates memory for use by adapter.
579 * @ha: Pointer to host adapter structure
580 *
581 * Allocates DMA memory for request and response queues. Also allocates memory
582 * for srbs.
583 **/
584static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
585{
586 unsigned long align;
587
588 /* Allocate contiguous block of DMA memory for queues. */
589 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
590 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
591 sizeof(struct shadow_regs) +
592 MEM_ALIGN_VALUE +
593 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
594 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
595 &ha->queues_dma, GFP_KERNEL);
596 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530597 ql4_printk(KERN_WARNING, ha,
598 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700599
600 goto mem_alloc_error_exit;
601 }
602 memset(ha->queues, 0, ha->queues_len);
603
604 /*
605 * As per RISC alignment requirements -- the bus-address must be a
606 * multiple of the request-ring size (in bytes).
607 */
608 align = 0;
609 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
610 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
611 (MEM_ALIGN_VALUE - 1));
612
613 /* Update request and response queue pointers. */
614 ha->request_dma = ha->queues_dma + align;
615 ha->request_ring = (struct queue_entry *) (ha->queues + align);
616 ha->response_dma = ha->queues_dma + align +
617 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
618 ha->response_ring = (struct queue_entry *) (ha->queues + align +
619 (REQUEST_QUEUE_DEPTH *
620 QUEUE_SIZE));
621 ha->shadow_regs_dma = ha->queues_dma + align +
622 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
623 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
624 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
625 (REQUEST_QUEUE_DEPTH *
626 QUEUE_SIZE) +
627 (RESPONSE_QUEUE_DEPTH *
628 QUEUE_SIZE));
629
630 /* Allocate memory for srb pool. */
631 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
632 mempool_free_slab, srb_cachep);
633 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530634 ql4_printk(KERN_WARNING, ha,
635 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700636
637 goto mem_alloc_error_exit;
638 }
639
640 return QLA_SUCCESS;
641
642mem_alloc_error_exit:
643 qla4xxx_mem_free(ha);
644 return QLA_ERROR;
645}
646
647/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530648 * qla4_8xxx_check_fw_alive - Check firmware health
649 * @ha: Pointer to host adapter structure.
650 *
651 * Context: Interrupt
652 **/
653static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
654{
655 uint32_t fw_heartbeat_counter, halt_status;
656
657 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
658
659 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
660 ha->seconds_since_last_heartbeat++;
661 /* FW not alive after 2 seconds */
662 if (ha->seconds_since_last_heartbeat == 2) {
663 ha->seconds_since_last_heartbeat = 0;
664 halt_status = qla4_8xxx_rd_32(ha,
665 QLA82XX_PEG_HALT_STATUS1);
Nilesh Javali21033632010-07-30 14:28:07 +0530666
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530667 /* Since we cannot change dev_state in interrupt
668 * context, set appropriate DPC flag then wakeup
669 * DPC */
670 if (halt_status & HALT_STATUS_UNRECOVERABLE)
671 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
672 else {
673 printk("scsi%ld: %s: detect abort needed!\n",
674 ha->host_no, __func__);
675 set_bit(DPC_RESET_HA, &ha->dpc_flags);
676 }
677 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +0530678 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530679 }
680 }
681 ha->fw_heartbeat_counter = fw_heartbeat_counter;
682}
683
684/**
685 * qla4_8xxx_watchdog - Poll dev state
686 * @ha: Pointer to host adapter structure.
687 *
688 * Context: Interrupt
689 **/
690void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
691{
692 uint32_t dev_state;
693
694 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
695
696 /* don't poll if reset is going on */
697 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags)) {
698 if (dev_state == QLA82XX_DEV_NEED_RESET &&
699 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
700 printk("scsi%ld: %s: HW State: NEED RESET!\n",
701 ha->host_no, __func__);
702 set_bit(DPC_RESET_HA, &ha->dpc_flags);
703 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +0530704 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530705 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
706 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
707 printk("scsi%ld: %s: HW State: NEED QUIES!\n",
708 ha->host_no, __func__);
709 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
710 qla4xxx_wake_dpc(ha);
711 } else {
712 /* Check firmware health */
713 qla4_8xxx_check_fw_alive(ha);
714 }
715 }
716}
717
718/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700719 * qla4xxx_timer - checks every second for work to do.
720 * @ha: Pointer to host adapter structure.
721 **/
722static void qla4xxx_timer(struct scsi_qla_host *ha)
723{
724 struct ddb_entry *ddb_entry, *dtemp;
725 int start_dpc = 0;
726
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530727 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags)) {
728 DEBUG2(ql4_printk(KERN_INFO, ha, "%s exited. HBA GOING AWAY\n",
729 __func__));
730 return;
731 }
732
733 if (is_qla8022(ha)) {
734 qla4_8xxx_watchdog(ha);
735 }
736
David Somayajuluafaf5a22006-09-19 10:28:00 -0700737 /* Search for relogin's to time-out and port down retry. */
738 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
739 /* Count down time between sending relogins */
740 if (adapter_up(ha) &&
741 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
742 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
743 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
744 INVALID_ENTRY) {
745 if (atomic_read(&ddb_entry->retry_relogin_timer)
746 == 0) {
747 atomic_set(&ddb_entry->
748 retry_relogin_timer,
749 INVALID_ENTRY);
750 set_bit(DPC_RELOGIN_DEVICE,
751 &ha->dpc_flags);
752 set_bit(DF_RELOGIN, &ddb_entry->flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530753 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
David Somayajuluafaf5a22006-09-19 10:28:00 -0700754 " login device\n",
755 ha->host_no, __func__,
756 ddb_entry->fw_ddb_index));
757 } else
758 atomic_dec(&ddb_entry->
759 retry_relogin_timer);
760 }
761 }
762
763 /* Wait for relogin to timeout */
764 if (atomic_read(&ddb_entry->relogin_timer) &&
765 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
766 /*
767 * If the relogin times out and the device is
768 * still NOT ONLINE then try and relogin again.
769 */
770 if (atomic_read(&ddb_entry->state) !=
771 DDB_STATE_ONLINE &&
772 ddb_entry->fw_ddb_device_state ==
773 DDB_DS_SESSION_FAILED) {
774 /* Reset retry relogin timer */
775 atomic_inc(&ddb_entry->relogin_retry_count);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530776 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
David Somayajuluafaf5a22006-09-19 10:28:00 -0700777 " timed out-retrying"
778 " relogin (%d)\n",
779 ha->host_no,
780 ddb_entry->fw_ddb_index,
781 atomic_read(&ddb_entry->
782 relogin_retry_count))
783 );
784 start_dpc++;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530785 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
David Somayajuluafaf5a22006-09-19 10:28:00 -0700786 "initate relogin after"
787 " %d seconds\n",
788 ha->host_no, ddb_entry->bus,
789 ddb_entry->target,
790 ddb_entry->fw_ddb_index,
791 ddb_entry->default_time2wait + 4)
792 );
793
794 atomic_set(&ddb_entry->retry_relogin_timer,
795 ddb_entry->default_time2wait + 4);
796 }
797 }
798 }
799
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530800 if (!is_qla8022(ha)) {
801 /* Check for heartbeat interval. */
802 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
803 ha->heartbeat_interval != 0) {
804 ha->seconds_since_last_heartbeat++;
805 if (ha->seconds_since_last_heartbeat >
806 ha->heartbeat_interval + 2)
807 set_bit(DPC_RESET_HA, &ha->dpc_flags);
808 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700809 }
810
David Somayajuluafaf5a22006-09-19 10:28:00 -0700811 /* Wakeup the dpc routine for this adapter, if needed. */
812 if ((start_dpc ||
813 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
814 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
815 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530816 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -0700817 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
818 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530819 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530820 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
821 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -0700822 test_bit(DPC_AEN, &ha->dpc_flags)) &&
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530823 !test_bit(AF_DPC_SCHEDULED, &ha->flags) &&
David Somayajuluafaf5a22006-09-19 10:28:00 -0700824 ha->dpc_thread) {
825 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
826 " - dpc flags = 0x%lx\n",
827 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530828 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700829 }
830
831 /* Reschedule timer thread to call us back in one second */
832 mod_timer(&ha->timer, jiffies + HZ);
833
834 DEBUG2(ha->seconds_since_last_intr++);
835}
836
837/**
838 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
839 * @ha: Pointer to host adapter structure.
840 *
841 * This routine stalls the driver until all outstanding commands are returned.
842 * Caller must release the Hardware Lock prior to calling this routine.
843 **/
844static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
845{
846 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700847 unsigned long flags;
848 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700849
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530850 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
851
852 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
853 "complete\n", WAIT_CMD_TOV));
854
855 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700856 spin_lock_irqsave(&ha->hardware_lock, flags);
857 /* Find a command that hasn't completed. */
858 for (index = 0; index < ha->host->can_queue; index++) {
859 cmd = scsi_host_find_tag(ha->host, index);
860 if (cmd != NULL)
861 break;
862 }
863 spin_unlock_irqrestore(&ha->hardware_lock, flags);
864
865 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530866 if (index == ha->host->can_queue)
867 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700868
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530869 msleep(1000);
870 }
871 /* If we timed out on waiting for commands to come back
872 * return ERROR. */
873 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700874}
875
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530876int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700877{
David Somayajuluafaf5a22006-09-19 10:28:00 -0700878 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800879 unsigned long flags = 0;
880
881 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700882
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530883 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
884 return QLA_ERROR;
885
David Somayajuluafaf5a22006-09-19 10:28:00 -0700886 spin_lock_irqsave(&ha->hardware_lock, flags);
887
888 /*
889 * If the SCSI Reset Interrupt bit is set, clear it.
890 * Otherwise, the Soft Reset won't work.
891 */
892 ctrl_status = readw(&ha->reg->ctrl_status);
893 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
894 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
895
896 /* Issue Soft Reset */
897 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
898 readl(&ha->reg->ctrl_status);
899
900 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530901 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800902}
903
904/**
905 * qla4xxx_soft_reset - performs soft reset.
906 * @ha: Pointer to host adapter structure.
907 **/
908int qla4xxx_soft_reset(struct scsi_qla_host *ha)
909{
910 uint32_t max_wait_time;
911 unsigned long flags = 0;
912 int status = QLA_ERROR;
913 uint32_t ctrl_status;
914
915 qla4xxx_hw_reset(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700916
917 /* Wait until the Network Reset Intr bit is cleared */
918 max_wait_time = RESET_INTR_TOV;
919 do {
920 spin_lock_irqsave(&ha->hardware_lock, flags);
921 ctrl_status = readw(&ha->reg->ctrl_status);
922 spin_unlock_irqrestore(&ha->hardware_lock, flags);
923
924 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
925 break;
926
927 msleep(1000);
928 } while ((--max_wait_time));
929
930 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
931 DEBUG2(printk(KERN_WARNING
932 "scsi%ld: Network Reset Intr not cleared by "
933 "Network function, clearing it now!\n",
934 ha->host_no));
935 spin_lock_irqsave(&ha->hardware_lock, flags);
936 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
937 readl(&ha->reg->ctrl_status);
938 spin_unlock_irqrestore(&ha->hardware_lock, flags);
939 }
940
941 /* Wait until the firmware tells us the Soft Reset is done */
942 max_wait_time = SOFT_RESET_TOV;
943 do {
944 spin_lock_irqsave(&ha->hardware_lock, flags);
945 ctrl_status = readw(&ha->reg->ctrl_status);
946 spin_unlock_irqrestore(&ha->hardware_lock, flags);
947
948 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
949 status = QLA_SUCCESS;
950 break;
951 }
952
953 msleep(1000);
954 } while ((--max_wait_time));
955
956 /*
957 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
958 * after the soft reset has taken place.
959 */
960 spin_lock_irqsave(&ha->hardware_lock, flags);
961 ctrl_status = readw(&ha->reg->ctrl_status);
962 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
963 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
964 readl(&ha->reg->ctrl_status);
965 }
966 spin_unlock_irqrestore(&ha->hardware_lock, flags);
967
968 /* If soft reset fails then most probably the bios on other
969 * function is also enabled.
970 * Since the initialization is sequential the other fn
971 * wont be able to acknowledge the soft reset.
972 * Issue a force soft reset to workaround this scenario.
973 */
974 if (max_wait_time == 0) {
975 /* Issue Force Soft Reset */
976 spin_lock_irqsave(&ha->hardware_lock, flags);
977 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
978 readl(&ha->reg->ctrl_status);
979 spin_unlock_irqrestore(&ha->hardware_lock, flags);
980 /* Wait until the firmware tells us the Soft Reset is done */
981 max_wait_time = SOFT_RESET_TOV;
982 do {
983 spin_lock_irqsave(&ha->hardware_lock, flags);
984 ctrl_status = readw(&ha->reg->ctrl_status);
985 spin_unlock_irqrestore(&ha->hardware_lock, flags);
986
987 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
988 status = QLA_SUCCESS;
989 break;
990 }
991
992 msleep(1000);
993 } while ((--max_wait_time));
994 }
995
996 return status;
997}
998
999/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301000 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001001 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301002 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07001003 *
1004 * This routine is called just prior to a HARD RESET to return all
1005 * outstanding commands back to the Operating System.
1006 * Caller should make sure that the following locks are released
1007 * before this calling routine: Hardware lock, and io_request_lock.
1008 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301009static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001010{
1011 struct srb *srb;
1012 int i;
1013 unsigned long flags;
1014
1015 spin_lock_irqsave(&ha->hardware_lock, flags);
1016 for (i = 0; i < ha->host->can_queue; i++) {
1017 srb = qla4xxx_del_from_active_array(ha, i);
1018 if (srb != NULL) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301019 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301020 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001021 }
1022 }
1023 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001024}
1025
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301026void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
1027{
1028 clear_bit(AF_ONLINE, &ha->flags);
1029
1030 /* Disable the board */
1031 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
1032 set_bit(AF_HBA_GOING_AWAY, &ha->flags);
1033
1034 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
1035 qla4xxx_mark_all_devices_missing(ha);
1036 clear_bit(AF_INIT_DONE, &ha->flags);
1037}
1038
David Somayajuluafaf5a22006-09-19 10:28:00 -07001039/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001040 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1041 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001042 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301043static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001044{
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301045 int status = QLA_ERROR;
1046 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001047
1048 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301049 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001050 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06001051
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301052 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001053
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301054 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001055
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301056 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1057 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001058
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301059 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1060 * do not reset adapter, jump to initialize_adapter */
1061 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1062 status = QLA_SUCCESS;
1063 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001064 }
1065
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301066 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1067 * from eh_host_reset or ioctl module */
1068 if (is_qla8022(ha) && !reset_chip &&
1069 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
1070
1071 DEBUG2(ql4_printk(KERN_INFO, ha,
1072 "scsi%ld: %s - Performing stop_firmware...\n",
1073 ha->host_no, __func__));
1074 status = ha->isp_ops->reset_firmware(ha);
1075 if (status == QLA_SUCCESS) {
1076 qla4xxx_cmd_wait(ha);
1077 ha->isp_ops->disable_intrs(ha);
1078 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1079 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1080 } else {
1081 /* If the stop_firmware fails then
1082 * reset the entire chip */
1083 reset_chip = 1;
1084 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1085 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1086 }
1087 }
1088
1089 /* Issue full chip reset if recovering from a catastrophic error,
1090 * or if stop_firmware fails for ISP-82xx.
1091 * This is the default case for ISP-4xxx */
1092 if (!is_qla8022(ha) || reset_chip) {
1093 qla4xxx_cmd_wait(ha);
1094 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1095 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1096 DEBUG2(ql4_printk(KERN_INFO, ha,
1097 "scsi%ld: %s - Performing chip reset..\n",
1098 ha->host_no, __func__));
1099 status = ha->isp_ops->reset_chip(ha);
1100 }
1101
1102 /* Flush any pending ddb changed AENs */
1103 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1104
1105recover_ha_init_adapter:
1106 /* Upon successful firmware/chip reset, re-initialize the adapter */
1107 if (status == QLA_SUCCESS) {
1108 /* For ISP-4xxx, force function 1 to always initialize
1109 * before function 3 to prevent both funcions from
1110 * stepping on top of the other */
1111 if (!is_qla8022(ha) && (ha->mac_index == 3))
1112 ssleep(6);
1113
1114 /* NOTE: AF_ONLINE flag set upon successful completion of
1115 * qla4xxx_initialize_adapter */
1116 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1117 }
1118
1119 /* Retry failed adapter initialization, if necessary
1120 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1121 * case to prevent ping-pong resets between functions */
1122 if (!test_bit(AF_ONLINE, &ha->flags) &&
1123 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001124 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301125 * resetting the ha.
1126 * Since we don't want to block the DPC for too long
1127 * with multiple resets in the same thread,
1128 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07001129 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1130 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1131 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1132 "(%d) more times\n", ha->host_no,
1133 ha->retry_reset_ha_cnt));
1134 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1135 status = QLA_ERROR;
1136 } else {
1137 if (ha->retry_reset_ha_cnt > 0) {
1138 /* Schedule another Reset HA--DPC will retry */
1139 ha->retry_reset_ha_cnt--;
1140 DEBUG2(printk("scsi%ld: recover adapter - "
1141 "retry remaining %d\n",
1142 ha->host_no,
1143 ha->retry_reset_ha_cnt));
1144 status = QLA_ERROR;
1145 }
1146
1147 if (ha->retry_reset_ha_cnt == 0) {
1148 /* Recover adapter retries have been exhausted.
1149 * Adapter DEAD */
1150 DEBUG2(printk("scsi%ld: recover adapter "
1151 "failed - board disabled\n",
1152 ha->host_no));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301153 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001154 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1155 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301156 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001157 &ha->dpc_flags);
1158 status = QLA_ERROR;
1159 }
1160 }
1161 } else {
1162 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301163 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001164 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1165 }
1166
1167 ha->adapter_error_count++;
1168
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301169 if (test_bit(AF_ONLINE, &ha->flags))
1170 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001171
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301172 scsi_unblock_requests(ha->host);
1173
1174 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1175 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
1176 status == QLA_ERROR ? "FAILED" : "SUCCEDED"));
1177
David Somayajuluafaf5a22006-09-19 10:28:00 -07001178 return status;
1179}
1180
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301181void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
1182{
1183 if (ha->dpc_thread &&
1184 !test_bit(AF_DPC_SCHEDULED, &ha->flags)) {
1185 set_bit(AF_DPC_SCHEDULED, &ha->flags);
1186 queue_work(ha->dpc_thread, &ha->dpc_work);
1187 }
1188}
1189
David Somayajuluafaf5a22006-09-19 10:28:00 -07001190/**
1191 * qla4xxx_do_dpc - dpc routine
1192 * @data: in our case pointer to adapter structure
1193 *
1194 * This routine is a task that is schedule by the interrupt handler
1195 * to perform the background processing for interrupts. We put it
1196 * on a task queue that is consumed whenever the scheduler runs; that's
1197 * so you can do anything (i.e. put the process to sleep etc). In fact,
1198 * the mid-level tries to sleep when it reaches the driver threshold
1199 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1200 **/
David Howellsc4028952006-11-22 14:57:56 +00001201static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001202{
David Howellsc4028952006-11-22 14:57:56 +00001203 struct scsi_qla_host *ha =
1204 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001205 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001206 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001207
David C Somayajuluf26b9042006-11-15 16:41:09 -08001208 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301209 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1210 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001211
1212 /* Initialization not yet finished. Don't do anything yet. */
1213 if (!test_bit(AF_INIT_DONE, &ha->flags))
Vikas Chaudhary0753b482010-07-30 14:27:19 +05301214 goto do_dpc_exit;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001215
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301216 /* HBA is in the process of being permanently disabled.
1217 * Don't process anything */
1218 if (test_bit(AF_HBA_GOING_AWAY, &ha->flags))
1219 return;
1220
1221 if (is_qla8022(ha)) {
1222 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
1223 qla4_8xxx_idc_lock(ha);
1224 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1225 QLA82XX_DEV_FAILED);
1226 qla4_8xxx_idc_unlock(ha);
1227 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
1228 qla4_8xxx_device_state_handler(ha);
1229 }
1230 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1231 qla4_8xxx_need_qsnt_handler(ha);
1232 }
1233 }
1234
1235 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
1236 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001237 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301238 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
1239 if (ql4xdontresethba) {
1240 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1241 ha->host_no, __func__));
1242 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1243 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1244 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1245 goto dpc_post_reset_ha;
1246 }
1247 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1248 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1249 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001250
David C Somayajulu477ffb92007-01-22 12:26:11 -08001251 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001252 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001253
David Somayajuluafaf5a22006-09-19 10:28:00 -07001254 while ((readw(&ha->reg->ctrl_status) &
1255 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1256 if (--wait_time == 0)
1257 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001258 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001259 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001260 if (wait_time == 0)
1261 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1262 "bit not cleared-- resetting\n",
1263 ha->host_no, __func__));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301264 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001265 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1266 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301267 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001268 }
1269 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1270 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301271 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001272 }
1273 }
1274
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301275dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001276 /* ---- process AEN? --- */
1277 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1278 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1279
1280 /* ---- Get DHCP IP Address? --- */
1281 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1282 qla4xxx_get_dhcp_ip_address(ha);
1283
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301284 /* ---- link change? --- */
1285 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
1286 if (!test_bit(AF_LINK_UP, &ha->flags)) {
1287 /* ---- link down? --- */
1288 list_for_each_entry_safe(ddb_entry, dtemp,
1289 &ha->ddb_list, list) {
1290 if (atomic_read(&ddb_entry->state) ==
1291 DDB_STATE_ONLINE)
1292 qla4xxx_mark_device_missing(ha,
1293 ddb_entry);
1294 }
1295 } else {
1296 /* ---- link up? --- *
1297 * F/W will auto login to all devices ONLY ONCE after
1298 * link up during driver initialization and runtime
1299 * fatal error recovery. Therefore, the driver must
1300 * manually relogin to devices when recovering from
1301 * connection failures, logouts, expired KATO, etc. */
1302
1303 list_for_each_entry_safe(ddb_entry, dtemp,
1304 &ha->ddb_list, list) {
1305 if ((atomic_read(&ddb_entry->state) ==
1306 DDB_STATE_MISSING) ||
1307 (atomic_read(&ddb_entry->state) ==
1308 DDB_STATE_DEAD)) {
1309 if (ddb_entry->fw_ddb_device_state ==
1310 DDB_DS_SESSION_ACTIVE) {
1311 atomic_set(&ddb_entry->state,
1312 DDB_STATE_ONLINE);
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301313 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301314 "scsi%ld: %s: ddb[%d]"
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301315 " marked ONLINE\n",
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301316 ha->host_no, __func__,
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301317 ddb_entry->fw_ddb_index);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301318
1319 iscsi_unblock_session(
1320 ddb_entry->sess);
1321 } else
1322 qla4xxx_relogin_device(
1323 ha, ddb_entry);
1324 }
1325
1326 }
1327 }
1328 }
1329
David Somayajuluafaf5a22006-09-19 10:28:00 -07001330 /* ---- relogin device? --- */
1331 if (adapter_up(ha) &&
1332 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1333 list_for_each_entry_safe(ddb_entry, dtemp,
1334 &ha->ddb_list, list) {
1335 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1336 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1337 qla4xxx_relogin_device(ha, ddb_entry);
1338
1339 /*
1340 * If mbx cmd times out there is no point
1341 * in continuing further.
1342 * With large no of targets this can hang
1343 * the system.
1344 */
1345 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1346 printk(KERN_WARNING "scsi%ld: %s: "
1347 "need to reset hba\n",
1348 ha->host_no, __func__);
1349 break;
1350 }
1351 }
1352 }
Vikas Chaudhary0753b482010-07-30 14:27:19 +05301353
1354do_dpc_exit:
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301355 clear_bit(AF_DPC_SCHEDULED, &ha->flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001356}
1357
1358/**
1359 * qla4xxx_free_adapter - release the adapter
1360 * @ha: pointer to adapter structure
1361 **/
1362static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1363{
1364
1365 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1366 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301367 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001368 }
1369
David Somayajuluafaf5a22006-09-19 10:28:00 -07001370 /* Remove timer thread, if present */
1371 if (ha->timer_active)
1372 qla4xxx_stop_timer(ha);
1373
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301374 /* Kill the kernel thread for this host */
1375 if (ha->dpc_thread)
1376 destroy_workqueue(ha->dpc_thread);
1377
1378 /* Put firmware in known state */
1379 ha->isp_ops->reset_firmware(ha);
1380
1381 if (is_qla8022(ha)) {
1382 qla4_8xxx_idc_lock(ha);
1383 qla4_8xxx_clear_drv_active(ha);
1384 qla4_8xxx_idc_unlock(ha);
1385 }
1386
David Somayajuluafaf5a22006-09-19 10:28:00 -07001387 /* Detach interrupts */
1388 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301389 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001390
David C Somayajulubee4fe82007-05-23 18:03:32 -07001391 /* free extra memory */
1392 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301393}
David C Somayajulubee4fe82007-05-23 18:03:32 -07001394
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301395int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1396{
1397 int status = 0;
1398 uint8_t revision_id;
1399 unsigned long mem_base, mem_len, db_base, db_len;
1400 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001401
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301402 status = pci_request_regions(pdev, DRIVER_NAME);
1403 if (status) {
1404 printk(KERN_WARNING
1405 "scsi(%ld) Failed to reserve PIO regions (%s) "
1406 "status=%d\n", ha->host_no, pci_name(pdev), status);
1407 goto iospace_error_exit;
1408 }
1409
1410 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
1411 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
1412 __func__, revision_id));
1413 ha->revision_id = revision_id;
1414
1415 /* remap phys address */
1416 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
1417 mem_len = pci_resource_len(pdev, 0);
1418 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
1419 __func__, mem_base, mem_len));
1420
1421 /* mapping of pcibase pointer */
1422 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
1423 if (!ha->nx_pcibase) {
1424 printk(KERN_ERR
1425 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
1426 pci_release_regions(ha->pdev);
1427 goto iospace_error_exit;
1428 }
1429
1430 /* Mapping of IO base pointer, door bell read and write pointer */
1431
1432 /* mapping of IO base pointer */
1433 ha->qla4_8xxx_reg =
1434 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
1435 0xbc000 + (ha->pdev->devfn << 11));
1436
1437 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
1438 db_len = pci_resource_len(pdev, 4);
1439
1440 /* mapping of doorbell write pointer */
1441 ha->nx_db_wr_ptr = (unsigned long)ioremap(db_base +
1442 (ha->pdev->devfn << 12), 4);
1443 if (!ha->nx_db_wr_ptr) {
1444 printk(KERN_ERR
1445 "cannot remap MMIO doorbell-write (%s), aborting\n",
1446 pci_name(pdev));
1447 goto iospace_error_exit;
1448 }
1449 /* mapping of doorbell read pointer */
1450 ha->nx_db_rd_ptr = (uint8_t *) ha->nx_pcibase + (512 * 1024) +
1451 (ha->pdev->devfn * 8);
1452 if (!ha->nx_db_rd_ptr)
1453 printk(KERN_ERR
1454 "cannot remap MMIO doorbell-read (%s), aborting\n",
1455 pci_name(pdev));
1456 return 0;
1457
1458iospace_error_exit:
1459 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001460}
1461
1462/***
1463 * qla4xxx_iospace_config - maps registers
1464 * @ha: pointer to adapter structure
1465 *
1466 * This routines maps HBA's registers from the pci address space
1467 * into the kernel virtual address space for memory mapped i/o.
1468 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301469int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001470{
1471 unsigned long pio, pio_len, pio_flags;
1472 unsigned long mmio, mmio_len, mmio_flags;
1473
1474 pio = pci_resource_start(ha->pdev, 0);
1475 pio_len = pci_resource_len(ha->pdev, 0);
1476 pio_flags = pci_resource_flags(ha->pdev, 0);
1477 if (pio_flags & IORESOURCE_IO) {
1478 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301479 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001480 "Invalid PCI I/O region size\n");
1481 pio = 0;
1482 }
1483 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301484 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001485 pio = 0;
1486 }
1487
1488 /* Use MMIO operations for all accesses. */
1489 mmio = pci_resource_start(ha->pdev, 1);
1490 mmio_len = pci_resource_len(ha->pdev, 1);
1491 mmio_flags = pci_resource_flags(ha->pdev, 1);
1492
1493 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301494 ql4_printk(KERN_ERR, ha,
1495 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001496
1497 goto iospace_error_exit;
1498 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301499
David Somayajuluafaf5a22006-09-19 10:28:00 -07001500 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301501 ql4_printk(KERN_ERR, ha,
1502 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001503 goto iospace_error_exit;
1504 }
1505
1506 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301507 ql4_printk(KERN_WARNING, ha,
1508 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001509
1510 goto iospace_error_exit;
1511 }
1512
1513 ha->pio_address = pio;
1514 ha->pio_length = pio_len;
1515 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1516 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301517 ql4_printk(KERN_ERR, ha,
1518 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001519
1520 goto iospace_error_exit;
1521 }
1522
1523 return 0;
1524
1525iospace_error_exit:
1526 return -ENOMEM;
1527}
1528
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301529static struct isp_operations qla4xxx_isp_ops = {
1530 .iospace_config = qla4xxx_iospace_config,
1531 .pci_config = qla4xxx_pci_config,
1532 .disable_intrs = qla4xxx_disable_intrs,
1533 .enable_intrs = qla4xxx_enable_intrs,
1534 .start_firmware = qla4xxx_start_firmware,
1535 .intr_handler = qla4xxx_intr_handler,
1536 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
1537 .reset_chip = qla4xxx_soft_reset,
1538 .reset_firmware = qla4xxx_hw_reset,
1539 .queue_iocb = qla4xxx_queue_iocb,
1540 .complete_iocb = qla4xxx_complete_iocb,
1541 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
1542 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
1543 .get_sys_info = qla4xxx_get_sys_info,
1544};
1545
1546static struct isp_operations qla4_8xxx_isp_ops = {
1547 .iospace_config = qla4_8xxx_iospace_config,
1548 .pci_config = qla4_8xxx_pci_config,
1549 .disable_intrs = qla4_8xxx_disable_intrs,
1550 .enable_intrs = qla4_8xxx_enable_intrs,
1551 .start_firmware = qla4_8xxx_load_risc,
1552 .intr_handler = qla4_8xxx_intr_handler,
1553 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
1554 .reset_chip = qla4_8xxx_isp_reset,
1555 .reset_firmware = qla4_8xxx_stop_firmware,
1556 .queue_iocb = qla4_8xxx_queue_iocb,
1557 .complete_iocb = qla4_8xxx_complete_iocb,
1558 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
1559 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
1560 .get_sys_info = qla4_8xxx_get_sys_info,
1561};
1562
1563uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1564{
1565 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
1566}
1567
1568uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1569{
1570 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
1571}
1572
1573uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1574{
1575 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
1576}
1577
1578uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1579{
1580 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
1581}
1582
David Somayajuluafaf5a22006-09-19 10:28:00 -07001583/**
1584 * qla4xxx_probe_adapter - callback function to probe HBA
1585 * @pdev: pointer to pci_dev structure
1586 * @pci_device_id: pointer to pci_device entry
1587 *
1588 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1589 * It returns zero if successful. It also initializes all data necessary for
1590 * the driver.
1591 **/
1592static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1593 const struct pci_device_id *ent)
1594{
1595 int ret = -ENODEV, status;
1596 struct Scsi_Host *host;
1597 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001598 uint8_t init_retry_count = 0;
1599 char buf[34];
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301600 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001601
1602 if (pci_enable_device(pdev))
1603 return -1;
1604
1605 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1606 if (host == NULL) {
1607 printk(KERN_WARNING
1608 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1609 goto probe_disable_device;
1610 }
1611
1612 /* Clear our data area */
1613 ha = (struct scsi_qla_host *) host->hostdata;
1614 memset(ha, 0, sizeof(*ha));
1615
1616 /* Save the information from PCI BIOS. */
1617 ha->pdev = pdev;
1618 ha->host = host;
1619 ha->host_no = host->host_no;
1620
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301621 /* Setup Runtime configurable options */
1622 if (is_qla8022(ha)) {
1623 ha->isp_ops = &qla4_8xxx_isp_ops;
1624 rwlock_init(&ha->hw_lock);
1625 ha->qdr_sn_window = -1;
1626 ha->ddr_mn_window = -1;
1627 ha->curr_window = 255;
1628 ha->func_num = PCI_FUNC(ha->pdev->devfn);
1629 nx_legacy_intr = &legacy_intr[ha->func_num];
1630 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
1631 ha->nx_legacy_intr.tgt_status_reg =
1632 nx_legacy_intr->tgt_status_reg;
1633 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
1634 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
1635 } else {
1636 ha->isp_ops = &qla4xxx_isp_ops;
1637 }
1638
David Somayajuluafaf5a22006-09-19 10:28:00 -07001639 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301640 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001641 if (ret)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301642 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001643
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301644 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07001645 pdev->device, pdev->irq, ha->reg);
1646
1647 qla4xxx_config_dma_addressing(ha);
1648
1649 /* Initialize lists and spinlocks. */
1650 INIT_LIST_HEAD(&ha->ddb_list);
1651 INIT_LIST_HEAD(&ha->free_srb_q);
1652
1653 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301654 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001655
1656 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001657
1658 /* Allocate dma buffers */
1659 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301660 ql4_printk(KERN_WARNING, ha,
1661 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001662
1663 ret = -ENOMEM;
1664 goto probe_failed;
1665 }
1666
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301667 if (is_qla8022(ha))
1668 (void) qla4_8xxx_get_flash_info(ha);
1669
David Somayajuluafaf5a22006-09-19 10:28:00 -07001670 /*
1671 * Initialize the Host adapter request/response queues and
1672 * firmware
1673 * NOTE: interrupts enabled upon successful completion
1674 */
1675 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301676 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
1677 init_retry_count++ < MAX_INIT_RETRIES) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001678 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1679 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301680
1681 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
1682 continue;
1683
David Somayajuluafaf5a22006-09-19 10:28:00 -07001684 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1685 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301686
1687 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301688 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001689
1690 ret = -ENODEV;
1691 goto probe_failed;
1692 }
1693
1694 host->cmd_per_lun = 3;
1695 host->max_channel = 0;
1696 host->max_lun = MAX_LUNS - 1;
1697 host->max_id = MAX_TARGETS;
1698 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1699 host->can_queue = MAX_SRBS ;
1700 host->transportt = qla4xxx_scsi_transport;
1701
1702 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1703 if (ret) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301704 ql4_printk(KERN_WARNING, ha,
1705 "scsi_init_shared_tag_map failed\n");
1706 goto probe_failed;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001707 }
1708
1709 /* Startup the kernel thread for this host adapter. */
1710 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1711 "qla4xxx_dpc\n", __func__));
1712 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1713 ha->dpc_thread = create_singlethread_workqueue(buf);
1714 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301715 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001716 ret = -ENODEV;
1717 goto probe_failed;
1718 }
David Howellsc4028952006-11-22 14:57:56 +00001719 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001720
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301721 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
1722 * (which is called indirectly by qla4xxx_initialize_adapter),
1723 * so that irqs will be registered after crbinit but before
1724 * mbx_intr_enable.
1725 */
1726 if (!is_qla8022(ha)) {
1727 ret = qla4xxx_request_irqs(ha);
1728 if (ret) {
1729 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
1730 "interrupt %d already in use.\n", pdev->irq);
1731 goto probe_failed;
1732 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001733 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001734
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301735 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001736
1737 /* Start timer thread. */
1738 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1739
1740 set_bit(AF_INIT_DONE, &ha->flags);
1741
1742 pci_set_drvdata(pdev, ha);
1743
1744 ret = scsi_add_host(host, &pdev->dev);
1745 if (ret)
1746 goto probe_failed;
1747
David Somayajuluafaf5a22006-09-19 10:28:00 -07001748 printk(KERN_INFO
1749 " QLogic iSCSI HBA Driver version: %s\n"
1750 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1751 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1752 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1753 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06001754 scsi_scan_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001755 return 0;
1756
David Somayajuluafaf5a22006-09-19 10:28:00 -07001757probe_failed:
1758 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301759
1760probe_failed_ioconfig:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001761 scsi_host_put(ha->host);
1762
1763probe_disable_device:
1764 pci_disable_device(pdev);
1765
1766 return ret;
1767}
1768
1769/**
1770 * qla4xxx_remove_adapter - calback function to remove adapter.
1771 * @pci_dev: PCI device pointer
1772 **/
1773static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1774{
1775 struct scsi_qla_host *ha;
1776
1777 ha = pci_get_drvdata(pdev);
1778
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301779 set_bit(AF_HBA_GOING_AWAY, &ha->flags);
David C Somayajulubee4fe82007-05-23 18:03:32 -07001780
David Somayajuluafaf5a22006-09-19 10:28:00 -07001781 /* remove devs from iscsi_sessions to scsi_devices */
1782 qla4xxx_free_ddb_list(ha);
1783
1784 scsi_remove_host(ha->host);
1785
1786 qla4xxx_free_adapter(ha);
1787
1788 scsi_host_put(ha->host);
1789
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301790 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001791 pci_set_drvdata(pdev, NULL);
1792}
1793
1794/**
1795 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1796 * @ha: HA context
1797 *
1798 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1799 * supported addressing method.
1800 */
Adrian Bunk47975472007-04-26 00:35:16 -07001801static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001802{
1803 int retval;
1804
1805 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07001806 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
1807 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001808 dev_dbg(&ha->pdev->dev,
1809 "Failed to set 64 bit PCI consistent mask; "
1810 "using 32 bit.\n");
1811 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07001812 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001813 }
1814 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07001815 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001816}
1817
1818static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1819{
1820 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1821 struct ddb_entry *ddb = sess->dd_data;
1822
1823 sdev->hostdata = ddb;
1824 sdev->tagged_supported = 1;
Mike Christied510d962008-07-11 19:50:33 -05001825 scsi_activate_tcq(sdev, QL4_DEF_QDEPTH);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001826 return 0;
1827}
1828
1829static int qla4xxx_slave_configure(struct scsi_device *sdev)
1830{
1831 sdev->tagged_supported = 1;
1832 return 0;
1833}
1834
1835static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1836{
1837 scsi_deactivate_tcq(sdev, 1);
1838}
1839
1840/**
1841 * qla4xxx_del_from_active_array - returns an active srb
1842 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02001843 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07001844 *
1845 * This routine removes and returns the srb at the specified index
1846 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301847struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
1848 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001849{
1850 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05301851 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001852
Vikas Chaudhary53698872010-04-28 11:41:59 +05301853 cmd = scsi_host_find_tag(ha->host, index);
1854 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001855 return srb;
1856
Vikas Chaudhary53698872010-04-28 11:41:59 +05301857 srb = (struct srb *)CMD_SP(cmd);
1858 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001859 return srb;
1860
1861 /* update counters */
1862 if (srb->flags & SRB_DMA_VALID) {
1863 ha->req_q_count += srb->iocb_cnt;
1864 ha->iocb_cnt -= srb->iocb_cnt;
1865 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05301866 srb->cmd->host_scribble =
1867 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001868 }
1869 return srb;
1870}
1871
1872/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001873 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301874 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001875 * @cmd: Scsi Command to wait on.
1876 *
1877 * This routine waits for the command to be returned by the Firmware
1878 * for some max time.
1879 **/
1880static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1881 struct scsi_cmnd *cmd)
1882{
1883 int done = 0;
1884 struct srb *rp;
1885 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
1886
1887 do {
1888 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05301889 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001890 if (rp == NULL) {
1891 done++;
1892 break;
1893 }
1894
1895 msleep(2000);
1896 } while (max_wait_time--);
1897
1898 return done;
1899}
1900
1901/**
1902 * qla4xxx_wait_for_hba_online - waits for HBA to come online
1903 * @ha: Pointer to host adapter structure
1904 **/
1905static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
1906{
1907 unsigned long wait_online;
1908
1909 wait_online = jiffies + (30 * HZ);
1910 while (time_before(jiffies, wait_online)) {
1911
1912 if (adapter_up(ha))
1913 return QLA_SUCCESS;
1914 else if (ha->retry_reset_ha_cnt == 0)
1915 return QLA_ERROR;
1916
1917 msleep(2000);
1918 }
1919
1920 return QLA_ERROR;
1921}
1922
1923/**
Mike Christiece545032008-02-29 18:25:20 -06001924 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02001925 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07001926 * @t: target id
1927 * @l: lun id
1928 *
1929 * This function waits for all outstanding commands to a lun to complete. It
1930 * returns 0 if all pending commands are returned and 1 otherwise.
1931 **/
Mike Christiece545032008-02-29 18:25:20 -06001932static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
1933 struct scsi_target *stgt,
1934 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001935{
1936 int cnt;
1937 int status = 0;
1938 struct scsi_cmnd *cmd;
1939
1940 /*
Mike Christiece545032008-02-29 18:25:20 -06001941 * Waiting for all commands for the designated target or dev
1942 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07001943 */
1944 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
1945 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06001946 if (cmd && stgt == scsi_target(cmd->device) &&
1947 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001948 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
1949 status++;
1950 break;
1951 }
1952 }
1953 }
1954 return status;
1955}
1956
1957/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301958 * qla4xxx_eh_abort - callback for abort task.
1959 * @cmd: Pointer to Linux's SCSI command structure
1960 *
1961 * This routine is called by the Linux OS to abort the specified
1962 * command.
1963 **/
1964static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
1965{
1966 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
1967 unsigned int id = cmd->device->id;
1968 unsigned int lun = cmd->device->lun;
1969 unsigned long serial = cmd->serial_number;
1970 struct srb *srb = NULL;
1971 int ret = SUCCESS;
1972 int wait = 0;
1973
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301974 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301975 "scsi%ld:%d:%d: Abort command issued cmd=%p, pid=%ld\n",
1976 ha->host_no, id, lun, cmd, serial);
1977
1978 srb = (struct srb *) CMD_SP(cmd);
1979
1980 if (!srb)
1981 return SUCCESS;
1982
1983 kref_get(&srb->srb_ref);
1984
1985 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
1986 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
1987 ha->host_no, id, lun));
1988 ret = FAILED;
1989 } else {
1990 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
1991 ha->host_no, id, lun));
1992 wait = 1;
1993 }
1994
1995 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
1996
1997 /* Wait for command to complete */
1998 if (wait) {
1999 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2000 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
2001 ha->host_no, id, lun));
2002 ret = FAILED;
2003 }
2004 }
2005
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302006 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302007 "scsi%ld:%d:%d: Abort command - %s\n",
2008 ha->host_no, id, lun, (ret == SUCCESS) ? "succeded" : "failed");
2009
2010 return ret;
2011}
2012
2013/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002014 * qla4xxx_eh_device_reset - callback for target reset.
2015 * @cmd: Pointer to Linux's SCSI command structure
2016 *
2017 * This routine is called by the Linux OS to reset all luns on the
2018 * specified target.
2019 **/
2020static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
2021{
2022 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2023 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002024 int ret = FAILED, stat;
2025
Karen Higgins612f73482009-07-15 15:03:01 -05002026 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002027 return ret;
2028
Mike Christiec01be6d2010-07-22 16:59:49 +05302029 ret = iscsi_block_scsi_eh(cmd);
2030 if (ret)
2031 return ret;
2032 ret = FAILED;
2033
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302034 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002035 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2036 cmd->device->channel, cmd->device->id, cmd->device->lun);
2037
2038 DEBUG2(printk(KERN_INFO
2039 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2040 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07002041 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002042 ha->dpc_flags, cmd->result, cmd->allowed));
2043
2044 /* FIXME: wait for hba to go online */
2045 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
2046 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302047 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002048 goto eh_dev_reset_done;
2049 }
2050
Mike Christiece545032008-02-29 18:25:20 -06002051 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2052 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302053 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06002054 "DEVICE RESET FAILED - waiting for "
2055 "commands.\n");
2056 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002057 }
2058
David C Somayajulu9d562912008-03-19 11:23:03 -07002059 /* Send marker. */
2060 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2061 MM_LUN_RESET) != QLA_SUCCESS)
2062 goto eh_dev_reset_done;
2063
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302064 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002065 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2066 ha->host_no, cmd->device->channel, cmd->device->id,
2067 cmd->device->lun);
2068
2069 ret = SUCCESS;
2070
2071eh_dev_reset_done:
2072
2073 return ret;
2074}
2075
2076/**
Mike Christiece545032008-02-29 18:25:20 -06002077 * qla4xxx_eh_target_reset - callback for target reset.
2078 * @cmd: Pointer to Linux's SCSI command structure
2079 *
2080 * This routine is called by the Linux OS to reset the target.
2081 **/
2082static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
2083{
2084 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2085 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05302086 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06002087
2088 if (!ddb_entry)
2089 return FAILED;
2090
Mike Christiec01be6d2010-07-22 16:59:49 +05302091 ret = iscsi_block_scsi_eh(cmd);
2092 if (ret)
2093 return ret;
2094
Mike Christiece545032008-02-29 18:25:20 -06002095 starget_printk(KERN_INFO, scsi_target(cmd->device),
2096 "WARM TARGET RESET ISSUED.\n");
2097
2098 DEBUG2(printk(KERN_INFO
2099 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2100 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07002101 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06002102 ha->dpc_flags, cmd->result, cmd->allowed));
2103
2104 stat = qla4xxx_reset_target(ha, ddb_entry);
2105 if (stat != QLA_SUCCESS) {
2106 starget_printk(KERN_INFO, scsi_target(cmd->device),
2107 "WARM TARGET RESET FAILED.\n");
2108 return FAILED;
2109 }
2110
Mike Christiece545032008-02-29 18:25:20 -06002111 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2112 NULL)) {
2113 starget_printk(KERN_INFO, scsi_target(cmd->device),
2114 "WARM TARGET DEVICE RESET FAILED - "
2115 "waiting for commands.\n");
2116 return FAILED;
2117 }
2118
David C Somayajulu9d562912008-03-19 11:23:03 -07002119 /* Send marker. */
2120 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2121 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
2122 starget_printk(KERN_INFO, scsi_target(cmd->device),
2123 "WARM TARGET DEVICE RESET FAILED - "
2124 "marker iocb failed.\n");
2125 return FAILED;
2126 }
2127
Mike Christiece545032008-02-29 18:25:20 -06002128 starget_printk(KERN_INFO, scsi_target(cmd->device),
2129 "WARM TARGET RESET SUCCEEDED.\n");
2130 return SUCCESS;
2131}
2132
2133/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002134 * qla4xxx_eh_host_reset - kernel callback
2135 * @cmd: Pointer to Linux's SCSI command structure
2136 *
2137 * This routine is invoked by the Linux kernel to perform fatal error
2138 * recovery on the specified adapter.
2139 **/
2140static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2141{
2142 int return_status = FAILED;
2143 struct scsi_qla_host *ha;
2144
2145 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
2146
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302147 if (ql4xdontresethba) {
2148 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2149 ha->host_no, __func__));
2150 return FAILED;
2151 }
2152
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302153 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05002154 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002155 cmd->device->channel, cmd->device->id, cmd->device->lun);
2156
2157 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2158 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2159 "DEAD.\n", ha->host_no, cmd->device->channel,
2160 __func__));
2161
2162 return FAILED;
2163 }
2164
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302165 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2166 if (is_qla8022(ha))
2167 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2168 else
2169 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2170 }
Mike Christie50a29ae2008-03-04 13:26:53 -06002171
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302172 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002173 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002174
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302175 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07002176 return_status == FAILED ? "FAILED" : "SUCCEDED");
2177
2178 return return_status;
2179}
2180
David Somayajuluafaf5a22006-09-19 10:28:00 -07002181static struct pci_device_id qla4xxx_pci_tbl[] = {
2182 {
2183 .vendor = PCI_VENDOR_ID_QLOGIC,
2184 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
2185 .subvendor = PCI_ANY_ID,
2186 .subdevice = PCI_ANY_ID,
2187 },
2188 {
2189 .vendor = PCI_VENDOR_ID_QLOGIC,
2190 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
2191 .subvendor = PCI_ANY_ID,
2192 .subdevice = PCI_ANY_ID,
2193 },
David C Somayajulud9150582006-11-15 17:38:40 -08002194 {
2195 .vendor = PCI_VENDOR_ID_QLOGIC,
2196 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
2197 .subvendor = PCI_ANY_ID,
2198 .subdevice = PCI_ANY_ID,
2199 },
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302200 {
2201 .vendor = PCI_VENDOR_ID_QLOGIC,
2202 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
2203 .subvendor = PCI_ANY_ID,
2204 .subdevice = PCI_ANY_ID,
2205 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07002206 {0, 0},
2207};
2208MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
2209
Adrian Bunk47975472007-04-26 00:35:16 -07002210static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002211 .name = DRIVER_NAME,
2212 .id_table = qla4xxx_pci_tbl,
2213 .probe = qla4xxx_probe_adapter,
2214 .remove = qla4xxx_remove_adapter,
2215};
2216
2217static int __init qla4xxx_module_init(void)
2218{
2219 int ret;
2220
2221 /* Allocate cache for SRBs. */
2222 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002223 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002224 if (srb_cachep == NULL) {
2225 printk(KERN_ERR
2226 "%s: Unable to allocate SRB cache..."
2227 "Failing load!\n", DRIVER_NAME);
2228 ret = -ENOMEM;
2229 goto no_srp_cache;
2230 }
2231
2232 /* Derive version string. */
2233 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002234 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002235 strcat(qla4xxx_version_str, "-debug");
2236
2237 qla4xxx_scsi_transport =
2238 iscsi_register_transport(&qla4xxx_iscsi_transport);
2239 if (!qla4xxx_scsi_transport){
2240 ret = -ENODEV;
2241 goto release_srb_cache;
2242 }
2243
David Somayajuluafaf5a22006-09-19 10:28:00 -07002244 ret = pci_register_driver(&qla4xxx_pci_driver);
2245 if (ret)
2246 goto unregister_transport;
2247
2248 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
2249 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05002250
David Somayajuluafaf5a22006-09-19 10:28:00 -07002251unregister_transport:
2252 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2253release_srb_cache:
2254 kmem_cache_destroy(srb_cachep);
2255no_srp_cache:
2256 return ret;
2257}
2258
2259static void __exit qla4xxx_module_exit(void)
2260{
David Somayajuluafaf5a22006-09-19 10:28:00 -07002261 pci_unregister_driver(&qla4xxx_pci_driver);
2262 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2263 kmem_cache_destroy(srb_cachep);
2264}
2265
2266module_init(qla4xxx_module_init);
2267module_exit(qla4xxx_module_exit);
2268
2269MODULE_AUTHOR("QLogic Corporation");
2270MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
2271MODULE_LICENSE("GPL");
2272MODULE_VERSION(QLA4XXX_DRIVER_VERSION);