blob: f2364ec59f0349e43950fd2a4585ba7f2c26838c [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
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 */
David Somayajuluafaf5a22006-09-19 10:28:00 -070032int ql4xdontresethba = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053033module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070034MODULE_PARM_DESC(ql4xdontresethba,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053035 "Don't reset the HBA for driver recovery \n"
36 " 0 - It will reset HBA (Default)\n"
37 " 1 - It will NOT reset HBA");
David Somayajuluafaf5a22006-09-19 10:28:00 -070038
Andrew Vasquez11010fe2006-10-06 09:54:59 -070039int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053040module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070041MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070042 "Option to enable extended error logging, "
43 "Default is 0 - no logging, 1 - debug logging");
44
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053045int ql4xenablemsix = 1;
46module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(ql4xenablemsix,
48 "Set to enable MSI or MSI-X interrupt mechanism.\n"
49 " 0 = enable INTx interrupt mechanism.\n"
50 " 1 = enable MSI-X interrupt mechanism (Default).\n"
51 " 2 = enable MSI interrupt mechanism.");
David C Somayajulu477ffb92007-01-22 12:26:11 -080052
Mike Christied510d962008-07-11 19:50:33 -050053#define QL4_DEF_QDEPTH 32
Vikas Chaudhary8bb40332011-03-21 03:34:31 -070054static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
55module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
56MODULE_PARM_DESC(ql4xmaxqdepth,
57 "Maximum queue depth to report for target devices.\n"
58 " Default: 32.");
Mike Christied510d962008-07-11 19:50:33 -050059
Vikas Chaudhary30387272011-03-21 03:34:32 -070060static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
61module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
62MODULE_PARM_DESC(ql4xsess_recovery_tmo,
63 "Target Session Recovery Timeout.\n"
64 " Default: 30 sec.");
65
David Somayajuluafaf5a22006-09-19 10:28:00 -070066/*
67 * SCSI host template entry points
68 */
Adrian Bunk47975472007-04-26 00:35:16 -070069static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070070
71/*
72 * iSCSI template entry points
73 */
Mike Christie2174a042007-05-30 12:57:10 -050074static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
75 enum iscsi_tgt_dscvr type, uint32_t enable,
76 struct sockaddr *dst_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -070077static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
78 enum iscsi_param param, char *buf);
79static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
80 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050081static int qla4xxx_host_get_param(struct Scsi_Host *shost,
82 enum iscsi_host_param param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -070083static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
Mike Christie5c656af2009-07-15 15:02:59 -050084static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
David Somayajuluafaf5a22006-09-19 10:28:00 -070085
86/*
87 * SCSI host template entry points
88 */
Jeff Garzikf2812332010-11-16 02:10:29 -050089static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +053090static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070091static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -060092static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070093static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
94static int qla4xxx_slave_alloc(struct scsi_device *device);
95static int qla4xxx_slave_configure(struct scsi_device *device);
96static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie024f8012008-03-04 13:26:54 -060097static void qla4xxx_scan_start(struct Scsi_Host *shost);
David Somayajuluafaf5a22006-09-19 10:28:00 -070098
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053099static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
100 QLA82XX_LEGACY_INTR_CONFIG;
101
David Somayajuluafaf5a22006-09-19 10:28:00 -0700102static struct scsi_host_template qla4xxx_driver_template = {
103 .module = THIS_MODULE,
104 .name = DRIVER_NAME,
105 .proc_name = DRIVER_NAME,
106 .queuecommand = qla4xxx_queuecommand,
107
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530108 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700109 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600110 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700111 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500112 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700113
114 .slave_configure = qla4xxx_slave_configure,
115 .slave_alloc = qla4xxx_slave_alloc,
116 .slave_destroy = qla4xxx_slave_destroy,
117
Mike Christie921601b2008-01-31 13:36:49 -0600118 .scan_finished = iscsi_scan_finished,
Mike Christie024f8012008-03-04 13:26:54 -0600119 .scan_start = qla4xxx_scan_start,
Mike Christie921601b2008-01-31 13:36:49 -0600120
David Somayajuluafaf5a22006-09-19 10:28:00 -0700121 .this_id = -1,
122 .cmd_per_lun = 3,
123 .use_clustering = ENABLE_CLUSTERING,
124 .sg_tablesize = SG_ALL,
125
126 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700127 .shost_attrs = qla4xxx_host_attrs,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700128};
129
130static struct iscsi_transport qla4xxx_iscsi_transport = {
131 .owner = THIS_MODULE,
132 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500133 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
134 CAP_DATA_PATH_OFFLOAD,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500135 .param_mask = ISCSI_CONN_PORT | ISCSI_CONN_ADDRESS |
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530136 ISCSI_TARGET_NAME | ISCSI_TPGT |
137 ISCSI_TARGET_ALIAS,
Mike Christie8ad57812007-05-30 12:57:13 -0500138 .host_param_mask = ISCSI_HOST_HWADDRESS |
Mike Christie22236962007-05-30 12:57:24 -0500139 ISCSI_HOST_IPADDRESS |
Mike Christie8ad57812007-05-30 12:57:13 -0500140 ISCSI_HOST_INITIATOR_NAME,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700141 .tgt_dscvr = qla4xxx_tgt_dscvr,
142 .get_conn_param = qla4xxx_conn_get_param,
143 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500144 .get_host_param = qla4xxx_host_get_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700145 .session_recovery_timedout = qla4xxx_recovery_timedout,
146};
147
148static struct scsi_transport_template *qla4xxx_scsi_transport;
149
Mike Christie5c656af2009-07-15 15:02:59 -0500150static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
151{
152 struct iscsi_cls_session *session;
153 struct ddb_entry *ddb_entry;
154
155 session = starget_to_session(scsi_target(sc->device));
156 ddb_entry = session->dd_data;
157
158 /* if we are not logged in then the LLD is going to clean up the cmd */
159 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
160 return BLK_EH_RESET_TIMER;
161 else
162 return BLK_EH_NOT_HANDLED;
163}
164
David Somayajuluafaf5a22006-09-19 10:28:00 -0700165static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
166{
167 struct ddb_entry *ddb_entry = session->dd_data;
168 struct scsi_qla_host *ha = ddb_entry->ha;
169
Mike Christie568d3032008-01-31 13:36:47 -0600170 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
171 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700172
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530173 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
Mike Christie568d3032008-01-31 13:36:47 -0600174 "of (%d) secs exhausted, marking device DEAD.\n",
175 ha->host_no, __func__, ddb_entry->fw_ddb_index,
Vikas Chaudhary30387272011-03-21 03:34:32 -0700176 ddb_entry->sess->recovery_tmo));
Mike Christie568d3032008-01-31 13:36:47 -0600177 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700178}
179
Mike Christieaa1e93a2007-05-30 12:57:09 -0500180static int qla4xxx_host_get_param(struct Scsi_Host *shost,
181 enum iscsi_host_param param, char *buf)
182{
183 struct scsi_qla_host *ha = to_qla_host(shost);
184 int len;
185
186 switch (param) {
187 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800188 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500189 break;
Mike Christie22236962007-05-30 12:57:24 -0500190 case ISCSI_HOST_PARAM_IPADDRESS:
191 len = sprintf(buf, "%d.%d.%d.%d\n", ha->ip_address[0],
192 ha->ip_address[1], ha->ip_address[2],
193 ha->ip_address[3]);
194 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500195 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500196 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500197 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500198 default:
199 return -ENOSYS;
200 }
201
202 return len;
203}
204
David Somayajuluafaf5a22006-09-19 10:28:00 -0700205static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
206 enum iscsi_param param, char *buf)
207{
208 struct ddb_entry *ddb_entry = sess->dd_data;
209 int len;
210
211 switch (param) {
212 case ISCSI_PARAM_TARGET_NAME:
213 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
214 ddb_entry->iscsi_name);
215 break;
216 case ISCSI_PARAM_TPGT:
217 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
218 break;
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530219 case ISCSI_PARAM_TARGET_ALIAS:
220 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
221 ddb_entry->iscsi_alias);
222 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700223 default:
224 return -ENOSYS;
225 }
226
227 return len;
228}
229
230static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
231 enum iscsi_param param, char *buf)
232{
233 struct iscsi_cls_session *session;
234 struct ddb_entry *ddb_entry;
235 int len;
236
237 session = iscsi_dev_to_session(conn->dev.parent);
238 ddb_entry = session->dd_data;
239
240 switch (param) {
241 case ISCSI_PARAM_CONN_PORT:
242 len = sprintf(buf, "%hu\n", ddb_entry->port);
243 break;
244 case ISCSI_PARAM_CONN_ADDRESS:
245 /* TODO: what are the ipv6 bits */
Harvey Harrison63779432008-10-31 00:56:00 -0700246 len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700247 break;
248 default:
249 return -ENOSYS;
250 }
251
252 return len;
253}
254
Mike Christie2174a042007-05-30 12:57:10 -0500255static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
256 enum iscsi_tgt_dscvr type, uint32_t enable,
257 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700258{
259 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700260 struct sockaddr_in *addr;
261 struct sockaddr_in6 *addr6;
262 int ret = 0;
263
David Somayajuluafaf5a22006-09-19 10:28:00 -0700264 ha = (struct scsi_qla_host *) shost->hostdata;
265
266 switch (type) {
267 case ISCSI_TGT_DSCVR_SEND_TARGETS:
268 if (dst_addr->sa_family == AF_INET) {
269 addr = (struct sockaddr_in *)dst_addr;
270 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
271 addr->sin_port) != QLA_SUCCESS)
272 ret = -EIO;
273 } else if (dst_addr->sa_family == AF_INET6) {
274 /*
275 * TODO: fix qla4xxx_send_tgts
276 */
277 addr6 = (struct sockaddr_in6 *)dst_addr;
278 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
279 addr6->sin6_port) != QLA_SUCCESS)
280 ret = -EIO;
281 } else
282 ret = -ENOSYS;
283 break;
284 default:
285 ret = -ENOSYS;
286 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700287 return ret;
288}
289
290void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
291{
292 if (!ddb_entry->sess)
293 return;
294
295 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600296 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700297 iscsi_remove_session(ddb_entry->sess);
298 }
299 iscsi_free_session(ddb_entry->sess);
300}
301
302int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
303{
304 int err;
305
Vikas Chaudhary30387272011-03-21 03:34:32 -0700306 ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530307
David Somayajuluafaf5a22006-09-19 10:28:00 -0700308 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
309 if (err) {
310 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
311 return err;
312 }
313
Mike Christie5d91e202008-05-21 15:54:01 -0500314 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700315 if (!ddb_entry->conn) {
316 iscsi_remove_session(ddb_entry->sess);
317 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
318 return -ENOMEM;
319 }
Mike Christieb6359302008-01-31 13:36:44 -0600320
321 /* finally ready to go */
322 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700323 return 0;
324}
325
326struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
327{
328 struct ddb_entry *ddb_entry;
329 struct iscsi_cls_session *sess;
330
Mike Christie5d91e202008-05-21 15:54:01 -0500331 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
332 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700333 if (!sess)
334 return NULL;
335
336 ddb_entry = sess->dd_data;
337 memset(ddb_entry, 0, sizeof(*ddb_entry));
338 ddb_entry->ha = ha;
339 ddb_entry->sess = sess;
340 return ddb_entry;
341}
342
Mike Christie024f8012008-03-04 13:26:54 -0600343static void qla4xxx_scan_start(struct Scsi_Host *shost)
344{
345 struct scsi_qla_host *ha = shost_priv(shost);
346 struct ddb_entry *ddb_entry, *ddbtemp;
347
348 /* finish setup of sessions that were already setup in firmware */
349 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
350 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
351 qla4xxx_add_sess(ddb_entry);
352 }
353}
354
David Somayajuluafaf5a22006-09-19 10:28:00 -0700355/*
356 * Timer routines
357 */
358
359static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
360 unsigned long interval)
361{
362 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
363 __func__, ha->host->host_no));
364 init_timer(&ha->timer);
365 ha->timer.expires = jiffies + interval * HZ;
366 ha->timer.data = (unsigned long)ha;
367 ha->timer.function = (void (*)(unsigned long))func;
368 add_timer(&ha->timer);
369 ha->timer_active = 1;
370}
371
372static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
373{
374 del_timer_sync(&ha->timer);
375 ha->timer_active = 0;
376}
377
378/***
379 * qla4xxx_mark_device_missing - mark a device as missing.
380 * @ha: Pointer to host adapter structure.
381 * @ddb_entry: Pointer to device database entry
382 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530383 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700384 **/
385void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
386 struct ddb_entry *ddb_entry)
387{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530388 if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
389 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
390 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
391 ha->host_no, ddb_entry->fw_ddb_index));
392 } else
393 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
394 ddb_entry->fw_ddb_index))
395
Mike Christieb6359302008-01-31 13:36:44 -0600396 iscsi_block_session(ddb_entry->sess);
Mike Christiee5bd7b52008-09-24 11:46:10 -0500397 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700398}
399
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530400/**
401 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
402 * @ha: Pointer to host adapter structure.
403 *
404 * This routine marks a device missing and resets the relogin retry count.
405 **/
406void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
407{
408 struct ddb_entry *ddb_entry, *ddbtemp;
409 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
410 qla4xxx_mark_device_missing(ha, ddb_entry);
411 }
412}
413
David Somayajuluafaf5a22006-09-19 10:28:00 -0700414static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
415 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700416 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700417{
418 struct srb *srb;
419
420 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
421 if (!srb)
422 return srb;
423
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530424 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700425 srb->ha = ha;
426 srb->ddb = ddb_entry;
427 srb->cmd = cmd;
428 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +0530429 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700430
431 return srb;
432}
433
434static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
435{
436 struct scsi_cmnd *cmd = srb->cmd;
437
438 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900439 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700440 srb->flags &= ~SRB_DMA_VALID;
441 }
Vikas Chaudhary53698872010-04-28 11:41:59 +0530442 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700443}
444
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530445void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700446{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530447 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700448 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530449 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700450
451 qla4xxx_srb_free_dma(ha, srb);
452
453 mempool_free(srb, ha->srb_mempool);
454
455 cmd->scsi_done(cmd);
456}
457
458/**
459 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700460 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -0700461 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700462 *
463 * Remarks:
464 * This routine is invoked by Linux to send a SCSI command to the driver.
465 * The mid-level driver tries to ensure that queuecommand never gets
466 * invoked concurrently with itself or the interrupt handler (although
467 * the interrupt handler may call this routine as part of request-
468 * completion handling). Unfortunely, it sometimes calls the scheduler
469 * in interrupt context which is a big NO! NO!.
470 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700471static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700472{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700473 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700474 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -0600475 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700476 struct srb *srb;
477 int rval;
478
Lalit Chandivade2232be02010-07-30 14:38:47 +0530479 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
480 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
481 cmd->result = DID_NO_CONNECT << 16;
482 else
483 cmd->result = DID_REQUEUE << 16;
484 goto qc_fail_command;
485 }
486
Mike Christie7fb19212008-01-31 13:36:45 -0600487 if (!sess) {
488 cmd->result = DID_IMM_RETRY << 16;
489 goto qc_fail_command;
490 }
491
492 rval = iscsi_session_chkready(sess);
493 if (rval) {
494 cmd->result = rval;
495 goto qc_fail_command;
496 }
497
David Somayajuluafaf5a22006-09-19 10:28:00 -0700498 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
499 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
500 cmd->result = DID_NO_CONNECT << 16;
501 goto qc_fail_command;
502 }
Mike Christiec5e98e92008-08-17 15:24:39 -0500503 return SCSI_MLQUEUE_TARGET_BUSY;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700504 }
505
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530506 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
507 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
508 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
509 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
510 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
511 !test_bit(AF_ONLINE, &ha->flags) ||
512 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -0800513 goto qc_host_busy;
514
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700515 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700516 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700517 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700518
519 rval = qla4xxx_send_command_to_isp(ha, srb);
520 if (rval != QLA_SUCCESS)
521 goto qc_host_busy_free_sp;
522
David Somayajuluafaf5a22006-09-19 10:28:00 -0700523 return 0;
524
525qc_host_busy_free_sp:
526 qla4xxx_srb_free_dma(ha, srb);
527 mempool_free(srb, ha->srb_mempool);
528
David Somayajuluafaf5a22006-09-19 10:28:00 -0700529qc_host_busy:
530 return SCSI_MLQUEUE_HOST_BUSY;
531
532qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700533 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700534
535 return 0;
536}
537
538/**
539 * qla4xxx_mem_free - frees memory allocated to adapter
540 * @ha: Pointer to host adapter structure.
541 *
542 * Frees memory previously allocated by qla4xxx_mem_alloc
543 **/
544static void qla4xxx_mem_free(struct scsi_qla_host *ha)
545{
546 if (ha->queues)
547 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
548 ha->queues_dma);
549
550 ha->queues_len = 0;
551 ha->queues = NULL;
552 ha->queues_dma = 0;
553 ha->request_ring = NULL;
554 ha->request_dma = 0;
555 ha->response_ring = NULL;
556 ha->response_dma = 0;
557 ha->shadow_regs = NULL;
558 ha->shadow_regs_dma = 0;
559
560 /* Free srb pool. */
561 if (ha->srb_mempool)
562 mempool_destroy(ha->srb_mempool);
563
564 ha->srb_mempool = NULL;
565
566 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530567 if (is_qla8022(ha)) {
568 if (ha->nx_pcibase)
569 iounmap(
570 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530571 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700572 iounmap(ha->reg);
573 pci_release_regions(ha->pdev);
574}
575
576/**
577 * qla4xxx_mem_alloc - allocates memory for use by adapter.
578 * @ha: Pointer to host adapter structure
579 *
580 * Allocates DMA memory for request and response queues. Also allocates memory
581 * for srbs.
582 **/
583static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
584{
585 unsigned long align;
586
587 /* Allocate contiguous block of DMA memory for queues. */
588 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
589 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
590 sizeof(struct shadow_regs) +
591 MEM_ALIGN_VALUE +
592 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
593 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
594 &ha->queues_dma, GFP_KERNEL);
595 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530596 ql4_printk(KERN_WARNING, ha,
597 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700598
599 goto mem_alloc_error_exit;
600 }
601 memset(ha->queues, 0, ha->queues_len);
602
603 /*
604 * As per RISC alignment requirements -- the bus-address must be a
605 * multiple of the request-ring size (in bytes).
606 */
607 align = 0;
608 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
609 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
610 (MEM_ALIGN_VALUE - 1));
611
612 /* Update request and response queue pointers. */
613 ha->request_dma = ha->queues_dma + align;
614 ha->request_ring = (struct queue_entry *) (ha->queues + align);
615 ha->response_dma = ha->queues_dma + align +
616 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
617 ha->response_ring = (struct queue_entry *) (ha->queues + align +
618 (REQUEST_QUEUE_DEPTH *
619 QUEUE_SIZE));
620 ha->shadow_regs_dma = ha->queues_dma + align +
621 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
622 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
623 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
624 (REQUEST_QUEUE_DEPTH *
625 QUEUE_SIZE) +
626 (RESPONSE_QUEUE_DEPTH *
627 QUEUE_SIZE));
628
629 /* Allocate memory for srb pool. */
630 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
631 mempool_free_slab, srb_cachep);
632 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +0530633 ql4_printk(KERN_WARNING, ha,
634 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -0700635
636 goto mem_alloc_error_exit;
637 }
638
639 return QLA_SUCCESS;
640
641mem_alloc_error_exit:
642 qla4xxx_mem_free(ha);
643 return QLA_ERROR;
644}
645
646/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530647 * qla4_8xxx_check_fw_alive - Check firmware health
648 * @ha: Pointer to host adapter structure.
649 *
650 * Context: Interrupt
651 **/
652static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
653{
654 uint32_t fw_heartbeat_counter, halt_status;
655
656 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +0530657 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
658 if (fw_heartbeat_counter == 0xffffffff) {
659 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
660 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
661 ha->host_no, __func__));
662 return;
663 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530664
665 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
666 ha->seconds_since_last_heartbeat++;
667 /* FW not alive after 2 seconds */
668 if (ha->seconds_since_last_heartbeat == 2) {
669 ha->seconds_since_last_heartbeat = 0;
670 halt_status = qla4_8xxx_rd_32(ha,
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -0700671 QLA82XX_PEG_HALT_STATUS1);
672
673 ql4_printk(KERN_INFO, ha,
674 "scsi(%ld): %s, Dumping hw/fw registers:\n "
675 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
676 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
677 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
678 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
679 ha->host_no, __func__, halt_status,
680 qla4_8xxx_rd_32(ha,
681 QLA82XX_PEG_HALT_STATUS2),
682 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
683 0x3c),
684 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
685 0x3c),
686 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
687 0x3c),
688 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
689 0x3c),
690 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
691 0x3c));
Nilesh Javali21033632010-07-30 14:28:07 +0530692
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530693 /* Since we cannot change dev_state in interrupt
694 * context, set appropriate DPC flag then wakeup
695 * DPC */
696 if (halt_status & HALT_STATUS_UNRECOVERABLE)
697 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
698 else {
699 printk("scsi%ld: %s: detect abort needed!\n",
700 ha->host_no, __func__);
701 set_bit(DPC_RESET_HA, &ha->dpc_flags);
702 }
703 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +0530704 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530705 }
Lalit Chandivade99457d72010-10-06 22:49:32 -0700706 } else
707 ha->seconds_since_last_heartbeat = 0;
708
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530709 ha->fw_heartbeat_counter = fw_heartbeat_counter;
710}
711
712/**
713 * qla4_8xxx_watchdog - Poll dev state
714 * @ha: Pointer to host adapter structure.
715 *
716 * Context: Interrupt
717 **/
718void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
719{
720 uint32_t dev_state;
721
722 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
723
724 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -0800725 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
726 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -0700727 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530728 if (dev_state == QLA82XX_DEV_NEED_RESET &&
729 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -0800730 if (!ql4xdontresethba) {
731 ql4_printk(KERN_INFO, ha, "%s: HW State: "
732 "NEED RESET!\n", __func__);
733 set_bit(DPC_RESET_HA, &ha->dpc_flags);
734 qla4xxx_wake_dpc(ha);
735 qla4xxx_mailbox_premature_completion(ha);
736 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530737 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
738 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -0800739 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
740 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530741 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
742 qla4xxx_wake_dpc(ha);
743 } else {
744 /* Check firmware health */
745 qla4_8xxx_check_fw_alive(ha);
746 }
747 }
748}
749
750/**
David Somayajuluafaf5a22006-09-19 10:28:00 -0700751 * qla4xxx_timer - checks every second for work to do.
752 * @ha: Pointer to host adapter structure.
753 **/
754static void qla4xxx_timer(struct scsi_qla_host *ha)
755{
756 struct ddb_entry *ddb_entry, *dtemp;
757 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +0530758 uint16_t w;
759
760 /* If we are in the middle of AER/EEH processing
761 * skip any processing and reschedule the timer
762 */
763 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
764 mod_timer(&ha->timer, jiffies + HZ);
765 return;
766 }
767
768 /* Hardware read to trigger an EEH error during mailbox waits. */
769 if (!pci_channel_offline(ha->pdev))
770 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700771
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530772 if (is_qla8022(ha)) {
773 qla4_8xxx_watchdog(ha);
774 }
775
David Somayajuluafaf5a22006-09-19 10:28:00 -0700776 /* Search for relogin's to time-out and port down retry. */
777 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
778 /* Count down time between sending relogins */
779 if (adapter_up(ha) &&
780 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
781 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
782 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
783 INVALID_ENTRY) {
784 if (atomic_read(&ddb_entry->retry_relogin_timer)
785 == 0) {
786 atomic_set(&ddb_entry->
787 retry_relogin_timer,
788 INVALID_ENTRY);
789 set_bit(DPC_RELOGIN_DEVICE,
790 &ha->dpc_flags);
791 set_bit(DF_RELOGIN, &ddb_entry->flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530792 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
David Somayajuluafaf5a22006-09-19 10:28:00 -0700793 " login device\n",
794 ha->host_no, __func__,
795 ddb_entry->fw_ddb_index));
796 } else
797 atomic_dec(&ddb_entry->
798 retry_relogin_timer);
799 }
800 }
801
802 /* Wait for relogin to timeout */
803 if (atomic_read(&ddb_entry->relogin_timer) &&
804 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
805 /*
806 * If the relogin times out and the device is
807 * still NOT ONLINE then try and relogin again.
808 */
809 if (atomic_read(&ddb_entry->state) !=
810 DDB_STATE_ONLINE &&
811 ddb_entry->fw_ddb_device_state ==
812 DDB_DS_SESSION_FAILED) {
813 /* Reset retry relogin timer */
814 atomic_inc(&ddb_entry->relogin_retry_count);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530815 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
David Somayajuluafaf5a22006-09-19 10:28:00 -0700816 " timed out-retrying"
817 " relogin (%d)\n",
818 ha->host_no,
819 ddb_entry->fw_ddb_index,
820 atomic_read(&ddb_entry->
821 relogin_retry_count))
822 );
823 start_dpc++;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530824 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
Justin P. Mattockcd09b2c2011-01-28 11:49:08 -0800825 "initiate relogin after"
David Somayajuluafaf5a22006-09-19 10:28:00 -0700826 " %d seconds\n",
827 ha->host_no, ddb_entry->bus,
828 ddb_entry->target,
829 ddb_entry->fw_ddb_index,
830 ddb_entry->default_time2wait + 4)
831 );
832
833 atomic_set(&ddb_entry->retry_relogin_timer,
834 ddb_entry->default_time2wait + 4);
835 }
836 }
837 }
838
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530839 if (!is_qla8022(ha)) {
840 /* Check for heartbeat interval. */
841 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
842 ha->heartbeat_interval != 0) {
843 ha->seconds_since_last_heartbeat++;
844 if (ha->seconds_since_last_heartbeat >
845 ha->heartbeat_interval + 2)
846 set_bit(DPC_RESET_HA, &ha->dpc_flags);
847 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700848 }
849
David Somayajuluafaf5a22006-09-19 10:28:00 -0700850 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -0700851 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -0700852 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
853 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
854 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530855 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -0700856 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
857 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +0530858 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530859 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
860 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -0700861 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700862 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
863 " - dpc flags = 0x%lx\n",
864 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530865 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700866 }
867
868 /* Reschedule timer thread to call us back in one second */
869 mod_timer(&ha->timer, jiffies + HZ);
870
871 DEBUG2(ha->seconds_since_last_intr++);
872}
873
874/**
875 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
876 * @ha: Pointer to host adapter structure.
877 *
878 * This routine stalls the driver until all outstanding commands are returned.
879 * Caller must release the Hardware Lock prior to calling this routine.
880 **/
881static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
882{
883 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700884 unsigned long flags;
885 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700886
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530887 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
888
889 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
890 "complete\n", WAIT_CMD_TOV));
891
892 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -0700893 spin_lock_irqsave(&ha->hardware_lock, flags);
894 /* Find a command that hasn't completed. */
895 for (index = 0; index < ha->host->can_queue; index++) {
896 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -0700897 /*
898 * We cannot just check if the index is valid,
899 * becase if we are run from the scsi eh, then
900 * the scsi/block layer is going to prevent
901 * the tag from being released.
902 */
903 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -0700904 break;
905 }
906 spin_unlock_irqrestore(&ha->hardware_lock, flags);
907
908 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530909 if (index == ha->host->can_queue)
910 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700911
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530912 msleep(1000);
913 }
914 /* If we timed out on waiting for commands to come back
915 * return ERROR. */
916 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700917}
918
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530919int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700920{
David Somayajuluafaf5a22006-09-19 10:28:00 -0700921 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800922 unsigned long flags = 0;
923
924 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700925
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530926 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
927 return QLA_ERROR;
928
David Somayajuluafaf5a22006-09-19 10:28:00 -0700929 spin_lock_irqsave(&ha->hardware_lock, flags);
930
931 /*
932 * If the SCSI Reset Interrupt bit is set, clear it.
933 * Otherwise, the Soft Reset won't work.
934 */
935 ctrl_status = readw(&ha->reg->ctrl_status);
936 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
937 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
938
939 /* Issue Soft Reset */
940 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
941 readl(&ha->reg->ctrl_status);
942
943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530944 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800945}
946
947/**
948 * qla4xxx_soft_reset - performs soft reset.
949 * @ha: Pointer to host adapter structure.
950 **/
951int qla4xxx_soft_reset(struct scsi_qla_host *ha)
952{
953 uint32_t max_wait_time;
954 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -0700955 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -0800956 uint32_t ctrl_status;
957
Vikas Chaudharyf931c532010-10-06 22:48:07 -0700958 status = qla4xxx_hw_reset(ha);
959 if (status != QLA_SUCCESS)
960 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700961
Vikas Chaudharyf931c532010-10-06 22:48:07 -0700962 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700963 /* Wait until the Network Reset Intr bit is cleared */
964 max_wait_time = RESET_INTR_TOV;
965 do {
966 spin_lock_irqsave(&ha->hardware_lock, flags);
967 ctrl_status = readw(&ha->reg->ctrl_status);
968 spin_unlock_irqrestore(&ha->hardware_lock, flags);
969
970 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
971 break;
972
973 msleep(1000);
974 } while ((--max_wait_time));
975
976 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
977 DEBUG2(printk(KERN_WARNING
978 "scsi%ld: Network Reset Intr not cleared by "
979 "Network function, clearing it now!\n",
980 ha->host_no));
981 spin_lock_irqsave(&ha->hardware_lock, flags);
982 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
983 readl(&ha->reg->ctrl_status);
984 spin_unlock_irqrestore(&ha->hardware_lock, flags);
985 }
986
987 /* Wait until the firmware tells us the Soft Reset is done */
988 max_wait_time = SOFT_RESET_TOV;
989 do {
990 spin_lock_irqsave(&ha->hardware_lock, flags);
991 ctrl_status = readw(&ha->reg->ctrl_status);
992 spin_unlock_irqrestore(&ha->hardware_lock, flags);
993
994 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
995 status = QLA_SUCCESS;
996 break;
997 }
998
999 msleep(1000);
1000 } while ((--max_wait_time));
1001
1002 /*
1003 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1004 * after the soft reset has taken place.
1005 */
1006 spin_lock_irqsave(&ha->hardware_lock, flags);
1007 ctrl_status = readw(&ha->reg->ctrl_status);
1008 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
1009 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1010 readl(&ha->reg->ctrl_status);
1011 }
1012 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1013
1014 /* If soft reset fails then most probably the bios on other
1015 * function is also enabled.
1016 * Since the initialization is sequential the other fn
1017 * wont be able to acknowledge the soft reset.
1018 * Issue a force soft reset to workaround this scenario.
1019 */
1020 if (max_wait_time == 0) {
1021 /* Issue Force Soft Reset */
1022 spin_lock_irqsave(&ha->hardware_lock, flags);
1023 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
1024 readl(&ha->reg->ctrl_status);
1025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1026 /* Wait until the firmware tells us the Soft Reset is done */
1027 max_wait_time = SOFT_RESET_TOV;
1028 do {
1029 spin_lock_irqsave(&ha->hardware_lock, flags);
1030 ctrl_status = readw(&ha->reg->ctrl_status);
1031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1032
1033 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
1034 status = QLA_SUCCESS;
1035 break;
1036 }
1037
1038 msleep(1000);
1039 } while ((--max_wait_time));
1040 }
1041
1042 return status;
1043}
1044
1045/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301046 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001047 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301048 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07001049 *
1050 * This routine is called just prior to a HARD RESET to return all
1051 * outstanding commands back to the Operating System.
1052 * Caller should make sure that the following locks are released
1053 * before this calling routine: Hardware lock, and io_request_lock.
1054 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301055static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001056{
1057 struct srb *srb;
1058 int i;
1059 unsigned long flags;
1060
1061 spin_lock_irqsave(&ha->hardware_lock, flags);
1062 for (i = 0; i < ha->host->can_queue; i++) {
1063 srb = qla4xxx_del_from_active_array(ha, i);
1064 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301065 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301066 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001067 }
1068 }
1069 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001070}
1071
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301072void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
1073{
1074 clear_bit(AF_ONLINE, &ha->flags);
1075
1076 /* Disable the board */
1077 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301078
1079 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
1080 qla4xxx_mark_all_devices_missing(ha);
1081 clear_bit(AF_INIT_DONE, &ha->flags);
1082}
1083
David Somayajuluafaf5a22006-09-19 10:28:00 -07001084/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001085 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1086 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001087 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301088static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001089{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301090 int status = QLA_ERROR;
1091 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001092
1093 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301094 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001095 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06001096
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301097 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001098
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301099 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001100
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301101 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1102 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001103
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301104 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1105 * do not reset adapter, jump to initialize_adapter */
1106 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1107 status = QLA_SUCCESS;
1108 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001109 }
1110
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301111 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1112 * from eh_host_reset or ioctl module */
1113 if (is_qla8022(ha) && !reset_chip &&
1114 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
1115
1116 DEBUG2(ql4_printk(KERN_INFO, ha,
1117 "scsi%ld: %s - Performing stop_firmware...\n",
1118 ha->host_no, __func__));
1119 status = ha->isp_ops->reset_firmware(ha);
1120 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001121 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1122 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301123 ha->isp_ops->disable_intrs(ha);
1124 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1125 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1126 } else {
1127 /* If the stop_firmware fails then
1128 * reset the entire chip */
1129 reset_chip = 1;
1130 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1131 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1132 }
1133 }
1134
1135 /* Issue full chip reset if recovering from a catastrophic error,
1136 * or if stop_firmware fails for ISP-82xx.
1137 * This is the default case for ISP-4xxx */
1138 if (!is_qla8022(ha) || reset_chip) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001139 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1140 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301141 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1142 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1143 DEBUG2(ql4_printk(KERN_INFO, ha,
1144 "scsi%ld: %s - Performing chip reset..\n",
1145 ha->host_no, __func__));
1146 status = ha->isp_ops->reset_chip(ha);
1147 }
1148
1149 /* Flush any pending ddb changed AENs */
1150 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1151
1152recover_ha_init_adapter:
1153 /* Upon successful firmware/chip reset, re-initialize the adapter */
1154 if (status == QLA_SUCCESS) {
1155 /* For ISP-4xxx, force function 1 to always initialize
1156 * before function 3 to prevent both funcions from
1157 * stepping on top of the other */
1158 if (!is_qla8022(ha) && (ha->mac_index == 3))
1159 ssleep(6);
1160
1161 /* NOTE: AF_ONLINE flag set upon successful completion of
1162 * qla4xxx_initialize_adapter */
1163 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1164 }
1165
1166 /* Retry failed adapter initialization, if necessary
1167 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1168 * case to prevent ping-pong resets between functions */
1169 if (!test_bit(AF_ONLINE, &ha->flags) &&
1170 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001171 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301172 * resetting the ha.
1173 * Since we don't want to block the DPC for too long
1174 * with multiple resets in the same thread,
1175 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07001176 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1177 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1178 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1179 "(%d) more times\n", ha->host_no,
1180 ha->retry_reset_ha_cnt));
1181 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1182 status = QLA_ERROR;
1183 } else {
1184 if (ha->retry_reset_ha_cnt > 0) {
1185 /* Schedule another Reset HA--DPC will retry */
1186 ha->retry_reset_ha_cnt--;
1187 DEBUG2(printk("scsi%ld: recover adapter - "
1188 "retry remaining %d\n",
1189 ha->host_no,
1190 ha->retry_reset_ha_cnt));
1191 status = QLA_ERROR;
1192 }
1193
1194 if (ha->retry_reset_ha_cnt == 0) {
1195 /* Recover adapter retries have been exhausted.
1196 * Adapter DEAD */
1197 DEBUG2(printk("scsi%ld: recover adapter "
1198 "failed - board disabled\n",
1199 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301200 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001201 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1202 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301203 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001204 &ha->dpc_flags);
1205 status = QLA_ERROR;
1206 }
1207 }
1208 } else {
1209 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301210 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001211 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1212 }
1213
1214 ha->adapter_error_count++;
1215
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301216 if (test_bit(AF_ONLINE, &ha->flags))
1217 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001218
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301219 scsi_unblock_requests(ha->host);
1220
1221 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1222 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001223 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301224
David Somayajuluafaf5a22006-09-19 10:28:00 -07001225 return status;
1226}
1227
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001228static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
1229{
1230 struct ddb_entry *ddb_entry, *dtemp;
1231
1232 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1233 if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) ||
1234 (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) {
1235 if (ddb_entry->fw_ddb_device_state ==
1236 DDB_DS_SESSION_ACTIVE) {
1237 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1238 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
1239 " marked ONLINE\n", ha->host_no, __func__,
1240 ddb_entry->fw_ddb_index);
1241
1242 iscsi_unblock_session(ddb_entry->sess);
1243 } else
1244 qla4xxx_relogin_device(ha, ddb_entry);
1245 }
1246 }
1247}
1248
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301249void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
1250{
Lalit Chandivade1b468072011-05-17 23:17:09 -07001251 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301252 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301253}
1254
David Somayajuluafaf5a22006-09-19 10:28:00 -07001255/**
1256 * qla4xxx_do_dpc - dpc routine
1257 * @data: in our case pointer to adapter structure
1258 *
1259 * This routine is a task that is schedule by the interrupt handler
1260 * to perform the background processing for interrupts. We put it
1261 * on a task queue that is consumed whenever the scheduler runs; that's
1262 * so you can do anything (i.e. put the process to sleep etc). In fact,
1263 * the mid-level tries to sleep when it reaches the driver threshold
1264 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1265 **/
David Howellsc4028952006-11-22 14:57:56 +00001266static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001267{
David Howellsc4028952006-11-22 14:57:56 +00001268 struct scsi_qla_host *ha =
1269 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001270 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001271 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001272
David C Somayajuluf26b9042006-11-15 16:41:09 -08001273 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301274 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1275 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001276
1277 /* Initialization not yet finished. Don't do anything yet. */
1278 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07001279 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001280
Lalit Chandivade2232be02010-07-30 14:38:47 +05301281 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1282 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
1283 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07001284 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301285 }
1286
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301287 if (is_qla8022(ha)) {
1288 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
1289 qla4_8xxx_idc_lock(ha);
1290 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1291 QLA82XX_DEV_FAILED);
1292 qla4_8xxx_idc_unlock(ha);
1293 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
1294 qla4_8xxx_device_state_handler(ha);
1295 }
1296 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1297 qla4_8xxx_need_qsnt_handler(ha);
1298 }
1299 }
1300
1301 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
1302 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001303 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301304 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
1305 if (ql4xdontresethba) {
1306 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1307 ha->host_no, __func__));
1308 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1309 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1310 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1311 goto dpc_post_reset_ha;
1312 }
1313 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1314 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1315 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001316
David C Somayajulu477ffb92007-01-22 12:26:11 -08001317 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001318 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001319
David Somayajuluafaf5a22006-09-19 10:28:00 -07001320 while ((readw(&ha->reg->ctrl_status) &
1321 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1322 if (--wait_time == 0)
1323 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001324 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001325 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001326 if (wait_time == 0)
1327 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1328 "bit not cleared-- resetting\n",
1329 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301330 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001331 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1332 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301333 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001334 }
1335 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1336 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301337 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001338 }
1339 }
1340
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301341dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001342 /* ---- process AEN? --- */
1343 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1344 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1345
1346 /* ---- Get DHCP IP Address? --- */
1347 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1348 qla4xxx_get_dhcp_ip_address(ha);
1349
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301350 /* ---- link change? --- */
1351 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
1352 if (!test_bit(AF_LINK_UP, &ha->flags)) {
1353 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001354 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301355 } else {
1356 /* ---- link up? --- *
1357 * F/W will auto login to all devices ONLY ONCE after
1358 * link up during driver initialization and runtime
1359 * fatal error recovery. Therefore, the driver must
1360 * manually relogin to devices when recovering from
1361 * connection failures, logouts, expired KATO, etc. */
1362
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001363 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301364 }
1365 }
1366
David Somayajuluafaf5a22006-09-19 10:28:00 -07001367 /* ---- relogin device? --- */
1368 if (adapter_up(ha) &&
1369 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1370 list_for_each_entry_safe(ddb_entry, dtemp,
1371 &ha->ddb_list, list) {
1372 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1373 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1374 qla4xxx_relogin_device(ha, ddb_entry);
1375
1376 /*
1377 * If mbx cmd times out there is no point
1378 * in continuing further.
1379 * With large no of targets this can hang
1380 * the system.
1381 */
1382 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1383 printk(KERN_WARNING "scsi%ld: %s: "
1384 "need to reset hba\n",
1385 ha->host_no, __func__);
1386 break;
1387 }
1388 }
1389 }
Vikas Chaudhary0753b482010-07-30 14:27:19 +05301390
David Somayajuluafaf5a22006-09-19 10:28:00 -07001391}
1392
1393/**
1394 * qla4xxx_free_adapter - release the adapter
1395 * @ha: pointer to adapter structure
1396 **/
1397static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1398{
1399
1400 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1401 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301402 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001403 }
1404
David Somayajuluafaf5a22006-09-19 10:28:00 -07001405 /* Remove timer thread, if present */
1406 if (ha->timer_active)
1407 qla4xxx_stop_timer(ha);
1408
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301409 /* Kill the kernel thread for this host */
1410 if (ha->dpc_thread)
1411 destroy_workqueue(ha->dpc_thread);
1412
1413 /* Put firmware in known state */
1414 ha->isp_ops->reset_firmware(ha);
1415
1416 if (is_qla8022(ha)) {
1417 qla4_8xxx_idc_lock(ha);
1418 qla4_8xxx_clear_drv_active(ha);
1419 qla4_8xxx_idc_unlock(ha);
1420 }
1421
David Somayajuluafaf5a22006-09-19 10:28:00 -07001422 /* Detach interrupts */
1423 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301424 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001425
David C Somayajulubee4fe82007-05-23 18:03:32 -07001426 /* free extra memory */
1427 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301428}
David C Somayajulubee4fe82007-05-23 18:03:32 -07001429
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301430int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1431{
1432 int status = 0;
1433 uint8_t revision_id;
1434 unsigned long mem_base, mem_len, db_base, db_len;
1435 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001436
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301437 status = pci_request_regions(pdev, DRIVER_NAME);
1438 if (status) {
1439 printk(KERN_WARNING
1440 "scsi(%ld) Failed to reserve PIO regions (%s) "
1441 "status=%d\n", ha->host_no, pci_name(pdev), status);
1442 goto iospace_error_exit;
1443 }
1444
1445 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
1446 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
1447 __func__, revision_id));
1448 ha->revision_id = revision_id;
1449
1450 /* remap phys address */
1451 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
1452 mem_len = pci_resource_len(pdev, 0);
1453 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
1454 __func__, mem_base, mem_len));
1455
1456 /* mapping of pcibase pointer */
1457 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
1458 if (!ha->nx_pcibase) {
1459 printk(KERN_ERR
1460 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
1461 pci_release_regions(ha->pdev);
1462 goto iospace_error_exit;
1463 }
1464
1465 /* Mapping of IO base pointer, door bell read and write pointer */
1466
1467 /* mapping of IO base pointer */
1468 ha->qla4_8xxx_reg =
1469 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
1470 0xbc000 + (ha->pdev->devfn << 11));
1471
1472 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
1473 db_len = pci_resource_len(pdev, 4);
1474
Shyam Sundar2657c802010-10-06 22:50:29 -07001475 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
1476 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301477
Shyam Sundar2657c802010-10-06 22:50:29 -07001478 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301479iospace_error_exit:
1480 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001481}
1482
1483/***
1484 * qla4xxx_iospace_config - maps registers
1485 * @ha: pointer to adapter structure
1486 *
1487 * This routines maps HBA's registers from the pci address space
1488 * into the kernel virtual address space for memory mapped i/o.
1489 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301490int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001491{
1492 unsigned long pio, pio_len, pio_flags;
1493 unsigned long mmio, mmio_len, mmio_flags;
1494
1495 pio = pci_resource_start(ha->pdev, 0);
1496 pio_len = pci_resource_len(ha->pdev, 0);
1497 pio_flags = pci_resource_flags(ha->pdev, 0);
1498 if (pio_flags & IORESOURCE_IO) {
1499 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301500 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001501 "Invalid PCI I/O region size\n");
1502 pio = 0;
1503 }
1504 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301505 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001506 pio = 0;
1507 }
1508
1509 /* Use MMIO operations for all accesses. */
1510 mmio = pci_resource_start(ha->pdev, 1);
1511 mmio_len = pci_resource_len(ha->pdev, 1);
1512 mmio_flags = pci_resource_flags(ha->pdev, 1);
1513
1514 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301515 ql4_printk(KERN_ERR, ha,
1516 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001517
1518 goto iospace_error_exit;
1519 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301520
David Somayajuluafaf5a22006-09-19 10:28:00 -07001521 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301522 ql4_printk(KERN_ERR, ha,
1523 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001524 goto iospace_error_exit;
1525 }
1526
1527 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301528 ql4_printk(KERN_WARNING, ha,
1529 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001530
1531 goto iospace_error_exit;
1532 }
1533
1534 ha->pio_address = pio;
1535 ha->pio_length = pio_len;
1536 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
1537 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301538 ql4_printk(KERN_ERR, ha,
1539 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001540
1541 goto iospace_error_exit;
1542 }
1543
1544 return 0;
1545
1546iospace_error_exit:
1547 return -ENOMEM;
1548}
1549
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301550static struct isp_operations qla4xxx_isp_ops = {
1551 .iospace_config = qla4xxx_iospace_config,
1552 .pci_config = qla4xxx_pci_config,
1553 .disable_intrs = qla4xxx_disable_intrs,
1554 .enable_intrs = qla4xxx_enable_intrs,
1555 .start_firmware = qla4xxx_start_firmware,
1556 .intr_handler = qla4xxx_intr_handler,
1557 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
1558 .reset_chip = qla4xxx_soft_reset,
1559 .reset_firmware = qla4xxx_hw_reset,
1560 .queue_iocb = qla4xxx_queue_iocb,
1561 .complete_iocb = qla4xxx_complete_iocb,
1562 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
1563 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
1564 .get_sys_info = qla4xxx_get_sys_info,
1565};
1566
1567static struct isp_operations qla4_8xxx_isp_ops = {
1568 .iospace_config = qla4_8xxx_iospace_config,
1569 .pci_config = qla4_8xxx_pci_config,
1570 .disable_intrs = qla4_8xxx_disable_intrs,
1571 .enable_intrs = qla4_8xxx_enable_intrs,
1572 .start_firmware = qla4_8xxx_load_risc,
1573 .intr_handler = qla4_8xxx_intr_handler,
1574 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
1575 .reset_chip = qla4_8xxx_isp_reset,
1576 .reset_firmware = qla4_8xxx_stop_firmware,
1577 .queue_iocb = qla4_8xxx_queue_iocb,
1578 .complete_iocb = qla4_8xxx_complete_iocb,
1579 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
1580 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
1581 .get_sys_info = qla4_8xxx_get_sys_info,
1582};
1583
1584uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1585{
1586 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
1587}
1588
1589uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
1590{
1591 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
1592}
1593
1594uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1595{
1596 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
1597}
1598
1599uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
1600{
1601 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
1602}
1603
David Somayajuluafaf5a22006-09-19 10:28:00 -07001604/**
1605 * qla4xxx_probe_adapter - callback function to probe HBA
1606 * @pdev: pointer to pci_dev structure
1607 * @pci_device_id: pointer to pci_device entry
1608 *
1609 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
1610 * It returns zero if successful. It also initializes all data necessary for
1611 * the driver.
1612 **/
1613static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
1614 const struct pci_device_id *ent)
1615{
1616 int ret = -ENODEV, status;
1617 struct Scsi_Host *host;
1618 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001619 uint8_t init_retry_count = 0;
1620 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301621 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07001622 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001623
1624 if (pci_enable_device(pdev))
1625 return -1;
1626
1627 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
1628 if (host == NULL) {
1629 printk(KERN_WARNING
1630 "qla4xxx: Couldn't allocate host from scsi layer!\n");
1631 goto probe_disable_device;
1632 }
1633
1634 /* Clear our data area */
1635 ha = (struct scsi_qla_host *) host->hostdata;
1636 memset(ha, 0, sizeof(*ha));
1637
1638 /* Save the information from PCI BIOS. */
1639 ha->pdev = pdev;
1640 ha->host = host;
1641 ha->host_no = host->host_no;
1642
Lalit Chandivade2232be02010-07-30 14:38:47 +05301643 pci_enable_pcie_error_reporting(pdev);
1644
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301645 /* Setup Runtime configurable options */
1646 if (is_qla8022(ha)) {
1647 ha->isp_ops = &qla4_8xxx_isp_ops;
1648 rwlock_init(&ha->hw_lock);
1649 ha->qdr_sn_window = -1;
1650 ha->ddr_mn_window = -1;
1651 ha->curr_window = 255;
1652 ha->func_num = PCI_FUNC(ha->pdev->devfn);
1653 nx_legacy_intr = &legacy_intr[ha->func_num];
1654 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
1655 ha->nx_legacy_intr.tgt_status_reg =
1656 nx_legacy_intr->tgt_status_reg;
1657 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
1658 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
1659 } else {
1660 ha->isp_ops = &qla4xxx_isp_ops;
1661 }
1662
Lalit Chandivade2232be02010-07-30 14:38:47 +05301663 /* Set EEH reset type to fundamental if required by hba */
1664 if (is_qla8022(ha))
1665 pdev->needs_freset = 1;
1666
David Somayajuluafaf5a22006-09-19 10:28:00 -07001667 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301668 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001669 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301670 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001671
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301672 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07001673 pdev->device, pdev->irq, ha->reg);
1674
1675 qla4xxx_config_dma_addressing(ha);
1676
1677 /* Initialize lists and spinlocks. */
1678 INIT_LIST_HEAD(&ha->ddb_list);
1679 INIT_LIST_HEAD(&ha->free_srb_q);
1680
1681 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301682 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001683
1684 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001685
1686 /* Allocate dma buffers */
1687 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301688 ql4_printk(KERN_WARNING, ha,
1689 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001690
1691 ret = -ENOMEM;
1692 goto probe_failed;
1693 }
1694
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301695 if (is_qla8022(ha))
1696 (void) qla4_8xxx_get_flash_info(ha);
1697
David Somayajuluafaf5a22006-09-19 10:28:00 -07001698 /*
1699 * Initialize the Host adapter request/response queues and
1700 * firmware
1701 * NOTE: interrupts enabled upon successful completion
1702 */
1703 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301704 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
1705 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07001706
1707 if (is_qla8022(ha)) {
1708 qla4_8xxx_idc_lock(ha);
1709 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1710 qla4_8xxx_idc_unlock(ha);
1711 if (dev_state == QLA82XX_DEV_FAILED) {
1712 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
1713 "initialize adapter. H/W is in failed state\n",
1714 __func__);
1715 break;
1716 }
1717 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001718 DEBUG2(printk("scsi: %s: retrying adapter initialization "
1719 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301720
1721 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
1722 continue;
1723
David Somayajuluafaf5a22006-09-19 10:28:00 -07001724 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
1725 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301726
1727 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301728 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001729
Lalit Chandivadefe998522010-12-02 22:12:36 -08001730 if (is_qla8022(ha) && ql4xdontresethba) {
1731 /* Put the device in failed state. */
1732 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
1733 qla4_8xxx_idc_lock(ha);
1734 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1735 QLA82XX_DEV_FAILED);
1736 qla4_8xxx_idc_unlock(ha);
1737 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001738 ret = -ENODEV;
1739 goto probe_failed;
1740 }
1741
1742 host->cmd_per_lun = 3;
1743 host->max_channel = 0;
1744 host->max_lun = MAX_LUNS - 1;
1745 host->max_id = MAX_TARGETS;
1746 host->max_cmd_len = IOCB_MAX_CDB_LEN;
1747 host->can_queue = MAX_SRBS ;
1748 host->transportt = qla4xxx_scsi_transport;
1749
1750 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
1751 if (ret) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301752 ql4_printk(KERN_WARNING, ha,
1753 "scsi_init_shared_tag_map failed\n");
1754 goto probe_failed;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001755 }
1756
1757 /* Startup the kernel thread for this host adapter. */
1758 DEBUG2(printk("scsi: %s: Starting kernel thread for "
1759 "qla4xxx_dpc\n", __func__));
1760 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
1761 ha->dpc_thread = create_singlethread_workqueue(buf);
1762 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301763 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001764 ret = -ENODEV;
1765 goto probe_failed;
1766 }
David Howellsc4028952006-11-22 14:57:56 +00001767 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001768
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301769 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
1770 * (which is called indirectly by qla4xxx_initialize_adapter),
1771 * so that irqs will be registered after crbinit but before
1772 * mbx_intr_enable.
1773 */
1774 if (!is_qla8022(ha)) {
1775 ret = qla4xxx_request_irqs(ha);
1776 if (ret) {
1777 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
1778 "interrupt %d already in use.\n", pdev->irq);
1779 goto probe_failed;
1780 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001781 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001782
Lalit Chandivade2232be02010-07-30 14:38:47 +05301783 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301784 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001785
1786 /* Start timer thread. */
1787 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
1788
1789 set_bit(AF_INIT_DONE, &ha->flags);
1790
1791 pci_set_drvdata(pdev, ha);
1792
1793 ret = scsi_add_host(host, &pdev->dev);
1794 if (ret)
1795 goto probe_failed;
1796
David Somayajuluafaf5a22006-09-19 10:28:00 -07001797 printk(KERN_INFO
1798 " QLogic iSCSI HBA Driver version: %s\n"
1799 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
1800 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
1801 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
1802 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06001803 scsi_scan_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001804 return 0;
1805
David Somayajuluafaf5a22006-09-19 10:28:00 -07001806probe_failed:
1807 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301808
1809probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05301810 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001811 scsi_host_put(ha->host);
1812
1813probe_disable_device:
1814 pci_disable_device(pdev);
1815
1816 return ret;
1817}
1818
1819/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07001820 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
1821 * @ha: pointer to adapter structure
1822 *
1823 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
1824 * so that the other port will not re-initialize while in the process of
1825 * removing the ha due to driver unload or hba hotplug.
1826 **/
1827static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
1828{
1829 struct scsi_qla_host *other_ha = NULL;
1830 struct pci_dev *other_pdev = NULL;
1831 int fn = ISP4XXX_PCI_FN_2;
1832
1833 /*iscsi function numbers for ISP4xxx is 1 and 3*/
1834 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
1835 fn = ISP4XXX_PCI_FN_1;
1836
1837 other_pdev =
1838 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
1839 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
1840 fn));
1841
1842 /* Get other_ha if other_pdev is valid and state is enable*/
1843 if (other_pdev) {
1844 if (atomic_read(&other_pdev->enable_cnt)) {
1845 other_ha = pci_get_drvdata(other_pdev);
1846 if (other_ha) {
1847 set_bit(AF_HA_REMOVAL, &other_ha->flags);
1848 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
1849 "Prevent %s reinit\n", __func__,
1850 dev_name(&other_ha->pdev->dev)));
1851 }
1852 }
1853 pci_dev_put(other_pdev);
1854 }
1855}
1856
1857/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001858 * qla4xxx_remove_adapter - calback function to remove adapter.
1859 * @pci_dev: PCI device pointer
1860 **/
1861static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1862{
1863 struct scsi_qla_host *ha;
1864
1865 ha = pci_get_drvdata(pdev);
1866
Karen Higgins7eece5a2011-03-21 03:34:29 -07001867 if (!is_qla8022(ha))
1868 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07001869
David Somayajuluafaf5a22006-09-19 10:28:00 -07001870 /* remove devs from iscsi_sessions to scsi_devices */
1871 qla4xxx_free_ddb_list(ha);
1872
1873 scsi_remove_host(ha->host);
1874
1875 qla4xxx_free_adapter(ha);
1876
1877 scsi_host_put(ha->host);
1878
Lalit Chandivade2232be02010-07-30 14:38:47 +05301879 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301880 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001881 pci_set_drvdata(pdev, NULL);
1882}
1883
1884/**
1885 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
1886 * @ha: HA context
1887 *
1888 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1889 * supported addressing method.
1890 */
Adrian Bunk47975472007-04-26 00:35:16 -07001891static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001892{
1893 int retval;
1894
1895 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07001896 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
1897 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001898 dev_dbg(&ha->pdev->dev,
1899 "Failed to set 64 bit PCI consistent mask; "
1900 "using 32 bit.\n");
1901 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07001902 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001903 }
1904 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07001905 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001906}
1907
1908static int qla4xxx_slave_alloc(struct scsi_device *sdev)
1909{
1910 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
1911 struct ddb_entry *ddb = sess->dd_data;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07001912 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001913
1914 sdev->hostdata = ddb;
1915 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07001916
1917 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
1918 queue_depth = ql4xmaxqdepth;
1919
1920 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001921 return 0;
1922}
1923
1924static int qla4xxx_slave_configure(struct scsi_device *sdev)
1925{
1926 sdev->tagged_supported = 1;
1927 return 0;
1928}
1929
1930static void qla4xxx_slave_destroy(struct scsi_device *sdev)
1931{
1932 scsi_deactivate_tcq(sdev, 1);
1933}
1934
1935/**
1936 * qla4xxx_del_from_active_array - returns an active srb
1937 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02001938 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07001939 *
1940 * This routine removes and returns the srb at the specified index
1941 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301942struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
1943 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001944{
1945 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05301946 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001947
Vikas Chaudhary53698872010-04-28 11:41:59 +05301948 cmd = scsi_host_find_tag(ha->host, index);
1949 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001950 return srb;
1951
Vikas Chaudhary53698872010-04-28 11:41:59 +05301952 srb = (struct srb *)CMD_SP(cmd);
1953 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001954 return srb;
1955
1956 /* update counters */
1957 if (srb->flags & SRB_DMA_VALID) {
1958 ha->req_q_count += srb->iocb_cnt;
1959 ha->iocb_cnt -= srb->iocb_cnt;
1960 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05301961 srb->cmd->host_scribble =
1962 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001963 }
1964 return srb;
1965}
1966
1967/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001968 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301969 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001970 * @cmd: Scsi Command to wait on.
1971 *
1972 * This routine waits for the command to be returned by the Firmware
1973 * for some max time.
1974 **/
1975static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
1976 struct scsi_cmnd *cmd)
1977{
1978 int done = 0;
1979 struct srb *rp;
1980 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301981 int ret = SUCCESS;
1982
1983 /* Dont wait on command if PCI error is being handled
1984 * by PCI AER driver
1985 */
1986 if (unlikely(pci_channel_offline(ha->pdev)) ||
1987 (test_bit(AF_EEH_BUSY, &ha->flags))) {
1988 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
1989 ha->host_no, __func__);
1990 return ret;
1991 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001992
1993 do {
1994 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05301995 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001996 if (rp == NULL) {
1997 done++;
1998 break;
1999 }
2000
2001 msleep(2000);
2002 } while (max_wait_time--);
2003
2004 return done;
2005}
2006
2007/**
2008 * qla4xxx_wait_for_hba_online - waits for HBA to come online
2009 * @ha: Pointer to host adapter structure
2010 **/
2011static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
2012{
2013 unsigned long wait_online;
2014
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002015 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002016 while (time_before(jiffies, wait_online)) {
2017
2018 if (adapter_up(ha))
2019 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002020
2021 msleep(2000);
2022 }
2023
2024 return QLA_ERROR;
2025}
2026
2027/**
Mike Christiece545032008-02-29 18:25:20 -06002028 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002029 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07002030 * @t: target id
2031 * @l: lun id
2032 *
2033 * This function waits for all outstanding commands to a lun to complete. It
2034 * returns 0 if all pending commands are returned and 1 otherwise.
2035 **/
Mike Christiece545032008-02-29 18:25:20 -06002036static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
2037 struct scsi_target *stgt,
2038 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002039{
2040 int cnt;
2041 int status = 0;
2042 struct scsi_cmnd *cmd;
2043
2044 /*
Mike Christiece545032008-02-29 18:25:20 -06002045 * Waiting for all commands for the designated target or dev
2046 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002047 */
2048 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
2049 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06002050 if (cmd && stgt == scsi_target(cmd->device) &&
2051 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002052 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2053 status++;
2054 break;
2055 }
2056 }
2057 }
2058 return status;
2059}
2060
2061/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302062 * qla4xxx_eh_abort - callback for abort task.
2063 * @cmd: Pointer to Linux's SCSI command structure
2064 *
2065 * This routine is called by the Linux OS to abort the specified
2066 * command.
2067 **/
2068static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
2069{
2070 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2071 unsigned int id = cmd->device->id;
2072 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002073 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302074 struct srb *srb = NULL;
2075 int ret = SUCCESS;
2076 int wait = 0;
2077
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302078 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04002079 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
2080 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302081
Mike Christie92b3e5b2010-10-06 22:51:17 -07002082 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302083 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002084 if (!srb) {
2085 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302086 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002087 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302088 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002089 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302090
2091 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
2092 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
2093 ha->host_no, id, lun));
2094 ret = FAILED;
2095 } else {
2096 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
2097 ha->host_no, id, lun));
2098 wait = 1;
2099 }
2100
2101 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2102
2103 /* Wait for command to complete */
2104 if (wait) {
2105 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2106 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
2107 ha->host_no, id, lun));
2108 ret = FAILED;
2109 }
2110 }
2111
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302112 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302113 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002114 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302115
2116 return ret;
2117}
2118
2119/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002120 * qla4xxx_eh_device_reset - callback for target reset.
2121 * @cmd: Pointer to Linux's SCSI command structure
2122 *
2123 * This routine is called by the Linux OS to reset all luns on the
2124 * specified target.
2125 **/
2126static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
2127{
2128 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2129 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002130 int ret = FAILED, stat;
2131
Karen Higgins612f7342009-07-15 15:03:01 -05002132 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002133 return ret;
2134
Mike Christiec01be6d2010-07-22 16:59:49 +05302135 ret = iscsi_block_scsi_eh(cmd);
2136 if (ret)
2137 return ret;
2138 ret = FAILED;
2139
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302140 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002141 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2142 cmd->device->channel, cmd->device->id, cmd->device->lun);
2143
2144 DEBUG2(printk(KERN_INFO
2145 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2146 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07002147 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002148 ha->dpc_flags, cmd->result, cmd->allowed));
2149
2150 /* FIXME: wait for hba to go online */
2151 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
2152 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302153 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002154 goto eh_dev_reset_done;
2155 }
2156
Mike Christiece545032008-02-29 18:25:20 -06002157 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2158 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302159 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06002160 "DEVICE RESET FAILED - waiting for "
2161 "commands.\n");
2162 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002163 }
2164
David C Somayajulu9d562912008-03-19 11:23:03 -07002165 /* Send marker. */
2166 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2167 MM_LUN_RESET) != QLA_SUCCESS)
2168 goto eh_dev_reset_done;
2169
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302170 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002171 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2172 ha->host_no, cmd->device->channel, cmd->device->id,
2173 cmd->device->lun);
2174
2175 ret = SUCCESS;
2176
2177eh_dev_reset_done:
2178
2179 return ret;
2180}
2181
2182/**
Mike Christiece545032008-02-29 18:25:20 -06002183 * qla4xxx_eh_target_reset - callback for target reset.
2184 * @cmd: Pointer to Linux's SCSI command structure
2185 *
2186 * This routine is called by the Linux OS to reset the target.
2187 **/
2188static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
2189{
2190 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2191 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05302192 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06002193
2194 if (!ddb_entry)
2195 return FAILED;
2196
Mike Christiec01be6d2010-07-22 16:59:49 +05302197 ret = iscsi_block_scsi_eh(cmd);
2198 if (ret)
2199 return ret;
2200
Mike Christiece545032008-02-29 18:25:20 -06002201 starget_printk(KERN_INFO, scsi_target(cmd->device),
2202 "WARM TARGET RESET ISSUED.\n");
2203
2204 DEBUG2(printk(KERN_INFO
2205 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2206 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07002207 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06002208 ha->dpc_flags, cmd->result, cmd->allowed));
2209
2210 stat = qla4xxx_reset_target(ha, ddb_entry);
2211 if (stat != QLA_SUCCESS) {
2212 starget_printk(KERN_INFO, scsi_target(cmd->device),
2213 "WARM TARGET RESET FAILED.\n");
2214 return FAILED;
2215 }
2216
Mike Christiece545032008-02-29 18:25:20 -06002217 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2218 NULL)) {
2219 starget_printk(KERN_INFO, scsi_target(cmd->device),
2220 "WARM TARGET DEVICE RESET FAILED - "
2221 "waiting for commands.\n");
2222 return FAILED;
2223 }
2224
David C Somayajulu9d562912008-03-19 11:23:03 -07002225 /* Send marker. */
2226 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2227 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
2228 starget_printk(KERN_INFO, scsi_target(cmd->device),
2229 "WARM TARGET DEVICE RESET FAILED - "
2230 "marker iocb failed.\n");
2231 return FAILED;
2232 }
2233
Mike Christiece545032008-02-29 18:25:20 -06002234 starget_printk(KERN_INFO, scsi_target(cmd->device),
2235 "WARM TARGET RESET SUCCEEDED.\n");
2236 return SUCCESS;
2237}
2238
2239/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002240 * qla4xxx_eh_host_reset - kernel callback
2241 * @cmd: Pointer to Linux's SCSI command structure
2242 *
2243 * This routine is invoked by the Linux kernel to perform fatal error
2244 * recovery on the specified adapter.
2245 **/
2246static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2247{
2248 int return_status = FAILED;
2249 struct scsi_qla_host *ha;
2250
2251 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
2252
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302253 if (ql4xdontresethba) {
2254 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2255 ha->host_no, __func__));
2256 return FAILED;
2257 }
2258
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302259 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05002260 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002261 cmd->device->channel, cmd->device->id, cmd->device->lun);
2262
2263 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2264 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2265 "DEAD.\n", ha->host_no, cmd->device->channel,
2266 __func__));
2267
2268 return FAILED;
2269 }
2270
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302271 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2272 if (is_qla8022(ha))
2273 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2274 else
2275 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2276 }
Mike Christie50a29ae2008-03-04 13:26:53 -06002277
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302278 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002279 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002280
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302281 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002282 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002283
2284 return return_status;
2285}
2286
Lalit Chandivade2232be02010-07-30 14:38:47 +05302287/* PCI AER driver recovers from all correctable errors w/o
2288 * driver intervention. For uncorrectable errors PCI AER
2289 * driver calls the following device driver's callbacks
2290 *
2291 * - Fatal Errors - link_reset
2292 * - Non-Fatal Errors - driver's pci_error_detected() which
2293 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
2294 *
2295 * PCI AER driver calls
2296 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
2297 * returns RECOVERED or NEED_RESET if fw_hung
2298 * NEED_RESET - driver's slot_reset()
2299 * DISCONNECT - device is dead & cannot recover
2300 * RECOVERED - driver's pci_resume()
2301 */
2302static pci_ers_result_t
2303qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2304{
2305 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2306
2307 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
2308 ha->host_no, __func__, state);
2309
2310 if (!is_aer_supported(ha))
2311 return PCI_ERS_RESULT_NONE;
2312
2313 switch (state) {
2314 case pci_channel_io_normal:
2315 clear_bit(AF_EEH_BUSY, &ha->flags);
2316 return PCI_ERS_RESULT_CAN_RECOVER;
2317 case pci_channel_io_frozen:
2318 set_bit(AF_EEH_BUSY, &ha->flags);
2319 qla4xxx_mailbox_premature_completion(ha);
2320 qla4xxx_free_irqs(ha);
2321 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002322 /* Return back all IOs */
2323 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302324 return PCI_ERS_RESULT_NEED_RESET;
2325 case pci_channel_io_perm_failure:
2326 set_bit(AF_EEH_BUSY, &ha->flags);
2327 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
2328 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2329 return PCI_ERS_RESULT_DISCONNECT;
2330 }
2331 return PCI_ERS_RESULT_NEED_RESET;
2332}
2333
2334/**
2335 * qla4xxx_pci_mmio_enabled() gets called if
2336 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
2337 * and read/write to the device still works.
2338 **/
2339static pci_ers_result_t
2340qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
2341{
2342 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2343
2344 if (!is_aer_supported(ha))
2345 return PCI_ERS_RESULT_NONE;
2346
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002347 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302348}
2349
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002350static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05302351{
2352 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002353 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302354 int fn;
2355 struct pci_dev *other_pdev = NULL;
2356
2357 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
2358
2359 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2360
2361 if (test_bit(AF_ONLINE, &ha->flags)) {
2362 clear_bit(AF_ONLINE, &ha->flags);
2363 qla4xxx_mark_all_devices_missing(ha);
2364 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302365 }
2366
2367 fn = PCI_FUNC(ha->pdev->devfn);
2368 while (fn > 0) {
2369 fn--;
2370 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
2371 "func %x\n", ha->host_no, __func__, fn);
2372 /* Get the pci device given the domain, bus,
2373 * slot/function number */
2374 other_pdev =
2375 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2376 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2377 fn));
2378
2379 if (!other_pdev)
2380 continue;
2381
2382 if (atomic_read(&other_pdev->enable_cnt)) {
2383 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
2384 "func in enabled state%x\n", ha->host_no,
2385 __func__, fn);
2386 pci_dev_put(other_pdev);
2387 break;
2388 }
2389 pci_dev_put(other_pdev);
2390 }
2391
2392 /* The first function on the card, the reset owner will
2393 * start & initialize the firmware. The other functions
2394 * on the card will reset the firmware context
2395 */
2396 if (!fn) {
2397 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
2398 "0x%x is the owner\n", ha->host_no, __func__,
2399 ha->pdev->devfn);
2400
2401 qla4_8xxx_idc_lock(ha);
2402 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2403 QLA82XX_DEV_COLD);
2404
2405 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
2406 QLA82XX_IDC_VERSION);
2407
2408 qla4_8xxx_idc_unlock(ha);
2409 clear_bit(AF_FW_RECOVERY, &ha->flags);
2410 rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
2411 qla4_8xxx_idc_lock(ha);
2412
2413 if (rval != QLA_SUCCESS) {
2414 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2415 "FAILED\n", ha->host_no, __func__);
2416 qla4_8xxx_clear_drv_active(ha);
2417 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2418 QLA82XX_DEV_FAILED);
2419 } else {
2420 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2421 "READY\n", ha->host_no, __func__);
2422 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2423 QLA82XX_DEV_READY);
2424 /* Clear driver state register */
2425 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
2426 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002427 ret = qla4xxx_request_irqs(ha);
2428 if (ret) {
2429 ql4_printk(KERN_WARNING, ha, "Failed to "
2430 "reserve interrupt %d already in use.\n",
2431 ha->pdev->irq);
2432 rval = QLA_ERROR;
2433 } else {
2434 ha->isp_ops->enable_intrs(ha);
2435 rval = QLA_SUCCESS;
2436 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302437 }
2438 qla4_8xxx_idc_unlock(ha);
2439 } else {
2440 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
2441 "the reset owner\n", ha->host_no, __func__,
2442 ha->pdev->devfn);
2443 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
2444 QLA82XX_DEV_READY)) {
2445 clear_bit(AF_FW_RECOVERY, &ha->flags);
2446 rval = qla4xxx_initialize_adapter(ha,
2447 PRESERVE_DDB_LIST);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002448 if (rval == QLA_SUCCESS) {
2449 ret = qla4xxx_request_irqs(ha);
2450 if (ret) {
2451 ql4_printk(KERN_WARNING, ha, "Failed to"
2452 " reserve interrupt %d already in"
2453 " use.\n", ha->pdev->irq);
2454 rval = QLA_ERROR;
2455 } else {
2456 ha->isp_ops->enable_intrs(ha);
2457 rval = QLA_SUCCESS;
2458 }
2459 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302460 qla4_8xxx_idc_lock(ha);
2461 qla4_8xxx_set_drv_active(ha);
2462 qla4_8xxx_idc_unlock(ha);
2463 }
2464 }
2465 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2466 return rval;
2467}
2468
2469static pci_ers_result_t
2470qla4xxx_pci_slot_reset(struct pci_dev *pdev)
2471{
2472 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2473 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2474 int rc;
2475
2476 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
2477 ha->host_no, __func__);
2478
2479 if (!is_aer_supported(ha))
2480 return PCI_ERS_RESULT_NONE;
2481
2482 /* Restore the saved state of PCIe device -
2483 * BAR registers, PCI Config space, PCIX, MSI,
2484 * IOV states
2485 */
2486 pci_restore_state(pdev);
2487
2488 /* pci_restore_state() clears the saved_state flag of the device
2489 * save restored state which resets saved_state flag
2490 */
2491 pci_save_state(pdev);
2492
2493 /* Initialize device or resume if in suspended state */
2494 rc = pci_enable_device(pdev);
2495 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002496 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05302497 "device after reset\n", ha->host_no, __func__);
2498 goto exit_slot_reset;
2499 }
2500
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002501 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302502
2503 if (is_qla8022(ha)) {
2504 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
2505 ret = PCI_ERS_RESULT_RECOVERED;
2506 goto exit_slot_reset;
2507 } else
2508 goto exit_slot_reset;
2509 }
2510
2511exit_slot_reset:
2512 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
2513 "device after reset\n", ha->host_no, __func__, ret);
2514 return ret;
2515}
2516
2517static void
2518qla4xxx_pci_resume(struct pci_dev *pdev)
2519{
2520 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2521 int ret;
2522
2523 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
2524 ha->host_no, __func__);
2525
2526 ret = qla4xxx_wait_for_hba_online(ha);
2527 if (ret != QLA_SUCCESS) {
2528 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
2529 "resume I/O from slot/link_reset\n", ha->host_no,
2530 __func__);
2531 }
2532
2533 pci_cleanup_aer_uncorrect_error_status(pdev);
2534 clear_bit(AF_EEH_BUSY, &ha->flags);
2535}
2536
2537static struct pci_error_handlers qla4xxx_err_handler = {
2538 .error_detected = qla4xxx_pci_error_detected,
2539 .mmio_enabled = qla4xxx_pci_mmio_enabled,
2540 .slot_reset = qla4xxx_pci_slot_reset,
2541 .resume = qla4xxx_pci_resume,
2542};
2543
David Somayajuluafaf5a22006-09-19 10:28:00 -07002544static struct pci_device_id qla4xxx_pci_tbl[] = {
2545 {
2546 .vendor = PCI_VENDOR_ID_QLOGIC,
2547 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
2548 .subvendor = PCI_ANY_ID,
2549 .subdevice = PCI_ANY_ID,
2550 },
2551 {
2552 .vendor = PCI_VENDOR_ID_QLOGIC,
2553 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
2554 .subvendor = PCI_ANY_ID,
2555 .subdevice = PCI_ANY_ID,
2556 },
David C Somayajulud9150582006-11-15 17:38:40 -08002557 {
2558 .vendor = PCI_VENDOR_ID_QLOGIC,
2559 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
2560 .subvendor = PCI_ANY_ID,
2561 .subdevice = PCI_ANY_ID,
2562 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302563 {
2564 .vendor = PCI_VENDOR_ID_QLOGIC,
2565 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
2566 .subvendor = PCI_ANY_ID,
2567 .subdevice = PCI_ANY_ID,
2568 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07002569 {0, 0},
2570};
2571MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
2572
Adrian Bunk47975472007-04-26 00:35:16 -07002573static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002574 .name = DRIVER_NAME,
2575 .id_table = qla4xxx_pci_tbl,
2576 .probe = qla4xxx_probe_adapter,
2577 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05302578 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002579};
2580
2581static int __init qla4xxx_module_init(void)
2582{
2583 int ret;
2584
2585 /* Allocate cache for SRBs. */
2586 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09002587 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002588 if (srb_cachep == NULL) {
2589 printk(KERN_ERR
2590 "%s: Unable to allocate SRB cache..."
2591 "Failing load!\n", DRIVER_NAME);
2592 ret = -ENOMEM;
2593 goto no_srp_cache;
2594 }
2595
2596 /* Derive version string. */
2597 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002598 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002599 strcat(qla4xxx_version_str, "-debug");
2600
2601 qla4xxx_scsi_transport =
2602 iscsi_register_transport(&qla4xxx_iscsi_transport);
2603 if (!qla4xxx_scsi_transport){
2604 ret = -ENODEV;
2605 goto release_srb_cache;
2606 }
2607
David Somayajuluafaf5a22006-09-19 10:28:00 -07002608 ret = pci_register_driver(&qla4xxx_pci_driver);
2609 if (ret)
2610 goto unregister_transport;
2611
2612 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
2613 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05002614
David Somayajuluafaf5a22006-09-19 10:28:00 -07002615unregister_transport:
2616 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2617release_srb_cache:
2618 kmem_cache_destroy(srb_cachep);
2619no_srp_cache:
2620 return ret;
2621}
2622
2623static void __exit qla4xxx_module_exit(void)
2624{
David Somayajuluafaf5a22006-09-19 10:28:00 -07002625 pci_unregister_driver(&qla4xxx_pci_driver);
2626 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
2627 kmem_cache_destroy(srb_cachep);
2628}
2629
2630module_init(qla4xxx_module_init);
2631module_exit(qla4xxx_module_exit);
2632
2633MODULE_AUTHOR("QLogic Corporation");
2634MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
2635MODULE_LICENSE("GPL");
2636MODULE_VERSION(QLA4XXX_DRIVER_VERSION);