blob: bfb3d37612fc07cf5d21345428da77c65a87aec5 [file] [log] [blame]
David Somayajuluafaf5a22006-09-19 10:28:00 -07001/*
2 * QLogic iSCSI HBA Driver
Vikas Chaudhary7d01d062010-12-02 22:12:51 -08003 * Copyright (c) 2003-2010 QLogic Corporation
David Somayajuluafaf5a22006-09-19 10:28:00 -07004 *
5 * See LICENSE.qla4xxx for copyright and licensing details.
6 */
7#include <linux/moduleparam.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -07009
10#include <scsi/scsi_tcq.h>
11#include <scsi/scsicam.h>
12
13#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070014#include "ql4_version.h"
15#include "ql4_glbl.h"
16#include "ql4_dbg.h"
17#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070018
19/*
20 * Driver version
21 */
Adrian Bunk47975472007-04-26 00:35:16 -070022static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070023
24/*
25 * SRB allocation cache
26 */
Christoph Lametere18b8902006-12-06 20:33:20 -080027static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070028
29/*
30 * Module parameter information and variables
31 */
David Somayajuluafaf5a22006-09-19 10:28:00 -070032int ql4xdontresethba = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053033module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070034MODULE_PARM_DESC(ql4xdontresethba,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053035 "Don't reset the HBA for driver recovery \n"
36 " 0 - It will reset HBA (Default)\n"
37 " 1 - It will NOT reset HBA");
David Somayajuluafaf5a22006-09-19 10:28:00 -070038
Andrew Vasquez11010fe2006-10-06 09:54:59 -070039int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053040module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070041MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070042 "Option to enable extended error logging, "
43 "Default is 0 - no logging, 1 - debug logging");
44
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053045int ql4xenablemsix = 1;
46module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
47MODULE_PARM_DESC(ql4xenablemsix,
48 "Set to enable MSI or MSI-X interrupt mechanism.\n"
49 " 0 = enable INTx interrupt mechanism.\n"
50 " 1 = enable MSI-X interrupt mechanism (Default).\n"
51 " 2 = enable MSI interrupt mechanism.");
David C Somayajulu477ffb92007-01-22 12:26:11 -080052
Mike Christied510d962008-07-11 19:50:33 -050053#define QL4_DEF_QDEPTH 32
Vikas Chaudhary8bb40332011-03-21 03:34:31 -070054static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
55module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
56MODULE_PARM_DESC(ql4xmaxqdepth,
57 "Maximum queue depth to report for target devices.\n"
58 " Default: 32.");
Mike Christied510d962008-07-11 19:50:33 -050059
Vikas Chaudhary30387272011-03-21 03:34:32 -070060static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
61module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
62MODULE_PARM_DESC(ql4xsess_recovery_tmo,
63 "Target Session Recovery Timeout.\n"
64 " Default: 30 sec.");
65
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 */
David Somayajuluafaf5a22006-09-19 10:28:00 -070075static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
76 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050077static int qla4xxx_host_get_param(struct Scsi_Host *shost,
78 enum iscsi_host_param param, char *buf);
Mike Christied00efe32011-07-25 13:48:38 -050079static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data,
80 int count);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -050081static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
82 enum iscsi_param_type param_type,
83 int param, char *buf);
Mike Christie5c656af2009-07-15 15:02:59 -050084static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
Manish Rangankarb3a271a2011-07-25 13:48:53 -050085static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
86 struct sockaddr *dst_addr,
87 int non_blocking);
88static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
89static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
90static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
91 enum iscsi_param param, char *buf);
92static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
93static struct iscsi_cls_conn *
94qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
95static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
96 struct iscsi_cls_conn *cls_conn,
97 uint64_t transport_fd, int is_leading);
98static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
99static struct iscsi_cls_session *
100qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
101 uint16_t qdepth, uint32_t initial_cmdsn);
102static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
103static void qla4xxx_task_work(struct work_struct *wdata);
104static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
105static int qla4xxx_task_xmit(struct iscsi_task *);
106static void qla4xxx_task_cleanup(struct iscsi_task *);
107static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
108static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
109 struct iscsi_stats *stats);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700110/*
111 * SCSI host template entry points
112 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500113static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530114static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700115static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600116static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700117static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
118static int qla4xxx_slave_alloc(struct scsi_device *device);
119static int qla4xxx_slave_configure(struct scsi_device *device);
120static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Mike Christie3128c6c2011-07-25 13:48:42 -0500121static mode_t ql4_attr_is_visible(int param_type, int param);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700122
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530123static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
124 QLA82XX_LEGACY_INTR_CONFIG;
125
David Somayajuluafaf5a22006-09-19 10:28:00 -0700126static struct scsi_host_template qla4xxx_driver_template = {
127 .module = THIS_MODULE,
128 .name = DRIVER_NAME,
129 .proc_name = DRIVER_NAME,
130 .queuecommand = qla4xxx_queuecommand,
131
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530132 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700133 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600134 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700135 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500136 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700137
138 .slave_configure = qla4xxx_slave_configure,
139 .slave_alloc = qla4xxx_slave_alloc,
140 .slave_destroy = qla4xxx_slave_destroy,
141
142 .this_id = -1,
143 .cmd_per_lun = 3,
144 .use_clustering = ENABLE_CLUSTERING,
145 .sg_tablesize = SG_ALL,
146
147 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700148 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500149 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700150};
151
152static struct iscsi_transport qla4xxx_iscsi_transport = {
153 .owner = THIS_MODULE,
154 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500155 .caps = CAP_TEXT_NEGO |
156 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
157 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
158 CAP_MULTI_R2T,
Mike Christie3128c6c2011-07-25 13:48:42 -0500159 .attr_is_visible = ql4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500160 .create_session = qla4xxx_session_create,
161 .destroy_session = qla4xxx_session_destroy,
162 .start_conn = qla4xxx_conn_start,
163 .create_conn = qla4xxx_conn_create,
164 .bind_conn = qla4xxx_conn_bind,
165 .stop_conn = iscsi_conn_stop,
166 .destroy_conn = qla4xxx_conn_destroy,
167 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700168 .get_conn_param = qla4xxx_conn_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500169 .get_session_param = iscsi_session_get_param,
170 .get_ep_param = qla4xxx_get_ep_param,
171 .ep_connect = qla4xxx_ep_connect,
172 .ep_poll = qla4xxx_ep_poll,
173 .ep_disconnect = qla4xxx_ep_disconnect,
174 .get_stats = qla4xxx_conn_get_stats,
175 .send_pdu = iscsi_conn_send_pdu,
176 .xmit_task = qla4xxx_task_xmit,
177 .cleanup_task = qla4xxx_task_cleanup,
178 .alloc_pdu = qla4xxx_alloc_pdu,
179
Mike Christieaa1e93a2007-05-30 12:57:09 -0500180 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500181 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500182 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500183 .bsg_request = qla4xxx_bsg_request,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700184};
185
186static struct scsi_transport_template *qla4xxx_scsi_transport;
187
Mike Christie3128c6c2011-07-25 13:48:42 -0500188static mode_t ql4_attr_is_visible(int param_type, int param)
189{
190 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500191 case ISCSI_HOST_PARAM:
192 switch (param) {
193 case ISCSI_HOST_PARAM_HWADDRESS:
194 case ISCSI_HOST_PARAM_IPADDRESS:
195 case ISCSI_HOST_PARAM_INITIATOR_NAME:
196 return S_IRUGO;
197 default:
198 return 0;
199 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500200 case ISCSI_PARAM:
201 switch (param) {
202 case ISCSI_PARAM_CONN_ADDRESS:
203 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500204 case ISCSI_PARAM_TARGET_NAME:
205 case ISCSI_PARAM_TPGT:
206 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500207 case ISCSI_PARAM_MAX_BURST:
208 case ISCSI_PARAM_MAX_R2T:
209 case ISCSI_PARAM_FIRST_BURST:
210 case ISCSI_PARAM_MAX_RECV_DLENGTH:
211 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christie3128c6c2011-07-25 13:48:42 -0500212 return S_IRUGO;
213 default:
214 return 0;
215 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500216 case ISCSI_NET_PARAM:
217 switch (param) {
218 case ISCSI_NET_PARAM_IPV4_ADDR:
219 case ISCSI_NET_PARAM_IPV4_SUBNET:
220 case ISCSI_NET_PARAM_IPV4_GW:
221 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
222 case ISCSI_NET_PARAM_IFACE_ENABLE:
223 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
224 case ISCSI_NET_PARAM_IPV6_ADDR:
225 case ISCSI_NET_PARAM_IPV6_ROUTER:
226 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
227 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500228 case ISCSI_NET_PARAM_VLAN_ID:
229 case ISCSI_NET_PARAM_VLAN_PRIORITY:
230 case ISCSI_NET_PARAM_VLAN_ENABLED:
Mike Christieb78dbba2011-07-25 13:48:44 -0500231 return S_IRUGO;
232 default:
233 return 0;
234 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500235 }
236
237 return 0;
238}
239
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500240static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
241 enum iscsi_param_type param_type,
242 int param, char *buf)
243{
244 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
245 struct scsi_qla_host *ha = to_qla_host(shost);
246 int len = -ENOSYS;
247
248 if (param_type != ISCSI_NET_PARAM)
249 return -ENOSYS;
250
251 switch (param) {
252 case ISCSI_NET_PARAM_IPV4_ADDR:
253 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
254 break;
255 case ISCSI_NET_PARAM_IPV4_SUBNET:
256 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
257 break;
258 case ISCSI_NET_PARAM_IPV4_GW:
259 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
260 break;
261 case ISCSI_NET_PARAM_IFACE_ENABLE:
262 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
263 len = sprintf(buf, "%s\n",
264 (ha->ip_config.ipv4_options &
265 IPOPT_IPV4_PROTOCOL_ENABLE) ?
266 "enabled" : "disabled");
267 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
268 len = sprintf(buf, "%s\n",
269 (ha->ip_config.ipv6_options &
270 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
271 "enabled" : "disabled");
272 break;
273 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
274 len = sprintf(buf, "%s\n",
275 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
276 "dhcp" : "static");
277 break;
278 case ISCSI_NET_PARAM_IPV6_ADDR:
279 if (iface->iface_num == 0)
280 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
281 if (iface->iface_num == 1)
282 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
283 break;
284 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
285 len = sprintf(buf, "%pI6\n",
286 &ha->ip_config.ipv6_link_local_addr);
287 break;
288 case ISCSI_NET_PARAM_IPV6_ROUTER:
289 len = sprintf(buf, "%pI6\n",
290 &ha->ip_config.ipv6_default_router_addr);
291 break;
292 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
293 len = sprintf(buf, "%s\n",
294 (ha->ip_config.ipv6_addl_options &
295 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
296 "nd" : "static");
297 break;
298 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
299 len = sprintf(buf, "%s\n",
300 (ha->ip_config.ipv6_addl_options &
301 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
302 "auto" : "static");
303 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500304 case ISCSI_NET_PARAM_VLAN_ID:
305 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
306 len = sprintf(buf, "%d\n",
307 (ha->ip_config.ipv4_vlan_tag &
308 ISCSI_MAX_VLAN_ID));
309 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
310 len = sprintf(buf, "%d\n",
311 (ha->ip_config.ipv6_vlan_tag &
312 ISCSI_MAX_VLAN_ID));
313 break;
314 case ISCSI_NET_PARAM_VLAN_PRIORITY:
315 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
316 len = sprintf(buf, "%d\n",
317 ((ha->ip_config.ipv4_vlan_tag >> 13) &
318 ISCSI_MAX_VLAN_PRIORITY));
319 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
320 len = sprintf(buf, "%d\n",
321 ((ha->ip_config.ipv6_vlan_tag >> 13) &
322 ISCSI_MAX_VLAN_PRIORITY));
323 break;
324 case ISCSI_NET_PARAM_VLAN_ENABLED:
325 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
326 len = sprintf(buf, "%s\n",
327 (ha->ip_config.ipv4_options &
328 IPOPT_VLAN_TAGGING_ENABLE) ?
329 "enabled" : "disabled");
330 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
331 len = sprintf(buf, "%s\n",
332 (ha->ip_config.ipv6_options &
333 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
334 "enabled" : "disabled");
335 break;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500336 default:
337 len = -ENOSYS;
338 }
339
340 return len;
341}
342
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500343static struct iscsi_endpoint *
344qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
345 int non_blocking)
346{
347 int ret;
348 struct iscsi_endpoint *ep;
349 struct qla_endpoint *qla_ep;
350 struct scsi_qla_host *ha;
351 struct sockaddr_in *addr;
352 struct sockaddr_in6 *addr6;
353
354 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
355 if (!shost) {
356 ret = -ENXIO;
357 printk(KERN_ERR "%s: shost is NULL\n",
358 __func__);
359 return ERR_PTR(ret);
360 }
361
362 ha = iscsi_host_priv(shost);
363
364 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
365 if (!ep) {
366 ret = -ENOMEM;
367 return ERR_PTR(ret);
368 }
369
370 qla_ep = ep->dd_data;
371 memset(qla_ep, 0, sizeof(struct qla_endpoint));
372 if (dst_addr->sa_family == AF_INET) {
373 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
374 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
375 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
376 (char *)&addr->sin_addr));
377 } else if (dst_addr->sa_family == AF_INET6) {
378 memcpy(&qla_ep->dst_addr, dst_addr,
379 sizeof(struct sockaddr_in6));
380 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
381 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
382 (char *)&addr6->sin6_addr));
383 }
384
385 qla_ep->host = shost;
386
387 return ep;
388}
389
390static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
391{
392 struct qla_endpoint *qla_ep;
393 struct scsi_qla_host *ha;
394 int ret = 0;
395
396 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
397 qla_ep = ep->dd_data;
398 ha = to_qla_host(qla_ep->host);
399
400 if (adapter_up(ha))
401 ret = 1;
402
403 return ret;
404}
405
406static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
407{
408 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
409 iscsi_destroy_endpoint(ep);
410}
411
412static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
413 enum iscsi_param param,
414 char *buf)
415{
416 struct qla_endpoint *qla_ep = ep->dd_data;
417 struct sockaddr *dst_addr;
418
419 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
420
421 switch (param) {
422 case ISCSI_PARAM_CONN_PORT:
423 case ISCSI_PARAM_CONN_ADDRESS:
424 if (!qla_ep)
425 return -ENOTCONN;
426
427 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
428 if (!dst_addr)
429 return -ENOTCONN;
430
431 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
432 &qla_ep->dst_addr, param, buf);
433 default:
434 return -ENOSYS;
435 }
436}
437
438static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
439 struct iscsi_stats *stats)
440{
441 struct iscsi_session *sess;
442 struct iscsi_cls_session *cls_sess;
443 struct ddb_entry *ddb_entry;
444 struct scsi_qla_host *ha;
445 struct ql_iscsi_stats *ql_iscsi_stats;
446 int stats_size;
447 int ret;
448 dma_addr_t iscsi_stats_dma;
449
450 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
451
452 cls_sess = iscsi_conn_to_session(cls_conn);
453 sess = cls_sess->dd_data;
454 ddb_entry = sess->dd_data;
455 ha = ddb_entry->ha;
456
457 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
458 /* Allocate memory */
459 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
460 &iscsi_stats_dma, GFP_KERNEL);
461 if (!ql_iscsi_stats) {
462 ql4_printk(KERN_ERR, ha,
463 "Unable to allocate memory for iscsi stats\n");
464 goto exit_get_stats;
465 }
466
467 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
468 iscsi_stats_dma);
469 if (ret != QLA_SUCCESS) {
470 ql4_printk(KERN_ERR, ha,
471 "Unable to retreive iscsi stats\n");
472 goto free_stats;
473 }
474
475 /* octets */
476 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
477 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
478 /* xmit pdus */
479 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
480 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
481 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
482 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
483 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
484 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
485 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
486 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
487 /* recv pdus */
488 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
489 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
490 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
491 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
492 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
493 stats->logoutrsp_pdus =
494 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
495 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
496 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
497 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
498
499free_stats:
500 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
501 iscsi_stats_dma);
502exit_get_stats:
503 return;
504}
505
Mike Christie5c656af2009-07-15 15:02:59 -0500506static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
507{
508 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500509 struct iscsi_session *sess;
510 unsigned long flags;
511 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -0500512
513 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500514 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -0500515
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500516 spin_lock_irqsave(&session->lock, flags);
517 if (session->state == ISCSI_SESSION_FAILED)
518 ret = BLK_EH_RESET_TIMER;
519 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -0500520
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500521 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700522}
523
Mike Christieaa1e93a2007-05-30 12:57:09 -0500524static int qla4xxx_host_get_param(struct Scsi_Host *shost,
525 enum iscsi_host_param param, char *buf)
526{
527 struct scsi_qla_host *ha = to_qla_host(shost);
528 int len;
529
530 switch (param) {
531 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800532 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500533 break;
Mike Christie22236962007-05-30 12:57:24 -0500534 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500535 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -0500536 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500537 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500538 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500539 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500540 default:
541 return -ENOSYS;
542 }
543
544 return len;
545}
546
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500547static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
548{
549 if (ha->iface_ipv4)
550 return;
551
552 /* IPv4 */
553 ha->iface_ipv4 = iscsi_create_iface(ha->host,
554 &qla4xxx_iscsi_transport,
555 ISCSI_IFACE_TYPE_IPV4, 0, 0);
556 if (!ha->iface_ipv4)
557 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
558 "iface0.\n");
559}
560
561static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
562{
563 if (!ha->iface_ipv6_0)
564 /* IPv6 iface-0 */
565 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
566 &qla4xxx_iscsi_transport,
567 ISCSI_IFACE_TYPE_IPV6, 0,
568 0);
569 if (!ha->iface_ipv6_0)
570 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
571 "iface0.\n");
572
573 if (!ha->iface_ipv6_1)
574 /* IPv6 iface-1 */
575 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
576 &qla4xxx_iscsi_transport,
577 ISCSI_IFACE_TYPE_IPV6, 1,
578 0);
579 if (!ha->iface_ipv6_1)
580 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
581 "iface1.\n");
582}
583
584static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
585{
586 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
587 qla4xxx_create_ipv4_iface(ha);
588
589 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
590 qla4xxx_create_ipv6_iface(ha);
591}
592
593static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
594{
595 if (ha->iface_ipv4) {
596 iscsi_destroy_iface(ha->iface_ipv4);
597 ha->iface_ipv4 = NULL;
598 }
599}
600
601static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
602{
603 if (ha->iface_ipv6_0) {
604 iscsi_destroy_iface(ha->iface_ipv6_0);
605 ha->iface_ipv6_0 = NULL;
606 }
607 if (ha->iface_ipv6_1) {
608 iscsi_destroy_iface(ha->iface_ipv6_1);
609 ha->iface_ipv6_1 = NULL;
610 }
611}
612
613static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
614{
615 qla4xxx_destroy_ipv4_iface(ha);
616 qla4xxx_destroy_ipv6_iface(ha);
617}
618
Mike Christied00efe32011-07-25 13:48:38 -0500619static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
620 struct iscsi_iface_param_info *iface_param,
621 struct addr_ctrl_blk *init_fw_cb)
622{
623 /*
624 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
625 * iface_num 1 is valid only for IPv6 Addr.
626 */
627 switch (iface_param->param) {
628 case ISCSI_NET_PARAM_IPV6_ADDR:
629 if (iface_param->iface_num & 0x1)
630 /* IPv6 Addr 1 */
631 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
632 sizeof(init_fw_cb->ipv6_addr1));
633 else
634 /* IPv6 Addr 0 */
635 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
636 sizeof(init_fw_cb->ipv6_addr0));
637 break;
638 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
639 if (iface_param->iface_num & 0x1)
640 break;
641 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
642 sizeof(init_fw_cb->ipv6_if_id));
643 break;
644 case ISCSI_NET_PARAM_IPV6_ROUTER:
645 if (iface_param->iface_num & 0x1)
646 break;
647 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
648 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
649 break;
650 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
651 /* Autocfg applies to even interface */
652 if (iface_param->iface_num & 0x1)
653 break;
654
655 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
656 init_fw_cb->ipv6_addtl_opts &=
657 cpu_to_le16(
658 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
659 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
660 init_fw_cb->ipv6_addtl_opts |=
661 cpu_to_le16(
662 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
663 else
664 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
665 "IPv6 addr\n");
666 break;
667 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
668 /* Autocfg applies to even interface */
669 if (iface_param->iface_num & 0x1)
670 break;
671
672 if (iface_param->value[0] ==
673 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
674 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
675 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
676 else if (iface_param->value[0] ==
677 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
678 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
679 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
680 else
681 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
682 "IPv6 linklocal addr\n");
683 break;
684 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
685 /* Autocfg applies to even interface */
686 if (iface_param->iface_num & 0x1)
687 break;
688
689 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
690 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
691 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
692 break;
693 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500694 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500695 init_fw_cb->ipv6_opts |=
696 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500697 qla4xxx_create_ipv6_iface(ha);
698 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500699 init_fw_cb->ipv6_opts &=
700 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
701 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500702 qla4xxx_destroy_ipv6_iface(ha);
703 }
Mike Christied00efe32011-07-25 13:48:38 -0500704 break;
705 case ISCSI_NET_PARAM_VLAN_ID:
706 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
707 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500708 init_fw_cb->ipv6_vlan_tag =
709 cpu_to_be16(*(uint16_t *)iface_param->value);
710 break;
711 case ISCSI_NET_PARAM_VLAN_ENABLED:
712 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
713 init_fw_cb->ipv6_opts |=
714 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
715 else
716 init_fw_cb->ipv6_opts &=
717 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500718 break;
719 default:
720 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
721 iface_param->param);
722 break;
723 }
724}
725
726static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
727 struct iscsi_iface_param_info *iface_param,
728 struct addr_ctrl_blk *init_fw_cb)
729{
730 switch (iface_param->param) {
731 case ISCSI_NET_PARAM_IPV4_ADDR:
732 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
733 sizeof(init_fw_cb->ipv4_addr));
734 break;
735 case ISCSI_NET_PARAM_IPV4_SUBNET:
736 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
737 sizeof(init_fw_cb->ipv4_subnet));
738 break;
739 case ISCSI_NET_PARAM_IPV4_GW:
740 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
741 sizeof(init_fw_cb->ipv4_gw_addr));
742 break;
743 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
744 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
745 init_fw_cb->ipv4_tcp_opts |=
746 cpu_to_le16(TCPOPT_DHCP_ENABLE);
747 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
748 init_fw_cb->ipv4_tcp_opts &=
749 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
750 else
751 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
752 break;
753 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500754 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500755 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500756 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500757 qla4xxx_create_ipv4_iface(ha);
758 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500759 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500760 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -0500761 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500762 qla4xxx_destroy_ipv4_iface(ha);
763 }
Mike Christied00efe32011-07-25 13:48:38 -0500764 break;
765 case ISCSI_NET_PARAM_VLAN_ID:
766 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
767 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500768 init_fw_cb->ipv4_vlan_tag =
769 cpu_to_be16(*(uint16_t *)iface_param->value);
770 break;
771 case ISCSI_NET_PARAM_VLAN_ENABLED:
772 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
773 init_fw_cb->ipv4_ip_opts |=
774 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
775 else
776 init_fw_cb->ipv4_ip_opts &=
777 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500778 break;
779 default:
780 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
781 iface_param->param);
782 break;
783 }
784}
785
786static void
787qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
788{
789 struct addr_ctrl_blk_def *acb;
790 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
791 memset(acb->reserved1, 0, sizeof(acb->reserved1));
792 memset(acb->reserved2, 0, sizeof(acb->reserved2));
793 memset(acb->reserved3, 0, sizeof(acb->reserved3));
794 memset(acb->reserved4, 0, sizeof(acb->reserved4));
795 memset(acb->reserved5, 0, sizeof(acb->reserved5));
796 memset(acb->reserved6, 0, sizeof(acb->reserved6));
797 memset(acb->reserved7, 0, sizeof(acb->reserved7));
798 memset(acb->reserved8, 0, sizeof(acb->reserved8));
799 memset(acb->reserved9, 0, sizeof(acb->reserved9));
800 memset(acb->reserved10, 0, sizeof(acb->reserved10));
801 memset(acb->reserved11, 0, sizeof(acb->reserved11));
802 memset(acb->reserved12, 0, sizeof(acb->reserved12));
803 memset(acb->reserved13, 0, sizeof(acb->reserved13));
804 memset(acb->reserved14, 0, sizeof(acb->reserved14));
805 memset(acb->reserved15, 0, sizeof(acb->reserved15));
806}
807
808static int
809qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count)
810{
811 struct scsi_qla_host *ha = to_qla_host(shost);
812 int rval = 0;
813 struct iscsi_iface_param_info *iface_param = NULL;
814 struct addr_ctrl_blk *init_fw_cb = NULL;
815 dma_addr_t init_fw_cb_dma;
816 uint32_t mbox_cmd[MBOX_REG_COUNT];
817 uint32_t mbox_sts[MBOX_REG_COUNT];
818 uint32_t total_param_count;
819 uint32_t length;
820
821 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
822 sizeof(struct addr_ctrl_blk),
823 &init_fw_cb_dma, GFP_KERNEL);
824 if (!init_fw_cb) {
825 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
826 __func__);
827 return -ENOMEM;
828 }
829
830 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
831 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
832 memset(&mbox_sts, 0, sizeof(mbox_sts));
833
834 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
835 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
836 rval = -EIO;
837 goto exit_init_fw_cb;
838 }
839
840 total_param_count = count;
841 iface_param = (struct iscsi_iface_param_info *)data;
842
843 for ( ; total_param_count != 0; total_param_count--) {
844 length = iface_param->len;
845
846 if (iface_param->param_type != ISCSI_NET_PARAM)
847 continue;
848
849 switch (iface_param->iface_type) {
850 case ISCSI_IFACE_TYPE_IPV4:
851 switch (iface_param->iface_num) {
852 case 0:
853 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
854 break;
855 default:
856 /* Cannot have more than one IPv4 interface */
857 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
858 "number = %d\n",
859 iface_param->iface_num);
860 break;
861 }
862 break;
863 case ISCSI_IFACE_TYPE_IPV6:
864 switch (iface_param->iface_num) {
865 case 0:
866 case 1:
867 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
868 break;
869 default:
870 /* Cannot have more than two IPv6 interface */
871 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
872 "number = %d\n",
873 iface_param->iface_num);
874 break;
875 }
876 break;
877 default:
878 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
879 break;
880 }
881
882 iface_param = (struct iscsi_iface_param_info *)
883 ((uint8_t *)iface_param +
884 sizeof(struct iscsi_iface_param_info) + length);
885 }
886
887 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
888
889 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
890 sizeof(struct addr_ctrl_blk),
891 FLASH_OPT_RMW_COMMIT);
892 if (rval != QLA_SUCCESS) {
893 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
894 __func__);
895 rval = -EIO;
896 goto exit_init_fw_cb;
897 }
898
899 qla4xxx_disable_acb(ha);
900
901 qla4xxx_initcb_to_acb(init_fw_cb);
902
903 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
904 if (rval != QLA_SUCCESS) {
905 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
906 __func__);
907 rval = -EIO;
908 goto exit_init_fw_cb;
909 }
910
911 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
912 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
913 init_fw_cb_dma);
914
915exit_init_fw_cb:
916 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
917 init_fw_cb, init_fw_cb_dma);
918
919 return rval;
920}
921
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500922static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700923 enum iscsi_param param, char *buf)
924{
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500925 struct iscsi_conn *conn;
926 struct qla_conn *qla_conn;
927 struct sockaddr *dst_addr;
928 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700929
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500930 conn = cls_conn->dd_data;
931 qla_conn = conn->dd_data;
932 dst_addr = &qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700933
934 switch (param) {
935 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700936 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500937 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
938 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700939 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500940 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700941 }
942
943 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500944
David Somayajuluafaf5a22006-09-19 10:28:00 -0700945}
946
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500947static struct iscsi_cls_session *
948qla4xxx_session_create(struct iscsi_endpoint *ep,
949 uint16_t cmds_max, uint16_t qdepth,
950 uint32_t initial_cmdsn)
951{
952 struct iscsi_cls_session *cls_sess;
953 struct scsi_qla_host *ha;
954 struct qla_endpoint *qla_ep;
955 struct ddb_entry *ddb_entry;
956 uint32_t ddb_index;
957 uint32_t mbx_sts = 0;
958 struct iscsi_session *sess;
959 struct sockaddr *dst_addr;
960 int ret;
961
962 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
963 if (!ep) {
964 printk(KERN_ERR "qla4xxx: missing ep.\n");
965 return NULL;
966 }
967
968 qla_ep = ep->dd_data;
969 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
970 ha = to_qla_host(qla_ep->host);
971get_ddb_index:
972 ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
973
974 if (ddb_index >= MAX_DDB_ENTRIES) {
975 DEBUG2(ql4_printk(KERN_INFO, ha,
976 "Free DDB index not available\n"));
977 return NULL;
978 }
979
980 if (test_and_set_bit(ddb_index, ha->ddb_idx_map))
981 goto get_ddb_index;
982
983 DEBUG2(ql4_printk(KERN_INFO, ha,
984 "Found a free DDB index at %d\n", ddb_index));
985 ret = qla4xxx_req_ddb_entry(ha, ddb_index, &mbx_sts);
986 if (ret == QLA_ERROR) {
987 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
988 ql4_printk(KERN_INFO, ha,
989 "DDB index = %d not available trying next\n",
990 ddb_index);
991 goto get_ddb_index;
992 }
993 DEBUG2(ql4_printk(KERN_INFO, ha,
994 "Free FW DDB not available\n"));
995 return NULL;
996 }
997
998 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
999 cmds_max, sizeof(struct ddb_entry),
1000 sizeof(struct ql4_task_data),
1001 initial_cmdsn, ddb_index);
1002 if (!cls_sess)
1003 return NULL;
1004
1005 sess = cls_sess->dd_data;
1006 ddb_entry = sess->dd_data;
1007 ddb_entry->fw_ddb_index = ddb_index;
1008 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1009 ddb_entry->ha = ha;
1010 ddb_entry->sess = cls_sess;
1011 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1012 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1013 ha->tot_ddbs++;
1014
1015 return cls_sess;
1016}
1017
1018static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1019{
1020 struct iscsi_session *sess;
1021 struct ddb_entry *ddb_entry;
1022 struct scsi_qla_host *ha;
1023 unsigned long flags;
1024
1025 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1026 sess = cls_sess->dd_data;
1027 ddb_entry = sess->dd_data;
1028 ha = ddb_entry->ha;
1029
1030 spin_lock_irqsave(&ha->hardware_lock, flags);
1031 qla4xxx_free_ddb(ha, ddb_entry);
1032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1033 iscsi_session_teardown(cls_sess);
1034}
1035
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001036static struct iscsi_cls_conn *
1037qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1038{
1039 struct iscsi_cls_conn *cls_conn;
1040 struct iscsi_session *sess;
1041 struct ddb_entry *ddb_entry;
1042
1043 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1044 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1045 conn_idx);
1046 sess = cls_sess->dd_data;
1047 ddb_entry = sess->dd_data;
1048 ddb_entry->conn = cls_conn;
1049
1050 return cls_conn;
1051}
1052
1053static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1054 struct iscsi_cls_conn *cls_conn,
1055 uint64_t transport_fd, int is_leading)
1056{
1057 struct iscsi_conn *conn;
1058 struct qla_conn *qla_conn;
1059 struct iscsi_endpoint *ep;
1060
1061 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1062
1063 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1064 return -EINVAL;
1065 ep = iscsi_lookup_endpoint(transport_fd);
1066 conn = cls_conn->dd_data;
1067 qla_conn = conn->dd_data;
1068 qla_conn->qla_ep = ep->dd_data;
1069 return 0;
1070}
1071
1072static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1073{
1074 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1075 struct iscsi_session *sess;
1076 struct ddb_entry *ddb_entry;
1077 struct scsi_qla_host *ha;
1078 struct dev_db_entry *fw_ddb_entry;
1079 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001080 uint32_t mbx_sts = 0;
1081 int ret = 0;
1082 int status = QLA_SUCCESS;
1083
1084 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1085 sess = cls_sess->dd_data;
1086 ddb_entry = sess->dd_data;
1087 ha = ddb_entry->ha;
1088
1089 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1090 &fw_ddb_entry_dma, GFP_KERNEL);
1091 if (!fw_ddb_entry) {
1092 ql4_printk(KERN_ERR, ha,
1093 "%s: Unable to allocate dma buffer\n", __func__);
1094 return -ENOMEM;
1095 }
1096
1097 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1098 if (ret) {
1099 /* If iscsid is stopped and started then no need to do
1100 * set param again since ddb state will be already
1101 * active and FW does not allow set ddb to an
1102 * active session.
1103 */
1104 if (mbx_sts)
1105 if (ddb_entry->fw_ddb_device_state ==
1106 DDB_DS_SESSION_ACTIVE)
1107 goto exit_set_param;
1108
1109 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1110 __func__, ddb_entry->fw_ddb_index);
1111 goto exit_conn_start;
1112 }
1113
1114 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1115 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05001116 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1117 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001118 ret = -EINVAL;
1119 goto exit_conn_start;
1120 }
1121
1122 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1123
1124exit_set_param:
1125 iscsi_conn_start(cls_conn);
1126 ret = 0;
1127
1128exit_conn_start:
1129 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1130 fw_ddb_entry, fw_ddb_entry_dma);
1131 return ret;
1132}
1133
1134static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1135{
1136 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1137 struct iscsi_session *sess;
1138 struct scsi_qla_host *ha;
1139 struct ddb_entry *ddb_entry;
1140 int options;
1141
1142 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1143 sess = cls_sess->dd_data;
1144 ddb_entry = sess->dd_data;
1145 ha = ddb_entry->ha;
1146
1147 options = LOGOUT_OPTION_CLOSE_SESSION;
1148 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1149 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
1150 else
1151 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1152
1153 /*
1154 * Clear the DDB bit so that next login can use the bit
1155 * if FW is not clearing the DDB entry then set DDB will fail anyways
1156 */
1157 clear_bit(ddb_entry->fw_ddb_index, ha->ddb_idx_map);
1158}
1159
1160static void qla4xxx_task_work(struct work_struct *wdata)
1161{
1162 struct ql4_task_data *task_data;
1163 struct scsi_qla_host *ha;
1164 struct passthru_status *sts;
1165 struct iscsi_task *task;
1166 struct iscsi_hdr *hdr;
1167 uint8_t *data;
1168 uint32_t data_len;
1169 struct iscsi_conn *conn;
1170 int hdr_len;
1171 itt_t itt;
1172
1173 task_data = container_of(wdata, struct ql4_task_data, task_work);
1174 ha = task_data->ha;
1175 task = task_data->task;
1176 sts = &task_data->sts;
1177 hdr_len = sizeof(struct iscsi_hdr);
1178
1179 DEBUG3(printk(KERN_INFO "Status returned\n"));
1180 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1181 DEBUG3(printk(KERN_INFO "Response buffer"));
1182 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1183
1184 conn = task->conn;
1185
1186 switch (sts->completionStatus) {
1187 case PASSTHRU_STATUS_COMPLETE:
1188 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1189 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1190 itt = sts->handle;
1191 hdr->itt = itt;
1192 data = task_data->resp_buffer + hdr_len;
1193 data_len = task_data->resp_len - hdr_len;
1194 iscsi_complete_pdu(conn, hdr, data, data_len);
1195 break;
1196 default:
1197 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1198 sts->completionStatus);
1199 break;
1200 }
1201 return;
1202}
1203
1204static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1205{
1206 struct ql4_task_data *task_data;
1207 struct iscsi_session *sess;
1208 struct ddb_entry *ddb_entry;
1209 struct scsi_qla_host *ha;
1210 int hdr_len;
1211
1212 sess = task->conn->session;
1213 ddb_entry = sess->dd_data;
1214 ha = ddb_entry->ha;
1215 task_data = task->dd_data;
1216 memset(task_data, 0, sizeof(struct ql4_task_data));
1217
1218 if (task->sc) {
1219 ql4_printk(KERN_INFO, ha,
1220 "%s: SCSI Commands not implemented\n", __func__);
1221 return -EINVAL;
1222 }
1223
1224 hdr_len = sizeof(struct iscsi_hdr);
1225 task_data->ha = ha;
1226 task_data->task = task;
1227
1228 if (task->data_count) {
1229 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1230 task->data_count,
1231 PCI_DMA_TODEVICE);
1232 }
1233
1234 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1235 __func__, task->conn->max_recv_dlength, hdr_len));
1236
1237 task_data->resp_len = task->conn->max_recv_dlength;
1238 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1239 task_data->resp_len,
1240 &task_data->resp_dma,
1241 GFP_ATOMIC);
1242 if (!task_data->resp_buffer)
1243 goto exit_alloc_pdu;
1244
1245 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
1246 task->data_count + hdr_len,
1247 &task_data->req_dma,
1248 GFP_ATOMIC);
1249 if (!task_data->req_buffer)
1250 goto exit_alloc_pdu;
1251
1252 task->hdr = task_data->req_buffer;
1253
1254 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1255
1256 return 0;
1257
1258exit_alloc_pdu:
1259 if (task_data->resp_buffer)
1260 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1261 task_data->resp_buffer, task_data->resp_dma);
1262
1263 if (task_data->req_buffer)
1264 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1265 task_data->req_buffer, task_data->req_dma);
1266 return -ENOMEM;
1267}
1268
1269static void qla4xxx_task_cleanup(struct iscsi_task *task)
1270{
1271 struct ql4_task_data *task_data;
1272 struct iscsi_session *sess;
1273 struct ddb_entry *ddb_entry;
1274 struct scsi_qla_host *ha;
1275 int hdr_len;
1276
1277 hdr_len = sizeof(struct iscsi_hdr);
1278 sess = task->conn->session;
1279 ddb_entry = sess->dd_data;
1280 ha = ddb_entry->ha;
1281 task_data = task->dd_data;
1282
1283 if (task->data_count) {
1284 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1285 task->data_count, 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 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1292 task_data->resp_buffer, task_data->resp_dma);
1293 dma_free_coherent(&ha->pdev->dev, task->data_count + hdr_len,
1294 task_data->req_buffer, task_data->req_dma);
1295 return;
1296}
1297
1298static int qla4xxx_task_xmit(struct iscsi_task *task)
1299{
1300 struct scsi_cmnd *sc = task->sc;
1301 struct iscsi_session *sess = task->conn->session;
1302 struct ddb_entry *ddb_entry = sess->dd_data;
1303 struct scsi_qla_host *ha = ddb_entry->ha;
1304
1305 if (!sc)
1306 return qla4xxx_send_passthru0(task);
1307
1308 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1309 __func__);
1310 return -ENOSYS;
1311}
1312
1313void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1314 struct ddb_entry *ddb_entry)
1315{
1316 struct iscsi_cls_session *cls_sess;
1317 struct iscsi_cls_conn *cls_conn;
1318 struct iscsi_session *sess;
1319 struct iscsi_conn *conn;
1320 uint32_t ddb_state;
1321 dma_addr_t fw_ddb_entry_dma;
1322 struct dev_db_entry *fw_ddb_entry;
1323
1324 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1325 &fw_ddb_entry_dma, GFP_KERNEL);
1326 if (!fw_ddb_entry) {
1327 ql4_printk(KERN_ERR, ha,
1328 "%s: Unable to allocate dma buffer\n", __func__);
1329 return;
1330 }
1331
1332 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1333 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1334 NULL, NULL, NULL) == QLA_ERROR) {
1335 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1336 "get_ddb_entry for fw_ddb_index %d\n",
1337 ha->host_no, __func__,
1338 ddb_entry->fw_ddb_index));
1339 return;
1340 }
1341
1342 cls_sess = ddb_entry->sess;
1343 sess = cls_sess->dd_data;
1344
1345 cls_conn = ddb_entry->conn;
1346 conn = cls_conn->dd_data;
1347
1348 /* Update params */
1349 conn->max_recv_dlength = BYTE_UNITS *
1350 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1351
1352 conn->max_xmit_dlength = BYTE_UNITS *
1353 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1354
1355 sess->initial_r2t_en =
1356 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1357
1358 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1359
1360 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1361
1362 sess->first_burst = BYTE_UNITS *
1363 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1364
1365 sess->max_burst = BYTE_UNITS *
1366 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1367
1368 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1369
1370 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1371
1372 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1373
1374 memcpy(sess->initiatorname, ha->name_string,
1375 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
1376}
1377
David Somayajuluafaf5a22006-09-19 10:28:00 -07001378/*
1379 * Timer routines
1380 */
1381
1382static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
1383 unsigned long interval)
1384{
1385 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
1386 __func__, ha->host->host_no));
1387 init_timer(&ha->timer);
1388 ha->timer.expires = jiffies + interval * HZ;
1389 ha->timer.data = (unsigned long)ha;
1390 ha->timer.function = (void (*)(unsigned long))func;
1391 add_timer(&ha->timer);
1392 ha->timer_active = 1;
1393}
1394
1395static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
1396{
1397 del_timer_sync(&ha->timer);
1398 ha->timer_active = 0;
1399}
1400
1401/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001402 * qla4xxx_mark_device_missing - blocks the session
1403 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07001404 * @ddb_entry: Pointer to device database entry
1405 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301406 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001407 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001408void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001409{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001410 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001411}
1412
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301413/**
1414 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
1415 * @ha: Pointer to host adapter structure.
1416 *
1417 * This routine marks a device missing and resets the relogin retry count.
1418 **/
1419void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
1420{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001421 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301422}
1423
David Somayajuluafaf5a22006-09-19 10:28:00 -07001424static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1425 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001426 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001427{
1428 struct srb *srb;
1429
1430 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
1431 if (!srb)
1432 return srb;
1433
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301434 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001435 srb->ha = ha;
1436 srb->ddb = ddb_entry;
1437 srb->cmd = cmd;
1438 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05301439 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001440
1441 return srb;
1442}
1443
1444static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1445{
1446 struct scsi_cmnd *cmd = srb->cmd;
1447
1448 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09001449 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001450 srb->flags &= ~SRB_DMA_VALID;
1451 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05301452 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001453}
1454
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301455void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001456{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301457 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001458 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301459 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001460
1461 qla4xxx_srb_free_dma(ha, srb);
1462
1463 mempool_free(srb, ha->srb_mempool);
1464
1465 cmd->scsi_done(cmd);
1466}
1467
1468/**
1469 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001470 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07001471 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07001472 *
1473 * Remarks:
1474 * This routine is invoked by Linux to send a SCSI command to the driver.
1475 * The mid-level driver tries to ensure that queuecommand never gets
1476 * invoked concurrently with itself or the interrupt handler (although
1477 * the interrupt handler may call this routine as part of request-
1478 * completion handling). Unfortunely, it sometimes calls the scheduler
1479 * in interrupt context which is a big NO! NO!.
1480 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001481static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001482{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001483 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001484 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06001485 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001486 struct srb *srb;
1487 int rval;
1488
Lalit Chandivade2232be02010-07-30 14:38:47 +05301489 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1490 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1491 cmd->result = DID_NO_CONNECT << 16;
1492 else
1493 cmd->result = DID_REQUEUE << 16;
1494 goto qc_fail_command;
1495 }
1496
Mike Christie7fb19212008-01-31 13:36:45 -06001497 if (!sess) {
1498 cmd->result = DID_IMM_RETRY << 16;
1499 goto qc_fail_command;
1500 }
1501
1502 rval = iscsi_session_chkready(sess);
1503 if (rval) {
1504 cmd->result = rval;
1505 goto qc_fail_command;
1506 }
1507
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301508 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1509 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1510 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1511 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1512 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1513 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001514 !test_bit(AF_LINK_UP, &ha->flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301515 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08001516 goto qc_host_busy;
1517
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001518 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001519 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001520 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001521
1522 rval = qla4xxx_send_command_to_isp(ha, srb);
1523 if (rval != QLA_SUCCESS)
1524 goto qc_host_busy_free_sp;
1525
David Somayajuluafaf5a22006-09-19 10:28:00 -07001526 return 0;
1527
1528qc_host_busy_free_sp:
1529 qla4xxx_srb_free_dma(ha, srb);
1530 mempool_free(srb, ha->srb_mempool);
1531
David Somayajuluafaf5a22006-09-19 10:28:00 -07001532qc_host_busy:
1533 return SCSI_MLQUEUE_HOST_BUSY;
1534
1535qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001536 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001537
1538 return 0;
1539}
1540
1541/**
1542 * qla4xxx_mem_free - frees memory allocated to adapter
1543 * @ha: Pointer to host adapter structure.
1544 *
1545 * Frees memory previously allocated by qla4xxx_mem_alloc
1546 **/
1547static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1548{
1549 if (ha->queues)
1550 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1551 ha->queues_dma);
1552
1553 ha->queues_len = 0;
1554 ha->queues = NULL;
1555 ha->queues_dma = 0;
1556 ha->request_ring = NULL;
1557 ha->request_dma = 0;
1558 ha->response_ring = NULL;
1559 ha->response_dma = 0;
1560 ha->shadow_regs = NULL;
1561 ha->shadow_regs_dma = 0;
1562
1563 /* Free srb pool. */
1564 if (ha->srb_mempool)
1565 mempool_destroy(ha->srb_mempool);
1566
1567 ha->srb_mempool = NULL;
1568
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001569 if (ha->chap_dma_pool)
1570 dma_pool_destroy(ha->chap_dma_pool);
1571
David Somayajuluafaf5a22006-09-19 10:28:00 -07001572 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301573 if (is_qla8022(ha)) {
1574 if (ha->nx_pcibase)
1575 iounmap(
1576 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301577 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001578 iounmap(ha->reg);
1579 pci_release_regions(ha->pdev);
1580}
1581
1582/**
1583 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1584 * @ha: Pointer to host adapter structure
1585 *
1586 * Allocates DMA memory for request and response queues. Also allocates memory
1587 * for srbs.
1588 **/
1589static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1590{
1591 unsigned long align;
1592
1593 /* Allocate contiguous block of DMA memory for queues. */
1594 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1595 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1596 sizeof(struct shadow_regs) +
1597 MEM_ALIGN_VALUE +
1598 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1599 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1600 &ha->queues_dma, GFP_KERNEL);
1601 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301602 ql4_printk(KERN_WARNING, ha,
1603 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001604
1605 goto mem_alloc_error_exit;
1606 }
1607 memset(ha->queues, 0, ha->queues_len);
1608
1609 /*
1610 * As per RISC alignment requirements -- the bus-address must be a
1611 * multiple of the request-ring size (in bytes).
1612 */
1613 align = 0;
1614 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1615 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1616 (MEM_ALIGN_VALUE - 1));
1617
1618 /* Update request and response queue pointers. */
1619 ha->request_dma = ha->queues_dma + align;
1620 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1621 ha->response_dma = ha->queues_dma + align +
1622 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1623 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1624 (REQUEST_QUEUE_DEPTH *
1625 QUEUE_SIZE));
1626 ha->shadow_regs_dma = ha->queues_dma + align +
1627 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1628 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1629 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1630 (REQUEST_QUEUE_DEPTH *
1631 QUEUE_SIZE) +
1632 (RESPONSE_QUEUE_DEPTH *
1633 QUEUE_SIZE));
1634
1635 /* Allocate memory for srb pool. */
1636 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1637 mempool_free_slab, srb_cachep);
1638 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301639 ql4_printk(KERN_WARNING, ha,
1640 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001641
1642 goto mem_alloc_error_exit;
1643 }
1644
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001645 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
1646 CHAP_DMA_BLOCK_SIZE, 8, 0);
1647
1648 if (ha->chap_dma_pool == NULL) {
1649 ql4_printk(KERN_WARNING, ha,
1650 "%s: chap_dma_pool allocation failed..\n", __func__);
1651 goto mem_alloc_error_exit;
1652 }
1653
David Somayajuluafaf5a22006-09-19 10:28:00 -07001654 return QLA_SUCCESS;
1655
1656mem_alloc_error_exit:
1657 qla4xxx_mem_free(ha);
1658 return QLA_ERROR;
1659}
1660
1661/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301662 * qla4_8xxx_check_fw_alive - Check firmware health
1663 * @ha: Pointer to host adapter structure.
1664 *
1665 * Context: Interrupt
1666 **/
1667static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
1668{
1669 uint32_t fw_heartbeat_counter, halt_status;
1670
1671 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05301672 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
1673 if (fw_heartbeat_counter == 0xffffffff) {
1674 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
1675 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
1676 ha->host_no, __func__));
1677 return;
1678 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301679
1680 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
1681 ha->seconds_since_last_heartbeat++;
1682 /* FW not alive after 2 seconds */
1683 if (ha->seconds_since_last_heartbeat == 2) {
1684 ha->seconds_since_last_heartbeat = 0;
1685 halt_status = qla4_8xxx_rd_32(ha,
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07001686 QLA82XX_PEG_HALT_STATUS1);
1687
1688 ql4_printk(KERN_INFO, ha,
1689 "scsi(%ld): %s, Dumping hw/fw registers:\n "
1690 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
1691 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
1692 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
1693 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
1694 ha->host_no, __func__, halt_status,
1695 qla4_8xxx_rd_32(ha,
1696 QLA82XX_PEG_HALT_STATUS2),
1697 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
1698 0x3c),
1699 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
1700 0x3c),
1701 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
1702 0x3c),
1703 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
1704 0x3c),
1705 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
1706 0x3c));
Nilesh Javali21033632010-07-30 14:28:07 +05301707
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301708 /* Since we cannot change dev_state in interrupt
1709 * context, set appropriate DPC flag then wakeup
1710 * DPC */
1711 if (halt_status & HALT_STATUS_UNRECOVERABLE)
1712 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
1713 else {
1714 printk("scsi%ld: %s: detect abort needed!\n",
1715 ha->host_no, __func__);
1716 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1717 }
1718 qla4xxx_wake_dpc(ha);
Nilesh Javali21033632010-07-30 14:28:07 +05301719 qla4xxx_mailbox_premature_completion(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301720 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07001721 } else
1722 ha->seconds_since_last_heartbeat = 0;
1723
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301724 ha->fw_heartbeat_counter = fw_heartbeat_counter;
1725}
1726
1727/**
1728 * qla4_8xxx_watchdog - Poll dev state
1729 * @ha: Pointer to host adapter structure.
1730 *
1731 * Context: Interrupt
1732 **/
1733void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
1734{
1735 uint32_t dev_state;
1736
1737 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
1738
1739 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08001740 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1741 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07001742 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301743 if (dev_state == QLA82XX_DEV_NEED_RESET &&
1744 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001745 if (!ql4xdontresethba) {
1746 ql4_printk(KERN_INFO, ha, "%s: HW State: "
1747 "NEED RESET!\n", __func__);
1748 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1749 qla4xxx_wake_dpc(ha);
1750 qla4xxx_mailbox_premature_completion(ha);
1751 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301752 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
1753 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08001754 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
1755 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301756 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
1757 qla4xxx_wake_dpc(ha);
1758 } else {
1759 /* Check firmware health */
1760 qla4_8xxx_check_fw_alive(ha);
1761 }
1762 }
1763}
1764
1765/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07001766 * qla4xxx_timer - checks every second for work to do.
1767 * @ha: Pointer to host adapter structure.
1768 **/
1769static void qla4xxx_timer(struct scsi_qla_host *ha)
1770{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001771 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05301772 uint16_t w;
1773
1774 /* If we are in the middle of AER/EEH processing
1775 * skip any processing and reschedule the timer
1776 */
1777 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1778 mod_timer(&ha->timer, jiffies + HZ);
1779 return;
1780 }
1781
1782 /* Hardware read to trigger an EEH error during mailbox waits. */
1783 if (!pci_channel_offline(ha->pdev))
1784 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001785
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301786 if (is_qla8022(ha)) {
1787 qla4_8xxx_watchdog(ha);
1788 }
1789
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301790 if (!is_qla8022(ha)) {
1791 /* Check for heartbeat interval. */
1792 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
1793 ha->heartbeat_interval != 0) {
1794 ha->seconds_since_last_heartbeat++;
1795 if (ha->seconds_since_last_heartbeat >
1796 ha->heartbeat_interval + 2)
1797 set_bit(DPC_RESET_HA, &ha->dpc_flags);
1798 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07001799 }
1800
David Somayajuluafaf5a22006-09-19 10:28:00 -07001801 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07001802 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001803 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1804 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
1805 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301806 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07001807 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1808 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05301809 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301810 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1811 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07001812 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001813 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
1814 " - dpc flags = 0x%lx\n",
1815 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301816 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001817 }
1818
1819 /* Reschedule timer thread to call us back in one second */
1820 mod_timer(&ha->timer, jiffies + HZ);
1821
1822 DEBUG2(ha->seconds_since_last_intr++);
1823}
1824
1825/**
1826 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
1827 * @ha: Pointer to host adapter structure.
1828 *
1829 * This routine stalls the driver until all outstanding commands are returned.
1830 * Caller must release the Hardware Lock prior to calling this routine.
1831 **/
1832static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
1833{
1834 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001835 unsigned long flags;
1836 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001837
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301838 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
1839
1840 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
1841 "complete\n", WAIT_CMD_TOV));
1842
1843 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07001844 spin_lock_irqsave(&ha->hardware_lock, flags);
1845 /* Find a command that hasn't completed. */
1846 for (index = 0; index < ha->host->can_queue; index++) {
1847 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07001848 /*
1849 * We cannot just check if the index is valid,
1850 * becase if we are run from the scsi eh, then
1851 * the scsi/block layer is going to prevent
1852 * the tag from being released.
1853 */
1854 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07001855 break;
1856 }
1857 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1858
1859 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301860 if (index == ha->host->can_queue)
1861 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001862
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301863 msleep(1000);
1864 }
1865 /* If we timed out on waiting for commands to come back
1866 * return ERROR. */
1867 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001868}
1869
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301870int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001871{
David Somayajuluafaf5a22006-09-19 10:28:00 -07001872 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001873 unsigned long flags = 0;
1874
1875 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07001876
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301877 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
1878 return QLA_ERROR;
1879
David Somayajuluafaf5a22006-09-19 10:28:00 -07001880 spin_lock_irqsave(&ha->hardware_lock, flags);
1881
1882 /*
1883 * If the SCSI Reset Interrupt bit is set, clear it.
1884 * Otherwise, the Soft Reset won't work.
1885 */
1886 ctrl_status = readw(&ha->reg->ctrl_status);
1887 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
1888 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1889
1890 /* Issue Soft Reset */
1891 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
1892 readl(&ha->reg->ctrl_status);
1893
1894 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301895 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001896}
1897
1898/**
1899 * qla4xxx_soft_reset - performs soft reset.
1900 * @ha: Pointer to host adapter structure.
1901 **/
1902int qla4xxx_soft_reset(struct scsi_qla_host *ha)
1903{
1904 uint32_t max_wait_time;
1905 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001906 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08001907 uint32_t ctrl_status;
1908
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001909 status = qla4xxx_hw_reset(ha);
1910 if (status != QLA_SUCCESS)
1911 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001912
Vikas Chaudharyf931c532010-10-06 22:48:07 -07001913 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001914 /* Wait until the Network Reset Intr bit is cleared */
1915 max_wait_time = RESET_INTR_TOV;
1916 do {
1917 spin_lock_irqsave(&ha->hardware_lock, flags);
1918 ctrl_status = readw(&ha->reg->ctrl_status);
1919 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1920
1921 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
1922 break;
1923
1924 msleep(1000);
1925 } while ((--max_wait_time));
1926
1927 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
1928 DEBUG2(printk(KERN_WARNING
1929 "scsi%ld: Network Reset Intr not cleared by "
1930 "Network function, clearing it now!\n",
1931 ha->host_no));
1932 spin_lock_irqsave(&ha->hardware_lock, flags);
1933 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
1934 readl(&ha->reg->ctrl_status);
1935 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1936 }
1937
1938 /* Wait until the firmware tells us the Soft Reset is done */
1939 max_wait_time = SOFT_RESET_TOV;
1940 do {
1941 spin_lock_irqsave(&ha->hardware_lock, flags);
1942 ctrl_status = readw(&ha->reg->ctrl_status);
1943 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1944
1945 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
1946 status = QLA_SUCCESS;
1947 break;
1948 }
1949
1950 msleep(1000);
1951 } while ((--max_wait_time));
1952
1953 /*
1954 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
1955 * after the soft reset has taken place.
1956 */
1957 spin_lock_irqsave(&ha->hardware_lock, flags);
1958 ctrl_status = readw(&ha->reg->ctrl_status);
1959 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
1960 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
1961 readl(&ha->reg->ctrl_status);
1962 }
1963 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1964
1965 /* If soft reset fails then most probably the bios on other
1966 * function is also enabled.
1967 * Since the initialization is sequential the other fn
1968 * wont be able to acknowledge the soft reset.
1969 * Issue a force soft reset to workaround this scenario.
1970 */
1971 if (max_wait_time == 0) {
1972 /* Issue Force Soft Reset */
1973 spin_lock_irqsave(&ha->hardware_lock, flags);
1974 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
1975 readl(&ha->reg->ctrl_status);
1976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1977 /* Wait until the firmware tells us the Soft Reset is done */
1978 max_wait_time = SOFT_RESET_TOV;
1979 do {
1980 spin_lock_irqsave(&ha->hardware_lock, flags);
1981 ctrl_status = readw(&ha->reg->ctrl_status);
1982 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1983
1984 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
1985 status = QLA_SUCCESS;
1986 break;
1987 }
1988
1989 msleep(1000);
1990 } while ((--max_wait_time));
1991 }
1992
1993 return status;
1994}
1995
1996/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301997 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001998 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301999 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07002000 *
2001 * This routine is called just prior to a HARD RESET to return all
2002 * outstanding commands back to the Operating System.
2003 * Caller should make sure that the following locks are released
2004 * before this calling routine: Hardware lock, and io_request_lock.
2005 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302006static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002007{
2008 struct srb *srb;
2009 int i;
2010 unsigned long flags;
2011
2012 spin_lock_irqsave(&ha->hardware_lock, flags);
2013 for (i = 0; i < ha->host->can_queue; i++) {
2014 srb = qla4xxx_del_from_active_array(ha, i);
2015 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302016 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302017 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002018 }
2019 }
2020 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002021}
2022
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302023void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2024{
2025 clear_bit(AF_ONLINE, &ha->flags);
2026
2027 /* Disable the board */
2028 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302029
2030 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2031 qla4xxx_mark_all_devices_missing(ha);
2032 clear_bit(AF_INIT_DONE, &ha->flags);
2033}
2034
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002035static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2036{
2037 struct iscsi_session *sess;
2038 struct ddb_entry *ddb_entry;
2039
2040 sess = cls_session->dd_data;
2041 ddb_entry = sess->dd_data;
2042 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
2043 iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
2044}
2045
David Somayajuluafaf5a22006-09-19 10:28:00 -07002046/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002047 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2048 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002049 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302050static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002051{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302052 int status = QLA_ERROR;
2053 uint8_t reset_chip = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002054
2055 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302056 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002057 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002058 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06002059
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302060 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002061
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302062 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002063
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002064 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2065
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302066 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2067 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002068
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302069 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2070 * do not reset adapter, jump to initialize_adapter */
2071 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2072 status = QLA_SUCCESS;
2073 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002074 }
2075
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302076 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2077 * from eh_host_reset or ioctl module */
2078 if (is_qla8022(ha) && !reset_chip &&
2079 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2080
2081 DEBUG2(ql4_printk(KERN_INFO, ha,
2082 "scsi%ld: %s - Performing stop_firmware...\n",
2083 ha->host_no, __func__));
2084 status = ha->isp_ops->reset_firmware(ha);
2085 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07002086 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2087 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302088 ha->isp_ops->disable_intrs(ha);
2089 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2090 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2091 } else {
2092 /* If the stop_firmware fails then
2093 * reset the entire chip */
2094 reset_chip = 1;
2095 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2096 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2097 }
2098 }
2099
2100 /* Issue full chip reset if recovering from a catastrophic error,
2101 * or if stop_firmware fails for ISP-82xx.
2102 * This is the default case for ISP-4xxx */
2103 if (!is_qla8022(ha) || reset_chip) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07002104 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2105 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302106 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2107 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2108 DEBUG2(ql4_printk(KERN_INFO, ha,
2109 "scsi%ld: %s - Performing chip reset..\n",
2110 ha->host_no, __func__));
2111 status = ha->isp_ops->reset_chip(ha);
2112 }
2113
2114 /* Flush any pending ddb changed AENs */
2115 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2116
2117recover_ha_init_adapter:
2118 /* Upon successful firmware/chip reset, re-initialize the adapter */
2119 if (status == QLA_SUCCESS) {
2120 /* For ISP-4xxx, force function 1 to always initialize
2121 * before function 3 to prevent both funcions from
2122 * stepping on top of the other */
2123 if (!is_qla8022(ha) && (ha->mac_index == 3))
2124 ssleep(6);
2125
2126 /* NOTE: AF_ONLINE flag set upon successful completion of
2127 * qla4xxx_initialize_adapter */
Manish Rangankar0e7e8502011-07-25 13:48:54 -05002128 status = qla4xxx_initialize_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302129 }
2130
2131 /* Retry failed adapter initialization, if necessary
2132 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2133 * case to prevent ping-pong resets between functions */
2134 if (!test_bit(AF_ONLINE, &ha->flags) &&
2135 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002136 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302137 * resetting the ha.
2138 * Since we don't want to block the DPC for too long
2139 * with multiple resets in the same thread,
2140 * utilize DPC to retry */
David Somayajuluafaf5a22006-09-19 10:28:00 -07002141 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2142 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2143 DEBUG2(printk("scsi%ld: recover adapter - retrying "
2144 "(%d) more times\n", ha->host_no,
2145 ha->retry_reset_ha_cnt));
2146 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2147 status = QLA_ERROR;
2148 } else {
2149 if (ha->retry_reset_ha_cnt > 0) {
2150 /* Schedule another Reset HA--DPC will retry */
2151 ha->retry_reset_ha_cnt--;
2152 DEBUG2(printk("scsi%ld: recover adapter - "
2153 "retry remaining %d\n",
2154 ha->host_no,
2155 ha->retry_reset_ha_cnt));
2156 status = QLA_ERROR;
2157 }
2158
2159 if (ha->retry_reset_ha_cnt == 0) {
2160 /* Recover adapter retries have been exhausted.
2161 * Adapter DEAD */
2162 DEBUG2(printk("scsi%ld: recover adapter "
2163 "failed - board disabled\n",
2164 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302165 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002166 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2167 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302168 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002169 &ha->dpc_flags);
2170 status = QLA_ERROR;
2171 }
2172 }
2173 } else {
2174 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302175 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002176 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2177 }
2178
2179 ha->adapter_error_count++;
2180
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302181 if (test_bit(AF_ONLINE, &ha->flags))
2182 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002183
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302184 scsi_unblock_requests(ha->host);
2185
2186 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2187 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002188 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302189
David Somayajuluafaf5a22006-09-19 10:28:00 -07002190 return status;
2191}
2192
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002193static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002194{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002195 struct iscsi_session *sess;
2196 struct ddb_entry *ddb_entry;
2197 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002198
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002199 sess = cls_session->dd_data;
2200 ddb_entry = sess->dd_data;
2201 ha = ddb_entry->ha;
2202 if (!iscsi_is_session_online(cls_session)) {
2203 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
2204 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2205 " unblock session\n", ha->host_no, __func__,
2206 ddb_entry->fw_ddb_index);
2207 iscsi_unblock_session(ddb_entry->sess);
2208 } else {
2209 /* Trigger relogin */
2210 iscsi_session_failure(cls_session->dd_data,
2211 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002212 }
2213 }
2214}
2215
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002216static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
2217{
2218 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
2219}
2220
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302221void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
2222{
Lalit Chandivade1b468072011-05-17 23:17:09 -07002223 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302224 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302225}
2226
David Somayajuluafaf5a22006-09-19 10:28:00 -07002227/**
2228 * qla4xxx_do_dpc - dpc routine
2229 * @data: in our case pointer to adapter structure
2230 *
2231 * This routine is a task that is schedule by the interrupt handler
2232 * to perform the background processing for interrupts. We put it
2233 * on a task queue that is consumed whenever the scheduler runs; that's
2234 * so you can do anything (i.e. put the process to sleep etc). In fact,
2235 * the mid-level tries to sleep when it reaches the driver threshold
2236 * "host->can_queue". This can cause a panic if we were in our interrupt code.
2237 **/
David Howellsc4028952006-11-22 14:57:56 +00002238static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002239{
David Howellsc4028952006-11-22 14:57:56 +00002240 struct scsi_qla_host *ha =
2241 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002242 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002243
David C Somayajuluf26b9042006-11-15 16:41:09 -08002244 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302245 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
2246 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07002247
2248 /* Initialization not yet finished. Don't do anything yet. */
2249 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07002250 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002251
Lalit Chandivade2232be02010-07-30 14:38:47 +05302252 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2253 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
2254 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07002255 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302256 }
2257
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302258 if (is_qla8022(ha)) {
2259 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
2260 qla4_8xxx_idc_lock(ha);
2261 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2262 QLA82XX_DEV_FAILED);
2263 qla4_8xxx_idc_unlock(ha);
2264 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2265 qla4_8xxx_device_state_handler(ha);
2266 }
2267 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2268 qla4_8xxx_need_qsnt_handler(ha);
2269 }
2270 }
2271
2272 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
2273 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07002274 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302275 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
2276 if (ql4xdontresethba) {
2277 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2278 ha->host_no, __func__));
2279 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2280 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2281 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2282 goto dpc_post_reset_ha;
2283 }
2284 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2285 test_bit(DPC_RESET_HA, &ha->dpc_flags))
2286 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002287
David C Somayajulu477ffb92007-01-22 12:26:11 -08002288 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002289 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002290
David Somayajuluafaf5a22006-09-19 10:28:00 -07002291 while ((readw(&ha->reg->ctrl_status) &
2292 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
2293 if (--wait_time == 0)
2294 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002295 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002296 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002297 if (wait_time == 0)
2298 DEBUG2(printk("scsi%ld: %s: SR|FSR "
2299 "bit not cleared-- resetting\n",
2300 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302301 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002302 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
2303 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302304 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002305 }
2306 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2307 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302308 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002309 }
2310 }
2311
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302312dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002313 /* ---- process AEN? --- */
2314 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
2315 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
2316
2317 /* ---- Get DHCP IP Address? --- */
2318 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
2319 qla4xxx_get_dhcp_ip_address(ha);
2320
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302321 /* ---- link change? --- */
2322 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
2323 if (!test_bit(AF_LINK_UP, &ha->flags)) {
2324 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002325 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302326 } else {
2327 /* ---- link up? --- *
2328 * F/W will auto login to all devices ONLY ONCE after
2329 * link up during driver initialization and runtime
2330 * fatal error recovery. Therefore, the driver must
2331 * manually relogin to devices when recovering from
2332 * connection failures, logouts, expired KATO, etc. */
2333
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002334 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302335 }
2336 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002337}
2338
2339/**
2340 * qla4xxx_free_adapter - release the adapter
2341 * @ha: pointer to adapter structure
2342 **/
2343static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
2344{
2345
2346 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
2347 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302348 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002349 }
2350
David Somayajuluafaf5a22006-09-19 10:28:00 -07002351 /* Remove timer thread, if present */
2352 if (ha->timer_active)
2353 qla4xxx_stop_timer(ha);
2354
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302355 /* Kill the kernel thread for this host */
2356 if (ha->dpc_thread)
2357 destroy_workqueue(ha->dpc_thread);
2358
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002359 /* Kill the kernel thread for this host */
2360 if (ha->task_wq)
2361 destroy_workqueue(ha->task_wq);
2362
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302363 /* Put firmware in known state */
2364 ha->isp_ops->reset_firmware(ha);
2365
2366 if (is_qla8022(ha)) {
2367 qla4_8xxx_idc_lock(ha);
2368 qla4_8xxx_clear_drv_active(ha);
2369 qla4_8xxx_idc_unlock(ha);
2370 }
2371
David Somayajuluafaf5a22006-09-19 10:28:00 -07002372 /* Detach interrupts */
2373 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302374 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002375
David C Somayajulubee4fe82007-05-23 18:03:32 -07002376 /* free extra memory */
2377 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302378}
David C Somayajulubee4fe82007-05-23 18:03:32 -07002379
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302380int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
2381{
2382 int status = 0;
2383 uint8_t revision_id;
2384 unsigned long mem_base, mem_len, db_base, db_len;
2385 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002386
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302387 status = pci_request_regions(pdev, DRIVER_NAME);
2388 if (status) {
2389 printk(KERN_WARNING
2390 "scsi(%ld) Failed to reserve PIO regions (%s) "
2391 "status=%d\n", ha->host_no, pci_name(pdev), status);
2392 goto iospace_error_exit;
2393 }
2394
2395 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
2396 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
2397 __func__, revision_id));
2398 ha->revision_id = revision_id;
2399
2400 /* remap phys address */
2401 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
2402 mem_len = pci_resource_len(pdev, 0);
2403 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
2404 __func__, mem_base, mem_len));
2405
2406 /* mapping of pcibase pointer */
2407 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
2408 if (!ha->nx_pcibase) {
2409 printk(KERN_ERR
2410 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
2411 pci_release_regions(ha->pdev);
2412 goto iospace_error_exit;
2413 }
2414
2415 /* Mapping of IO base pointer, door bell read and write pointer */
2416
2417 /* mapping of IO base pointer */
2418 ha->qla4_8xxx_reg =
2419 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
2420 0xbc000 + (ha->pdev->devfn << 11));
2421
2422 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
2423 db_len = pci_resource_len(pdev, 4);
2424
Shyam Sundar2657c802010-10-06 22:50:29 -07002425 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
2426 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302427
Shyam Sundar2657c802010-10-06 22:50:29 -07002428 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302429iospace_error_exit:
2430 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002431}
2432
2433/***
2434 * qla4xxx_iospace_config - maps registers
2435 * @ha: pointer to adapter structure
2436 *
2437 * This routines maps HBA's registers from the pci address space
2438 * into the kernel virtual address space for memory mapped i/o.
2439 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302440int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002441{
2442 unsigned long pio, pio_len, pio_flags;
2443 unsigned long mmio, mmio_len, mmio_flags;
2444
2445 pio = pci_resource_start(ha->pdev, 0);
2446 pio_len = pci_resource_len(ha->pdev, 0);
2447 pio_flags = pci_resource_flags(ha->pdev, 0);
2448 if (pio_flags & IORESOURCE_IO) {
2449 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302450 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002451 "Invalid PCI I/O region size\n");
2452 pio = 0;
2453 }
2454 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302455 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002456 pio = 0;
2457 }
2458
2459 /* Use MMIO operations for all accesses. */
2460 mmio = pci_resource_start(ha->pdev, 1);
2461 mmio_len = pci_resource_len(ha->pdev, 1);
2462 mmio_flags = pci_resource_flags(ha->pdev, 1);
2463
2464 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302465 ql4_printk(KERN_ERR, ha,
2466 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002467
2468 goto iospace_error_exit;
2469 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302470
David Somayajuluafaf5a22006-09-19 10:28:00 -07002471 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302472 ql4_printk(KERN_ERR, ha,
2473 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002474 goto iospace_error_exit;
2475 }
2476
2477 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302478 ql4_printk(KERN_WARNING, ha,
2479 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002480
2481 goto iospace_error_exit;
2482 }
2483
2484 ha->pio_address = pio;
2485 ha->pio_length = pio_len;
2486 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
2487 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302488 ql4_printk(KERN_ERR, ha,
2489 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002490
2491 goto iospace_error_exit;
2492 }
2493
2494 return 0;
2495
2496iospace_error_exit:
2497 return -ENOMEM;
2498}
2499
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302500static struct isp_operations qla4xxx_isp_ops = {
2501 .iospace_config = qla4xxx_iospace_config,
2502 .pci_config = qla4xxx_pci_config,
2503 .disable_intrs = qla4xxx_disable_intrs,
2504 .enable_intrs = qla4xxx_enable_intrs,
2505 .start_firmware = qla4xxx_start_firmware,
2506 .intr_handler = qla4xxx_intr_handler,
2507 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
2508 .reset_chip = qla4xxx_soft_reset,
2509 .reset_firmware = qla4xxx_hw_reset,
2510 .queue_iocb = qla4xxx_queue_iocb,
2511 .complete_iocb = qla4xxx_complete_iocb,
2512 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
2513 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
2514 .get_sys_info = qla4xxx_get_sys_info,
2515};
2516
2517static struct isp_operations qla4_8xxx_isp_ops = {
2518 .iospace_config = qla4_8xxx_iospace_config,
2519 .pci_config = qla4_8xxx_pci_config,
2520 .disable_intrs = qla4_8xxx_disable_intrs,
2521 .enable_intrs = qla4_8xxx_enable_intrs,
2522 .start_firmware = qla4_8xxx_load_risc,
2523 .intr_handler = qla4_8xxx_intr_handler,
2524 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
2525 .reset_chip = qla4_8xxx_isp_reset,
2526 .reset_firmware = qla4_8xxx_stop_firmware,
2527 .queue_iocb = qla4_8xxx_queue_iocb,
2528 .complete_iocb = qla4_8xxx_complete_iocb,
2529 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
2530 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
2531 .get_sys_info = qla4_8xxx_get_sys_info,
2532};
2533
2534uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2535{
2536 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
2537}
2538
2539uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
2540{
2541 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
2542}
2543
2544uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2545{
2546 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
2547}
2548
2549uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
2550{
2551 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
2552}
2553
David Somayajuluafaf5a22006-09-19 10:28:00 -07002554/**
2555 * qla4xxx_probe_adapter - callback function to probe HBA
2556 * @pdev: pointer to pci_dev structure
2557 * @pci_device_id: pointer to pci_device entry
2558 *
2559 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
2560 * It returns zero if successful. It also initializes all data necessary for
2561 * the driver.
2562 **/
2563static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
2564 const struct pci_device_id *ent)
2565{
2566 int ret = -ENODEV, status;
2567 struct Scsi_Host *host;
2568 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002569 uint8_t init_retry_count = 0;
2570 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302571 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002572 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002573
2574 if (pci_enable_device(pdev))
2575 return -1;
2576
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002577 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002578 if (host == NULL) {
2579 printk(KERN_WARNING
2580 "qla4xxx: Couldn't allocate host from scsi layer!\n");
2581 goto probe_disable_device;
2582 }
2583
2584 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002585 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002586 memset(ha, 0, sizeof(*ha));
2587
2588 /* Save the information from PCI BIOS. */
2589 ha->pdev = pdev;
2590 ha->host = host;
2591 ha->host_no = host->host_no;
2592
Lalit Chandivade2232be02010-07-30 14:38:47 +05302593 pci_enable_pcie_error_reporting(pdev);
2594
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302595 /* Setup Runtime configurable options */
2596 if (is_qla8022(ha)) {
2597 ha->isp_ops = &qla4_8xxx_isp_ops;
2598 rwlock_init(&ha->hw_lock);
2599 ha->qdr_sn_window = -1;
2600 ha->ddr_mn_window = -1;
2601 ha->curr_window = 255;
2602 ha->func_num = PCI_FUNC(ha->pdev->devfn);
2603 nx_legacy_intr = &legacy_intr[ha->func_num];
2604 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
2605 ha->nx_legacy_intr.tgt_status_reg =
2606 nx_legacy_intr->tgt_status_reg;
2607 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
2608 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
2609 } else {
2610 ha->isp_ops = &qla4xxx_isp_ops;
2611 }
2612
Lalit Chandivade2232be02010-07-30 14:38:47 +05302613 /* Set EEH reset type to fundamental if required by hba */
2614 if (is_qla8022(ha))
2615 pdev->needs_freset = 1;
2616
David Somayajuluafaf5a22006-09-19 10:28:00 -07002617 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302618 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002619 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302620 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002621
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302622 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07002623 pdev->device, pdev->irq, ha->reg);
2624
2625 qla4xxx_config_dma_addressing(ha);
2626
2627 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07002628 INIT_LIST_HEAD(&ha->free_srb_q);
2629
2630 mutex_init(&ha->mbox_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302631 init_completion(&ha->mbx_intr_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002632
2633 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002634
2635 /* Allocate dma buffers */
2636 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302637 ql4_printk(KERN_WARNING, ha,
2638 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002639
2640 ret = -ENOMEM;
2641 goto probe_failed;
2642 }
2643
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002644 host->cmd_per_lun = 3;
2645 host->max_channel = 0;
2646 host->max_lun = MAX_LUNS - 1;
2647 host->max_id = MAX_TARGETS;
2648 host->max_cmd_len = IOCB_MAX_CDB_LEN;
2649 host->can_queue = MAX_SRBS ;
2650 host->transportt = qla4xxx_scsi_transport;
2651
2652 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
2653 if (ret) {
2654 ql4_printk(KERN_WARNING, ha,
2655 "%s: scsi_init_shared_tag_map failed\n", __func__);
2656 goto probe_failed;
2657 }
2658
2659 pci_set_drvdata(pdev, ha);
2660
2661 ret = scsi_add_host(host, &pdev->dev);
2662 if (ret)
2663 goto probe_failed;
2664
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302665 if (is_qla8022(ha))
2666 (void) qla4_8xxx_get_flash_info(ha);
2667
David Somayajuluafaf5a22006-09-19 10:28:00 -07002668 /*
2669 * Initialize the Host adapter request/response queues and
2670 * firmware
2671 * NOTE: interrupts enabled upon successful completion
2672 */
Manish Rangankar0e7e8502011-07-25 13:48:54 -05002673 status = qla4xxx_initialize_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302674 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
2675 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07002676
2677 if (is_qla8022(ha)) {
2678 qla4_8xxx_idc_lock(ha);
2679 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2680 qla4_8xxx_idc_unlock(ha);
2681 if (dev_state == QLA82XX_DEV_FAILED) {
2682 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
2683 "initialize adapter. H/W is in failed state\n",
2684 __func__);
2685 break;
2686 }
2687 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002688 DEBUG2(printk("scsi: %s: retrying adapter initialization "
2689 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302690
2691 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
2692 continue;
2693
Manish Rangankar0e7e8502011-07-25 13:48:54 -05002694 status = qla4xxx_initialize_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002695 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302696
2697 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302698 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002699
Lalit Chandivadefe998522010-12-02 22:12:36 -08002700 if (is_qla8022(ha) && ql4xdontresethba) {
2701 /* Put the device in failed state. */
2702 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
2703 qla4_8xxx_idc_lock(ha);
2704 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2705 QLA82XX_DEV_FAILED);
2706 qla4_8xxx_idc_unlock(ha);
2707 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002708 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002709 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002710 }
2711
David Somayajuluafaf5a22006-09-19 10:28:00 -07002712 /* Startup the kernel thread for this host adapter. */
2713 DEBUG2(printk("scsi: %s: Starting kernel thread for "
2714 "qla4xxx_dpc\n", __func__));
2715 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
2716 ha->dpc_thread = create_singlethread_workqueue(buf);
2717 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05302718 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07002719 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002720 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002721 }
David Howellsc4028952006-11-22 14:57:56 +00002722 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002723
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002724 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
2725 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
2726 if (!ha->task_wq) {
2727 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
2728 ret = -ENODEV;
2729 goto remove_host;
2730 }
2731
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302732 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
2733 * (which is called indirectly by qla4xxx_initialize_adapter),
2734 * so that irqs will be registered after crbinit but before
2735 * mbx_intr_enable.
2736 */
2737 if (!is_qla8022(ha)) {
2738 ret = qla4xxx_request_irqs(ha);
2739 if (ret) {
2740 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
2741 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002742 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302743 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002744 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002745
Lalit Chandivade2232be02010-07-30 14:38:47 +05302746 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302747 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002748
2749 /* Start timer thread. */
2750 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
2751
2752 set_bit(AF_INIT_DONE, &ha->flags);
2753
David Somayajuluafaf5a22006-09-19 10:28:00 -07002754 printk(KERN_INFO
2755 " QLogic iSCSI HBA Driver version: %s\n"
2756 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
2757 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
2758 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
2759 ha->patch_number, ha->build_number);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002760
2761 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002762 return 0;
2763
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002764remove_host:
2765 scsi_remove_host(ha->host);
2766
David Somayajuluafaf5a22006-09-19 10:28:00 -07002767probe_failed:
2768 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302769
2770probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05302771 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002772 scsi_host_put(ha->host);
2773
2774probe_disable_device:
2775 pci_disable_device(pdev);
2776
2777 return ret;
2778}
2779
2780/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07002781 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
2782 * @ha: pointer to adapter structure
2783 *
2784 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
2785 * so that the other port will not re-initialize while in the process of
2786 * removing the ha due to driver unload or hba hotplug.
2787 **/
2788static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
2789{
2790 struct scsi_qla_host *other_ha = NULL;
2791 struct pci_dev *other_pdev = NULL;
2792 int fn = ISP4XXX_PCI_FN_2;
2793
2794 /*iscsi function numbers for ISP4xxx is 1 and 3*/
2795 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
2796 fn = ISP4XXX_PCI_FN_1;
2797
2798 other_pdev =
2799 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
2800 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
2801 fn));
2802
2803 /* Get other_ha if other_pdev is valid and state is enable*/
2804 if (other_pdev) {
2805 if (atomic_read(&other_pdev->enable_cnt)) {
2806 other_ha = pci_get_drvdata(other_pdev);
2807 if (other_ha) {
2808 set_bit(AF_HA_REMOVAL, &other_ha->flags);
2809 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
2810 "Prevent %s reinit\n", __func__,
2811 dev_name(&other_ha->pdev->dev)));
2812 }
2813 }
2814 pci_dev_put(other_pdev);
2815 }
2816}
2817
2818/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002819 * qla4xxx_remove_adapter - calback function to remove adapter.
2820 * @pci_dev: PCI device pointer
2821 **/
2822static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
2823{
2824 struct scsi_qla_host *ha;
2825
2826 ha = pci_get_drvdata(pdev);
2827
Karen Higgins7eece5a2011-03-21 03:34:29 -07002828 if (!is_qla8022(ha))
2829 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07002830
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05002831 /* destroy iface from sysfs */
2832 qla4xxx_destroy_ifaces(ha);
2833
David Somayajuluafaf5a22006-09-19 10:28:00 -07002834 scsi_remove_host(ha->host);
2835
2836 qla4xxx_free_adapter(ha);
2837
2838 scsi_host_put(ha->host);
2839
Lalit Chandivade2232be02010-07-30 14:38:47 +05302840 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302841 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002842 pci_set_drvdata(pdev, NULL);
2843}
2844
2845/**
2846 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
2847 * @ha: HA context
2848 *
2849 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
2850 * supported addressing method.
2851 */
Adrian Bunk47975472007-04-26 00:35:16 -07002852static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002853{
2854 int retval;
2855
2856 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07002857 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
2858 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002859 dev_dbg(&ha->pdev->dev,
2860 "Failed to set 64 bit PCI consistent mask; "
2861 "using 32 bit.\n");
2862 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07002863 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002864 }
2865 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07002866 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002867}
2868
2869static int qla4xxx_slave_alloc(struct scsi_device *sdev)
2870{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002871 struct iscsi_cls_session *cls_sess;
2872 struct iscsi_session *sess;
2873 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002874 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002875
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002876 cls_sess = starget_to_session(sdev->sdev_target);
2877 sess = cls_sess->dd_data;
2878 ddb = sess->dd_data;
2879
David Somayajuluafaf5a22006-09-19 10:28:00 -07002880 sdev->hostdata = ddb;
2881 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07002882
2883 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
2884 queue_depth = ql4xmaxqdepth;
2885
2886 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002887 return 0;
2888}
2889
2890static int qla4xxx_slave_configure(struct scsi_device *sdev)
2891{
2892 sdev->tagged_supported = 1;
2893 return 0;
2894}
2895
2896static void qla4xxx_slave_destroy(struct scsi_device *sdev)
2897{
2898 scsi_deactivate_tcq(sdev, 1);
2899}
2900
2901/**
2902 * qla4xxx_del_from_active_array - returns an active srb
2903 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002904 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07002905 *
2906 * This routine removes and returns the srb at the specified index
2907 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302908struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
2909 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002910{
2911 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05302912 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002913
Vikas Chaudhary53698872010-04-28 11:41:59 +05302914 cmd = scsi_host_find_tag(ha->host, index);
2915 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002916 return srb;
2917
Vikas Chaudhary53698872010-04-28 11:41:59 +05302918 srb = (struct srb *)CMD_SP(cmd);
2919 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002920 return srb;
2921
2922 /* update counters */
2923 if (srb->flags & SRB_DMA_VALID) {
2924 ha->req_q_count += srb->iocb_cnt;
2925 ha->iocb_cnt -= srb->iocb_cnt;
2926 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05302927 srb->cmd->host_scribble =
2928 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002929 }
2930 return srb;
2931}
2932
2933/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002934 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302935 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002936 * @cmd: Scsi Command to wait on.
2937 *
2938 * This routine waits for the command to be returned by the Firmware
2939 * for some max time.
2940 **/
2941static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
2942 struct scsi_cmnd *cmd)
2943{
2944 int done = 0;
2945 struct srb *rp;
2946 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302947 int ret = SUCCESS;
2948
2949 /* Dont wait on command if PCI error is being handled
2950 * by PCI AER driver
2951 */
2952 if (unlikely(pci_channel_offline(ha->pdev)) ||
2953 (test_bit(AF_EEH_BUSY, &ha->flags))) {
2954 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
2955 ha->host_no, __func__);
2956 return ret;
2957 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002958
2959 do {
2960 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05302961 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002962 if (rp == NULL) {
2963 done++;
2964 break;
2965 }
2966
2967 msleep(2000);
2968 } while (max_wait_time--);
2969
2970 return done;
2971}
2972
2973/**
2974 * qla4xxx_wait_for_hba_online - waits for HBA to come online
2975 * @ha: Pointer to host adapter structure
2976 **/
2977static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
2978{
2979 unsigned long wait_online;
2980
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07002981 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002982 while (time_before(jiffies, wait_online)) {
2983
2984 if (adapter_up(ha))
2985 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002986
2987 msleep(2000);
2988 }
2989
2990 return QLA_ERROR;
2991}
2992
2993/**
Mike Christiece545032008-02-29 18:25:20 -06002994 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02002995 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07002996 * @t: target id
2997 * @l: lun id
2998 *
2999 * This function waits for all outstanding commands to a lun to complete. It
3000 * returns 0 if all pending commands are returned and 1 otherwise.
3001 **/
Mike Christiece545032008-02-29 18:25:20 -06003002static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
3003 struct scsi_target *stgt,
3004 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003005{
3006 int cnt;
3007 int status = 0;
3008 struct scsi_cmnd *cmd;
3009
3010 /*
Mike Christiece545032008-02-29 18:25:20 -06003011 * Waiting for all commands for the designated target or dev
3012 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07003013 */
3014 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
3015 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06003016 if (cmd && stgt == scsi_target(cmd->device) &&
3017 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003018 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3019 status++;
3020 break;
3021 }
3022 }
3023 }
3024 return status;
3025}
3026
3027/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303028 * qla4xxx_eh_abort - callback for abort task.
3029 * @cmd: Pointer to Linux's SCSI command structure
3030 *
3031 * This routine is called by the Linux OS to abort the specified
3032 * command.
3033 **/
3034static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
3035{
3036 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3037 unsigned int id = cmd->device->id;
3038 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07003039 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303040 struct srb *srb = NULL;
3041 int ret = SUCCESS;
3042 int wait = 0;
3043
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303044 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04003045 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
3046 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303047
Mike Christie92b3e5b2010-10-06 22:51:17 -07003048 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303049 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07003050 if (!srb) {
3051 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303052 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07003053 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303054 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07003055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303056
3057 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
3058 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
3059 ha->host_no, id, lun));
3060 ret = FAILED;
3061 } else {
3062 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
3063 ha->host_no, id, lun));
3064 wait = 1;
3065 }
3066
3067 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
3068
3069 /* Wait for command to complete */
3070 if (wait) {
3071 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
3072 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
3073 ha->host_no, id, lun));
3074 ret = FAILED;
3075 }
3076 }
3077
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303078 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303079 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003080 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05303081
3082 return ret;
3083}
3084
3085/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07003086 * qla4xxx_eh_device_reset - callback for target reset.
3087 * @cmd: Pointer to Linux's SCSI command structure
3088 *
3089 * This routine is called by the Linux OS to reset all luns on the
3090 * specified target.
3091 **/
3092static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
3093{
3094 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3095 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003096 int ret = FAILED, stat;
3097
Karen Higgins612f7342009-07-15 15:03:01 -05003098 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003099 return ret;
3100
Mike Christiec01be6d2010-07-22 16:59:49 +05303101 ret = iscsi_block_scsi_eh(cmd);
3102 if (ret)
3103 return ret;
3104 ret = FAILED;
3105
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303106 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003107 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
3108 cmd->device->channel, cmd->device->id, cmd->device->lun);
3109
3110 DEBUG2(printk(KERN_INFO
3111 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
3112 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07003113 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003114 ha->dpc_flags, cmd->result, cmd->allowed));
3115
3116 /* FIXME: wait for hba to go online */
3117 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
3118 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303119 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003120 goto eh_dev_reset_done;
3121 }
3122
Mike Christiece545032008-02-29 18:25:20 -06003123 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3124 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303125 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06003126 "DEVICE RESET FAILED - waiting for "
3127 "commands.\n");
3128 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003129 }
3130
David C Somayajulu9d562912008-03-19 11:23:03 -07003131 /* Send marker. */
3132 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3133 MM_LUN_RESET) != QLA_SUCCESS)
3134 goto eh_dev_reset_done;
3135
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303136 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003137 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
3138 ha->host_no, cmd->device->channel, cmd->device->id,
3139 cmd->device->lun);
3140
3141 ret = SUCCESS;
3142
3143eh_dev_reset_done:
3144
3145 return ret;
3146}
3147
3148/**
Mike Christiece545032008-02-29 18:25:20 -06003149 * qla4xxx_eh_target_reset - callback for target reset.
3150 * @cmd: Pointer to Linux's SCSI command structure
3151 *
3152 * This routine is called by the Linux OS to reset the target.
3153 **/
3154static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
3155{
3156 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
3157 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05303158 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06003159
3160 if (!ddb_entry)
3161 return FAILED;
3162
Mike Christiec01be6d2010-07-22 16:59:49 +05303163 ret = iscsi_block_scsi_eh(cmd);
3164 if (ret)
3165 return ret;
3166
Mike Christiece545032008-02-29 18:25:20 -06003167 starget_printk(KERN_INFO, scsi_target(cmd->device),
3168 "WARM TARGET RESET ISSUED.\n");
3169
3170 DEBUG2(printk(KERN_INFO
3171 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
3172 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07003173 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06003174 ha->dpc_flags, cmd->result, cmd->allowed));
3175
3176 stat = qla4xxx_reset_target(ha, ddb_entry);
3177 if (stat != QLA_SUCCESS) {
3178 starget_printk(KERN_INFO, scsi_target(cmd->device),
3179 "WARM TARGET RESET FAILED.\n");
3180 return FAILED;
3181 }
3182
Mike Christiece545032008-02-29 18:25:20 -06003183 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
3184 NULL)) {
3185 starget_printk(KERN_INFO, scsi_target(cmd->device),
3186 "WARM TARGET DEVICE RESET FAILED - "
3187 "waiting for commands.\n");
3188 return FAILED;
3189 }
3190
David C Somayajulu9d562912008-03-19 11:23:03 -07003191 /* Send marker. */
3192 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
3193 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
3194 starget_printk(KERN_INFO, scsi_target(cmd->device),
3195 "WARM TARGET DEVICE RESET FAILED - "
3196 "marker iocb failed.\n");
3197 return FAILED;
3198 }
3199
Mike Christiece545032008-02-29 18:25:20 -06003200 starget_printk(KERN_INFO, scsi_target(cmd->device),
3201 "WARM TARGET RESET SUCCEEDED.\n");
3202 return SUCCESS;
3203}
3204
3205/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07003206 * qla4xxx_eh_host_reset - kernel callback
3207 * @cmd: Pointer to Linux's SCSI command structure
3208 *
3209 * This routine is invoked by the Linux kernel to perform fatal error
3210 * recovery on the specified adapter.
3211 **/
3212static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
3213{
3214 int return_status = FAILED;
3215 struct scsi_qla_host *ha;
3216
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003217 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003218
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303219 if (ql4xdontresethba) {
3220 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
3221 ha->host_no, __func__));
3222 return FAILED;
3223 }
3224
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303225 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05003226 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003227 cmd->device->channel, cmd->device->id, cmd->device->lun);
3228
3229 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
3230 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
3231 "DEAD.\n", ha->host_no, cmd->device->channel,
3232 __func__));
3233
3234 return FAILED;
3235 }
3236
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303237 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
3238 if (is_qla8022(ha))
3239 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
3240 else
3241 set_bit(DPC_RESET_HA, &ha->dpc_flags);
3242 }
Mike Christie50a29ae2008-03-04 13:26:53 -06003243
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303244 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003245 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003246
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303247 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003248 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003249
3250 return return_status;
3251}
3252
Lalit Chandivade2232be02010-07-30 14:38:47 +05303253/* PCI AER driver recovers from all correctable errors w/o
3254 * driver intervention. For uncorrectable errors PCI AER
3255 * driver calls the following device driver's callbacks
3256 *
3257 * - Fatal Errors - link_reset
3258 * - Non-Fatal Errors - driver's pci_error_detected() which
3259 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
3260 *
3261 * PCI AER driver calls
3262 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
3263 * returns RECOVERED or NEED_RESET if fw_hung
3264 * NEED_RESET - driver's slot_reset()
3265 * DISCONNECT - device is dead & cannot recover
3266 * RECOVERED - driver's pci_resume()
3267 */
3268static pci_ers_result_t
3269qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3270{
3271 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3272
3273 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
3274 ha->host_no, __func__, state);
3275
3276 if (!is_aer_supported(ha))
3277 return PCI_ERS_RESULT_NONE;
3278
3279 switch (state) {
3280 case pci_channel_io_normal:
3281 clear_bit(AF_EEH_BUSY, &ha->flags);
3282 return PCI_ERS_RESULT_CAN_RECOVER;
3283 case pci_channel_io_frozen:
3284 set_bit(AF_EEH_BUSY, &ha->flags);
3285 qla4xxx_mailbox_premature_completion(ha);
3286 qla4xxx_free_irqs(ha);
3287 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003288 /* Return back all IOs */
3289 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303290 return PCI_ERS_RESULT_NEED_RESET;
3291 case pci_channel_io_perm_failure:
3292 set_bit(AF_EEH_BUSY, &ha->flags);
3293 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
3294 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
3295 return PCI_ERS_RESULT_DISCONNECT;
3296 }
3297 return PCI_ERS_RESULT_NEED_RESET;
3298}
3299
3300/**
3301 * qla4xxx_pci_mmio_enabled() gets called if
3302 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
3303 * and read/write to the device still works.
3304 **/
3305static pci_ers_result_t
3306qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
3307{
3308 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3309
3310 if (!is_aer_supported(ha))
3311 return PCI_ERS_RESULT_NONE;
3312
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003313 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05303314}
3315
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003316static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05303317{
3318 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003319 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05303320 int fn;
3321 struct pci_dev *other_pdev = NULL;
3322
3323 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
3324
3325 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3326
3327 if (test_bit(AF_ONLINE, &ha->flags)) {
3328 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05003329 clear_bit(AF_LINK_UP, &ha->flags);
3330 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303331 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303332 }
3333
3334 fn = PCI_FUNC(ha->pdev->devfn);
3335 while (fn > 0) {
3336 fn--;
3337 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
3338 "func %x\n", ha->host_no, __func__, fn);
3339 /* Get the pci device given the domain, bus,
3340 * slot/function number */
3341 other_pdev =
3342 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
3343 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
3344 fn));
3345
3346 if (!other_pdev)
3347 continue;
3348
3349 if (atomic_read(&other_pdev->enable_cnt)) {
3350 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
3351 "func in enabled state%x\n", ha->host_no,
3352 __func__, fn);
3353 pci_dev_put(other_pdev);
3354 break;
3355 }
3356 pci_dev_put(other_pdev);
3357 }
3358
3359 /* The first function on the card, the reset owner will
3360 * start & initialize the firmware. The other functions
3361 * on the card will reset the firmware context
3362 */
3363 if (!fn) {
3364 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
3365 "0x%x is the owner\n", ha->host_no, __func__,
3366 ha->pdev->devfn);
3367
3368 qla4_8xxx_idc_lock(ha);
3369 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3370 QLA82XX_DEV_COLD);
3371
3372 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
3373 QLA82XX_IDC_VERSION);
3374
3375 qla4_8xxx_idc_unlock(ha);
3376 clear_bit(AF_FW_RECOVERY, &ha->flags);
Manish Rangankar0e7e8502011-07-25 13:48:54 -05003377 rval = qla4xxx_initialize_adapter(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303378 qla4_8xxx_idc_lock(ha);
3379
3380 if (rval != QLA_SUCCESS) {
3381 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3382 "FAILED\n", ha->host_no, __func__);
3383 qla4_8xxx_clear_drv_active(ha);
3384 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3385 QLA82XX_DEV_FAILED);
3386 } else {
3387 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
3388 "READY\n", ha->host_no, __func__);
3389 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3390 QLA82XX_DEV_READY);
3391 /* Clear driver state register */
3392 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
3393 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003394 ret = qla4xxx_request_irqs(ha);
3395 if (ret) {
3396 ql4_printk(KERN_WARNING, ha, "Failed to "
3397 "reserve interrupt %d already in use.\n",
3398 ha->pdev->irq);
3399 rval = QLA_ERROR;
3400 } else {
3401 ha->isp_ops->enable_intrs(ha);
3402 rval = QLA_SUCCESS;
3403 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05303404 }
3405 qla4_8xxx_idc_unlock(ha);
3406 } else {
3407 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
3408 "the reset owner\n", ha->host_no, __func__,
3409 ha->pdev->devfn);
3410 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
3411 QLA82XX_DEV_READY)) {
3412 clear_bit(AF_FW_RECOVERY, &ha->flags);
Manish Rangankar0e7e8502011-07-25 13:48:54 -05003413 rval = qla4xxx_initialize_adapter(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003414 if (rval == QLA_SUCCESS) {
3415 ret = qla4xxx_request_irqs(ha);
3416 if (ret) {
3417 ql4_printk(KERN_WARNING, ha, "Failed to"
3418 " reserve interrupt %d already in"
3419 " use.\n", ha->pdev->irq);
3420 rval = QLA_ERROR;
3421 } else {
3422 ha->isp_ops->enable_intrs(ha);
3423 rval = QLA_SUCCESS;
3424 }
3425 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05303426 qla4_8xxx_idc_lock(ha);
3427 qla4_8xxx_set_drv_active(ha);
3428 qla4_8xxx_idc_unlock(ha);
3429 }
3430 }
3431 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
3432 return rval;
3433}
3434
3435static pci_ers_result_t
3436qla4xxx_pci_slot_reset(struct pci_dev *pdev)
3437{
3438 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
3439 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3440 int rc;
3441
3442 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
3443 ha->host_no, __func__);
3444
3445 if (!is_aer_supported(ha))
3446 return PCI_ERS_RESULT_NONE;
3447
3448 /* Restore the saved state of PCIe device -
3449 * BAR registers, PCI Config space, PCIX, MSI,
3450 * IOV states
3451 */
3452 pci_restore_state(pdev);
3453
3454 /* pci_restore_state() clears the saved_state flag of the device
3455 * save restored state which resets saved_state flag
3456 */
3457 pci_save_state(pdev);
3458
3459 /* Initialize device or resume if in suspended state */
3460 rc = pci_enable_device(pdev);
3461 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003462 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05303463 "device after reset\n", ha->host_no, __func__);
3464 goto exit_slot_reset;
3465 }
3466
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07003467 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05303468
3469 if (is_qla8022(ha)) {
3470 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
3471 ret = PCI_ERS_RESULT_RECOVERED;
3472 goto exit_slot_reset;
3473 } else
3474 goto exit_slot_reset;
3475 }
3476
3477exit_slot_reset:
3478 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
3479 "device after reset\n", ha->host_no, __func__, ret);
3480 return ret;
3481}
3482
3483static void
3484qla4xxx_pci_resume(struct pci_dev *pdev)
3485{
3486 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
3487 int ret;
3488
3489 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
3490 ha->host_no, __func__);
3491
3492 ret = qla4xxx_wait_for_hba_online(ha);
3493 if (ret != QLA_SUCCESS) {
3494 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
3495 "resume I/O from slot/link_reset\n", ha->host_no,
3496 __func__);
3497 }
3498
3499 pci_cleanup_aer_uncorrect_error_status(pdev);
3500 clear_bit(AF_EEH_BUSY, &ha->flags);
3501}
3502
3503static struct pci_error_handlers qla4xxx_err_handler = {
3504 .error_detected = qla4xxx_pci_error_detected,
3505 .mmio_enabled = qla4xxx_pci_mmio_enabled,
3506 .slot_reset = qla4xxx_pci_slot_reset,
3507 .resume = qla4xxx_pci_resume,
3508};
3509
David Somayajuluafaf5a22006-09-19 10:28:00 -07003510static struct pci_device_id qla4xxx_pci_tbl[] = {
3511 {
3512 .vendor = PCI_VENDOR_ID_QLOGIC,
3513 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
3514 .subvendor = PCI_ANY_ID,
3515 .subdevice = PCI_ANY_ID,
3516 },
3517 {
3518 .vendor = PCI_VENDOR_ID_QLOGIC,
3519 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
3520 .subvendor = PCI_ANY_ID,
3521 .subdevice = PCI_ANY_ID,
3522 },
David C Somayajulud9150582006-11-15 17:38:40 -08003523 {
3524 .vendor = PCI_VENDOR_ID_QLOGIC,
3525 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
3526 .subvendor = PCI_ANY_ID,
3527 .subdevice = PCI_ANY_ID,
3528 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303529 {
3530 .vendor = PCI_VENDOR_ID_QLOGIC,
3531 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
3532 .subvendor = PCI_ANY_ID,
3533 .subdevice = PCI_ANY_ID,
3534 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07003535 {0, 0},
3536};
3537MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
3538
Adrian Bunk47975472007-04-26 00:35:16 -07003539static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07003540 .name = DRIVER_NAME,
3541 .id_table = qla4xxx_pci_tbl,
3542 .probe = qla4xxx_probe_adapter,
3543 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05303544 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003545};
3546
3547static int __init qla4xxx_module_init(void)
3548{
3549 int ret;
3550
3551 /* Allocate cache for SRBs. */
3552 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003553 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07003554 if (srb_cachep == NULL) {
3555 printk(KERN_ERR
3556 "%s: Unable to allocate SRB cache..."
3557 "Failing load!\n", DRIVER_NAME);
3558 ret = -ENOMEM;
3559 goto no_srp_cache;
3560 }
3561
3562 /* Derive version string. */
3563 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003564 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003565 strcat(qla4xxx_version_str, "-debug");
3566
3567 qla4xxx_scsi_transport =
3568 iscsi_register_transport(&qla4xxx_iscsi_transport);
3569 if (!qla4xxx_scsi_transport){
3570 ret = -ENODEV;
3571 goto release_srb_cache;
3572 }
3573
David Somayajuluafaf5a22006-09-19 10:28:00 -07003574 ret = pci_register_driver(&qla4xxx_pci_driver);
3575 if (ret)
3576 goto unregister_transport;
3577
3578 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
3579 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05003580
David Somayajuluafaf5a22006-09-19 10:28:00 -07003581unregister_transport:
3582 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3583release_srb_cache:
3584 kmem_cache_destroy(srb_cachep);
3585no_srp_cache:
3586 return ret;
3587}
3588
3589static void __exit qla4xxx_module_exit(void)
3590{
David Somayajuluafaf5a22006-09-19 10:28:00 -07003591 pci_unregister_driver(&qla4xxx_pci_driver);
3592 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
3593 kmem_cache_destroy(srb_cachep);
3594}
3595
3596module_init(qla4xxx_module_init);
3597module_exit(qla4xxx_module_exit);
3598
3599MODULE_AUTHOR("QLogic Corporation");
3600MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
3601MODULE_LICENSE("GPL");
3602MODULE_VERSION(QLA4XXX_DRIVER_VERSION);