blob: 4e47bb1a85d1da917cb96be7bcbb542ea854a5f8 [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,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500134 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700135};
136
137static struct iscsi_transport qla4xxx_iscsi_transport = {
138 .owner = THIS_MODULE,
139 .name = DRIVER_NAME,
Mike Christied8196ed2007-05-30 12:57:25 -0500140 .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD |
141 CAP_DATA_PATH_OFFLOAD,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700142 .tgt_dscvr = qla4xxx_tgt_dscvr,
Mike Christie3128c6c2011-07-25 13:48:42 -0500143 .attr_is_visible = ql4_attr_is_visible,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700144 .get_conn_param = qla4xxx_conn_get_param,
145 .get_session_param = qla4xxx_sess_get_param,
Mike Christieaa1e93a2007-05-30 12:57:09 -0500146 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500147 .set_iface_param = qla4xxx_iface_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700148 .session_recovery_timedout = qla4xxx_recovery_timedout,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500149 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500150 .bsg_request = qla4xxx_bsg_request,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700151};
152
153static struct scsi_transport_template *qla4xxx_scsi_transport;
154
Mike Christie3128c6c2011-07-25 13:48:42 -0500155static mode_t ql4_attr_is_visible(int param_type, int param)
156{
157 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500158 case ISCSI_HOST_PARAM:
159 switch (param) {
160 case ISCSI_HOST_PARAM_HWADDRESS:
161 case ISCSI_HOST_PARAM_IPADDRESS:
162 case ISCSI_HOST_PARAM_INITIATOR_NAME:
163 return S_IRUGO;
164 default:
165 return 0;
166 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500167 case ISCSI_PARAM:
168 switch (param) {
169 case ISCSI_PARAM_CONN_ADDRESS:
170 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500171 case ISCSI_PARAM_TARGET_NAME:
172 case ISCSI_PARAM_TPGT:
173 case ISCSI_PARAM_TARGET_ALIAS:
Mike Christie3128c6c2011-07-25 13:48:42 -0500174 return S_IRUGO;
175 default:
176 return 0;
177 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500178 case ISCSI_NET_PARAM:
179 switch (param) {
180 case ISCSI_NET_PARAM_IPV4_ADDR:
181 case ISCSI_NET_PARAM_IPV4_SUBNET:
182 case ISCSI_NET_PARAM_IPV4_GW:
183 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
184 case ISCSI_NET_PARAM_IFACE_ENABLE:
185 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
186 case ISCSI_NET_PARAM_IPV6_ADDR:
187 case ISCSI_NET_PARAM_IPV6_ROUTER:
188 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
189 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500190 case ISCSI_NET_PARAM_VLAN_ID:
191 case ISCSI_NET_PARAM_VLAN_PRIORITY:
192 case ISCSI_NET_PARAM_VLAN_ENABLED:
Mike Christieb78dbba2011-07-25 13:48:44 -0500193 return S_IRUGO;
194 default:
195 return 0;
196 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500197 }
198
199 return 0;
200}
201
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500202static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
203 enum iscsi_param_type param_type,
204 int param, char *buf)
205{
206 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
207 struct scsi_qla_host *ha = to_qla_host(shost);
208 int len = -ENOSYS;
209
210 if (param_type != ISCSI_NET_PARAM)
211 return -ENOSYS;
212
213 switch (param) {
214 case ISCSI_NET_PARAM_IPV4_ADDR:
215 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
216 break;
217 case ISCSI_NET_PARAM_IPV4_SUBNET:
218 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
219 break;
220 case ISCSI_NET_PARAM_IPV4_GW:
221 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
222 break;
223 case ISCSI_NET_PARAM_IFACE_ENABLE:
224 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
225 len = sprintf(buf, "%s\n",
226 (ha->ip_config.ipv4_options &
227 IPOPT_IPV4_PROTOCOL_ENABLE) ?
228 "enabled" : "disabled");
229 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
230 len = sprintf(buf, "%s\n",
231 (ha->ip_config.ipv6_options &
232 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
233 "enabled" : "disabled");
234 break;
235 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
236 len = sprintf(buf, "%s\n",
237 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
238 "dhcp" : "static");
239 break;
240 case ISCSI_NET_PARAM_IPV6_ADDR:
241 if (iface->iface_num == 0)
242 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
243 if (iface->iface_num == 1)
244 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
245 break;
246 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
247 len = sprintf(buf, "%pI6\n",
248 &ha->ip_config.ipv6_link_local_addr);
249 break;
250 case ISCSI_NET_PARAM_IPV6_ROUTER:
251 len = sprintf(buf, "%pI6\n",
252 &ha->ip_config.ipv6_default_router_addr);
253 break;
254 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
255 len = sprintf(buf, "%s\n",
256 (ha->ip_config.ipv6_addl_options &
257 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
258 "nd" : "static");
259 break;
260 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
261 len = sprintf(buf, "%s\n",
262 (ha->ip_config.ipv6_addl_options &
263 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
264 "auto" : "static");
265 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500266 case ISCSI_NET_PARAM_VLAN_ID:
267 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
268 len = sprintf(buf, "%d\n",
269 (ha->ip_config.ipv4_vlan_tag &
270 ISCSI_MAX_VLAN_ID));
271 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
272 len = sprintf(buf, "%d\n",
273 (ha->ip_config.ipv6_vlan_tag &
274 ISCSI_MAX_VLAN_ID));
275 break;
276 case ISCSI_NET_PARAM_VLAN_PRIORITY:
277 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
278 len = sprintf(buf, "%d\n",
279 ((ha->ip_config.ipv4_vlan_tag >> 13) &
280 ISCSI_MAX_VLAN_PRIORITY));
281 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
282 len = sprintf(buf, "%d\n",
283 ((ha->ip_config.ipv6_vlan_tag >> 13) &
284 ISCSI_MAX_VLAN_PRIORITY));
285 break;
286 case ISCSI_NET_PARAM_VLAN_ENABLED:
287 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
288 len = sprintf(buf, "%s\n",
289 (ha->ip_config.ipv4_options &
290 IPOPT_VLAN_TAGGING_ENABLE) ?
291 "enabled" : "disabled");
292 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
293 len = sprintf(buf, "%s\n",
294 (ha->ip_config.ipv6_options &
295 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
296 "enabled" : "disabled");
297 break;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500298 default:
299 len = -ENOSYS;
300 }
301
302 return len;
303}
304
Mike Christie5c656af2009-07-15 15:02:59 -0500305static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
306{
307 struct iscsi_cls_session *session;
308 struct ddb_entry *ddb_entry;
309
310 session = starget_to_session(scsi_target(sc->device));
311 ddb_entry = session->dd_data;
312
313 /* if we are not logged in then the LLD is going to clean up the cmd */
314 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
315 return BLK_EH_RESET_TIMER;
316 else
317 return BLK_EH_NOT_HANDLED;
318}
319
David Somayajuluafaf5a22006-09-19 10:28:00 -0700320static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
321{
322 struct ddb_entry *ddb_entry = session->dd_data;
323 struct scsi_qla_host *ha = ddb_entry->ha;
324
Mike Christie568d3032008-01-31 13:36:47 -0600325 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
326 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700327
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530328 DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout "
Mike Christie568d3032008-01-31 13:36:47 -0600329 "of (%d) secs exhausted, marking device DEAD.\n",
330 ha->host_no, __func__, ddb_entry->fw_ddb_index,
Vikas Chaudhary30387272011-03-21 03:34:32 -0700331 ddb_entry->sess->recovery_tmo));
Mike Christie568d3032008-01-31 13:36:47 -0600332 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700333}
334
Mike Christieaa1e93a2007-05-30 12:57:09 -0500335static int qla4xxx_host_get_param(struct Scsi_Host *shost,
336 enum iscsi_host_param param, char *buf)
337{
338 struct scsi_qla_host *ha = to_qla_host(shost);
339 int len;
340
341 switch (param) {
342 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800343 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500344 break;
Mike Christie22236962007-05-30 12:57:24 -0500345 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500346 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -0500347 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500348 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500349 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500350 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500351 default:
352 return -ENOSYS;
353 }
354
355 return len;
356}
357
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500358static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
359{
360 if (ha->iface_ipv4)
361 return;
362
363 /* IPv4 */
364 ha->iface_ipv4 = iscsi_create_iface(ha->host,
365 &qla4xxx_iscsi_transport,
366 ISCSI_IFACE_TYPE_IPV4, 0, 0);
367 if (!ha->iface_ipv4)
368 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
369 "iface0.\n");
370}
371
372static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
373{
374 if (!ha->iface_ipv6_0)
375 /* IPv6 iface-0 */
376 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
377 &qla4xxx_iscsi_transport,
378 ISCSI_IFACE_TYPE_IPV6, 0,
379 0);
380 if (!ha->iface_ipv6_0)
381 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
382 "iface0.\n");
383
384 if (!ha->iface_ipv6_1)
385 /* IPv6 iface-1 */
386 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
387 &qla4xxx_iscsi_transport,
388 ISCSI_IFACE_TYPE_IPV6, 1,
389 0);
390 if (!ha->iface_ipv6_1)
391 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
392 "iface1.\n");
393}
394
395static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
396{
397 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
398 qla4xxx_create_ipv4_iface(ha);
399
400 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
401 qla4xxx_create_ipv6_iface(ha);
402}
403
404static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
405{
406 if (ha->iface_ipv4) {
407 iscsi_destroy_iface(ha->iface_ipv4);
408 ha->iface_ipv4 = NULL;
409 }
410}
411
412static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
413{
414 if (ha->iface_ipv6_0) {
415 iscsi_destroy_iface(ha->iface_ipv6_0);
416 ha->iface_ipv6_0 = NULL;
417 }
418 if (ha->iface_ipv6_1) {
419 iscsi_destroy_iface(ha->iface_ipv6_1);
420 ha->iface_ipv6_1 = NULL;
421 }
422}
423
424static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
425{
426 qla4xxx_destroy_ipv4_iface(ha);
427 qla4xxx_destroy_ipv6_iface(ha);
428}
429
Mike Christied00efe32011-07-25 13:48:38 -0500430static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
431 struct iscsi_iface_param_info *iface_param,
432 struct addr_ctrl_blk *init_fw_cb)
433{
434 /*
435 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
436 * iface_num 1 is valid only for IPv6 Addr.
437 */
438 switch (iface_param->param) {
439 case ISCSI_NET_PARAM_IPV6_ADDR:
440 if (iface_param->iface_num & 0x1)
441 /* IPv6 Addr 1 */
442 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
443 sizeof(init_fw_cb->ipv6_addr1));
444 else
445 /* IPv6 Addr 0 */
446 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
447 sizeof(init_fw_cb->ipv6_addr0));
448 break;
449 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
450 if (iface_param->iface_num & 0x1)
451 break;
452 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
453 sizeof(init_fw_cb->ipv6_if_id));
454 break;
455 case ISCSI_NET_PARAM_IPV6_ROUTER:
456 if (iface_param->iface_num & 0x1)
457 break;
458 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
459 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
460 break;
461 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
462 /* Autocfg applies to even interface */
463 if (iface_param->iface_num & 0x1)
464 break;
465
466 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
467 init_fw_cb->ipv6_addtl_opts &=
468 cpu_to_le16(
469 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
470 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
471 init_fw_cb->ipv6_addtl_opts |=
472 cpu_to_le16(
473 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
474 else
475 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
476 "IPv6 addr\n");
477 break;
478 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
479 /* Autocfg applies to even interface */
480 if (iface_param->iface_num & 0x1)
481 break;
482
483 if (iface_param->value[0] ==
484 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
485 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
486 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
487 else if (iface_param->value[0] ==
488 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
489 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
490 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
491 else
492 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
493 "IPv6 linklocal addr\n");
494 break;
495 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
496 /* Autocfg applies to even interface */
497 if (iface_param->iface_num & 0x1)
498 break;
499
500 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
501 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
502 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
503 break;
504 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500505 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500506 init_fw_cb->ipv6_opts |=
507 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500508 qla4xxx_create_ipv6_iface(ha);
509 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500510 init_fw_cb->ipv6_opts &=
511 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
512 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500513 qla4xxx_destroy_ipv6_iface(ha);
514 }
Mike Christied00efe32011-07-25 13:48:38 -0500515 break;
516 case ISCSI_NET_PARAM_VLAN_ID:
517 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
518 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500519 init_fw_cb->ipv6_vlan_tag =
520 cpu_to_be16(*(uint16_t *)iface_param->value);
521 break;
522 case ISCSI_NET_PARAM_VLAN_ENABLED:
523 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
524 init_fw_cb->ipv6_opts |=
525 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
526 else
527 init_fw_cb->ipv6_opts &=
528 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500529 break;
530 default:
531 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
532 iface_param->param);
533 break;
534 }
535}
536
537static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
538 struct iscsi_iface_param_info *iface_param,
539 struct addr_ctrl_blk *init_fw_cb)
540{
541 switch (iface_param->param) {
542 case ISCSI_NET_PARAM_IPV4_ADDR:
543 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
544 sizeof(init_fw_cb->ipv4_addr));
545 break;
546 case ISCSI_NET_PARAM_IPV4_SUBNET:
547 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
548 sizeof(init_fw_cb->ipv4_subnet));
549 break;
550 case ISCSI_NET_PARAM_IPV4_GW:
551 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
552 sizeof(init_fw_cb->ipv4_gw_addr));
553 break;
554 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
555 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
556 init_fw_cb->ipv4_tcp_opts |=
557 cpu_to_le16(TCPOPT_DHCP_ENABLE);
558 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
559 init_fw_cb->ipv4_tcp_opts &=
560 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
561 else
562 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
563 break;
564 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500565 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500566 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500567 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500568 qla4xxx_create_ipv4_iface(ha);
569 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500570 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500571 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -0500572 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500573 qla4xxx_destroy_ipv4_iface(ha);
574 }
Mike Christied00efe32011-07-25 13:48:38 -0500575 break;
576 case ISCSI_NET_PARAM_VLAN_ID:
577 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
578 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500579 init_fw_cb->ipv4_vlan_tag =
580 cpu_to_be16(*(uint16_t *)iface_param->value);
581 break;
582 case ISCSI_NET_PARAM_VLAN_ENABLED:
583 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
584 init_fw_cb->ipv4_ip_opts |=
585 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
586 else
587 init_fw_cb->ipv4_ip_opts &=
588 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500589 break;
590 default:
591 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
592 iface_param->param);
593 break;
594 }
595}
596
597static void
598qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
599{
600 struct addr_ctrl_blk_def *acb;
601 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
602 memset(acb->reserved1, 0, sizeof(acb->reserved1));
603 memset(acb->reserved2, 0, sizeof(acb->reserved2));
604 memset(acb->reserved3, 0, sizeof(acb->reserved3));
605 memset(acb->reserved4, 0, sizeof(acb->reserved4));
606 memset(acb->reserved5, 0, sizeof(acb->reserved5));
607 memset(acb->reserved6, 0, sizeof(acb->reserved6));
608 memset(acb->reserved7, 0, sizeof(acb->reserved7));
609 memset(acb->reserved8, 0, sizeof(acb->reserved8));
610 memset(acb->reserved9, 0, sizeof(acb->reserved9));
611 memset(acb->reserved10, 0, sizeof(acb->reserved10));
612 memset(acb->reserved11, 0, sizeof(acb->reserved11));
613 memset(acb->reserved12, 0, sizeof(acb->reserved12));
614 memset(acb->reserved13, 0, sizeof(acb->reserved13));
615 memset(acb->reserved14, 0, sizeof(acb->reserved14));
616 memset(acb->reserved15, 0, sizeof(acb->reserved15));
617}
618
619static int
620qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
621{
622 struct scsi_qla_host *ha = to_qla_host(shost);
623 int rval = 0;
624 struct iscsi_iface_param_info *iface_param = NULL;
625 struct addr_ctrl_blk *init_fw_cb = NULL;
626 dma_addr_t init_fw_cb_dma;
627 uint32_t mbox_cmd[MBOX_REG_COUNT];
628 uint32_t mbox_sts[MBOX_REG_COUNT];
629 uint32_t total_param_count;
630 uint32_t length;
631
632 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
633 sizeof(struct addr_ctrl_blk),
634 &init_fw_cb_dma, GFP_KERNEL);
635 if (!init_fw_cb) {
636 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
637 __func__);
638 return -ENOMEM;
639 }
640
641 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
642 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
643 memset(&mbox_sts, 0, sizeof(mbox_sts));
644
645 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
646 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
647 rval = -EIO;
648 goto exit_init_fw_cb;
649 }
650
651 total_param_count = count;
652 iface_param = (struct iscsi_iface_param_info *)data;
653
654 for ( ; total_param_count != 0; total_param_count--) {
655 length = iface_param->len;
656
657 if (iface_param->param_type != ISCSI_NET_PARAM)
658 continue;
659
660 switch (iface_param->iface_type) {
661 case ISCSI_IFACE_TYPE_IPV4:
662 switch (iface_param->iface_num) {
663 case 0:
664 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
665 break;
666 default:
667 /* Cannot have more than one IPv4 interface */
668 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
669 "number = %d\n",
670 iface_param->iface_num);
671 break;
672 }
673 break;
674 case ISCSI_IFACE_TYPE_IPV6:
675 switch (iface_param->iface_num) {
676 case 0:
677 case 1:
678 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
679 break;
680 default:
681 /* Cannot have more than two IPv6 interface */
682 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
683 "number = %d\n",
684 iface_param->iface_num);
685 break;
686 }
687 break;
688 default:
689 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
690 break;
691 }
692
693 iface_param = (struct iscsi_iface_param_info *)
694 ((uint8_t *)iface_param +
695 sizeof(struct iscsi_iface_param_info) + length);
696 }
697
698 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
699
700 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
701 sizeof(struct addr_ctrl_blk),
702 FLASH_OPT_RMW_COMMIT);
703 if (rval != QLA_SUCCESS) {
704 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
705 __func__);
706 rval = -EIO;
707 goto exit_init_fw_cb;
708 }
709
710 qla4xxx_disable_acb(ha);
711
712 qla4xxx_initcb_to_acb(init_fw_cb);
713
714 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
715 if (rval != QLA_SUCCESS) {
716 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
717 __func__);
718 rval = -EIO;
719 goto exit_init_fw_cb;
720 }
721
722 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
723 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
724 init_fw_cb_dma);
725
726exit_init_fw_cb:
727 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
728 init_fw_cb, init_fw_cb_dma);
729
730 return rval;
731}
732
David Somayajuluafaf5a22006-09-19 10:28:00 -0700733static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
734 enum iscsi_param param, char *buf)
735{
736 struct ddb_entry *ddb_entry = sess->dd_data;
737 int len;
738
739 switch (param) {
740 case ISCSI_PARAM_TARGET_NAME:
741 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
742 ddb_entry->iscsi_name);
743 break;
744 case ISCSI_PARAM_TPGT:
745 len = sprintf(buf, "%u\n", ddb_entry->tpgt);
746 break;
Vikas Chaudhary3b2bef12010-07-10 14:51:30 +0530747 case ISCSI_PARAM_TARGET_ALIAS:
748 len = snprintf(buf, PAGE_SIZE - 1, "%s\n",
749 ddb_entry->iscsi_alias);
750 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700751 default:
752 return -ENOSYS;
753 }
754
755 return len;
756}
757
758static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
759 enum iscsi_param param, char *buf)
760{
761 struct iscsi_cls_session *session;
762 struct ddb_entry *ddb_entry;
763 int len;
764
765 session = iscsi_dev_to_session(conn->dev.parent);
766 ddb_entry = session->dd_data;
767
768 switch (param) {
769 case ISCSI_PARAM_CONN_PORT:
770 len = sprintf(buf, "%hu\n", ddb_entry->port);
771 break;
772 case ISCSI_PARAM_CONN_ADDRESS:
773 /* TODO: what are the ipv6 bits */
Harvey Harrison63779432008-10-31 00:56:00 -0700774 len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700775 break;
776 default:
777 return -ENOSYS;
778 }
779
780 return len;
781}
782
Mike Christie2174a042007-05-30 12:57:10 -0500783static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
784 enum iscsi_tgt_dscvr type, uint32_t enable,
785 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700786{
787 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700788 struct sockaddr_in *addr;
789 struct sockaddr_in6 *addr6;
790 int ret = 0;
791
David Somayajuluafaf5a22006-09-19 10:28:00 -0700792 ha = (struct scsi_qla_host *) shost->hostdata;
793
794 switch (type) {
795 case ISCSI_TGT_DSCVR_SEND_TARGETS:
796 if (dst_addr->sa_family == AF_INET) {
797 addr = (struct sockaddr_in *)dst_addr;
798 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
799 addr->sin_port) != QLA_SUCCESS)
800 ret = -EIO;
801 } else if (dst_addr->sa_family == AF_INET6) {
802 /*
803 * TODO: fix qla4xxx_send_tgts
804 */
805 addr6 = (struct sockaddr_in6 *)dst_addr;
806 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
807 addr6->sin6_port) != QLA_SUCCESS)
808 ret = -EIO;
809 } else
810 ret = -ENOSYS;
811 break;
812 default:
813 ret = -ENOSYS;
814 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700815 return ret;
816}
817
818void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
819{
820 if (!ddb_entry->sess)
821 return;
822
823 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -0600824 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700825 iscsi_remove_session(ddb_entry->sess);
826 }
827 iscsi_free_session(ddb_entry->sess);
828}
829
830int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
831{
832 int err;
833
Vikas Chaudhary30387272011-03-21 03:34:32 -0700834 ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
Vikas Chaudhary3013cea2010-07-30 14:25:46 +0530835
David Somayajuluafaf5a22006-09-19 10:28:00 -0700836 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
837 if (err) {
838 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
839 return err;
840 }
841
Mike Christie5d91e202008-05-21 15:54:01 -0500842 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700843 if (!ddb_entry->conn) {
844 iscsi_remove_session(ddb_entry->sess);
845 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
846 return -ENOMEM;
847 }
Mike Christieb6359302008-01-31 13:36:44 -0600848
849 /* finally ready to go */
850 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700851 return 0;
852}
853
854struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
855{
856 struct ddb_entry *ddb_entry;
857 struct iscsi_cls_session *sess;
858
Mike Christie5d91e202008-05-21 15:54:01 -0500859 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
860 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -0700861 if (!sess)
862 return NULL;
863
864 ddb_entry = sess->dd_data;
865 memset(ddb_entry, 0, sizeof(*ddb_entry));
866 ddb_entry->ha = ha;
867 ddb_entry->sess = sess;
868 return ddb_entry;
869}
870
Mike Christie024f8012008-03-04 13:26:54 -0600871static void qla4xxx_scan_start(struct Scsi_Host *shost)
872{
873 struct scsi_qla_host *ha = shost_priv(shost);
874 struct ddb_entry *ddb_entry, *ddbtemp;
875
876 /* finish setup of sessions that were already setup in firmware */
877 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
878 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
879 qla4xxx_add_sess(ddb_entry);
880 }
881}
882
David Somayajuluafaf5a22006-09-19 10:28:00 -0700883/*
884 * Timer routines
885 */
886
887static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
888 unsigned long interval)
889{
890 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
891 __func__, ha->host->host_no));
892 init_timer(&ha->timer);
893 ha->timer.expires = jiffies + interval * HZ;
894 ha->timer.data = (unsigned long)ha;
895 ha->timer.function = (void (*)(unsigned long))func;
896 add_timer(&ha->timer);
897 ha->timer_active = 1;
898}
899
900static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
901{
902 del_timer_sync(&ha->timer);
903 ha->timer_active = 0;
904}
905
906/***
907 * qla4xxx_mark_device_missing - mark a device as missing.
908 * @ha: Pointer to host adapter structure.
909 * @ddb_entry: Pointer to device database entry
910 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530911 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -0700912 **/
913void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
914 struct ddb_entry *ddb_entry)
915{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530916 if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) {
917 atomic_set(&ddb_entry->state, DDB_STATE_MISSING);
918 DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n",
919 ha->host_no, ddb_entry->fw_ddb_index));
920 } else
921 DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no,
922 ddb_entry->fw_ddb_index))
923
Mike Christieb6359302008-01-31 13:36:44 -0600924 iscsi_block_session(ddb_entry->sess);
Mike Christiee5bd7b52008-09-24 11:46:10 -0500925 iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700926}
927
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530928/**
929 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
930 * @ha: Pointer to host adapter structure.
931 *
932 * This routine marks a device missing and resets the relogin retry count.
933 **/
934void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
935{
936 struct ddb_entry *ddb_entry, *ddbtemp;
937 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
938 qla4xxx_mark_device_missing(ha, ddb_entry);
939 }
940}
941
David Somayajuluafaf5a22006-09-19 10:28:00 -0700942static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
943 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700944 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700945{
946 struct srb *srb;
947
948 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
949 if (!srb)
950 return srb;
951
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530952 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700953 srb->ha = ha;
954 srb->ddb = ddb_entry;
955 srb->cmd = cmd;
956 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +0530957 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700958
959 return srb;
960}
961
962static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
963{
964 struct scsi_cmnd *cmd = srb->cmd;
965
966 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +0900967 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700968 srb->flags &= ~SRB_DMA_VALID;
969 }
Vikas Chaudhary53698872010-04-28 11:41:59 +0530970 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700971}
972
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530973void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700974{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530975 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700976 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530977 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700978
979 qla4xxx_srb_free_dma(ha, srb);
980
981 mempool_free(srb, ha->srb_mempool);
982
983 cmd->scsi_done(cmd);
984}
985
986/**
987 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700988 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -0700989 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -0700990 *
991 * Remarks:
992 * This routine is invoked by Linux to send a SCSI command to the driver.
993 * The mid-level driver tries to ensure that queuecommand never gets
994 * invoked concurrently with itself or the interrupt handler (although
995 * the interrupt handler may call this routine as part of request-
996 * completion handling). Unfortunely, it sometimes calls the scheduler
997 * in interrupt context which is a big NO! NO!.
998 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -0700999static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001000{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001001 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001002 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06001003 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001004 struct srb *srb;
1005 int rval;
1006
Lalit Chandivade2232be02010-07-30 14:38:47 +05301007 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1008 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1009 cmd->result = DID_NO_CONNECT << 16;
1010 else
1011 cmd->result = DID_REQUEUE << 16;
1012 goto qc_fail_command;
1013 }
1014
Mike Christie7fb19212008-01-31 13:36:45 -06001015 if (!sess) {
1016 cmd->result = DID_IMM_RETRY << 16;
1017 goto qc_fail_command;
1018 }
1019
1020 rval = iscsi_session_chkready(sess);
1021 if (rval) {
1022 cmd->result = rval;
1023 goto qc_fail_command;
1024 }
1025
David Somayajuluafaf5a22006-09-19 10:28:00 -07001026 if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1027 if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
1028 cmd->result = DID_NO_CONNECT << 16;
1029 goto qc_fail_command;
1030 }
Mike Christiec5e98e92008-08-17 15:24:39 -05001031 return SCSI_MLQUEUE_TARGET_BUSY;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001032 }
1033
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301034 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1035 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1036 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1037 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1038 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1039 !test_bit(AF_ONLINE, &ha->flags) ||
1040 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08001041 goto qc_host_busy;
1042
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001043 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001044 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001045 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001046
1047 rval = qla4xxx_send_command_to_isp(ha, srb);
1048 if (rval != QLA_SUCCESS)
1049 goto qc_host_busy_free_sp;
1050
David Somayajuluafaf5a22006-09-19 10:28:00 -07001051 return 0;
1052
1053qc_host_busy_free_sp:
1054 qla4xxx_srb_free_dma(ha, srb);
1055 mempool_free(srb, ha->srb_mempool);
1056
David Somayajuluafaf5a22006-09-19 10:28:00 -07001057qc_host_busy:
1058 return SCSI_MLQUEUE_HOST_BUSY;
1059
1060qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001061 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001062
1063 return 0;
1064}
1065
1066/**
1067 * qla4xxx_mem_free - frees memory allocated to adapter
1068 * @ha: Pointer to host adapter structure.
1069 *
1070 * Frees memory previously allocated by qla4xxx_mem_alloc
1071 **/
1072static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1073{
1074 if (ha->queues)
1075 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1076 ha->queues_dma);
1077
1078 ha->queues_len = 0;
1079 ha->queues = NULL;
1080 ha->queues_dma = 0;
1081 ha->request_ring = NULL;
1082 ha->request_dma = 0;
1083 ha->response_ring = NULL;
1084 ha->response_dma = 0;
1085 ha->shadow_regs = NULL;
1086 ha->shadow_regs_dma = 0;
1087
1088 /* Free srb pool. */
1089 if (ha->srb_mempool)
1090 mempool_destroy(ha->srb_mempool);
1091
1092 ha->srb_mempool = NULL;
1093
1094 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301095 if (is_qla8022(ha)) {
1096 if (ha->nx_pcibase)
1097 iounmap(
1098 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301099 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001100 iounmap(ha->reg);
1101 pci_release_regions(ha->pdev);
1102}
1103
1104/**
1105 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1106 * @ha: Pointer to host adapter structure
1107 *
1108 * Allocates DMA memory for request and response queues. Also allocates memory
1109 * for srbs.
1110 **/
1111static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1112{
1113 unsigned long align;
1114
1115 /* Allocate contiguous block of DMA memory for queues. */
1116 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1117 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1118 sizeof(struct shadow_regs) +
1119 MEM_ALIGN_VALUE +
1120 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1121 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1122 &ha->queues_dma, GFP_KERNEL);
1123 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301124 ql4_printk(KERN_WARNING, ha,
1125 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001126
1127 goto mem_alloc_error_exit;
1128 }
1129 memset(ha->queues, 0, ha->queues_len);
1130
1131 /*
1132 * As per RISC alignment requirements -- the bus-address must be a
1133 * multiple of the request-ring size (in bytes).
1134 */
1135 align = 0;
1136 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1137 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1138 (MEM_ALIGN_VALUE - 1));
1139
1140 /* Update request and response queue pointers. */
1141 ha->request_dma = ha->queues_dma + align;
1142 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1143 ha->response_dma = ha->queues_dma + align +
1144 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1145 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1146 (REQUEST_QUEUE_DEPTH *
1147 QUEUE_SIZE));
1148 ha->shadow_regs_dma = ha->queues_dma + align +
1149 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1150 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1151 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1152 (REQUEST_QUEUE_DEPTH *
1153 QUEUE_SIZE) +
1154 (RESPONSE_QUEUE_DEPTH *
1155 QUEUE_SIZE));
1156
1157 /* Allocate memory for srb pool. */
1158 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1159 mempool_free_slab, srb_cachep);
1160 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301161 ql4_printk(KERN_WARNING, ha,
1162 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001163
1164 goto mem_alloc_error_exit;
1165 }
1166
1167 return QLA_SUCCESS;
1168
1169mem_alloc_error_exit:
1170 qla4xxx_mem_free(ha);
1171 return QLA_ERROR;
1172}
1173
1174/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301175 * qla4_8xxx_check_fw_alive - Check firmware health
1176 * @ha: Pointer to host adapter structure.
1177 *
1178 * Context: Interrupt
1179 **/
1180static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
1181{
1182 uint32_t fw_heartbeat_counter, halt_status;
1183
1184 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05301185 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1186 if (fw_heartbeat_counter == 0xffffffff) {
1187 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
1188 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1189 ha->host_no, __func__));
1190 return;
1191 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301192
1193 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
1194 ha->seconds_since_last_heartbeat++;
1195 /* FW not alive after 2 seconds */
1196 if (ha->seconds_since_last_heartbeat == 2) {
1197 ha->seconds_since_last_heartbeat = 0;
1198 halt_status = qla4_8xxx_rd_32(ha,
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07001199 QLA82XX_PEG_HALT_STATUS1);
1200
1201 ql4_printk(KERN_INFO, ha,
1202 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1203 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1204 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1205 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1206 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1207 ha->host_no, __func__, halt_status,
1208 qla4_8xxx_rd_32(ha,
1209 QLA82XX_PEG_HALT_STATUS2),
1210 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
1211 0x3c),
1212 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
1213 0x3c),
1214 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
1215 0x3c),
1216 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
1217 0x3c),
1218 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
1219 0x3c));
Nilesh Javali21033632010-07-30 14:28:07 +05301220
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301221 /* Since we cannot change dev_state in interrupt
1222 * context, set appropriate DPC flag then wakeup
1223 * DPC */
1224 if (halt_status & HALT_STATUS_UNRECOVERABLE)
1225 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1226 else {
1227 printk("scsi%ld: %s: detect abort needed!\n",
1228 ha->host_no, __func__);
1229 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1230 }
1231 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +05301232 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301233 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07001234 } else
1235 ha->seconds_since_last_heartbeat = 0;
1236
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301237 ha->fw_heartbeat_counter = fw_heartbeat_counter;
1238}
1239
1240/**
1241 * qla4_8xxx_watchdog - Poll dev state
1242 * @ha: Pointer to host adapter structure.
1243 *
1244 * Context: Interrupt
1245 **/
1246void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
1247{
1248 uint32_t dev_state;
1249
1250 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1251
1252 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08001253 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1254 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07001255 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301256 if (dev_state == QLA82XX_DEV_NEED_RESET &&
1257 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001258 if (!ql4xdontresethba) {
1259 ql4_printk(KERN_INFO, ha, "%s: HW State: "
1260 "NEED RESET!\n", __func__);
1261 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1262 qla4xxx_wake_dpc(ha);
1263 qla4xxx_mailbox_premature_completion(ha);
1264 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301265 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
1266 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001267 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
1268 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301269 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
1270 qla4xxx_wake_dpc(ha);
1271 } else {
1272 /* Check firmware health */
1273 qla4_8xxx_check_fw_alive(ha);
1274 }
1275 }
1276}
1277
1278/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001279 * qla4xxx_timer - checks every second for work to do.
1280 * @ha: Pointer to host adapter structure.
1281 **/
1282static void qla4xxx_timer(struct scsi_qla_host *ha)
1283{
1284 struct ddb_entry *ddb_entry, *dtemp;
1285 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301286 uint16_t w;
1287
1288 /* If we are in the middle of AER/EEH processing
1289 * skip any processing and reschedule the timer
1290 */
1291 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1292 mod_timer(&ha->timer, jiffies + HZ);
1293 return;
1294 }
1295
1296 /* Hardware read to trigger an EEH error during mailbox waits. */
1297 if (!pci_channel_offline(ha->pdev))
1298 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001299
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301300 if (is_qla8022(ha)) {
1301 qla4_8xxx_watchdog(ha);
1302 }
1303
David Somayajuluafaf5a22006-09-19 10:28:00 -07001304 /* Search for relogin's to time-out and port down retry. */
1305 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1306 /* Count down time between sending relogins */
1307 if (adapter_up(ha) &&
1308 !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
1309 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
1310 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
1311 INVALID_ENTRY) {
1312 if (atomic_read(&ddb_entry->retry_relogin_timer)
1313 == 0) {
1314 atomic_set(&ddb_entry->
1315 retry_relogin_timer,
1316 INVALID_ENTRY);
1317 set_bit(DPC_RELOGIN_DEVICE,
1318 &ha->dpc_flags);
1319 set_bit(DF_RELOGIN, &ddb_entry->flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301320 DEBUG2(printk("scsi%ld: %s: ddb [%d]"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001321 " login device\n",
1322 ha->host_no, __func__,
1323 ddb_entry->fw_ddb_index));
1324 } else
1325 atomic_dec(&ddb_entry->
1326 retry_relogin_timer);
1327 }
1328 }
1329
1330 /* Wait for relogin to timeout */
1331 if (atomic_read(&ddb_entry->relogin_timer) &&
1332 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
1333 /*
1334 * If the relogin times out and the device is
1335 * still NOT ONLINE then try and relogin again.
1336 */
1337 if (atomic_read(&ddb_entry->state) !=
1338 DDB_STATE_ONLINE &&
1339 ddb_entry->fw_ddb_device_state ==
1340 DDB_DS_SESSION_FAILED) {
1341 /* Reset retry relogin timer */
1342 atomic_inc(&ddb_entry->relogin_retry_count);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301343 DEBUG2(printk("scsi%ld: ddb [%d] relogin"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001344 " timed out-retrying"
1345 " relogin (%d)\n",
1346 ha->host_no,
1347 ddb_entry->fw_ddb_index,
1348 atomic_read(&ddb_entry->
1349 relogin_retry_count))
1350 );
1351 start_dpc++;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301352 DEBUG(printk("scsi%ld:%d:%d: ddb [%d] "
Justin P. Mattockcd09b2c2011-01-28 11:49:08 -08001353 "initiate relogin after"
David Somayajuluafaf5a22006-09-19 10:28:00 -07001354 " %d seconds\n",
1355 ha->host_no, ddb_entry->bus,
1356 ddb_entry->target,
1357 ddb_entry->fw_ddb_index,
1358 ddb_entry->default_time2wait + 4)
1359 );
1360
1361 atomic_set(&ddb_entry->retry_relogin_timer,
1362 ddb_entry->default_time2wait + 4);
1363 }
1364 }
1365 }
1366
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301367 if (!is_qla8022(ha)) {
1368 /* Check for heartbeat interval. */
1369 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1370 ha->heartbeat_interval != 0) {
1371 ha->seconds_since_last_heartbeat++;
1372 if (ha->seconds_since_last_heartbeat >
1373 ha->heartbeat_interval + 2)
1374 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1375 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001376 }
1377
David Somayajuluafaf5a22006-09-19 10:28:00 -07001378 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07001379 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001380 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1381 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1382 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301383 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001384 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1385 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301386 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301387 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1388 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07001389 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001390 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1391 " - dpc flags = 0x%lx\n",
1392 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301393 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001394 }
1395
1396 /* Reschedule timer thread to call us back in one second */
1397 mod_timer(&ha->timer, jiffies + HZ);
1398
1399 DEBUG2(ha->seconds_since_last_intr++);
1400}
1401
1402/**
1403 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1404 * @ha: Pointer to host adapter structure.
1405 *
1406 * This routine stalls the driver until all outstanding commands are returned.
1407 * Caller must release the Hardware Lock prior to calling this routine.
1408 **/
1409static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
1410{
1411 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001412 unsigned long flags;
1413 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001414
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301415 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
1416
1417 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
1418 "complete\n", WAIT_CMD_TOV));
1419
1420 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001421 spin_lock_irqsave(&ha->hardware_lock, flags);
1422 /* Find a command that hasn't completed. */
1423 for (index = 0; index < ha->host->can_queue; index++) {
1424 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07001425 /*
1426 * We cannot just check if the index is valid,
1427 * becase if we are run from the scsi eh, then
1428 * the scsi/block layer is going to prevent
1429 * the tag from being released.
1430 */
1431 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001432 break;
1433 }
1434 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1435
1436 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301437 if (index == ha->host->can_queue)
1438 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001439
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301440 msleep(1000);
1441 }
1442 /* If we timed out on waiting for commands to come back
1443 * return ERROR. */
1444 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001445}
1446
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301447int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001448{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001449 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001450 unsigned long flags = 0;
1451
1452 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001453
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301454 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
1455 return QLA_ERROR;
1456
David Somayajuluafaf5a22006-09-19 10:28:00 -07001457 spin_lock_irqsave(&ha->hardware_lock, flags);
1458
1459 /*
1460 * If the SCSI Reset Interrupt bit is set, clear it.
1461 * Otherwise, the Soft Reset won't work.
1462 */
1463 ctrl_status = readw(&ha->reg->ctrl_status);
1464 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
1465 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1466
1467 /* Issue Soft Reset */
1468 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1469 readl(&ha->reg->ctrl_status);
1470
1471 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301472 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001473}
1474
1475/**
1476 * qla4xxx_soft_reset - performs soft reset.
1477 * @ha: Pointer to host adapter structure.
1478 **/
1479int qla4xxx_soft_reset(struct scsi_qla_host *ha)
1480{
1481 uint32_t max_wait_time;
1482 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001483 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001484 uint32_t ctrl_status;
1485
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001486 status = qla4xxx_hw_reset(ha);
1487 if (status != QLA_SUCCESS)
1488 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001489
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001490 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001491 /* Wait until the Network Reset Intr bit is cleared */
1492 max_wait_time = RESET_INTR_TOV;
1493 do {
1494 spin_lock_irqsave(&ha->hardware_lock, flags);
1495 ctrl_status = readw(&ha->reg->ctrl_status);
1496 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1497
1498 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
1499 break;
1500
1501 msleep(1000);
1502 } while ((--max_wait_time));
1503
1504 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
1505 DEBUG2(printk(KERN_WARNING
1506 "scsi%ld: Network Reset Intr not cleared by "
1507 "Network function, clearing it now!\n",
1508 ha->host_no));
1509 spin_lock_irqsave(&ha->hardware_lock, flags);
1510 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
1511 readl(&ha->reg->ctrl_status);
1512 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1513 }
1514
1515 /* Wait until the firmware tells us the Soft Reset is done */
1516 max_wait_time = SOFT_RESET_TOV;
1517 do {
1518 spin_lock_irqsave(&ha->hardware_lock, flags);
1519 ctrl_status = readw(&ha->reg->ctrl_status);
1520 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1521
1522 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
1523 status = QLA_SUCCESS;
1524 break;
1525 }
1526
1527 msleep(1000);
1528 } while ((--max_wait_time));
1529
1530 /*
1531 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1532 * after the soft reset has taken place.
1533 */
1534 spin_lock_irqsave(&ha->hardware_lock, flags);
1535 ctrl_status = readw(&ha->reg->ctrl_status);
1536 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
1537 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1538 readl(&ha->reg->ctrl_status);
1539 }
1540 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1541
1542 /* If soft reset fails then most probably the bios on other
1543 * function is also enabled.
1544 * Since the initialization is sequential the other fn
1545 * wont be able to acknowledge the soft reset.
1546 * Issue a force soft reset to workaround this scenario.
1547 */
1548 if (max_wait_time == 0) {
1549 /* Issue Force Soft Reset */
1550 spin_lock_irqsave(&ha->hardware_lock, flags);
1551 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
1552 readl(&ha->reg->ctrl_status);
1553 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1554 /* Wait until the firmware tells us the Soft Reset is done */
1555 max_wait_time = SOFT_RESET_TOV;
1556 do {
1557 spin_lock_irqsave(&ha->hardware_lock, flags);
1558 ctrl_status = readw(&ha->reg->ctrl_status);
1559 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1560
1561 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
1562 status = QLA_SUCCESS;
1563 break;
1564 }
1565
1566 msleep(1000);
1567 } while ((--max_wait_time));
1568 }
1569
1570 return status;
1571}
1572
1573/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301574 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001575 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301576 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07001577 *
1578 * This routine is called just prior to a HARD RESET to return all
1579 * outstanding commands back to the Operating System.
1580 * Caller should make sure that the following locks are released
1581 * before this calling routine: Hardware lock, and io_request_lock.
1582 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301583static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001584{
1585 struct srb *srb;
1586 int i;
1587 unsigned long flags;
1588
1589 spin_lock_irqsave(&ha->hardware_lock, flags);
1590 for (i = 0; i < ha->host->can_queue; i++) {
1591 srb = qla4xxx_del_from_active_array(ha, i);
1592 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301593 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301594 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001595 }
1596 }
1597 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001598}
1599
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301600void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
1601{
1602 clear_bit(AF_ONLINE, &ha->flags);
1603
1604 /* Disable the board */
1605 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301606
1607 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
1608 qla4xxx_mark_all_devices_missing(ha);
1609 clear_bit(AF_INIT_DONE, &ha->flags);
1610}
1611
David Somayajuluafaf5a22006-09-19 10:28:00 -07001612/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001613 * qla4xxx_recover_adapter - recovers adapter after a fatal error
1614 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001615 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301616static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001617{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301618 int status = QLA_ERROR;
1619 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001620
1621 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301622 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001623 clear_bit(AF_ONLINE, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06001624
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301625 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001626
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301627 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001628
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301629 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
1630 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001631
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301632 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
1633 * do not reset adapter, jump to initialize_adapter */
1634 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
1635 status = QLA_SUCCESS;
1636 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001637 }
1638
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301639 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
1640 * from eh_host_reset or ioctl module */
1641 if (is_qla8022(ha) && !reset_chip &&
1642 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
1643
1644 DEBUG2(ql4_printk(KERN_INFO, ha,
1645 "scsi%ld: %s - Performing stop_firmware...\n",
1646 ha->host_no, __func__));
1647 status = ha->isp_ops->reset_firmware(ha);
1648 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001649 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1650 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301651 ha->isp_ops->disable_intrs(ha);
1652 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1653 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1654 } else {
1655 /* If the stop_firmware fails then
1656 * reset the entire chip */
1657 reset_chip = 1;
1658 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1659 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1660 }
1661 }
1662
1663 /* Issue full chip reset if recovering from a catastrophic error,
1664 * or if stop_firmware fails for ISP-82xx.
1665 * This is the default case for ISP-4xxx */
1666 if (!is_qla8022(ha) || reset_chip) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07001667 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
1668 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301669 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1670 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
1671 DEBUG2(ql4_printk(KERN_INFO, ha,
1672 "scsi%ld: %s - Performing chip reset..\n",
1673 ha->host_no, __func__));
1674 status = ha->isp_ops->reset_chip(ha);
1675 }
1676
1677 /* Flush any pending ddb changed AENs */
1678 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
1679
1680recover_ha_init_adapter:
1681 /* Upon successful firmware/chip reset, re-initialize the adapter */
1682 if (status == QLA_SUCCESS) {
1683 /* For ISP-4xxx, force function 1 to always initialize
1684 * before function 3 to prevent both funcions from
1685 * stepping on top of the other */
1686 if (!is_qla8022(ha) && (ha->mac_index == 3))
1687 ssleep(6);
1688
1689 /* NOTE: AF_ONLINE flag set upon successful completion of
1690 * qla4xxx_initialize_adapter */
1691 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
1692 }
1693
1694 /* Retry failed adapter initialization, if necessary
1695 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
1696 * case to prevent ping-pong resets between functions */
1697 if (!test_bit(AF_ONLINE, &ha->flags) &&
1698 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001699 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301700 * resetting the ha.
1701 * Since we don't want to block the DPC for too long
1702 * with multiple resets in the same thread,
1703 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07001704 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
1705 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
1706 DEBUG2(printk("scsi%ld: recover adapter - retrying "
1707 "(%d) more times\n", ha->host_no,
1708 ha->retry_reset_ha_cnt));
1709 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1710 status = QLA_ERROR;
1711 } else {
1712 if (ha->retry_reset_ha_cnt > 0) {
1713 /* Schedule another Reset HA--DPC will retry */
1714 ha->retry_reset_ha_cnt--;
1715 DEBUG2(printk("scsi%ld: recover adapter - "
1716 "retry remaining %d\n",
1717 ha->host_no,
1718 ha->retry_reset_ha_cnt));
1719 status = QLA_ERROR;
1720 }
1721
1722 if (ha->retry_reset_ha_cnt == 0) {
1723 /* Recover adapter retries have been exhausted.
1724 * Adapter DEAD */
1725 DEBUG2(printk("scsi%ld: recover adapter "
1726 "failed - board disabled\n",
1727 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301728 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001729 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1730 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301731 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07001732 &ha->dpc_flags);
1733 status = QLA_ERROR;
1734 }
1735 }
1736 } else {
1737 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301738 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001739 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
1740 }
1741
1742 ha->adapter_error_count++;
1743
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301744 if (test_bit(AF_ONLINE, &ha->flags))
1745 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001746
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301747 scsi_unblock_requests(ha->host);
1748
1749 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
1750 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001751 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301752
David Somayajuluafaf5a22006-09-19 10:28:00 -07001753 return status;
1754}
1755
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001756static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
1757{
1758 struct ddb_entry *ddb_entry, *dtemp;
1759
1760 list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) {
1761 if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) ||
1762 (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) {
1763 if (ddb_entry->fw_ddb_device_state ==
1764 DDB_DS_SESSION_ACTIVE) {
1765 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
1766 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
1767 " marked ONLINE\n", ha->host_no, __func__,
1768 ddb_entry->fw_ddb_index);
1769
1770 iscsi_unblock_session(ddb_entry->sess);
1771 } else
1772 qla4xxx_relogin_device(ha, ddb_entry);
1773 }
1774 }
1775}
1776
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301777void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
1778{
Lalit Chandivade1b468072011-05-17 23:17:09 -07001779 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301780 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301781}
1782
David Somayajuluafaf5a22006-09-19 10:28:00 -07001783/**
1784 * qla4xxx_do_dpc - dpc routine
1785 * @data: in our case pointer to adapter structure
1786 *
1787 * This routine is a task that is schedule by the interrupt handler
1788 * to perform the background processing for interrupts. We put it
1789 * on a task queue that is consumed whenever the scheduler runs; that's
1790 * so you can do anything (i.e. put the process to sleep etc). In fact,
1791 * the mid-level tries to sleep when it reaches the driver threshold
1792 * "host->can_queue". This can cause a panic if we were in our interrupt code.
1793 **/
David Howellsc4028952006-11-22 14:57:56 +00001794static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001795{
David Howellsc4028952006-11-22 14:57:56 +00001796 struct scsi_qla_host *ha =
1797 container_of(work, struct scsi_qla_host, dpc_work);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001798 struct ddb_entry *ddb_entry, *dtemp;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001799 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001800
David C Somayajuluf26b9042006-11-15 16:41:09 -08001801 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301802 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
1803 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001804
1805 /* Initialization not yet finished. Don't do anything yet. */
1806 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07001807 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001808
Lalit Chandivade2232be02010-07-30 14:38:47 +05301809 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1810 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
1811 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07001812 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301813 }
1814
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301815 if (is_qla8022(ha)) {
1816 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
1817 qla4_8xxx_idc_lock(ha);
1818 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
1819 QLA82XX_DEV_FAILED);
1820 qla4_8xxx_idc_unlock(ha);
1821 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
1822 qla4_8xxx_device_state_handler(ha);
1823 }
1824 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
1825 qla4_8xxx_need_qsnt_handler(ha);
1826 }
1827 }
1828
1829 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
1830 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001831 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301832 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
1833 if (ql4xdontresethba) {
1834 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
1835 ha->host_no, __func__));
1836 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
1837 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1838 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
1839 goto dpc_post_reset_ha;
1840 }
1841 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
1842 test_bit(DPC_RESET_HA, &ha->dpc_flags))
1843 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001844
David C Somayajulu477ffb92007-01-22 12:26:11 -08001845 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001846 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001847
David Somayajuluafaf5a22006-09-19 10:28:00 -07001848 while ((readw(&ha->reg->ctrl_status) &
1849 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
1850 if (--wait_time == 0)
1851 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001852 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001853 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001854 if (wait_time == 0)
1855 DEBUG2(printk("scsi%ld: %s: SR|FSR "
1856 "bit not cleared-- resetting\n",
1857 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301858 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001859 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
1860 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301861 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08001862 }
1863 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
1864 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301865 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001866 }
1867 }
1868
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301869dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07001870 /* ---- process AEN? --- */
1871 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
1872 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
1873
1874 /* ---- Get DHCP IP Address? --- */
1875 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
1876 qla4xxx_get_dhcp_ip_address(ha);
1877
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301878 /* ---- link change? --- */
1879 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
1880 if (!test_bit(AF_LINK_UP, &ha->flags)) {
1881 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001882 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301883 } else {
1884 /* ---- link up? --- *
1885 * F/W will auto login to all devices ONLY ONCE after
1886 * link up during driver initialization and runtime
1887 * fatal error recovery. Therefore, the driver must
1888 * manually relogin to devices when recovering from
1889 * connection failures, logouts, expired KATO, etc. */
1890
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07001891 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301892 }
1893 }
1894
David Somayajuluafaf5a22006-09-19 10:28:00 -07001895 /* ---- relogin device? --- */
1896 if (adapter_up(ha) &&
1897 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
1898 list_for_each_entry_safe(ddb_entry, dtemp,
1899 &ha->ddb_list, list) {
1900 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
1901 atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE)
1902 qla4xxx_relogin_device(ha, ddb_entry);
1903
1904 /*
1905 * If mbx cmd times out there is no point
1906 * in continuing further.
1907 * With large no of targets this can hang
1908 * the system.
1909 */
1910 if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
1911 printk(KERN_WARNING "scsi%ld: %s: "
1912 "need to reset hba\n",
1913 ha->host_no, __func__);
1914 break;
1915 }
1916 }
1917 }
Vikas Chaudhary0753b482010-07-30 14:27:19 +05301918
David Somayajuluafaf5a22006-09-19 10:28:00 -07001919}
1920
1921/**
1922 * qla4xxx_free_adapter - release the adapter
1923 * @ha: pointer to adapter structure
1924 **/
1925static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
1926{
1927
1928 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
1929 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301930 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001931 }
1932
David Somayajuluafaf5a22006-09-19 10:28:00 -07001933 /* Remove timer thread, if present */
1934 if (ha->timer_active)
1935 qla4xxx_stop_timer(ha);
1936
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301937 /* Kill the kernel thread for this host */
1938 if (ha->dpc_thread)
1939 destroy_workqueue(ha->dpc_thread);
1940
1941 /* Put firmware in known state */
1942 ha->isp_ops->reset_firmware(ha);
1943
1944 if (is_qla8022(ha)) {
1945 qla4_8xxx_idc_lock(ha);
1946 qla4_8xxx_clear_drv_active(ha);
1947 qla4_8xxx_idc_unlock(ha);
1948 }
1949
David Somayajuluafaf5a22006-09-19 10:28:00 -07001950 /* Detach interrupts */
1951 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301952 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001953
David C Somayajulubee4fe82007-05-23 18:03:32 -07001954 /* free extra memory */
1955 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301956}
David C Somayajulubee4fe82007-05-23 18:03:32 -07001957
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301958int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
1959{
1960 int status = 0;
1961 uint8_t revision_id;
1962 unsigned long mem_base, mem_len, db_base, db_len;
1963 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001964
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301965 status = pci_request_regions(pdev, DRIVER_NAME);
1966 if (status) {
1967 printk(KERN_WARNING
1968 "scsi(%ld) Failed to reserve PIO regions (%s) "
1969 "status=%d\n", ha->host_no, pci_name(pdev), status);
1970 goto iospace_error_exit;
1971 }
1972
1973 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
1974 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
1975 __func__, revision_id));
1976 ha->revision_id = revision_id;
1977
1978 /* remap phys address */
1979 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
1980 mem_len = pci_resource_len(pdev, 0);
1981 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
1982 __func__, mem_base, mem_len));
1983
1984 /* mapping of pcibase pointer */
1985 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
1986 if (!ha->nx_pcibase) {
1987 printk(KERN_ERR
1988 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
1989 pci_release_regions(ha->pdev);
1990 goto iospace_error_exit;
1991 }
1992
1993 /* Mapping of IO base pointer, door bell read and write pointer */
1994
1995 /* mapping of IO base pointer */
1996 ha->qla4_8xxx_reg =
1997 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
1998 0xbc000 + (ha->pdev->devfn << 11));
1999
2000 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
2001 db_len = pci_resource_len(pdev, 4);
2002
Shyam Sundar2657c802010-10-06 22:50:29 -07002003 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
2004 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302005
Shyam Sundar2657c802010-10-06 22:50:29 -07002006 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302007iospace_error_exit:
2008 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002009}
2010
2011/***
2012 * qla4xxx_iospace_config - maps registers
2013 * @ha: pointer to adapter structure
2014 *
2015 * This routines maps HBA's registers from the pci address space
2016 * into the kernel virtual address space for memory mapped i/o.
2017 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302018int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002019{
2020 unsigned long pio, pio_len, pio_flags;
2021 unsigned long mmio, mmio_len, mmio_flags;
2022
2023 pio = pci_resource_start(ha->pdev, 0);
2024 pio_len = pci_resource_len(ha->pdev, 0);
2025 pio_flags = pci_resource_flags(ha->pdev, 0);
2026 if (pio_flags & IORESOURCE_IO) {
2027 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302028 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002029 "Invalid PCI I/O region size\n");
2030 pio = 0;
2031 }
2032 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302033 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002034 pio = 0;
2035 }
2036
2037 /* Use MMIO operations for all accesses. */
2038 mmio = pci_resource_start(ha->pdev, 1);
2039 mmio_len = pci_resource_len(ha->pdev, 1);
2040 mmio_flags = pci_resource_flags(ha->pdev, 1);
2041
2042 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302043 ql4_printk(KERN_ERR, ha,
2044 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002045
2046 goto iospace_error_exit;
2047 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302048
David Somayajuluafaf5a22006-09-19 10:28:00 -07002049 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302050 ql4_printk(KERN_ERR, ha,
2051 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002052 goto iospace_error_exit;
2053 }
2054
2055 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302056 ql4_printk(KERN_WARNING, ha,
2057 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002058
2059 goto iospace_error_exit;
2060 }
2061
2062 ha->pio_address = pio;
2063 ha->pio_length = pio_len;
2064 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
2065 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302066 ql4_printk(KERN_ERR, ha,
2067 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002068
2069 goto iospace_error_exit;
2070 }
2071
2072 return 0;
2073
2074iospace_error_exit:
2075 return -ENOMEM;
2076}
2077
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302078static struct isp_operations qla4xxx_isp_ops = {
2079 .iospace_config = qla4xxx_iospace_config,
2080 .pci_config = qla4xxx_pci_config,
2081 .disable_intrs = qla4xxx_disable_intrs,
2082 .enable_intrs = qla4xxx_enable_intrs,
2083 .start_firmware = qla4xxx_start_firmware,
2084 .intr_handler = qla4xxx_intr_handler,
2085 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
2086 .reset_chip = qla4xxx_soft_reset,
2087 .reset_firmware = qla4xxx_hw_reset,
2088 .queue_iocb = qla4xxx_queue_iocb,
2089 .complete_iocb = qla4xxx_complete_iocb,
2090 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
2091 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
2092 .get_sys_info = qla4xxx_get_sys_info,
2093};
2094
2095static struct isp_operations qla4_8xxx_isp_ops = {
2096 .iospace_config = qla4_8xxx_iospace_config,
2097 .pci_config = qla4_8xxx_pci_config,
2098 .disable_intrs = qla4_8xxx_disable_intrs,
2099 .enable_intrs = qla4_8xxx_enable_intrs,
2100 .start_firmware = qla4_8xxx_load_risc,
2101 .intr_handler = qla4_8xxx_intr_handler,
2102 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
2103 .reset_chip = qla4_8xxx_isp_reset,
2104 .reset_firmware = qla4_8xxx_stop_firmware,
2105 .queue_iocb = qla4_8xxx_queue_iocb,
2106 .complete_iocb = qla4_8xxx_complete_iocb,
2107 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
2108 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
2109 .get_sys_info = qla4_8xxx_get_sys_info,
2110};
2111
2112uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2113{
2114 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
2115}
2116
2117uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2118{
2119 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
2120}
2121
2122uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2123{
2124 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
2125}
2126
2127uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2128{
2129 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
2130}
2131
David Somayajuluafaf5a22006-09-19 10:28:00 -07002132/**
2133 * qla4xxx_probe_adapter - callback function to probe HBA
2134 * @pdev: pointer to pci_dev structure
2135 * @pci_device_id: pointer to pci_device entry
2136 *
2137 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
2138 * It returns zero if successful. It also initializes all data necessary for
2139 * the driver.
2140 **/
2141static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
2142 const struct pci_device_id *ent)
2143{
2144 int ret = -ENODEV, status;
2145 struct Scsi_Host *host;
2146 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002147 uint8_t init_retry_count = 0;
2148 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302149 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002150 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002151
2152 if (pci_enable_device(pdev))
2153 return -1;
2154
2155 host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha));
2156 if (host == NULL) {
2157 printk(KERN_WARNING
2158 "qla4xxx: Couldn't allocate host from scsi layer!\n");
2159 goto probe_disable_device;
2160 }
2161
2162 /* Clear our data area */
2163 ha = (struct scsi_qla_host *) host->hostdata;
2164 memset(ha, 0, sizeof(*ha));
2165
2166 /* Save the information from PCI BIOS. */
2167 ha->pdev = pdev;
2168 ha->host = host;
2169 ha->host_no = host->host_no;
2170
Lalit Chandivade2232be02010-07-30 14:38:47 +05302171 pci_enable_pcie_error_reporting(pdev);
2172
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302173 /* Setup Runtime configurable options */
2174 if (is_qla8022(ha)) {
2175 ha->isp_ops = &qla4_8xxx_isp_ops;
2176 rwlock_init(&ha->hw_lock);
2177 ha->qdr_sn_window = -1;
2178 ha->ddr_mn_window = -1;
2179 ha->curr_window = 255;
2180 ha->func_num = PCI_FUNC(ha->pdev->devfn);
2181 nx_legacy_intr = &legacy_intr[ha->func_num];
2182 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
2183 ha->nx_legacy_intr.tgt_status_reg =
2184 nx_legacy_intr->tgt_status_reg;
2185 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
2186 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
2187 } else {
2188 ha->isp_ops = &qla4xxx_isp_ops;
2189 }
2190
Lalit Chandivade2232be02010-07-30 14:38:47 +05302191 /* Set EEH reset type to fundamental if required by hba */
2192 if (is_qla8022(ha))
2193 pdev->needs_freset = 1;
2194
David Somayajuluafaf5a22006-09-19 10:28:00 -07002195 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302196 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002197 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302198 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002199
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302200 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07002201 pdev->device, pdev->irq, ha->reg);
2202
2203 qla4xxx_config_dma_addressing(ha);
2204
2205 /* Initialize lists and spinlocks. */
2206 INIT_LIST_HEAD(&ha->ddb_list);
2207 INIT_LIST_HEAD(&ha->free_srb_q);
2208
2209 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302210 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002211
2212 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002213
2214 /* Allocate dma buffers */
2215 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302216 ql4_printk(KERN_WARNING, ha,
2217 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002218
2219 ret = -ENOMEM;
2220 goto probe_failed;
2221 }
2222
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302223 if (is_qla8022(ha))
2224 (void) qla4_8xxx_get_flash_info(ha);
2225
David Somayajuluafaf5a22006-09-19 10:28:00 -07002226 /*
2227 * Initialize the Host adapter request/response queues and
2228 * firmware
2229 * NOTE: interrupts enabled upon successful completion
2230 */
2231 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302232 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
2233 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002234
2235 if (is_qla8022(ha)) {
2236 qla4_8xxx_idc_lock(ha);
2237 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2238 qla4_8xxx_idc_unlock(ha);
2239 if (dev_state == QLA82XX_DEV_FAILED) {
2240 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
2241 "initialize adapter. H/W is in failed state\n",
2242 __func__);
2243 break;
2244 }
2245 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002246 DEBUG2(printk("scsi: %s: retrying adapter initialization "
2247 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302248
2249 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
2250 continue;
2251
David Somayajuluafaf5a22006-09-19 10:28:00 -07002252 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
2253 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302254
2255 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302256 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002257
Lalit Chandivadefe998522010-12-02 22:12:36 -08002258 if (is_qla8022(ha) && ql4xdontresethba) {
2259 /* Put the device in failed state. */
2260 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
2261 qla4_8xxx_idc_lock(ha);
2262 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2263 QLA82XX_DEV_FAILED);
2264 qla4_8xxx_idc_unlock(ha);
2265 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002266 ret = -ENODEV;
2267 goto probe_failed;
2268 }
2269
2270 host->cmd_per_lun = 3;
2271 host->max_channel = 0;
2272 host->max_lun = MAX_LUNS - 1;
2273 host->max_id = MAX_TARGETS;
2274 host->max_cmd_len = IOCB_MAX_CDB_LEN;
2275 host->can_queue = MAX_SRBS ;
2276 host->transportt = qla4xxx_scsi_transport;
2277
2278 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
2279 if (ret) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302280 ql4_printk(KERN_WARNING, ha,
2281 "scsi_init_shared_tag_map failed\n");
2282 goto probe_failed;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002283 }
2284
2285 /* Startup the kernel thread for this host adapter. */
2286 DEBUG2(printk("scsi: %s: Starting kernel thread for "
2287 "qla4xxx_dpc\n", __func__));
2288 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
2289 ha->dpc_thread = create_singlethread_workqueue(buf);
2290 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302291 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002292 ret = -ENODEV;
2293 goto probe_failed;
2294 }
David Howellsc4028952006-11-22 14:57:56 +00002295 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002296
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302297 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
2298 * (which is called indirectly by qla4xxx_initialize_adapter),
2299 * so that irqs will be registered after crbinit but before
2300 * mbx_intr_enable.
2301 */
2302 if (!is_qla8022(ha)) {
2303 ret = qla4xxx_request_irqs(ha);
2304 if (ret) {
2305 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
2306 "interrupt %d already in use.\n", pdev->irq);
2307 goto probe_failed;
2308 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002309 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002310
Lalit Chandivade2232be02010-07-30 14:38:47 +05302311 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302312 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002313
2314 /* Start timer thread. */
2315 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
2316
2317 set_bit(AF_INIT_DONE, &ha->flags);
2318
2319 pci_set_drvdata(pdev, ha);
2320
2321 ret = scsi_add_host(host, &pdev->dev);
2322 if (ret)
2323 goto probe_failed;
2324
David Somayajuluafaf5a22006-09-19 10:28:00 -07002325 printk(KERN_INFO
2326 " QLogic iSCSI HBA Driver version: %s\n"
2327 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2328 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
2329 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2330 ha->patch_number, ha->build_number);
Mike Christie921601b2008-01-31 13:36:49 -06002331 scsi_scan_host(host);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002332
2333 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002334 return 0;
2335
David Somayajuluafaf5a22006-09-19 10:28:00 -07002336probe_failed:
2337 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302338
2339probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05302340 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002341 scsi_host_put(ha->host);
2342
2343probe_disable_device:
2344 pci_disable_device(pdev);
2345
2346 return ret;
2347}
2348
2349/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07002350 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
2351 * @ha: pointer to adapter structure
2352 *
2353 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
2354 * so that the other port will not re-initialize while in the process of
2355 * removing the ha due to driver unload or hba hotplug.
2356 **/
2357static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
2358{
2359 struct scsi_qla_host *other_ha = NULL;
2360 struct pci_dev *other_pdev = NULL;
2361 int fn = ISP4XXX_PCI_FN_2;
2362
2363 /*iscsi function numbers for ISP4xxx is 1 and 3*/
2364 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
2365 fn = ISP4XXX_PCI_FN_1;
2366
2367 other_pdev =
2368 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2369 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2370 fn));
2371
2372 /* Get other_ha if other_pdev is valid and state is enable*/
2373 if (other_pdev) {
2374 if (atomic_read(&other_pdev->enable_cnt)) {
2375 other_ha = pci_get_drvdata(other_pdev);
2376 if (other_ha) {
2377 set_bit(AF_HA_REMOVAL, &other_ha->flags);
2378 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
2379 "Prevent %s reinit\n", __func__,
2380 dev_name(&other_ha->pdev->dev)));
2381 }
2382 }
2383 pci_dev_put(other_pdev);
2384 }
2385}
2386
2387/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002388 * qla4xxx_remove_adapter - calback function to remove adapter.
2389 * @pci_dev: PCI device pointer
2390 **/
2391static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
2392{
2393 struct scsi_qla_host *ha;
2394
2395 ha = pci_get_drvdata(pdev);
2396
Karen Higgins7eece5a2011-03-21 03:34:29 -07002397 if (!is_qla8022(ha))
2398 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07002399
David Somayajuluafaf5a22006-09-19 10:28:00 -07002400 /* remove devs from iscsi_sessions to scsi_devices */
2401 qla4xxx_free_ddb_list(ha);
2402
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002403 /* destroy iface from sysfs */
2404 qla4xxx_destroy_ifaces(ha);
2405
David Somayajuluafaf5a22006-09-19 10:28:00 -07002406 scsi_remove_host(ha->host);
2407
2408 qla4xxx_free_adapter(ha);
2409
2410 scsi_host_put(ha->host);
2411
Lalit Chandivade2232be02010-07-30 14:38:47 +05302412 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302413 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002414 pci_set_drvdata(pdev, NULL);
2415}
2416
2417/**
2418 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
2419 * @ha: HA context
2420 *
2421 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2422 * supported addressing method.
2423 */
Adrian Bunk47975472007-04-26 00:35:16 -07002424static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002425{
2426 int retval;
2427
2428 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07002429 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
2430 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002431 dev_dbg(&ha->pdev->dev,
2432 "Failed to set 64 bit PCI consistent mask; "
2433 "using 32 bit.\n");
2434 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07002435 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002436 }
2437 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07002438 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002439}
2440
2441static int qla4xxx_slave_alloc(struct scsi_device *sdev)
2442{
2443 struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target);
2444 struct ddb_entry *ddb = sess->dd_data;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002445 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002446
2447 sdev->hostdata = ddb;
2448 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002449
2450 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
2451 queue_depth = ql4xmaxqdepth;
2452
2453 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002454 return 0;
2455}
2456
2457static int qla4xxx_slave_configure(struct scsi_device *sdev)
2458{
2459 sdev->tagged_supported = 1;
2460 return 0;
2461}
2462
2463static void qla4xxx_slave_destroy(struct scsi_device *sdev)
2464{
2465 scsi_deactivate_tcq(sdev, 1);
2466}
2467
2468/**
2469 * qla4xxx_del_from_active_array - returns an active srb
2470 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002471 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002472 *
2473 * This routine removes and returns the srb at the specified index
2474 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302475struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
2476 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002477{
2478 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05302479 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002480
Vikas Chaudhary53698872010-04-28 11:41:59 +05302481 cmd = scsi_host_find_tag(ha->host, index);
2482 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002483 return srb;
2484
Vikas Chaudhary53698872010-04-28 11:41:59 +05302485 srb = (struct srb *)CMD_SP(cmd);
2486 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002487 return srb;
2488
2489 /* update counters */
2490 if (srb->flags & SRB_DMA_VALID) {
2491 ha->req_q_count += srb->iocb_cnt;
2492 ha->iocb_cnt -= srb->iocb_cnt;
2493 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05302494 srb->cmd->host_scribble =
2495 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002496 }
2497 return srb;
2498}
2499
2500/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002501 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302502 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002503 * @cmd: Scsi Command to wait on.
2504 *
2505 * This routine waits for the command to be returned by the Firmware
2506 * for some max time.
2507 **/
2508static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
2509 struct scsi_cmnd *cmd)
2510{
2511 int done = 0;
2512 struct srb *rp;
2513 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302514 int ret = SUCCESS;
2515
2516 /* Dont wait on command if PCI error is being handled
2517 * by PCI AER driver
2518 */
2519 if (unlikely(pci_channel_offline(ha->pdev)) ||
2520 (test_bit(AF_EEH_BUSY, &ha->flags))) {
2521 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
2522 ha->host_no, __func__);
2523 return ret;
2524 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002525
2526 do {
2527 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05302528 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002529 if (rp == NULL) {
2530 done++;
2531 break;
2532 }
2533
2534 msleep(2000);
2535 } while (max_wait_time--);
2536
2537 return done;
2538}
2539
2540/**
2541 * qla4xxx_wait_for_hba_online - waits for HBA to come online
2542 * @ha: Pointer to host adapter structure
2543 **/
2544static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
2545{
2546 unsigned long wait_online;
2547
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002548 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002549 while (time_before(jiffies, wait_online)) {
2550
2551 if (adapter_up(ha))
2552 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002553
2554 msleep(2000);
2555 }
2556
2557 return QLA_ERROR;
2558}
2559
2560/**
Mike Christiece545032008-02-29 18:25:20 -06002561 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002562 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07002563 * @t: target id
2564 * @l: lun id
2565 *
2566 * This function waits for all outstanding commands to a lun to complete. It
2567 * returns 0 if all pending commands are returned and 1 otherwise.
2568 **/
Mike Christiece545032008-02-29 18:25:20 -06002569static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
2570 struct scsi_target *stgt,
2571 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002572{
2573 int cnt;
2574 int status = 0;
2575 struct scsi_cmnd *cmd;
2576
2577 /*
Mike Christiece545032008-02-29 18:25:20 -06002578 * Waiting for all commands for the designated target or dev
2579 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002580 */
2581 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
2582 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06002583 if (cmd && stgt == scsi_target(cmd->device) &&
2584 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002585 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2586 status++;
2587 break;
2588 }
2589 }
2590 }
2591 return status;
2592}
2593
2594/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302595 * qla4xxx_eh_abort - callback for abort task.
2596 * @cmd: Pointer to Linux's SCSI command structure
2597 *
2598 * This routine is called by the Linux OS to abort the specified
2599 * command.
2600 **/
2601static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
2602{
2603 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2604 unsigned int id = cmd->device->id;
2605 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002606 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302607 struct srb *srb = NULL;
2608 int ret = SUCCESS;
2609 int wait = 0;
2610
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302611 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04002612 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
2613 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302614
Mike Christie92b3e5b2010-10-06 22:51:17 -07002615 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302616 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002617 if (!srb) {
2618 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302619 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07002620 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302621 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07002622 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302623
2624 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
2625 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
2626 ha->host_no, id, lun));
2627 ret = FAILED;
2628 } else {
2629 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
2630 ha->host_no, id, lun));
2631 wait = 1;
2632 }
2633
2634 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
2635
2636 /* Wait for command to complete */
2637 if (wait) {
2638 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
2639 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
2640 ha->host_no, id, lun));
2641 ret = FAILED;
2642 }
2643 }
2644
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302645 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302646 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002647 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302648
2649 return ret;
2650}
2651
2652/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002653 * qla4xxx_eh_device_reset - callback for target reset.
2654 * @cmd: Pointer to Linux's SCSI command structure
2655 *
2656 * This routine is called by the Linux OS to reset all luns on the
2657 * specified target.
2658 **/
2659static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
2660{
2661 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2662 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002663 int ret = FAILED, stat;
2664
Karen Higgins612f7342009-07-15 15:03:01 -05002665 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002666 return ret;
2667
Mike Christiec01be6d2010-07-22 16:59:49 +05302668 ret = iscsi_block_scsi_eh(cmd);
2669 if (ret)
2670 return ret;
2671 ret = FAILED;
2672
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302673 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002674 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
2675 cmd->device->channel, cmd->device->id, cmd->device->lun);
2676
2677 DEBUG2(printk(KERN_INFO
2678 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
2679 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07002680 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002681 ha->dpc_flags, cmd->result, cmd->allowed));
2682
2683 /* FIXME: wait for hba to go online */
2684 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
2685 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302686 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002687 goto eh_dev_reset_done;
2688 }
2689
Mike Christiece545032008-02-29 18:25:20 -06002690 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2691 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302692 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06002693 "DEVICE RESET FAILED - waiting for "
2694 "commands.\n");
2695 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002696 }
2697
David C Somayajulu9d562912008-03-19 11:23:03 -07002698 /* Send marker. */
2699 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2700 MM_LUN_RESET) != QLA_SUCCESS)
2701 goto eh_dev_reset_done;
2702
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302703 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002704 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
2705 ha->host_no, cmd->device->channel, cmd->device->id,
2706 cmd->device->lun);
2707
2708 ret = SUCCESS;
2709
2710eh_dev_reset_done:
2711
2712 return ret;
2713}
2714
2715/**
Mike Christiece545032008-02-29 18:25:20 -06002716 * qla4xxx_eh_target_reset - callback for target reset.
2717 * @cmd: Pointer to Linux's SCSI command structure
2718 *
2719 * This routine is called by the Linux OS to reset the target.
2720 **/
2721static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
2722{
2723 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
2724 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05302725 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06002726
2727 if (!ddb_entry)
2728 return FAILED;
2729
Mike Christiec01be6d2010-07-22 16:59:49 +05302730 ret = iscsi_block_scsi_eh(cmd);
2731 if (ret)
2732 return ret;
2733
Mike Christiece545032008-02-29 18:25:20 -06002734 starget_printk(KERN_INFO, scsi_target(cmd->device),
2735 "WARM TARGET RESET ISSUED.\n");
2736
2737 DEBUG2(printk(KERN_INFO
2738 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
2739 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07002740 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06002741 ha->dpc_flags, cmd->result, cmd->allowed));
2742
2743 stat = qla4xxx_reset_target(ha, ddb_entry);
2744 if (stat != QLA_SUCCESS) {
2745 starget_printk(KERN_INFO, scsi_target(cmd->device),
2746 "WARM TARGET RESET FAILED.\n");
2747 return FAILED;
2748 }
2749
Mike Christiece545032008-02-29 18:25:20 -06002750 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
2751 NULL)) {
2752 starget_printk(KERN_INFO, scsi_target(cmd->device),
2753 "WARM TARGET DEVICE RESET FAILED - "
2754 "waiting for commands.\n");
2755 return FAILED;
2756 }
2757
David C Somayajulu9d562912008-03-19 11:23:03 -07002758 /* Send marker. */
2759 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
2760 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
2761 starget_printk(KERN_INFO, scsi_target(cmd->device),
2762 "WARM TARGET DEVICE RESET FAILED - "
2763 "marker iocb failed.\n");
2764 return FAILED;
2765 }
2766
Mike Christiece545032008-02-29 18:25:20 -06002767 starget_printk(KERN_INFO, scsi_target(cmd->device),
2768 "WARM TARGET RESET SUCCEEDED.\n");
2769 return SUCCESS;
2770}
2771
2772/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002773 * qla4xxx_eh_host_reset - kernel callback
2774 * @cmd: Pointer to Linux's SCSI command structure
2775 *
2776 * This routine is invoked by the Linux kernel to perform fatal error
2777 * recovery on the specified adapter.
2778 **/
2779static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
2780{
2781 int return_status = FAILED;
2782 struct scsi_qla_host *ha;
2783
2784 ha = (struct scsi_qla_host *) cmd->device->host->hostdata;
2785
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302786 if (ql4xdontresethba) {
2787 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2788 ha->host_no, __func__));
2789 return FAILED;
2790 }
2791
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302792 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05002793 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002794 cmd->device->channel, cmd->device->id, cmd->device->lun);
2795
2796 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
2797 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
2798 "DEAD.\n", ha->host_no, cmd->device->channel,
2799 __func__));
2800
2801 return FAILED;
2802 }
2803
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302804 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
2805 if (is_qla8022(ha))
2806 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2807 else
2808 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2809 }
Mike Christie50a29ae2008-03-04 13:26:53 -06002810
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302811 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002812 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002813
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302814 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002815 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002816
2817 return return_status;
2818}
2819
Lalit Chandivade2232be02010-07-30 14:38:47 +05302820/* PCI AER driver recovers from all correctable errors w/o
2821 * driver intervention. For uncorrectable errors PCI AER
2822 * driver calls the following device driver's callbacks
2823 *
2824 * - Fatal Errors - link_reset
2825 * - Non-Fatal Errors - driver's pci_error_detected() which
2826 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
2827 *
2828 * PCI AER driver calls
2829 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
2830 * returns RECOVERED or NEED_RESET if fw_hung
2831 * NEED_RESET - driver's slot_reset()
2832 * DISCONNECT - device is dead & cannot recover
2833 * RECOVERED - driver's pci_resume()
2834 */
2835static pci_ers_result_t
2836qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2837{
2838 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2839
2840 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
2841 ha->host_no, __func__, state);
2842
2843 if (!is_aer_supported(ha))
2844 return PCI_ERS_RESULT_NONE;
2845
2846 switch (state) {
2847 case pci_channel_io_normal:
2848 clear_bit(AF_EEH_BUSY, &ha->flags);
2849 return PCI_ERS_RESULT_CAN_RECOVER;
2850 case pci_channel_io_frozen:
2851 set_bit(AF_EEH_BUSY, &ha->flags);
2852 qla4xxx_mailbox_premature_completion(ha);
2853 qla4xxx_free_irqs(ha);
2854 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002855 /* Return back all IOs */
2856 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302857 return PCI_ERS_RESULT_NEED_RESET;
2858 case pci_channel_io_perm_failure:
2859 set_bit(AF_EEH_BUSY, &ha->flags);
2860 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
2861 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2862 return PCI_ERS_RESULT_DISCONNECT;
2863 }
2864 return PCI_ERS_RESULT_NEED_RESET;
2865}
2866
2867/**
2868 * qla4xxx_pci_mmio_enabled() gets called if
2869 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
2870 * and read/write to the device still works.
2871 **/
2872static pci_ers_result_t
2873qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
2874{
2875 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
2876
2877 if (!is_aer_supported(ha))
2878 return PCI_ERS_RESULT_NONE;
2879
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002880 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302881}
2882
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002883static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05302884{
2885 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002886 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302887 int fn;
2888 struct pci_dev *other_pdev = NULL;
2889
2890 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
2891
2892 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2893
2894 if (test_bit(AF_ONLINE, &ha->flags)) {
2895 clear_bit(AF_ONLINE, &ha->flags);
2896 qla4xxx_mark_all_devices_missing(ha);
2897 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302898 }
2899
2900 fn = PCI_FUNC(ha->pdev->devfn);
2901 while (fn > 0) {
2902 fn--;
2903 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
2904 "func %x\n", ha->host_no, __func__, fn);
2905 /* Get the pci device given the domain, bus,
2906 * slot/function number */
2907 other_pdev =
2908 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2909 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2910 fn));
2911
2912 if (!other_pdev)
2913 continue;
2914
2915 if (atomic_read(&other_pdev->enable_cnt)) {
2916 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
2917 "func in enabled state%x\n", ha->host_no,
2918 __func__, fn);
2919 pci_dev_put(other_pdev);
2920 break;
2921 }
2922 pci_dev_put(other_pdev);
2923 }
2924
2925 /* The first function on the card, the reset owner will
2926 * start & initialize the firmware. The other functions
2927 * on the card will reset the firmware context
2928 */
2929 if (!fn) {
2930 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
2931 "0x%x is the owner\n", ha->host_no, __func__,
2932 ha->pdev->devfn);
2933
2934 qla4_8xxx_idc_lock(ha);
2935 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2936 QLA82XX_DEV_COLD);
2937
2938 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
2939 QLA82XX_IDC_VERSION);
2940
2941 qla4_8xxx_idc_unlock(ha);
2942 clear_bit(AF_FW_RECOVERY, &ha->flags);
2943 rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
2944 qla4_8xxx_idc_lock(ha);
2945
2946 if (rval != QLA_SUCCESS) {
2947 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2948 "FAILED\n", ha->host_no, __func__);
2949 qla4_8xxx_clear_drv_active(ha);
2950 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2951 QLA82XX_DEV_FAILED);
2952 } else {
2953 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
2954 "READY\n", ha->host_no, __func__);
2955 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2956 QLA82XX_DEV_READY);
2957 /* Clear driver state register */
2958 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
2959 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002960 ret = qla4xxx_request_irqs(ha);
2961 if (ret) {
2962 ql4_printk(KERN_WARNING, ha, "Failed to "
2963 "reserve interrupt %d already in use.\n",
2964 ha->pdev->irq);
2965 rval = QLA_ERROR;
2966 } else {
2967 ha->isp_ops->enable_intrs(ha);
2968 rval = QLA_SUCCESS;
2969 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302970 }
2971 qla4_8xxx_idc_unlock(ha);
2972 } else {
2973 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
2974 "the reset owner\n", ha->host_no, __func__,
2975 ha->pdev->devfn);
2976 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
2977 QLA82XX_DEV_READY)) {
2978 clear_bit(AF_FW_RECOVERY, &ha->flags);
2979 rval = qla4xxx_initialize_adapter(ha,
2980 PRESERVE_DDB_LIST);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07002981 if (rval == QLA_SUCCESS) {
2982 ret = qla4xxx_request_irqs(ha);
2983 if (ret) {
2984 ql4_printk(KERN_WARNING, ha, "Failed to"
2985 " reserve interrupt %d already in"
2986 " use.\n", ha->pdev->irq);
2987 rval = QLA_ERROR;
2988 } else {
2989 ha->isp_ops->enable_intrs(ha);
2990 rval = QLA_SUCCESS;
2991 }
2992 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05302993 qla4_8xxx_idc_lock(ha);
2994 qla4_8xxx_set_drv_active(ha);
2995 qla4_8xxx_idc_unlock(ha);
2996 }
2997 }
2998 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2999 return rval;
3000}
3001
3002static pci_ers_result_t
3003qla4xxx_pci_slot_reset(struct pci_dev *pdev)
3004{
3005 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3006 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3007 int rc;
3008
3009 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
3010 ha->host_no, __func__);
3011
3012 if (!is_aer_supported(ha))
3013 return PCI_ERS_RESULT_NONE;
3014
3015 /* Restore the saved state of PCIe device -
3016 * BAR registers, PCI Config space, PCIX, MSI,
3017 * IOV states
3018 */
3019 pci_restore_state(pdev);
3020
3021 /* pci_restore_state() clears the saved_state flag of the device
3022 * save restored state which resets saved_state flag
3023 */
3024 pci_save_state(pdev);
3025
3026 /* Initialize device or resume if in suspended state */
3027 rc = pci_enable_device(pdev);
3028 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003029 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05303030 "device after reset\n", ha->host_no, __func__);
3031 goto exit_slot_reset;
3032 }
3033
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003034 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303035
3036 if (is_qla8022(ha)) {
3037 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
3038 ret = PCI_ERS_RESULT_RECOVERED;
3039 goto exit_slot_reset;
3040 } else
3041 goto exit_slot_reset;
3042 }
3043
3044exit_slot_reset:
3045 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
3046 "device after reset\n", ha->host_no, __func__, ret);
3047 return ret;
3048}
3049
3050static void
3051qla4xxx_pci_resume(struct pci_dev *pdev)
3052{
3053 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3054 int ret;
3055
3056 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
3057 ha->host_no, __func__);
3058
3059 ret = qla4xxx_wait_for_hba_online(ha);
3060 if (ret != QLA_SUCCESS) {
3061 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
3062 "resume I/O from slot/link_reset\n", ha->host_no,
3063 __func__);
3064 }
3065
3066 pci_cleanup_aer_uncorrect_error_status(pdev);
3067 clear_bit(AF_EEH_BUSY, &ha->flags);
3068}
3069
3070static struct pci_error_handlers qla4xxx_err_handler = {
3071 .error_detected = qla4xxx_pci_error_detected,
3072 .mmio_enabled = qla4xxx_pci_mmio_enabled,
3073 .slot_reset = qla4xxx_pci_slot_reset,
3074 .resume = qla4xxx_pci_resume,
3075};
3076
David Somayajuluafaf5a22006-09-19 10:28:00 -07003077static struct pci_device_id qla4xxx_pci_tbl[] = {
3078 {
3079 .vendor = PCI_VENDOR_ID_QLOGIC,
3080 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
3081 .subvendor = PCI_ANY_ID,
3082 .subdevice = PCI_ANY_ID,
3083 },
3084 {
3085 .vendor = PCI_VENDOR_ID_QLOGIC,
3086 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
3087 .subvendor = PCI_ANY_ID,
3088 .subdevice = PCI_ANY_ID,
3089 },
David C Somayajulud9150582006-11-15 17:38:40 -08003090 {
3091 .vendor = PCI_VENDOR_ID_QLOGIC,
3092 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
3093 .subvendor = PCI_ANY_ID,
3094 .subdevice = PCI_ANY_ID,
3095 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303096 {
3097 .vendor = PCI_VENDOR_ID_QLOGIC,
3098 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
3099 .subvendor = PCI_ANY_ID,
3100 .subdevice = PCI_ANY_ID,
3101 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07003102 {0, 0},
3103};
3104MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
3105
Adrian Bunk47975472007-04-26 00:35:16 -07003106static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003107 .name = DRIVER_NAME,
3108 .id_table = qla4xxx_pci_tbl,
3109 .probe = qla4xxx_probe_adapter,
3110 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05303111 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003112};
3113
3114static int __init qla4xxx_module_init(void)
3115{
3116 int ret;
3117
3118 /* Allocate cache for SRBs. */
3119 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003120 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003121 if (srb_cachep == NULL) {
3122 printk(KERN_ERR
3123 "%s: Unable to allocate SRB cache..."
3124 "Failing load!\n", DRIVER_NAME);
3125 ret = -ENOMEM;
3126 goto no_srp_cache;
3127 }
3128
3129 /* Derive version string. */
3130 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003131 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003132 strcat(qla4xxx_version_str, "-debug");
3133
3134 qla4xxx_scsi_transport =
3135 iscsi_register_transport(&qla4xxx_iscsi_transport);
3136 if (!qla4xxx_scsi_transport){
3137 ret = -ENODEV;
3138 goto release_srb_cache;
3139 }
3140
David Somayajuluafaf5a22006-09-19 10:28:00 -07003141 ret = pci_register_driver(&qla4xxx_pci_driver);
3142 if (ret)
3143 goto unregister_transport;
3144
3145 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
3146 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05003147
David Somayajuluafaf5a22006-09-19 10:28:00 -07003148unregister_transport:
3149 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3150release_srb_cache:
3151 kmem_cache_destroy(srb_cachep);
3152no_srp_cache:
3153 return ret;
3154}
3155
3156static void __exit qla4xxx_module_exit(void)
3157{
David Somayajuluafaf5a22006-09-19 10:28:00 -07003158 pci_unregister_driver(&qla4xxx_pci_driver);
3159 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3160 kmem_cache_destroy(srb_cachep);
3161}
3162
3163module_init(qla4xxx_module_init);
3164module_exit(qla4xxx_module_exit);
3165
3166MODULE_AUTHOR("QLogic Corporation");
3167MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
3168MODULE_LICENSE("GPL");
3169MODULE_VERSION(QLA4XXX_DRIVER_VERSION);