blob: a9da3152ee5146162ac7c684f021828cd575b81d [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);
Mike Christied00efe32011-07-25 13:48:38 -050083static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
84 int count);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -050085static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
86 enum iscsi_param_type param_type,
87 int param, char *buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -070088static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
Mike Christie5c656af2009-07-15 15:02:59 -050089static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
David Somayajuluafaf5a22006-09-19 10:28:00 -070090
91/*
92 * SCSI host template entry points
93 */
Jeff Garzikf2812332010-11-16 02:10:29 -050094static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +053095static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070096static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -060097static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -070098static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
99static int qla4xxx_slave_alloc(struct scsi_device *device);
100static int qla4xxx_slave_configure(struct scsi_device *device);
101static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie024f8012008-03-04 13:26:54 -0600102static void qla4xxx_scan_start(struct Scsi_Host *shost);
Mike Christie3128c6c2011-07-25 13:48:42 -0500103static mode_t ql4_attr_is_visible(int param_type, int param);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700104
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530105static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
106 QLA82XX_LEGACY_INTR_CONFIG;
107
David Somayajuluafaf5a22006-09-19 10:28:00 -0700108static struct scsi_host_template qla4xxx_driver_template = {
109 .module = THIS_MODULE,
110 .name = DRIVER_NAME,
111 .proc_name = DRIVER_NAME,
112 .queuecommand = qla4xxx_queuecommand,
113
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530114 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700115 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600116 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700117 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500118 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700119
120 .slave_configure = qla4xxx_slave_configure,
121 .slave_alloc = qla4xxx_slave_alloc,
122 .slave_destroy = qla4xxx_slave_destroy,
123
Mike Christie921601b2008-01-31 13:36:49 -0600124 .scan_finished = iscsi_scan_finished,
Mike Christie024f8012008-03-04 13:26:54 -0600125 .scan_start = qla4xxx_scan_start,
Mike Christie921601b2008-01-31 13:36:49 -0600126
David Somayajuluafaf5a22006-09-19 10:28:00 -0700127 .this_id = -1,
128 .cmd_per_lun = 3,
129 .use_clustering = ENABLE_CLUSTERING,
130 .sg_tablesize = SG_ALL,
131
132 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700133 .shost_attrs = qla4xxx_host_attrs,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700134};
135
136static struct iscsi_transport qla4xxx_iscsi_transport = {
137 .owner = THIS_MODULE,
138 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500139 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
140 CAP_DATA_PATH_OFFLOAD,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700141 .tgt_dscvr = qla4xxx_tgt_dscvr,
Mike Christie3128c6c2011-07-25 13:48:42 -0500142 .attr_is_visible = ql4_attr_is_visible,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700143 .get_conn_param = qla4xxx_conn_get_param,
144 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500145 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500146 .set_iface_param = qla4xxx_iface_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700147 .session_recovery_timedout = qla4xxx_recovery_timedout,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500148 .get_iface_param = qla4xxx_get_iface_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700149};
150
151static struct scsi_transport_template *qla4xxx_scsi_transport;
152
Mike Christie3128c6c2011-07-25 13:48:42 -0500153static mode_t ql4_attr_is_visible(int param_type, int param)
154{
155 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500156 case ISCSI_HOST_PARAM:
157 switch (param) {
158 case ISCSI_HOST_PARAM_HWADDRESS:
159 case ISCSI_HOST_PARAM_IPADDRESS:
160 case ISCSI_HOST_PARAM_INITIATOR_NAME:
161 return S_IRUGO;
162 default:
163 return 0;
164 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500165 case ISCSI_PARAM:
166 switch (param) {
167 case ISCSI_PARAM_CONN_ADDRESS:
168 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500169 case ISCSI_PARAM_TARGET_NAME:
170 case ISCSI_PARAM_TPGT:
171 case ISCSI_PARAM_TARGET_ALIAS:
Mike Christie3128c6c2011-07-25 13:48:42 -0500172 return S_IRUGO;
173 default:
174 return 0;
175 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500176 case ISCSI_NET_PARAM:
177 switch (param) {
178 case ISCSI_NET_PARAM_IPV4_ADDR:
179 case ISCSI_NET_PARAM_IPV4_SUBNET:
180 case ISCSI_NET_PARAM_IPV4_GW:
181 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
182 case ISCSI_NET_PARAM_IFACE_ENABLE:
183 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
184 case ISCSI_NET_PARAM_IPV6_ADDR:
185 case ISCSI_NET_PARAM_IPV6_ROUTER:
186 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
187 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
188 return S_IRUGO;
189 default:
190 return 0;
191 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500192 }
193
194 return 0;
195}
196
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500197static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
198 enum iscsi_param_type param_type,
199 int param, char *buf)
200{
201 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
202 struct scsi_qla_host *ha = to_qla_host(shost);
203 int len = -ENOSYS;
204
205 if (param_type != ISCSI_NET_PARAM)
206 return -ENOSYS;
207
208 switch (param) {
209 case ISCSI_NET_PARAM_IPV4_ADDR:
210 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
211 break;
212 case ISCSI_NET_PARAM_IPV4_SUBNET:
213 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
214 break;
215 case ISCSI_NET_PARAM_IPV4_GW:
216 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
217 break;
218 case ISCSI_NET_PARAM_IFACE_ENABLE:
219 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
220 len = sprintf(buf, "%s\n",
221 (ha->ip_config.ipv4_options &
222 IPOPT_IPV4_PROTOCOL_ENABLE) ?
223 "enabled" : "disabled");
224 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
225 len = sprintf(buf, "%s\n",
226 (ha->ip_config.ipv6_options &
227 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
228 "enabled" : "disabled");
229 break;
230 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
231 len = sprintf(buf, "%s\n",
232 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
233 "dhcp" : "static");
234 break;
235 case ISCSI_NET_PARAM_IPV6_ADDR:
236 if (iface->iface_num == 0)
237 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
238 if (iface->iface_num == 1)
239 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
240 break;
241 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
242 len = sprintf(buf, "%pI6\n",
243 &ha->ip_config.ipv6_link_local_addr);
244 break;
245 case ISCSI_NET_PARAM_IPV6_ROUTER:
246 len = sprintf(buf, "%pI6\n",
247 &ha->ip_config.ipv6_default_router_addr);
248 break;
249 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
250 len = sprintf(buf, "%s\n",
251 (ha->ip_config.ipv6_addl_options &
252 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
253 "nd" : "static");
254 break;
255 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
256 len = sprintf(buf, "%s\n",
257 (ha->ip_config.ipv6_addl_options &
258 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
259 "auto" : "static");
260 break;
261 default:
262 len = -ENOSYS;
263 }
264
265 return len;
266}
267
Mike Christie5c656af2009-07-15 15:02:59 -0500268static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
269{
270 struct iscsi_cls_session *session;
271 struct ddb_entry *ddb_entry;
272
273 session = starget_to_session(scsi_target(sc->device));
274 ddb_entry = session->dd_data;
275
276 /* if we are not logged in then the LLD is going to clean up the cmd */
277 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
278 return BLK_EH_RESET_TIMER;
279 else
280 return BLK_EH_NOT_HANDLED;
281}
282
David Somayajuluafaf5a22006-09-19 10:28:00 -0700283static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
284{
285 struct ddb_entry *ddb_entry = session->dd_data;
286 struct scsi_qla_host *ha = ddb_entry->ha;
287
Mike Christie568d3032008-01-31 13:36:47 -0600288 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
289 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700290
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530291 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
Mike Christie568d3032008-01-31 13:36:47 -0600292 "of (%d) secs exhausted, marking device DEAD.\n",
293 ha->host_no, __func__, ddb_entry->fw_ddb_index,
Vikas Chaudhary30387272011-03-21 03:34:32 -0700294 ddb_entry->sess->recovery_tmo));
Mike Christie568d3032008-01-31 13:36:47 -0600295 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700296}
297
Mike Christieaa1e93a2007-05-30 12:57:09 -0500298static int qla4xxx_host_get_param(struct Scsi_Host *shost,
299 enum iscsi_host_param param, char *buf)
300{
301 struct scsi_qla_host *ha = to_qla_host(shost);
302 int len;
303
304 switch (param) {
305 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800306 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500307 break;
Mike Christie22236962007-05-30 12:57:24 -0500308 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500309 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -0500310 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500311 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500312 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500313 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500314 default:
315 return -ENOSYS;
316 }
317
318 return len;
319}
320
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500321static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
322{
323 if (ha->iface_ipv4)
324 return;
325
326 /* IPv4 */
327 ha->iface_ipv4 = iscsi_create_iface(ha->host,
328 &qla4xxx_iscsi_transport,
329 ISCSI_IFACE_TYPE_IPV4, 0, 0);
330 if (!ha->iface_ipv4)
331 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
332 "iface0.\n");
333}
334
335static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
336{
337 if (!ha->iface_ipv6_0)
338 /* IPv6 iface-0 */
339 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
340 &qla4xxx_iscsi_transport,
341 ISCSI_IFACE_TYPE_IPV6, 0,
342 0);
343 if (!ha->iface_ipv6_0)
344 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
345 "iface0.\n");
346
347 if (!ha->iface_ipv6_1)
348 /* IPv6 iface-1 */
349 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
350 &qla4xxx_iscsi_transport,
351 ISCSI_IFACE_TYPE_IPV6, 1,
352 0);
353 if (!ha->iface_ipv6_1)
354 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
355 "iface1.\n");
356}
357
358static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
359{
360 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
361 qla4xxx_create_ipv4_iface(ha);
362
363 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
364 qla4xxx_create_ipv6_iface(ha);
365}
366
367static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
368{
369 if (ha->iface_ipv4) {
370 iscsi_destroy_iface(ha->iface_ipv4);
371 ha->iface_ipv4 = NULL;
372 }
373}
374
375static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
376{
377 if (ha->iface_ipv6_0) {
378 iscsi_destroy_iface(ha->iface_ipv6_0);
379 ha->iface_ipv6_0 = NULL;
380 }
381 if (ha->iface_ipv6_1) {
382 iscsi_destroy_iface(ha->iface_ipv6_1);
383 ha->iface_ipv6_1 = NULL;
384 }
385}
386
387static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
388{
389 qla4xxx_destroy_ipv4_iface(ha);
390 qla4xxx_destroy_ipv6_iface(ha);
391}
392
Mike Christied00efe32011-07-25 13:48:38 -0500393static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
394 struct iscsi_iface_param_info *iface_param,
395 struct addr_ctrl_blk *init_fw_cb)
396{
397 /*
398 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
399 * iface_num 1 is valid only for IPv6 Addr.
400 */
401 switch (iface_param->param) {
402 case ISCSI_NET_PARAM_IPV6_ADDR:
403 if (iface_param->iface_num & 0x1)
404 /* IPv6 Addr 1 */
405 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
406 sizeof(init_fw_cb->ipv6_addr1));
407 else
408 /* IPv6 Addr 0 */
409 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
410 sizeof(init_fw_cb->ipv6_addr0));
411 break;
412 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
413 if (iface_param->iface_num & 0x1)
414 break;
415 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
416 sizeof(init_fw_cb->ipv6_if_id));
417 break;
418 case ISCSI_NET_PARAM_IPV6_ROUTER:
419 if (iface_param->iface_num & 0x1)
420 break;
421 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
422 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
423 break;
424 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
425 /* Autocfg applies to even interface */
426 if (iface_param->iface_num & 0x1)
427 break;
428
429 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
430 init_fw_cb->ipv6_addtl_opts &=
431 cpu_to_le16(
432 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
433 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
434 init_fw_cb->ipv6_addtl_opts |=
435 cpu_to_le16(
436 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
437 else
438 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
439 "IPv6 addr\n");
440 break;
441 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
442 /* Autocfg applies to even interface */
443 if (iface_param->iface_num & 0x1)
444 break;
445
446 if (iface_param->value[0] ==
447 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
448 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
449 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
450 else if (iface_param->value[0] ==
451 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
452 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
453 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
454 else
455 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
456 "IPv6 linklocal addr\n");
457 break;
458 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
459 /* Autocfg applies to even interface */
460 if (iface_param->iface_num & 0x1)
461 break;
462
463 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
464 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
465 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
466 break;
467 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500468 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500469 init_fw_cb->ipv6_opts |=
470 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500471 qla4xxx_create_ipv6_iface(ha);
472 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500473 init_fw_cb->ipv6_opts &=
474 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
475 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500476 qla4xxx_destroy_ipv6_iface(ha);
477 }
Mike Christied00efe32011-07-25 13:48:38 -0500478 break;
479 case ISCSI_NET_PARAM_VLAN_ID:
480 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
481 break;
482 init_fw_cb->ipv6_vlan_tag = *(uint16_t *)iface_param->value;
483 break;
484 default:
485 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
486 iface_param->param);
487 break;
488 }
489}
490
491static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
492 struct iscsi_iface_param_info *iface_param,
493 struct addr_ctrl_blk *init_fw_cb)
494{
495 switch (iface_param->param) {
496 case ISCSI_NET_PARAM_IPV4_ADDR:
497 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
498 sizeof(init_fw_cb->ipv4_addr));
499 break;
500 case ISCSI_NET_PARAM_IPV4_SUBNET:
501 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
502 sizeof(init_fw_cb->ipv4_subnet));
503 break;
504 case ISCSI_NET_PARAM_IPV4_GW:
505 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
506 sizeof(init_fw_cb->ipv4_gw_addr));
507 break;
508 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
509 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
510 init_fw_cb->ipv4_tcp_opts |=
511 cpu_to_le16(TCPOPT_DHCP_ENABLE);
512 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
513 init_fw_cb->ipv4_tcp_opts &=
514 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
515 else
516 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
517 break;
518 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500519 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500520 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500521 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500522 qla4xxx_create_ipv4_iface(ha);
523 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500524 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500525 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -0500526 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500527 qla4xxx_destroy_ipv4_iface(ha);
528 }
Mike Christied00efe32011-07-25 13:48:38 -0500529 break;
530 case ISCSI_NET_PARAM_VLAN_ID:
531 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
532 break;
533 init_fw_cb->ipv4_vlan_tag = *(uint16_t *)iface_param->value;
534 break;
535 default:
536 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
537 iface_param->param);
538 break;
539 }
540}
541
542static void
543qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
544{
545 struct addr_ctrl_blk_def *acb;
546 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
547 memset(acb->reserved1, 0, sizeof(acb->reserved1));
548 memset(acb->reserved2, 0, sizeof(acb->reserved2));
549 memset(acb->reserved3, 0, sizeof(acb->reserved3));
550 memset(acb->reserved4, 0, sizeof(acb->reserved4));
551 memset(acb->reserved5, 0, sizeof(acb->reserved5));
552 memset(acb->reserved6, 0, sizeof(acb->reserved6));
553 memset(acb->reserved7, 0, sizeof(acb->reserved7));
554 memset(acb->reserved8, 0, sizeof(acb->reserved8));
555 memset(acb->reserved9, 0, sizeof(acb->reserved9));
556 memset(acb->reserved10, 0, sizeof(acb->reserved10));
557 memset(acb->reserved11, 0, sizeof(acb->reserved11));
558 memset(acb->reserved12, 0, sizeof(acb->reserved12));
559 memset(acb->reserved13, 0, sizeof(acb->reserved13));
560 memset(acb->reserved14, 0, sizeof(acb->reserved14));
561 memset(acb->reserved15, 0, sizeof(acb->reserved15));
562}
563
564static int
565qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
566{
567 struct scsi_qla_host *ha = to_qla_host(shost);
568 int rval = 0;
569 struct iscsi_iface_param_info *iface_param = NULL;
570 struct addr_ctrl_blk *init_fw_cb = NULL;
571 dma_addr_t init_fw_cb_dma;
572 uint32_t mbox_cmd[MBOX_REG_COUNT];
573 uint32_t mbox_sts[MBOX_REG_COUNT];
574 uint32_t total_param_count;
575 uint32_t length;
576
577 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
578 sizeof(struct addr_ctrl_blk),
579 &init_fw_cb_dma, GFP_KERNEL);
580 if (!init_fw_cb) {
581 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
582 __func__);
583 return -ENOMEM;
584 }
585
586 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
587 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
588 memset(&mbox_sts, 0, sizeof(mbox_sts));
589
590 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
591 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
592 rval = -EIO;
593 goto exit_init_fw_cb;
594 }
595
596 total_param_count = count;
597 iface_param = (struct iscsi_iface_param_info *)data;
598
599 for ( ; total_param_count != 0; total_param_count--) {
600 length = iface_param->len;
601
602 if (iface_param->param_type != ISCSI_NET_PARAM)
603 continue;
604
605 switch (iface_param->iface_type) {
606 case ISCSI_IFACE_TYPE_IPV4:
607 switch (iface_param->iface_num) {
608 case 0:
609 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
610 break;
611 default:
612 /* Cannot have more than one IPv4 interface */
613 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
614 "number = %d\n",
615 iface_param->iface_num);
616 break;
617 }
618 break;
619 case ISCSI_IFACE_TYPE_IPV6:
620 switch (iface_param->iface_num) {
621 case 0:
622 case 1:
623 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
624 break;
625 default:
626 /* Cannot have more than two IPv6 interface */
627 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
628 "number = %d\n",
629 iface_param->iface_num);
630 break;
631 }
632 break;
633 default:
634 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
635 break;
636 }
637
638 iface_param = (struct iscsi_iface_param_info *)
639 ((uint8_t *)iface_param +
640 sizeof(struct iscsi_iface_param_info) + length);
641 }
642
643 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
644
645 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
646 sizeof(struct addr_ctrl_blk),
647 FLASH_OPT_RMW_COMMIT);
648 if (rval != QLA_SUCCESS) {
649 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
650 __func__);
651 rval = -EIO;
652 goto exit_init_fw_cb;
653 }
654
655 qla4xxx_disable_acb(ha);
656
657 qla4xxx_initcb_to_acb(init_fw_cb);
658
659 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
660 if (rval != QLA_SUCCESS) {
661 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
662 __func__);
663 rval = -EIO;
664 goto exit_init_fw_cb;
665 }
666
667 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
668 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
669 init_fw_cb_dma);
670
671exit_init_fw_cb:
672 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
673 init_fw_cb, init_fw_cb_dma);
674
675 return rval;
676}
677
David Somayajuluafaf5a22006-09-19 10:28:00 -0700678static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
679 enum iscsi_param param, char *buf)
680{
681 struct ddb_entry *ddb_entry = sess->dd_data;
682 int len;
683
684 switch (param) {
685 case ISCSI_PARAM_TARGET_NAME:
686 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
687 ddb_entry->iscsi_name);
688 break;
689 case ISCSI_PARAM_TPGT:
690 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
691 break;
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530692 case ISCSI_PARAM_TARGET_ALIAS:
693 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
694 ddb_entry->iscsi_alias);
695 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700696 default:
697 return -ENOSYS;
698 }
699
700 return len;
701}
702
703static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
704 enum iscsi_param param, char *buf)
705{
706 struct iscsi_cls_session *session;
707 struct ddb_entry *ddb_entry;
708 int len;
709
710 session = iscsi_dev_to_session(conn->dev.parent);
711 ddb_entry = session->dd_data;
712
713 switch (param) {
714 case ISCSI_PARAM_CONN_PORT:
715 len = sprintf(buf, "%hu\n", ddb_entry->port);
716 break;
717 case ISCSI_PARAM_CONN_ADDRESS:
718 /* TODO: what are the ipv6 bits */
Harvey Harrison63779432008-10-31 00:56:00 -0700719 len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700720 break;
721 default:
722 return -ENOSYS;
723 }
724
725 return len;
726}
727
Mike Christie2174a042007-05-30 12:57:10 -0500728static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
729 enum iscsi_tgt_dscvr type, uint32_t enable,
730 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700731{
732 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700733 struct sockaddr_in *addr;
734 struct sockaddr_in6 *addr6;
735 int ret = 0;
736
David Somayajuluafaf5a22006-09-19 10:28:00 -0700737 ha = (struct scsi_qla_host *) shost->hostdata;
738
739 switch (type) {
740 case ISCSI_TGT_DSCVR_SEND_TARGETS:
741 if (dst_addr->sa_family == AF_INET) {
742 addr = (struct sockaddr_in *)dst_addr;
743 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
744 addr->sin_port) != QLA_SUCCESS)
745 ret = -EIO;
746 } else if (dst_addr->sa_family == AF_INET6) {
747 /*
748 * TODO: fix qla4xxx_send_tgts
749 */
750 addr6 = (struct sockaddr_in6 *)dst_addr;
751 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
752 addr6->sin6_port) != QLA_SUCCESS)
753 ret = -EIO;
754 } else
755 ret = -ENOSYS;
756 break;
757 default:
758 ret = -ENOSYS;
759 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700760 return ret;
761}
762
763void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
764{
765 if (!ddb_entry->sess)
766 return;
767
768 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600769 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700770 iscsi_remove_session(ddb_entry->sess);
771 }
772 iscsi_free_session(ddb_entry->sess);
773}
774
775int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
776{
777 int err;
778
Vikas Chaudhary30387272011-03-21 03:34:32 -0700779 ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530780
David Somayajuluafaf5a22006-09-19 10:28:00 -0700781 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
782 if (err) {
783 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
784 return err;
785 }
786
Mike Christie5d91e202008-05-21 15:54:01 -0500787 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700788 if (!ddb_entry->conn) {
789 iscsi_remove_session(ddb_entry->sess);
790 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
791 return -ENOMEM;
792 }
Mike Christieb6359302008-01-31 13:36:44 -0600793
794 /* finally ready to go */
795 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700796 return 0;
797}
798
799struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
800{
801 struct ddb_entry *ddb_entry;
802 struct iscsi_cls_session *sess;
803
Mike Christie5d91e202008-05-21 15:54:01 -0500804 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
805 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700806 if (!sess)
807 return NULL;
808
809 ddb_entry = sess->dd_data;
810 memset(ddb_entry, 0, sizeof(*ddb_entry));
811 ddb_entry->ha = ha;
812 ddb_entry->sess = sess;
813 return ddb_entry;
814}
815
Mike Christie024f8012008-03-04 13:26:54 -0600816static void qla4xxx_scan_start(struct Scsi_Host *shost)
817{
818 struct scsi_qla_host *ha = shost_priv(shost);
819 struct ddb_entry *ddb_entry, *ddbtemp;
820
821 /* finish setup of sessions that were already setup in firmware */
822 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
823 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
824 qla4xxx_add_sess(ddb_entry);
825 }
826}
827
David Somayajuluafaf5a22006-09-19 10:28:00 -0700828/*
829 * Timer routines
830 */
831
832static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
833 unsigned long interval)
834{
835 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
836 __func__, ha->host->host_no));
837 init_timer(&ha->timer);
838 ha->timer.expires = jiffies + interval * HZ;
839 ha->timer.data = (unsigned long)ha;
840 ha->timer.function = (void (*)(unsigned long))func;
841 add_timer(&ha->timer);
842 ha->timer_active = 1;
843}
844
845static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
846{
847 del_timer_sync(&ha->timer);
848 ha->timer_active = 0;
849}
850
851/***
852 * qla4xxx_mark_device_missing - mark a device as missing.
853 * @ha: Pointer to host adapter structure.
854 * @ddb_entry: Pointer to device database entry
855 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530856 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700857 **/
858void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
859 struct ddb_entry *ddb_entry)
860{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530861 if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
862 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
863 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
864 ha->host_no, ddb_entry->fw_ddb_index));
865 } else
866 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
867 ddb_entry->fw_ddb_index))
868
Mike Christieb6359302008-01-31 13:36:44 -0600869 iscsi_block_session(ddb_entry->sess);
Mike Christiee5bd7b52008-09-24 11:46:10 -0500870 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700871}
872
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530873/**
874 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
875 * @ha: Pointer to host adapter structure.
876 *
877 * This routine marks a device missing and resets the relogin retry count.
878 **/
879void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
880{
881 struct ddb_entry *ddb_entry, *ddbtemp;
882 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
883 qla4xxx_mark_device_missing(ha, ddb_entry);
884 }
885}
886
David Somayajuluafaf5a22006-09-19 10:28:00 -0700887static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
888 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700889 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700890{
891 struct srb *srb;
892
893 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
894 if (!srb)
895 return srb;
896
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530897 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700898 srb->ha = ha;
899 srb->ddb = ddb_entry;
900 srb->cmd = cmd;
901 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +0530902 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700903
904 return srb;
905}
906
907static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
908{
909 struct scsi_cmnd *cmd = srb->cmd;
910
911 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900912 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700913 srb->flags &= ~SRB_DMA_VALID;
914 }
Vikas Chaudhary53698872010-04-28 11:41:59 +0530915 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700916}
917
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530918void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700919{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530920 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700921 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530922 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700923
924 qla4xxx_srb_free_dma(ha, srb);
925
926 mempool_free(srb, ha->srb_mempool);
927
928 cmd->scsi_done(cmd);
929}
930
931/**
932 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700933 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -0700934 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700935 *
936 * Remarks:
937 * This routine is invoked by Linux to send a SCSI command to the driver.
938 * The mid-level driver tries to ensure that queuecommand never gets
939 * invoked concurrently with itself or the interrupt handler (although
940 * the interrupt handler may call this routine as part of request-
941 * completion handling). Unfortunely, it sometimes calls the scheduler
942 * in interrupt context which is a big NO! NO!.
943 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700944static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700945{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700946 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700947 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -0600948 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700949 struct srb *srb;
950 int rval;
951
Lalit Chandivade2232be02010-07-30 14:38:47 +0530952 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
953 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
954 cmd->result = DID_NO_CONNECT << 16;
955 else
956 cmd->result = DID_REQUEUE << 16;
957 goto qc_fail_command;
958 }
959
Mike Christie7fb19212008-01-31 13:36:45 -0600960 if (!sess) {
961 cmd->result = DID_IMM_RETRY << 16;
962 goto qc_fail_command;
963 }
964
965 rval = iscsi_session_chkready(sess);
966 if (rval) {
967 cmd->result = rval;
968 goto qc_fail_command;
969 }
970
David Somayajuluafaf5a22006-09-19 10:28:00 -0700971 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
972 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
973 cmd->result = DID_NO_CONNECT << 16;
974 goto qc_fail_command;
975 }
Mike Christiec5e98e92008-08-17 15:24:39 -0500976 return SCSI_MLQUEUE_TARGET_BUSY;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700977 }
978
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530979 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
980 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
981 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
982 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
983 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
984 !test_bit(AF_ONLINE, &ha->flags) ||
985 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -0800986 goto qc_host_busy;
987
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700988 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700989 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700990 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700991
992 rval = qla4xxx_send_command_to_isp(ha, srb);
993 if (rval != QLA_SUCCESS)
994 goto qc_host_busy_free_sp;
995
David Somayajuluafaf5a22006-09-19 10:28:00 -0700996 return 0;
997
998qc_host_busy_free_sp:
999 qla4xxx_srb_free_dma(ha, srb);
1000 mempool_free(srb, ha->srb_mempool);
1001
David Somayajuluafaf5a22006-09-19 10:28:00 -07001002qc_host_busy:
1003 return SCSI_MLQUEUE_HOST_BUSY;
1004
1005qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001006 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001007
1008 return 0;
1009}
1010
1011/**
1012 * qla4xxx_mem_free - frees memory allocated to adapter
1013 * @ha: Pointer to host adapter structure.
1014 *
1015 * Frees memory previously allocated by qla4xxx_mem_alloc
1016 **/
1017static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1018{
1019 if (ha->queues)
1020 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1021 ha->queues_dma);
1022
1023 ha->queues_len = 0;
1024 ha->queues = NULL;
1025 ha->queues_dma = 0;
1026 ha->request_ring = NULL;
1027 ha->request_dma = 0;
1028 ha->response_ring = NULL;
1029 ha->response_dma = 0;
1030 ha->shadow_regs = NULL;
1031 ha->shadow_regs_dma = 0;
1032
1033 /* Free srb pool. */
1034 if (ha->srb_mempool)
1035 mempool_destroy(ha->srb_mempool);
1036
1037 ha->srb_mempool = NULL;
1038
1039 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301040 if (is_qla8022(ha)) {
1041 if (ha->nx_pcibase)
1042 iounmap(
1043 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301044 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001045 iounmap(ha->reg);
1046 pci_release_regions(ha->pdev);
1047}
1048
1049/**
1050 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1051 * @ha: Pointer to host adapter structure
1052 *
1053 * Allocates DMA memory for request and response queues. Also allocates memory
1054 * for srbs.
1055 **/
1056static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1057{
1058 unsigned long align;
1059
1060 /* Allocate contiguous block of DMA memory for queues. */
1061 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1062 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1063 sizeof(struct shadow_regs) +
1064 MEM_ALIGN_VALUE +
1065 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1066 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1067 &ha->queues_dma, GFP_KERNEL);
1068 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301069 ql4_printk(KERN_WARNING, ha,
1070 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001071
1072 goto mem_alloc_error_exit;
1073 }
1074 memset(ha->queues, 0, ha->queues_len);
1075
1076 /*
1077 * As per RISC alignment requirements -- the bus-address must be a
1078 * multiple of the request-ring size (in bytes).
1079 */
1080 align = 0;
1081 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1082 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1083 (MEM_ALIGN_VALUE - 1));
1084
1085 /* Update request and response queue pointers. */
1086 ha->request_dma = ha->queues_dma + align;
1087 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1088 ha->response_dma = ha->queues_dma + align +
1089 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1090 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1091 (REQUEST_QUEUE_DEPTH *
1092 QUEUE_SIZE));
1093 ha->shadow_regs_dma = ha->queues_dma + align +
1094 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1095 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1096 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1097 (REQUEST_QUEUE_DEPTH *
1098 QUEUE_SIZE) +
1099 (RESPONSE_QUEUE_DEPTH *
1100 QUEUE_SIZE));
1101
1102 /* Allocate memory for srb pool. */
1103 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1104 mempool_free_slab, srb_cachep);
1105 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301106 ql4_printk(KERN_WARNING, ha,
1107 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001108
1109 goto mem_alloc_error_exit;
1110 }
1111
1112 return QLA_SUCCESS;
1113
1114mem_alloc_error_exit:
1115 qla4xxx_mem_free(ha);
1116 return QLA_ERROR;
1117}
1118
1119/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301120 * qla4_8xxx_check_fw_alive - Check firmware health
1121 * @ha: Pointer to host adapter structure.
1122 *
1123 * Context: Interrupt
1124 **/
1125static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
1126{
1127 uint32_t fw_heartbeat_counter, halt_status;
1128
1129 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05301130 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1131 if (fw_heartbeat_counter == 0xffffffff) {
1132 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
1133 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1134 ha->host_no, __func__));
1135 return;
1136 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301137
1138 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
1139 ha->seconds_since_last_heartbeat++;
1140 /* FW not alive after 2 seconds */
1141 if (ha->seconds_since_last_heartbeat == 2) {
1142 ha->seconds_since_last_heartbeat = 0;
1143 halt_status = qla4_8xxx_rd_32(ha,
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07001144 QLA82XX_PEG_HALT_STATUS1);
1145
1146 ql4_printk(KERN_INFO, ha,
1147 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1148 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1149 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1150 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1151 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1152 ha->host_no, __func__, halt_status,
1153 qla4_8xxx_rd_32(ha,
1154 QLA82XX_PEG_HALT_STATUS2),
1155 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
1156 0x3c),
1157 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
1158 0x3c),
1159 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
1160 0x3c),
1161 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
1162 0x3c),
1163 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
1164 0x3c));
Nilesh Javali21033632010-07-30 14:28:07 +05301165
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301166 /* Since we cannot change dev_state in interrupt
1167 * context, set appropriate DPC flag then wakeup
1168 * DPC */
1169 if (halt_status & HALT_STATUS_UNRECOVERABLE)
1170 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1171 else {
1172 printk("scsi%ld: %s: detect abort needed!\n",
1173 ha->host_no, __func__);
1174 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1175 }
1176 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +05301177 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301178 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07001179 } else
1180 ha->seconds_since_last_heartbeat = 0;
1181
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301182 ha->fw_heartbeat_counter = fw_heartbeat_counter;
1183}
1184
1185/**
1186 * qla4_8xxx_watchdog - Poll dev state
1187 * @ha: Pointer to host adapter structure.
1188 *
1189 * Context: Interrupt
1190 **/
1191void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
1192{
1193 uint32_t dev_state;
1194
1195 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1196
1197 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08001198 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1199 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07001200 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301201 if (dev_state == QLA82XX_DEV_NEED_RESET &&
1202 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001203 if (!ql4xdontresethba) {
1204 ql4_printk(KERN_INFO, ha, "%s: HW State: "
1205 "NEED RESET!\n", __func__);
1206 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1207 qla4xxx_wake_dpc(ha);
1208 qla4xxx_mailbox_premature_completion(ha);
1209 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301210 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
1211 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001212 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
1213 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301214 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
1215 qla4xxx_wake_dpc(ha);
1216 } else {
1217 /* Check firmware health */
1218 qla4_8xxx_check_fw_alive(ha);
1219 }
1220 }
1221}
1222
1223/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001224 * qla4xxx_timer - checks every second for work to do.
1225 * @ha: Pointer to host adapter structure.
1226 **/
1227static void qla4xxx_timer(struct scsi_qla_host *ha)
1228{
1229 struct ddb_entry *ddb_entry, *dtemp;
1230 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301231 uint16_t w;
1232
1233 /* If we are in the middle of AER/EEH processing
1234 * skip any processing and reschedule the timer
1235 */
1236 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1237 mod_timer(&ha->timer, jiffies + HZ);
1238 return;
1239 }
1240
1241 /* Hardware read to trigger an EEH error during mailbox waits. */
1242 if (!pci_channel_offline(ha->pdev))
1243 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001244
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301245 if (is_qla8022(ha)) {
1246 qla4_8xxx_watchdog(ha);
1247 }
1248
David Somayajuluafaf5a22006-09-19 10:28:00 -07001249 /* Search for relogin's to time-out and port down retry. */
1250 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1251 /* Count down time between sending relogins */
1252 if (adapter_up(ha) &&
1253 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
1254 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1255 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
1256 INVALID_ENTRY) {
1257 if (atomic_read(&ddb_entry->retry_relogin_timer)
1258 == 0) {
1259 atomic_set(&ddb_entry->
1260 retry_relogin_timer,
1261 INVALID_ENTRY);
1262 set_bit(DPC_RELOGIN_DEVICE,
1263 &ha->dpc_flags);
1264 set_bit(DF_RELOGIN, &ddb_entry->flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301265 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001266 " login device\n",
1267 ha->host_no, __func__,
1268 ddb_entry->fw_ddb_index));
1269 } else
1270 atomic_dec(&ddb_entry->
1271 retry_relogin_timer);
1272 }
1273 }
1274
1275 /* Wait for relogin to timeout */
1276 if (atomic_read(&ddb_entry->relogin_timer) &&
1277 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
1278 /*
1279 * If the relogin times out and the device is
1280 * still NOT ONLINE then try and relogin again.
1281 */
1282 if (atomic_read(&ddb_entry->state) !=
1283 DDB_STATE_ONLINE &&
1284 ddb_entry->fw_ddb_device_state ==
1285 DDB_DS_SESSION_FAILED) {
1286 /* Reset retry relogin timer */
1287 atomic_inc(&ddb_entry->relogin_retry_count);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301288 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001289 " timed out-retrying"
1290 " relogin (%d)\n",
1291 ha->host_no,
1292 ddb_entry->fw_ddb_index,
1293 atomic_read(&ddb_entry->
1294 relogin_retry_count))
1295 );
1296 start_dpc++;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301297 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
Justin P. Mattockcd09b2c2011-01-28 11:49:08 -08001298 "initiate relogin after"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001299 " %d seconds\n",
1300 ha->host_no, ddb_entry->bus,
1301 ddb_entry->target,
1302 ddb_entry->fw_ddb_index,
1303 ddb_entry->default_time2wait + 4)
1304 );
1305
1306 atomic_set(&ddb_entry->retry_relogin_timer,
1307 ddb_entry->default_time2wait + 4);
1308 }
1309 }
1310 }
1311
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301312 if (!is_qla8022(ha)) {
1313 /* Check for heartbeat interval. */
1314 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1315 ha->heartbeat_interval != 0) {
1316 ha->seconds_since_last_heartbeat++;
1317 if (ha->seconds_since_last_heartbeat >
1318 ha->heartbeat_interval + 2)
1319 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1320 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001321 }
1322
David Somayajuluafaf5a22006-09-19 10:28:00 -07001323 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07001324 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001325 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1326 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1327 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301328 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001329 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1330 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301331 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301332 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1333 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07001334 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001335 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1336 " - dpc flags = 0x%lx\n",
1337 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301338 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001339 }
1340
1341 /* Reschedule timer thread to call us back in one second */
1342 mod_timer(&ha->timer, jiffies + HZ);
1343
1344 DEBUG2(ha->seconds_since_last_intr++);
1345}
1346
1347/**
1348 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1349 * @ha: Pointer to host adapter structure.
1350 *
1351 * This routine stalls the driver until all outstanding commands are returned.
1352 * Caller must release the Hardware Lock prior to calling this routine.
1353 **/
1354static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
1355{
1356 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001357 unsigned long flags;
1358 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001359
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301360 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
1361
1362 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
1363 "complete\n", WAIT_CMD_TOV));
1364
1365 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001366 spin_lock_irqsave(&ha->hardware_lock, flags);
1367 /* Find a command that hasn't completed. */
1368 for (index = 0; index < ha->host->can_queue; index++) {
1369 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07001370 /*
1371 * We cannot just check if the index is valid,
1372 * becase if we are run from the scsi eh, then
1373 * the scsi/block layer is going to prevent
1374 * the tag from being released.
1375 */
1376 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001377 break;
1378 }
1379 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1380
1381 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301382 if (index == ha->host->can_queue)
1383 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001384
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301385 msleep(1000);
1386 }
1387 /* If we timed out on waiting for commands to come back
1388 * return ERROR. */
1389 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001390}
1391
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301392int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001393{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001394 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001395 unsigned long flags = 0;
1396
1397 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001398
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301399 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
1400 return QLA_ERROR;
1401
David Somayajuluafaf5a22006-09-19 10:28:00 -07001402 spin_lock_irqsave(&ha->hardware_lock, flags);
1403
1404 /*
1405 * If the SCSI Reset Interrupt bit is set, clear it.
1406 * Otherwise, the Soft Reset won't work.
1407 */
1408 ctrl_status = readw(&ha->reg->ctrl_status);
1409 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
1410 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1411
1412 /* Issue Soft Reset */
1413 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1414 readl(&ha->reg->ctrl_status);
1415
1416 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301417 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001418}
1419
1420/**
1421 * qla4xxx_soft_reset - performs soft reset.
1422 * @ha: Pointer to host adapter structure.
1423 **/
1424int qla4xxx_soft_reset(struct scsi_qla_host *ha)
1425{
1426 uint32_t max_wait_time;
1427 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001428 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001429 uint32_t ctrl_status;
1430
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001431 status = qla4xxx_hw_reset(ha);
1432 if (status != QLA_SUCCESS)
1433 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001434
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001435 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001436 /* Wait until the Network Reset Intr bit is cleared */
1437 max_wait_time = RESET_INTR_TOV;
1438 do {
1439 spin_lock_irqsave(&ha->hardware_lock, flags);
1440 ctrl_status = readw(&ha->reg->ctrl_status);
1441 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1442
1443 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
1444 break;
1445
1446 msleep(1000);
1447 } while ((--max_wait_time));
1448
1449 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
1450 DEBUG2(printk(KERN_WARNING
1451 "scsi%ld: Network Reset Intr not cleared by "
1452 "Network function, clearing it now!\n",
1453 ha->host_no));
1454 spin_lock_irqsave(&ha->hardware_lock, flags);
1455 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
1456 readl(&ha->reg->ctrl_status);
1457 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1458 }
1459
1460 /* Wait until the firmware tells us the Soft Reset is done */
1461 max_wait_time = SOFT_RESET_TOV;
1462 do {
1463 spin_lock_irqsave(&ha->hardware_lock, flags);
1464 ctrl_status = readw(&ha->reg->ctrl_status);
1465 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1466
1467 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
1468 status = QLA_SUCCESS;
1469 break;
1470 }
1471
1472 msleep(1000);
1473 } while ((--max_wait_time));
1474
1475 /*
1476 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1477 * after the soft reset has taken place.
1478 */
1479 spin_lock_irqsave(&ha->hardware_lock, flags);
1480 ctrl_status = readw(&ha->reg->ctrl_status);
1481 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
1482 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1483 readl(&ha->reg->ctrl_status);
1484 }
1485 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1486
1487 /* If soft reset fails then most probably the bios on other
1488 * function is also enabled.
1489 * Since the initialization is sequential the other fn
1490 * wont be able to acknowledge the soft reset.
1491 * Issue a force soft reset to workaround this scenario.
1492 */
1493 if (max_wait_time == 0) {
1494 /* Issue Force Soft Reset */
1495 spin_lock_irqsave(&ha->hardware_lock, flags);
1496 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
1497 readl(&ha->reg->ctrl_status);
1498 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1499 /* Wait until the firmware tells us the Soft Reset is done */
1500 max_wait_time = SOFT_RESET_TOV;
1501 do {
1502 spin_lock_irqsave(&ha->hardware_lock, flags);
1503 ctrl_status = readw(&ha->reg->ctrl_status);
1504 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1505
1506 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
1507 status = QLA_SUCCESS;
1508 break;
1509 }
1510
1511 msleep(1000);
1512 } while ((--max_wait_time));
1513 }
1514
1515 return status;
1516}
1517
1518/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301519 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001520 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301521 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07001522 *
1523 * This routine is called just prior to a HARD RESET to return all
1524 * outstanding commands back to the Operating System.
1525 * Caller should make sure that the following locks are released
1526 * before this calling routine: Hardware lock, and io_request_lock.
1527 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301528static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001529{
1530 struct srb *srb;
1531 int i;
1532 unsigned long flags;
1533
1534 spin_lock_irqsave(&ha->hardware_lock, flags);
1535 for (i = 0; i < ha->host->can_queue; i++) {
1536 srb = qla4xxx_del_from_active_array(ha, i);
1537 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301538 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301539 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001540 }
1541 }
1542 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001543}
1544
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301545void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
1546{
1547 clear_bit(AF_ONLINE, &ha->flags);
1548
1549 /* Disable the board */
1550 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301551
1552 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
1553 qla4xxx_mark_all_devices_missing(ha);
1554 clear_bit(AF_INIT_DONE, &ha->flags);
1555}
1556
David Somayajuluafaf5a22006-09-19 10:28:00 -07001557/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001558 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1559 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001560 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301561static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001562{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301563 int status = QLA_ERROR;
1564 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001565
1566 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301567 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001568 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06001569
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301570 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001571
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301572 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001573
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301574 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1575 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001576
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301577 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1578 * do not reset adapter, jump to initialize_adapter */
1579 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1580 status = QLA_SUCCESS;
1581 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001582 }
1583
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301584 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1585 * from eh_host_reset or ioctl module */
1586 if (is_qla8022(ha) && !reset_chip &&
1587 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
1588
1589 DEBUG2(ql4_printk(KERN_INFO, ha,
1590 "scsi%ld: %s - Performing stop_firmware...\n",
1591 ha->host_no, __func__));
1592 status = ha->isp_ops->reset_firmware(ha);
1593 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001594 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1595 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301596 ha->isp_ops->disable_intrs(ha);
1597 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1598 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1599 } else {
1600 /* If the stop_firmware fails then
1601 * reset the entire chip */
1602 reset_chip = 1;
1603 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1604 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1605 }
1606 }
1607
1608 /* Issue full chip reset if recovering from a catastrophic error,
1609 * or if stop_firmware fails for ISP-82xx.
1610 * This is the default case for ISP-4xxx */
1611 if (!is_qla8022(ha) || reset_chip) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001612 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1613 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301614 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1615 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1616 DEBUG2(ql4_printk(KERN_INFO, ha,
1617 "scsi%ld: %s - Performing chip reset..\n",
1618 ha->host_no, __func__));
1619 status = ha->isp_ops->reset_chip(ha);
1620 }
1621
1622 /* Flush any pending ddb changed AENs */
1623 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1624
1625recover_ha_init_adapter:
1626 /* Upon successful firmware/chip reset, re-initialize the adapter */
1627 if (status == QLA_SUCCESS) {
1628 /* For ISP-4xxx, force function 1 to always initialize
1629 * before function 3 to prevent both funcions from
1630 * stepping on top of the other */
1631 if (!is_qla8022(ha) && (ha->mac_index == 3))
1632 ssleep(6);
1633
1634 /* NOTE: AF_ONLINE flag set upon successful completion of
1635 * qla4xxx_initialize_adapter */
1636 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1637 }
1638
1639 /* Retry failed adapter initialization, if necessary
1640 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1641 * case to prevent ping-pong resets between functions */
1642 if (!test_bit(AF_ONLINE, &ha->flags) &&
1643 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001644 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301645 * resetting the ha.
1646 * Since we don't want to block the DPC for too long
1647 * with multiple resets in the same thread,
1648 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07001649 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1650 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1651 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1652 "(%d) more times\n", ha->host_no,
1653 ha->retry_reset_ha_cnt));
1654 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1655 status = QLA_ERROR;
1656 } else {
1657 if (ha->retry_reset_ha_cnt > 0) {
1658 /* Schedule another Reset HA--DPC will retry */
1659 ha->retry_reset_ha_cnt--;
1660 DEBUG2(printk("scsi%ld: recover adapter - "
1661 "retry remaining %d\n",
1662 ha->host_no,
1663 ha->retry_reset_ha_cnt));
1664 status = QLA_ERROR;
1665 }
1666
1667 if (ha->retry_reset_ha_cnt == 0) {
1668 /* Recover adapter retries have been exhausted.
1669 * Adapter DEAD */
1670 DEBUG2(printk("scsi%ld: recover adapter "
1671 "failed - board disabled\n",
1672 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301673 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001674 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1675 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301676 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001677 &ha->dpc_flags);
1678 status = QLA_ERROR;
1679 }
1680 }
1681 } else {
1682 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301683 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001684 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1685 }
1686
1687 ha->adapter_error_count++;
1688
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301689 if (test_bit(AF_ONLINE, &ha->flags))
1690 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001691
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301692 scsi_unblock_requests(ha->host);
1693
1694 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1695 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001696 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301697
David Somayajuluafaf5a22006-09-19 10:28:00 -07001698 return status;
1699}
1700
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001701static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
1702{
1703 struct ddb_entry *ddb_entry, *dtemp;
1704
1705 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1706 if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) ||
1707 (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) {
1708 if (ddb_entry->fw_ddb_device_state ==
1709 DDB_DS_SESSION_ACTIVE) {
1710 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1711 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
1712 " marked ONLINE\n", ha->host_no, __func__,
1713 ddb_entry->fw_ddb_index);
1714
1715 iscsi_unblock_session(ddb_entry->sess);
1716 } else
1717 qla4xxx_relogin_device(ha, ddb_entry);
1718 }
1719 }
1720}
1721
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301722void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
1723{
Lalit Chandivade1b468072011-05-17 23:17:09 -07001724 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301725 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301726}
1727
David Somayajuluafaf5a22006-09-19 10:28:00 -07001728/**
1729 * qla4xxx_do_dpc - dpc routine
1730 * @data: in our case pointer to adapter structure
1731 *
1732 * This routine is a task that is schedule by the interrupt handler
1733 * to perform the background processing for interrupts. We put it
1734 * on a task queue that is consumed whenever the scheduler runs; that's
1735 * so you can do anything (i.e. put the process to sleep etc). In fact,
1736 * the mid-level tries to sleep when it reaches the driver threshold
1737 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1738 **/
David Howellsc4028952006-11-22 14:57:56 +00001739static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001740{
David Howellsc4028952006-11-22 14:57:56 +00001741 struct scsi_qla_host *ha =
1742 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001743 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001744 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001745
David C Somayajuluf26b9042006-11-15 16:41:09 -08001746 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301747 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1748 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001749
1750 /* Initialization not yet finished. Don't do anything yet. */
1751 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07001752 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001753
Lalit Chandivade2232be02010-07-30 14:38:47 +05301754 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1755 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
1756 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07001757 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301758 }
1759
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301760 if (is_qla8022(ha)) {
1761 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
1762 qla4_8xxx_idc_lock(ha);
1763 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1764 QLA82XX_DEV_FAILED);
1765 qla4_8xxx_idc_unlock(ha);
1766 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
1767 qla4_8xxx_device_state_handler(ha);
1768 }
1769 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1770 qla4_8xxx_need_qsnt_handler(ha);
1771 }
1772 }
1773
1774 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
1775 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001776 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301777 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
1778 if (ql4xdontresethba) {
1779 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1780 ha->host_no, __func__));
1781 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1782 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1783 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1784 goto dpc_post_reset_ha;
1785 }
1786 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1787 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1788 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001789
David C Somayajulu477ffb92007-01-22 12:26:11 -08001790 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001791 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001792
David Somayajuluafaf5a22006-09-19 10:28:00 -07001793 while ((readw(&ha->reg->ctrl_status) &
1794 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1795 if (--wait_time == 0)
1796 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001797 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001798 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001799 if (wait_time == 0)
1800 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1801 "bit not cleared-- resetting\n",
1802 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301803 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001804 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1805 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301806 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001807 }
1808 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1809 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301810 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001811 }
1812 }
1813
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301814dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001815 /* ---- process AEN? --- */
1816 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1817 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1818
1819 /* ---- Get DHCP IP Address? --- */
1820 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1821 qla4xxx_get_dhcp_ip_address(ha);
1822
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301823 /* ---- link change? --- */
1824 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
1825 if (!test_bit(AF_LINK_UP, &ha->flags)) {
1826 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001827 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301828 } else {
1829 /* ---- link up? --- *
1830 * F/W will auto login to all devices ONLY ONCE after
1831 * link up during driver initialization and runtime
1832 * fatal error recovery. Therefore, the driver must
1833 * manually relogin to devices when recovering from
1834 * connection failures, logouts, expired KATO, etc. */
1835
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001836 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301837 }
1838 }
1839
David Somayajuluafaf5a22006-09-19 10:28:00 -07001840 /* ---- relogin device? --- */
1841 if (adapter_up(ha) &&
1842 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1843 list_for_each_entry_safe(ddb_entry, dtemp,
1844 &ha->ddb_list, list) {
1845 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1846 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1847 qla4xxx_relogin_device(ha, ddb_entry);
1848
1849 /*
1850 * If mbx cmd times out there is no point
1851 * in continuing further.
1852 * With large no of targets this can hang
1853 * the system.
1854 */
1855 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1856 printk(KERN_WARNING "scsi%ld: %s: "
1857 "need to reset hba\n",
1858 ha->host_no, __func__);
1859 break;
1860 }
1861 }
1862 }
Vikas Chaudhary0753b482010-07-30 14:27:19 +05301863
David Somayajuluafaf5a22006-09-19 10:28:00 -07001864}
1865
1866/**
1867 * qla4xxx_free_adapter - release the adapter
1868 * @ha: pointer to adapter structure
1869 **/
1870static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1871{
1872
1873 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1874 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301875 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001876 }
1877
David Somayajuluafaf5a22006-09-19 10:28:00 -07001878 /* Remove timer thread, if present */
1879 if (ha->timer_active)
1880 qla4xxx_stop_timer(ha);
1881
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301882 /* Kill the kernel thread for this host */
1883 if (ha->dpc_thread)
1884 destroy_workqueue(ha->dpc_thread);
1885
1886 /* Put firmware in known state */
1887 ha->isp_ops->reset_firmware(ha);
1888
1889 if (is_qla8022(ha)) {
1890 qla4_8xxx_idc_lock(ha);
1891 qla4_8xxx_clear_drv_active(ha);
1892 qla4_8xxx_idc_unlock(ha);
1893 }
1894
David Somayajuluafaf5a22006-09-19 10:28:00 -07001895 /* Detach interrupts */
1896 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301897 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001898
David C Somayajulubee4fe82007-05-23 18:03:32 -07001899 /* free extra memory */
1900 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301901}
David C Somayajulubee4fe82007-05-23 18:03:32 -07001902
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301903int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1904{
1905 int status = 0;
1906 uint8_t revision_id;
1907 unsigned long mem_base, mem_len, db_base, db_len;
1908 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001909
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301910 status = pci_request_regions(pdev, DRIVER_NAME);
1911 if (status) {
1912 printk(KERN_WARNING
1913 "scsi(%ld) Failed to reserve PIO regions (%s) "
1914 "status=%d\n", ha->host_no, pci_name(pdev), status);
1915 goto iospace_error_exit;
1916 }
1917
1918 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
1919 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
1920 __func__, revision_id));
1921 ha->revision_id = revision_id;
1922
1923 /* remap phys address */
1924 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
1925 mem_len = pci_resource_len(pdev, 0);
1926 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
1927 __func__, mem_base, mem_len));
1928
1929 /* mapping of pcibase pointer */
1930 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
1931 if (!ha->nx_pcibase) {
1932 printk(KERN_ERR
1933 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
1934 pci_release_regions(ha->pdev);
1935 goto iospace_error_exit;
1936 }
1937
1938 /* Mapping of IO base pointer, door bell read and write pointer */
1939
1940 /* mapping of IO base pointer */
1941 ha->qla4_8xxx_reg =
1942 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
1943 0xbc000 + (ha->pdev->devfn << 11));
1944
1945 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
1946 db_len = pci_resource_len(pdev, 4);
1947
Shyam Sundar2657c802010-10-06 22:50:29 -07001948 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
1949 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301950
Shyam Sundar2657c802010-10-06 22:50:29 -07001951 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301952iospace_error_exit:
1953 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001954}
1955
1956/***
1957 * qla4xxx_iospace_config - maps registers
1958 * @ha: pointer to adapter structure
1959 *
1960 * This routines maps HBA's registers from the pci address space
1961 * into the kernel virtual address space for memory mapped i/o.
1962 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301963int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001964{
1965 unsigned long pio, pio_len, pio_flags;
1966 unsigned long mmio, mmio_len, mmio_flags;
1967
1968 pio = pci_resource_start(ha->pdev, 0);
1969 pio_len = pci_resource_len(ha->pdev, 0);
1970 pio_flags = pci_resource_flags(ha->pdev, 0);
1971 if (pio_flags & IORESOURCE_IO) {
1972 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301973 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001974 "Invalid PCI I/O region size\n");
1975 pio = 0;
1976 }
1977 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301978 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001979 pio = 0;
1980 }
1981
1982 /* Use MMIO operations for all accesses. */
1983 mmio = pci_resource_start(ha->pdev, 1);
1984 mmio_len = pci_resource_len(ha->pdev, 1);
1985 mmio_flags = pci_resource_flags(ha->pdev, 1);
1986
1987 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301988 ql4_printk(KERN_ERR, ha,
1989 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001990
1991 goto iospace_error_exit;
1992 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301993
David Somayajuluafaf5a22006-09-19 10:28:00 -07001994 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301995 ql4_printk(KERN_ERR, ha,
1996 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001997 goto iospace_error_exit;
1998 }
1999
2000 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302001 ql4_printk(KERN_WARNING, ha,
2002 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002003
2004 goto iospace_error_exit;
2005 }
2006
2007 ha->pio_address = pio;
2008 ha->pio_length = pio_len;
2009 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
2010 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302011 ql4_printk(KERN_ERR, ha,
2012 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002013
2014 goto iospace_error_exit;
2015 }
2016
2017 return 0;
2018
2019iospace_error_exit:
2020 return -ENOMEM;
2021}
2022
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302023static struct isp_operations qla4xxx_isp_ops = {
2024 .iospace_config = qla4xxx_iospace_config,
2025 .pci_config = qla4xxx_pci_config,
2026 .disable_intrs = qla4xxx_disable_intrs,
2027 .enable_intrs = qla4xxx_enable_intrs,
2028 .start_firmware = qla4xxx_start_firmware,
2029 .intr_handler = qla4xxx_intr_handler,
2030 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
2031 .reset_chip = qla4xxx_soft_reset,
2032 .reset_firmware = qla4xxx_hw_reset,
2033 .queue_iocb = qla4xxx_queue_iocb,
2034 .complete_iocb = qla4xxx_complete_iocb,
2035 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
2036 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
2037 .get_sys_info = qla4xxx_get_sys_info,
2038};
2039
2040static struct isp_operations qla4_8xxx_isp_ops = {
2041 .iospace_config = qla4_8xxx_iospace_config,
2042 .pci_config = qla4_8xxx_pci_config,
2043 .disable_intrs = qla4_8xxx_disable_intrs,
2044 .enable_intrs = qla4_8xxx_enable_intrs,
2045 .start_firmware = qla4_8xxx_load_risc,
2046 .intr_handler = qla4_8xxx_intr_handler,
2047 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
2048 .reset_chip = qla4_8xxx_isp_reset,
2049 .reset_firmware = qla4_8xxx_stop_firmware,
2050 .queue_iocb = qla4_8xxx_queue_iocb,
2051 .complete_iocb = qla4_8xxx_complete_iocb,
2052 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
2053 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
2054 .get_sys_info = qla4_8xxx_get_sys_info,
2055};
2056
2057uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2058{
2059 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
2060}
2061
2062uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2063{
2064 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
2065}
2066
2067uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2068{
2069 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
2070}
2071
2072uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2073{
2074 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
2075}
2076
David Somayajuluafaf5a22006-09-19 10:28:00 -07002077/**
2078 * qla4xxx_probe_adapter - callback function to probe HBA
2079 * @pdev: pointer to pci_dev structure
2080 * @pci_device_id: pointer to pci_device entry
2081 *
2082 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
2083 * It returns zero if successful. It also initializes all data necessary for
2084 * the driver.
2085 **/
2086static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
2087 const struct pci_device_id *ent)
2088{
2089 int ret = -ENODEV, status;
2090 struct Scsi_Host *host;
2091 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002092 uint8_t init_retry_count = 0;
2093 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302094 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002095 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002096
2097 if (pci_enable_device(pdev))
2098 return -1;
2099
2100 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
2101 if (host == NULL) {
2102 printk(KERN_WARNING
2103 "qla4xxx: Couldn't allocate host from scsi layer!\n");
2104 goto probe_disable_device;
2105 }
2106
2107 /* Clear our data area */
2108 ha = (struct scsi_qla_host *) host->hostdata;
2109 memset(ha, 0, sizeof(*ha));
2110
2111 /* Save the information from PCI BIOS. */
2112 ha->pdev = pdev;
2113 ha->host = host;
2114 ha->host_no = host->host_no;
2115
Lalit Chandivade2232be02010-07-30 14:38:47 +05302116 pci_enable_pcie_error_reporting(pdev);
2117
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302118 /* Setup Runtime configurable options */
2119 if (is_qla8022(ha)) {
2120 ha->isp_ops = &qla4_8xxx_isp_ops;
2121 rwlock_init(&ha->hw_lock);
2122 ha->qdr_sn_window = -1;
2123 ha->ddr_mn_window = -1;
2124 ha->curr_window = 255;
2125 ha->func_num = PCI_FUNC(ha->pdev->devfn);
2126 nx_legacy_intr = &legacy_intr[ha->func_num];
2127 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
2128 ha->nx_legacy_intr.tgt_status_reg =
2129 nx_legacy_intr->tgt_status_reg;
2130 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
2131 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
2132 } else {
2133 ha->isp_ops = &qla4xxx_isp_ops;
2134 }
2135
Lalit Chandivade2232be02010-07-30 14:38:47 +05302136 /* Set EEH reset type to fundamental if required by hba */
2137 if (is_qla8022(ha))
2138 pdev->needs_freset = 1;
2139
David Somayajuluafaf5a22006-09-19 10:28:00 -07002140 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302141 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002142 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302143 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002144
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302145 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07002146 pdev->device, pdev->irq, ha->reg);
2147
2148 qla4xxx_config_dma_addressing(ha);
2149
2150 /* Initialize lists and spinlocks. */
2151 INIT_LIST_HEAD(&ha->ddb_list);
2152 INIT_LIST_HEAD(&ha->free_srb_q);
2153
2154 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302155 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002156
2157 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002158
2159 /* Allocate dma buffers */
2160 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302161 ql4_printk(KERN_WARNING, ha,
2162 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002163
2164 ret = -ENOMEM;
2165 goto probe_failed;
2166 }
2167
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302168 if (is_qla8022(ha))
2169 (void) qla4_8xxx_get_flash_info(ha);
2170
David Somayajuluafaf5a22006-09-19 10:28:00 -07002171 /*
2172 * Initialize the Host adapter request/response queues and
2173 * firmware
2174 * NOTE: interrupts enabled upon successful completion
2175 */
2176 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302177 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
2178 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002179
2180 if (is_qla8022(ha)) {
2181 qla4_8xxx_idc_lock(ha);
2182 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2183 qla4_8xxx_idc_unlock(ha);
2184 if (dev_state == QLA82XX_DEV_FAILED) {
2185 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
2186 "initialize adapter. H/W is in failed state\n",
2187 __func__);
2188 break;
2189 }
2190 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002191 DEBUG2(printk("scsi: %s: retrying adapter initialization "
2192 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302193
2194 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
2195 continue;
2196
David Somayajuluafaf5a22006-09-19 10:28:00 -07002197 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
2198 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302199
2200 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302201 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002202
Lalit Chandivadefe998522010-12-02 22:12:36 -08002203 if (is_qla8022(ha) && ql4xdontresethba) {
2204 /* Put the device in failed state. */
2205 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
2206 qla4_8xxx_idc_lock(ha);
2207 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2208 QLA82XX_DEV_FAILED);
2209 qla4_8xxx_idc_unlock(ha);
2210 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002211 ret = -ENODEV;
2212 goto probe_failed;
2213 }
2214
2215 host->cmd_per_lun = 3;
2216 host->max_channel = 0;
2217 host->max_lun = MAX_LUNS - 1;
2218 host->max_id = MAX_TARGETS;
2219 host->max_cmd_len = IOCB_MAX_CDB_LEN;
2220 host->can_queue = MAX_SRBS ;
2221 host->transportt = qla4xxx_scsi_transport;
2222
2223 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
2224 if (ret) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302225 ql4_printk(KERN_WARNING, ha,
2226 "scsi_init_shared_tag_map failed\n");
2227 goto probe_failed;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002228 }
2229
2230 /* Startup the kernel thread for this host adapter. */
2231 DEBUG2(printk("scsi: %s: Starting kernel thread for "
2232 "qla4xxx_dpc\n", __func__));
2233 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
2234 ha->dpc_thread = create_singlethread_workqueue(buf);
2235 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302236 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002237 ret = -ENODEV;
2238 goto probe_failed;
2239 }
David Howellsc4028952006-11-22 14:57:56 +00002240 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002241
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302242 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
2243 * (which is called indirectly by qla4xxx_initialize_adapter),
2244 * so that irqs will be registered after crbinit but before
2245 * mbx_intr_enable.
2246 */
2247 if (!is_qla8022(ha)) {
2248 ret = qla4xxx_request_irqs(ha);
2249 if (ret) {
2250 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
2251 "interrupt %d already in use.\n", pdev->irq);
2252 goto probe_failed;
2253 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002254 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002255
Lalit Chandivade2232be02010-07-30 14:38:47 +05302256 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302257 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002258
2259 /* Start timer thread. */
2260 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
2261
2262 set_bit(AF_INIT_DONE, &ha->flags);
2263
2264 pci_set_drvdata(pdev, ha);
2265
2266 ret = scsi_add_host(host, &pdev->dev);
2267 if (ret)
2268 goto probe_failed;
2269
David Somayajuluafaf5a22006-09-19 10:28:00 -07002270 printk(KERN_INFO
2271 " QLogic iSCSI HBA Driver version: %s\n"
2272 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2273 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
2274 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2275 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06002276 scsi_scan_host(host);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002277
2278 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002279 return 0;
2280
David Somayajuluafaf5a22006-09-19 10:28:00 -07002281probe_failed:
2282 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302283
2284probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05302285 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002286 scsi_host_put(ha->host);
2287
2288probe_disable_device:
2289 pci_disable_device(pdev);
2290
2291 return ret;
2292}
2293
2294/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07002295 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
2296 * @ha: pointer to adapter structure
2297 *
2298 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
2299 * so that the other port will not re-initialize while in the process of
2300 * removing the ha due to driver unload or hba hotplug.
2301 **/
2302static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
2303{
2304 struct scsi_qla_host *other_ha = NULL;
2305 struct pci_dev *other_pdev = NULL;
2306 int fn = ISP4XXX_PCI_FN_2;
2307
2308 /*iscsi function numbers for ISP4xxx is 1 and 3*/
2309 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
2310 fn = ISP4XXX_PCI_FN_1;
2311
2312 other_pdev =
2313 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2314 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2315 fn));
2316
2317 /* Get other_ha if other_pdev is valid and state is enable*/
2318 if (other_pdev) {
2319 if (atomic_read(&other_pdev->enable_cnt)) {
2320 other_ha = pci_get_drvdata(other_pdev);
2321 if (other_ha) {
2322 set_bit(AF_HA_REMOVAL, &other_ha->flags);
2323 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
2324 "Prevent %s reinit\n", __func__,
2325 dev_name(&other_ha->pdev->dev)));
2326 }
2327 }
2328 pci_dev_put(other_pdev);
2329 }
2330}
2331
2332/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002333 * qla4xxx_remove_adapter - calback function to remove adapter.
2334 * @pci_dev: PCI device pointer
2335 **/
2336static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
2337{
2338 struct scsi_qla_host *ha;
2339
2340 ha = pci_get_drvdata(pdev);
2341
Karen Higgins7eece5a2011-03-21 03:34:29 -07002342 if (!is_qla8022(ha))
2343 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07002344
David Somayajuluafaf5a22006-09-19 10:28:00 -07002345 /* remove devs from iscsi_sessions to scsi_devices */
2346 qla4xxx_free_ddb_list(ha);
2347
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002348 /* destroy iface from sysfs */
2349 qla4xxx_destroy_ifaces(ha);
2350
David Somayajuluafaf5a22006-09-19 10:28:00 -07002351 scsi_remove_host(ha->host);
2352
2353 qla4xxx_free_adapter(ha);
2354
2355 scsi_host_put(ha->host);
2356
Lalit Chandivade2232be02010-07-30 14:38:47 +05302357 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302358 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002359 pci_set_drvdata(pdev, NULL);
2360}
2361
2362/**
2363 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
2364 * @ha: HA context
2365 *
2366 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2367 * supported addressing method.
2368 */
Adrian Bunk47975472007-04-26 00:35:16 -07002369static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002370{
2371 int retval;
2372
2373 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07002374 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
2375 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002376 dev_dbg(&ha->pdev->dev,
2377 "Failed to set 64 bit PCI consistent mask; "
2378 "using 32 bit.\n");
2379 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07002380 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002381 }
2382 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07002383 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002384}
2385
2386static int qla4xxx_slave_alloc(struct scsi_device *sdev)
2387{
2388 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
2389 struct ddb_entry *ddb = sess->dd_data;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002390 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002391
2392 sdev->hostdata = ddb;
2393 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002394
2395 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
2396 queue_depth = ql4xmaxqdepth;
2397
2398 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002399 return 0;
2400}
2401
2402static int qla4xxx_slave_configure(struct scsi_device *sdev)
2403{
2404 sdev->tagged_supported = 1;
2405 return 0;
2406}
2407
2408static void qla4xxx_slave_destroy(struct scsi_device *sdev)
2409{
2410 scsi_deactivate_tcq(sdev, 1);
2411}
2412
2413/**
2414 * qla4xxx_del_from_active_array - returns an active srb
2415 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002416 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002417 *
2418 * This routine removes and returns the srb at the specified index
2419 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302420struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
2421 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002422{
2423 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05302424 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002425
Vikas Chaudhary53698872010-04-28 11:41:59 +05302426 cmd = scsi_host_find_tag(ha->host, index);
2427 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002428 return srb;
2429
Vikas Chaudhary53698872010-04-28 11:41:59 +05302430 srb = (struct srb *)CMD_SP(cmd);
2431 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002432 return srb;
2433
2434 /* update counters */
2435 if (srb->flags & SRB_DMA_VALID) {
2436 ha->req_q_count += srb->iocb_cnt;
2437 ha->iocb_cnt -= srb->iocb_cnt;
2438 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05302439 srb->cmd->host_scribble =
2440 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002441 }
2442 return srb;
2443}
2444
2445/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002446 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302447 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002448 * @cmd: Scsi Command to wait on.
2449 *
2450 * This routine waits for the command to be returned by the Firmware
2451 * for some max time.
2452 **/
2453static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
2454 struct scsi_cmnd *cmd)
2455{
2456 int done = 0;
2457 struct srb *rp;
2458 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302459 int ret = SUCCESS;
2460
2461 /* Dont wait on command if PCI error is being handled
2462 * by PCI AER driver
2463 */
2464 if (unlikely(pci_channel_offline(ha->pdev)) ||
2465 (test_bit(AF_EEH_BUSY, &ha->flags))) {
2466 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
2467 ha->host_no, __func__);
2468 return ret;
2469 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002470
2471 do {
2472 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05302473 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002474 if (rp == NULL) {
2475 done++;
2476 break;
2477 }
2478
2479 msleep(2000);
2480 } while (max_wait_time--);
2481
2482 return done;
2483}
2484
2485/**
2486 * qla4xxx_wait_for_hba_online - waits for HBA to come online
2487 * @ha: Pointer to host adapter structure
2488 **/
2489static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
2490{
2491 unsigned long wait_online;
2492
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002493 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002494 while (time_before(jiffies, wait_online)) {
2495
2496 if (adapter_up(ha))
2497 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002498
2499 msleep(2000);
2500 }
2501
2502 return QLA_ERROR;
2503}
2504
2505/**
Mike Christiece545032008-02-29 18:25:20 -06002506 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002507 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07002508 * @t: target id
2509 * @l: lun id
2510 *
2511 * This function waits for all outstanding commands to a lun to complete. It
2512 * returns 0 if all pending commands are returned and 1 otherwise.
2513 **/
Mike Christiece545032008-02-29 18:25:20 -06002514static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
2515 struct scsi_target *stgt,
2516 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002517{
2518 int cnt;
2519 int status = 0;
2520 struct scsi_cmnd *cmd;
2521
2522 /*
Mike Christiece545032008-02-29 18:25:20 -06002523 * Waiting for all commands for the designated target or dev
2524 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002525 */
2526 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
2527 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06002528 if (cmd && stgt == scsi_target(cmd->device) &&
2529 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002530 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2531 status++;
2532 break;
2533 }
2534 }
2535 }
2536 return status;
2537}
2538
2539/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302540 * qla4xxx_eh_abort - callback for abort task.
2541 * @cmd: Pointer to Linux's SCSI command structure
2542 *
2543 * This routine is called by the Linux OS to abort the specified
2544 * command.
2545 **/
2546static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
2547{
2548 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2549 unsigned int id = cmd->device->id;
2550 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002551 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302552 struct srb *srb = NULL;
2553 int ret = SUCCESS;
2554 int wait = 0;
2555
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302556 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04002557 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
2558 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302559
Mike Christie92b3e5b2010-10-06 22:51:17 -07002560 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302561 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002562 if (!srb) {
2563 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302564 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002565 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302566 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002567 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302568
2569 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
2570 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
2571 ha->host_no, id, lun));
2572 ret = FAILED;
2573 } else {
2574 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
2575 ha->host_no, id, lun));
2576 wait = 1;
2577 }
2578
2579 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2580
2581 /* Wait for command to complete */
2582 if (wait) {
2583 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2584 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
2585 ha->host_no, id, lun));
2586 ret = FAILED;
2587 }
2588 }
2589
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302590 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302591 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002592 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302593
2594 return ret;
2595}
2596
2597/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002598 * qla4xxx_eh_device_reset - callback for target reset.
2599 * @cmd: Pointer to Linux's SCSI command structure
2600 *
2601 * This routine is called by the Linux OS to reset all luns on the
2602 * specified target.
2603 **/
2604static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
2605{
2606 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2607 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002608 int ret = FAILED, stat;
2609
Karen Higgins612f7342009-07-15 15:03:01 -05002610 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002611 return ret;
2612
Mike Christiec01be6d2010-07-22 16:59:49 +05302613 ret = iscsi_block_scsi_eh(cmd);
2614 if (ret)
2615 return ret;
2616 ret = FAILED;
2617
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302618 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002619 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2620 cmd->device->channel, cmd->device->id, cmd->device->lun);
2621
2622 DEBUG2(printk(KERN_INFO
2623 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2624 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07002625 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002626 ha->dpc_flags, cmd->result, cmd->allowed));
2627
2628 /* FIXME: wait for hba to go online */
2629 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
2630 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302631 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002632 goto eh_dev_reset_done;
2633 }
2634
Mike Christiece545032008-02-29 18:25:20 -06002635 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2636 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302637 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06002638 "DEVICE RESET FAILED - waiting for "
2639 "commands.\n");
2640 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002641 }
2642
David C Somayajulu9d562912008-03-19 11:23:03 -07002643 /* Send marker. */
2644 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2645 MM_LUN_RESET) != QLA_SUCCESS)
2646 goto eh_dev_reset_done;
2647
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302648 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002649 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2650 ha->host_no, cmd->device->channel, cmd->device->id,
2651 cmd->device->lun);
2652
2653 ret = SUCCESS;
2654
2655eh_dev_reset_done:
2656
2657 return ret;
2658}
2659
2660/**
Mike Christiece545032008-02-29 18:25:20 -06002661 * qla4xxx_eh_target_reset - callback for target reset.
2662 * @cmd: Pointer to Linux's SCSI command structure
2663 *
2664 * This routine is called by the Linux OS to reset the target.
2665 **/
2666static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
2667{
2668 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2669 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05302670 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06002671
2672 if (!ddb_entry)
2673 return FAILED;
2674
Mike Christiec01be6d2010-07-22 16:59:49 +05302675 ret = iscsi_block_scsi_eh(cmd);
2676 if (ret)
2677 return ret;
2678
Mike Christiece545032008-02-29 18:25:20 -06002679 starget_printk(KERN_INFO, scsi_target(cmd->device),
2680 "WARM TARGET RESET ISSUED.\n");
2681
2682 DEBUG2(printk(KERN_INFO
2683 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2684 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07002685 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06002686 ha->dpc_flags, cmd->result, cmd->allowed));
2687
2688 stat = qla4xxx_reset_target(ha, ddb_entry);
2689 if (stat != QLA_SUCCESS) {
2690 starget_printk(KERN_INFO, scsi_target(cmd->device),
2691 "WARM TARGET RESET FAILED.\n");
2692 return FAILED;
2693 }
2694
Mike Christiece545032008-02-29 18:25:20 -06002695 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2696 NULL)) {
2697 starget_printk(KERN_INFO, scsi_target(cmd->device),
2698 "WARM TARGET DEVICE RESET FAILED - "
2699 "waiting for commands.\n");
2700 return FAILED;
2701 }
2702
David C Somayajulu9d562912008-03-19 11:23:03 -07002703 /* Send marker. */
2704 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2705 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
2706 starget_printk(KERN_INFO, scsi_target(cmd->device),
2707 "WARM TARGET DEVICE RESET FAILED - "
2708 "marker iocb failed.\n");
2709 return FAILED;
2710 }
2711
Mike Christiece545032008-02-29 18:25:20 -06002712 starget_printk(KERN_INFO, scsi_target(cmd->device),
2713 "WARM TARGET RESET SUCCEEDED.\n");
2714 return SUCCESS;
2715}
2716
2717/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002718 * qla4xxx_eh_host_reset - kernel callback
2719 * @cmd: Pointer to Linux's SCSI command structure
2720 *
2721 * This routine is invoked by the Linux kernel to perform fatal error
2722 * recovery on the specified adapter.
2723 **/
2724static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2725{
2726 int return_status = FAILED;
2727 struct scsi_qla_host *ha;
2728
2729 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
2730
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302731 if (ql4xdontresethba) {
2732 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2733 ha->host_no, __func__));
2734 return FAILED;
2735 }
2736
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302737 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05002738 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002739 cmd->device->channel, cmd->device->id, cmd->device->lun);
2740
2741 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2742 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2743 "DEAD.\n", ha->host_no, cmd->device->channel,
2744 __func__));
2745
2746 return FAILED;
2747 }
2748
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302749 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2750 if (is_qla8022(ha))
2751 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2752 else
2753 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2754 }
Mike Christie50a29ae2008-03-04 13:26:53 -06002755
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302756 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002757 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002758
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302759 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002760 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002761
2762 return return_status;
2763}
2764
Lalit Chandivade2232be02010-07-30 14:38:47 +05302765/* PCI AER driver recovers from all correctable errors w/o
2766 * driver intervention. For uncorrectable errors PCI AER
2767 * driver calls the following device driver's callbacks
2768 *
2769 * - Fatal Errors - link_reset
2770 * - Non-Fatal Errors - driver's pci_error_detected() which
2771 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
2772 *
2773 * PCI AER driver calls
2774 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
2775 * returns RECOVERED or NEED_RESET if fw_hung
2776 * NEED_RESET - driver's slot_reset()
2777 * DISCONNECT - device is dead & cannot recover
2778 * RECOVERED - driver's pci_resume()
2779 */
2780static pci_ers_result_t
2781qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2782{
2783 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2784
2785 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
2786 ha->host_no, __func__, state);
2787
2788 if (!is_aer_supported(ha))
2789 return PCI_ERS_RESULT_NONE;
2790
2791 switch (state) {
2792 case pci_channel_io_normal:
2793 clear_bit(AF_EEH_BUSY, &ha->flags);
2794 return PCI_ERS_RESULT_CAN_RECOVER;
2795 case pci_channel_io_frozen:
2796 set_bit(AF_EEH_BUSY, &ha->flags);
2797 qla4xxx_mailbox_premature_completion(ha);
2798 qla4xxx_free_irqs(ha);
2799 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002800 /* Return back all IOs */
2801 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302802 return PCI_ERS_RESULT_NEED_RESET;
2803 case pci_channel_io_perm_failure:
2804 set_bit(AF_EEH_BUSY, &ha->flags);
2805 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
2806 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2807 return PCI_ERS_RESULT_DISCONNECT;
2808 }
2809 return PCI_ERS_RESULT_NEED_RESET;
2810}
2811
2812/**
2813 * qla4xxx_pci_mmio_enabled() gets called if
2814 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
2815 * and read/write to the device still works.
2816 **/
2817static pci_ers_result_t
2818qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
2819{
2820 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2821
2822 if (!is_aer_supported(ha))
2823 return PCI_ERS_RESULT_NONE;
2824
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002825 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302826}
2827
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002828static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05302829{
2830 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002831 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302832 int fn;
2833 struct pci_dev *other_pdev = NULL;
2834
2835 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
2836
2837 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2838
2839 if (test_bit(AF_ONLINE, &ha->flags)) {
2840 clear_bit(AF_ONLINE, &ha->flags);
2841 qla4xxx_mark_all_devices_missing(ha);
2842 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302843 }
2844
2845 fn = PCI_FUNC(ha->pdev->devfn);
2846 while (fn > 0) {
2847 fn--;
2848 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
2849 "func %x\n", ha->host_no, __func__, fn);
2850 /* Get the pci device given the domain, bus,
2851 * slot/function number */
2852 other_pdev =
2853 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2854 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2855 fn));
2856
2857 if (!other_pdev)
2858 continue;
2859
2860 if (atomic_read(&other_pdev->enable_cnt)) {
2861 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
2862 "func in enabled state%x\n", ha->host_no,
2863 __func__, fn);
2864 pci_dev_put(other_pdev);
2865 break;
2866 }
2867 pci_dev_put(other_pdev);
2868 }
2869
2870 /* The first function on the card, the reset owner will
2871 * start & initialize the firmware. The other functions
2872 * on the card will reset the firmware context
2873 */
2874 if (!fn) {
2875 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
2876 "0x%x is the owner\n", ha->host_no, __func__,
2877 ha->pdev->devfn);
2878
2879 qla4_8xxx_idc_lock(ha);
2880 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2881 QLA82XX_DEV_COLD);
2882
2883 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
2884 QLA82XX_IDC_VERSION);
2885
2886 qla4_8xxx_idc_unlock(ha);
2887 clear_bit(AF_FW_RECOVERY, &ha->flags);
2888 rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
2889 qla4_8xxx_idc_lock(ha);
2890
2891 if (rval != QLA_SUCCESS) {
2892 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2893 "FAILED\n", ha->host_no, __func__);
2894 qla4_8xxx_clear_drv_active(ha);
2895 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2896 QLA82XX_DEV_FAILED);
2897 } else {
2898 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2899 "READY\n", ha->host_no, __func__);
2900 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2901 QLA82XX_DEV_READY);
2902 /* Clear driver state register */
2903 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
2904 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002905 ret = qla4xxx_request_irqs(ha);
2906 if (ret) {
2907 ql4_printk(KERN_WARNING, ha, "Failed to "
2908 "reserve interrupt %d already in use.\n",
2909 ha->pdev->irq);
2910 rval = QLA_ERROR;
2911 } else {
2912 ha->isp_ops->enable_intrs(ha);
2913 rval = QLA_SUCCESS;
2914 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302915 }
2916 qla4_8xxx_idc_unlock(ha);
2917 } else {
2918 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
2919 "the reset owner\n", ha->host_no, __func__,
2920 ha->pdev->devfn);
2921 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
2922 QLA82XX_DEV_READY)) {
2923 clear_bit(AF_FW_RECOVERY, &ha->flags);
2924 rval = qla4xxx_initialize_adapter(ha,
2925 PRESERVE_DDB_LIST);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002926 if (rval == QLA_SUCCESS) {
2927 ret = qla4xxx_request_irqs(ha);
2928 if (ret) {
2929 ql4_printk(KERN_WARNING, ha, "Failed to"
2930 " reserve interrupt %d already in"
2931 " use.\n", ha->pdev->irq);
2932 rval = QLA_ERROR;
2933 } else {
2934 ha->isp_ops->enable_intrs(ha);
2935 rval = QLA_SUCCESS;
2936 }
2937 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302938 qla4_8xxx_idc_lock(ha);
2939 qla4_8xxx_set_drv_active(ha);
2940 qla4_8xxx_idc_unlock(ha);
2941 }
2942 }
2943 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2944 return rval;
2945}
2946
2947static pci_ers_result_t
2948qla4xxx_pci_slot_reset(struct pci_dev *pdev)
2949{
2950 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
2951 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2952 int rc;
2953
2954 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
2955 ha->host_no, __func__);
2956
2957 if (!is_aer_supported(ha))
2958 return PCI_ERS_RESULT_NONE;
2959
2960 /* Restore the saved state of PCIe device -
2961 * BAR registers, PCI Config space, PCIX, MSI,
2962 * IOV states
2963 */
2964 pci_restore_state(pdev);
2965
2966 /* pci_restore_state() clears the saved_state flag of the device
2967 * save restored state which resets saved_state flag
2968 */
2969 pci_save_state(pdev);
2970
2971 /* Initialize device or resume if in suspended state */
2972 rc = pci_enable_device(pdev);
2973 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002974 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05302975 "device after reset\n", ha->host_no, __func__);
2976 goto exit_slot_reset;
2977 }
2978
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002979 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302980
2981 if (is_qla8022(ha)) {
2982 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
2983 ret = PCI_ERS_RESULT_RECOVERED;
2984 goto exit_slot_reset;
2985 } else
2986 goto exit_slot_reset;
2987 }
2988
2989exit_slot_reset:
2990 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
2991 "device after reset\n", ha->host_no, __func__, ret);
2992 return ret;
2993}
2994
2995static void
2996qla4xxx_pci_resume(struct pci_dev *pdev)
2997{
2998 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2999 int ret;
3000
3001 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
3002 ha->host_no, __func__);
3003
3004 ret = qla4xxx_wait_for_hba_online(ha);
3005 if (ret != QLA_SUCCESS) {
3006 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
3007 "resume I/O from slot/link_reset\n", ha->host_no,
3008 __func__);
3009 }
3010
3011 pci_cleanup_aer_uncorrect_error_status(pdev);
3012 clear_bit(AF_EEH_BUSY, &ha->flags);
3013}
3014
3015static struct pci_error_handlers qla4xxx_err_handler = {
3016 .error_detected = qla4xxx_pci_error_detected,
3017 .mmio_enabled = qla4xxx_pci_mmio_enabled,
3018 .slot_reset = qla4xxx_pci_slot_reset,
3019 .resume = qla4xxx_pci_resume,
3020};
3021
David Somayajuluafaf5a22006-09-19 10:28:00 -07003022static struct pci_device_id qla4xxx_pci_tbl[] = {
3023 {
3024 .vendor = PCI_VENDOR_ID_QLOGIC,
3025 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
3026 .subvendor = PCI_ANY_ID,
3027 .subdevice = PCI_ANY_ID,
3028 },
3029 {
3030 .vendor = PCI_VENDOR_ID_QLOGIC,
3031 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
3032 .subvendor = PCI_ANY_ID,
3033 .subdevice = PCI_ANY_ID,
3034 },
David C Somayajulud9150582006-11-15 17:38:40 -08003035 {
3036 .vendor = PCI_VENDOR_ID_QLOGIC,
3037 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
3038 .subvendor = PCI_ANY_ID,
3039 .subdevice = PCI_ANY_ID,
3040 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303041 {
3042 .vendor = PCI_VENDOR_ID_QLOGIC,
3043 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
3044 .subvendor = PCI_ANY_ID,
3045 .subdevice = PCI_ANY_ID,
3046 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07003047 {0, 0},
3048};
3049MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
3050
Adrian Bunk47975472007-04-26 00:35:16 -07003051static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003052 .name = DRIVER_NAME,
3053 .id_table = qla4xxx_pci_tbl,
3054 .probe = qla4xxx_probe_adapter,
3055 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05303056 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003057};
3058
3059static int __init qla4xxx_module_init(void)
3060{
3061 int ret;
3062
3063 /* Allocate cache for SRBs. */
3064 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003065 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003066 if (srb_cachep == NULL) {
3067 printk(KERN_ERR
3068 "%s: Unable to allocate SRB cache..."
3069 "Failing load!\n", DRIVER_NAME);
3070 ret = -ENOMEM;
3071 goto no_srp_cache;
3072 }
3073
3074 /* Derive version string. */
3075 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003076 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003077 strcat(qla4xxx_version_str, "-debug");
3078
3079 qla4xxx_scsi_transport =
3080 iscsi_register_transport(&qla4xxx_iscsi_transport);
3081 if (!qla4xxx_scsi_transport){
3082 ret = -ENODEV;
3083 goto release_srb_cache;
3084 }
3085
David Somayajuluafaf5a22006-09-19 10:28:00 -07003086 ret = pci_register_driver(&qla4xxx_pci_driver);
3087 if (ret)
3088 goto unregister_transport;
3089
3090 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
3091 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05003092
David Somayajuluafaf5a22006-09-19 10:28:00 -07003093unregister_transport:
3094 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3095release_srb_cache:
3096 kmem_cache_destroy(srb_cachep);
3097no_srp_cache:
3098 return ret;
3099}
3100
3101static void __exit qla4xxx_module_exit(void)
3102{
David Somayajuluafaf5a22006-09-19 10:28:00 -07003103 pci_unregister_driver(&qla4xxx_pci_driver);
3104 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3105 kmem_cache_destroy(srb_cachep);
3106}
3107
3108module_init(qla4xxx_module_init);
3109module_exit(qla4xxx_module_exit);
3110
3111MODULE_AUTHOR("QLogic Corporation");
3112MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
3113MODULE_LICENSE("GPL");
3114MODULE_VERSION(QLA4XXX_DRIVER_VERSION);