blob: 2374475080f4e623efc37652966bf8f767a35a98 [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 Chaudharyf4f5df22010-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 Chaudharyf4f5df22010-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 Chaudharyf4f5df22010-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 Chaudharyf4f5df22010-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
Manish Rangankarb3a271a2011-07-25 13:48:53 -050066static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070067/*
68 * SCSI host template entry points
69 */
Adrian Bunk47975472007-04-26 00:35:16 -070070static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070071
72/*
73 * iSCSI template entry points
74 */
Mike Christie2174a042007-05-30 12:57:10 -050075static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
76 enum iscsi_tgt_dscvr type, uint32_t enable,
77 struct sockaddr *dst_addr);
David Somayajuluafaf5a22006-09-19 10:28:00 -070078static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
79 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050080static int qla4xxx_host_get_param(struct Scsi_Host *shost,
81 enum iscsi_host_param param, char *buf);
Mike Christied00efe32011-07-25 13:48:38 -050082static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
83 int count);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -050084static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
85 enum iscsi_param_type param_type,
86 int param, char *buf);
Mike Christie5c656af2009-07-15 15:02:59 -050087static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
Manish Rangankarb3a271a2011-07-25 13:48:53 -050088static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
89 struct sockaddr *dst_addr,
90 int non_blocking);
91static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
92static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
93static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
94 enum iscsi_param param, char *buf);
95static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
96static struct iscsi_cls_conn *
97qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
98static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
99 struct iscsi_cls_conn *cls_conn,
100 uint64_t transport_fd, int is_leading);
101static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
102static struct iscsi_cls_session *
103qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
104 uint16_t qdepth, uint32_t initial_cmdsn);
105static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
106static void qla4xxx_task_work(struct work_struct *wdata);
107static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
108static int qla4xxx_task_xmit(struct iscsi_task *);
109static void qla4xxx_task_cleanup(struct iscsi_task *);
110static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
111static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
112 struct iscsi_stats *stats);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700113/*
114 * SCSI host template entry points
115 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500116static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530117static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700118static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600119static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700120static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
121static int qla4xxx_slave_alloc(struct scsi_device *device);
122static int qla4xxx_slave_configure(struct scsi_device *device);
123static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie024f8012008-03-04 13:26:54 -0600124static void qla4xxx_scan_start(struct Scsi_Host *shost);
Mike Christie3128c6c2011-07-25 13:48:42 -0500125static mode_t ql4_attr_is_visible(int param_type, int param);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700126
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +0530127static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
128 QLA82XX_LEGACY_INTR_CONFIG;
129
David Somayajuluafaf5a22006-09-19 10:28:00 -0700130static struct scsi_host_template qla4xxx_driver_template = {
131 .module = THIS_MODULE,
132 .name = DRIVER_NAME,
133 .proc_name = DRIVER_NAME,
134 .queuecommand = qla4xxx_queuecommand,
135
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530136 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700137 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600138 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700139 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500140 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700141
142 .slave_configure = qla4xxx_slave_configure,
143 .slave_alloc = qla4xxx_slave_alloc,
144 .slave_destroy = qla4xxx_slave_destroy,
145
146 .this_id = -1,
147 .cmd_per_lun = 3,
148 .use_clustering = ENABLE_CLUSTERING,
149 .sg_tablesize = SG_ALL,
150
151 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700152 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500153 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700154};
155
156static struct iscsi_transport qla4xxx_iscsi_transport = {
157 .owner = THIS_MODULE,
158 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500159 .caps = CAP_TEXT_NEGO |
160 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
161 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
162 CAP_MULTI_R2T,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700163 .tgt_dscvr = qla4xxx_tgt_dscvr,
Mike Christie3128c6c2011-07-25 13:48:42 -0500164 .attr_is_visible = ql4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500165 .create_session = qla4xxx_session_create,
166 .destroy_session = qla4xxx_session_destroy,
167 .start_conn = qla4xxx_conn_start,
168 .create_conn = qla4xxx_conn_create,
169 .bind_conn = qla4xxx_conn_bind,
170 .stop_conn = iscsi_conn_stop,
171 .destroy_conn = qla4xxx_conn_destroy,
172 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700173 .get_conn_param = qla4xxx_conn_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500174 .get_session_param = iscsi_session_get_param,
175 .get_ep_param = qla4xxx_get_ep_param,
176 .ep_connect = qla4xxx_ep_connect,
177 .ep_poll = qla4xxx_ep_poll,
178 .ep_disconnect = qla4xxx_ep_disconnect,
179 .get_stats = qla4xxx_conn_get_stats,
180 .send_pdu = iscsi_conn_send_pdu,
181 .xmit_task = qla4xxx_task_xmit,
182 .cleanup_task = qla4xxx_task_cleanup,
183 .alloc_pdu = qla4xxx_alloc_pdu,
184
Mike Christieaa1e93a2007-05-30 12:57:09 -0500185 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500186 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500187 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500188 .bsg_request = qla4xxx_bsg_request,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700189};
190
191static struct scsi_transport_template *qla4xxx_scsi_transport;
192
Mike Christie3128c6c2011-07-25 13:48:42 -0500193static mode_t ql4_attr_is_visible(int param_type, int param)
194{
195 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500196 case ISCSI_HOST_PARAM:
197 switch (param) {
198 case ISCSI_HOST_PARAM_HWADDRESS:
199 case ISCSI_HOST_PARAM_IPADDRESS:
200 case ISCSI_HOST_PARAM_INITIATOR_NAME:
201 return S_IRUGO;
202 default:
203 return 0;
204 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500205 case ISCSI_PARAM:
206 switch (param) {
207 case ISCSI_PARAM_CONN_ADDRESS:
208 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500209 case ISCSI_PARAM_TARGET_NAME:
210 case ISCSI_PARAM_TPGT:
211 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500212 case ISCSI_PARAM_MAX_BURST:
213 case ISCSI_PARAM_MAX_R2T:
214 case ISCSI_PARAM_FIRST_BURST:
215 case ISCSI_PARAM_MAX_RECV_DLENGTH:
216 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christie3128c6c2011-07-25 13:48:42 -0500217 return S_IRUGO;
218 default:
219 return 0;
220 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500221 case ISCSI_NET_PARAM:
222 switch (param) {
223 case ISCSI_NET_PARAM_IPV4_ADDR:
224 case ISCSI_NET_PARAM_IPV4_SUBNET:
225 case ISCSI_NET_PARAM_IPV4_GW:
226 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
227 case ISCSI_NET_PARAM_IFACE_ENABLE:
228 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
229 case ISCSI_NET_PARAM_IPV6_ADDR:
230 case ISCSI_NET_PARAM_IPV6_ROUTER:
231 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
232 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500233 case ISCSI_NET_PARAM_VLAN_ID:
234 case ISCSI_NET_PARAM_VLAN_PRIORITY:
235 case ISCSI_NET_PARAM_VLAN_ENABLED:
Mike Christieb78dbba2011-07-25 13:48:44 -0500236 return S_IRUGO;
237 default:
238 return 0;
239 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500240 }
241
242 return 0;
243}
244
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500245static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
246 enum iscsi_param_type param_type,
247 int param, char *buf)
248{
249 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
250 struct scsi_qla_host *ha = to_qla_host(shost);
251 int len = -ENOSYS;
252
253 if (param_type != ISCSI_NET_PARAM)
254 return -ENOSYS;
255
256 switch (param) {
257 case ISCSI_NET_PARAM_IPV4_ADDR:
258 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
259 break;
260 case ISCSI_NET_PARAM_IPV4_SUBNET:
261 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
262 break;
263 case ISCSI_NET_PARAM_IPV4_GW:
264 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
265 break;
266 case ISCSI_NET_PARAM_IFACE_ENABLE:
267 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
268 len = sprintf(buf, "%s\n",
269 (ha->ip_config.ipv4_options &
270 IPOPT_IPV4_PROTOCOL_ENABLE) ?
271 "enabled" : "disabled");
272 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
273 len = sprintf(buf, "%s\n",
274 (ha->ip_config.ipv6_options &
275 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
276 "enabled" : "disabled");
277 break;
278 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
279 len = sprintf(buf, "%s\n",
280 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
281 "dhcp" : "static");
282 break;
283 case ISCSI_NET_PARAM_IPV6_ADDR:
284 if (iface->iface_num == 0)
285 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
286 if (iface->iface_num == 1)
287 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
288 break;
289 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
290 len = sprintf(buf, "%pI6\n",
291 &ha->ip_config.ipv6_link_local_addr);
292 break;
293 case ISCSI_NET_PARAM_IPV6_ROUTER:
294 len = sprintf(buf, "%pI6\n",
295 &ha->ip_config.ipv6_default_router_addr);
296 break;
297 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
298 len = sprintf(buf, "%s\n",
299 (ha->ip_config.ipv6_addl_options &
300 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
301 "nd" : "static");
302 break;
303 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
304 len = sprintf(buf, "%s\n",
305 (ha->ip_config.ipv6_addl_options &
306 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
307 "auto" : "static");
308 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500309 case ISCSI_NET_PARAM_VLAN_ID:
310 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
311 len = sprintf(buf, "%d\n",
312 (ha->ip_config.ipv4_vlan_tag &
313 ISCSI_MAX_VLAN_ID));
314 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
315 len = sprintf(buf, "%d\n",
316 (ha->ip_config.ipv6_vlan_tag &
317 ISCSI_MAX_VLAN_ID));
318 break;
319 case ISCSI_NET_PARAM_VLAN_PRIORITY:
320 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
321 len = sprintf(buf, "%d\n",
322 ((ha->ip_config.ipv4_vlan_tag >> 13) &
323 ISCSI_MAX_VLAN_PRIORITY));
324 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
325 len = sprintf(buf, "%d\n",
326 ((ha->ip_config.ipv6_vlan_tag >> 13) &
327 ISCSI_MAX_VLAN_PRIORITY));
328 break;
329 case ISCSI_NET_PARAM_VLAN_ENABLED:
330 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
331 len = sprintf(buf, "%s\n",
332 (ha->ip_config.ipv4_options &
333 IPOPT_VLAN_TAGGING_ENABLE) ?
334 "enabled" : "disabled");
335 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
336 len = sprintf(buf, "%s\n",
337 (ha->ip_config.ipv6_options &
338 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
339 "enabled" : "disabled");
340 break;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500341 default:
342 len = -ENOSYS;
343 }
344
345 return len;
346}
347
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500348static struct iscsi_endpoint *
349qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
350 int non_blocking)
351{
352 int ret;
353 struct iscsi_endpoint *ep;
354 struct qla_endpoint *qla_ep;
355 struct scsi_qla_host *ha;
356 struct sockaddr_in *addr;
357 struct sockaddr_in6 *addr6;
358
359 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
360 if (!shost) {
361 ret = -ENXIO;
362 printk(KERN_ERR "%s: shost is NULL\n",
363 __func__);
364 return ERR_PTR(ret);
365 }
366
367 ha = iscsi_host_priv(shost);
368
369 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
370 if (!ep) {
371 ret = -ENOMEM;
372 return ERR_PTR(ret);
373 }
374
375 qla_ep = ep->dd_data;
376 memset(qla_ep, 0, sizeof(struct qla_endpoint));
377 if (dst_addr->sa_family == AF_INET) {
378 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
379 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
380 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
381 (char *)&addr->sin_addr));
382 } else if (dst_addr->sa_family == AF_INET6) {
383 memcpy(&qla_ep->dst_addr, dst_addr,
384 sizeof(struct sockaddr_in6));
385 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
386 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
387 (char *)&addr6->sin6_addr));
388 }
389
390 qla_ep->host = shost;
391
392 return ep;
393}
394
395static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
396{
397 struct qla_endpoint *qla_ep;
398 struct scsi_qla_host *ha;
399 int ret = 0;
400
401 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
402 qla_ep = ep->dd_data;
403 ha = to_qla_host(qla_ep->host);
404
405 if (adapter_up(ha))
406 ret = 1;
407
408 return ret;
409}
410
411static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
412{
413 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
414 iscsi_destroy_endpoint(ep);
415}
416
417static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
418 enum iscsi_param param,
419 char *buf)
420{
421 struct qla_endpoint *qla_ep = ep->dd_data;
422 struct sockaddr *dst_addr;
423
424 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
425
426 switch (param) {
427 case ISCSI_PARAM_CONN_PORT:
428 case ISCSI_PARAM_CONN_ADDRESS:
429 if (!qla_ep)
430 return -ENOTCONN;
431
432 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
433 if (!dst_addr)
434 return -ENOTCONN;
435
436 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
437 &qla_ep->dst_addr, param, buf);
438 default:
439 return -ENOSYS;
440 }
441}
442
443static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
444 struct iscsi_stats *stats)
445{
446 struct iscsi_session *sess;
447 struct iscsi_cls_session *cls_sess;
448 struct ddb_entry *ddb_entry;
449 struct scsi_qla_host *ha;
450 struct ql_iscsi_stats *ql_iscsi_stats;
451 int stats_size;
452 int ret;
453 dma_addr_t iscsi_stats_dma;
454
455 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
456
457 cls_sess = iscsi_conn_to_session(cls_conn);
458 sess = cls_sess->dd_data;
459 ddb_entry = sess->dd_data;
460 ha = ddb_entry->ha;
461
462 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
463 /* Allocate memory */
464 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
465 &iscsi_stats_dma, GFP_KERNEL);
466 if (!ql_iscsi_stats) {
467 ql4_printk(KERN_ERR, ha,
468 "Unable to allocate memory for iscsi stats\n");
469 goto exit_get_stats;
470 }
471
472 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
473 iscsi_stats_dma);
474 if (ret != QLA_SUCCESS) {
475 ql4_printk(KERN_ERR, ha,
476 "Unable to retreive iscsi stats\n");
477 goto free_stats;
478 }
479
480 /* octets */
481 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
482 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
483 /* xmit pdus */
484 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
485 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
486 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
487 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
488 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
489 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
490 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
491 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
492 /* recv pdus */
493 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
494 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
495 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
496 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
497 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
498 stats->logoutrsp_pdus =
499 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
500 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
501 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
502 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
503
504free_stats:
505 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
506 iscsi_stats_dma);
507exit_get_stats:
508 return;
509}
510
Mike Christie5c656af2009-07-15 15:02:59 -0500511static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
512{
513 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500514 struct iscsi_session *sess;
515 unsigned long flags;
516 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -0500517
518 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500519 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -0500520
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500521 spin_lock_irqsave(&session->lock, flags);
522 if (session->state == ISCSI_SESSION_FAILED)
523 ret = BLK_EH_RESET_TIMER;
524 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -0500525
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500526 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700527}
528
Mike Christieaa1e93a2007-05-30 12:57:09 -0500529static int qla4xxx_host_get_param(struct Scsi_Host *shost,
530 enum iscsi_host_param param, char *buf)
531{
532 struct scsi_qla_host *ha = to_qla_host(shost);
533 int len;
534
535 switch (param) {
536 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800537 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500538 break;
Mike Christie22236962007-05-30 12:57:24 -0500539 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500540 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -0500541 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500542 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500543 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500544 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500545 default:
546 return -ENOSYS;
547 }
548
549 return len;
550}
551
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500552static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
553{
554 if (ha->iface_ipv4)
555 return;
556
557 /* IPv4 */
558 ha->iface_ipv4 = iscsi_create_iface(ha->host,
559 &qla4xxx_iscsi_transport,
560 ISCSI_IFACE_TYPE_IPV4, 0, 0);
561 if (!ha->iface_ipv4)
562 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
563 "iface0.\n");
564}
565
566static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
567{
568 if (!ha->iface_ipv6_0)
569 /* IPv6 iface-0 */
570 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
571 &qla4xxx_iscsi_transport,
572 ISCSI_IFACE_TYPE_IPV6, 0,
573 0);
574 if (!ha->iface_ipv6_0)
575 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
576 "iface0.\n");
577
578 if (!ha->iface_ipv6_1)
579 /* IPv6 iface-1 */
580 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
581 &qla4xxx_iscsi_transport,
582 ISCSI_IFACE_TYPE_IPV6, 1,
583 0);
584 if (!ha->iface_ipv6_1)
585 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
586 "iface1.\n");
587}
588
589static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
590{
591 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
592 qla4xxx_create_ipv4_iface(ha);
593
594 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
595 qla4xxx_create_ipv6_iface(ha);
596}
597
598static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
599{
600 if (ha->iface_ipv4) {
601 iscsi_destroy_iface(ha->iface_ipv4);
602 ha->iface_ipv4 = NULL;
603 }
604}
605
606static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
607{
608 if (ha->iface_ipv6_0) {
609 iscsi_destroy_iface(ha->iface_ipv6_0);
610 ha->iface_ipv6_0 = NULL;
611 }
612 if (ha->iface_ipv6_1) {
613 iscsi_destroy_iface(ha->iface_ipv6_1);
614 ha->iface_ipv6_1 = NULL;
615 }
616}
617
618static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
619{
620 qla4xxx_destroy_ipv4_iface(ha);
621 qla4xxx_destroy_ipv6_iface(ha);
622}
623
Mike Christied00efe32011-07-25 13:48:38 -0500624static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
625 struct iscsi_iface_param_info *iface_param,
626 struct addr_ctrl_blk *init_fw_cb)
627{
628 /*
629 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
630 * iface_num 1 is valid only for IPv6 Addr.
631 */
632 switch (iface_param->param) {
633 case ISCSI_NET_PARAM_IPV6_ADDR:
634 if (iface_param->iface_num & 0x1)
635 /* IPv6 Addr 1 */
636 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
637 sizeof(init_fw_cb->ipv6_addr1));
638 else
639 /* IPv6 Addr 0 */
640 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
641 sizeof(init_fw_cb->ipv6_addr0));
642 break;
643 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
644 if (iface_param->iface_num & 0x1)
645 break;
646 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
647 sizeof(init_fw_cb->ipv6_if_id));
648 break;
649 case ISCSI_NET_PARAM_IPV6_ROUTER:
650 if (iface_param->iface_num & 0x1)
651 break;
652 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
653 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
654 break;
655 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
656 /* Autocfg applies to even interface */
657 if (iface_param->iface_num & 0x1)
658 break;
659
660 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
661 init_fw_cb->ipv6_addtl_opts &=
662 cpu_to_le16(
663 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
664 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
665 init_fw_cb->ipv6_addtl_opts |=
666 cpu_to_le16(
667 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
668 else
669 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
670 "IPv6 addr\n");
671 break;
672 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
673 /* Autocfg applies to even interface */
674 if (iface_param->iface_num & 0x1)
675 break;
676
677 if (iface_param->value[0] ==
678 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
679 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
680 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
681 else if (iface_param->value[0] ==
682 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
683 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
684 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
685 else
686 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
687 "IPv6 linklocal addr\n");
688 break;
689 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
690 /* Autocfg applies to even interface */
691 if (iface_param->iface_num & 0x1)
692 break;
693
694 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
695 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
696 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
697 break;
698 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500699 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500700 init_fw_cb->ipv6_opts |=
701 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500702 qla4xxx_create_ipv6_iface(ha);
703 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500704 init_fw_cb->ipv6_opts &=
705 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
706 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500707 qla4xxx_destroy_ipv6_iface(ha);
708 }
Mike Christied00efe32011-07-25 13:48:38 -0500709 break;
710 case ISCSI_NET_PARAM_VLAN_ID:
711 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
712 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500713 init_fw_cb->ipv6_vlan_tag =
714 cpu_to_be16(*(uint16_t *)iface_param->value);
715 break;
716 case ISCSI_NET_PARAM_VLAN_ENABLED:
717 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
718 init_fw_cb->ipv6_opts |=
719 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
720 else
721 init_fw_cb->ipv6_opts &=
722 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500723 break;
724 default:
725 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
726 iface_param->param);
727 break;
728 }
729}
730
731static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
732 struct iscsi_iface_param_info *iface_param,
733 struct addr_ctrl_blk *init_fw_cb)
734{
735 switch (iface_param->param) {
736 case ISCSI_NET_PARAM_IPV4_ADDR:
737 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
738 sizeof(init_fw_cb->ipv4_addr));
739 break;
740 case ISCSI_NET_PARAM_IPV4_SUBNET:
741 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
742 sizeof(init_fw_cb->ipv4_subnet));
743 break;
744 case ISCSI_NET_PARAM_IPV4_GW:
745 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
746 sizeof(init_fw_cb->ipv4_gw_addr));
747 break;
748 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
749 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
750 init_fw_cb->ipv4_tcp_opts |=
751 cpu_to_le16(TCPOPT_DHCP_ENABLE);
752 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
753 init_fw_cb->ipv4_tcp_opts &=
754 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
755 else
756 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
757 break;
758 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500759 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500760 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500761 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500762 qla4xxx_create_ipv4_iface(ha);
763 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500764 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500765 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -0500766 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500767 qla4xxx_destroy_ipv4_iface(ha);
768 }
Mike Christied00efe32011-07-25 13:48:38 -0500769 break;
770 case ISCSI_NET_PARAM_VLAN_ID:
771 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
772 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500773 init_fw_cb->ipv4_vlan_tag =
774 cpu_to_be16(*(uint16_t *)iface_param->value);
775 break;
776 case ISCSI_NET_PARAM_VLAN_ENABLED:
777 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
778 init_fw_cb->ipv4_ip_opts |=
779 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
780 else
781 init_fw_cb->ipv4_ip_opts &=
782 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500783 break;
784 default:
785 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
786 iface_param->param);
787 break;
788 }
789}
790
791static void
792qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
793{
794 struct addr_ctrl_blk_def *acb;
795 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
796 memset(acb->reserved1, 0, sizeof(acb->reserved1));
797 memset(acb->reserved2, 0, sizeof(acb->reserved2));
798 memset(acb->reserved3, 0, sizeof(acb->reserved3));
799 memset(acb->reserved4, 0, sizeof(acb->reserved4));
800 memset(acb->reserved5, 0, sizeof(acb->reserved5));
801 memset(acb->reserved6, 0, sizeof(acb->reserved6));
802 memset(acb->reserved7, 0, sizeof(acb->reserved7));
803 memset(acb->reserved8, 0, sizeof(acb->reserved8));
804 memset(acb->reserved9, 0, sizeof(acb->reserved9));
805 memset(acb->reserved10, 0, sizeof(acb->reserved10));
806 memset(acb->reserved11, 0, sizeof(acb->reserved11));
807 memset(acb->reserved12, 0, sizeof(acb->reserved12));
808 memset(acb->reserved13, 0, sizeof(acb->reserved13));
809 memset(acb->reserved14, 0, sizeof(acb->reserved14));
810 memset(acb->reserved15, 0, sizeof(acb->reserved15));
811}
812
813static int
814qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
815{
816 struct scsi_qla_host *ha = to_qla_host(shost);
817 int rval = 0;
818 struct iscsi_iface_param_info *iface_param = NULL;
819 struct addr_ctrl_blk *init_fw_cb = NULL;
820 dma_addr_t init_fw_cb_dma;
821 uint32_t mbox_cmd[MBOX_REG_COUNT];
822 uint32_t mbox_sts[MBOX_REG_COUNT];
823 uint32_t total_param_count;
824 uint32_t length;
825
826 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
827 sizeof(struct addr_ctrl_blk),
828 &init_fw_cb_dma, GFP_KERNEL);
829 if (!init_fw_cb) {
830 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
831 __func__);
832 return -ENOMEM;
833 }
834
835 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
836 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
837 memset(&mbox_sts, 0, sizeof(mbox_sts));
838
839 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
840 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
841 rval = -EIO;
842 goto exit_init_fw_cb;
843 }
844
845 total_param_count = count;
846 iface_param = (struct iscsi_iface_param_info *)data;
847
848 for ( ; total_param_count != 0; total_param_count--) {
849 length = iface_param->len;
850
851 if (iface_param->param_type != ISCSI_NET_PARAM)
852 continue;
853
854 switch (iface_param->iface_type) {
855 case ISCSI_IFACE_TYPE_IPV4:
856 switch (iface_param->iface_num) {
857 case 0:
858 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
859 break;
860 default:
861 /* Cannot have more than one IPv4 interface */
862 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
863 "number = %d\n",
864 iface_param->iface_num);
865 break;
866 }
867 break;
868 case ISCSI_IFACE_TYPE_IPV6:
869 switch (iface_param->iface_num) {
870 case 0:
871 case 1:
872 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
873 break;
874 default:
875 /* Cannot have more than two IPv6 interface */
876 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
877 "number = %d\n",
878 iface_param->iface_num);
879 break;
880 }
881 break;
882 default:
883 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
884 break;
885 }
886
887 iface_param = (struct iscsi_iface_param_info *)
888 ((uint8_t *)iface_param +
889 sizeof(struct iscsi_iface_param_info) + length);
890 }
891
892 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
893
894 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
895 sizeof(struct addr_ctrl_blk),
896 FLASH_OPT_RMW_COMMIT);
897 if (rval != QLA_SUCCESS) {
898 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
899 __func__);
900 rval = -EIO;
901 goto exit_init_fw_cb;
902 }
903
904 qla4xxx_disable_acb(ha);
905
906 qla4xxx_initcb_to_acb(init_fw_cb);
907
908 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
909 if (rval != QLA_SUCCESS) {
910 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
911 __func__);
912 rval = -EIO;
913 goto exit_init_fw_cb;
914 }
915
916 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
917 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
918 init_fw_cb_dma);
919
920exit_init_fw_cb:
921 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
922 init_fw_cb, init_fw_cb_dma);
923
924 return rval;
925}
926
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500927static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700928 enum iscsi_param param, char *buf)
929{
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500930 struct iscsi_conn *conn;
931 struct qla_conn *qla_conn;
932 struct sockaddr *dst_addr;
933 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700934
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500935 conn = cls_conn->dd_data;
936 qla_conn = conn->dd_data;
937 dst_addr = &qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700938
939 switch (param) {
940 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700941 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500942 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
943 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700944 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500945 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700946 }
947
948 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500949
David Somayajuluafaf5a22006-09-19 10:28:00 -0700950}
951
Mike Christie2174a042007-05-30 12:57:10 -0500952static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost,
953 enum iscsi_tgt_dscvr type, uint32_t enable,
954 struct sockaddr *dst_addr)
David Somayajuluafaf5a22006-09-19 10:28:00 -0700955{
956 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700957 struct sockaddr_in *addr;
958 struct sockaddr_in6 *addr6;
959 int ret = 0;
960
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500961 ha = (struct scsi_qla_host *) to_qla_host(shost);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700962
963 switch (type) {
964 case ISCSI_TGT_DSCVR_SEND_TARGETS:
965 if (dst_addr->sa_family == AF_INET) {
966 addr = (struct sockaddr_in *)dst_addr;
967 if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr,
968 addr->sin_port) != QLA_SUCCESS)
969 ret = -EIO;
970 } else if (dst_addr->sa_family == AF_INET6) {
971 /*
972 * TODO: fix qla4xxx_send_tgts
973 */
974 addr6 = (struct sockaddr_in6 *)dst_addr;
975 if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr,
976 addr6->sin6_port) != QLA_SUCCESS)
977 ret = -EIO;
978 } else
979 ret = -ENOSYS;
980 break;
981 default:
982 ret = -ENOSYS;
983 }
David Somayajuluafaf5a22006-09-19 10:28:00 -0700984 return ret;
985}
986
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500987static struct iscsi_cls_session *
988qla4xxx_session_create(struct iscsi_endpoint *ep,
989 uint16_t cmds_max, uint16_t qdepth,
990 uint32_t initial_cmdsn)
991{
992 struct iscsi_cls_session *cls_sess;
993 struct scsi_qla_host *ha;
994 struct qla_endpoint *qla_ep;
995 struct ddb_entry *ddb_entry;
996 uint32_t ddb_index;
997 uint32_t mbx_sts = 0;
998 struct iscsi_session *sess;
999 struct sockaddr *dst_addr;
1000 int ret;
1001
1002 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1003 if (!ep) {
1004 printk(KERN_ERR "qla4xxx: missing ep.\n");
1005 return NULL;
1006 }
1007
1008 qla_ep = ep->dd_data;
1009 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1010 ha = to_qla_host(qla_ep->host);
1011get_ddb_index:
1012 ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1013
1014 if (ddb_index >= MAX_DDB_ENTRIES) {
1015 DEBUG2(ql4_printk(KERN_INFO, ha,
1016 "Free DDB index not available\n"));
1017 return NULL;
1018 }
1019
1020 if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
1021 goto get_ddb_index;
1022
1023 DEBUG2(ql4_printk(KERN_INFO, ha,
1024 "Found a free DDB index at %d\n", ddb_index));
1025 ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
1026 if (ret == QLA_ERROR) {
1027 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1028 ql4_printk(KERN_INFO, ha,
1029 "DDB index = %d not available trying next\n",
1030 ddb_index);
1031 goto get_ddb_index;
1032 }
1033 DEBUG2(ql4_printk(KERN_INFO, ha,
1034 "Free FW DDB not available\n"));
1035 return NULL;
1036 }
1037
1038 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1039 cmds_max, sizeof(struct ddb_entry),
1040 sizeof(struct ql4_task_data),
1041 initial_cmdsn, ddb_index);
1042 if (!cls_sess)
1043 return NULL;
1044
1045 sess = cls_sess->dd_data;
1046 ddb_entry = sess->dd_data;
1047 ddb_entry->fw_ddb_index = ddb_index;
1048 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1049 ddb_entry->ha = ha;
1050 ddb_entry->sess = cls_sess;
1051 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1052 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1053 ha->tot_ddbs++;
1054
1055 return cls_sess;
1056}
1057
1058static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1059{
1060 struct iscsi_session *sess;
1061 struct ddb_entry *ddb_entry;
1062 struct scsi_qla_host *ha;
1063 unsigned long flags;
1064
1065 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1066 sess = cls_sess->dd_data;
1067 ddb_entry = sess->dd_data;
1068 ha = ddb_entry->ha;
1069
1070 spin_lock_irqsave(&ha->hardware_lock, flags);
1071 qla4xxx_free_ddb(ha, ddb_entry);
1072 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1073 iscsi_session_teardown(cls_sess);
1074}
1075
David Somayajuluafaf5a22006-09-19 10:28:00 -07001076void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry)
1077{
1078 if (!ddb_entry->sess)
1079 return;
1080
1081 if (ddb_entry->conn) {
Mike Christie26974782007-12-13 12:43:29 -06001082 atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001083 iscsi_remove_session(ddb_entry->sess);
1084 }
1085 iscsi_free_session(ddb_entry->sess);
1086}
1087
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001088static struct iscsi_cls_conn *
1089qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1090{
1091 struct iscsi_cls_conn *cls_conn;
1092 struct iscsi_session *sess;
1093 struct ddb_entry *ddb_entry;
1094
1095 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1096 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1097 conn_idx);
1098 sess = cls_sess->dd_data;
1099 ddb_entry = sess->dd_data;
1100 ddb_entry->conn = cls_conn;
1101
1102 return cls_conn;
1103}
1104
1105static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1106 struct iscsi_cls_conn *cls_conn,
1107 uint64_t transport_fd, int is_leading)
1108{
1109 struct iscsi_conn *conn;
1110 struct qla_conn *qla_conn;
1111 struct iscsi_endpoint *ep;
1112
1113 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1114
1115 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1116 return -EINVAL;
1117 ep = iscsi_lookup_endpoint(transport_fd);
1118 conn = cls_conn->dd_data;
1119 qla_conn = conn->dd_data;
1120 qla_conn->qla_ep = ep->dd_data;
1121 return 0;
1122}
1123
1124static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1125{
1126 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1127 struct iscsi_session *sess;
1128 struct ddb_entry *ddb_entry;
1129 struct scsi_qla_host *ha;
1130 struct dev_db_entry *fw_ddb_entry;
1131 dma_addr_t fw_ddb_entry_dma;
1132 uint32_t fw_ddb_device_state;
1133 uint32_t mbx_sts = 0;
1134 int ret = 0;
1135 int status = QLA_SUCCESS;
1136
1137 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1138 sess = cls_sess->dd_data;
1139 ddb_entry = sess->dd_data;
1140 ha = ddb_entry->ha;
1141
1142 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1143 &fw_ddb_entry_dma, GFP_KERNEL);
1144 if (!fw_ddb_entry) {
1145 ql4_printk(KERN_ERR, ha,
1146 "%s: Unable to allocate dma buffer\n", __func__);
1147 return -ENOMEM;
1148 }
1149
1150 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1151 if (ret) {
1152 /* If iscsid is stopped and started then no need to do
1153 * set param again since ddb state will be already
1154 * active and FW does not allow set ddb to an
1155 * active session.
1156 */
1157 if (mbx_sts)
1158 if (ddb_entry->fw_ddb_device_state ==
1159 DDB_DS_SESSION_ACTIVE)
1160 goto exit_set_param;
1161
1162 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1163 __func__, ddb_entry->fw_ddb_index);
1164 goto exit_conn_start;
1165 }
1166
1167 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1168 if (status == QLA_ERROR) {
1169 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s %s:%d\n",
1170 __func__, ddb_entry->iscsi_name,
1171 ddb_entry->ip_addr, ddb_entry->port);
1172 ret = -EINVAL;
1173 goto exit_conn_start;
1174 }
1175
1176 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1177
1178exit_set_param:
1179 iscsi_conn_start(cls_conn);
1180 ret = 0;
1181
1182exit_conn_start:
1183 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1184 fw_ddb_entry, fw_ddb_entry_dma);
1185 return ret;
1186}
1187
1188static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1189{
1190 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1191 struct iscsi_session *sess;
1192 struct scsi_qla_host *ha;
1193 struct ddb_entry *ddb_entry;
1194 int options;
1195
1196 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1197 sess = cls_sess->dd_data;
1198 ddb_entry = sess->dd_data;
1199 ha = ddb_entry->ha;
1200
1201 options = LOGOUT_OPTION_CLOSE_SESSION;
1202 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1203 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1204 else
1205 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1206
1207 /*
1208 * Clear the DDB bit so that next login can use the bit
1209 * if FW is not clearing the DDB entry then set DDB will fail anyways
1210 */
1211 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
1212}
1213
1214static void qla4xxx_task_work(struct work_struct *wdata)
1215{
1216 struct ql4_task_data *task_data;
1217 struct scsi_qla_host *ha;
1218 struct passthru_status *sts;
1219 struct iscsi_task *task;
1220 struct iscsi_hdr *hdr;
1221 uint8_t *data;
1222 uint32_t data_len;
1223 struct iscsi_conn *conn;
1224 int hdr_len;
1225 itt_t itt;
1226
1227 task_data = container_of(wdata, struct ql4_task_data, task_work);
1228 ha = task_data->ha;
1229 task = task_data->task;
1230 sts = &task_data->sts;
1231 hdr_len = sizeof(struct iscsi_hdr);
1232
1233 DEBUG3(printk(KERN_INFO "Status returned\n"));
1234 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1235 DEBUG3(printk(KERN_INFO "Response buffer"));
1236 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1237
1238 conn = task->conn;
1239
1240 switch (sts->completionStatus) {
1241 case PASSTHRU_STATUS_COMPLETE:
1242 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1243 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1244 itt = sts->handle;
1245 hdr->itt = itt;
1246 data = task_data->resp_buffer + hdr_len;
1247 data_len = task_data->resp_len - hdr_len;
1248 iscsi_complete_pdu(conn, hdr, data, data_len);
1249 break;
1250 default:
1251 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1252 sts->completionStatus);
1253 break;
1254 }
1255 return;
1256}
1257
1258static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1259{
1260 struct ql4_task_data *task_data;
1261 struct iscsi_session *sess;
1262 struct ddb_entry *ddb_entry;
1263 struct scsi_qla_host *ha;
1264 int hdr_len;
1265
1266 sess = task->conn->session;
1267 ddb_entry = sess->dd_data;
1268 ha = ddb_entry->ha;
1269 task_data = task->dd_data;
1270 memset(task_data, 0, sizeof(struct ql4_task_data));
1271
1272 if (task->sc) {
1273 ql4_printk(KERN_INFO, ha,
1274 "%s: SCSI Commands not implemented\n", __func__);
1275 return -EINVAL;
1276 }
1277
1278 hdr_len = sizeof(struct iscsi_hdr);
1279 task_data->ha = ha;
1280 task_data->task = task;
1281
1282 if (task->data_count) {
1283 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1284 task->data_count,
1285 PCI_DMA_TODEVICE);
1286 }
1287
1288 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1289 __func__, task->conn->max_recv_dlength, hdr_len));
1290
1291 task_data->resp_len = task->conn->max_recv_dlength;
1292 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1293 task_data->resp_len,
1294 &task_data->resp_dma,
1295 GFP_ATOMIC);
1296 if (!task_data->resp_buffer)
1297 goto exit_alloc_pdu;
1298
1299 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1300 task->data_count + hdr_len,
1301 &task_data->req_dma,
1302 GFP_ATOMIC);
1303 if (!task_data->req_buffer)
1304 goto exit_alloc_pdu;
1305
1306 task->hdr = task_data->req_buffer;
1307
1308 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1309
1310 return 0;
1311
1312exit_alloc_pdu:
1313 if (task_data->resp_buffer)
1314 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1315 task_data->resp_buffer, task_data->resp_dma);
1316
1317 if (task_data->req_buffer)
1318 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1319 task_data->req_buffer, task_data->req_dma);
1320 return -ENOMEM;
1321}
1322
1323static void qla4xxx_task_cleanup(struct iscsi_task *task)
1324{
1325 struct ql4_task_data *task_data;
1326 struct iscsi_session *sess;
1327 struct ddb_entry *ddb_entry;
1328 struct scsi_qla_host *ha;
1329 int hdr_len;
1330
1331 hdr_len = sizeof(struct iscsi_hdr);
1332 sess = task->conn->session;
1333 ddb_entry = sess->dd_data;
1334 ha = ddb_entry->ha;
1335 task_data = task->dd_data;
1336
1337 if (task->data_count) {
1338 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1339 task->data_count, PCI_DMA_TODEVICE);
1340 }
1341
1342 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1343 __func__, task->conn->max_recv_dlength, hdr_len));
1344
1345 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1346 task_data->resp_buffer, task_data->resp_dma);
1347 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1348 task_data->req_buffer, task_data->req_dma);
1349 return;
1350}
1351
1352static int qla4xxx_task_xmit(struct iscsi_task *task)
1353{
1354 struct scsi_cmnd *sc = task->sc;
1355 struct iscsi_session *sess = task->conn->session;
1356 struct ddb_entry *ddb_entry = sess->dd_data;
1357 struct scsi_qla_host *ha = ddb_entry->ha;
1358
1359 if (!sc)
1360 return qla4xxx_send_passthru0(task);
1361
1362 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1363 __func__);
1364 return -ENOSYS;
1365}
1366
1367void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1368 struct ddb_entry *ddb_entry)
1369{
1370 struct iscsi_cls_session *cls_sess;
1371 struct iscsi_cls_conn *cls_conn;
1372 struct iscsi_session *sess;
1373 struct iscsi_conn *conn;
1374 uint32_t ddb_state;
1375 dma_addr_t fw_ddb_entry_dma;
1376 struct dev_db_entry *fw_ddb_entry;
1377
1378 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1379 &fw_ddb_entry_dma, GFP_KERNEL);
1380 if (!fw_ddb_entry) {
1381 ql4_printk(KERN_ERR, ha,
1382 "%s: Unable to allocate dma buffer\n", __func__);
1383 return;
1384 }
1385
1386 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1387 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1388 NULL, NULL, NULL) == QLA_ERROR) {
1389 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1390 "get_ddb_entry for fw_ddb_index %d\n",
1391 ha->host_no, __func__,
1392 ddb_entry->fw_ddb_index));
1393 return;
1394 }
1395
1396 cls_sess = ddb_entry->sess;
1397 sess = cls_sess->dd_data;
1398
1399 cls_conn = ddb_entry->conn;
1400 conn = cls_conn->dd_data;
1401
1402 /* Update params */
1403 conn->max_recv_dlength = BYTE_UNITS *
1404 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1405
1406 conn->max_xmit_dlength = BYTE_UNITS *
1407 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1408
1409 sess->initial_r2t_en =
1410 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1411
1412 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1413
1414 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1415
1416 sess->first_burst = BYTE_UNITS *
1417 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1418
1419 sess->max_burst = BYTE_UNITS *
1420 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1421
1422 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1423
1424 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1425
1426 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1427
1428 memcpy(sess->initiatorname, ha->name_string,
1429 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
1430}
1431
David Somayajuluafaf5a22006-09-19 10:28:00 -07001432int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
1433{
1434 int err;
1435
Vikas Chaudhary30387272011-03-21 03:34:32 -07001436 ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo;
Vikas Chaudhary3013cea2010-07-30 14:25:46 +05301437
David Somayajuluafaf5a22006-09-19 10:28:00 -07001438 err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index);
1439 if (err) {
1440 DEBUG2(printk(KERN_ERR "Could not add session.\n"));
1441 return err;
1442 }
1443
Mike Christie5d91e202008-05-21 15:54:01 -05001444 ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001445 if (!ddb_entry->conn) {
1446 iscsi_remove_session(ddb_entry->sess);
1447 DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
1448 return -ENOMEM;
1449 }
Mike Christieb6359302008-01-31 13:36:44 -06001450
1451 /* finally ready to go */
1452 iscsi_unblock_session(ddb_entry->sess);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001453 return 0;
1454}
1455
1456struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha)
1457{
1458 struct ddb_entry *ddb_entry;
1459 struct iscsi_cls_session *sess;
1460
Mike Christie5d91e202008-05-21 15:54:01 -05001461 sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport,
1462 sizeof(struct ddb_entry));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001463 if (!sess)
1464 return NULL;
1465
1466 ddb_entry = sess->dd_data;
1467 memset(ddb_entry, 0, sizeof(*ddb_entry));
1468 ddb_entry->ha = ha;
1469 ddb_entry->sess = sess;
1470 return ddb_entry;
1471}
1472
Mike Christie024f8012008-03-04 13:26:54 -06001473static void qla4xxx_scan_start(struct Scsi_Host *shost)
1474{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001475 struct scsi_qla_host *ha = to_qla_host(shost);
Mike Christie024f8012008-03-04 13:26:54 -06001476 struct ddb_entry *ddb_entry, *ddbtemp;
1477
1478 /* finish setup of sessions that were already setup in firmware */
1479 list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) {
1480 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE)
1481 qla4xxx_add_sess(ddb_entry);
1482 }
1483}
1484
David Somayajuluafaf5a22006-09-19 10:28:00 -07001485/*
1486 * Timer routines
1487 */
1488
1489static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
1490 unsigned long interval)
1491{
1492 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
1493 __func__, ha->host->host_no));
1494 init_timer(&ha->timer);
1495 ha->timer.expires = jiffies + interval * HZ;
1496 ha->timer.data = (unsigned long)ha;
1497 ha->timer.function = (void (*)(unsigned long))func;
1498 add_timer(&ha->timer);
1499 ha->timer_active = 1;
1500}
1501
1502static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
1503{
1504 del_timer_sync(&ha->timer);
1505 ha->timer_active = 0;
1506}
1507
1508/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001509 * qla4xxx_mark_device_missing - blocks the session
1510 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07001511 * @ddb_entry: Pointer to device database entry
1512 *
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301513 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001514 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001515void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001516{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001517 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001518}
1519
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301520/**
1521 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
1522 * @ha: Pointer to host adapter structure.
1523 *
1524 * This routine marks a device missing and resets the relogin retry count.
1525 **/
1526void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
1527{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001528 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301529}
1530
David Somayajuluafaf5a22006-09-19 10:28:00 -07001531static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1532 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001533 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001534{
1535 struct srb *srb;
1536
1537 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
1538 if (!srb)
1539 return srb;
1540
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301541 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001542 srb->ha = ha;
1543 srb->ddb = ddb_entry;
1544 srb->cmd = cmd;
1545 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05301546 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001547
1548 return srb;
1549}
1550
1551static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1552{
1553 struct scsi_cmnd *cmd = srb->cmd;
1554
1555 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09001556 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001557 srb->flags &= ~SRB_DMA_VALID;
1558 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05301559 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001560}
1561
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301562void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001563{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301564 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001565 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301566 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001567
1568 qla4xxx_srb_free_dma(ha, srb);
1569
1570 mempool_free(srb, ha->srb_mempool);
1571
1572 cmd->scsi_done(cmd);
1573}
1574
1575/**
1576 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001577 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07001578 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07001579 *
1580 * Remarks:
1581 * This routine is invoked by Linux to send a SCSI command to the driver.
1582 * The mid-level driver tries to ensure that queuecommand never gets
1583 * invoked concurrently with itself or the interrupt handler (although
1584 * the interrupt handler may call this routine as part of request-
1585 * completion handling). Unfortunely, it sometimes calls the scheduler
1586 * in interrupt context which is a big NO! NO!.
1587 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001588static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001589{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001590 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001591 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06001592 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001593 struct srb *srb;
1594 int rval;
1595
Lalit Chandivade2232be02010-07-30 14:38:47 +05301596 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1597 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1598 cmd->result = DID_NO_CONNECT << 16;
1599 else
1600 cmd->result = DID_REQUEUE << 16;
1601 goto qc_fail_command;
1602 }
1603
Mike Christie7fb19212008-01-31 13:36:45 -06001604 if (!sess) {
1605 cmd->result = DID_IMM_RETRY << 16;
1606 goto qc_fail_command;
1607 }
1608
1609 rval = iscsi_session_chkready(sess);
1610 if (rval) {
1611 cmd->result = rval;
1612 goto qc_fail_command;
1613 }
1614
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301615 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1616 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1617 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1618 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1619 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1620 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001621 !test_bit(AF_LINK_UP, &ha->flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301622 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08001623 goto qc_host_busy;
1624
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001625 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001626 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001627 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001628
1629 rval = qla4xxx_send_command_to_isp(ha, srb);
1630 if (rval != QLA_SUCCESS)
1631 goto qc_host_busy_free_sp;
1632
David Somayajuluafaf5a22006-09-19 10:28:00 -07001633 return 0;
1634
1635qc_host_busy_free_sp:
1636 qla4xxx_srb_free_dma(ha, srb);
1637 mempool_free(srb, ha->srb_mempool);
1638
David Somayajuluafaf5a22006-09-19 10:28:00 -07001639qc_host_busy:
1640 return SCSI_MLQUEUE_HOST_BUSY;
1641
1642qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001643 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001644
1645 return 0;
1646}
1647
1648/**
1649 * qla4xxx_mem_free - frees memory allocated to adapter
1650 * @ha: Pointer to host adapter structure.
1651 *
1652 * Frees memory previously allocated by qla4xxx_mem_alloc
1653 **/
1654static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1655{
1656 if (ha->queues)
1657 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1658 ha->queues_dma);
1659
1660 ha->queues_len = 0;
1661 ha->queues = NULL;
1662 ha->queues_dma = 0;
1663 ha->request_ring = NULL;
1664 ha->request_dma = 0;
1665 ha->response_ring = NULL;
1666 ha->response_dma = 0;
1667 ha->shadow_regs = NULL;
1668 ha->shadow_regs_dma = 0;
1669
1670 /* Free srb pool. */
1671 if (ha->srb_mempool)
1672 mempool_destroy(ha->srb_mempool);
1673
1674 ha->srb_mempool = NULL;
1675
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001676 if (ha->chap_dma_pool)
1677 dma_pool_destroy(ha->chap_dma_pool);
1678
David Somayajuluafaf5a22006-09-19 10:28:00 -07001679 /* release io space registers */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301680 if (is_qla8022(ha)) {
1681 if (ha->nx_pcibase)
1682 iounmap(
1683 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301684 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001685 iounmap(ha->reg);
1686 pci_release_regions(ha->pdev);
1687}
1688
1689/**
1690 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1691 * @ha: Pointer to host adapter structure
1692 *
1693 * Allocates DMA memory for request and response queues. Also allocates memory
1694 * for srbs.
1695 **/
1696static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1697{
1698 unsigned long align;
1699
1700 /* Allocate contiguous block of DMA memory for queues. */
1701 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1702 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1703 sizeof(struct shadow_regs) +
1704 MEM_ALIGN_VALUE +
1705 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1706 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1707 &ha->queues_dma, GFP_KERNEL);
1708 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301709 ql4_printk(KERN_WARNING, ha,
1710 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001711
1712 goto mem_alloc_error_exit;
1713 }
1714 memset(ha->queues, 0, ha->queues_len);
1715
1716 /*
1717 * As per RISC alignment requirements -- the bus-address must be a
1718 * multiple of the request-ring size (in bytes).
1719 */
1720 align = 0;
1721 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1722 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1723 (MEM_ALIGN_VALUE - 1));
1724
1725 /* Update request and response queue pointers. */
1726 ha->request_dma = ha->queues_dma + align;
1727 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1728 ha->response_dma = ha->queues_dma + align +
1729 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1730 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1731 (REQUEST_QUEUE_DEPTH *
1732 QUEUE_SIZE));
1733 ha->shadow_regs_dma = ha->queues_dma + align +
1734 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1735 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1736 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1737 (REQUEST_QUEUE_DEPTH *
1738 QUEUE_SIZE) +
1739 (RESPONSE_QUEUE_DEPTH *
1740 QUEUE_SIZE));
1741
1742 /* Allocate memory for srb pool. */
1743 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1744 mempool_free_slab, srb_cachep);
1745 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301746 ql4_printk(KERN_WARNING, ha,
1747 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001748
1749 goto mem_alloc_error_exit;
1750 }
1751
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001752 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
1753 CHAP_DMA_BLOCK_SIZE, 8, 0);
1754
1755 if (ha->chap_dma_pool == NULL) {
1756 ql4_printk(KERN_WARNING, ha,
1757 "%s: chap_dma_pool allocation failed..\n", __func__);
1758 goto mem_alloc_error_exit;
1759 }
1760
David Somayajuluafaf5a22006-09-19 10:28:00 -07001761 return QLA_SUCCESS;
1762
1763mem_alloc_error_exit:
1764 qla4xxx_mem_free(ha);
1765 return QLA_ERROR;
1766}
1767
1768/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301769 * qla4_8xxx_check_fw_alive - Check firmware health
1770 * @ha: Pointer to host adapter structure.
1771 *
1772 * Context: Interrupt
1773 **/
1774static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
1775{
1776 uint32_t fw_heartbeat_counter, halt_status;
1777
1778 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05301779 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1780 if (fw_heartbeat_counter == 0xffffffff) {
1781 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
1782 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1783 ha->host_no, __func__));
1784 return;
1785 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301786
1787 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
1788 ha->seconds_since_last_heartbeat++;
1789 /* FW not alive after 2 seconds */
1790 if (ha->seconds_since_last_heartbeat == 2) {
1791 ha->seconds_since_last_heartbeat = 0;
1792 halt_status = qla4_8xxx_rd_32(ha,
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07001793 QLA82XX_PEG_HALT_STATUS1);
1794
1795 ql4_printk(KERN_INFO, ha,
1796 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1797 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1798 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1799 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1800 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1801 ha->host_no, __func__, halt_status,
1802 qla4_8xxx_rd_32(ha,
1803 QLA82XX_PEG_HALT_STATUS2),
1804 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
1805 0x3c),
1806 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
1807 0x3c),
1808 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
1809 0x3c),
1810 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
1811 0x3c),
1812 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
1813 0x3c));
Nilesh Javali21033632010-07-30 14:28:07 +05301814
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301815 /* Since we cannot change dev_state in interrupt
1816 * context, set appropriate DPC flag then wakeup
1817 * DPC */
1818 if (halt_status & HALT_STATUS_UNRECOVERABLE)
1819 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1820 else {
1821 printk("scsi%ld: %s: detect abort needed!\n",
1822 ha->host_no, __func__);
1823 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1824 }
1825 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +05301826 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301827 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07001828 } else
1829 ha->seconds_since_last_heartbeat = 0;
1830
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301831 ha->fw_heartbeat_counter = fw_heartbeat_counter;
1832}
1833
1834/**
1835 * qla4_8xxx_watchdog - Poll dev state
1836 * @ha: Pointer to host adapter structure.
1837 *
1838 * Context: Interrupt
1839 **/
1840void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
1841{
1842 uint32_t dev_state;
1843
1844 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1845
1846 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08001847 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1848 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07001849 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301850 if (dev_state == QLA82XX_DEV_NEED_RESET &&
1851 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001852 if (!ql4xdontresethba) {
1853 ql4_printk(KERN_INFO, ha, "%s: HW State: "
1854 "NEED RESET!\n", __func__);
1855 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1856 qla4xxx_wake_dpc(ha);
1857 qla4xxx_mailbox_premature_completion(ha);
1858 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301859 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
1860 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001861 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
1862 __func__);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301863 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
1864 qla4xxx_wake_dpc(ha);
1865 } else {
1866 /* Check firmware health */
1867 qla4_8xxx_check_fw_alive(ha);
1868 }
1869 }
1870}
1871
1872/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001873 * qla4xxx_timer - checks every second for work to do.
1874 * @ha: Pointer to host adapter structure.
1875 **/
1876static void qla4xxx_timer(struct scsi_qla_host *ha)
1877{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001878 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301879 uint16_t w;
1880
1881 /* If we are in the middle of AER/EEH processing
1882 * skip any processing and reschedule the timer
1883 */
1884 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1885 mod_timer(&ha->timer, jiffies + HZ);
1886 return;
1887 }
1888
1889 /* Hardware read to trigger an EEH error during mailbox waits. */
1890 if (!pci_channel_offline(ha->pdev))
1891 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001892
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301893 if (is_qla8022(ha)) {
1894 qla4_8xxx_watchdog(ha);
1895 }
1896
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301897 if (!is_qla8022(ha)) {
1898 /* Check for heartbeat interval. */
1899 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1900 ha->heartbeat_interval != 0) {
1901 ha->seconds_since_last_heartbeat++;
1902 if (ha->seconds_since_last_heartbeat >
1903 ha->heartbeat_interval + 2)
1904 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1905 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001906 }
1907
David Somayajuluafaf5a22006-09-19 10:28:00 -07001908 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07001909 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001910 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1911 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1912 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301913 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001914 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1915 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301916 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301917 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1918 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07001919 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001920 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1921 " - dpc flags = 0x%lx\n",
1922 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301923 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001924 }
1925
1926 /* Reschedule timer thread to call us back in one second */
1927 mod_timer(&ha->timer, jiffies + HZ);
1928
1929 DEBUG2(ha->seconds_since_last_intr++);
1930}
1931
1932/**
1933 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1934 * @ha: Pointer to host adapter structure.
1935 *
1936 * This routine stalls the driver until all outstanding commands are returned.
1937 * Caller must release the Hardware Lock prior to calling this routine.
1938 **/
1939static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
1940{
1941 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001942 unsigned long flags;
1943 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001944
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301945 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
1946
1947 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
1948 "complete\n", WAIT_CMD_TOV));
1949
1950 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001951 spin_lock_irqsave(&ha->hardware_lock, flags);
1952 /* Find a command that hasn't completed. */
1953 for (index = 0; index < ha->host->can_queue; index++) {
1954 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07001955 /*
1956 * We cannot just check if the index is valid,
1957 * becase if we are run from the scsi eh, then
1958 * the scsi/block layer is going to prevent
1959 * the tag from being released.
1960 */
1961 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001962 break;
1963 }
1964 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1965
1966 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301967 if (index == ha->host->can_queue)
1968 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001969
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301970 msleep(1000);
1971 }
1972 /* If we timed out on waiting for commands to come back
1973 * return ERROR. */
1974 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001975}
1976
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301977int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001978{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001979 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001980 unsigned long flags = 0;
1981
1982 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001983
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05301984 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
1985 return QLA_ERROR;
1986
David Somayajuluafaf5a22006-09-19 10:28:00 -07001987 spin_lock_irqsave(&ha->hardware_lock, flags);
1988
1989 /*
1990 * If the SCSI Reset Interrupt bit is set, clear it.
1991 * Otherwise, the Soft Reset won't work.
1992 */
1993 ctrl_status = readw(&ha->reg->ctrl_status);
1994 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
1995 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1996
1997 /* Issue Soft Reset */
1998 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1999 readl(&ha->reg->ctrl_status);
2000
2001 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302002 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08002003}
2004
2005/**
2006 * qla4xxx_soft_reset - performs soft reset.
2007 * @ha: Pointer to host adapter structure.
2008 **/
2009int qla4xxx_soft_reset(struct scsi_qla_host *ha)
2010{
2011 uint32_t max_wait_time;
2012 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002013 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08002014 uint32_t ctrl_status;
2015
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002016 status = qla4xxx_hw_reset(ha);
2017 if (status != QLA_SUCCESS)
2018 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002019
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002020 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002021 /* Wait until the Network Reset Intr bit is cleared */
2022 max_wait_time = RESET_INTR_TOV;
2023 do {
2024 spin_lock_irqsave(&ha->hardware_lock, flags);
2025 ctrl_status = readw(&ha->reg->ctrl_status);
2026 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2027
2028 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
2029 break;
2030
2031 msleep(1000);
2032 } while ((--max_wait_time));
2033
2034 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
2035 DEBUG2(printk(KERN_WARNING
2036 "scsi%ld: Network Reset Intr not cleared by "
2037 "Network function, clearing it now!\n",
2038 ha->host_no));
2039 spin_lock_irqsave(&ha->hardware_lock, flags);
2040 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
2041 readl(&ha->reg->ctrl_status);
2042 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2043 }
2044
2045 /* Wait until the firmware tells us the Soft Reset is done */
2046 max_wait_time = SOFT_RESET_TOV;
2047 do {
2048 spin_lock_irqsave(&ha->hardware_lock, flags);
2049 ctrl_status = readw(&ha->reg->ctrl_status);
2050 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2051
2052 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
2053 status = QLA_SUCCESS;
2054 break;
2055 }
2056
2057 msleep(1000);
2058 } while ((--max_wait_time));
2059
2060 /*
2061 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
2062 * after the soft reset has taken place.
2063 */
2064 spin_lock_irqsave(&ha->hardware_lock, flags);
2065 ctrl_status = readw(&ha->reg->ctrl_status);
2066 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
2067 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2068 readl(&ha->reg->ctrl_status);
2069 }
2070 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2071
2072 /* If soft reset fails then most probably the bios on other
2073 * function is also enabled.
2074 * Since the initialization is sequential the other fn
2075 * wont be able to acknowledge the soft reset.
2076 * Issue a force soft reset to workaround this scenario.
2077 */
2078 if (max_wait_time == 0) {
2079 /* Issue Force Soft Reset */
2080 spin_lock_irqsave(&ha->hardware_lock, flags);
2081 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
2082 readl(&ha->reg->ctrl_status);
2083 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2084 /* Wait until the firmware tells us the Soft Reset is done */
2085 max_wait_time = SOFT_RESET_TOV;
2086 do {
2087 spin_lock_irqsave(&ha->hardware_lock, flags);
2088 ctrl_status = readw(&ha->reg->ctrl_status);
2089 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2090
2091 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
2092 status = QLA_SUCCESS;
2093 break;
2094 }
2095
2096 msleep(1000);
2097 } while ((--max_wait_time));
2098 }
2099
2100 return status;
2101}
2102
2103/**
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302104 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002105 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302106 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07002107 *
2108 * This routine is called just prior to a HARD RESET to return all
2109 * outstanding commands back to the Operating System.
2110 * Caller should make sure that the following locks are released
2111 * before this calling routine: Hardware lock, and io_request_lock.
2112 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302113static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002114{
2115 struct srb *srb;
2116 int i;
2117 unsigned long flags;
2118
2119 spin_lock_irqsave(&ha->hardware_lock, flags);
2120 for (i = 0; i < ha->host->can_queue; i++) {
2121 srb = qla4xxx_del_from_active_array(ha, i);
2122 if (srb != NULL) {
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302123 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302124 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002125 }
2126 }
2127 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002128}
2129
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302130void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2131{
2132 clear_bit(AF_ONLINE, &ha->flags);
2133
2134 /* Disable the board */
2135 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302136
2137 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2138 qla4xxx_mark_all_devices_missing(ha);
2139 clear_bit(AF_INIT_DONE, &ha->flags);
2140}
2141
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002142static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2143{
2144 struct iscsi_session *sess;
2145 struct ddb_entry *ddb_entry;
2146
2147 sess = cls_session->dd_data;
2148 ddb_entry = sess->dd_data;
2149 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2150 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
2151}
2152
David Somayajuluafaf5a22006-09-19 10:28:00 -07002153/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002154 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2155 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002156 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302157static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002158{
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302159 int status = QLA_ERROR;
2160 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002161
2162 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302163 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002164 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002165 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06002166
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302167 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002168
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302169 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002170
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002171 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2172
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302173 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2174 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002175
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302176 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2177 * do not reset adapter, jump to initialize_adapter */
2178 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2179 status = QLA_SUCCESS;
2180 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002181 }
2182
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302183 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2184 * from eh_host_reset or ioctl module */
2185 if (is_qla8022(ha) && !reset_chip &&
2186 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2187
2188 DEBUG2(ql4_printk(KERN_INFO, ha,
2189 "scsi%ld: %s - Performing stop_firmware...\n",
2190 ha->host_no, __func__));
2191 status = ha->isp_ops->reset_firmware(ha);
2192 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2be2010-10-06 22:49:20 -07002193 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2194 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302195 ha->isp_ops->disable_intrs(ha);
2196 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2197 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2198 } else {
2199 /* If the stop_firmware fails then
2200 * reset the entire chip */
2201 reset_chip = 1;
2202 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2203 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2204 }
2205 }
2206
2207 /* Issue full chip reset if recovering from a catastrophic error,
2208 * or if stop_firmware fails for ISP-82xx.
2209 * This is the default case for ISP-4xxx */
2210 if (!is_qla8022(ha) || reset_chip) {
Nilesh Javali2bd1e2be2010-10-06 22:49:20 -07002211 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2212 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302213 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2214 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2215 DEBUG2(ql4_printk(KERN_INFO, ha,
2216 "scsi%ld: %s - Performing chip reset..\n",
2217 ha->host_no, __func__));
2218 status = ha->isp_ops->reset_chip(ha);
2219 }
2220
2221 /* Flush any pending ddb changed AENs */
2222 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2223
2224recover_ha_init_adapter:
2225 /* Upon successful firmware/chip reset, re-initialize the adapter */
2226 if (status == QLA_SUCCESS) {
2227 /* For ISP-4xxx, force function 1 to always initialize
2228 * before function 3 to prevent both funcions from
2229 * stepping on top of the other */
2230 if (!is_qla8022(ha) && (ha->mac_index == 3))
2231 ssleep(6);
2232
2233 /* NOTE: AF_ONLINE flag set upon successful completion of
2234 * qla4xxx_initialize_adapter */
2235 status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
2236 }
2237
2238 /* Retry failed adapter initialization, if necessary
2239 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2240 * case to prevent ping-pong resets between functions */
2241 if (!test_bit(AF_ONLINE, &ha->flags) &&
2242 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002243 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302244 * resetting the ha.
2245 * Since we don't want to block the DPC for too long
2246 * with multiple resets in the same thread,
2247 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07002248 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2249 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2250 DEBUG2(printk("scsi%ld: recover adapter - retrying "
2251 "(%d) more times\n", ha->host_no,
2252 ha->retry_reset_ha_cnt));
2253 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2254 status = QLA_ERROR;
2255 } else {
2256 if (ha->retry_reset_ha_cnt > 0) {
2257 /* Schedule another Reset HA--DPC will retry */
2258 ha->retry_reset_ha_cnt--;
2259 DEBUG2(printk("scsi%ld: recover adapter - "
2260 "retry remaining %d\n",
2261 ha->host_no,
2262 ha->retry_reset_ha_cnt));
2263 status = QLA_ERROR;
2264 }
2265
2266 if (ha->retry_reset_ha_cnt == 0) {
2267 /* Recover adapter retries have been exhausted.
2268 * Adapter DEAD */
2269 DEBUG2(printk("scsi%ld: recover adapter "
2270 "failed - board disabled\n",
2271 ha->host_no));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302272 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002273 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2274 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302275 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002276 &ha->dpc_flags);
2277 status = QLA_ERROR;
2278 }
2279 }
2280 } else {
2281 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302282 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002283 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2284 }
2285
2286 ha->adapter_error_count++;
2287
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302288 if (test_bit(AF_ONLINE, &ha->flags))
2289 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002290
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302291 scsi_unblock_requests(ha->host);
2292
2293 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2294 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002295 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302296
David Somayajuluafaf5a22006-09-19 10:28:00 -07002297 return status;
2298}
2299
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002300static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002301{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002302 struct iscsi_session *sess;
2303 struct ddb_entry *ddb_entry;
2304 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002305
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002306 sess = cls_session->dd_data;
2307 ddb_entry = sess->dd_data;
2308 ha = ddb_entry->ha;
2309 if (!iscsi_is_session_online(cls_session)) {
2310 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
2311 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2312 " unblock session\n", ha->host_no, __func__,
2313 ddb_entry->fw_ddb_index);
2314 iscsi_unblock_session(ddb_entry->sess);
2315 } else {
2316 /* Trigger relogin */
2317 iscsi_session_failure(cls_session->dd_data,
2318 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002319 }
2320 }
2321}
2322
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002323static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
2324{
2325 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
2326}
2327
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302328void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
2329{
Lalit Chandivade1b468072011-05-17 23:17:09 -07002330 if (ha->dpc_thread)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302331 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302332}
2333
David Somayajuluafaf5a22006-09-19 10:28:00 -07002334/**
2335 * qla4xxx_do_dpc - dpc routine
2336 * @data: in our case pointer to adapter structure
2337 *
2338 * This routine is a task that is schedule by the interrupt handler
2339 * to perform the background processing for interrupts. We put it
2340 * on a task queue that is consumed whenever the scheduler runs; that's
2341 * so you can do anything (i.e. put the process to sleep etc). In fact,
2342 * the mid-level tries to sleep when it reaches the driver threshold
2343 * "host->can_queue". This can cause a panic if we were in our interrupt code.
2344 **/
David Howellsc4028952006-11-22 14:57:56 +00002345static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002346{
David Howellsc4028952006-11-22 14:57:56 +00002347 struct scsi_qla_host *ha =
2348 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002349 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002350
David C Somayajuluf26b9042006-11-15 16:41:09 -08002351 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302352 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
2353 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07002354
2355 /* Initialization not yet finished. Don't do anything yet. */
2356 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07002357 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002358
Lalit Chandivade2232be02010-07-30 14:38:47 +05302359 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2360 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
2361 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07002362 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302363 }
2364
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302365 if (is_qla8022(ha)) {
2366 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
2367 qla4_8xxx_idc_lock(ha);
2368 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2369 QLA82XX_DEV_FAILED);
2370 qla4_8xxx_idc_unlock(ha);
2371 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2372 qla4_8xxx_device_state_handler(ha);
2373 }
2374 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2375 qla4_8xxx_need_qsnt_handler(ha);
2376 }
2377 }
2378
2379 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
2380 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07002381 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302382 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
2383 if (ql4xdontresethba) {
2384 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2385 ha->host_no, __func__));
2386 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2387 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2388 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2389 goto dpc_post_reset_ha;
2390 }
2391 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2392 test_bit(DPC_RESET_HA, &ha->dpc_flags))
2393 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002394
David C Somayajulu477ffb92007-01-22 12:26:11 -08002395 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002396 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002397
David Somayajuluafaf5a22006-09-19 10:28:00 -07002398 while ((readw(&ha->reg->ctrl_status) &
2399 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
2400 if (--wait_time == 0)
2401 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002402 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002403 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002404 if (wait_time == 0)
2405 DEBUG2(printk("scsi%ld: %s: SR|FSR "
2406 "bit not cleared-- resetting\n",
2407 ha->host_no, __func__));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302408 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002409 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
2410 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302411 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002412 }
2413 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2414 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302415 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002416 }
2417 }
2418
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302419dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002420 /* ---- process AEN? --- */
2421 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
2422 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
2423
2424 /* ---- Get DHCP IP Address? --- */
2425 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
2426 qla4xxx_get_dhcp_ip_address(ha);
2427
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302428 /* ---- link change? --- */
2429 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
2430 if (!test_bit(AF_LINK_UP, &ha->flags)) {
2431 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002432 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302433 } else {
2434 /* ---- link up? --- *
2435 * F/W will auto login to all devices ONLY ONCE after
2436 * link up during driver initialization and runtime
2437 * fatal error recovery. Therefore, the driver must
2438 * manually relogin to devices when recovering from
2439 * connection failures, logouts, expired KATO, etc. */
2440
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002441 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302442 }
2443 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002444}
2445
2446/**
2447 * qla4xxx_free_adapter - release the adapter
2448 * @ha: pointer to adapter structure
2449 **/
2450static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
2451{
2452
2453 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
2454 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302455 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002456 }
2457
David Somayajuluafaf5a22006-09-19 10:28:00 -07002458 /* Remove timer thread, if present */
2459 if (ha->timer_active)
2460 qla4xxx_stop_timer(ha);
2461
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302462 /* Kill the kernel thread for this host */
2463 if (ha->dpc_thread)
2464 destroy_workqueue(ha->dpc_thread);
2465
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002466 /* Kill the kernel thread for this host */
2467 if (ha->task_wq)
2468 destroy_workqueue(ha->task_wq);
2469
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302470 /* Put firmware in known state */
2471 ha->isp_ops->reset_firmware(ha);
2472
2473 if (is_qla8022(ha)) {
2474 qla4_8xxx_idc_lock(ha);
2475 qla4_8xxx_clear_drv_active(ha);
2476 qla4_8xxx_idc_unlock(ha);
2477 }
2478
David Somayajuluafaf5a22006-09-19 10:28:00 -07002479 /* Detach interrupts */
2480 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302481 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002482
David C Somayajulubee4fe82007-05-23 18:03:32 -07002483 /* free extra memory */
2484 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302485}
David C Somayajulubee4fe82007-05-23 18:03:32 -07002486
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302487int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
2488{
2489 int status = 0;
2490 uint8_t revision_id;
2491 unsigned long mem_base, mem_len, db_base, db_len;
2492 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002493
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302494 status = pci_request_regions(pdev, DRIVER_NAME);
2495 if (status) {
2496 printk(KERN_WARNING
2497 "scsi(%ld) Failed to reserve PIO regions (%s) "
2498 "status=%d\n", ha->host_no, pci_name(pdev), status);
2499 goto iospace_error_exit;
2500 }
2501
2502 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
2503 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
2504 __func__, revision_id));
2505 ha->revision_id = revision_id;
2506
2507 /* remap phys address */
2508 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
2509 mem_len = pci_resource_len(pdev, 0);
2510 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
2511 __func__, mem_base, mem_len));
2512
2513 /* mapping of pcibase pointer */
2514 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
2515 if (!ha->nx_pcibase) {
2516 printk(KERN_ERR
2517 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
2518 pci_release_regions(ha->pdev);
2519 goto iospace_error_exit;
2520 }
2521
2522 /* Mapping of IO base pointer, door bell read and write pointer */
2523
2524 /* mapping of IO base pointer */
2525 ha->qla4_8xxx_reg =
2526 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
2527 0xbc000 + (ha->pdev->devfn << 11));
2528
2529 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
2530 db_len = pci_resource_len(pdev, 4);
2531
Shyam Sundar2657c802010-10-06 22:50:29 -07002532 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
2533 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302534
Shyam Sundar2657c802010-10-06 22:50:29 -07002535 return 0;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302536iospace_error_exit:
2537 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002538}
2539
2540/***
2541 * qla4xxx_iospace_config - maps registers
2542 * @ha: pointer to adapter structure
2543 *
2544 * This routines maps HBA's registers from the pci address space
2545 * into the kernel virtual address space for memory mapped i/o.
2546 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302547int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002548{
2549 unsigned long pio, pio_len, pio_flags;
2550 unsigned long mmio, mmio_len, mmio_flags;
2551
2552 pio = pci_resource_start(ha->pdev, 0);
2553 pio_len = pci_resource_len(ha->pdev, 0);
2554 pio_flags = pci_resource_flags(ha->pdev, 0);
2555 if (pio_flags & IORESOURCE_IO) {
2556 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302557 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002558 "Invalid PCI I/O region size\n");
2559 pio = 0;
2560 }
2561 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302562 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002563 pio = 0;
2564 }
2565
2566 /* Use MMIO operations for all accesses. */
2567 mmio = pci_resource_start(ha->pdev, 1);
2568 mmio_len = pci_resource_len(ha->pdev, 1);
2569 mmio_flags = pci_resource_flags(ha->pdev, 1);
2570
2571 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302572 ql4_printk(KERN_ERR, ha,
2573 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002574
2575 goto iospace_error_exit;
2576 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302577
David Somayajuluafaf5a22006-09-19 10:28:00 -07002578 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302579 ql4_printk(KERN_ERR, ha,
2580 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002581 goto iospace_error_exit;
2582 }
2583
2584 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302585 ql4_printk(KERN_WARNING, ha,
2586 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002587
2588 goto iospace_error_exit;
2589 }
2590
2591 ha->pio_address = pio;
2592 ha->pio_length = pio_len;
2593 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
2594 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302595 ql4_printk(KERN_ERR, ha,
2596 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002597
2598 goto iospace_error_exit;
2599 }
2600
2601 return 0;
2602
2603iospace_error_exit:
2604 return -ENOMEM;
2605}
2606
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302607static struct isp_operations qla4xxx_isp_ops = {
2608 .iospace_config = qla4xxx_iospace_config,
2609 .pci_config = qla4xxx_pci_config,
2610 .disable_intrs = qla4xxx_disable_intrs,
2611 .enable_intrs = qla4xxx_enable_intrs,
2612 .start_firmware = qla4xxx_start_firmware,
2613 .intr_handler = qla4xxx_intr_handler,
2614 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
2615 .reset_chip = qla4xxx_soft_reset,
2616 .reset_firmware = qla4xxx_hw_reset,
2617 .queue_iocb = qla4xxx_queue_iocb,
2618 .complete_iocb = qla4xxx_complete_iocb,
2619 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
2620 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
2621 .get_sys_info = qla4xxx_get_sys_info,
2622};
2623
2624static struct isp_operations qla4_8xxx_isp_ops = {
2625 .iospace_config = qla4_8xxx_iospace_config,
2626 .pci_config = qla4_8xxx_pci_config,
2627 .disable_intrs = qla4_8xxx_disable_intrs,
2628 .enable_intrs = qla4_8xxx_enable_intrs,
2629 .start_firmware = qla4_8xxx_load_risc,
2630 .intr_handler = qla4_8xxx_intr_handler,
2631 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
2632 .reset_chip = qla4_8xxx_isp_reset,
2633 .reset_firmware = qla4_8xxx_stop_firmware,
2634 .queue_iocb = qla4_8xxx_queue_iocb,
2635 .complete_iocb = qla4_8xxx_complete_iocb,
2636 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
2637 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
2638 .get_sys_info = qla4_8xxx_get_sys_info,
2639};
2640
2641uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2642{
2643 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
2644}
2645
2646uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2647{
2648 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
2649}
2650
2651uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2652{
2653 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
2654}
2655
2656uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2657{
2658 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
2659}
2660
David Somayajuluafaf5a22006-09-19 10:28:00 -07002661/**
2662 * qla4xxx_probe_adapter - callback function to probe HBA
2663 * @pdev: pointer to pci_dev structure
2664 * @pci_device_id: pointer to pci_device entry
2665 *
2666 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
2667 * It returns zero if successful. It also initializes all data necessary for
2668 * the driver.
2669 **/
2670static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
2671 const struct pci_device_id *ent)
2672{
2673 int ret = -ENODEV, status;
2674 struct Scsi_Host *host;
2675 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002676 uint8_t init_retry_count = 0;
2677 char buf[34];
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302678 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002679 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002680
2681 if (pci_enable_device(pdev))
2682 return -1;
2683
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002684 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002685 if (host == NULL) {
2686 printk(KERN_WARNING
2687 "qla4xxx: Couldn't allocate host from scsi layer!\n");
2688 goto probe_disable_device;
2689 }
2690
2691 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002692 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002693 memset(ha, 0, sizeof(*ha));
2694
2695 /* Save the information from PCI BIOS. */
2696 ha->pdev = pdev;
2697 ha->host = host;
2698 ha->host_no = host->host_no;
2699
Lalit Chandivade2232be02010-07-30 14:38:47 +05302700 pci_enable_pcie_error_reporting(pdev);
2701
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302702 /* Setup Runtime configurable options */
2703 if (is_qla8022(ha)) {
2704 ha->isp_ops = &qla4_8xxx_isp_ops;
2705 rwlock_init(&ha->hw_lock);
2706 ha->qdr_sn_window = -1;
2707 ha->ddr_mn_window = -1;
2708 ha->curr_window = 255;
2709 ha->func_num = PCI_FUNC(ha->pdev->devfn);
2710 nx_legacy_intr = &legacy_intr[ha->func_num];
2711 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
2712 ha->nx_legacy_intr.tgt_status_reg =
2713 nx_legacy_intr->tgt_status_reg;
2714 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
2715 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
2716 } else {
2717 ha->isp_ops = &qla4xxx_isp_ops;
2718 }
2719
Lalit Chandivade2232be02010-07-30 14:38:47 +05302720 /* Set EEH reset type to fundamental if required by hba */
2721 if (is_qla8022(ha))
2722 pdev->needs_freset = 1;
2723
David Somayajuluafaf5a22006-09-19 10:28:00 -07002724 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302725 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002726 if (ret)
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302727 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002728
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302729 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07002730 pdev->device, pdev->irq, ha->reg);
2731
2732 qla4xxx_config_dma_addressing(ha);
2733
2734 /* Initialize lists and spinlocks. */
2735 INIT_LIST_HEAD(&ha->ddb_list);
2736 INIT_LIST_HEAD(&ha->free_srb_q);
2737
2738 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302739 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002740
2741 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002742
2743 /* Allocate dma buffers */
2744 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302745 ql4_printk(KERN_WARNING, ha,
2746 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002747
2748 ret = -ENOMEM;
2749 goto probe_failed;
2750 }
2751
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002752 host->cmd_per_lun = 3;
2753 host->max_channel = 0;
2754 host->max_lun = MAX_LUNS - 1;
2755 host->max_id = MAX_TARGETS;
2756 host->max_cmd_len = IOCB_MAX_CDB_LEN;
2757 host->can_queue = MAX_SRBS ;
2758 host->transportt = qla4xxx_scsi_transport;
2759
2760 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
2761 if (ret) {
2762 ql4_printk(KERN_WARNING, ha,
2763 "%s: scsi_init_shared_tag_map failed\n", __func__);
2764 goto probe_failed;
2765 }
2766
2767 pci_set_drvdata(pdev, ha);
2768
2769 ret = scsi_add_host(host, &pdev->dev);
2770 if (ret)
2771 goto probe_failed;
2772
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302773 if (is_qla8022(ha))
2774 (void) qla4_8xxx_get_flash_info(ha);
2775
David Somayajuluafaf5a22006-09-19 10:28:00 -07002776 /*
2777 * Initialize the Host adapter request/response queues and
2778 * firmware
2779 * NOTE: interrupts enabled upon successful completion
2780 */
2781 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302782 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
2783 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002784
2785 if (is_qla8022(ha)) {
2786 qla4_8xxx_idc_lock(ha);
2787 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2788 qla4_8xxx_idc_unlock(ha);
2789 if (dev_state == QLA82XX_DEV_FAILED) {
2790 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
2791 "initialize adapter. H/W is in failed state\n",
2792 __func__);
2793 break;
2794 }
2795 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002796 DEBUG2(printk("scsi: %s: retrying adapter initialization "
2797 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302798
2799 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
2800 continue;
2801
David Somayajuluafaf5a22006-09-19 10:28:00 -07002802 status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST);
2803 }
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302804
2805 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302806 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002807
Lalit Chandivadefe998522010-12-02 22:12:36 -08002808 if (is_qla8022(ha) && ql4xdontresethba) {
2809 /* Put the device in failed state. */
2810 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
2811 qla4_8xxx_idc_lock(ha);
2812 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2813 QLA82XX_DEV_FAILED);
2814 qla4_8xxx_idc_unlock(ha);
2815 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002816 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002817 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002818 }
2819
David Somayajuluafaf5a22006-09-19 10:28:00 -07002820 /* Startup the kernel thread for this host adapter. */
2821 DEBUG2(printk("scsi: %s: Starting kernel thread for "
2822 "qla4xxx_dpc\n", __func__));
2823 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
2824 ha->dpc_thread = create_singlethread_workqueue(buf);
2825 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302826 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002827 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002828 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002829 }
David Howellsc4028952006-11-22 14:57:56 +00002830 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002831
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002832 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
2833 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
2834 if (!ha->task_wq) {
2835 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
2836 ret = -ENODEV;
2837 goto remove_host;
2838 }
2839
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302840 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
2841 * (which is called indirectly by qla4xxx_initialize_adapter),
2842 * so that irqs will be registered after crbinit but before
2843 * mbx_intr_enable.
2844 */
2845 if (!is_qla8022(ha)) {
2846 ret = qla4xxx_request_irqs(ha);
2847 if (ret) {
2848 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
2849 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002850 goto remove_host;
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302851 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002852 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002853
Lalit Chandivade2232be02010-07-30 14:38:47 +05302854 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302855 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002856
2857 /* Start timer thread. */
2858 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
2859
2860 set_bit(AF_INIT_DONE, &ha->flags);
2861
David Somayajuluafaf5a22006-09-19 10:28:00 -07002862 printk(KERN_INFO
2863 " QLogic iSCSI HBA Driver version: %s\n"
2864 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2865 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
2866 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2867 ha->patch_number, ha->build_number);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002868
2869 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002870 return 0;
2871
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002872remove_host:
2873 scsi_remove_host(ha->host);
2874
David Somayajuluafaf5a22006-09-19 10:28:00 -07002875probe_failed:
2876 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302877
2878probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05302879 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002880 scsi_host_put(ha->host);
2881
2882probe_disable_device:
2883 pci_disable_device(pdev);
2884
2885 return ret;
2886}
2887
2888/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07002889 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
2890 * @ha: pointer to adapter structure
2891 *
2892 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
2893 * so that the other port will not re-initialize while in the process of
2894 * removing the ha due to driver unload or hba hotplug.
2895 **/
2896static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
2897{
2898 struct scsi_qla_host *other_ha = NULL;
2899 struct pci_dev *other_pdev = NULL;
2900 int fn = ISP4XXX_PCI_FN_2;
2901
2902 /*iscsi function numbers for ISP4xxx is 1 and 3*/
2903 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
2904 fn = ISP4XXX_PCI_FN_1;
2905
2906 other_pdev =
2907 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2908 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2909 fn));
2910
2911 /* Get other_ha if other_pdev is valid and state is enable*/
2912 if (other_pdev) {
2913 if (atomic_read(&other_pdev->enable_cnt)) {
2914 other_ha = pci_get_drvdata(other_pdev);
2915 if (other_ha) {
2916 set_bit(AF_HA_REMOVAL, &other_ha->flags);
2917 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
2918 "Prevent %s reinit\n", __func__,
2919 dev_name(&other_ha->pdev->dev)));
2920 }
2921 }
2922 pci_dev_put(other_pdev);
2923 }
2924}
2925
2926/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002927 * qla4xxx_remove_adapter - calback function to remove adapter.
2928 * @pci_dev: PCI device pointer
2929 **/
2930static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
2931{
2932 struct scsi_qla_host *ha;
2933
2934 ha = pci_get_drvdata(pdev);
2935
Karen Higgins7eece5a2011-03-21 03:34:29 -07002936 if (!is_qla8022(ha))
2937 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07002938
David Somayajuluafaf5a22006-09-19 10:28:00 -07002939 /* remove devs from iscsi_sessions to scsi_devices */
2940 qla4xxx_free_ddb_list(ha);
2941
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002942 /* destroy iface from sysfs */
2943 qla4xxx_destroy_ifaces(ha);
2944
David Somayajuluafaf5a22006-09-19 10:28:00 -07002945 scsi_remove_host(ha->host);
2946
2947 qla4xxx_free_adapter(ha);
2948
2949 scsi_host_put(ha->host);
2950
Lalit Chandivade2232be02010-07-30 14:38:47 +05302951 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05302952 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002953 pci_set_drvdata(pdev, NULL);
2954}
2955
2956/**
2957 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
2958 * @ha: HA context
2959 *
2960 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2961 * supported addressing method.
2962 */
Adrian Bunk47975472007-04-26 00:35:16 -07002963static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002964{
2965 int retval;
2966
2967 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07002968 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
2969 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002970 dev_dbg(&ha->pdev->dev,
2971 "Failed to set 64 bit PCI consistent mask; "
2972 "using 32 bit.\n");
2973 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07002974 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002975 }
2976 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07002977 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002978}
2979
2980static int qla4xxx_slave_alloc(struct scsi_device *sdev)
2981{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002982 struct iscsi_cls_session *cls_sess;
2983 struct iscsi_session *sess;
2984 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002985 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002986
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002987 cls_sess = starget_to_session(sdev->sdev_target);
2988 sess = cls_sess->dd_data;
2989 ddb = sess->dd_data;
2990
David Somayajuluafaf5a22006-09-19 10:28:00 -07002991 sdev->hostdata = ddb;
2992 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002993
2994 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
2995 queue_depth = ql4xmaxqdepth;
2996
2997 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002998 return 0;
2999}
3000
3001static int qla4xxx_slave_configure(struct scsi_device *sdev)
3002{
3003 sdev->tagged_supported = 1;
3004 return 0;
3005}
3006
3007static void qla4xxx_slave_destroy(struct scsi_device *sdev)
3008{
3009 scsi_deactivate_tcq(sdev, 1);
3010}
3011
3012/**
3013 * qla4xxx_del_from_active_array - returns an active srb
3014 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02003015 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07003016 *
3017 * This routine removes and returns the srb at the specified index
3018 **/
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303019struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
3020 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003021{
3022 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05303023 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003024
Vikas Chaudhary53698872010-04-28 11:41:59 +05303025 cmd = scsi_host_find_tag(ha->host, index);
3026 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003027 return srb;
3028
Vikas Chaudhary53698872010-04-28 11:41:59 +05303029 srb = (struct srb *)CMD_SP(cmd);
3030 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003031 return srb;
3032
3033 /* update counters */
3034 if (srb->flags & SRB_DMA_VALID) {
3035 ha->req_q_count += srb->iocb_cnt;
3036 ha->iocb_cnt -= srb->iocb_cnt;
3037 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05303038 srb->cmd->host_scribble =
3039 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003040 }
3041 return srb;
3042}
3043
3044/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07003045 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303046 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07003047 * @cmd: Scsi Command to wait on.
3048 *
3049 * This routine waits for the command to be returned by the Firmware
3050 * for some max time.
3051 **/
3052static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
3053 struct scsi_cmnd *cmd)
3054{
3055 int done = 0;
3056 struct srb *rp;
3057 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05303058 int ret = SUCCESS;
3059
3060 /* Dont wait on command if PCI error is being handled
3061 * by PCI AER driver
3062 */
3063 if (unlikely(pci_channel_offline(ha->pdev)) ||
3064 (test_bit(AF_EEH_BUSY, &ha->flags))) {
3065 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
3066 ha->host_no, __func__);
3067 return ret;
3068 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07003069
3070 do {
3071 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05303072 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003073 if (rp == NULL) {
3074 done++;
3075 break;
3076 }
3077
3078 msleep(2000);
3079 } while (max_wait_time--);
3080
3081 return done;
3082}
3083
3084/**
3085 * qla4xxx_wait_for_hba_online - waits for HBA to come online
3086 * @ha: Pointer to host adapter structure
3087 **/
3088static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
3089{
3090 unsigned long wait_online;
3091
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07003092 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003093 while (time_before(jiffies, wait_online)) {
3094
3095 if (adapter_up(ha))
3096 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003097
3098 msleep(2000);
3099 }
3100
3101 return QLA_ERROR;
3102}
3103
3104/**
Mike Christiece545032008-02-29 18:25:20 -06003105 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02003106 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07003107 * @t: target id
3108 * @l: lun id
3109 *
3110 * This function waits for all outstanding commands to a lun to complete. It
3111 * returns 0 if all pending commands are returned and 1 otherwise.
3112 **/
Mike Christiece545032008-02-29 18:25:20 -06003113static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
3114 struct scsi_target *stgt,
3115 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003116{
3117 int cnt;
3118 int status = 0;
3119 struct scsi_cmnd *cmd;
3120
3121 /*
Mike Christiece545032008-02-29 18:25:20 -06003122 * Waiting for all commands for the designated target or dev
3123 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07003124 */
3125 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
3126 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06003127 if (cmd && stgt == scsi_target(cmd->device) &&
3128 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003129 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3130 status++;
3131 break;
3132 }
3133 }
3134 }
3135 return status;
3136}
3137
3138/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303139 * qla4xxx_eh_abort - callback for abort task.
3140 * @cmd: Pointer to Linux's SCSI command structure
3141 *
3142 * This routine is called by the Linux OS to abort the specified
3143 * command.
3144 **/
3145static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
3146{
3147 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3148 unsigned int id = cmd->device->id;
3149 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07003150 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303151 struct srb *srb = NULL;
3152 int ret = SUCCESS;
3153 int wait = 0;
3154
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303155 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04003156 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
3157 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303158
Mike Christie92b3e5b2010-10-06 22:51:17 -07003159 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303160 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07003161 if (!srb) {
3162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303163 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07003164 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303165 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07003166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303167
3168 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
3169 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
3170 ha->host_no, id, lun));
3171 ret = FAILED;
3172 } else {
3173 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
3174 ha->host_no, id, lun));
3175 wait = 1;
3176 }
3177
3178 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
3179
3180 /* Wait for command to complete */
3181 if (wait) {
3182 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3183 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
3184 ha->host_no, id, lun));
3185 ret = FAILED;
3186 }
3187 }
3188
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303189 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303190 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003191 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303192
3193 return ret;
3194}
3195
3196/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07003197 * qla4xxx_eh_device_reset - callback for target reset.
3198 * @cmd: Pointer to Linux's SCSI command structure
3199 *
3200 * This routine is called by the Linux OS to reset all luns on the
3201 * specified target.
3202 **/
3203static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
3204{
3205 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3206 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003207 int ret = FAILED, stat;
3208
Karen Higgins612f73482009-07-15 15:03:01 -05003209 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003210 return ret;
3211
Mike Christiec01be6d2010-07-22 16:59:49 +05303212 ret = iscsi_block_scsi_eh(cmd);
3213 if (ret)
3214 return ret;
3215 ret = FAILED;
3216
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303217 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003218 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
3219 cmd->device->channel, cmd->device->id, cmd->device->lun);
3220
3221 DEBUG2(printk(KERN_INFO
3222 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
3223 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07003224 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003225 ha->dpc_flags, cmd->result, cmd->allowed));
3226
3227 /* FIXME: wait for hba to go online */
3228 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
3229 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303230 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003231 goto eh_dev_reset_done;
3232 }
3233
Mike Christiece545032008-02-29 18:25:20 -06003234 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3235 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303236 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06003237 "DEVICE RESET FAILED - waiting for "
3238 "commands.\n");
3239 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003240 }
3241
David C Somayajulu9d562912008-03-19 11:23:03 -07003242 /* Send marker. */
3243 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3244 MM_LUN_RESET) != QLA_SUCCESS)
3245 goto eh_dev_reset_done;
3246
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303247 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003248 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
3249 ha->host_no, cmd->device->channel, cmd->device->id,
3250 cmd->device->lun);
3251
3252 ret = SUCCESS;
3253
3254eh_dev_reset_done:
3255
3256 return ret;
3257}
3258
3259/**
Mike Christiece545032008-02-29 18:25:20 -06003260 * qla4xxx_eh_target_reset - callback for target reset.
3261 * @cmd: Pointer to Linux's SCSI command structure
3262 *
3263 * This routine is called by the Linux OS to reset the target.
3264 **/
3265static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
3266{
3267 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3268 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05303269 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06003270
3271 if (!ddb_entry)
3272 return FAILED;
3273
Mike Christiec01be6d2010-07-22 16:59:49 +05303274 ret = iscsi_block_scsi_eh(cmd);
3275 if (ret)
3276 return ret;
3277
Mike Christiece545032008-02-29 18:25:20 -06003278 starget_printk(KERN_INFO, scsi_target(cmd->device),
3279 "WARM TARGET RESET ISSUED.\n");
3280
3281 DEBUG2(printk(KERN_INFO
3282 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
3283 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07003284 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06003285 ha->dpc_flags, cmd->result, cmd->allowed));
3286
3287 stat = qla4xxx_reset_target(ha, ddb_entry);
3288 if (stat != QLA_SUCCESS) {
3289 starget_printk(KERN_INFO, scsi_target(cmd->device),
3290 "WARM TARGET RESET FAILED.\n");
3291 return FAILED;
3292 }
3293
Mike Christiece545032008-02-29 18:25:20 -06003294 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3295 NULL)) {
3296 starget_printk(KERN_INFO, scsi_target(cmd->device),
3297 "WARM TARGET DEVICE RESET FAILED - "
3298 "waiting for commands.\n");
3299 return FAILED;
3300 }
3301
David C Somayajulu9d562912008-03-19 11:23:03 -07003302 /* Send marker. */
3303 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3304 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
3305 starget_printk(KERN_INFO, scsi_target(cmd->device),
3306 "WARM TARGET DEVICE RESET FAILED - "
3307 "marker iocb failed.\n");
3308 return FAILED;
3309 }
3310
Mike Christiece545032008-02-29 18:25:20 -06003311 starget_printk(KERN_INFO, scsi_target(cmd->device),
3312 "WARM TARGET RESET SUCCEEDED.\n");
3313 return SUCCESS;
3314}
3315
3316/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07003317 * qla4xxx_eh_host_reset - kernel callback
3318 * @cmd: Pointer to Linux's SCSI command structure
3319 *
3320 * This routine is invoked by the Linux kernel to perform fatal error
3321 * recovery on the specified adapter.
3322 **/
3323static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
3324{
3325 int return_status = FAILED;
3326 struct scsi_qla_host *ha;
3327
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003328 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003329
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303330 if (ql4xdontresethba) {
3331 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3332 ha->host_no, __func__));
3333 return FAILED;
3334 }
3335
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303336 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05003337 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003338 cmd->device->channel, cmd->device->id, cmd->device->lun);
3339
3340 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
3341 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
3342 "DEAD.\n", ha->host_no, cmd->device->channel,
3343 __func__));
3344
3345 return FAILED;
3346 }
3347
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303348 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
3349 if (is_qla8022(ha))
3350 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3351 else
3352 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3353 }
Mike Christie50a29ae2008-03-04 13:26:53 -06003354
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303355 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003356 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003357
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303358 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003359 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003360
3361 return return_status;
3362}
3363
Lalit Chandivade2232be02010-07-30 14:38:47 +05303364/* PCI AER driver recovers from all correctable errors w/o
3365 * driver intervention. For uncorrectable errors PCI AER
3366 * driver calls the following device driver's callbacks
3367 *
3368 * - Fatal Errors - link_reset
3369 * - Non-Fatal Errors - driver's pci_error_detected() which
3370 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
3371 *
3372 * PCI AER driver calls
3373 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
3374 * returns RECOVERED or NEED_RESET if fw_hung
3375 * NEED_RESET - driver's slot_reset()
3376 * DISCONNECT - device is dead & cannot recover
3377 * RECOVERED - driver's pci_resume()
3378 */
3379static pci_ers_result_t
3380qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3381{
3382 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3383
3384 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
3385 ha->host_no, __func__, state);
3386
3387 if (!is_aer_supported(ha))
3388 return PCI_ERS_RESULT_NONE;
3389
3390 switch (state) {
3391 case pci_channel_io_normal:
3392 clear_bit(AF_EEH_BUSY, &ha->flags);
3393 return PCI_ERS_RESULT_CAN_RECOVER;
3394 case pci_channel_io_frozen:
3395 set_bit(AF_EEH_BUSY, &ha->flags);
3396 qla4xxx_mailbox_premature_completion(ha);
3397 qla4xxx_free_irqs(ha);
3398 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003399 /* Return back all IOs */
3400 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303401 return PCI_ERS_RESULT_NEED_RESET;
3402 case pci_channel_io_perm_failure:
3403 set_bit(AF_EEH_BUSY, &ha->flags);
3404 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
3405 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3406 return PCI_ERS_RESULT_DISCONNECT;
3407 }
3408 return PCI_ERS_RESULT_NEED_RESET;
3409}
3410
3411/**
3412 * qla4xxx_pci_mmio_enabled() gets called if
3413 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
3414 * and read/write to the device still works.
3415 **/
3416static pci_ers_result_t
3417qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
3418{
3419 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3420
3421 if (!is_aer_supported(ha))
3422 return PCI_ERS_RESULT_NONE;
3423
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003424 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05303425}
3426
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003427static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05303428{
3429 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003430 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05303431 int fn;
3432 struct pci_dev *other_pdev = NULL;
3433
3434 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
3435
3436 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3437
3438 if (test_bit(AF_ONLINE, &ha->flags)) {
3439 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003440 clear_bit(AF_LINK_UP, &ha->flags);
3441 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303442 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303443 }
3444
3445 fn = PCI_FUNC(ha->pdev->devfn);
3446 while (fn > 0) {
3447 fn--;
3448 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
3449 "func %x\n", ha->host_no, __func__, fn);
3450 /* Get the pci device given the domain, bus,
3451 * slot/function number */
3452 other_pdev =
3453 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
3454 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
3455 fn));
3456
3457 if (!other_pdev)
3458 continue;
3459
3460 if (atomic_read(&other_pdev->enable_cnt)) {
3461 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
3462 "func in enabled state%x\n", ha->host_no,
3463 __func__, fn);
3464 pci_dev_put(other_pdev);
3465 break;
3466 }
3467 pci_dev_put(other_pdev);
3468 }
3469
3470 /* The first function on the card, the reset owner will
3471 * start & initialize the firmware. The other functions
3472 * on the card will reset the firmware context
3473 */
3474 if (!fn) {
3475 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
3476 "0x%x is the owner\n", ha->host_no, __func__,
3477 ha->pdev->devfn);
3478
3479 qla4_8xxx_idc_lock(ha);
3480 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3481 QLA82XX_DEV_COLD);
3482
3483 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
3484 QLA82XX_IDC_VERSION);
3485
3486 qla4_8xxx_idc_unlock(ha);
3487 clear_bit(AF_FW_RECOVERY, &ha->flags);
3488 rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST);
3489 qla4_8xxx_idc_lock(ha);
3490
3491 if (rval != QLA_SUCCESS) {
3492 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3493 "FAILED\n", ha->host_no, __func__);
3494 qla4_8xxx_clear_drv_active(ha);
3495 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3496 QLA82XX_DEV_FAILED);
3497 } else {
3498 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3499 "READY\n", ha->host_no, __func__);
3500 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3501 QLA82XX_DEV_READY);
3502 /* Clear driver state register */
3503 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
3504 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003505 ret = qla4xxx_request_irqs(ha);
3506 if (ret) {
3507 ql4_printk(KERN_WARNING, ha, "Failed to "
3508 "reserve interrupt %d already in use.\n",
3509 ha->pdev->irq);
3510 rval = QLA_ERROR;
3511 } else {
3512 ha->isp_ops->enable_intrs(ha);
3513 rval = QLA_SUCCESS;
3514 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05303515 }
3516 qla4_8xxx_idc_unlock(ha);
3517 } else {
3518 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
3519 "the reset owner\n", ha->host_no, __func__,
3520 ha->pdev->devfn);
3521 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
3522 QLA82XX_DEV_READY)) {
3523 clear_bit(AF_FW_RECOVERY, &ha->flags);
3524 rval = qla4xxx_initialize_adapter(ha,
3525 PRESERVE_DDB_LIST);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003526 if (rval == QLA_SUCCESS) {
3527 ret = qla4xxx_request_irqs(ha);
3528 if (ret) {
3529 ql4_printk(KERN_WARNING, ha, "Failed to"
3530 " reserve interrupt %d already in"
3531 " use.\n", ha->pdev->irq);
3532 rval = QLA_ERROR;
3533 } else {
3534 ha->isp_ops->enable_intrs(ha);
3535 rval = QLA_SUCCESS;
3536 }
3537 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05303538 qla4_8xxx_idc_lock(ha);
3539 qla4_8xxx_set_drv_active(ha);
3540 qla4_8xxx_idc_unlock(ha);
3541 }
3542 }
3543 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3544 return rval;
3545}
3546
3547static pci_ers_result_t
3548qla4xxx_pci_slot_reset(struct pci_dev *pdev)
3549{
3550 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3551 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3552 int rc;
3553
3554 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
3555 ha->host_no, __func__);
3556
3557 if (!is_aer_supported(ha))
3558 return PCI_ERS_RESULT_NONE;
3559
3560 /* Restore the saved state of PCIe device -
3561 * BAR registers, PCI Config space, PCIX, MSI,
3562 * IOV states
3563 */
3564 pci_restore_state(pdev);
3565
3566 /* pci_restore_state() clears the saved_state flag of the device
3567 * save restored state which resets saved_state flag
3568 */
3569 pci_save_state(pdev);
3570
3571 /* Initialize device or resume if in suspended state */
3572 rc = pci_enable_device(pdev);
3573 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003574 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05303575 "device after reset\n", ha->host_no, __func__);
3576 goto exit_slot_reset;
3577 }
3578
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003579 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303580
3581 if (is_qla8022(ha)) {
3582 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
3583 ret = PCI_ERS_RESULT_RECOVERED;
3584 goto exit_slot_reset;
3585 } else
3586 goto exit_slot_reset;
3587 }
3588
3589exit_slot_reset:
3590 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
3591 "device after reset\n", ha->host_no, __func__, ret);
3592 return ret;
3593}
3594
3595static void
3596qla4xxx_pci_resume(struct pci_dev *pdev)
3597{
3598 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3599 int ret;
3600
3601 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
3602 ha->host_no, __func__);
3603
3604 ret = qla4xxx_wait_for_hba_online(ha);
3605 if (ret != QLA_SUCCESS) {
3606 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
3607 "resume I/O from slot/link_reset\n", ha->host_no,
3608 __func__);
3609 }
3610
3611 pci_cleanup_aer_uncorrect_error_status(pdev);
3612 clear_bit(AF_EEH_BUSY, &ha->flags);
3613}
3614
3615static struct pci_error_handlers qla4xxx_err_handler = {
3616 .error_detected = qla4xxx_pci_error_detected,
3617 .mmio_enabled = qla4xxx_pci_mmio_enabled,
3618 .slot_reset = qla4xxx_pci_slot_reset,
3619 .resume = qla4xxx_pci_resume,
3620};
3621
David Somayajuluafaf5a22006-09-19 10:28:00 -07003622static struct pci_device_id qla4xxx_pci_tbl[] = {
3623 {
3624 .vendor = PCI_VENDOR_ID_QLOGIC,
3625 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
3626 .subvendor = PCI_ANY_ID,
3627 .subdevice = PCI_ANY_ID,
3628 },
3629 {
3630 .vendor = PCI_VENDOR_ID_QLOGIC,
3631 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
3632 .subvendor = PCI_ANY_ID,
3633 .subdevice = PCI_ANY_ID,
3634 },
David C Somayajulud9150582006-11-15 17:38:40 -08003635 {
3636 .vendor = PCI_VENDOR_ID_QLOGIC,
3637 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
3638 .subvendor = PCI_ANY_ID,
3639 .subdevice = PCI_ANY_ID,
3640 },
Vikas Chaudharyf4f5df22010-07-28 15:53:44 +05303641 {
3642 .vendor = PCI_VENDOR_ID_QLOGIC,
3643 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
3644 .subvendor = PCI_ANY_ID,
3645 .subdevice = PCI_ANY_ID,
3646 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07003647 {0, 0},
3648};
3649MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
3650
Adrian Bunk47975472007-04-26 00:35:16 -07003651static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003652 .name = DRIVER_NAME,
3653 .id_table = qla4xxx_pci_tbl,
3654 .probe = qla4xxx_probe_adapter,
3655 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05303656 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003657};
3658
3659static int __init qla4xxx_module_init(void)
3660{
3661 int ret;
3662
3663 /* Allocate cache for SRBs. */
3664 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003665 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003666 if (srb_cachep == NULL) {
3667 printk(KERN_ERR
3668 "%s: Unable to allocate SRB cache..."
3669 "Failing load!\n", DRIVER_NAME);
3670 ret = -ENOMEM;
3671 goto no_srp_cache;
3672 }
3673
3674 /* Derive version string. */
3675 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003676 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003677 strcat(qla4xxx_version_str, "-debug");
3678
3679 qla4xxx_scsi_transport =
3680 iscsi_register_transport(&qla4xxx_iscsi_transport);
3681 if (!qla4xxx_scsi_transport){
3682 ret = -ENODEV;
3683 goto release_srb_cache;
3684 }
3685
David Somayajuluafaf5a22006-09-19 10:28:00 -07003686 ret = pci_register_driver(&qla4xxx_pci_driver);
3687 if (ret)
3688 goto unregister_transport;
3689
3690 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
3691 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05003692
David Somayajuluafaf5a22006-09-19 10:28:00 -07003693unregister_transport:
3694 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3695release_srb_cache:
3696 kmem_cache_destroy(srb_cachep);
3697no_srp_cache:
3698 return ret;
3699}
3700
3701static void __exit qla4xxx_module_exit(void)
3702{
David Somayajuluafaf5a22006-09-19 10:28:00 -07003703 pci_unregister_driver(&qla4xxx_pci_driver);
3704 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3705 kmem_cache_destroy(srb_cachep);
3706}
3707
3708module_init(qla4xxx_module_init);
3709module_exit(qla4xxx_module_exit);
3710
3711MODULE_AUTHOR("QLogic Corporation");
3712MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
3713MODULE_LICENSE("GPL");
3714MODULE_VERSION(QLA4XXX_DRIVER_VERSION);