blob: b75590af8ed309051579c73caaf08dc25c73b091 [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>
Manish Rangankar2a991c22011-07-25 13:48:55 -05009#include <linux/blkdev.h>
10#include <linux/iscsi_boot_sysfs.h>
Mike Christie13483732011-12-01 21:38:41 -060011#include <linux/inet.h>
David Somayajuluafaf5a22006-09-19 10:28:00 -070012
13#include <scsi/scsi_tcq.h>
14#include <scsi/scsicam.h>
15
16#include "ql4_def.h"
David C Somayajulubee4fe82007-05-23 18:03:32 -070017#include "ql4_version.h"
18#include "ql4_glbl.h"
19#include "ql4_dbg.h"
20#include "ql4_inline.h"
David Somayajuluafaf5a22006-09-19 10:28:00 -070021
22/*
23 * Driver version
24 */
Adrian Bunk47975472007-04-26 00:35:16 -070025static char qla4xxx_version_str[40];
David Somayajuluafaf5a22006-09-19 10:28:00 -070026
27/*
28 * SRB allocation cache
29 */
Christoph Lametere18b8902006-12-06 20:33:20 -080030static struct kmem_cache *srb_cachep;
David Somayajuluafaf5a22006-09-19 10:28:00 -070031
32/*
33 * Module parameter information and variables
34 */
Mike Christie13483732011-12-01 21:38:41 -060035int ql4xdisablesysfsboot = 1;
36module_param(ql4xdisablesysfsboot, int, S_IRUGO | S_IWUSR);
37MODULE_PARM_DESC(ql4xdisablesysfsboot,
38 "Set to disable exporting boot targets to sysfs\n"
39 " 0 - Export boot targets\n"
40 " 1 - Do not export boot targets (Default)");
41
David Somayajuluafaf5a22006-09-19 10:28:00 -070042int ql4xdontresethba = 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053043module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR);
David Somayajuluafaf5a22006-09-19 10:28:00 -070044MODULE_PARM_DESC(ql4xdontresethba,
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053045 "Don't reset the HBA for driver recovery \n"
46 " 0 - It will reset HBA (Default)\n"
47 " 1 - It will NOT reset HBA");
David Somayajuluafaf5a22006-09-19 10:28:00 -070048
Andrew Vasquez11010fe2006-10-06 09:54:59 -070049int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053050module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070051MODULE_PARM_DESC(ql4xextended_error_logging,
David Somayajuluafaf5a22006-09-19 10:28:00 -070052 "Option to enable extended error logging, "
53 "Default is 0 - no logging, 1 - debug logging");
54
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +053055int ql4xenablemsix = 1;
56module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR);
57MODULE_PARM_DESC(ql4xenablemsix,
58 "Set to enable MSI or MSI-X interrupt mechanism.\n"
59 " 0 = enable INTx interrupt mechanism.\n"
60 " 1 = enable MSI-X interrupt mechanism (Default).\n"
61 " 2 = enable MSI interrupt mechanism.");
David C Somayajulu477ffb92007-01-22 12:26:11 -080062
Mike Christied510d962008-07-11 19:50:33 -050063#define QL4_DEF_QDEPTH 32
Vikas Chaudhary8bb40332011-03-21 03:34:31 -070064static int ql4xmaxqdepth = QL4_DEF_QDEPTH;
65module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR);
66MODULE_PARM_DESC(ql4xmaxqdepth,
67 "Maximum queue depth to report for target devices.\n"
68 " Default: 32.");
Mike Christied510d962008-07-11 19:50:33 -050069
Vikas Chaudhary30387272011-03-21 03:34:32 -070070static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO;
71module_param(ql4xsess_recovery_tmo, int, S_IRUGO);
72MODULE_PARM_DESC(ql4xsess_recovery_tmo,
73 "Target Session Recovery Timeout.\n"
Mike Christie13483732011-12-01 21:38:41 -060074 " Default: 120 sec.");
Vikas Chaudhary30387272011-03-21 03:34:32 -070075
Manish Rangankarb3a271a2011-07-25 13:48:53 -050076static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070077/*
78 * SCSI host template entry points
79 */
Adrian Bunk47975472007-04-26 00:35:16 -070080static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -070081
82/*
83 * iSCSI template entry points
84 */
David Somayajuluafaf5a22006-09-19 10:28:00 -070085static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn,
86 enum iscsi_param param, char *buf);
Mike Christieaa1e93a2007-05-30 12:57:09 -050087static int qla4xxx_host_get_param(struct Scsi_Host *shost,
88 enum iscsi_host_param param, char *buf);
Mike Christie00c31882011-10-06 03:56:59 -050089static int qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data,
90 uint32_t len);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -050091static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
92 enum iscsi_param_type param_type,
93 int param, char *buf);
Mike Christie5c656af2009-07-15 15:02:59 -050094static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc);
Manish Rangankarb3a271a2011-07-25 13:48:53 -050095static struct iscsi_endpoint *qla4xxx_ep_connect(struct Scsi_Host *shost,
96 struct sockaddr *dst_addr,
97 int non_blocking);
98static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms);
99static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep);
100static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
101 enum iscsi_param param, char *buf);
102static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
103static struct iscsi_cls_conn *
104qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx);
105static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
106 struct iscsi_cls_conn *cls_conn,
107 uint64_t transport_fd, int is_leading);
108static void qla4xxx_conn_destroy(struct iscsi_cls_conn *conn);
109static struct iscsi_cls_session *
110qla4xxx_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,
111 uint16_t qdepth, uint32_t initial_cmdsn);
112static void qla4xxx_session_destroy(struct iscsi_cls_session *sess);
113static void qla4xxx_task_work(struct work_struct *wdata);
114static int qla4xxx_alloc_pdu(struct iscsi_task *, uint8_t);
115static int qla4xxx_task_xmit(struct iscsi_task *);
116static void qla4xxx_task_cleanup(struct iscsi_task *);
117static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session);
118static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
119 struct iscsi_stats *stats);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700120/*
121 * SCSI host template entry points
122 */
Jeff Garzikf2812332010-11-16 02:10:29 -0500123static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530124static int qla4xxx_eh_abort(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700125static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
Mike Christiece545032008-02-29 18:25:20 -0600126static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700127static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
128static int qla4xxx_slave_alloc(struct scsi_device *device);
129static int qla4xxx_slave_configure(struct scsi_device *device);
130static void qla4xxx_slave_destroy(struct scsi_device *sdev);
Al Viro587a1f12011-07-23 23:11:19 -0400131static umode_t ql4_attr_is_visible(int param_type, int param);
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700132static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700133
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +0530134static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
135 QLA82XX_LEGACY_INTR_CONFIG;
136
David Somayajuluafaf5a22006-09-19 10:28:00 -0700137static struct scsi_host_template qla4xxx_driver_template = {
138 .module = THIS_MODULE,
139 .name = DRIVER_NAME,
140 .proc_name = DRIVER_NAME,
141 .queuecommand = qla4xxx_queuecommand,
142
Vikas Chaudhary09a0f712010-04-28 11:42:24 +0530143 .eh_abort_handler = qla4xxx_eh_abort,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700144 .eh_device_reset_handler = qla4xxx_eh_device_reset,
Mike Christiece545032008-02-29 18:25:20 -0600145 .eh_target_reset_handler = qla4xxx_eh_target_reset,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700146 .eh_host_reset_handler = qla4xxx_eh_host_reset,
Mike Christie5c656af2009-07-15 15:02:59 -0500147 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700148
149 .slave_configure = qla4xxx_slave_configure,
150 .slave_alloc = qla4xxx_slave_alloc,
151 .slave_destroy = qla4xxx_slave_destroy,
152
153 .this_id = -1,
154 .cmd_per_lun = 3,
155 .use_clustering = ENABLE_CLUSTERING,
156 .sg_tablesize = SG_ALL,
157
158 .max_sectors = 0xFFFF,
Harish Zunjarrao7ad633c2011-05-17 23:17:11 -0700159 .shost_attrs = qla4xxx_host_attrs,
Vikas Chaudhary95d31262011-08-12 02:51:29 -0700160 .host_reset = qla4xxx_host_reset,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500161 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700162};
163
164static struct iscsi_transport qla4xxx_iscsi_transport = {
165 .owner = THIS_MODULE,
166 .name = DRIVER_NAME,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500167 .caps = CAP_TEXT_NEGO |
168 CAP_DATA_PATH_OFFLOAD | CAP_HDRDGST |
169 CAP_DATADGST | CAP_LOGIN_OFFLOAD |
170 CAP_MULTI_R2T,
Mike Christie3128c6c2011-07-25 13:48:42 -0500171 .attr_is_visible = ql4_attr_is_visible,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500172 .create_session = qla4xxx_session_create,
173 .destroy_session = qla4xxx_session_destroy,
174 .start_conn = qla4xxx_conn_start,
175 .create_conn = qla4xxx_conn_create,
176 .bind_conn = qla4xxx_conn_bind,
177 .stop_conn = iscsi_conn_stop,
178 .destroy_conn = qla4xxx_conn_destroy,
179 .set_param = iscsi_set_param,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700180 .get_conn_param = qla4xxx_conn_get_param,
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500181 .get_session_param = iscsi_session_get_param,
182 .get_ep_param = qla4xxx_get_ep_param,
183 .ep_connect = qla4xxx_ep_connect,
184 .ep_poll = qla4xxx_ep_poll,
185 .ep_disconnect = qla4xxx_ep_disconnect,
186 .get_stats = qla4xxx_conn_get_stats,
187 .send_pdu = iscsi_conn_send_pdu,
188 .xmit_task = qla4xxx_task_xmit,
189 .cleanup_task = qla4xxx_task_cleanup,
190 .alloc_pdu = qla4xxx_alloc_pdu,
191
Mike Christieaa1e93a2007-05-30 12:57:09 -0500192 .get_host_param = qla4xxx_host_get_param,
Mike Christied00efe32011-07-25 13:48:38 -0500193 .set_iface_param = qla4xxx_iface_set_param,
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500194 .get_iface_param = qla4xxx_get_iface_param,
Vikas Chaudharya3559432011-07-25 13:48:51 -0500195 .bsg_request = qla4xxx_bsg_request,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700196};
197
198static struct scsi_transport_template *qla4xxx_scsi_transport;
199
Al Viro587a1f12011-07-23 23:11:19 -0400200static umode_t ql4_attr_is_visible(int param_type, int param)
Mike Christie3128c6c2011-07-25 13:48:42 -0500201{
202 switch (param_type) {
Mike Christief27fb2e2011-07-25 13:48:45 -0500203 case ISCSI_HOST_PARAM:
204 switch (param) {
205 case ISCSI_HOST_PARAM_HWADDRESS:
206 case ISCSI_HOST_PARAM_IPADDRESS:
207 case ISCSI_HOST_PARAM_INITIATOR_NAME:
208 return S_IRUGO;
209 default:
210 return 0;
211 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500212 case ISCSI_PARAM:
213 switch (param) {
Mike Christie590134f2011-10-17 22:42:13 -0500214 case ISCSI_PARAM_PERSISTENT_ADDRESS:
215 case ISCSI_PARAM_PERSISTENT_PORT:
Mike Christie3128c6c2011-07-25 13:48:42 -0500216 case ISCSI_PARAM_CONN_ADDRESS:
217 case ISCSI_PARAM_CONN_PORT:
Mike Christie1d063c12011-07-25 13:48:43 -0500218 case ISCSI_PARAM_TARGET_NAME:
219 case ISCSI_PARAM_TPGT:
220 case ISCSI_PARAM_TARGET_ALIAS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500221 case ISCSI_PARAM_MAX_BURST:
222 case ISCSI_PARAM_MAX_R2T:
223 case ISCSI_PARAM_FIRST_BURST:
224 case ISCSI_PARAM_MAX_RECV_DLENGTH:
225 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
Mike Christiede379202011-08-14 20:42:56 -0500226 case ISCSI_PARAM_IFACE_NAME:
Mike Christie3128c6c2011-07-25 13:48:42 -0500227 return S_IRUGO;
228 default:
229 return 0;
230 }
Mike Christieb78dbba2011-07-25 13:48:44 -0500231 case ISCSI_NET_PARAM:
232 switch (param) {
233 case ISCSI_NET_PARAM_IPV4_ADDR:
234 case ISCSI_NET_PARAM_IPV4_SUBNET:
235 case ISCSI_NET_PARAM_IPV4_GW:
236 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
237 case ISCSI_NET_PARAM_IFACE_ENABLE:
238 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
239 case ISCSI_NET_PARAM_IPV6_ADDR:
240 case ISCSI_NET_PARAM_IPV6_ROUTER:
241 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
242 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500243 case ISCSI_NET_PARAM_VLAN_ID:
244 case ISCSI_NET_PARAM_VLAN_PRIORITY:
245 case ISCSI_NET_PARAM_VLAN_ENABLED:
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700246 case ISCSI_NET_PARAM_MTU:
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700247 case ISCSI_NET_PARAM_PORT:
Mike Christieb78dbba2011-07-25 13:48:44 -0500248 return S_IRUGO;
249 default:
250 return 0;
251 }
Mike Christie3128c6c2011-07-25 13:48:42 -0500252 }
253
254 return 0;
255}
256
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500257static int qla4xxx_get_iface_param(struct iscsi_iface *iface,
258 enum iscsi_param_type param_type,
259 int param, char *buf)
260{
261 struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
262 struct scsi_qla_host *ha = to_qla_host(shost);
263 int len = -ENOSYS;
264
265 if (param_type != ISCSI_NET_PARAM)
266 return -ENOSYS;
267
268 switch (param) {
269 case ISCSI_NET_PARAM_IPV4_ADDR:
270 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
271 break;
272 case ISCSI_NET_PARAM_IPV4_SUBNET:
273 len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask);
274 break;
275 case ISCSI_NET_PARAM_IPV4_GW:
276 len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway);
277 break;
278 case ISCSI_NET_PARAM_IFACE_ENABLE:
279 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
280 len = sprintf(buf, "%s\n",
281 (ha->ip_config.ipv4_options &
282 IPOPT_IPV4_PROTOCOL_ENABLE) ?
283 "enabled" : "disabled");
284 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
285 len = sprintf(buf, "%s\n",
286 (ha->ip_config.ipv6_options &
287 IPV6_OPT_IPV6_PROTOCOL_ENABLE) ?
288 "enabled" : "disabled");
289 break;
290 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
291 len = sprintf(buf, "%s\n",
292 (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ?
293 "dhcp" : "static");
294 break;
295 case ISCSI_NET_PARAM_IPV6_ADDR:
296 if (iface->iface_num == 0)
297 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0);
298 if (iface->iface_num == 1)
299 len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1);
300 break;
301 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
302 len = sprintf(buf, "%pI6\n",
303 &ha->ip_config.ipv6_link_local_addr);
304 break;
305 case ISCSI_NET_PARAM_IPV6_ROUTER:
306 len = sprintf(buf, "%pI6\n",
307 &ha->ip_config.ipv6_default_router_addr);
308 break;
309 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
310 len = sprintf(buf, "%s\n",
311 (ha->ip_config.ipv6_addl_options &
312 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ?
313 "nd" : "static");
314 break;
315 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
316 len = sprintf(buf, "%s\n",
317 (ha->ip_config.ipv6_addl_options &
318 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ?
319 "auto" : "static");
320 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500321 case ISCSI_NET_PARAM_VLAN_ID:
322 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
323 len = sprintf(buf, "%d\n",
324 (ha->ip_config.ipv4_vlan_tag &
325 ISCSI_MAX_VLAN_ID));
326 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
327 len = sprintf(buf, "%d\n",
328 (ha->ip_config.ipv6_vlan_tag &
329 ISCSI_MAX_VLAN_ID));
330 break;
331 case ISCSI_NET_PARAM_VLAN_PRIORITY:
332 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
333 len = sprintf(buf, "%d\n",
334 ((ha->ip_config.ipv4_vlan_tag >> 13) &
335 ISCSI_MAX_VLAN_PRIORITY));
336 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
337 len = sprintf(buf, "%d\n",
338 ((ha->ip_config.ipv6_vlan_tag >> 13) &
339 ISCSI_MAX_VLAN_PRIORITY));
340 break;
341 case ISCSI_NET_PARAM_VLAN_ENABLED:
342 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
343 len = sprintf(buf, "%s\n",
344 (ha->ip_config.ipv4_options &
345 IPOPT_VLAN_TAGGING_ENABLE) ?
346 "enabled" : "disabled");
347 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
348 len = sprintf(buf, "%s\n",
349 (ha->ip_config.ipv6_options &
350 IPV6_OPT_VLAN_TAGGING_ENABLE) ?
351 "enabled" : "disabled");
352 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700353 case ISCSI_NET_PARAM_MTU:
354 len = sprintf(buf, "%d\n", ha->ip_config.eth_mtu_size);
355 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700356 case ISCSI_NET_PARAM_PORT:
357 if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
358 len = sprintf(buf, "%d\n", ha->ip_config.ipv4_port);
359 else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
360 len = sprintf(buf, "%d\n", ha->ip_config.ipv6_port);
361 break;
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500362 default:
363 len = -ENOSYS;
364 }
365
366 return len;
367}
368
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500369static struct iscsi_endpoint *
370qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
371 int non_blocking)
372{
373 int ret;
374 struct iscsi_endpoint *ep;
375 struct qla_endpoint *qla_ep;
376 struct scsi_qla_host *ha;
377 struct sockaddr_in *addr;
378 struct sockaddr_in6 *addr6;
379
380 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
381 if (!shost) {
382 ret = -ENXIO;
383 printk(KERN_ERR "%s: shost is NULL\n",
384 __func__);
385 return ERR_PTR(ret);
386 }
387
388 ha = iscsi_host_priv(shost);
389
390 ep = iscsi_create_endpoint(sizeof(struct qla_endpoint));
391 if (!ep) {
392 ret = -ENOMEM;
393 return ERR_PTR(ret);
394 }
395
396 qla_ep = ep->dd_data;
397 memset(qla_ep, 0, sizeof(struct qla_endpoint));
398 if (dst_addr->sa_family == AF_INET) {
399 memcpy(&qla_ep->dst_addr, dst_addr, sizeof(struct sockaddr_in));
400 addr = (struct sockaddr_in *)&qla_ep->dst_addr;
401 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI4\n", __func__,
402 (char *)&addr->sin_addr));
403 } else if (dst_addr->sa_family == AF_INET6) {
404 memcpy(&qla_ep->dst_addr, dst_addr,
405 sizeof(struct sockaddr_in6));
406 addr6 = (struct sockaddr_in6 *)&qla_ep->dst_addr;
407 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: %pI6\n", __func__,
408 (char *)&addr6->sin6_addr));
409 }
410
411 qla_ep->host = shost;
412
413 return ep;
414}
415
416static int qla4xxx_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
417{
418 struct qla_endpoint *qla_ep;
419 struct scsi_qla_host *ha;
420 int ret = 0;
421
422 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
423 qla_ep = ep->dd_data;
424 ha = to_qla_host(qla_ep->host);
425
Mike Christie13483732011-12-01 21:38:41 -0600426 if (adapter_up(ha) && !test_bit(AF_BUILD_DDB_LIST, &ha->flags))
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500427 ret = 1;
428
429 return ret;
430}
431
432static void qla4xxx_ep_disconnect(struct iscsi_endpoint *ep)
433{
434 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
435 iscsi_destroy_endpoint(ep);
436}
437
438static int qla4xxx_get_ep_param(struct iscsi_endpoint *ep,
439 enum iscsi_param param,
440 char *buf)
441{
442 struct qla_endpoint *qla_ep = ep->dd_data;
443 struct sockaddr *dst_addr;
444
445 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
446
447 switch (param) {
448 case ISCSI_PARAM_CONN_PORT:
449 case ISCSI_PARAM_CONN_ADDRESS:
450 if (!qla_ep)
451 return -ENOTCONN;
452
453 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
454 if (!dst_addr)
455 return -ENOTCONN;
456
457 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
458 &qla_ep->dst_addr, param, buf);
459 default:
460 return -ENOSYS;
461 }
462}
463
464static void qla4xxx_conn_get_stats(struct iscsi_cls_conn *cls_conn,
465 struct iscsi_stats *stats)
466{
467 struct iscsi_session *sess;
468 struct iscsi_cls_session *cls_sess;
469 struct ddb_entry *ddb_entry;
470 struct scsi_qla_host *ha;
471 struct ql_iscsi_stats *ql_iscsi_stats;
472 int stats_size;
473 int ret;
474 dma_addr_t iscsi_stats_dma;
475
476 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
477
478 cls_sess = iscsi_conn_to_session(cls_conn);
479 sess = cls_sess->dd_data;
480 ddb_entry = sess->dd_data;
481 ha = ddb_entry->ha;
482
483 stats_size = PAGE_ALIGN(sizeof(struct ql_iscsi_stats));
484 /* Allocate memory */
485 ql_iscsi_stats = dma_alloc_coherent(&ha->pdev->dev, stats_size,
486 &iscsi_stats_dma, GFP_KERNEL);
487 if (!ql_iscsi_stats) {
488 ql4_printk(KERN_ERR, ha,
489 "Unable to allocate memory for iscsi stats\n");
490 goto exit_get_stats;
491 }
492
493 ret = qla4xxx_get_mgmt_data(ha, ddb_entry->fw_ddb_index, stats_size,
494 iscsi_stats_dma);
495 if (ret != QLA_SUCCESS) {
496 ql4_printk(KERN_ERR, ha,
497 "Unable to retreive iscsi stats\n");
498 goto free_stats;
499 }
500
501 /* octets */
502 stats->txdata_octets = le64_to_cpu(ql_iscsi_stats->tx_data_octets);
503 stats->rxdata_octets = le64_to_cpu(ql_iscsi_stats->rx_data_octets);
504 /* xmit pdus */
505 stats->noptx_pdus = le32_to_cpu(ql_iscsi_stats->tx_nopout_pdus);
506 stats->scsicmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_cmd_pdus);
507 stats->tmfcmd_pdus = le32_to_cpu(ql_iscsi_stats->tx_tmf_cmd_pdus);
508 stats->login_pdus = le32_to_cpu(ql_iscsi_stats->tx_login_cmd_pdus);
509 stats->text_pdus = le32_to_cpu(ql_iscsi_stats->tx_text_cmd_pdus);
510 stats->dataout_pdus = le32_to_cpu(ql_iscsi_stats->tx_scsi_write_pdus);
511 stats->logout_pdus = le32_to_cpu(ql_iscsi_stats->tx_logout_cmd_pdus);
512 stats->snack_pdus = le32_to_cpu(ql_iscsi_stats->tx_snack_req_pdus);
513 /* recv pdus */
514 stats->noprx_pdus = le32_to_cpu(ql_iscsi_stats->rx_nopin_pdus);
515 stats->scsirsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_resp_pdus);
516 stats->tmfrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_tmf_resp_pdus);
517 stats->textrsp_pdus = le32_to_cpu(ql_iscsi_stats->rx_text_resp_pdus);
518 stats->datain_pdus = le32_to_cpu(ql_iscsi_stats->rx_scsi_read_pdus);
519 stats->logoutrsp_pdus =
520 le32_to_cpu(ql_iscsi_stats->rx_logout_resp_pdus);
521 stats->r2t_pdus = le32_to_cpu(ql_iscsi_stats->rx_r2t_pdus);
522 stats->async_pdus = le32_to_cpu(ql_iscsi_stats->rx_async_pdus);
523 stats->rjt_pdus = le32_to_cpu(ql_iscsi_stats->rx_reject_pdus);
524
525free_stats:
526 dma_free_coherent(&ha->pdev->dev, stats_size, ql_iscsi_stats,
527 iscsi_stats_dma);
528exit_get_stats:
529 return;
530}
531
Mike Christie5c656af2009-07-15 15:02:59 -0500532static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
533{
534 struct iscsi_cls_session *session;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500535 struct iscsi_session *sess;
536 unsigned long flags;
537 enum blk_eh_timer_return ret = BLK_EH_NOT_HANDLED;
Mike Christie5c656af2009-07-15 15:02:59 -0500538
539 session = starget_to_session(scsi_target(sc->device));
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500540 sess = session->dd_data;
Mike Christie5c656af2009-07-15 15:02:59 -0500541
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500542 spin_lock_irqsave(&session->lock, flags);
543 if (session->state == ISCSI_SESSION_FAILED)
544 ret = BLK_EH_RESET_TIMER;
545 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie5c656af2009-07-15 15:02:59 -0500546
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500547 return ret;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700548}
549
Mike Christieaa1e93a2007-05-30 12:57:09 -0500550static int qla4xxx_host_get_param(struct Scsi_Host *shost,
551 enum iscsi_host_param param, char *buf)
552{
553 struct scsi_qla_host *ha = to_qla_host(shost);
554 int len;
555
556 switch (param) {
557 case ISCSI_HOST_PARAM_HWADDRESS:
Michael Chan7ffc49a2007-12-24 21:28:09 -0800558 len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN);
Mike Christieaa1e93a2007-05-30 12:57:09 -0500559 break;
Mike Christie22236962007-05-30 12:57:24 -0500560 case ISCSI_HOST_PARAM_IPADDRESS:
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500561 len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address);
Mike Christie22236962007-05-30 12:57:24 -0500562 break;
Mike Christie8ad57812007-05-30 12:57:13 -0500563 case ISCSI_HOST_PARAM_INITIATOR_NAME:
Mike Christie22236962007-05-30 12:57:24 -0500564 len = sprintf(buf, "%s\n", ha->name_string);
Mike Christie8ad57812007-05-30 12:57:13 -0500565 break;
Mike Christieaa1e93a2007-05-30 12:57:09 -0500566 default:
567 return -ENOSYS;
568 }
569
570 return len;
571}
572
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500573static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha)
574{
575 if (ha->iface_ipv4)
576 return;
577
578 /* IPv4 */
579 ha->iface_ipv4 = iscsi_create_iface(ha->host,
580 &qla4xxx_iscsi_transport,
581 ISCSI_IFACE_TYPE_IPV4, 0, 0);
582 if (!ha->iface_ipv4)
583 ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI "
584 "iface0.\n");
585}
586
587static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha)
588{
589 if (!ha->iface_ipv6_0)
590 /* IPv6 iface-0 */
591 ha->iface_ipv6_0 = iscsi_create_iface(ha->host,
592 &qla4xxx_iscsi_transport,
593 ISCSI_IFACE_TYPE_IPV6, 0,
594 0);
595 if (!ha->iface_ipv6_0)
596 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
597 "iface0.\n");
598
599 if (!ha->iface_ipv6_1)
600 /* IPv6 iface-1 */
601 ha->iface_ipv6_1 = iscsi_create_iface(ha->host,
602 &qla4xxx_iscsi_transport,
603 ISCSI_IFACE_TYPE_IPV6, 1,
604 0);
605 if (!ha->iface_ipv6_1)
606 ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI "
607 "iface1.\n");
608}
609
610static void qla4xxx_create_ifaces(struct scsi_qla_host *ha)
611{
612 if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE)
613 qla4xxx_create_ipv4_iface(ha);
614
615 if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE)
616 qla4xxx_create_ipv6_iface(ha);
617}
618
619static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha)
620{
621 if (ha->iface_ipv4) {
622 iscsi_destroy_iface(ha->iface_ipv4);
623 ha->iface_ipv4 = NULL;
624 }
625}
626
627static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha)
628{
629 if (ha->iface_ipv6_0) {
630 iscsi_destroy_iface(ha->iface_ipv6_0);
631 ha->iface_ipv6_0 = NULL;
632 }
633 if (ha->iface_ipv6_1) {
634 iscsi_destroy_iface(ha->iface_ipv6_1);
635 ha->iface_ipv6_1 = NULL;
636 }
637}
638
639static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha)
640{
641 qla4xxx_destroy_ipv4_iface(ha);
642 qla4xxx_destroy_ipv6_iface(ha);
643}
644
Mike Christied00efe32011-07-25 13:48:38 -0500645static void qla4xxx_set_ipv6(struct scsi_qla_host *ha,
646 struct iscsi_iface_param_info *iface_param,
647 struct addr_ctrl_blk *init_fw_cb)
648{
649 /*
650 * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg.
651 * iface_num 1 is valid only for IPv6 Addr.
652 */
653 switch (iface_param->param) {
654 case ISCSI_NET_PARAM_IPV6_ADDR:
655 if (iface_param->iface_num & 0x1)
656 /* IPv6 Addr 1 */
657 memcpy(init_fw_cb->ipv6_addr1, iface_param->value,
658 sizeof(init_fw_cb->ipv6_addr1));
659 else
660 /* IPv6 Addr 0 */
661 memcpy(init_fw_cb->ipv6_addr0, iface_param->value,
662 sizeof(init_fw_cb->ipv6_addr0));
663 break;
664 case ISCSI_NET_PARAM_IPV6_LINKLOCAL:
665 if (iface_param->iface_num & 0x1)
666 break;
667 memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8],
668 sizeof(init_fw_cb->ipv6_if_id));
669 break;
670 case ISCSI_NET_PARAM_IPV6_ROUTER:
671 if (iface_param->iface_num & 0x1)
672 break;
673 memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value,
674 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
675 break;
676 case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG:
677 /* Autocfg applies to even interface */
678 if (iface_param->iface_num & 0x1)
679 break;
680
681 if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE)
682 init_fw_cb->ipv6_addtl_opts &=
683 cpu_to_le16(
684 ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
685 else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE)
686 init_fw_cb->ipv6_addtl_opts |=
687 cpu_to_le16(
688 IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE);
689 else
690 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
691 "IPv6 addr\n");
692 break;
693 case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG:
694 /* Autocfg applies to even interface */
695 if (iface_param->iface_num & 0x1)
696 break;
697
698 if (iface_param->value[0] ==
699 ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE)
700 init_fw_cb->ipv6_addtl_opts |= cpu_to_le16(
701 IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
702 else if (iface_param->value[0] ==
703 ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE)
704 init_fw_cb->ipv6_addtl_opts &= cpu_to_le16(
705 ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR);
706 else
707 ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for "
708 "IPv6 linklocal addr\n");
709 break;
710 case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG:
711 /* Autocfg applies to even interface */
712 if (iface_param->iface_num & 0x1)
713 break;
714
715 if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE)
716 memset(init_fw_cb->ipv6_dflt_rtr_addr, 0,
717 sizeof(init_fw_cb->ipv6_dflt_rtr_addr));
718 break;
719 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500720 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500721 init_fw_cb->ipv6_opts |=
722 cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500723 qla4xxx_create_ipv6_iface(ha);
724 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500725 init_fw_cb->ipv6_opts &=
726 cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE &
727 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500728 qla4xxx_destroy_ipv6_iface(ha);
729 }
Mike Christied00efe32011-07-25 13:48:38 -0500730 break;
Mike Christie2d636732011-10-11 17:55:11 -0500731 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -0500732 if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag))
733 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500734 init_fw_cb->ipv6_vlan_tag =
735 cpu_to_be16(*(uint16_t *)iface_param->value);
736 break;
737 case ISCSI_NET_PARAM_VLAN_ENABLED:
738 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
739 init_fw_cb->ipv6_opts |=
740 cpu_to_le16(IPV6_OPT_VLAN_TAGGING_ENABLE);
741 else
742 init_fw_cb->ipv6_opts &=
743 cpu_to_le16(~IPV6_OPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500744 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700745 case ISCSI_NET_PARAM_MTU:
746 init_fw_cb->eth_mtu_size =
747 cpu_to_le16(*(uint16_t *)iface_param->value);
748 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700749 case ISCSI_NET_PARAM_PORT:
750 /* Autocfg applies to even interface */
751 if (iface_param->iface_num & 0x1)
752 break;
753
754 init_fw_cb->ipv6_port =
755 cpu_to_le16(*(uint16_t *)iface_param->value);
756 break;
Mike Christied00efe32011-07-25 13:48:38 -0500757 default:
758 ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n",
759 iface_param->param);
760 break;
761 }
762}
763
764static void qla4xxx_set_ipv4(struct scsi_qla_host *ha,
765 struct iscsi_iface_param_info *iface_param,
766 struct addr_ctrl_blk *init_fw_cb)
767{
768 switch (iface_param->param) {
769 case ISCSI_NET_PARAM_IPV4_ADDR:
770 memcpy(init_fw_cb->ipv4_addr, iface_param->value,
771 sizeof(init_fw_cb->ipv4_addr));
772 break;
773 case ISCSI_NET_PARAM_IPV4_SUBNET:
774 memcpy(init_fw_cb->ipv4_subnet, iface_param->value,
775 sizeof(init_fw_cb->ipv4_subnet));
776 break;
777 case ISCSI_NET_PARAM_IPV4_GW:
778 memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value,
779 sizeof(init_fw_cb->ipv4_gw_addr));
780 break;
781 case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
782 if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
783 init_fw_cb->ipv4_tcp_opts |=
784 cpu_to_le16(TCPOPT_DHCP_ENABLE);
785 else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
786 init_fw_cb->ipv4_tcp_opts &=
787 cpu_to_le16(~TCPOPT_DHCP_ENABLE);
788 else
789 ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n");
790 break;
791 case ISCSI_NET_PARAM_IFACE_ENABLE:
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500792 if (iface_param->value[0] == ISCSI_IFACE_ENABLE) {
Mike Christied00efe32011-07-25 13:48:38 -0500793 init_fw_cb->ipv4_ip_opts |=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500794 cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500795 qla4xxx_create_ipv4_iface(ha);
796 } else {
Mike Christied00efe32011-07-25 13:48:38 -0500797 init_fw_cb->ipv4_ip_opts &=
Vikas Chaudhary2bab08f2011-07-25 13:48:39 -0500798 cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE &
Mike Christied00efe32011-07-25 13:48:38 -0500799 0xFFFF);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -0500800 qla4xxx_destroy_ipv4_iface(ha);
801 }
Mike Christied00efe32011-07-25 13:48:38 -0500802 break;
Mike Christie2d636732011-10-11 17:55:11 -0500803 case ISCSI_NET_PARAM_VLAN_TAG:
Mike Christied00efe32011-07-25 13:48:38 -0500804 if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag))
805 break;
Vikas Chaudhary6ac73e82011-07-25 13:48:49 -0500806 init_fw_cb->ipv4_vlan_tag =
807 cpu_to_be16(*(uint16_t *)iface_param->value);
808 break;
809 case ISCSI_NET_PARAM_VLAN_ENABLED:
810 if (iface_param->value[0] == ISCSI_VLAN_ENABLE)
811 init_fw_cb->ipv4_ip_opts |=
812 cpu_to_le16(IPOPT_VLAN_TAGGING_ENABLE);
813 else
814 init_fw_cb->ipv4_ip_opts &=
815 cpu_to_le16(~IPOPT_VLAN_TAGGING_ENABLE);
Mike Christied00efe32011-07-25 13:48:38 -0500816 break;
Vikas Chaudhary943c1572011-08-01 03:26:13 -0700817 case ISCSI_NET_PARAM_MTU:
818 init_fw_cb->eth_mtu_size =
819 cpu_to_le16(*(uint16_t *)iface_param->value);
820 break;
Vikas Chaudhary2ada7fc2011-08-01 03:26:19 -0700821 case ISCSI_NET_PARAM_PORT:
822 init_fw_cb->ipv4_port =
823 cpu_to_le16(*(uint16_t *)iface_param->value);
824 break;
Mike Christied00efe32011-07-25 13:48:38 -0500825 default:
826 ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n",
827 iface_param->param);
828 break;
829 }
830}
831
832static void
833qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb)
834{
835 struct addr_ctrl_blk_def *acb;
836 acb = (struct addr_ctrl_blk_def *)init_fw_cb;
837 memset(acb->reserved1, 0, sizeof(acb->reserved1));
838 memset(acb->reserved2, 0, sizeof(acb->reserved2));
839 memset(acb->reserved3, 0, sizeof(acb->reserved3));
840 memset(acb->reserved4, 0, sizeof(acb->reserved4));
841 memset(acb->reserved5, 0, sizeof(acb->reserved5));
842 memset(acb->reserved6, 0, sizeof(acb->reserved6));
843 memset(acb->reserved7, 0, sizeof(acb->reserved7));
844 memset(acb->reserved8, 0, sizeof(acb->reserved8));
845 memset(acb->reserved9, 0, sizeof(acb->reserved9));
846 memset(acb->reserved10, 0, sizeof(acb->reserved10));
847 memset(acb->reserved11, 0, sizeof(acb->reserved11));
848 memset(acb->reserved12, 0, sizeof(acb->reserved12));
849 memset(acb->reserved13, 0, sizeof(acb->reserved13));
850 memset(acb->reserved14, 0, sizeof(acb->reserved14));
851 memset(acb->reserved15, 0, sizeof(acb->reserved15));
852}
853
854static int
Mike Christie00c31882011-10-06 03:56:59 -0500855qla4xxx_iface_set_param(struct Scsi_Host *shost, void *data, uint32_t len)
Mike Christied00efe32011-07-25 13:48:38 -0500856{
857 struct scsi_qla_host *ha = to_qla_host(shost);
858 int rval = 0;
859 struct iscsi_iface_param_info *iface_param = NULL;
860 struct addr_ctrl_blk *init_fw_cb = NULL;
861 dma_addr_t init_fw_cb_dma;
862 uint32_t mbox_cmd[MBOX_REG_COUNT];
863 uint32_t mbox_sts[MBOX_REG_COUNT];
Mike Christie00c31882011-10-06 03:56:59 -0500864 uint32_t rem = len;
865 struct nlattr *attr;
Mike Christied00efe32011-07-25 13:48:38 -0500866
867 init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
868 sizeof(struct addr_ctrl_blk),
869 &init_fw_cb_dma, GFP_KERNEL);
870 if (!init_fw_cb) {
871 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
872 __func__);
873 return -ENOMEM;
874 }
875
876 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
877 memset(&mbox_cmd, 0, sizeof(mbox_cmd));
878 memset(&mbox_sts, 0, sizeof(mbox_sts));
879
880 if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) {
881 ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__);
882 rval = -EIO;
883 goto exit_init_fw_cb;
884 }
885
Mike Christie00c31882011-10-06 03:56:59 -0500886 nla_for_each_attr(attr, data, len, rem) {
887 iface_param = nla_data(attr);
Mike Christied00efe32011-07-25 13:48:38 -0500888
889 if (iface_param->param_type != ISCSI_NET_PARAM)
890 continue;
891
892 switch (iface_param->iface_type) {
893 case ISCSI_IFACE_TYPE_IPV4:
894 switch (iface_param->iface_num) {
895 case 0:
896 qla4xxx_set_ipv4(ha, iface_param, init_fw_cb);
897 break;
898 default:
899 /* Cannot have more than one IPv4 interface */
900 ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface "
901 "number = %d\n",
902 iface_param->iface_num);
903 break;
904 }
905 break;
906 case ISCSI_IFACE_TYPE_IPV6:
907 switch (iface_param->iface_num) {
908 case 0:
909 case 1:
910 qla4xxx_set_ipv6(ha, iface_param, init_fw_cb);
911 break;
912 default:
913 /* Cannot have more than two IPv6 interface */
914 ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface "
915 "number = %d\n",
916 iface_param->iface_num);
917 break;
918 }
919 break;
920 default:
921 ql4_printk(KERN_ERR, ha, "Invalid iface type\n");
922 break;
923 }
Mike Christied00efe32011-07-25 13:48:38 -0500924 }
925
926 init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A);
927
928 rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB,
929 sizeof(struct addr_ctrl_blk),
930 FLASH_OPT_RMW_COMMIT);
931 if (rval != QLA_SUCCESS) {
932 ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n",
933 __func__);
934 rval = -EIO;
935 goto exit_init_fw_cb;
936 }
937
Vikas Chaudharyce505f92011-12-01 22:42:10 -0800938 rval = qla4xxx_disable_acb(ha);
939 if (rval != QLA_SUCCESS) {
940 ql4_printk(KERN_ERR, ha, "%s: disable acb mbx failed\n",
941 __func__);
942 rval = -EIO;
943 goto exit_init_fw_cb;
944 }
945
946 wait_for_completion_timeout(&ha->disable_acb_comp,
947 DISABLE_ACB_TOV * HZ);
Mike Christied00efe32011-07-25 13:48:38 -0500948
949 qla4xxx_initcb_to_acb(init_fw_cb);
950
951 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma);
952 if (rval != QLA_SUCCESS) {
953 ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n",
954 __func__);
955 rval = -EIO;
956 goto exit_init_fw_cb;
957 }
958
959 memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
960 qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb,
961 init_fw_cb_dma);
962
963exit_init_fw_cb:
964 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk),
965 init_fw_cb, init_fw_cb_dma);
966
967 return rval;
968}
969
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500970static int qla4xxx_conn_get_param(struct iscsi_cls_conn *cls_conn,
David Somayajuluafaf5a22006-09-19 10:28:00 -0700971 enum iscsi_param param, char *buf)
972{
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500973 struct iscsi_conn *conn;
974 struct qla_conn *qla_conn;
975 struct sockaddr *dst_addr;
976 int len = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700977
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500978 conn = cls_conn->dd_data;
979 qla_conn = conn->dd_data;
980 dst_addr = &qla_conn->qla_ep->dst_addr;
David Somayajuluafaf5a22006-09-19 10:28:00 -0700981
982 switch (param) {
983 case ISCSI_PARAM_CONN_PORT:
David Somayajuluafaf5a22006-09-19 10:28:00 -0700984 case ISCSI_PARAM_CONN_ADDRESS:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500985 return iscsi_conn_get_addr_param((struct sockaddr_storage *)
986 dst_addr, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700987 default:
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500988 return iscsi_conn_get_param(cls_conn, param, buf);
David Somayajuluafaf5a22006-09-19 10:28:00 -0700989 }
990
991 return len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -0500992
David Somayajuluafaf5a22006-09-19 10:28:00 -0700993}
994
Mike Christie13483732011-12-01 21:38:41 -0600995int qla4xxx_get_ddb_index(struct scsi_qla_host *ha, uint16_t *ddb_index)
996{
997 uint32_t mbx_sts = 0;
998 uint16_t tmp_ddb_index;
999 int ret;
1000
1001get_ddb_index:
1002 tmp_ddb_index = find_first_zero_bit(ha->ddb_idx_map, MAX_DDB_ENTRIES);
1003
1004 if (tmp_ddb_index >= MAX_DDB_ENTRIES) {
1005 DEBUG2(ql4_printk(KERN_INFO, ha,
1006 "Free DDB index not available\n"));
1007 ret = QLA_ERROR;
1008 goto exit_get_ddb_index;
1009 }
1010
1011 if (test_and_set_bit(tmp_ddb_index, ha->ddb_idx_map))
1012 goto get_ddb_index;
1013
1014 DEBUG2(ql4_printk(KERN_INFO, ha,
1015 "Found a free DDB index at %d\n", tmp_ddb_index));
1016 ret = qla4xxx_req_ddb_entry(ha, tmp_ddb_index, &mbx_sts);
1017 if (ret == QLA_ERROR) {
1018 if (mbx_sts == MBOX_STS_COMMAND_ERROR) {
1019 ql4_printk(KERN_INFO, ha,
1020 "DDB index = %d not available trying next\n",
1021 tmp_ddb_index);
1022 goto get_ddb_index;
1023 }
1024 DEBUG2(ql4_printk(KERN_INFO, ha,
1025 "Free FW DDB not available\n"));
1026 }
1027
1028 *ddb_index = tmp_ddb_index;
1029
1030exit_get_ddb_index:
1031 return ret;
1032}
1033
1034static int qla4xxx_match_ipaddress(struct scsi_qla_host *ha,
1035 struct ddb_entry *ddb_entry,
1036 char *existing_ipaddr,
1037 char *user_ipaddr)
1038{
1039 uint8_t dst_ipaddr[IPv6_ADDR_LEN];
1040 char formatted_ipaddr[DDB_IPADDR_LEN];
1041 int status = QLA_SUCCESS, ret = 0;
1042
1043 if (ddb_entry->fw_ddb_entry.options & DDB_OPT_IPV6_DEVICE) {
1044 ret = in6_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1045 '\0', NULL);
1046 if (ret == 0) {
1047 status = QLA_ERROR;
1048 goto out_match;
1049 }
1050 ret = sprintf(formatted_ipaddr, "%pI6", dst_ipaddr);
1051 } else {
1052 ret = in4_pton(user_ipaddr, strlen(user_ipaddr), dst_ipaddr,
1053 '\0', NULL);
1054 if (ret == 0) {
1055 status = QLA_ERROR;
1056 goto out_match;
1057 }
1058 ret = sprintf(formatted_ipaddr, "%pI4", dst_ipaddr);
1059 }
1060
1061 if (strcmp(existing_ipaddr, formatted_ipaddr))
1062 status = QLA_ERROR;
1063
1064out_match:
1065 return status;
1066}
1067
1068static int qla4xxx_match_fwdb_session(struct scsi_qla_host *ha,
1069 struct iscsi_cls_conn *cls_conn)
1070{
1071 int idx = 0, max_ddbs, rval;
1072 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1073 struct iscsi_session *sess, *existing_sess;
1074 struct iscsi_conn *conn, *existing_conn;
1075 struct ddb_entry *ddb_entry;
1076
1077 sess = cls_sess->dd_data;
1078 conn = cls_conn->dd_data;
1079
1080 if (sess->targetname == NULL ||
1081 conn->persistent_address == NULL ||
1082 conn->persistent_port == 0)
1083 return QLA_ERROR;
1084
1085 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
1086 MAX_DEV_DB_ENTRIES;
1087
1088 for (idx = 0; idx < max_ddbs; idx++) {
1089 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
1090 if (ddb_entry == NULL)
1091 continue;
1092
1093 if (ddb_entry->ddb_type != FLASH_DDB)
1094 continue;
1095
1096 existing_sess = ddb_entry->sess->dd_data;
1097 existing_conn = ddb_entry->conn->dd_data;
1098
1099 if (existing_sess->targetname == NULL ||
1100 existing_conn->persistent_address == NULL ||
1101 existing_conn->persistent_port == 0)
1102 continue;
1103
1104 DEBUG2(ql4_printk(KERN_INFO, ha,
1105 "IQN = %s User IQN = %s\n",
1106 existing_sess->targetname,
1107 sess->targetname));
1108
1109 DEBUG2(ql4_printk(KERN_INFO, ha,
1110 "IP = %s User IP = %s\n",
1111 existing_conn->persistent_address,
1112 conn->persistent_address));
1113
1114 DEBUG2(ql4_printk(KERN_INFO, ha,
1115 "Port = %d User Port = %d\n",
1116 existing_conn->persistent_port,
1117 conn->persistent_port));
1118
1119 if (strcmp(existing_sess->targetname, sess->targetname))
1120 continue;
1121 rval = qla4xxx_match_ipaddress(ha, ddb_entry,
1122 existing_conn->persistent_address,
1123 conn->persistent_address);
1124 if (rval == QLA_ERROR)
1125 continue;
1126 if (existing_conn->persistent_port != conn->persistent_port)
1127 continue;
1128 break;
1129 }
1130
1131 if (idx == max_ddbs)
1132 return QLA_ERROR;
1133
1134 DEBUG2(ql4_printk(KERN_INFO, ha,
1135 "Match found in fwdb sessions\n"));
1136 return QLA_SUCCESS;
1137}
1138
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001139static struct iscsi_cls_session *
1140qla4xxx_session_create(struct iscsi_endpoint *ep,
1141 uint16_t cmds_max, uint16_t qdepth,
1142 uint32_t initial_cmdsn)
1143{
1144 struct iscsi_cls_session *cls_sess;
1145 struct scsi_qla_host *ha;
1146 struct qla_endpoint *qla_ep;
1147 struct ddb_entry *ddb_entry;
Mike Christie13483732011-12-01 21:38:41 -06001148 uint16_t ddb_index;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001149 struct iscsi_session *sess;
1150 struct sockaddr *dst_addr;
1151 int ret;
1152
1153 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1154 if (!ep) {
1155 printk(KERN_ERR "qla4xxx: missing ep.\n");
1156 return NULL;
1157 }
1158
1159 qla_ep = ep->dd_data;
1160 dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
1161 ha = to_qla_host(qla_ep->host);
Manish Rangankar736cf362011-10-07 16:55:46 -07001162
Mike Christie13483732011-12-01 21:38:41 -06001163 ret = qla4xxx_get_ddb_index(ha, &ddb_index);
1164 if (ret == QLA_ERROR)
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001165 return NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001166
1167 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, qla_ep->host,
1168 cmds_max, sizeof(struct ddb_entry),
1169 sizeof(struct ql4_task_data),
1170 initial_cmdsn, ddb_index);
1171 if (!cls_sess)
1172 return NULL;
1173
1174 sess = cls_sess->dd_data;
1175 ddb_entry = sess->dd_data;
1176 ddb_entry->fw_ddb_index = ddb_index;
1177 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
1178 ddb_entry->ha = ha;
1179 ddb_entry->sess = cls_sess;
Mike Christie13483732011-12-01 21:38:41 -06001180 ddb_entry->unblock_sess = qla4xxx_unblock_ddb;
1181 ddb_entry->ddb_change = qla4xxx_ddb_change;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001182 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
1183 ha->fw_ddb_index_map[ddb_entry->fw_ddb_index] = ddb_entry;
1184 ha->tot_ddbs++;
1185
1186 return cls_sess;
1187}
1188
1189static void qla4xxx_session_destroy(struct iscsi_cls_session *cls_sess)
1190{
1191 struct iscsi_session *sess;
1192 struct ddb_entry *ddb_entry;
1193 struct scsi_qla_host *ha;
1194 unsigned long flags;
1195
1196 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1197 sess = cls_sess->dd_data;
1198 ddb_entry = sess->dd_data;
1199 ha = ddb_entry->ha;
1200
Manish Rangankar736cf362011-10-07 16:55:46 -07001201 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
1202
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001203 spin_lock_irqsave(&ha->hardware_lock, flags);
1204 qla4xxx_free_ddb(ha, ddb_entry);
1205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1206 iscsi_session_teardown(cls_sess);
1207}
1208
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001209static struct iscsi_cls_conn *
1210qla4xxx_conn_create(struct iscsi_cls_session *cls_sess, uint32_t conn_idx)
1211{
1212 struct iscsi_cls_conn *cls_conn;
1213 struct iscsi_session *sess;
1214 struct ddb_entry *ddb_entry;
1215
1216 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1217 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn),
1218 conn_idx);
Mike Christieff1d0312011-12-01 21:38:43 -06001219 if (!cls_conn)
1220 return NULL;
1221
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001222 sess = cls_sess->dd_data;
1223 ddb_entry = sess->dd_data;
1224 ddb_entry->conn = cls_conn;
1225
1226 return cls_conn;
1227}
1228
1229static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,
1230 struct iscsi_cls_conn *cls_conn,
1231 uint64_t transport_fd, int is_leading)
1232{
1233 struct iscsi_conn *conn;
1234 struct qla_conn *qla_conn;
1235 struct iscsi_endpoint *ep;
1236
1237 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1238
1239 if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
1240 return -EINVAL;
1241 ep = iscsi_lookup_endpoint(transport_fd);
1242 conn = cls_conn->dd_data;
1243 qla_conn = conn->dd_data;
1244 qla_conn->qla_ep = ep->dd_data;
1245 return 0;
1246}
1247
1248static int qla4xxx_conn_start(struct iscsi_cls_conn *cls_conn)
1249{
1250 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1251 struct iscsi_session *sess;
1252 struct ddb_entry *ddb_entry;
1253 struct scsi_qla_host *ha;
Mike Christie13483732011-12-01 21:38:41 -06001254 struct dev_db_entry *fw_ddb_entry = NULL;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001255 dma_addr_t fw_ddb_entry_dma;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001256 uint32_t mbx_sts = 0;
1257 int ret = 0;
1258 int status = QLA_SUCCESS;
1259
1260 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1261 sess = cls_sess->dd_data;
1262 ddb_entry = sess->dd_data;
1263 ha = ddb_entry->ha;
1264
Mike Christie13483732011-12-01 21:38:41 -06001265 /* Check if we have matching FW DDB, if yes then do not
1266 * login to this target. This could cause target to logout previous
1267 * connection
1268 */
1269 ret = qla4xxx_match_fwdb_session(ha, cls_conn);
1270 if (ret == QLA_SUCCESS) {
1271 ql4_printk(KERN_INFO, ha,
1272 "Session already exist in FW.\n");
1273 ret = -EEXIST;
1274 goto exit_conn_start;
1275 }
1276
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001277 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1278 &fw_ddb_entry_dma, GFP_KERNEL);
1279 if (!fw_ddb_entry) {
1280 ql4_printk(KERN_ERR, ha,
1281 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06001282 ret = -ENOMEM;
1283 goto exit_conn_start;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001284 }
1285
1286 ret = qla4xxx_set_param_ddbentry(ha, ddb_entry, cls_conn, &mbx_sts);
1287 if (ret) {
1288 /* If iscsid is stopped and started then no need to do
1289 * set param again since ddb state will be already
1290 * active and FW does not allow set ddb to an
1291 * active session.
1292 */
1293 if (mbx_sts)
1294 if (ddb_entry->fw_ddb_device_state ==
Manish Rangankarf922da72011-10-07 16:55:49 -07001295 DDB_DS_SESSION_ACTIVE) {
Mike Christie13483732011-12-01 21:38:41 -06001296 ddb_entry->unblock_sess(ddb_entry->sess);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001297 goto exit_set_param;
Manish Rangankarf922da72011-10-07 16:55:49 -07001298 }
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001299
1300 ql4_printk(KERN_ERR, ha, "%s: Failed set param for index[%d]\n",
1301 __func__, ddb_entry->fw_ddb_index);
1302 goto exit_conn_start;
1303 }
1304
1305 status = qla4xxx_conn_open(ha, ddb_entry->fw_ddb_index);
1306 if (status == QLA_ERROR) {
Manish Rangankar0e7e8502011-07-25 13:48:54 -05001307 ql4_printk(KERN_ERR, ha, "%s: Login failed: %s\n", __func__,
1308 sess->targetname);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001309 ret = -EINVAL;
1310 goto exit_conn_start;
1311 }
1312
Manish Rangankar98270ab2011-10-07 16:55:47 -07001313 if (ddb_entry->fw_ddb_device_state == DDB_DS_NO_CONNECTION_ACTIVE)
1314 ddb_entry->fw_ddb_device_state = DDB_DS_LOGIN_IN_PROCESS;
1315
1316 DEBUG2(printk(KERN_INFO "%s: DDB state [%d]\n", __func__,
1317 ddb_entry->fw_ddb_device_state));
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001318
1319exit_set_param:
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001320 ret = 0;
1321
1322exit_conn_start:
Mike Christie13483732011-12-01 21:38:41 -06001323 if (fw_ddb_entry)
1324 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1325 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001326 return ret;
1327}
1328
1329static void qla4xxx_conn_destroy(struct iscsi_cls_conn *cls_conn)
1330{
1331 struct iscsi_cls_session *cls_sess = iscsi_conn_to_session(cls_conn);
1332 struct iscsi_session *sess;
1333 struct scsi_qla_host *ha;
1334 struct ddb_entry *ddb_entry;
1335 int options;
1336
1337 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
1338 sess = cls_sess->dd_data;
1339 ddb_entry = sess->dd_data;
1340 ha = ddb_entry->ha;
1341
1342 options = LOGOUT_OPTION_CLOSE_SESSION;
1343 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options) == QLA_ERROR)
1344 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n", __func__);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001345}
1346
1347static void qla4xxx_task_work(struct work_struct *wdata)
1348{
1349 struct ql4_task_data *task_data;
1350 struct scsi_qla_host *ha;
1351 struct passthru_status *sts;
1352 struct iscsi_task *task;
1353 struct iscsi_hdr *hdr;
1354 uint8_t *data;
1355 uint32_t data_len;
1356 struct iscsi_conn *conn;
1357 int hdr_len;
1358 itt_t itt;
1359
1360 task_data = container_of(wdata, struct ql4_task_data, task_work);
1361 ha = task_data->ha;
1362 task = task_data->task;
1363 sts = &task_data->sts;
1364 hdr_len = sizeof(struct iscsi_hdr);
1365
1366 DEBUG3(printk(KERN_INFO "Status returned\n"));
1367 DEBUG3(qla4xxx_dump_buffer(sts, 64));
1368 DEBUG3(printk(KERN_INFO "Response buffer"));
1369 DEBUG3(qla4xxx_dump_buffer(task_data->resp_buffer, 64));
1370
1371 conn = task->conn;
1372
1373 switch (sts->completionStatus) {
1374 case PASSTHRU_STATUS_COMPLETE:
1375 hdr = (struct iscsi_hdr *)task_data->resp_buffer;
1376 /* Assign back the itt in hdr, until we use the PREASSIGN_TAG */
1377 itt = sts->handle;
1378 hdr->itt = itt;
1379 data = task_data->resp_buffer + hdr_len;
1380 data_len = task_data->resp_len - hdr_len;
1381 iscsi_complete_pdu(conn, hdr, data, data_len);
1382 break;
1383 default:
1384 ql4_printk(KERN_ERR, ha, "Passthru failed status = 0x%x\n",
1385 sts->completionStatus);
1386 break;
1387 }
1388 return;
1389}
1390
1391static int qla4xxx_alloc_pdu(struct iscsi_task *task, uint8_t opcode)
1392{
1393 struct ql4_task_data *task_data;
1394 struct iscsi_session *sess;
1395 struct ddb_entry *ddb_entry;
1396 struct scsi_qla_host *ha;
1397 int hdr_len;
1398
1399 sess = task->conn->session;
1400 ddb_entry = sess->dd_data;
1401 ha = ddb_entry->ha;
1402 task_data = task->dd_data;
1403 memset(task_data, 0, sizeof(struct ql4_task_data));
1404
1405 if (task->sc) {
1406 ql4_printk(KERN_INFO, ha,
1407 "%s: SCSI Commands not implemented\n", __func__);
1408 return -EINVAL;
1409 }
1410
1411 hdr_len = sizeof(struct iscsi_hdr);
1412 task_data->ha = ha;
1413 task_data->task = task;
1414
1415 if (task->data_count) {
1416 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
1417 task->data_count,
1418 PCI_DMA_TODEVICE);
1419 }
1420
1421 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1422 __func__, task->conn->max_recv_dlength, hdr_len));
1423
Manish Rangankar69ca2162011-10-07 16:55:50 -07001424 task_data->resp_len = task->conn->max_recv_dlength + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001425 task_data->resp_buffer = dma_alloc_coherent(&ha->pdev->dev,
1426 task_data->resp_len,
1427 &task_data->resp_dma,
1428 GFP_ATOMIC);
1429 if (!task_data->resp_buffer)
1430 goto exit_alloc_pdu;
1431
Manish Rangankar69ca2162011-10-07 16:55:50 -07001432 task_data->req_len = task->data_count + hdr_len;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001433 task_data->req_buffer = dma_alloc_coherent(&ha->pdev->dev,
Manish Rangankar69ca2162011-10-07 16:55:50 -07001434 task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001435 &task_data->req_dma,
1436 GFP_ATOMIC);
1437 if (!task_data->req_buffer)
1438 goto exit_alloc_pdu;
1439
1440 task->hdr = task_data->req_buffer;
1441
1442 INIT_WORK(&task_data->task_work, qla4xxx_task_work);
1443
1444 return 0;
1445
1446exit_alloc_pdu:
1447 if (task_data->resp_buffer)
1448 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1449 task_data->resp_buffer, task_data->resp_dma);
1450
1451 if (task_data->req_buffer)
Manish Rangankar69ca2162011-10-07 16:55:50 -07001452 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001453 task_data->req_buffer, task_data->req_dma);
1454 return -ENOMEM;
1455}
1456
1457static void qla4xxx_task_cleanup(struct iscsi_task *task)
1458{
1459 struct ql4_task_data *task_data;
1460 struct iscsi_session *sess;
1461 struct ddb_entry *ddb_entry;
1462 struct scsi_qla_host *ha;
1463 int hdr_len;
1464
1465 hdr_len = sizeof(struct iscsi_hdr);
1466 sess = task->conn->session;
1467 ddb_entry = sess->dd_data;
1468 ha = ddb_entry->ha;
1469 task_data = task->dd_data;
1470
1471 if (task->data_count) {
1472 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
1473 task->data_count, PCI_DMA_TODEVICE);
1474 }
1475
1476 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
1477 __func__, task->conn->max_recv_dlength, hdr_len));
1478
1479 dma_free_coherent(&ha->pdev->dev, task_data->resp_len,
1480 task_data->resp_buffer, task_data->resp_dma);
Manish Rangankar69ca2162011-10-07 16:55:50 -07001481 dma_free_coherent(&ha->pdev->dev, task_data->req_len,
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001482 task_data->req_buffer, task_data->req_dma);
1483 return;
1484}
1485
1486static int qla4xxx_task_xmit(struct iscsi_task *task)
1487{
1488 struct scsi_cmnd *sc = task->sc;
1489 struct iscsi_session *sess = task->conn->session;
1490 struct ddb_entry *ddb_entry = sess->dd_data;
1491 struct scsi_qla_host *ha = ddb_entry->ha;
1492
1493 if (!sc)
1494 return qla4xxx_send_passthru0(task);
1495
1496 ql4_printk(KERN_INFO, ha, "%s: scsi cmd xmit not implemented\n",
1497 __func__);
1498 return -ENOSYS;
1499}
1500
Mike Christie13483732011-12-01 21:38:41 -06001501static void qla4xxx_copy_fwddb_param(struct scsi_qla_host *ha,
1502 struct dev_db_entry *fw_ddb_entry,
1503 struct iscsi_cls_session *cls_sess,
1504 struct iscsi_cls_conn *cls_conn)
1505{
1506 int buflen = 0;
1507 struct iscsi_session *sess;
1508 struct iscsi_conn *conn;
1509 char ip_addr[DDB_IPADDR_LEN];
1510 uint16_t options = 0;
1511
1512 sess = cls_sess->dd_data;
1513 conn = cls_conn->dd_data;
1514
1515 conn->max_recv_dlength = BYTE_UNITS *
1516 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1517
1518 conn->max_xmit_dlength = BYTE_UNITS *
1519 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1520
1521 sess->initial_r2t_en =
1522 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1523
1524 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1525
1526 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1527
1528 sess->first_burst = BYTE_UNITS *
1529 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1530
1531 sess->max_burst = BYTE_UNITS *
1532 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1533
1534 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1535
1536 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1537
1538 conn->persistent_port = le16_to_cpu(fw_ddb_entry->port);
1539
1540 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1541
1542 options = le16_to_cpu(fw_ddb_entry->options);
1543 if (options & DDB_OPT_IPV6_DEVICE)
1544 sprintf(ip_addr, "%pI6", fw_ddb_entry->ip_addr);
1545 else
1546 sprintf(ip_addr, "%pI4", fw_ddb_entry->ip_addr);
1547
1548 iscsi_set_param(cls_conn, ISCSI_PARAM_TARGET_NAME,
1549 (char *)fw_ddb_entry->iscsi_name, buflen);
1550 iscsi_set_param(cls_conn, ISCSI_PARAM_INITIATOR_NAME,
1551 (char *)ha->name_string, buflen);
1552 iscsi_set_param(cls_conn, ISCSI_PARAM_PERSISTENT_ADDRESS,
1553 (char *)ip_addr, buflen);
1554}
1555
1556void qla4xxx_update_session_conn_fwddb_param(struct scsi_qla_host *ha,
1557 struct ddb_entry *ddb_entry)
1558{
1559 struct iscsi_cls_session *cls_sess;
1560 struct iscsi_cls_conn *cls_conn;
1561 uint32_t ddb_state;
1562 dma_addr_t fw_ddb_entry_dma;
1563 struct dev_db_entry *fw_ddb_entry;
1564
1565 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1566 &fw_ddb_entry_dma, GFP_KERNEL);
1567 if (!fw_ddb_entry) {
1568 ql4_printk(KERN_ERR, ha,
1569 "%s: Unable to allocate dma buffer\n", __func__);
1570 goto exit_session_conn_fwddb_param;
1571 }
1572
1573 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1574 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1575 NULL, NULL, NULL) == QLA_ERROR) {
1576 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1577 "get_ddb_entry for fw_ddb_index %d\n",
1578 ha->host_no, __func__,
1579 ddb_entry->fw_ddb_index));
1580 goto exit_session_conn_fwddb_param;
1581 }
1582
1583 cls_sess = ddb_entry->sess;
1584
1585 cls_conn = ddb_entry->conn;
1586
1587 /* Update params */
1588 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
1589
1590exit_session_conn_fwddb_param:
1591 if (fw_ddb_entry)
1592 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1593 fw_ddb_entry, fw_ddb_entry_dma);
1594}
1595
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001596void qla4xxx_update_session_conn_param(struct scsi_qla_host *ha,
1597 struct ddb_entry *ddb_entry)
1598{
1599 struct iscsi_cls_session *cls_sess;
1600 struct iscsi_cls_conn *cls_conn;
1601 struct iscsi_session *sess;
1602 struct iscsi_conn *conn;
1603 uint32_t ddb_state;
1604 dma_addr_t fw_ddb_entry_dma;
1605 struct dev_db_entry *fw_ddb_entry;
1606
1607 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1608 &fw_ddb_entry_dma, GFP_KERNEL);
1609 if (!fw_ddb_entry) {
1610 ql4_printk(KERN_ERR, ha,
1611 "%s: Unable to allocate dma buffer\n", __func__);
Mike Christie13483732011-12-01 21:38:41 -06001612 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001613 }
1614
1615 if (qla4xxx_get_fwddb_entry(ha, ddb_entry->fw_ddb_index, fw_ddb_entry,
1616 fw_ddb_entry_dma, NULL, NULL, &ddb_state,
1617 NULL, NULL, NULL) == QLA_ERROR) {
1618 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: failed "
1619 "get_ddb_entry for fw_ddb_index %d\n",
1620 ha->host_no, __func__,
1621 ddb_entry->fw_ddb_index));
Mike Christie13483732011-12-01 21:38:41 -06001622 goto exit_session_conn_param;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001623 }
1624
1625 cls_sess = ddb_entry->sess;
1626 sess = cls_sess->dd_data;
1627
1628 cls_conn = ddb_entry->conn;
1629 conn = cls_conn->dd_data;
1630
Mike Christie13483732011-12-01 21:38:41 -06001631 /* Update timers after login */
1632 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08001633 (le16_to_cpu(fw_ddb_entry->def_timeout) > LOGIN_TOV) &&
1634 (le16_to_cpu(fw_ddb_entry->def_timeout) < LOGIN_TOV * 10) ?
1635 le16_to_cpu(fw_ddb_entry->def_timeout) : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06001636 ddb_entry->default_time2wait =
1637 le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1638
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001639 /* Update params */
1640 conn->max_recv_dlength = BYTE_UNITS *
1641 le16_to_cpu(fw_ddb_entry->iscsi_max_rcv_data_seg_len);
1642
1643 conn->max_xmit_dlength = BYTE_UNITS *
1644 le16_to_cpu(fw_ddb_entry->iscsi_max_snd_data_seg_len);
1645
1646 sess->initial_r2t_en =
1647 (BIT_10 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1648
1649 sess->max_r2t = le16_to_cpu(fw_ddb_entry->iscsi_max_outsnd_r2t);
1650
1651 sess->imm_data_en = (BIT_11 & le16_to_cpu(fw_ddb_entry->iscsi_options));
1652
1653 sess->first_burst = BYTE_UNITS *
1654 le16_to_cpu(fw_ddb_entry->iscsi_first_burst_len);
1655
1656 sess->max_burst = BYTE_UNITS *
1657 le16_to_cpu(fw_ddb_entry->iscsi_max_burst_len);
1658
1659 sess->time2wait = le16_to_cpu(fw_ddb_entry->iscsi_def_time2wait);
1660
1661 sess->time2retain = le16_to_cpu(fw_ddb_entry->iscsi_def_time2retain);
1662
1663 sess->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
1664
1665 memcpy(sess->initiatorname, ha->name_string,
1666 min(sizeof(ha->name_string), sizeof(sess->initiatorname)));
Mike Christie13483732011-12-01 21:38:41 -06001667
1668exit_session_conn_param:
1669 if (fw_ddb_entry)
1670 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
1671 fw_ddb_entry, fw_ddb_entry_dma);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001672}
1673
David Somayajuluafaf5a22006-09-19 10:28:00 -07001674/*
1675 * Timer routines
1676 */
1677
1678static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func,
1679 unsigned long interval)
1680{
1681 DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n",
1682 __func__, ha->host->host_no));
1683 init_timer(&ha->timer);
1684 ha->timer.expires = jiffies + interval * HZ;
1685 ha->timer.data = (unsigned long)ha;
1686 ha->timer.function = (void (*)(unsigned long))func;
1687 add_timer(&ha->timer);
1688 ha->timer_active = 1;
1689}
1690
1691static void qla4xxx_stop_timer(struct scsi_qla_host *ha)
1692{
1693 del_timer_sync(&ha->timer);
1694 ha->timer_active = 0;
1695}
1696
1697/***
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001698 * qla4xxx_mark_device_missing - blocks the session
1699 * @cls_session: Pointer to the session to be blocked
David Somayajuluafaf5a22006-09-19 10:28:00 -07001700 * @ddb_entry: Pointer to device database entry
1701 *
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301702 * This routine marks a device missing and close connection.
David Somayajuluafaf5a22006-09-19 10:28:00 -07001703 **/
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001704void qla4xxx_mark_device_missing(struct iscsi_cls_session *cls_session)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001705{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001706 iscsi_block_session(cls_session);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001707}
1708
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301709/**
1710 * qla4xxx_mark_all_devices_missing - mark all devices as missing.
1711 * @ha: Pointer to host adapter structure.
1712 *
1713 * This routine marks a device missing and resets the relogin retry count.
1714 **/
1715void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha)
1716{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001717 iscsi_host_for_each_session(ha->host, qla4xxx_mark_device_missing);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301718}
1719
David Somayajuluafaf5a22006-09-19 10:28:00 -07001720static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
1721 struct ddb_entry *ddb_entry,
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001722 struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001723{
1724 struct srb *srb;
1725
1726 srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
1727 if (!srb)
1728 return srb;
1729
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301730 kref_init(&srb->srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001731 srb->ha = ha;
1732 srb->ddb = ddb_entry;
1733 srb->cmd = cmd;
1734 srb->flags = 0;
Vikas Chaudhary53698872010-04-28 11:41:59 +05301735 CMD_SP(cmd) = (void *)srb;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001736
1737 return srb;
1738}
1739
1740static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
1741{
1742 struct scsi_cmnd *cmd = srb->cmd;
1743
1744 if (srb->flags & SRB_DMA_VALID) {
FUJITA Tomonori5f7186c2007-05-26 14:08:20 +09001745 scsi_dma_unmap(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001746 srb->flags &= ~SRB_DMA_VALID;
1747 }
Vikas Chaudhary53698872010-04-28 11:41:59 +05301748 CMD_SP(cmd) = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001749}
1750
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301751void qla4xxx_srb_compl(struct kref *ref)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001752{
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301753 struct srb *srb = container_of(ref, struct srb, srb_ref);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001754 struct scsi_cmnd *cmd = srb->cmd;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05301755 struct scsi_qla_host *ha = srb->ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001756
1757 qla4xxx_srb_free_dma(ha, srb);
1758
1759 mempool_free(srb, ha->srb_mempool);
1760
1761 cmd->scsi_done(cmd);
1762}
1763
1764/**
1765 * qla4xxx_queuecommand - scsi layer issues scsi command to driver.
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001766 * @host: scsi host
David Somayajuluafaf5a22006-09-19 10:28:00 -07001767 * @cmd: Pointer to Linux's SCSI command structure
David Somayajuluafaf5a22006-09-19 10:28:00 -07001768 *
1769 * Remarks:
1770 * This routine is invoked by Linux to send a SCSI command to the driver.
1771 * The mid-level driver tries to ensure that queuecommand never gets
1772 * invoked concurrently with itself or the interrupt handler (although
1773 * the interrupt handler may call this routine as part of request-
1774 * completion handling). Unfortunely, it sometimes calls the scheduler
1775 * in interrupt context which is a big NO! NO!.
1776 **/
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001777static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001778{
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001779 struct scsi_qla_host *ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001780 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christie7fb19212008-01-31 13:36:45 -06001781 struct iscsi_cls_session *sess = ddb_entry->sess;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001782 struct srb *srb;
1783 int rval;
1784
Lalit Chandivade2232be02010-07-30 14:38:47 +05301785 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
1786 if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags))
1787 cmd->result = DID_NO_CONNECT << 16;
1788 else
1789 cmd->result = DID_REQUEUE << 16;
1790 goto qc_fail_command;
1791 }
1792
Mike Christie7fb19212008-01-31 13:36:45 -06001793 if (!sess) {
1794 cmd->result = DID_IMM_RETRY << 16;
1795 goto qc_fail_command;
1796 }
1797
1798 rval = iscsi_session_chkready(sess);
1799 if (rval) {
1800 cmd->result = rval;
1801 goto qc_fail_command;
1802 }
1803
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301804 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
1805 test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
1806 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
1807 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
1808 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
1809 !test_bit(AF_ONLINE, &ha->flags) ||
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001810 !test_bit(AF_LINK_UP, &ha->flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301811 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))
David C Somayajulu477ffb92007-01-22 12:26:11 -08001812 goto qc_host_busy;
1813
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001814 srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001815 if (!srb)
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001816 goto qc_host_busy;
David Somayajuluafaf5a22006-09-19 10:28:00 -07001817
1818 rval = qla4xxx_send_command_to_isp(ha, srb);
1819 if (rval != QLA_SUCCESS)
1820 goto qc_host_busy_free_sp;
1821
David Somayajuluafaf5a22006-09-19 10:28:00 -07001822 return 0;
1823
1824qc_host_busy_free_sp:
1825 qla4xxx_srb_free_dma(ha, srb);
1826 mempool_free(srb, ha->srb_mempool);
1827
David Somayajuluafaf5a22006-09-19 10:28:00 -07001828qc_host_busy:
1829 return SCSI_MLQUEUE_HOST_BUSY;
1830
1831qc_fail_command:
Vikas Chaudhary8f0722c2011-05-17 23:17:10 -07001832 cmd->scsi_done(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07001833
1834 return 0;
1835}
1836
1837/**
1838 * qla4xxx_mem_free - frees memory allocated to adapter
1839 * @ha: Pointer to host adapter structure.
1840 *
1841 * Frees memory previously allocated by qla4xxx_mem_alloc
1842 **/
1843static void qla4xxx_mem_free(struct scsi_qla_host *ha)
1844{
1845 if (ha->queues)
1846 dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues,
1847 ha->queues_dma);
1848
1849 ha->queues_len = 0;
1850 ha->queues = NULL;
1851 ha->queues_dma = 0;
1852 ha->request_ring = NULL;
1853 ha->request_dma = 0;
1854 ha->response_ring = NULL;
1855 ha->response_dma = 0;
1856 ha->shadow_regs = NULL;
1857 ha->shadow_regs_dma = 0;
1858
1859 /* Free srb pool. */
1860 if (ha->srb_mempool)
1861 mempool_destroy(ha->srb_mempool);
1862
1863 ha->srb_mempool = NULL;
1864
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001865 if (ha->chap_dma_pool)
1866 dma_pool_destroy(ha->chap_dma_pool);
1867
Lalit Chandivade45494152011-10-07 16:55:42 -07001868 if (ha->chap_list)
1869 vfree(ha->chap_list);
1870 ha->chap_list = NULL;
1871
Mike Christie13483732011-12-01 21:38:41 -06001872 if (ha->fw_ddb_dma_pool)
1873 dma_pool_destroy(ha->fw_ddb_dma_pool);
1874
David Somayajuluafaf5a22006-09-19 10:28:00 -07001875 /* release io space registers */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301876 if (is_qla8022(ha)) {
1877 if (ha->nx_pcibase)
1878 iounmap(
1879 (struct device_reg_82xx __iomem *)ha->nx_pcibase);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05301880 } else if (ha->reg)
David Somayajuluafaf5a22006-09-19 10:28:00 -07001881 iounmap(ha->reg);
1882 pci_release_regions(ha->pdev);
1883}
1884
1885/**
1886 * qla4xxx_mem_alloc - allocates memory for use by adapter.
1887 * @ha: Pointer to host adapter structure
1888 *
1889 * Allocates DMA memory for request and response queues. Also allocates memory
1890 * for srbs.
1891 **/
1892static int qla4xxx_mem_alloc(struct scsi_qla_host *ha)
1893{
1894 unsigned long align;
1895
1896 /* Allocate contiguous block of DMA memory for queues. */
1897 ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1898 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) +
1899 sizeof(struct shadow_regs) +
1900 MEM_ALIGN_VALUE +
1901 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
1902 ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
1903 &ha->queues_dma, GFP_KERNEL);
1904 if (ha->queues == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301905 ql4_printk(KERN_WARNING, ha,
1906 "Memory Allocation failed - queues.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001907
1908 goto mem_alloc_error_exit;
1909 }
1910 memset(ha->queues, 0, ha->queues_len);
1911
1912 /*
1913 * As per RISC alignment requirements -- the bus-address must be a
1914 * multiple of the request-ring size (in bytes).
1915 */
1916 align = 0;
1917 if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1))
1918 align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma &
1919 (MEM_ALIGN_VALUE - 1));
1920
1921 /* Update request and response queue pointers. */
1922 ha->request_dma = ha->queues_dma + align;
1923 ha->request_ring = (struct queue_entry *) (ha->queues + align);
1924 ha->response_dma = ha->queues_dma + align +
1925 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE);
1926 ha->response_ring = (struct queue_entry *) (ha->queues + align +
1927 (REQUEST_QUEUE_DEPTH *
1928 QUEUE_SIZE));
1929 ha->shadow_regs_dma = ha->queues_dma + align +
1930 (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) +
1931 (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE);
1932 ha->shadow_regs = (struct shadow_regs *) (ha->queues + align +
1933 (REQUEST_QUEUE_DEPTH *
1934 QUEUE_SIZE) +
1935 (RESPONSE_QUEUE_DEPTH *
1936 QUEUE_SIZE));
1937
1938 /* Allocate memory for srb pool. */
1939 ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab,
1940 mempool_free_slab, srb_cachep);
1941 if (ha->srb_mempool == NULL) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05301942 ql4_printk(KERN_WARNING, ha,
1943 "Memory Allocation failed - SRB Pool.\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07001944
1945 goto mem_alloc_error_exit;
1946 }
1947
Manish Rangankarb3a271a2011-07-25 13:48:53 -05001948 ha->chap_dma_pool = dma_pool_create("ql4_chap", &ha->pdev->dev,
1949 CHAP_DMA_BLOCK_SIZE, 8, 0);
1950
1951 if (ha->chap_dma_pool == NULL) {
1952 ql4_printk(KERN_WARNING, ha,
1953 "%s: chap_dma_pool allocation failed..\n", __func__);
1954 goto mem_alloc_error_exit;
1955 }
1956
Mike Christie13483732011-12-01 21:38:41 -06001957 ha->fw_ddb_dma_pool = dma_pool_create("ql4_fw_ddb", &ha->pdev->dev,
1958 DDB_DMA_BLOCK_SIZE, 8, 0);
1959
1960 if (ha->fw_ddb_dma_pool == NULL) {
1961 ql4_printk(KERN_WARNING, ha,
1962 "%s: fw_ddb_dma_pool allocation failed..\n",
1963 __func__);
1964 goto mem_alloc_error_exit;
1965 }
1966
David Somayajuluafaf5a22006-09-19 10:28:00 -07001967 return QLA_SUCCESS;
1968
1969mem_alloc_error_exit:
1970 qla4xxx_mem_free(ha);
1971 return QLA_ERROR;
1972}
1973
1974/**
Mike Hernandez4f770832012-01-11 02:44:15 -08001975 * qla4_8xxx_check_temp - Check the ISP82XX temperature.
1976 * @ha: adapter block pointer.
1977 *
1978 * Note: The caller should not hold the idc lock.
1979 **/
1980static int qla4_8xxx_check_temp(struct scsi_qla_host *ha)
1981{
1982 uint32_t temp, temp_state, temp_val;
1983 int status = QLA_SUCCESS;
1984
1985 temp = qla4_8xxx_rd_32(ha, CRB_TEMP_STATE);
1986
1987 temp_state = qla82xx_get_temp_state(temp);
1988 temp_val = qla82xx_get_temp_val(temp);
1989
1990 if (temp_state == QLA82XX_TEMP_PANIC) {
1991 ql4_printk(KERN_WARNING, ha, "Device temperature %d degrees C"
1992 " exceeds maximum allowed. Hardware has been shut"
1993 " down.\n", temp_val);
1994 status = QLA_ERROR;
1995 } else if (temp_state == QLA82XX_TEMP_WARN) {
1996 if (ha->temperature == QLA82XX_TEMP_NORMAL)
1997 ql4_printk(KERN_WARNING, ha, "Device temperature %d"
1998 " degrees C exceeds operating range."
1999 " Immediate action needed.\n", temp_val);
2000 } else {
2001 if (ha->temperature == QLA82XX_TEMP_WARN)
2002 ql4_printk(KERN_INFO, ha, "Device temperature is"
2003 " now %d degrees C in normal range.\n",
2004 temp_val);
2005 }
2006 ha->temperature = temp_state;
2007 return status;
2008}
2009
2010/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302011 * qla4_8xxx_check_fw_alive - Check firmware health
2012 * @ha: Pointer to host adapter structure.
2013 *
2014 * Context: Interrupt
2015 **/
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002016static int qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302017{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002018 uint32_t fw_heartbeat_counter;
2019 int status = QLA_SUCCESS;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302020
2021 fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05302022 /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */
2023 if (fw_heartbeat_counter == 0xffffffff) {
2024 DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen "
2025 "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n",
2026 ha->host_no, __func__));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002027 return status;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302028 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302029
2030 if (ha->fw_heartbeat_counter == fw_heartbeat_counter) {
2031 ha->seconds_since_last_heartbeat++;
2032 /* FW not alive after 2 seconds */
2033 if (ha->seconds_since_last_heartbeat == 2) {
2034 ha->seconds_since_last_heartbeat = 0;
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07002035
2036 ql4_printk(KERN_INFO, ha,
2037 "scsi(%ld): %s, Dumping hw/fw registers:\n "
2038 " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:"
2039 " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:"
2040 " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:"
2041 " 0x%x,\n PEG_NET_4_PC: 0x%x\n",
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002042 ha->host_no, __func__,
2043 qla4_8xxx_rd_32(ha,
2044 QLA82XX_PEG_HALT_STATUS1),
Vikas Chaudhary68d92eb2011-05-17 23:17:05 -07002045 qla4_8xxx_rd_32(ha,
2046 QLA82XX_PEG_HALT_STATUS2),
2047 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 +
2048 0x3c),
2049 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 +
2050 0x3c),
2051 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 +
2052 0x3c),
2053 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 +
2054 0x3c),
2055 qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 +
2056 0x3c));
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002057 status = QLA_ERROR;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302058 }
Lalit Chandivade99457d72010-10-06 22:49:32 -07002059 } else
2060 ha->seconds_since_last_heartbeat = 0;
2061
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302062 ha->fw_heartbeat_counter = fw_heartbeat_counter;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002063 return status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302064}
2065
2066/**
2067 * qla4_8xxx_watchdog - Poll dev state
2068 * @ha: Pointer to host adapter structure.
2069 *
2070 * Context: Interrupt
2071 **/
2072void qla4_8xxx_watchdog(struct scsi_qla_host *ha)
2073{
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002074 uint32_t dev_state, halt_status;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302075
2076 /* don't poll if reset is going on */
Lalit Chandivaded56a1f72010-12-02 22:12:45 -08002077 if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) ||
2078 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
Vikas Chaudhary977f46a2011-05-17 23:17:08 -07002079 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) {
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002080 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
Mike Hernandez4f770832012-01-11 02:44:15 -08002081
2082 if (qla4_8xxx_check_temp(ha)) {
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -08002083 ql4_printk(KERN_INFO, ha, "disabling pause"
2084 " transmit on port 0 & 1.\n");
2085 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2086 CRB_NIU_XG_PAUSE_CTL_P0 |
2087 CRB_NIU_XG_PAUSE_CTL_P1);
Mike Hernandez4f770832012-01-11 02:44:15 -08002088 set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags);
2089 qla4xxx_wake_dpc(ha);
2090 } else if (dev_state == QLA82XX_DEV_NEED_RESET &&
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302091 !test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08002092 if (!ql4xdontresethba) {
2093 ql4_printk(KERN_INFO, ha, "%s: HW State: "
2094 "NEED RESET!\n", __func__);
2095 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2096 qla4xxx_wake_dpc(ha);
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08002097 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302098 } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT &&
2099 !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
Vikas Chaudhary3930b8c2010-12-02 22:12:47 -08002100 ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n",
2101 __func__);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302102 set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags);
2103 qla4xxx_wake_dpc(ha);
2104 } else {
2105 /* Check firmware health */
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002106 if (qla4_8xxx_check_fw_alive(ha)) {
Giridhar Malavalie6bd0eb2012-01-11 02:44:16 -08002107 ql4_printk(KERN_INFO, ha, "disabling pause"
2108 " transmit on port 0 & 1.\n");
2109 qla4_8xxx_wr_32(ha, QLA82XX_CRB_NIU + 0x98,
2110 CRB_NIU_XG_PAUSE_CTL_P0 |
2111 CRB_NIU_XG_PAUSE_CTL_P1);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002112 halt_status = qla4_8xxx_rd_32(ha,
2113 QLA82XX_PEG_HALT_STATUS1);
2114
Nilesh Javali527c8b22012-01-11 02:44:17 -08002115 if (LSW(MSB(halt_status)) == 0x67)
2116 ql4_printk(KERN_ERR, ha, "%s:"
2117 " Firmware aborted with"
2118 " error code 0x00006700."
2119 " Device is being reset\n",
2120 __func__);
2121
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002122 /* Since we cannot change dev_state in interrupt
2123 * context, set appropriate DPC flag then wakeup
2124 * DPC */
2125 if (halt_status & HALT_STATUS_UNRECOVERABLE)
2126 set_bit(DPC_HA_UNRECOVERABLE,
2127 &ha->dpc_flags);
2128 else {
2129 ql4_printk(KERN_INFO, ha, "%s: detect "
2130 "abort needed!\n", __func__);
2131 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2132 }
2133 qla4xxx_mailbox_premature_completion(ha);
2134 qla4xxx_wake_dpc(ha);
2135 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302136 }
2137 }
2138}
2139
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08002140static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
Mike Christie13483732011-12-01 21:38:41 -06002141{
2142 struct iscsi_session *sess;
2143 struct ddb_entry *ddb_entry;
2144 struct scsi_qla_host *ha;
2145
2146 sess = cls_sess->dd_data;
2147 ddb_entry = sess->dd_data;
2148 ha = ddb_entry->ha;
2149
2150 if (!(ddb_entry->ddb_type == FLASH_DDB))
2151 return;
2152
2153 if (adapter_up(ha) && !test_bit(DF_RELOGIN, &ddb_entry->flags) &&
2154 !iscsi_is_session_online(cls_sess)) {
2155 if (atomic_read(&ddb_entry->retry_relogin_timer) !=
2156 INVALID_ENTRY) {
2157 if (atomic_read(&ddb_entry->retry_relogin_timer) ==
2158 0) {
2159 atomic_set(&ddb_entry->retry_relogin_timer,
2160 INVALID_ENTRY);
2161 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2162 set_bit(DF_RELOGIN, &ddb_entry->flags);
2163 DEBUG2(ql4_printk(KERN_INFO, ha,
2164 "%s: index [%d] login device\n",
2165 __func__, ddb_entry->fw_ddb_index));
2166 } else
2167 atomic_dec(&ddb_entry->retry_relogin_timer);
2168 }
2169 }
2170
2171 /* Wait for relogin to timeout */
2172 if (atomic_read(&ddb_entry->relogin_timer) &&
2173 (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) {
2174 /*
2175 * If the relogin times out and the device is
2176 * still NOT ONLINE then try and relogin again.
2177 */
2178 if (!iscsi_is_session_online(cls_sess)) {
2179 /* Reset retry relogin timer */
2180 atomic_inc(&ddb_entry->relogin_retry_count);
2181 DEBUG2(ql4_printk(KERN_INFO, ha,
2182 "%s: index[%d] relogin timed out-retrying"
2183 " relogin (%d), retry (%d)\n", __func__,
2184 ddb_entry->fw_ddb_index,
2185 atomic_read(&ddb_entry->relogin_retry_count),
2186 ddb_entry->default_time2wait + 4));
2187 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
2188 atomic_set(&ddb_entry->retry_relogin_timer,
2189 ddb_entry->default_time2wait + 4);
2190 }
2191 }
2192}
2193
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302194/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002195 * qla4xxx_timer - checks every second for work to do.
2196 * @ha: Pointer to host adapter structure.
2197 **/
2198static void qla4xxx_timer(struct scsi_qla_host *ha)
2199{
David Somayajuluafaf5a22006-09-19 10:28:00 -07002200 int start_dpc = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302201 uint16_t w;
2202
Mike Christie13483732011-12-01 21:38:41 -06002203 iscsi_host_for_each_session(ha->host, qla4xxx_check_relogin_flash_ddb);
2204
Lalit Chandivade2232be02010-07-30 14:38:47 +05302205 /* If we are in the middle of AER/EEH processing
2206 * skip any processing and reschedule the timer
2207 */
2208 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2209 mod_timer(&ha->timer, jiffies + HZ);
2210 return;
2211 }
2212
2213 /* Hardware read to trigger an EEH error during mailbox waits. */
2214 if (!pci_channel_offline(ha->pdev))
2215 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002216
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302217 if (is_qla8022(ha)) {
2218 qla4_8xxx_watchdog(ha);
2219 }
2220
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302221 if (!is_qla8022(ha)) {
2222 /* Check for heartbeat interval. */
2223 if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE &&
2224 ha->heartbeat_interval != 0) {
2225 ha->seconds_since_last_heartbeat++;
2226 if (ha->seconds_since_last_heartbeat >
2227 ha->heartbeat_interval + 2)
2228 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2229 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002230 }
2231
David Somayajuluafaf5a22006-09-19 10:28:00 -07002232 /* Wakeup the dpc routine for this adapter, if needed. */
Lalit Chandivade1b468072011-05-17 23:17:09 -07002233 if (start_dpc ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07002234 test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
2235 test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) ||
2236 test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302237 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07002238 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
2239 test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) ||
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302240 test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302241 test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) ||
2242 test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) ||
Lalit Chandivade1b468072011-05-17 23:17:09 -07002243 test_bit(DPC_AEN, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002244 DEBUG2(printk("scsi%ld: %s: scheduling dpc routine"
2245 " - dpc flags = 0x%lx\n",
2246 ha->host_no, __func__, ha->dpc_flags));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302247 qla4xxx_wake_dpc(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002248 }
2249
2250 /* Reschedule timer thread to call us back in one second */
2251 mod_timer(&ha->timer, jiffies + HZ);
2252
2253 DEBUG2(ha->seconds_since_last_intr++);
2254}
2255
2256/**
2257 * qla4xxx_cmd_wait - waits for all outstanding commands to complete
2258 * @ha: Pointer to host adapter structure.
2259 *
2260 * This routine stalls the driver until all outstanding commands are returned.
2261 * Caller must release the Hardware Lock prior to calling this routine.
2262 **/
2263static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
2264{
2265 uint32_t index = 0;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002266 unsigned long flags;
2267 struct scsi_cmnd *cmd;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002268
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302269 unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ);
2270
2271 DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to "
2272 "complete\n", WAIT_CMD_TOV));
2273
2274 while (!time_after_eq(jiffies, wtime)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002275 spin_lock_irqsave(&ha->hardware_lock, flags);
2276 /* Find a command that hasn't completed. */
2277 for (index = 0; index < ha->host->can_queue; index++) {
2278 cmd = scsi_host_find_tag(ha->host, index);
Mike Christiea1e00632010-10-26 05:45:30 -07002279 /*
2280 * We cannot just check if the index is valid,
2281 * becase if we are run from the scsi eh, then
2282 * the scsi/block layer is going to prevent
2283 * the tag from being released.
2284 */
2285 if (cmd != NULL && CMD_SP(cmd))
David Somayajuluafaf5a22006-09-19 10:28:00 -07002286 break;
2287 }
2288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2289
2290 /* If No Commands are pending, wait is complete */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302291 if (index == ha->host->can_queue)
2292 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002293
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302294 msleep(1000);
2295 }
2296 /* If we timed out on waiting for commands to come back
2297 * return ERROR. */
2298 return QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002299}
2300
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302301int qla4xxx_hw_reset(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002302{
David Somayajuluafaf5a22006-09-19 10:28:00 -07002303 uint32_t ctrl_status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08002304 unsigned long flags = 0;
2305
2306 DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002307
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302308 if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS)
2309 return QLA_ERROR;
2310
David Somayajuluafaf5a22006-09-19 10:28:00 -07002311 spin_lock_irqsave(&ha->hardware_lock, flags);
2312
2313 /*
2314 * If the SCSI Reset Interrupt bit is set, clear it.
2315 * Otherwise, the Soft Reset won't work.
2316 */
2317 ctrl_status = readw(&ha->reg->ctrl_status);
2318 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0)
2319 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2320
2321 /* Issue Soft Reset */
2322 writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status);
2323 readl(&ha->reg->ctrl_status);
2324
2325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302326 return QLA_SUCCESS;
David C Somayajulu477ffb92007-01-22 12:26:11 -08002327}
2328
2329/**
2330 * qla4xxx_soft_reset - performs soft reset.
2331 * @ha: Pointer to host adapter structure.
2332 **/
2333int qla4xxx_soft_reset(struct scsi_qla_host *ha)
2334{
2335 uint32_t max_wait_time;
2336 unsigned long flags = 0;
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002337 int status;
David C Somayajulu477ffb92007-01-22 12:26:11 -08002338 uint32_t ctrl_status;
2339
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002340 status = qla4xxx_hw_reset(ha);
2341 if (status != QLA_SUCCESS)
2342 return status;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002343
Vikas Chaudharyf931c532010-10-06 22:48:07 -07002344 status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002345 /* Wait until the Network Reset Intr bit is cleared */
2346 max_wait_time = RESET_INTR_TOV;
2347 do {
2348 spin_lock_irqsave(&ha->hardware_lock, flags);
2349 ctrl_status = readw(&ha->reg->ctrl_status);
2350 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2351
2352 if ((ctrl_status & CSR_NET_RESET_INTR) == 0)
2353 break;
2354
2355 msleep(1000);
2356 } while ((--max_wait_time));
2357
2358 if ((ctrl_status & CSR_NET_RESET_INTR) != 0) {
2359 DEBUG2(printk(KERN_WARNING
2360 "scsi%ld: Network Reset Intr not cleared by "
2361 "Network function, clearing it now!\n",
2362 ha->host_no));
2363 spin_lock_irqsave(&ha->hardware_lock, flags);
2364 writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status);
2365 readl(&ha->reg->ctrl_status);
2366 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2367 }
2368
2369 /* Wait until the firmware tells us the Soft Reset is done */
2370 max_wait_time = SOFT_RESET_TOV;
2371 do {
2372 spin_lock_irqsave(&ha->hardware_lock, flags);
2373 ctrl_status = readw(&ha->reg->ctrl_status);
2374 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2375
2376 if ((ctrl_status & CSR_SOFT_RESET) == 0) {
2377 status = QLA_SUCCESS;
2378 break;
2379 }
2380
2381 msleep(1000);
2382 } while ((--max_wait_time));
2383
2384 /*
2385 * Also, make sure that the SCSI Reset Interrupt bit has been cleared
2386 * after the soft reset has taken place.
2387 */
2388 spin_lock_irqsave(&ha->hardware_lock, flags);
2389 ctrl_status = readw(&ha->reg->ctrl_status);
2390 if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) {
2391 writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status);
2392 readl(&ha->reg->ctrl_status);
2393 }
2394 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2395
2396 /* If soft reset fails then most probably the bios on other
2397 * function is also enabled.
2398 * Since the initialization is sequential the other fn
2399 * wont be able to acknowledge the soft reset.
2400 * Issue a force soft reset to workaround this scenario.
2401 */
2402 if (max_wait_time == 0) {
2403 /* Issue Force Soft Reset */
2404 spin_lock_irqsave(&ha->hardware_lock, flags);
2405 writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status);
2406 readl(&ha->reg->ctrl_status);
2407 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2408 /* Wait until the firmware tells us the Soft Reset is done */
2409 max_wait_time = SOFT_RESET_TOV;
2410 do {
2411 spin_lock_irqsave(&ha->hardware_lock, flags);
2412 ctrl_status = readw(&ha->reg->ctrl_status);
2413 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2414
2415 if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) {
2416 status = QLA_SUCCESS;
2417 break;
2418 }
2419
2420 msleep(1000);
2421 } while ((--max_wait_time));
2422 }
2423
2424 return status;
2425}
2426
2427/**
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302428 * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002429 * @ha: Pointer to host adapter structure.
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302430 * @res: returned scsi status
David Somayajuluafaf5a22006-09-19 10:28:00 -07002431 *
2432 * This routine is called just prior to a HARD RESET to return all
2433 * outstanding commands back to the Operating System.
2434 * Caller should make sure that the following locks are released
2435 * before this calling routine: Hardware lock, and io_request_lock.
2436 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302437static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002438{
2439 struct srb *srb;
2440 int i;
2441 unsigned long flags;
2442
2443 spin_lock_irqsave(&ha->hardware_lock, flags);
2444 for (i = 0; i < ha->host->can_queue; i++) {
2445 srb = qla4xxx_del_from_active_array(ha, i);
2446 if (srb != NULL) {
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302447 srb->cmd->result = res;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05302448 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002449 }
2450 }
2451 spin_unlock_irqrestore(&ha->hardware_lock, flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002452}
2453
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302454void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha)
2455{
2456 clear_bit(AF_ONLINE, &ha->flags);
2457
2458 /* Disable the board */
2459 ql4_printk(KERN_INFO, ha, "Disabling the board\n");
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302460
2461 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
2462 qla4xxx_mark_all_devices_missing(ha);
2463 clear_bit(AF_INIT_DONE, &ha->flags);
2464}
2465
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002466static void qla4xxx_fail_session(struct iscsi_cls_session *cls_session)
2467{
2468 struct iscsi_session *sess;
2469 struct ddb_entry *ddb_entry;
2470
2471 sess = cls_session->dd_data;
2472 ddb_entry = sess->dd_data;
2473 ddb_entry->fw_ddb_device_state = DDB_DS_SESSION_FAILED;
Mike Christie13483732011-12-01 21:38:41 -06002474
2475 if (ddb_entry->ddb_type == FLASH_DDB)
2476 iscsi_block_session(ddb_entry->sess);
2477 else
2478 iscsi_session_failure(cls_session->dd_data,
2479 ISCSI_ERR_CONN_FAILED);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002480}
2481
David Somayajuluafaf5a22006-09-19 10:28:00 -07002482/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07002483 * qla4xxx_recover_adapter - recovers adapter after a fatal error
2484 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07002485 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302486static int qla4xxx_recover_adapter(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002487{
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302488 int status = QLA_ERROR;
2489 uint8_t reset_chip = 0;
Sarang Radke8e0f3a62011-12-01 22:42:09 -08002490 uint32_t dev_state;
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002491 unsigned long wait;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002492
2493 /* Stall incoming I/O until we are done */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302494 scsi_block_requests(ha->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002495 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002496 clear_bit(AF_LINK_UP, &ha->flags);
Mike Christie50a29ae2008-03-04 13:26:53 -06002497
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302498 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__));
David Somayajuluafaf5a22006-09-19 10:28:00 -07002499
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302500 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002501
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002502 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
2503
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302504 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
2505 reset_chip = 1;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002506
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302507 /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific)
2508 * do not reset adapter, jump to initialize_adapter */
2509 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
2510 status = QLA_SUCCESS;
2511 goto recover_ha_init_adapter;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002512 }
2513
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302514 /* For the ISP-82xx adapter, issue a stop_firmware if invoked
2515 * from eh_host_reset or ioctl module */
2516 if (is_qla8022(ha) && !reset_chip &&
2517 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) {
2518
2519 DEBUG2(ql4_printk(KERN_INFO, ha,
2520 "scsi%ld: %s - Performing stop_firmware...\n",
2521 ha->host_no, __func__));
2522 status = ha->isp_ops->reset_firmware(ha);
2523 if (status == QLA_SUCCESS) {
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07002524 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2525 qla4xxx_cmd_wait(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302526 ha->isp_ops->disable_intrs(ha);
2527 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2528 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2529 } else {
2530 /* If the stop_firmware fails then
2531 * reset the entire chip */
2532 reset_chip = 1;
2533 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2534 set_bit(DPC_RESET_HA, &ha->dpc_flags);
2535 }
2536 }
2537
2538 /* Issue full chip reset if recovering from a catastrophic error,
2539 * or if stop_firmware fails for ISP-82xx.
2540 * This is the default case for ISP-4xxx */
2541 if (!is_qla8022(ha) || reset_chip) {
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002542 if (!is_qla8022(ha))
2543 goto chip_reset;
2544
2545 /* Check if 82XX firmware is alive or not
2546 * We may have arrived here from NEED_RESET
2547 * detection only */
2548 if (test_bit(AF_FW_RECOVERY, &ha->flags))
2549 goto chip_reset;
2550
2551 wait = jiffies + (FW_ALIVE_WAIT_TOV * HZ);
2552 while (time_before(jiffies, wait)) {
2553 if (qla4_8xxx_check_fw_alive(ha)) {
2554 qla4xxx_mailbox_premature_completion(ha);
2555 break;
2556 }
2557
2558 set_current_state(TASK_UNINTERRUPTIBLE);
2559 schedule_timeout(HZ);
2560 }
2561
Nilesh Javali2bd1e2b2010-10-06 22:49:20 -07002562 if (!test_bit(AF_FW_RECOVERY, &ha->flags))
2563 qla4xxx_cmd_wait(ha);
Shyam Sunder9ee91a32011-12-01 22:42:13 -08002564chip_reset:
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302565 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2566 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
2567 DEBUG2(ql4_printk(KERN_INFO, ha,
2568 "scsi%ld: %s - Performing chip reset..\n",
2569 ha->host_no, __func__));
2570 status = ha->isp_ops->reset_chip(ha);
2571 }
2572
2573 /* Flush any pending ddb changed AENs */
2574 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
2575
2576recover_ha_init_adapter:
2577 /* Upon successful firmware/chip reset, re-initialize the adapter */
2578 if (status == QLA_SUCCESS) {
2579 /* For ISP-4xxx, force function 1 to always initialize
2580 * before function 3 to prevent both funcions from
2581 * stepping on top of the other */
2582 if (!is_qla8022(ha) && (ha->mac_index == 3))
2583 ssleep(6);
2584
2585 /* NOTE: AF_ONLINE flag set upon successful completion of
2586 * qla4xxx_initialize_adapter */
Mike Christie13483732011-12-01 21:38:41 -06002587 status = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302588 }
2589
2590 /* Retry failed adapter initialization, if necessary
2591 * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific)
2592 * case to prevent ping-pong resets between functions */
2593 if (!test_bit(AF_ONLINE, &ha->flags) &&
2594 !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002595 /* Adapter initialization failed, see if we can retry
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302596 * resetting the ha.
2597 * Since we don't want to block the DPC for too long
2598 * with multiple resets in the same thread,
2599 * utilize DPC to retry */
Sarang Radke8e0f3a62011-12-01 22:42:09 -08002600 if (is_qla8022(ha)) {
2601 qla4_8xxx_idc_lock(ha);
2602 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
2603 qla4_8xxx_idc_unlock(ha);
2604 if (dev_state == QLA82XX_DEV_FAILED) {
2605 ql4_printk(KERN_INFO, ha, "%s: don't retry "
2606 "recover adapter. H/W is in Failed "
2607 "state\n", __func__);
2608 qla4xxx_dead_adapter_cleanup(ha);
2609 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2610 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2611 clear_bit(DPC_RESET_HA_FW_CONTEXT,
2612 &ha->dpc_flags);
2613 status = QLA_ERROR;
2614
2615 goto exit_recover;
2616 }
2617 }
2618
David Somayajuluafaf5a22006-09-19 10:28:00 -07002619 if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) {
2620 ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES;
2621 DEBUG2(printk("scsi%ld: recover adapter - retrying "
2622 "(%d) more times\n", ha->host_no,
2623 ha->retry_reset_ha_cnt));
2624 set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2625 status = QLA_ERROR;
2626 } else {
2627 if (ha->retry_reset_ha_cnt > 0) {
2628 /* Schedule another Reset HA--DPC will retry */
2629 ha->retry_reset_ha_cnt--;
2630 DEBUG2(printk("scsi%ld: recover adapter - "
2631 "retry remaining %d\n",
2632 ha->host_no,
2633 ha->retry_reset_ha_cnt));
2634 status = QLA_ERROR;
2635 }
2636
2637 if (ha->retry_reset_ha_cnt == 0) {
2638 /* Recover adapter retries have been exhausted.
2639 * Adapter DEAD */
2640 DEBUG2(printk("scsi%ld: recover adapter "
2641 "failed - board disabled\n",
2642 ha->host_no));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302643 qla4xxx_dead_adapter_cleanup(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002644 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2645 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302646 clear_bit(DPC_RESET_HA_FW_CONTEXT,
David Somayajuluafaf5a22006-09-19 10:28:00 -07002647 &ha->dpc_flags);
2648 status = QLA_ERROR;
2649 }
2650 }
2651 } else {
2652 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302653 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002654 clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags);
2655 }
2656
Sarang Radke8e0f3a62011-12-01 22:42:09 -08002657exit_recover:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002658 ha->adapter_error_count++;
2659
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302660 if (test_bit(AF_ONLINE, &ha->flags))
2661 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002662
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302663 scsi_unblock_requests(ha->host);
2664
2665 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
2666 DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no,
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002667 status == QLA_ERROR ? "FAILED" : "SUCCEEDED"));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302668
David Somayajuluafaf5a22006-09-19 10:28:00 -07002669 return status;
2670}
2671
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002672static void qla4xxx_relogin_devices(struct iscsi_cls_session *cls_session)
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002673{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002674 struct iscsi_session *sess;
2675 struct ddb_entry *ddb_entry;
2676 struct scsi_qla_host *ha;
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002677
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002678 sess = cls_session->dd_data;
2679 ddb_entry = sess->dd_data;
2680 ha = ddb_entry->ha;
2681 if (!iscsi_is_session_online(cls_session)) {
2682 if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) {
2683 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2684 " unblock session\n", ha->host_no, __func__,
2685 ddb_entry->fw_ddb_index);
2686 iscsi_unblock_session(ddb_entry->sess);
2687 } else {
2688 /* Trigger relogin */
Mike Christie13483732011-12-01 21:38:41 -06002689 if (ddb_entry->ddb_type == FLASH_DDB) {
2690 if (!test_bit(DF_RELOGIN, &ddb_entry->flags))
2691 qla4xxx_arm_relogin_timer(ddb_entry);
2692 } else
2693 iscsi_session_failure(cls_session->dd_data,
2694 ISCSI_ERR_CONN_FAILED);
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002695 }
2696 }
2697}
2698
Mike Christie13483732011-12-01 21:38:41 -06002699int qla4xxx_unblock_flash_ddb(struct iscsi_cls_session *cls_session)
2700{
2701 struct iscsi_session *sess;
2702 struct ddb_entry *ddb_entry;
2703 struct scsi_qla_host *ha;
2704
2705 sess = cls_session->dd_data;
2706 ddb_entry = sess->dd_data;
2707 ha = ddb_entry->ha;
2708 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2709 " unblock session\n", ha->host_no, __func__,
2710 ddb_entry->fw_ddb_index);
2711
2712 iscsi_unblock_session(ddb_entry->sess);
2713
2714 /* Start scan target */
2715 if (test_bit(AF_ONLINE, &ha->flags)) {
2716 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2717 " start scan\n", ha->host_no, __func__,
2718 ddb_entry->fw_ddb_index);
2719 scsi_queue_work(ha->host, &ddb_entry->sess->scan_work);
2720 }
2721 return QLA_SUCCESS;
2722}
2723
2724int qla4xxx_unblock_ddb(struct iscsi_cls_session *cls_session)
2725{
2726 struct iscsi_session *sess;
2727 struct ddb_entry *ddb_entry;
2728 struct scsi_qla_host *ha;
2729
2730 sess = cls_session->dd_data;
2731 ddb_entry = sess->dd_data;
2732 ha = ddb_entry->ha;
2733 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]"
2734 " unblock user space session\n", ha->host_no, __func__,
2735 ddb_entry->fw_ddb_index);
2736 iscsi_conn_start(ddb_entry->conn);
2737 iscsi_conn_login_event(ddb_entry->conn,
2738 ISCSI_CONN_STATE_LOGGED_IN);
2739
2740 return QLA_SUCCESS;
2741}
2742
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002743static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha)
2744{
2745 iscsi_host_for_each_session(ha->host, qla4xxx_relogin_devices);
2746}
2747
Mike Christie13483732011-12-01 21:38:41 -06002748static void qla4xxx_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
2749{
2750 uint16_t relogin_timer;
2751 struct iscsi_session *sess;
2752 struct ddb_entry *ddb_entry;
2753 struct scsi_qla_host *ha;
2754
2755 sess = cls_sess->dd_data;
2756 ddb_entry = sess->dd_data;
2757 ha = ddb_entry->ha;
2758
2759 relogin_timer = max(ddb_entry->default_relogin_timeout,
2760 (uint16_t)RELOGIN_TOV);
2761 atomic_set(&ddb_entry->relogin_timer, relogin_timer);
2762
2763 DEBUG2(ql4_printk(KERN_INFO, ha,
2764 "scsi%ld: Relogin index [%d]. TOV=%d\n", ha->host_no,
2765 ddb_entry->fw_ddb_index, relogin_timer));
2766
2767 qla4xxx_login_flash_ddb(cls_sess);
2768}
2769
2770static void qla4xxx_dpc_relogin(struct iscsi_cls_session *cls_sess)
2771{
2772 struct iscsi_session *sess;
2773 struct ddb_entry *ddb_entry;
2774 struct scsi_qla_host *ha;
2775
2776 sess = cls_sess->dd_data;
2777 ddb_entry = sess->dd_data;
2778 ha = ddb_entry->ha;
2779
2780 if (!(ddb_entry->ddb_type == FLASH_DDB))
2781 return;
2782
2783 if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) &&
2784 !iscsi_is_session_online(cls_sess)) {
2785 DEBUG2(ql4_printk(KERN_INFO, ha,
2786 "relogin issued\n"));
2787 qla4xxx_relogin_flash_ddb(cls_sess);
2788 }
2789}
2790
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302791void qla4xxx_wake_dpc(struct scsi_qla_host *ha)
2792{
Lalit Chandivade1b468072011-05-17 23:17:09 -07002793 if (ha->dpc_thread)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302794 queue_work(ha->dpc_thread, &ha->dpc_work);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302795}
2796
David Somayajuluafaf5a22006-09-19 10:28:00 -07002797/**
2798 * qla4xxx_do_dpc - dpc routine
2799 * @data: in our case pointer to adapter structure
2800 *
2801 * This routine is a task that is schedule by the interrupt handler
2802 * to perform the background processing for interrupts. We put it
2803 * on a task queue that is consumed whenever the scheduler runs; that's
2804 * so you can do anything (i.e. put the process to sleep etc). In fact,
2805 * the mid-level tries to sleep when it reaches the driver threshold
2806 * "host->can_queue". This can cause a panic if we were in our interrupt code.
2807 **/
David Howellsc4028952006-11-22 14:57:56 +00002808static void qla4xxx_do_dpc(struct work_struct *work)
David Somayajuluafaf5a22006-09-19 10:28:00 -07002809{
David Howellsc4028952006-11-22 14:57:56 +00002810 struct scsi_qla_host *ha =
2811 container_of(work, struct scsi_qla_host, dpc_work);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002812 int status = QLA_ERROR;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002813
David C Somayajuluf26b9042006-11-15 16:41:09 -08002814 DEBUG2(printk("scsi%ld: %s: DPC handler waking up."
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302815 "flags = 0x%08lx, dpc_flags = 0x%08lx\n",
2816 ha->host_no, __func__, ha->flags, ha->dpc_flags))
David Somayajuluafaf5a22006-09-19 10:28:00 -07002817
2818 /* Initialization not yet finished. Don't do anything yet. */
2819 if (!test_bit(AF_INIT_DONE, &ha->flags))
Lalit Chandivade1b468072011-05-17 23:17:09 -07002820 return;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002821
Lalit Chandivade2232be02010-07-30 14:38:47 +05302822 if (test_bit(AF_EEH_BUSY, &ha->flags)) {
2823 DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n",
2824 ha->host_no, __func__, ha->flags));
Lalit Chandivade1b468072011-05-17 23:17:09 -07002825 return;
Lalit Chandivade2232be02010-07-30 14:38:47 +05302826 }
2827
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302828 if (is_qla8022(ha)) {
2829 if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) {
2830 qla4_8xxx_idc_lock(ha);
2831 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2832 QLA82XX_DEV_FAILED);
2833 qla4_8xxx_idc_unlock(ha);
2834 ql4_printk(KERN_INFO, ha, "HW State: FAILED\n");
2835 qla4_8xxx_device_state_handler(ha);
2836 }
2837 if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) {
2838 qla4_8xxx_need_qsnt_handler(ha);
2839 }
2840 }
2841
2842 if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) &&
2843 (test_bit(DPC_RESET_HA, &ha->dpc_flags) ||
David Somayajuluafaf5a22006-09-19 10:28:00 -07002844 test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) ||
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302845 test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) {
2846 if (ql4xdontresethba) {
2847 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
2848 ha->host_no, __func__));
2849 clear_bit(DPC_RESET_HA, &ha->dpc_flags);
2850 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2851 clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
2852 goto dpc_post_reset_ha;
2853 }
2854 if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) ||
2855 test_bit(DPC_RESET_HA, &ha->dpc_flags))
2856 qla4xxx_recover_adapter(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002857
David C Somayajulu477ffb92007-01-22 12:26:11 -08002858 if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07002859 uint8_t wait_time = RESET_INTR_TOV;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002860
David Somayajuluafaf5a22006-09-19 10:28:00 -07002861 while ((readw(&ha->reg->ctrl_status) &
2862 (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) {
2863 if (--wait_time == 0)
2864 break;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002865 msleep(1000);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002866 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002867 if (wait_time == 0)
2868 DEBUG2(printk("scsi%ld: %s: SR|FSR "
2869 "bit not cleared-- resetting\n",
2870 ha->host_no, __func__));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302871 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002872 if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) {
2873 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302874 status = qla4xxx_recover_adapter(ha);
David C Somayajulu477ffb92007-01-22 12:26:11 -08002875 }
2876 clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags);
2877 if (status == QLA_SUCCESS)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302878 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002879 }
2880 }
2881
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302882dpc_post_reset_ha:
David Somayajuluafaf5a22006-09-19 10:28:00 -07002883 /* ---- process AEN? --- */
2884 if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags))
2885 qla4xxx_process_aen(ha, PROCESS_ALL_AENS);
2886
2887 /* ---- Get DHCP IP Address? --- */
2888 if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags))
2889 qla4xxx_get_dhcp_ip_address(ha);
2890
Mike Christie13483732011-12-01 21:38:41 -06002891 /* ---- relogin device? --- */
2892 if (adapter_up(ha) &&
2893 test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) {
2894 iscsi_host_for_each_session(ha->host, qla4xxx_dpc_relogin);
2895 }
2896
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302897 /* ---- link change? --- */
2898 if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) {
2899 if (!test_bit(AF_LINK_UP, &ha->flags)) {
2900 /* ---- link down? --- */
Vikas Chaudhary2d7924e2011-03-21 03:34:33 -07002901 qla4xxx_mark_all_devices_missing(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302902 } else {
2903 /* ---- link up? --- *
2904 * F/W will auto login to all devices ONLY ONCE after
2905 * link up during driver initialization and runtime
2906 * fatal error recovery. Therefore, the driver must
2907 * manually relogin to devices when recovering from
2908 * connection failures, logouts, expired KATO, etc. */
Mike Christie13483732011-12-01 21:38:41 -06002909 if (test_and_clear_bit(AF_BUILD_DDB_LIST, &ha->flags)) {
2910 qla4xxx_build_ddb_list(ha, ha->is_reset);
2911 iscsi_host_for_each_session(ha->host,
2912 qla4xxx_login_flash_ddb);
2913 } else
2914 qla4xxx_relogin_all_devices(ha);
Vikas Chaudhary065aa1b2010-04-28 11:38:11 +05302915 }
2916 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07002917}
2918
2919/**
2920 * qla4xxx_free_adapter - release the adapter
2921 * @ha: pointer to adapter structure
2922 **/
2923static void qla4xxx_free_adapter(struct scsi_qla_host *ha)
2924{
Sarang Radke8a288962011-12-06 02:34:10 -08002925 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002926
2927 if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) {
2928 /* Turn-off interrupts on the card. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302929 ha->isp_ops->disable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002930 }
2931
David Somayajuluafaf5a22006-09-19 10:28:00 -07002932 /* Remove timer thread, if present */
2933 if (ha->timer_active)
2934 qla4xxx_stop_timer(ha);
2935
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302936 /* Kill the kernel thread for this host */
2937 if (ha->dpc_thread)
2938 destroy_workqueue(ha->dpc_thread);
2939
Manish Rangankarb3a271a2011-07-25 13:48:53 -05002940 /* Kill the kernel thread for this host */
2941 if (ha->task_wq)
2942 destroy_workqueue(ha->task_wq);
2943
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302944 /* Put firmware in known state */
2945 ha->isp_ops->reset_firmware(ha);
2946
2947 if (is_qla8022(ha)) {
2948 qla4_8xxx_idc_lock(ha);
2949 qla4_8xxx_clear_drv_active(ha);
2950 qla4_8xxx_idc_unlock(ha);
2951 }
2952
David Somayajuluafaf5a22006-09-19 10:28:00 -07002953 /* Detach interrupts */
2954 if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags))
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302955 qla4xxx_free_irqs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07002956
David C Somayajulubee4fe82007-05-23 18:03:32 -07002957 /* free extra memory */
2958 qla4xxx_mem_free(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302959}
David C Somayajulubee4fe82007-05-23 18:03:32 -07002960
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302961int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
2962{
2963 int status = 0;
2964 uint8_t revision_id;
2965 unsigned long mem_base, mem_len, db_base, db_len;
2966 struct pci_dev *pdev = ha->pdev;
David Somayajuluafaf5a22006-09-19 10:28:00 -07002967
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05302968 status = pci_request_regions(pdev, DRIVER_NAME);
2969 if (status) {
2970 printk(KERN_WARNING
2971 "scsi(%ld) Failed to reserve PIO regions (%s) "
2972 "status=%d\n", ha->host_no, pci_name(pdev), status);
2973 goto iospace_error_exit;
2974 }
2975
2976 pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id);
2977 DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n",
2978 __func__, revision_id));
2979 ha->revision_id = revision_id;
2980
2981 /* remap phys address */
2982 mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */
2983 mem_len = pci_resource_len(pdev, 0);
2984 DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n",
2985 __func__, mem_base, mem_len));
2986
2987 /* mapping of pcibase pointer */
2988 ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len);
2989 if (!ha->nx_pcibase) {
2990 printk(KERN_ERR
2991 "cannot remap MMIO (%s), aborting\n", pci_name(pdev));
2992 pci_release_regions(ha->pdev);
2993 goto iospace_error_exit;
2994 }
2995
2996 /* Mapping of IO base pointer, door bell read and write pointer */
2997
2998 /* mapping of IO base pointer */
2999 ha->qla4_8xxx_reg =
3000 (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase +
3001 0xbc000 + (ha->pdev->devfn << 11));
3002
3003 db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
3004 db_len = pci_resource_len(pdev, 4);
3005
Shyam Sundar2657c802010-10-06 22:50:29 -07003006 ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 :
3007 QLA82XX_CAM_RAM_DB2);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303008
Shyam Sundar2657c802010-10-06 22:50:29 -07003009 return 0;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303010iospace_error_exit:
3011 return -ENOMEM;
David Somayajuluafaf5a22006-09-19 10:28:00 -07003012}
3013
3014/***
3015 * qla4xxx_iospace_config - maps registers
3016 * @ha: pointer to adapter structure
3017 *
3018 * This routines maps HBA's registers from the pci address space
3019 * into the kernel virtual address space for memory mapped i/o.
3020 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303021int qla4xxx_iospace_config(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07003022{
3023 unsigned long pio, pio_len, pio_flags;
3024 unsigned long mmio, mmio_len, mmio_flags;
3025
3026 pio = pci_resource_start(ha->pdev, 0);
3027 pio_len = pci_resource_len(ha->pdev, 0);
3028 pio_flags = pci_resource_flags(ha->pdev, 0);
3029 if (pio_flags & IORESOURCE_IO) {
3030 if (pio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303031 ql4_printk(KERN_WARNING, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07003032 "Invalid PCI I/O region size\n");
3033 pio = 0;
3034 }
3035 } else {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303036 ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003037 pio = 0;
3038 }
3039
3040 /* Use MMIO operations for all accesses. */
3041 mmio = pci_resource_start(ha->pdev, 1);
3042 mmio_len = pci_resource_len(ha->pdev, 1);
3043 mmio_flags = pci_resource_flags(ha->pdev, 1);
3044
3045 if (!(mmio_flags & IORESOURCE_MEM)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303046 ql4_printk(KERN_ERR, ha,
3047 "region #0 not an MMIO resource, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003048
3049 goto iospace_error_exit;
3050 }
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303051
David Somayajuluafaf5a22006-09-19 10:28:00 -07003052 if (mmio_len < MIN_IOBASE_LEN) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303053 ql4_printk(KERN_ERR, ha,
3054 "Invalid PCI mem region size, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003055 goto iospace_error_exit;
3056 }
3057
3058 if (pci_request_regions(ha->pdev, DRIVER_NAME)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303059 ql4_printk(KERN_WARNING, ha,
3060 "Failed to reserve PIO/MMIO regions\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003061
3062 goto iospace_error_exit;
3063 }
3064
3065 ha->pio_address = pio;
3066 ha->pio_length = pio_len;
3067 ha->reg = ioremap(mmio, MIN_IOBASE_LEN);
3068 if (!ha->reg) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05303069 ql4_printk(KERN_ERR, ha,
3070 "cannot remap MMIO, aborting\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07003071
3072 goto iospace_error_exit;
3073 }
3074
3075 return 0;
3076
3077iospace_error_exit:
3078 return -ENOMEM;
3079}
3080
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05303081static struct isp_operations qla4xxx_isp_ops = {
3082 .iospace_config = qla4xxx_iospace_config,
3083 .pci_config = qla4xxx_pci_config,
3084 .disable_intrs = qla4xxx_disable_intrs,
3085 .enable_intrs = qla4xxx_enable_intrs,
3086 .start_firmware = qla4xxx_start_firmware,
3087 .intr_handler = qla4xxx_intr_handler,
3088 .interrupt_service_routine = qla4xxx_interrupt_service_routine,
3089 .reset_chip = qla4xxx_soft_reset,
3090 .reset_firmware = qla4xxx_hw_reset,
3091 .queue_iocb = qla4xxx_queue_iocb,
3092 .complete_iocb = qla4xxx_complete_iocb,
3093 .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out,
3094 .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in,
3095 .get_sys_info = qla4xxx_get_sys_info,
3096};
3097
3098static struct isp_operations qla4_8xxx_isp_ops = {
3099 .iospace_config = qla4_8xxx_iospace_config,
3100 .pci_config = qla4_8xxx_pci_config,
3101 .disable_intrs = qla4_8xxx_disable_intrs,
3102 .enable_intrs = qla4_8xxx_enable_intrs,
3103 .start_firmware = qla4_8xxx_load_risc,
3104 .intr_handler = qla4_8xxx_intr_handler,
3105 .interrupt_service_routine = qla4_8xxx_interrupt_service_routine,
3106 .reset_chip = qla4_8xxx_isp_reset,
3107 .reset_firmware = qla4_8xxx_stop_firmware,
3108 .queue_iocb = qla4_8xxx_queue_iocb,
3109 .complete_iocb = qla4_8xxx_complete_iocb,
3110 .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out,
3111 .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in,
3112 .get_sys_info = qla4_8xxx_get_sys_info,
3113};
3114
3115uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3116{
3117 return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out);
3118}
3119
3120uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha)
3121{
3122 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out));
3123}
3124
3125uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3126{
3127 return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in);
3128}
3129
3130uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha)
3131{
3132 return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in));
3133}
3134
Manish Rangankar2a991c22011-07-25 13:48:55 -05003135static ssize_t qla4xxx_show_boot_eth_info(void *data, int type, char *buf)
3136{
3137 struct scsi_qla_host *ha = data;
3138 char *str = buf;
3139 int rc;
3140
3141 switch (type) {
3142 case ISCSI_BOOT_ETH_FLAGS:
3143 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3144 break;
3145 case ISCSI_BOOT_ETH_INDEX:
3146 rc = sprintf(str, "0\n");
3147 break;
3148 case ISCSI_BOOT_ETH_MAC:
3149 rc = sysfs_format_mac(str, ha->my_mac,
3150 MAC_ADDR_LEN);
3151 break;
3152 default:
3153 rc = -ENOSYS;
3154 break;
3155 }
3156 return rc;
3157}
3158
Al Viro587a1f12011-07-23 23:11:19 -04003159static umode_t qla4xxx_eth_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05003160{
3161 int rc;
3162
3163 switch (type) {
3164 case ISCSI_BOOT_ETH_FLAGS:
3165 case ISCSI_BOOT_ETH_MAC:
3166 case ISCSI_BOOT_ETH_INDEX:
3167 rc = S_IRUGO;
3168 break;
3169 default:
3170 rc = 0;
3171 break;
3172 }
3173 return rc;
3174}
3175
3176static ssize_t qla4xxx_show_boot_ini_info(void *data, int type, char *buf)
3177{
3178 struct scsi_qla_host *ha = data;
3179 char *str = buf;
3180 int rc;
3181
3182 switch (type) {
3183 case ISCSI_BOOT_INI_INITIATOR_NAME:
3184 rc = sprintf(str, "%s\n", ha->name_string);
3185 break;
3186 default:
3187 rc = -ENOSYS;
3188 break;
3189 }
3190 return rc;
3191}
3192
Al Viro587a1f12011-07-23 23:11:19 -04003193static umode_t qla4xxx_ini_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05003194{
3195 int rc;
3196
3197 switch (type) {
3198 case ISCSI_BOOT_INI_INITIATOR_NAME:
3199 rc = S_IRUGO;
3200 break;
3201 default:
3202 rc = 0;
3203 break;
3204 }
3205 return rc;
3206}
3207
3208static ssize_t
3209qla4xxx_show_boot_tgt_info(struct ql4_boot_session_info *boot_sess, int type,
3210 char *buf)
3211{
3212 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3213 char *str = buf;
3214 int rc;
3215
3216 switch (type) {
3217 case ISCSI_BOOT_TGT_NAME:
3218 rc = sprintf(buf, "%s\n", (char *)&boot_sess->target_name);
3219 break;
3220 case ISCSI_BOOT_TGT_IP_ADDR:
3221 if (boot_sess->conn_list[0].dest_ipaddr.ip_type == 0x1)
3222 rc = sprintf(buf, "%pI4\n",
3223 &boot_conn->dest_ipaddr.ip_address);
3224 else
3225 rc = sprintf(str, "%pI6\n",
3226 &boot_conn->dest_ipaddr.ip_address);
3227 break;
3228 case ISCSI_BOOT_TGT_PORT:
3229 rc = sprintf(str, "%d\n", boot_conn->dest_port);
3230 break;
3231 case ISCSI_BOOT_TGT_CHAP_NAME:
3232 rc = sprintf(str, "%.*s\n",
3233 boot_conn->chap.target_chap_name_length,
3234 (char *)&boot_conn->chap.target_chap_name);
3235 break;
3236 case ISCSI_BOOT_TGT_CHAP_SECRET:
3237 rc = sprintf(str, "%.*s\n",
3238 boot_conn->chap.target_secret_length,
3239 (char *)&boot_conn->chap.target_secret);
3240 break;
3241 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3242 rc = sprintf(str, "%.*s\n",
3243 boot_conn->chap.intr_chap_name_length,
3244 (char *)&boot_conn->chap.intr_chap_name);
3245 break;
3246 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3247 rc = sprintf(str, "%.*s\n",
3248 boot_conn->chap.intr_secret_length,
3249 (char *)&boot_conn->chap.intr_secret);
3250 break;
3251 case ISCSI_BOOT_TGT_FLAGS:
3252 rc = sprintf(str, "%d\n", SYSFS_FLAG_FW_SEL_BOOT);
3253 break;
3254 case ISCSI_BOOT_TGT_NIC_ASSOC:
3255 rc = sprintf(str, "0\n");
3256 break;
3257 default:
3258 rc = -ENOSYS;
3259 break;
3260 }
3261 return rc;
3262}
3263
3264static ssize_t qla4xxx_show_boot_tgt_pri_info(void *data, int type, char *buf)
3265{
3266 struct scsi_qla_host *ha = data;
3267 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_pri_sess);
3268
3269 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3270}
3271
3272static ssize_t qla4xxx_show_boot_tgt_sec_info(void *data, int type, char *buf)
3273{
3274 struct scsi_qla_host *ha = data;
3275 struct ql4_boot_session_info *boot_sess = &(ha->boot_tgt.boot_sec_sess);
3276
3277 return qla4xxx_show_boot_tgt_info(boot_sess, type, buf);
3278}
3279
Al Viro587a1f12011-07-23 23:11:19 -04003280static umode_t qla4xxx_tgt_get_attr_visibility(void *data, int type)
Manish Rangankar2a991c22011-07-25 13:48:55 -05003281{
3282 int rc;
3283
3284 switch (type) {
3285 case ISCSI_BOOT_TGT_NAME:
3286 case ISCSI_BOOT_TGT_IP_ADDR:
3287 case ISCSI_BOOT_TGT_PORT:
3288 case ISCSI_BOOT_TGT_CHAP_NAME:
3289 case ISCSI_BOOT_TGT_CHAP_SECRET:
3290 case ISCSI_BOOT_TGT_REV_CHAP_NAME:
3291 case ISCSI_BOOT_TGT_REV_CHAP_SECRET:
3292 case ISCSI_BOOT_TGT_NIC_ASSOC:
3293 case ISCSI_BOOT_TGT_FLAGS:
3294 rc = S_IRUGO;
3295 break;
3296 default:
3297 rc = 0;
3298 break;
3299 }
3300 return rc;
3301}
3302
3303static void qla4xxx_boot_release(void *data)
3304{
3305 struct scsi_qla_host *ha = data;
3306
3307 scsi_host_put(ha->host);
3308}
3309
3310static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
3311{
3312 dma_addr_t buf_dma;
3313 uint32_t addr, pri_addr, sec_addr;
3314 uint32_t offset;
3315 uint16_t func_num;
3316 uint8_t val;
3317 uint8_t *buf = NULL;
3318 size_t size = 13 * sizeof(uint8_t);
3319 int ret = QLA_SUCCESS;
3320
3321 func_num = PCI_FUNC(ha->pdev->devfn);
3322
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07003323 ql4_printk(KERN_INFO, ha, "%s: Get FW boot info for 0x%x func %d\n",
3324 __func__, ha->pdev->device, func_num);
Manish Rangankar2a991c22011-07-25 13:48:55 -05003325
Manish Rangankar0d5b36b2011-10-07 16:55:51 -07003326 if (is_qla40XX(ha)) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05003327 if (func_num == 1) {
3328 addr = NVRAM_PORT0_BOOT_MODE;
3329 pri_addr = NVRAM_PORT0_BOOT_PRI_TGT;
3330 sec_addr = NVRAM_PORT0_BOOT_SEC_TGT;
3331 } else if (func_num == 3) {
3332 addr = NVRAM_PORT1_BOOT_MODE;
3333 pri_addr = NVRAM_PORT1_BOOT_PRI_TGT;
3334 sec_addr = NVRAM_PORT1_BOOT_SEC_TGT;
3335 } else {
3336 ret = QLA_ERROR;
3337 goto exit_boot_info;
3338 }
3339
3340 /* Check Boot Mode */
3341 val = rd_nvram_byte(ha, addr);
3342 if (!(val & 0x07)) {
3343 DEBUG2(ql4_printk(KERN_ERR, ha,
3344 "%s: Failed Boot options : 0x%x\n",
3345 __func__, val));
3346 ret = QLA_ERROR;
3347 goto exit_boot_info;
3348 }
3349
3350 /* get primary valid target index */
3351 val = rd_nvram_byte(ha, pri_addr);
3352 if (val & BIT_7)
3353 ddb_index[0] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05003354
3355 /* get secondary valid target index */
3356 val = rd_nvram_byte(ha, sec_addr);
3357 if (val & BIT_7)
3358 ddb_index[1] = (val & 0x7f);
Manish Rangankar2a991c22011-07-25 13:48:55 -05003359
3360 } else if (is_qla8022(ha)) {
3361 buf = dma_alloc_coherent(&ha->pdev->dev, size,
3362 &buf_dma, GFP_KERNEL);
3363 if (!buf) {
3364 DEBUG2(ql4_printk(KERN_ERR, ha,
3365 "%s: Unable to allocate dma buffer\n",
3366 __func__));
3367 ret = QLA_ERROR;
3368 goto exit_boot_info;
3369 }
3370
3371 if (ha->port_num == 0)
3372 offset = BOOT_PARAM_OFFSET_PORT0;
3373 else if (ha->port_num == 1)
3374 offset = BOOT_PARAM_OFFSET_PORT1;
3375 else {
3376 ret = QLA_ERROR;
3377 goto exit_boot_info_free;
3378 }
3379 addr = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_iscsi_param * 4) +
3380 offset;
3381 if (qla4xxx_get_flash(ha, buf_dma, addr,
3382 13 * sizeof(uint8_t)) != QLA_SUCCESS) {
3383 DEBUG2(ql4_printk(KERN_ERR, ha, "scsi%ld: %s: Get Flash"
3384 "failed\n", ha->host_no, __func__));
3385 ret = QLA_ERROR;
3386 goto exit_boot_info_free;
3387 }
3388 /* Check Boot Mode */
3389 if (!(buf[1] & 0x07)) {
3390 DEBUG2(ql4_printk(KERN_INFO, ha,
3391 "Failed: Boot options : 0x%x\n",
3392 buf[1]));
3393 ret = QLA_ERROR;
3394 goto exit_boot_info_free;
3395 }
3396
3397 /* get primary valid target index */
3398 if (buf[2] & BIT_7)
3399 ddb_index[0] = buf[2] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003400
3401 /* get secondary valid target index */
3402 if (buf[11] & BIT_7)
3403 ddb_index[1] = buf[11] & 0x7f;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003404 } else {
3405 ret = QLA_ERROR;
3406 goto exit_boot_info;
3407 }
3408
3409 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Primary target ID %d, Secondary"
3410 " target ID %d\n", __func__, ddb_index[0],
3411 ddb_index[1]));
3412
Mike Christie13483732011-12-01 21:38:41 -06003413 ha->pri_ddb_idx = ddb_index[0];
3414 ha->sec_ddb_idx = ddb_index[1];
3415
Manish Rangankar2a991c22011-07-25 13:48:55 -05003416exit_boot_info_free:
3417 dma_free_coherent(&ha->pdev->dev, size, buf, buf_dma);
3418exit_boot_info:
3419 return ret;
3420}
3421
Lalit Chandivade28deb452011-10-07 16:55:44 -07003422/**
3423 * qla4xxx_get_bidi_chap - Get a BIDI CHAP user and password
3424 * @ha: pointer to adapter structure
3425 * @username: CHAP username to be returned
3426 * @password: CHAP password to be returned
3427 *
3428 * If a boot entry has BIDI CHAP enabled then we need to set the BIDI CHAP
3429 * user and password in the sysfs entry in /sys/firmware/iscsi_boot#/.
3430 * So from the CHAP cache find the first BIDI CHAP entry and set it
3431 * to the boot record in sysfs.
3432 **/
3433static int qla4xxx_get_bidi_chap(struct scsi_qla_host *ha, char *username,
3434 char *password)
3435{
3436 int i, ret = -EINVAL;
3437 int max_chap_entries = 0;
3438 struct ql4_chap_table *chap_table;
3439
3440 if (is_qla8022(ha))
3441 max_chap_entries = (ha->hw.flt_chap_size / 2) /
3442 sizeof(struct ql4_chap_table);
3443 else
3444 max_chap_entries = MAX_CHAP_ENTRIES_40XX;
3445
3446 if (!ha->chap_list) {
3447 ql4_printk(KERN_ERR, ha, "Do not have CHAP table cache\n");
3448 return ret;
3449 }
3450
3451 mutex_lock(&ha->chap_sem);
3452 for (i = 0; i < max_chap_entries; i++) {
3453 chap_table = (struct ql4_chap_table *)ha->chap_list + i;
3454 if (chap_table->cookie !=
3455 __constant_cpu_to_le16(CHAP_VALID_COOKIE)) {
3456 continue;
3457 }
3458
3459 if (chap_table->flags & BIT_7) /* local */
3460 continue;
3461
3462 if (!(chap_table->flags & BIT_6)) /* Not BIDI */
3463 continue;
3464
3465 strncpy(password, chap_table->secret, QL4_CHAP_MAX_SECRET_LEN);
3466 strncpy(username, chap_table->name, QL4_CHAP_MAX_NAME_LEN);
3467 ret = 0;
3468 break;
3469 }
3470 mutex_unlock(&ha->chap_sem);
3471
3472 return ret;
3473}
3474
3475
Manish Rangankar2a991c22011-07-25 13:48:55 -05003476static int qla4xxx_get_boot_target(struct scsi_qla_host *ha,
3477 struct ql4_boot_session_info *boot_sess,
3478 uint16_t ddb_index)
3479{
3480 struct ql4_conn_info *boot_conn = &boot_sess->conn_list[0];
3481 struct dev_db_entry *fw_ddb_entry;
3482 dma_addr_t fw_ddb_entry_dma;
3483 uint16_t idx;
3484 uint16_t options;
3485 int ret = QLA_SUCCESS;
3486
3487 fw_ddb_entry = dma_alloc_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3488 &fw_ddb_entry_dma, GFP_KERNEL);
3489 if (!fw_ddb_entry) {
3490 DEBUG2(ql4_printk(KERN_ERR, ha,
3491 "%s: Unable to allocate dma buffer.\n",
3492 __func__));
3493 ret = QLA_ERROR;
3494 return ret;
3495 }
3496
3497 if (qla4xxx_bootdb_by_index(ha, fw_ddb_entry,
3498 fw_ddb_entry_dma, ddb_index)) {
3499 DEBUG2(ql4_printk(KERN_ERR, ha,
3500 "%s: Flash DDB read Failed\n", __func__));
3501 ret = QLA_ERROR;
3502 goto exit_boot_target;
3503 }
3504
3505 /* Update target name and IP from DDB */
3506 memcpy(boot_sess->target_name, fw_ddb_entry->iscsi_name,
3507 min(sizeof(boot_sess->target_name),
3508 sizeof(fw_ddb_entry->iscsi_name)));
3509
3510 options = le16_to_cpu(fw_ddb_entry->options);
3511 if (options & DDB_OPT_IPV6_DEVICE) {
3512 memcpy(&boot_conn->dest_ipaddr.ip_address,
3513 &fw_ddb_entry->ip_addr[0], IPv6_ADDR_LEN);
3514 } else {
3515 boot_conn->dest_ipaddr.ip_type = 0x1;
3516 memcpy(&boot_conn->dest_ipaddr.ip_address,
3517 &fw_ddb_entry->ip_addr[0], IP_ADDR_LEN);
3518 }
3519
3520 boot_conn->dest_port = le16_to_cpu(fw_ddb_entry->port);
3521
3522 /* update chap information */
3523 idx = __le16_to_cpu(fw_ddb_entry->chap_tbl_idx);
3524
3525 if (BIT_7 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
3526
3527 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting chap\n"));
3528
3529 ret = qla4xxx_get_chap(ha, (char *)&boot_conn->chap.
3530 target_chap_name,
3531 (char *)&boot_conn->chap.target_secret,
3532 idx);
3533 if (ret) {
3534 ql4_printk(KERN_ERR, ha, "Failed to set chap\n");
3535 ret = QLA_ERROR;
3536 goto exit_boot_target;
3537 }
3538
3539 boot_conn->chap.target_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
3540 boot_conn->chap.target_secret_length = QL4_CHAP_MAX_SECRET_LEN;
3541 }
3542
3543 if (BIT_4 & le16_to_cpu(fw_ddb_entry->iscsi_options)) {
3544
3545 DEBUG2(ql4_printk(KERN_INFO, ha, "Setting BIDI chap\n"));
3546
Lalit Chandivade28deb452011-10-07 16:55:44 -07003547 ret = qla4xxx_get_bidi_chap(ha,
3548 (char *)&boot_conn->chap.intr_chap_name,
3549 (char *)&boot_conn->chap.intr_secret);
3550
Manish Rangankar2a991c22011-07-25 13:48:55 -05003551 if (ret) {
3552 ql4_printk(KERN_ERR, ha, "Failed to set BIDI chap\n");
3553 ret = QLA_ERROR;
3554 goto exit_boot_target;
3555 }
3556
3557 boot_conn->chap.intr_chap_name_length = QL4_CHAP_MAX_NAME_LEN;
3558 boot_conn->chap.intr_secret_length = QL4_CHAP_MAX_SECRET_LEN;
3559 }
3560
3561exit_boot_target:
3562 dma_free_coherent(&ha->pdev->dev, sizeof(*fw_ddb_entry),
3563 fw_ddb_entry, fw_ddb_entry_dma);
3564 return ret;
3565}
3566
3567static int qla4xxx_get_boot_info(struct scsi_qla_host *ha)
3568{
3569 uint16_t ddb_index[2];
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003570 int ret = QLA_ERROR;
3571 int rval;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003572
3573 memset(ddb_index, 0, sizeof(ddb_index));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003574 ddb_index[0] = 0xffff;
3575 ddb_index[1] = 0xffff;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003576 ret = get_fw_boot_info(ha, ddb_index);
3577 if (ret != QLA_SUCCESS) {
3578 DEBUG2(ql4_printk(KERN_ERR, ha,
3579 "%s: Failed to set boot info.\n", __func__));
3580 return ret;
3581 }
3582
Mike Christie13483732011-12-01 21:38:41 -06003583 if (ql4xdisablesysfsboot)
3584 return QLA_SUCCESS;
3585
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003586 if (ddb_index[0] == 0xffff)
3587 goto sec_target;
3588
3589 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_pri_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05003590 ddb_index[0]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003591 if (rval != QLA_SUCCESS) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05003592 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
3593 "primary target\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003594 } else
3595 ret = QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003596
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003597sec_target:
3598 if (ddb_index[1] == 0xffff)
3599 goto exit_get_boot_info;
3600
3601 rval = qla4xxx_get_boot_target(ha, &(ha->boot_tgt.boot_sec_sess),
Manish Rangankar2a991c22011-07-25 13:48:55 -05003602 ddb_index[1]);
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003603 if (rval != QLA_SUCCESS) {
Manish Rangankar2a991c22011-07-25 13:48:55 -05003604 DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Failed to get "
3605 "secondary target\n", __func__));
Lalit Chandivade8de5b952011-10-07 16:55:43 -07003606 } else
3607 ret = QLA_SUCCESS;
3608
3609exit_get_boot_info:
Manish Rangankar2a991c22011-07-25 13:48:55 -05003610 return ret;
3611}
3612
3613static int qla4xxx_setup_boot_info(struct scsi_qla_host *ha)
3614{
3615 struct iscsi_boot_kobj *boot_kobj;
3616
3617 if (qla4xxx_get_boot_info(ha) != QLA_SUCCESS)
Mike Christie13483732011-12-01 21:38:41 -06003618 return QLA_ERROR;
3619
3620 if (ql4xdisablesysfsboot) {
3621 ql4_printk(KERN_INFO, ha,
3622 "%s: syfsboot disabled - driver will trigger login"
3623 "and publish session for discovery .\n", __func__);
3624 return QLA_SUCCESS;
3625 }
3626
Manish Rangankar2a991c22011-07-25 13:48:55 -05003627
3628 ha->boot_kset = iscsi_boot_create_host_kset(ha->host->host_no);
3629 if (!ha->boot_kset)
3630 goto kset_free;
3631
3632 if (!scsi_host_get(ha->host))
3633 goto kset_free;
3634 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 0, ha,
3635 qla4xxx_show_boot_tgt_pri_info,
3636 qla4xxx_tgt_get_attr_visibility,
3637 qla4xxx_boot_release);
3638 if (!boot_kobj)
3639 goto put_host;
3640
3641 if (!scsi_host_get(ha->host))
3642 goto kset_free;
3643 boot_kobj = iscsi_boot_create_target(ha->boot_kset, 1, ha,
3644 qla4xxx_show_boot_tgt_sec_info,
3645 qla4xxx_tgt_get_attr_visibility,
3646 qla4xxx_boot_release);
3647 if (!boot_kobj)
3648 goto put_host;
3649
3650 if (!scsi_host_get(ha->host))
3651 goto kset_free;
3652 boot_kobj = iscsi_boot_create_initiator(ha->boot_kset, 0, ha,
3653 qla4xxx_show_boot_ini_info,
3654 qla4xxx_ini_get_attr_visibility,
3655 qla4xxx_boot_release);
3656 if (!boot_kobj)
3657 goto put_host;
3658
3659 if (!scsi_host_get(ha->host))
3660 goto kset_free;
3661 boot_kobj = iscsi_boot_create_ethernet(ha->boot_kset, 0, ha,
3662 qla4xxx_show_boot_eth_info,
3663 qla4xxx_eth_get_attr_visibility,
3664 qla4xxx_boot_release);
3665 if (!boot_kobj)
3666 goto put_host;
3667
Mike Christie13483732011-12-01 21:38:41 -06003668 return QLA_SUCCESS;
Manish Rangankar2a991c22011-07-25 13:48:55 -05003669
3670put_host:
3671 scsi_host_put(ha->host);
3672kset_free:
3673 iscsi_boot_destroy_kset(ha->boot_kset);
3674 return -ENOMEM;
3675}
3676
Lalit Chandivade45494152011-10-07 16:55:42 -07003677
3678/**
3679 * qla4xxx_create chap_list - Create CHAP list from FLASH
3680 * @ha: pointer to adapter structure
3681 *
3682 * Read flash and make a list of CHAP entries, during login when a CHAP entry
3683 * is received, it will be checked in this list. If entry exist then the CHAP
3684 * entry index is set in the DDB. If CHAP entry does not exist in this list
3685 * then a new entry is added in FLASH in CHAP table and the index obtained is
3686 * used in the DDB.
3687 **/
3688static void qla4xxx_create_chap_list(struct scsi_qla_host *ha)
3689{
3690 int rval = 0;
3691 uint8_t *chap_flash_data = NULL;
3692 uint32_t offset;
3693 dma_addr_t chap_dma;
3694 uint32_t chap_size = 0;
3695
3696 if (is_qla40XX(ha))
3697 chap_size = MAX_CHAP_ENTRIES_40XX *
3698 sizeof(struct ql4_chap_table);
3699 else /* Single region contains CHAP info for both
3700 * ports which is divided into half for each port.
3701 */
3702 chap_size = ha->hw.flt_chap_size / 2;
3703
3704 chap_flash_data = dma_alloc_coherent(&ha->pdev->dev, chap_size,
3705 &chap_dma, GFP_KERNEL);
3706 if (!chap_flash_data) {
3707 ql4_printk(KERN_ERR, ha, "No memory for chap_flash_data\n");
3708 return;
3709 }
3710 if (is_qla40XX(ha))
3711 offset = FLASH_CHAP_OFFSET;
3712 else {
3713 offset = FLASH_RAW_ACCESS_ADDR + (ha->hw.flt_region_chap << 2);
3714 if (ha->port_num == 1)
3715 offset += chap_size;
3716 }
3717
3718 rval = qla4xxx_get_flash(ha, chap_dma, offset, chap_size);
3719 if (rval != QLA_SUCCESS)
3720 goto exit_chap_list;
3721
3722 if (ha->chap_list == NULL)
3723 ha->chap_list = vmalloc(chap_size);
3724 if (ha->chap_list == NULL) {
3725 ql4_printk(KERN_ERR, ha, "No memory for ha->chap_list\n");
3726 goto exit_chap_list;
3727 }
3728
3729 memcpy(ha->chap_list, chap_flash_data, chap_size);
3730
3731exit_chap_list:
3732 dma_free_coherent(&ha->pdev->dev, chap_size,
3733 chap_flash_data, chap_dma);
Lalit Chandivade45494152011-10-07 16:55:42 -07003734}
3735
Mike Christie13483732011-12-01 21:38:41 -06003736static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
3737 struct ql4_tuple_ddb *tddb)
3738{
3739 struct scsi_qla_host *ha;
3740 struct iscsi_cls_session *cls_sess;
3741 struct iscsi_cls_conn *cls_conn;
3742 struct iscsi_session *sess;
3743 struct iscsi_conn *conn;
3744
3745 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
3746 ha = ddb_entry->ha;
3747 cls_sess = ddb_entry->sess;
3748 sess = cls_sess->dd_data;
3749 cls_conn = ddb_entry->conn;
3750 conn = cls_conn->dd_data;
3751
3752 tddb->tpgt = sess->tpgt;
3753 tddb->port = conn->persistent_port;
3754 strncpy(tddb->iscsi_name, sess->targetname, ISCSI_NAME_SIZE);
3755 strncpy(tddb->ip_addr, conn->persistent_address, DDB_IPADDR_LEN);
3756}
3757
3758static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
3759 struct ql4_tuple_ddb *tddb)
3760{
3761 uint16_t options = 0;
3762
3763 tddb->tpgt = le32_to_cpu(fw_ddb_entry->tgt_portal_grp);
3764 memcpy(&tddb->iscsi_name[0], &fw_ddb_entry->iscsi_name[0],
3765 min(sizeof(tddb->iscsi_name), sizeof(fw_ddb_entry->iscsi_name)));
3766
3767 options = le16_to_cpu(fw_ddb_entry->options);
3768 if (options & DDB_OPT_IPV6_DEVICE)
3769 sprintf(tddb->ip_addr, "%pI6", fw_ddb_entry->ip_addr);
3770 else
3771 sprintf(tddb->ip_addr, "%pI4", fw_ddb_entry->ip_addr);
3772
3773 tddb->port = le16_to_cpu(fw_ddb_entry->port);
3774}
3775
3776static int qla4xxx_compare_tuple_ddb(struct scsi_qla_host *ha,
3777 struct ql4_tuple_ddb *old_tddb,
3778 struct ql4_tuple_ddb *new_tddb)
3779{
3780 if (strcmp(old_tddb->iscsi_name, new_tddb->iscsi_name))
3781 return QLA_ERROR;
3782
3783 if (strcmp(old_tddb->ip_addr, new_tddb->ip_addr))
3784 return QLA_ERROR;
3785
3786 if (old_tddb->port != new_tddb->port)
3787 return QLA_ERROR;
3788
3789 DEBUG2(ql4_printk(KERN_INFO, ha,
3790 "Match Found, fw[%d,%d,%s,%s], [%d,%d,%s,%s]",
3791 old_tddb->port, old_tddb->tpgt, old_tddb->ip_addr,
3792 old_tddb->iscsi_name, new_tddb->port, new_tddb->tpgt,
3793 new_tddb->ip_addr, new_tddb->iscsi_name));
3794
3795 return QLA_SUCCESS;
3796}
3797
3798static int qla4xxx_is_session_exists(struct scsi_qla_host *ha,
3799 struct dev_db_entry *fw_ddb_entry)
3800{
3801 struct ddb_entry *ddb_entry;
3802 struct ql4_tuple_ddb *fw_tddb = NULL;
3803 struct ql4_tuple_ddb *tmp_tddb = NULL;
3804 int idx;
3805 int ret = QLA_ERROR;
3806
3807 fw_tddb = vzalloc(sizeof(*fw_tddb));
3808 if (!fw_tddb) {
3809 DEBUG2(ql4_printk(KERN_WARNING, ha,
3810 "Memory Allocation failed.\n"));
3811 ret = QLA_SUCCESS;
3812 goto exit_check;
3813 }
3814
3815 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
3816 if (!tmp_tddb) {
3817 DEBUG2(ql4_printk(KERN_WARNING, ha,
3818 "Memory Allocation failed.\n"));
3819 ret = QLA_SUCCESS;
3820 goto exit_check;
3821 }
3822
3823 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
3824
3825 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
3826 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
3827 if (ddb_entry == NULL)
3828 continue;
3829
3830 qla4xxx_get_param_ddb(ddb_entry, tmp_tddb);
3831 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) {
3832 ret = QLA_SUCCESS; /* found */
3833 goto exit_check;
3834 }
3835 }
3836
3837exit_check:
3838 if (fw_tddb)
3839 vfree(fw_tddb);
3840 if (tmp_tddb)
3841 vfree(tmp_tddb);
3842 return ret;
3843}
3844
3845static int qla4xxx_is_flash_ddb_exists(struct scsi_qla_host *ha,
3846 struct list_head *list_nt,
3847 struct dev_db_entry *fw_ddb_entry)
3848{
3849 struct qla_ddb_index *nt_ddb_idx, *nt_ddb_idx_tmp;
3850 struct ql4_tuple_ddb *fw_tddb = NULL;
3851 struct ql4_tuple_ddb *tmp_tddb = NULL;
3852 int ret = QLA_ERROR;
3853
3854 fw_tddb = vzalloc(sizeof(*fw_tddb));
3855 if (!fw_tddb) {
3856 DEBUG2(ql4_printk(KERN_WARNING, ha,
3857 "Memory Allocation failed.\n"));
3858 ret = QLA_SUCCESS;
3859 goto exit_check;
3860 }
3861
3862 tmp_tddb = vzalloc(sizeof(*tmp_tddb));
3863 if (!tmp_tddb) {
3864 DEBUG2(ql4_printk(KERN_WARNING, ha,
3865 "Memory Allocation failed.\n"));
3866 ret = QLA_SUCCESS;
3867 goto exit_check;
3868 }
3869
3870 qla4xxx_convert_param_ddb(fw_ddb_entry, fw_tddb);
3871
3872 list_for_each_entry_safe(nt_ddb_idx, nt_ddb_idx_tmp, list_nt, list) {
3873 qla4xxx_convert_param_ddb(&nt_ddb_idx->fw_ddb, tmp_tddb);
3874 if (!qla4xxx_compare_tuple_ddb(ha, fw_tddb, tmp_tddb)) {
3875 ret = QLA_SUCCESS; /* found */
3876 goto exit_check;
3877 }
3878 }
3879
3880exit_check:
3881 if (fw_tddb)
3882 vfree(fw_tddb);
3883 if (tmp_tddb)
3884 vfree(tmp_tddb);
3885 return ret;
3886}
3887
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08003888static void qla4xxx_free_ddb_list(struct list_head *list_ddb)
Mike Christie13483732011-12-01 21:38:41 -06003889{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08003890 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
Mike Christie13483732011-12-01 21:38:41 -06003891
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08003892 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
3893 list_del_init(&ddb_idx->list);
3894 vfree(ddb_idx);
Mike Christie13483732011-12-01 21:38:41 -06003895 }
Mike Christie13483732011-12-01 21:38:41 -06003896}
3897
3898static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha,
3899 struct dev_db_entry *fw_ddb_entry)
3900{
3901 struct iscsi_endpoint *ep;
3902 struct sockaddr_in *addr;
3903 struct sockaddr_in6 *addr6;
3904 struct sockaddr *dst_addr;
3905 char *ip;
3906
3907 /* TODO: need to destroy on unload iscsi_endpoint*/
3908 dst_addr = vmalloc(sizeof(*dst_addr));
3909 if (!dst_addr)
3910 return NULL;
3911
3912 if (fw_ddb_entry->options & DDB_OPT_IPV6_DEVICE) {
3913 dst_addr->sa_family = AF_INET6;
3914 addr6 = (struct sockaddr_in6 *)dst_addr;
3915 ip = (char *)&addr6->sin6_addr;
3916 memcpy(ip, fw_ddb_entry->ip_addr, IPv6_ADDR_LEN);
3917 addr6->sin6_port = htons(le16_to_cpu(fw_ddb_entry->port));
3918
3919 } else {
3920 dst_addr->sa_family = AF_INET;
3921 addr = (struct sockaddr_in *)dst_addr;
3922 ip = (char *)&addr->sin_addr;
3923 memcpy(ip, fw_ddb_entry->ip_addr, IP_ADDR_LEN);
3924 addr->sin_port = htons(le16_to_cpu(fw_ddb_entry->port));
3925 }
3926
3927 ep = qla4xxx_ep_connect(ha->host, dst_addr, 0);
3928 vfree(dst_addr);
3929 return ep;
3930}
3931
3932static int qla4xxx_verify_boot_idx(struct scsi_qla_host *ha, uint16_t idx)
3933{
3934 if (ql4xdisablesysfsboot)
3935 return QLA_SUCCESS;
3936 if (idx == ha->pri_ddb_idx || idx == ha->sec_ddb_idx)
3937 return QLA_ERROR;
3938 return QLA_SUCCESS;
3939}
3940
3941static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
3942 struct ddb_entry *ddb_entry)
3943{
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003944 uint16_t def_timeout;
3945
Mike Christie13483732011-12-01 21:38:41 -06003946 ddb_entry->ddb_type = FLASH_DDB;
3947 ddb_entry->fw_ddb_index = INVALID_ENTRY;
3948 ddb_entry->fw_ddb_device_state = DDB_DS_NO_CONNECTION_ACTIVE;
3949 ddb_entry->ha = ha;
3950 ddb_entry->unblock_sess = qla4xxx_unblock_flash_ddb;
3951 ddb_entry->ddb_change = qla4xxx_flash_ddb_change;
3952
3953 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
3954 atomic_set(&ddb_entry->relogin_timer, 0);
3955 atomic_set(&ddb_entry->relogin_retry_count, 0);
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003956 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
Mike Christie13483732011-12-01 21:38:41 -06003957 ddb_entry->default_relogin_timeout =
Nilesh Javalic28eaac2011-12-18 21:40:44 -08003958 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
3959 def_timeout : LOGIN_TOV;
Mike Christie13483732011-12-01 21:38:41 -06003960 ddb_entry->default_time2wait =
3961 le16_to_cpu(ddb_entry->fw_ddb_entry.iscsi_def_time2wait);
3962}
3963
3964static void qla4xxx_wait_for_ip_configuration(struct scsi_qla_host *ha)
3965{
3966 uint32_t idx = 0;
3967 uint32_t ip_idx[IP_ADDR_COUNT] = {0, 1, 2, 3}; /* 4 IP interfaces */
3968 uint32_t sts[MBOX_REG_COUNT];
3969 uint32_t ip_state;
3970 unsigned long wtime;
3971 int ret;
3972
3973 wtime = jiffies + (HZ * IP_CONFIG_TOV);
3974 do {
3975 for (idx = 0; idx < IP_ADDR_COUNT; idx++) {
3976 if (ip_idx[idx] == -1)
3977 continue;
3978
3979 ret = qla4xxx_get_ip_state(ha, 0, ip_idx[idx], sts);
3980
3981 if (ret == QLA_ERROR) {
3982 ip_idx[idx] = -1;
3983 continue;
3984 }
3985
3986 ip_state = (sts[1] & IP_STATE_MASK) >> IP_STATE_SHIFT;
3987
3988 DEBUG2(ql4_printk(KERN_INFO, ha,
3989 "Waiting for IP state for idx = %d, state = 0x%x\n",
3990 ip_idx[idx], ip_state));
3991 if (ip_state == IP_ADDRSTATE_UNCONFIGURED ||
3992 ip_state == IP_ADDRSTATE_INVALID ||
3993 ip_state == IP_ADDRSTATE_PREFERRED ||
3994 ip_state == IP_ADDRSTATE_DEPRICATED ||
3995 ip_state == IP_ADDRSTATE_DISABLING)
3996 ip_idx[idx] = -1;
Mike Christie13483732011-12-01 21:38:41 -06003997 }
3998
3999 /* Break if all IP states checked */
4000 if ((ip_idx[0] == -1) &&
4001 (ip_idx[1] == -1) &&
4002 (ip_idx[2] == -1) &&
4003 (ip_idx[3] == -1))
4004 break;
4005 schedule_timeout_uninterruptible(HZ);
4006 } while (time_after(wtime, jiffies));
4007}
4008
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004009static void qla4xxx_build_st_list(struct scsi_qla_host *ha,
4010 struct list_head *list_st)
Mike Christie13483732011-12-01 21:38:41 -06004011{
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004012 struct qla_ddb_index *st_ddb_idx;
Mike Christie13483732011-12-01 21:38:41 -06004013 int max_ddbs;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004014 int fw_idx_size;
4015 struct dev_db_entry *fw_ddb_entry;
4016 dma_addr_t fw_ddb_dma;
Mike Christie13483732011-12-01 21:38:41 -06004017 int ret;
4018 uint32_t idx = 0, next_idx = 0;
4019 uint32_t state = 0, conn_err = 0;
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004020 uint16_t conn_id = 0;
Mike Christie13483732011-12-01 21:38:41 -06004021
4022 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4023 &fw_ddb_dma);
4024 if (fw_ddb_entry == NULL) {
4025 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004026 goto exit_st_list;
Mike Christie13483732011-12-01 21:38:41 -06004027 }
4028
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004029 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4030 MAX_DEV_DB_ENTRIES;
Mike Christie13483732011-12-01 21:38:41 -06004031 fw_idx_size = sizeof(struct qla_ddb_index);
4032
4033 for (idx = 0; idx < max_ddbs; idx = next_idx) {
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004034 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4035 NULL, &next_idx, &state,
4036 &conn_err, NULL, &conn_id);
Mike Christie13483732011-12-01 21:38:41 -06004037 if (ret == QLA_ERROR)
4038 break;
4039
Mike Christie13483732011-12-01 21:38:41 -06004040 /* Check if ST, add to the list_st */
4041 if (strlen((char *) fw_ddb_entry->iscsi_name) != 0)
4042 goto continue_next_st;
4043
4044 st_ddb_idx = vzalloc(fw_idx_size);
4045 if (!st_ddb_idx)
4046 break;
4047
4048 st_ddb_idx->fw_ddb_idx = idx;
4049
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004050 list_add_tail(&st_ddb_idx->list, list_st);
Mike Christie13483732011-12-01 21:38:41 -06004051continue_next_st:
4052 if (next_idx == 0)
4053 break;
4054 }
4055
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004056exit_st_list:
4057 if (fw_ddb_entry)
4058 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4059}
4060
4061/**
4062 * qla4xxx_remove_failed_ddb - Remove inactive or failed ddb from list
4063 * @ha: pointer to adapter structure
4064 * @list_ddb: List from which failed ddb to be removed
4065 *
4066 * Iterate over the list of DDBs and find and remove DDBs that are either in
4067 * no connection active state or failed state
4068 **/
4069static void qla4xxx_remove_failed_ddb(struct scsi_qla_host *ha,
4070 struct list_head *list_ddb)
4071{
4072 struct qla_ddb_index *ddb_idx, *ddb_idx_tmp;
4073 uint32_t next_idx = 0;
4074 uint32_t state = 0, conn_err = 0;
4075 int ret;
4076
4077 list_for_each_entry_safe(ddb_idx, ddb_idx_tmp, list_ddb, list) {
4078 ret = qla4xxx_get_fwddb_entry(ha, ddb_idx->fw_ddb_idx,
4079 NULL, 0, NULL, &next_idx, &state,
4080 &conn_err, NULL, NULL);
4081 if (ret == QLA_ERROR)
4082 continue;
4083
4084 if (state == DDB_DS_NO_CONNECTION_ACTIVE ||
4085 state == DDB_DS_SESSION_FAILED) {
4086 list_del_init(&ddb_idx->list);
4087 vfree(ddb_idx);
4088 }
4089 }
4090}
4091
4092static int qla4xxx_sess_conn_setup(struct scsi_qla_host *ha,
4093 struct dev_db_entry *fw_ddb_entry,
4094 int is_reset)
4095{
4096 struct iscsi_cls_session *cls_sess;
4097 struct iscsi_session *sess;
4098 struct iscsi_cls_conn *cls_conn;
4099 struct iscsi_endpoint *ep;
4100 uint16_t cmds_max = 32;
4101 uint16_t conn_id = 0;
4102 uint32_t initial_cmdsn = 0;
4103 int ret = QLA_SUCCESS;
4104
4105 struct ddb_entry *ddb_entry = NULL;
4106
4107 /* Create session object, with INVALID_ENTRY,
4108 * the targer_id would get set when we issue the login
4109 */
4110 cls_sess = iscsi_session_setup(&qla4xxx_iscsi_transport, ha->host,
4111 cmds_max, sizeof(struct ddb_entry),
4112 sizeof(struct ql4_task_data),
4113 initial_cmdsn, INVALID_ENTRY);
4114 if (!cls_sess) {
4115 ret = QLA_ERROR;
4116 goto exit_setup;
4117 }
4118
4119 /*
4120 * so calling module_put function to decrement the
4121 * reference count.
4122 **/
4123 module_put(qla4xxx_iscsi_transport.owner);
4124 sess = cls_sess->dd_data;
4125 ddb_entry = sess->dd_data;
4126 ddb_entry->sess = cls_sess;
4127
4128 cls_sess->recovery_tmo = ql4xsess_recovery_tmo;
4129 memcpy(&ddb_entry->fw_ddb_entry, fw_ddb_entry,
4130 sizeof(struct dev_db_entry));
4131
4132 qla4xxx_setup_flash_ddb_entry(ha, ddb_entry);
4133
4134 cls_conn = iscsi_conn_setup(cls_sess, sizeof(struct qla_conn), conn_id);
4135
4136 if (!cls_conn) {
4137 ret = QLA_ERROR;
4138 goto exit_setup;
4139 }
4140
4141 ddb_entry->conn = cls_conn;
4142
4143 /* Setup ep, for displaying attributes in sysfs */
4144 ep = qla4xxx_get_ep_fwdb(ha, fw_ddb_entry);
4145 if (ep) {
4146 ep->conn = cls_conn;
4147 cls_conn->ep = ep;
4148 } else {
4149 DEBUG2(ql4_printk(KERN_ERR, ha, "Unable to get ep\n"));
4150 ret = QLA_ERROR;
4151 goto exit_setup;
4152 }
4153
4154 /* Update sess/conn params */
4155 qla4xxx_copy_fwddb_param(ha, fw_ddb_entry, cls_sess, cls_conn);
4156
4157 if (is_reset == RESET_ADAPTER) {
4158 iscsi_block_session(cls_sess);
4159 /* Use the relogin path to discover new devices
4160 * by short-circuting the logic of setting
4161 * timer to relogin - instead set the flags
4162 * to initiate login right away.
4163 */
4164 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
4165 set_bit(DF_RELOGIN, &ddb_entry->flags);
4166 }
4167
4168exit_setup:
4169 return ret;
4170}
4171
4172static void qla4xxx_build_nt_list(struct scsi_qla_host *ha,
4173 struct list_head *list_nt, int is_reset)
4174{
4175 struct dev_db_entry *fw_ddb_entry;
4176 dma_addr_t fw_ddb_dma;
4177 int max_ddbs;
4178 int fw_idx_size;
4179 int ret;
4180 uint32_t idx = 0, next_idx = 0;
4181 uint32_t state = 0, conn_err = 0;
4182 uint16_t conn_id = 0;
4183 struct qla_ddb_index *nt_ddb_idx;
4184
4185 fw_ddb_entry = dma_pool_alloc(ha->fw_ddb_dma_pool, GFP_KERNEL,
4186 &fw_ddb_dma);
4187 if (fw_ddb_entry == NULL) {
4188 DEBUG2(ql4_printk(KERN_ERR, ha, "Out of memory\n"));
4189 goto exit_nt_list;
4190 }
4191 max_ddbs = is_qla40XX(ha) ? MAX_DEV_DB_ENTRIES_40XX :
4192 MAX_DEV_DB_ENTRIES;
4193 fw_idx_size = sizeof(struct qla_ddb_index);
4194
4195 for (idx = 0; idx < max_ddbs; idx = next_idx) {
4196 ret = qla4xxx_get_fwddb_entry(ha, idx, fw_ddb_entry, fw_ddb_dma,
4197 NULL, &next_idx, &state,
4198 &conn_err, NULL, &conn_id);
4199 if (ret == QLA_ERROR)
4200 break;
4201
4202 if (qla4xxx_verify_boot_idx(ha, idx) != QLA_SUCCESS)
4203 goto continue_next_nt;
4204
4205 /* Check if NT, then add to list it */
4206 if (strlen((char *) fw_ddb_entry->iscsi_name) == 0)
4207 goto continue_next_nt;
4208
4209 if (!(state == DDB_DS_NO_CONNECTION_ACTIVE ||
4210 state == DDB_DS_SESSION_FAILED))
4211 goto continue_next_nt;
4212
4213 DEBUG2(ql4_printk(KERN_INFO, ha,
4214 "Adding DDB to session = 0x%x\n", idx));
4215 if (is_reset == INIT_ADAPTER) {
4216 nt_ddb_idx = vmalloc(fw_idx_size);
4217 if (!nt_ddb_idx)
4218 break;
4219
4220 nt_ddb_idx->fw_ddb_idx = idx;
4221
4222 memcpy(&nt_ddb_idx->fw_ddb, fw_ddb_entry,
4223 sizeof(struct dev_db_entry));
4224
4225 if (qla4xxx_is_flash_ddb_exists(ha, list_nt,
4226 fw_ddb_entry) == QLA_SUCCESS) {
4227 vfree(nt_ddb_idx);
4228 goto continue_next_nt;
4229 }
4230 list_add_tail(&nt_ddb_idx->list, list_nt);
4231 } else if (is_reset == RESET_ADAPTER) {
4232 if (qla4xxx_is_session_exists(ha, fw_ddb_entry) ==
4233 QLA_SUCCESS)
4234 goto continue_next_nt;
4235 }
4236
4237 ret = qla4xxx_sess_conn_setup(ha, fw_ddb_entry, is_reset);
4238 if (ret == QLA_ERROR)
4239 goto exit_nt_list;
4240
4241continue_next_nt:
4242 if (next_idx == 0)
4243 break;
4244 }
4245
4246exit_nt_list:
4247 if (fw_ddb_entry)
4248 dma_pool_free(ha->fw_ddb_dma_pool, fw_ddb_entry, fw_ddb_dma);
4249}
4250
4251/**
4252 * qla4xxx_build_ddb_list - Build ddb list and setup sessions
4253 * @ha: pointer to adapter structure
4254 * @is_reset: Is this init path or reset path
4255 *
4256 * Create a list of sendtargets (st) from firmware DDBs, issue send targets
4257 * using connection open, then create the list of normal targets (nt)
4258 * from firmware DDBs. Based on the list of nt setup session and connection
4259 * objects.
4260 **/
4261void qla4xxx_build_ddb_list(struct scsi_qla_host *ha, int is_reset)
4262{
4263 uint16_t tmo = 0;
4264 struct list_head list_st, list_nt;
4265 struct qla_ddb_index *st_ddb_idx, *st_ddb_idx_tmp;
4266 unsigned long wtime;
4267
4268 if (!test_bit(AF_LINK_UP, &ha->flags)) {
4269 set_bit(AF_BUILD_DDB_LIST, &ha->flags);
4270 ha->is_reset = is_reset;
4271 return;
4272 }
4273
4274 INIT_LIST_HEAD(&list_st);
4275 INIT_LIST_HEAD(&list_nt);
4276
4277 qla4xxx_build_st_list(ha, &list_st);
4278
Mike Christie13483732011-12-01 21:38:41 -06004279 /* Before issuing conn open mbox, ensure all IPs states are configured
4280 * Note, conn open fails if IPs are not configured
4281 */
4282 qla4xxx_wait_for_ip_configuration(ha);
4283
4284 /* Go thru the STs and fire the sendtargets by issuing conn open mbx */
4285 list_for_each_entry_safe(st_ddb_idx, st_ddb_idx_tmp, &list_st, list) {
4286 qla4xxx_conn_open(ha, st_ddb_idx->fw_ddb_idx);
4287 }
4288
4289 /* Wait to ensure all sendtargets are done for min 12 sec wait */
Nilesh Javalic28eaac2011-12-18 21:40:44 -08004290 tmo = ((ha->def_timeout > LOGIN_TOV) &&
4291 (ha->def_timeout < LOGIN_TOV * 10) ?
4292 ha->def_timeout : LOGIN_TOV);
4293
Mike Christie13483732011-12-01 21:38:41 -06004294 DEBUG2(ql4_printk(KERN_INFO, ha,
4295 "Default time to wait for build ddb %d\n", tmo));
4296
4297 wtime = jiffies + (HZ * tmo);
4298 do {
Nilesh Javalif1f2e602011-12-16 01:58:57 -08004299 if (list_empty(&list_st))
4300 break;
4301
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004302 qla4xxx_remove_failed_ddb(ha, &list_st);
Mike Christie13483732011-12-01 21:38:41 -06004303 schedule_timeout_uninterruptible(HZ / 10);
4304 } while (time_after(wtime, jiffies));
4305
4306 /* Free up the sendtargets list */
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004307 qla4xxx_free_ddb_list(&list_st);
Mike Christie13483732011-12-01 21:38:41 -06004308
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004309 qla4xxx_build_nt_list(ha, &list_nt, is_reset);
Mike Christie13483732011-12-01 21:38:41 -06004310
Lalit Chandivade4a4bc2e2011-12-16 01:58:55 -08004311 qla4xxx_free_ddb_list(&list_nt);
Mike Christie13483732011-12-01 21:38:41 -06004312
4313 qla4xxx_free_ddb_index(ha);
4314}
4315
David Somayajuluafaf5a22006-09-19 10:28:00 -07004316/**
4317 * qla4xxx_probe_adapter - callback function to probe HBA
4318 * @pdev: pointer to pci_dev structure
4319 * @pci_device_id: pointer to pci_device entry
4320 *
4321 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
4322 * It returns zero if successful. It also initializes all data necessary for
4323 * the driver.
4324 **/
4325static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
4326 const struct pci_device_id *ent)
4327{
4328 int ret = -ENODEV, status;
4329 struct Scsi_Host *host;
4330 struct scsi_qla_host *ha;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004331 uint8_t init_retry_count = 0;
4332 char buf[34];
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304333 struct qla4_8xxx_legacy_intr_set *nx_legacy_intr;
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07004334 uint32_t dev_state;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004335
4336 if (pci_enable_device(pdev))
4337 return -1;
4338
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004339 host = iscsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha), 0);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004340 if (host == NULL) {
4341 printk(KERN_WARNING
4342 "qla4xxx: Couldn't allocate host from scsi layer!\n");
4343 goto probe_disable_device;
4344 }
4345
4346 /* Clear our data area */
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004347 ha = to_qla_host(host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004348 memset(ha, 0, sizeof(*ha));
4349
4350 /* Save the information from PCI BIOS. */
4351 ha->pdev = pdev;
4352 ha->host = host;
4353 ha->host_no = host->host_no;
4354
Lalit Chandivade2232be02010-07-30 14:38:47 +05304355 pci_enable_pcie_error_reporting(pdev);
4356
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304357 /* Setup Runtime configurable options */
4358 if (is_qla8022(ha)) {
4359 ha->isp_ops = &qla4_8xxx_isp_ops;
4360 rwlock_init(&ha->hw_lock);
4361 ha->qdr_sn_window = -1;
4362 ha->ddr_mn_window = -1;
4363 ha->curr_window = 255;
4364 ha->func_num = PCI_FUNC(ha->pdev->devfn);
4365 nx_legacy_intr = &legacy_intr[ha->func_num];
4366 ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit;
4367 ha->nx_legacy_intr.tgt_status_reg =
4368 nx_legacy_intr->tgt_status_reg;
4369 ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg;
4370 ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg;
4371 } else {
4372 ha->isp_ops = &qla4xxx_isp_ops;
4373 }
4374
Lalit Chandivade2232be02010-07-30 14:38:47 +05304375 /* Set EEH reset type to fundamental if required by hba */
4376 if (is_qla8022(ha))
4377 pdev->needs_freset = 1;
4378
David Somayajuluafaf5a22006-09-19 10:28:00 -07004379 /* Configure PCI I/O space. */
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304380 ret = ha->isp_ops->iospace_config(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004381 if (ret)
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304382 goto probe_failed_ioconfig;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004383
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304384 ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n",
David Somayajuluafaf5a22006-09-19 10:28:00 -07004385 pdev->device, pdev->irq, ha->reg);
4386
4387 qla4xxx_config_dma_addressing(ha);
4388
4389 /* Initialize lists and spinlocks. */
David Somayajuluafaf5a22006-09-19 10:28:00 -07004390 INIT_LIST_HEAD(&ha->free_srb_q);
4391
4392 mutex_init(&ha->mbox_sem);
Lalit Chandivade45494152011-10-07 16:55:42 -07004393 mutex_init(&ha->chap_sem);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304394 init_completion(&ha->mbx_intr_comp);
Vikas Chaudhary95d31262011-08-12 02:51:29 -07004395 init_completion(&ha->disable_acb_comp);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004396
4397 spin_lock_init(&ha->hardware_lock);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004398
4399 /* Allocate dma buffers */
4400 if (qla4xxx_mem_alloc(ha)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304401 ql4_printk(KERN_WARNING, ha,
4402 "[ERROR] Failed to allocate memory for adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004403
4404 ret = -ENOMEM;
4405 goto probe_failed;
4406 }
4407
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004408 host->cmd_per_lun = 3;
4409 host->max_channel = 0;
4410 host->max_lun = MAX_LUNS - 1;
4411 host->max_id = MAX_TARGETS;
4412 host->max_cmd_len = IOCB_MAX_CDB_LEN;
4413 host->can_queue = MAX_SRBS ;
4414 host->transportt = qla4xxx_scsi_transport;
4415
4416 ret = scsi_init_shared_tag_map(host, MAX_SRBS);
4417 if (ret) {
4418 ql4_printk(KERN_WARNING, ha,
4419 "%s: scsi_init_shared_tag_map failed\n", __func__);
4420 goto probe_failed;
4421 }
4422
4423 pci_set_drvdata(pdev, ha);
4424
4425 ret = scsi_add_host(host, &pdev->dev);
4426 if (ret)
4427 goto probe_failed;
4428
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304429 if (is_qla8022(ha))
4430 (void) qla4_8xxx_get_flash_info(ha);
4431
David Somayajuluafaf5a22006-09-19 10:28:00 -07004432 /*
4433 * Initialize the Host adapter request/response queues and
4434 * firmware
4435 * NOTE: interrupts enabled upon successful completion
4436 */
Mike Christie13483732011-12-01 21:38:41 -06004437 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304438 while ((!test_bit(AF_ONLINE, &ha->flags)) &&
4439 init_retry_count++ < MAX_INIT_RETRIES) {
Prasanna Mumbaif9880e72011-03-21 03:34:26 -07004440
4441 if (is_qla8022(ha)) {
4442 qla4_8xxx_idc_lock(ha);
4443 dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE);
4444 qla4_8xxx_idc_unlock(ha);
4445 if (dev_state == QLA82XX_DEV_FAILED) {
4446 ql4_printk(KERN_WARNING, ha, "%s: don't retry "
4447 "initialize adapter. H/W is in failed state\n",
4448 __func__);
4449 break;
4450 }
4451 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004452 DEBUG2(printk("scsi: %s: retrying adapter initialization "
4453 "(%d)\n", __func__, init_retry_count));
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304454
4455 if (ha->isp_ops->reset_chip(ha) == QLA_ERROR)
4456 continue;
4457
Mike Christie13483732011-12-01 21:38:41 -06004458 status = qla4xxx_initialize_adapter(ha, INIT_ADAPTER);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004459 }
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304460
4461 if (!test_bit(AF_ONLINE, &ha->flags)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304462 ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004463
Lalit Chandivadefe998522010-12-02 22:12:36 -08004464 if (is_qla8022(ha) && ql4xdontresethba) {
4465 /* Put the device in failed state. */
4466 DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n"));
4467 qla4_8xxx_idc_lock(ha);
4468 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4469 QLA82XX_DEV_FAILED);
4470 qla4_8xxx_idc_unlock(ha);
4471 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004472 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004473 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004474 }
4475
David Somayajuluafaf5a22006-09-19 10:28:00 -07004476 /* Startup the kernel thread for this host adapter. */
4477 DEBUG2(printk("scsi: %s: Starting kernel thread for "
4478 "qla4xxx_dpc\n", __func__));
4479 sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no);
4480 ha->dpc_thread = create_singlethread_workqueue(buf);
4481 if (!ha->dpc_thread) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304482 ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n");
David Somayajuluafaf5a22006-09-19 10:28:00 -07004483 ret = -ENODEV;
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004484 goto remove_host;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004485 }
David Howellsc4028952006-11-22 14:57:56 +00004486 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004487
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004488 sprintf(buf, "qla4xxx_%lu_task", ha->host_no);
4489 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1);
4490 if (!ha->task_wq) {
4491 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
4492 ret = -ENODEV;
4493 goto remove_host;
4494 }
4495
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304496 /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc
4497 * (which is called indirectly by qla4xxx_initialize_adapter),
4498 * so that irqs will be registered after crbinit but before
4499 * mbx_intr_enable.
4500 */
4501 if (!is_qla8022(ha)) {
4502 ret = qla4xxx_request_irqs(ha);
4503 if (ret) {
4504 ql4_printk(KERN_WARNING, ha, "Failed to reserve "
4505 "interrupt %d already in use.\n", pdev->irq);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004506 goto remove_host;
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304507 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004508 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004509
Lalit Chandivade2232be02010-07-30 14:38:47 +05304510 pci_save_state(ha->pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304511 ha->isp_ops->enable_intrs(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004512
4513 /* Start timer thread. */
4514 qla4xxx_start_timer(ha, qla4xxx_timer, 1);
4515
4516 set_bit(AF_INIT_DONE, &ha->flags);
4517
David Somayajuluafaf5a22006-09-19 10:28:00 -07004518 printk(KERN_INFO
4519 " QLogic iSCSI HBA Driver version: %s\n"
4520 " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n",
4521 qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
4522 ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
4523 ha->patch_number, ha->build_number);
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05004524
Manish Rangankar2a991c22011-07-25 13:48:55 -05004525 if (qla4xxx_setup_boot_info(ha))
4526 ql4_printk(KERN_ERR, ha, "%s:ISCSI boot info setup failed\n",
4527 __func__);
4528
Mike Christie13483732011-12-01 21:38:41 -06004529 /* Perform the build ddb list and login to each */
4530 qla4xxx_build_ddb_list(ha, INIT_ADAPTER);
4531 iscsi_host_for_each_session(ha->host, qla4xxx_login_flash_ddb);
4532
4533 qla4xxx_create_chap_list(ha);
4534
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05004535 qla4xxx_create_ifaces(ha);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004536 return 0;
4537
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004538remove_host:
4539 scsi_remove_host(ha->host);
4540
David Somayajuluafaf5a22006-09-19 10:28:00 -07004541probe_failed:
4542 qla4xxx_free_adapter(ha);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304543
4544probe_failed_ioconfig:
Lalit Chandivade2232be02010-07-30 14:38:47 +05304545 pci_disable_pcie_error_reporting(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004546 scsi_host_put(ha->host);
4547
4548probe_disable_device:
4549 pci_disable_device(pdev);
4550
4551 return ret;
4552}
4553
4554/**
Karen Higgins7eece5a2011-03-21 03:34:29 -07004555 * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize
4556 * @ha: pointer to adapter structure
4557 *
4558 * Mark the other ISP-4xxx port to indicate that the driver is being removed,
4559 * so that the other port will not re-initialize while in the process of
4560 * removing the ha due to driver unload or hba hotplug.
4561 **/
4562static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha)
4563{
4564 struct scsi_qla_host *other_ha = NULL;
4565 struct pci_dev *other_pdev = NULL;
4566 int fn = ISP4XXX_PCI_FN_2;
4567
4568 /*iscsi function numbers for ISP4xxx is 1 and 3*/
4569 if (PCI_FUNC(ha->pdev->devfn) & BIT_1)
4570 fn = ISP4XXX_PCI_FN_1;
4571
4572 other_pdev =
4573 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4574 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4575 fn));
4576
4577 /* Get other_ha if other_pdev is valid and state is enable*/
4578 if (other_pdev) {
4579 if (atomic_read(&other_pdev->enable_cnt)) {
4580 other_ha = pci_get_drvdata(other_pdev);
4581 if (other_ha) {
4582 set_bit(AF_HA_REMOVAL, &other_ha->flags);
4583 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: "
4584 "Prevent %s reinit\n", __func__,
4585 dev_name(&other_ha->pdev->dev)));
4586 }
4587 }
4588 pci_dev_put(other_pdev);
4589 }
4590}
4591
Mike Christie13483732011-12-01 21:38:41 -06004592static void qla4xxx_destroy_fw_ddb_session(struct scsi_qla_host *ha)
4593{
4594 struct ddb_entry *ddb_entry;
4595 int options;
4596 int idx;
4597
4598 for (idx = 0; idx < MAX_DDB_ENTRIES; idx++) {
4599
4600 ddb_entry = qla4xxx_lookup_ddb_by_fw_index(ha, idx);
4601 if ((ddb_entry != NULL) &&
4602 (ddb_entry->ddb_type == FLASH_DDB)) {
4603
4604 options = LOGOUT_OPTION_CLOSE_SESSION;
4605 if (qla4xxx_session_logout_ddb(ha, ddb_entry, options)
4606 == QLA_ERROR)
4607 ql4_printk(KERN_ERR, ha, "%s: Logout failed\n",
4608 __func__);
4609
4610 qla4xxx_clear_ddb_entry(ha, ddb_entry->fw_ddb_index);
4611 /*
4612 * we have decremented the reference count of the driver
4613 * when we setup the session to have the driver unload
4614 * to be seamless without actually destroying the
4615 * session
4616 **/
4617 try_module_get(qla4xxx_iscsi_transport.owner);
4618 iscsi_destroy_endpoint(ddb_entry->conn->ep);
4619 qla4xxx_free_ddb(ha, ddb_entry);
4620 iscsi_session_teardown(ddb_entry->sess);
4621 }
4622 }
4623}
Karen Higgins7eece5a2011-03-21 03:34:29 -07004624/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004625 * qla4xxx_remove_adapter - calback function to remove adapter.
4626 * @pci_dev: PCI device pointer
4627 **/
4628static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
4629{
4630 struct scsi_qla_host *ha;
4631
4632 ha = pci_get_drvdata(pdev);
4633
Karen Higgins7eece5a2011-03-21 03:34:29 -07004634 if (!is_qla8022(ha))
4635 qla4xxx_prevent_other_port_reinit(ha);
David C Somayajulubee4fe82007-05-23 18:03:32 -07004636
Vikas Chaudharyed1086e2011-07-25 13:48:41 -05004637 /* destroy iface from sysfs */
4638 qla4xxx_destroy_ifaces(ha);
4639
Mike Christie13483732011-12-01 21:38:41 -06004640 if ((!ql4xdisablesysfsboot) && ha->boot_kset)
Manish Rangankar2a991c22011-07-25 13:48:55 -05004641 iscsi_boot_destroy_kset(ha->boot_kset);
4642
Mike Christie13483732011-12-01 21:38:41 -06004643 qla4xxx_destroy_fw_ddb_session(ha);
4644
David Somayajuluafaf5a22006-09-19 10:28:00 -07004645 scsi_remove_host(ha->host);
4646
4647 qla4xxx_free_adapter(ha);
4648
4649 scsi_host_put(ha->host);
4650
Lalit Chandivade2232be02010-07-30 14:38:47 +05304651 pci_disable_pcie_error_reporting(pdev);
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304652 pci_disable_device(pdev);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004653 pci_set_drvdata(pdev, NULL);
4654}
4655
4656/**
4657 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
4658 * @ha: HA context
4659 *
4660 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
4661 * supported addressing method.
4662 */
Adrian Bunk47975472007-04-26 00:35:16 -07004663static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004664{
4665 int retval;
4666
4667 /* Update our PCI device dma_mask for full 64 bit mask */
Yang Hongyang6a355282009-04-06 19:01:13 -07004668 if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
4669 if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004670 dev_dbg(&ha->pdev->dev,
4671 "Failed to set 64 bit PCI consistent mask; "
4672 "using 32 bit.\n");
4673 retval = pci_set_consistent_dma_mask(ha->pdev,
Yang Hongyang284901a2009-04-06 19:01:15 -07004674 DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004675 }
4676 } else
Yang Hongyang284901a2009-04-06 19:01:15 -07004677 retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
David Somayajuluafaf5a22006-09-19 10:28:00 -07004678}
4679
4680static int qla4xxx_slave_alloc(struct scsi_device *sdev)
4681{
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004682 struct iscsi_cls_session *cls_sess;
4683 struct iscsi_session *sess;
4684 struct ddb_entry *ddb;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07004685 int queue_depth = QL4_DEF_QDEPTH;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004686
Manish Rangankarb3a271a2011-07-25 13:48:53 -05004687 cls_sess = starget_to_session(sdev->sdev_target);
4688 sess = cls_sess->dd_data;
4689 ddb = sess->dd_data;
4690
David Somayajuluafaf5a22006-09-19 10:28:00 -07004691 sdev->hostdata = ddb;
4692 sdev->tagged_supported = 1;
Vikas Chaudhary8bb40332011-03-21 03:34:31 -07004693
4694 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
4695 queue_depth = ql4xmaxqdepth;
4696
4697 scsi_activate_tcq(sdev, queue_depth);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004698 return 0;
4699}
4700
4701static int qla4xxx_slave_configure(struct scsi_device *sdev)
4702{
4703 sdev->tagged_supported = 1;
4704 return 0;
4705}
4706
4707static void qla4xxx_slave_destroy(struct scsi_device *sdev)
4708{
4709 scsi_deactivate_tcq(sdev, 1);
4710}
4711
4712/**
4713 * qla4xxx_del_from_active_array - returns an active srb
4714 * @ha: Pointer to host adapter structure.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02004715 * @index: index into the active_array
David Somayajuluafaf5a22006-09-19 10:28:00 -07004716 *
4717 * This routine removes and returns the srb at the specified index
4718 **/
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05304719struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
4720 uint32_t index)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004721{
4722 struct srb *srb = NULL;
Vikas Chaudhary53698872010-04-28 11:41:59 +05304723 struct scsi_cmnd *cmd = NULL;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004724
Vikas Chaudhary53698872010-04-28 11:41:59 +05304725 cmd = scsi_host_find_tag(ha->host, index);
4726 if (!cmd)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004727 return srb;
4728
Vikas Chaudhary53698872010-04-28 11:41:59 +05304729 srb = (struct srb *)CMD_SP(cmd);
4730 if (!srb)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004731 return srb;
4732
4733 /* update counters */
4734 if (srb->flags & SRB_DMA_VALID) {
4735 ha->req_q_count += srb->iocb_cnt;
4736 ha->iocb_cnt -= srb->iocb_cnt;
4737 if (srb->cmd)
Vikas Chaudhary53698872010-04-28 11:41:59 +05304738 srb->cmd->host_scribble =
4739 (unsigned char *)(unsigned long) MAX_SRBS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004740 }
4741 return srb;
4742}
4743
4744/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004745 * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304746 * @ha: Pointer to host adapter structure.
David Somayajuluafaf5a22006-09-19 10:28:00 -07004747 * @cmd: Scsi Command to wait on.
4748 *
4749 * This routine waits for the command to be returned by the Firmware
4750 * for some max time.
4751 **/
4752static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
4753 struct scsi_cmnd *cmd)
4754{
4755 int done = 0;
4756 struct srb *rp;
4757 uint32_t max_wait_time = EH_WAIT_CMD_TOV;
Lalit Chandivade2232be02010-07-30 14:38:47 +05304758 int ret = SUCCESS;
4759
4760 /* Dont wait on command if PCI error is being handled
4761 * by PCI AER driver
4762 */
4763 if (unlikely(pci_channel_offline(ha->pdev)) ||
4764 (test_bit(AF_EEH_BUSY, &ha->flags))) {
4765 ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n",
4766 ha->host_no, __func__);
4767 return ret;
4768 }
David Somayajuluafaf5a22006-09-19 10:28:00 -07004769
4770 do {
4771 /* Checking to see if its returned to OS */
Vikas Chaudhary53698872010-04-28 11:41:59 +05304772 rp = (struct srb *) CMD_SP(cmd);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004773 if (rp == NULL) {
4774 done++;
4775 break;
4776 }
4777
4778 msleep(2000);
4779 } while (max_wait_time--);
4780
4781 return done;
4782}
4783
4784/**
4785 * qla4xxx_wait_for_hba_online - waits for HBA to come online
4786 * @ha: Pointer to host adapter structure
4787 **/
4788static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha)
4789{
4790 unsigned long wait_online;
4791
Vikas Chaudharyf581a3f2010-10-06 22:47:48 -07004792 wait_online = jiffies + (HBA_ONLINE_TOV * HZ);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004793 while (time_before(jiffies, wait_online)) {
4794
4795 if (adapter_up(ha))
4796 return QLA_SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004797
4798 msleep(2000);
4799 }
4800
4801 return QLA_ERROR;
4802}
4803
4804/**
Mike Christiece545032008-02-29 18:25:20 -06004805 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
Anand Gadiyarfd589a82009-07-16 17:13:03 +02004806 * @ha: pointer to HBA
David Somayajuluafaf5a22006-09-19 10:28:00 -07004807 * @t: target id
4808 * @l: lun id
4809 *
4810 * This function waits for all outstanding commands to a lun to complete. It
4811 * returns 0 if all pending commands are returned and 1 otherwise.
4812 **/
Mike Christiece545032008-02-29 18:25:20 -06004813static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha,
4814 struct scsi_target *stgt,
4815 struct scsi_device *sdev)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004816{
4817 int cnt;
4818 int status = 0;
4819 struct scsi_cmnd *cmd;
4820
4821 /*
Mike Christiece545032008-02-29 18:25:20 -06004822 * Waiting for all commands for the designated target or dev
4823 * in the active array
David Somayajuluafaf5a22006-09-19 10:28:00 -07004824 */
4825 for (cnt = 0; cnt < ha->host->can_queue; cnt++) {
4826 cmd = scsi_host_find_tag(ha->host, cnt);
Mike Christiece545032008-02-29 18:25:20 -06004827 if (cmd && stgt == scsi_target(cmd->device) &&
4828 (!sdev || sdev == cmd->device)) {
David Somayajuluafaf5a22006-09-19 10:28:00 -07004829 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
4830 status++;
4831 break;
4832 }
4833 }
4834 }
4835 return status;
4836}
4837
4838/**
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304839 * qla4xxx_eh_abort - callback for abort task.
4840 * @cmd: Pointer to Linux's SCSI command structure
4841 *
4842 * This routine is called by the Linux OS to abort the specified
4843 * command.
4844 **/
4845static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
4846{
4847 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4848 unsigned int id = cmd->device->id;
4849 unsigned int lun = cmd->device->lun;
Mike Christie92b3e5b2010-10-06 22:51:17 -07004850 unsigned long flags;
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304851 struct srb *srb = NULL;
4852 int ret = SUCCESS;
4853 int wait = 0;
4854
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304855 ql4_printk(KERN_INFO, ha,
Christoph Hellwig5cd049a2011-04-04 09:42:14 -04004856 "scsi%ld:%d:%d: Abort command issued cmd=%p\n",
4857 ha->host_no, id, lun, cmd);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304858
Mike Christie92b3e5b2010-10-06 22:51:17 -07004859 spin_lock_irqsave(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304860 srb = (struct srb *) CMD_SP(cmd);
Mike Christie92b3e5b2010-10-06 22:51:17 -07004861 if (!srb) {
4862 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304863 return SUCCESS;
Mike Christie92b3e5b2010-10-06 22:51:17 -07004864 }
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304865 kref_get(&srb->srb_ref);
Mike Christie92b3e5b2010-10-06 22:51:17 -07004866 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304867
4868 if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) {
4869 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n",
4870 ha->host_no, id, lun));
4871 ret = FAILED;
4872 } else {
4873 DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n",
4874 ha->host_no, id, lun));
4875 wait = 1;
4876 }
4877
4878 kref_put(&srb->srb_ref, qla4xxx_srb_compl);
4879
4880 /* Wait for command to complete */
4881 if (wait) {
4882 if (!qla4xxx_eh_wait_on_command(ha, cmd)) {
4883 DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n",
4884 ha->host_no, id, lun));
4885 ret = FAILED;
4886 }
4887 }
4888
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304889 ql4_printk(KERN_INFO, ha,
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304890 "scsi%ld:%d:%d: Abort command - %s\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004891 ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed");
Vikas Chaudhary09a0f712010-04-28 11:42:24 +05304892
4893 return ret;
4894}
4895
4896/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07004897 * qla4xxx_eh_device_reset - callback for target reset.
4898 * @cmd: Pointer to Linux's SCSI command structure
4899 *
4900 * This routine is called by the Linux OS to reset all luns on the
4901 * specified target.
4902 **/
4903static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
4904{
4905 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4906 struct ddb_entry *ddb_entry = cmd->device->hostdata;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004907 int ret = FAILED, stat;
4908
Karen Higgins612f7342009-07-15 15:03:01 -05004909 if (!ddb_entry)
David Somayajuluafaf5a22006-09-19 10:28:00 -07004910 return ret;
4911
Mike Christiec01be6d2010-07-22 16:59:49 +05304912 ret = iscsi_block_scsi_eh(cmd);
4913 if (ret)
4914 return ret;
4915 ret = FAILED;
4916
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304917 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004918 "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
4919 cmd->device->channel, cmd->device->id, cmd->device->lun);
4920
4921 DEBUG2(printk(KERN_INFO
4922 "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
4923 "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
Jens Axboe242f9dc2008-09-14 05:55:09 -07004924 cmd, jiffies, cmd->request->timeout / HZ,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004925 ha->dpc_flags, cmd->result, cmd->allowed));
4926
4927 /* FIXME: wait for hba to go online */
4928 stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun);
4929 if (stat != QLA_SUCCESS) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304930 ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat);
David Somayajuluafaf5a22006-09-19 10:28:00 -07004931 goto eh_dev_reset_done;
4932 }
4933
Mike Christiece545032008-02-29 18:25:20 -06004934 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
4935 cmd->device)) {
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304936 ql4_printk(KERN_INFO, ha,
Mike Christiece545032008-02-29 18:25:20 -06004937 "DEVICE RESET FAILED - waiting for "
4938 "commands.\n");
4939 goto eh_dev_reset_done;
David Somayajuluafaf5a22006-09-19 10:28:00 -07004940 }
4941
David C Somayajulu9d562912008-03-19 11:23:03 -07004942 /* Send marker. */
4943 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
4944 MM_LUN_RESET) != QLA_SUCCESS)
4945 goto eh_dev_reset_done;
4946
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05304947 ql4_printk(KERN_INFO, ha,
David Somayajuluafaf5a22006-09-19 10:28:00 -07004948 "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n",
4949 ha->host_no, cmd->device->channel, cmd->device->id,
4950 cmd->device->lun);
4951
4952 ret = SUCCESS;
4953
4954eh_dev_reset_done:
4955
4956 return ret;
4957}
4958
4959/**
Mike Christiece545032008-02-29 18:25:20 -06004960 * qla4xxx_eh_target_reset - callback for target reset.
4961 * @cmd: Pointer to Linux's SCSI command structure
4962 *
4963 * This routine is called by the Linux OS to reset the target.
4964 **/
4965static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
4966{
4967 struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
4968 struct ddb_entry *ddb_entry = cmd->device->hostdata;
Mike Christiec01be6d2010-07-22 16:59:49 +05304969 int stat, ret;
Mike Christiece545032008-02-29 18:25:20 -06004970
4971 if (!ddb_entry)
4972 return FAILED;
4973
Mike Christiec01be6d2010-07-22 16:59:49 +05304974 ret = iscsi_block_scsi_eh(cmd);
4975 if (ret)
4976 return ret;
4977
Mike Christiece545032008-02-29 18:25:20 -06004978 starget_printk(KERN_INFO, scsi_target(cmd->device),
4979 "WARM TARGET RESET ISSUED.\n");
4980
4981 DEBUG2(printk(KERN_INFO
4982 "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
4983 "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
Jens Axboe242f9dc2008-09-14 05:55:09 -07004984 ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
Mike Christiece545032008-02-29 18:25:20 -06004985 ha->dpc_flags, cmd->result, cmd->allowed));
4986
4987 stat = qla4xxx_reset_target(ha, ddb_entry);
4988 if (stat != QLA_SUCCESS) {
4989 starget_printk(KERN_INFO, scsi_target(cmd->device),
4990 "WARM TARGET RESET FAILED.\n");
4991 return FAILED;
4992 }
4993
Mike Christiece545032008-02-29 18:25:20 -06004994 if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device),
4995 NULL)) {
4996 starget_printk(KERN_INFO, scsi_target(cmd->device),
4997 "WARM TARGET DEVICE RESET FAILED - "
4998 "waiting for commands.\n");
4999 return FAILED;
5000 }
5001
David C Somayajulu9d562912008-03-19 11:23:03 -07005002 /* Send marker. */
5003 if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun,
5004 MM_TGT_WARM_RESET) != QLA_SUCCESS) {
5005 starget_printk(KERN_INFO, scsi_target(cmd->device),
5006 "WARM TARGET DEVICE RESET FAILED - "
5007 "marker iocb failed.\n");
5008 return FAILED;
5009 }
5010
Mike Christiece545032008-02-29 18:25:20 -06005011 starget_printk(KERN_INFO, scsi_target(cmd->device),
5012 "WARM TARGET RESET SUCCEEDED.\n");
5013 return SUCCESS;
5014}
5015
5016/**
Sarang Radke8a288962011-12-06 02:34:10 -08005017 * qla4xxx_is_eh_active - check if error handler is running
5018 * @shost: Pointer to SCSI Host struct
5019 *
5020 * This routine finds that if reset host is called in EH
5021 * scenario or from some application like sg_reset
5022 **/
5023static int qla4xxx_is_eh_active(struct Scsi_Host *shost)
5024{
5025 if (shost->shost_state == SHOST_RECOVERY)
5026 return 1;
5027 return 0;
5028}
5029
5030/**
David Somayajuluafaf5a22006-09-19 10:28:00 -07005031 * qla4xxx_eh_host_reset - kernel callback
5032 * @cmd: Pointer to Linux's SCSI command structure
5033 *
5034 * This routine is invoked by the Linux kernel to perform fatal error
5035 * recovery on the specified adapter.
5036 **/
5037static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd)
5038{
5039 int return_status = FAILED;
5040 struct scsi_qla_host *ha;
5041
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005042 ha = to_qla_host(cmd->device->host);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005043
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305044 if (ql4xdontresethba) {
5045 DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n",
5046 ha->host_no, __func__));
Sarang Radke8a288962011-12-06 02:34:10 -08005047
5048 /* Clear outstanding srb in queues */
5049 if (qla4xxx_is_eh_active(cmd->device->host))
5050 qla4xxx_abort_active_cmds(ha, DID_ABORT << 16);
5051
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305052 return FAILED;
5053 }
5054
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305055 ql4_printk(KERN_INFO, ha,
Karen Higginsdca05c42009-07-15 15:03:00 -05005056 "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005057 cmd->device->channel, cmd->device->id, cmd->device->lun);
5058
5059 if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) {
5060 DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter "
5061 "DEAD.\n", ha->host_no, cmd->device->channel,
5062 __func__));
5063
5064 return FAILED;
5065 }
5066
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305067 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5068 if (is_qla8022(ha))
5069 set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags);
5070 else
5071 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5072 }
Mike Christie50a29ae2008-03-04 13:26:53 -06005073
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305074 if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005075 return_status = SUCCESS;
David Somayajuluafaf5a22006-09-19 10:28:00 -07005076
Vikas Chaudharyc2660df2010-07-10 14:51:02 +05305077 ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n",
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005078 return_status == FAILED ? "FAILED" : "SUCCEEDED");
David Somayajuluafaf5a22006-09-19 10:28:00 -07005079
5080 return return_status;
5081}
5082
Vikas Chaudhary95d31262011-08-12 02:51:29 -07005083static int qla4xxx_context_reset(struct scsi_qla_host *ha)
5084{
5085 uint32_t mbox_cmd[MBOX_REG_COUNT];
5086 uint32_t mbox_sts[MBOX_REG_COUNT];
5087 struct addr_ctrl_blk_def *acb = NULL;
5088 uint32_t acb_len = sizeof(struct addr_ctrl_blk_def);
5089 int rval = QLA_SUCCESS;
5090 dma_addr_t acb_dma;
5091
5092 acb = dma_alloc_coherent(&ha->pdev->dev,
5093 sizeof(struct addr_ctrl_blk_def),
5094 &acb_dma, GFP_KERNEL);
5095 if (!acb) {
5096 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc acb\n",
5097 __func__);
5098 rval = -ENOMEM;
5099 goto exit_port_reset;
5100 }
5101
5102 memset(acb, 0, acb_len);
5103
5104 rval = qla4xxx_get_acb(ha, acb_dma, PRIMARI_ACB, acb_len);
5105 if (rval != QLA_SUCCESS) {
5106 rval = -EIO;
5107 goto exit_free_acb;
5108 }
5109
5110 rval = qla4xxx_disable_acb(ha);
5111 if (rval != QLA_SUCCESS) {
5112 rval = -EIO;
5113 goto exit_free_acb;
5114 }
5115
5116 wait_for_completion_timeout(&ha->disable_acb_comp,
5117 DISABLE_ACB_TOV * HZ);
5118
5119 rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], acb_dma);
5120 if (rval != QLA_SUCCESS) {
5121 rval = -EIO;
5122 goto exit_free_acb;
5123 }
5124
5125exit_free_acb:
5126 dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk_def),
5127 acb, acb_dma);
5128exit_port_reset:
5129 DEBUG2(ql4_printk(KERN_INFO, ha, "%s %s\n", __func__,
5130 rval == QLA_SUCCESS ? "SUCCEEDED" : "FAILED"));
5131 return rval;
5132}
5133
5134static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type)
5135{
5136 struct scsi_qla_host *ha = to_qla_host(shost);
5137 int rval = QLA_SUCCESS;
5138
5139 if (ql4xdontresethba) {
5140 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Don't Reset HBA\n",
5141 __func__));
5142 rval = -EPERM;
5143 goto exit_host_reset;
5144 }
5145
5146 rval = qla4xxx_wait_for_hba_online(ha);
5147 if (rval != QLA_SUCCESS) {
5148 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: Unable to reset host "
5149 "adapter\n", __func__));
5150 rval = -EIO;
5151 goto exit_host_reset;
5152 }
5153
5154 if (test_bit(DPC_RESET_HA, &ha->dpc_flags))
5155 goto recover_adapter;
5156
5157 switch (reset_type) {
5158 case SCSI_ADAPTER_RESET:
5159 set_bit(DPC_RESET_HA, &ha->dpc_flags);
5160 break;
5161 case SCSI_FIRMWARE_RESET:
5162 if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) {
5163 if (is_qla8022(ha))
5164 /* set firmware context reset */
5165 set_bit(DPC_RESET_HA_FW_CONTEXT,
5166 &ha->dpc_flags);
5167 else {
5168 rval = qla4xxx_context_reset(ha);
5169 goto exit_host_reset;
5170 }
5171 }
5172 break;
5173 }
5174
5175recover_adapter:
5176 rval = qla4xxx_recover_adapter(ha);
5177 if (rval != QLA_SUCCESS) {
5178 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: recover adapter fail\n",
5179 __func__));
5180 rval = -EIO;
5181 }
5182
5183exit_host_reset:
5184 return rval;
5185}
5186
Lalit Chandivade2232be02010-07-30 14:38:47 +05305187/* PCI AER driver recovers from all correctable errors w/o
5188 * driver intervention. For uncorrectable errors PCI AER
5189 * driver calls the following device driver's callbacks
5190 *
5191 * - Fatal Errors - link_reset
5192 * - Non-Fatal Errors - driver's pci_error_detected() which
5193 * returns CAN_RECOVER, NEED_RESET or DISCONNECT.
5194 *
5195 * PCI AER driver calls
5196 * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled
5197 * returns RECOVERED or NEED_RESET if fw_hung
5198 * NEED_RESET - driver's slot_reset()
5199 * DISCONNECT - device is dead & cannot recover
5200 * RECOVERED - driver's pci_resume()
5201 */
5202static pci_ers_result_t
5203qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
5204{
5205 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5206
5207 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n",
5208 ha->host_no, __func__, state);
5209
5210 if (!is_aer_supported(ha))
5211 return PCI_ERS_RESULT_NONE;
5212
5213 switch (state) {
5214 case pci_channel_io_normal:
5215 clear_bit(AF_EEH_BUSY, &ha->flags);
5216 return PCI_ERS_RESULT_CAN_RECOVER;
5217 case pci_channel_io_frozen:
5218 set_bit(AF_EEH_BUSY, &ha->flags);
5219 qla4xxx_mailbox_premature_completion(ha);
5220 qla4xxx_free_irqs(ha);
5221 pci_disable_device(pdev);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005222 /* Return back all IOs */
5223 qla4xxx_abort_active_cmds(ha, DID_RESET << 16);
Lalit Chandivade2232be02010-07-30 14:38:47 +05305224 return PCI_ERS_RESULT_NEED_RESET;
5225 case pci_channel_io_perm_failure:
5226 set_bit(AF_EEH_BUSY, &ha->flags);
5227 set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags);
5228 qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16);
5229 return PCI_ERS_RESULT_DISCONNECT;
5230 }
5231 return PCI_ERS_RESULT_NEED_RESET;
5232}
5233
5234/**
5235 * qla4xxx_pci_mmio_enabled() gets called if
5236 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
5237 * and read/write to the device still works.
5238 **/
5239static pci_ers_result_t
5240qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
5241{
5242 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5243
5244 if (!is_aer_supported(ha))
5245 return PCI_ERS_RESULT_NONE;
5246
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005247 return PCI_ERS_RESULT_RECOVERED;
Lalit Chandivade2232be02010-07-30 14:38:47 +05305248}
5249
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005250static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha)
Lalit Chandivade2232be02010-07-30 14:38:47 +05305251{
5252 uint32_t rval = QLA_ERROR;
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005253 uint32_t ret = 0;
Lalit Chandivade2232be02010-07-30 14:38:47 +05305254 int fn;
5255 struct pci_dev *other_pdev = NULL;
5256
5257 ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__);
5258
5259 set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5260
5261 if (test_bit(AF_ONLINE, &ha->flags)) {
5262 clear_bit(AF_ONLINE, &ha->flags);
Manish Rangankarb3a271a2011-07-25 13:48:53 -05005263 clear_bit(AF_LINK_UP, &ha->flags);
5264 iscsi_host_for_each_session(ha->host, qla4xxx_fail_session);
Lalit Chandivade2232be02010-07-30 14:38:47 +05305265 qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS);
Lalit Chandivade2232be02010-07-30 14:38:47 +05305266 }
5267
5268 fn = PCI_FUNC(ha->pdev->devfn);
5269 while (fn > 0) {
5270 fn--;
5271 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at "
5272 "func %x\n", ha->host_no, __func__, fn);
5273 /* Get the pci device given the domain, bus,
5274 * slot/function number */
5275 other_pdev =
5276 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
5277 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
5278 fn));
5279
5280 if (!other_pdev)
5281 continue;
5282
5283 if (atomic_read(&other_pdev->enable_cnt)) {
5284 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI "
5285 "func in enabled state%x\n", ha->host_no,
5286 __func__, fn);
5287 pci_dev_put(other_pdev);
5288 break;
5289 }
5290 pci_dev_put(other_pdev);
5291 }
5292
5293 /* The first function on the card, the reset owner will
5294 * start & initialize the firmware. The other functions
5295 * on the card will reset the firmware context
5296 */
5297 if (!fn) {
5298 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset "
5299 "0x%x is the owner\n", ha->host_no, __func__,
5300 ha->pdev->devfn);
5301
5302 qla4_8xxx_idc_lock(ha);
5303 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5304 QLA82XX_DEV_COLD);
5305
5306 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
5307 QLA82XX_IDC_VERSION);
5308
5309 qla4_8xxx_idc_unlock(ha);
5310 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06005311 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Lalit Chandivade2232be02010-07-30 14:38:47 +05305312 qla4_8xxx_idc_lock(ha);
5313
5314 if (rval != QLA_SUCCESS) {
5315 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5316 "FAILED\n", ha->host_no, __func__);
5317 qla4_8xxx_clear_drv_active(ha);
5318 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5319 QLA82XX_DEV_FAILED);
5320 } else {
5321 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: "
5322 "READY\n", ha->host_no, __func__);
5323 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
5324 QLA82XX_DEV_READY);
5325 /* Clear driver state register */
5326 qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
5327 qla4_8xxx_set_drv_active(ha);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005328 ret = qla4xxx_request_irqs(ha);
5329 if (ret) {
5330 ql4_printk(KERN_WARNING, ha, "Failed to "
5331 "reserve interrupt %d already in use.\n",
5332 ha->pdev->irq);
5333 rval = QLA_ERROR;
5334 } else {
5335 ha->isp_ops->enable_intrs(ha);
5336 rval = QLA_SUCCESS;
5337 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05305338 }
5339 qla4_8xxx_idc_unlock(ha);
5340 } else {
5341 ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not "
5342 "the reset owner\n", ha->host_no, __func__,
5343 ha->pdev->devfn);
5344 if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
5345 QLA82XX_DEV_READY)) {
5346 clear_bit(AF_FW_RECOVERY, &ha->flags);
Mike Christie13483732011-12-01 21:38:41 -06005347 rval = qla4xxx_initialize_adapter(ha, RESET_ADAPTER);
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005348 if (rval == QLA_SUCCESS) {
5349 ret = qla4xxx_request_irqs(ha);
5350 if (ret) {
5351 ql4_printk(KERN_WARNING, ha, "Failed to"
5352 " reserve interrupt %d already in"
5353 " use.\n", ha->pdev->irq);
5354 rval = QLA_ERROR;
5355 } else {
5356 ha->isp_ops->enable_intrs(ha);
5357 rval = QLA_SUCCESS;
5358 }
5359 }
Lalit Chandivade2232be02010-07-30 14:38:47 +05305360 qla4_8xxx_idc_lock(ha);
5361 qla4_8xxx_set_drv_active(ha);
5362 qla4_8xxx_idc_unlock(ha);
5363 }
5364 }
5365 clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags);
5366 return rval;
5367}
5368
5369static pci_ers_result_t
5370qla4xxx_pci_slot_reset(struct pci_dev *pdev)
5371{
5372 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
5373 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5374 int rc;
5375
5376 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n",
5377 ha->host_no, __func__);
5378
5379 if (!is_aer_supported(ha))
5380 return PCI_ERS_RESULT_NONE;
5381
5382 /* Restore the saved state of PCIe device -
5383 * BAR registers, PCI Config space, PCIX, MSI,
5384 * IOV states
5385 */
5386 pci_restore_state(pdev);
5387
5388 /* pci_restore_state() clears the saved_state flag of the device
5389 * save restored state which resets saved_state flag
5390 */
5391 pci_save_state(pdev);
5392
5393 /* Initialize device or resume if in suspended state */
5394 rc = pci_enable_device(pdev);
5395 if (rc) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005396 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable "
Lalit Chandivade2232be02010-07-30 14:38:47 +05305397 "device after reset\n", ha->host_no, __func__);
5398 goto exit_slot_reset;
5399 }
5400
Vikas Chaudhary7b3595d2010-10-06 22:50:56 -07005401 ha->isp_ops->disable_intrs(ha);
Lalit Chandivade2232be02010-07-30 14:38:47 +05305402
5403 if (is_qla8022(ha)) {
5404 if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) {
5405 ret = PCI_ERS_RESULT_RECOVERED;
5406 goto exit_slot_reset;
5407 } else
5408 goto exit_slot_reset;
5409 }
5410
5411exit_slot_reset:
5412 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n"
5413 "device after reset\n", ha->host_no, __func__, ret);
5414 return ret;
5415}
5416
5417static void
5418qla4xxx_pci_resume(struct pci_dev *pdev)
5419{
5420 struct scsi_qla_host *ha = pci_get_drvdata(pdev);
5421 int ret;
5422
5423 ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n",
5424 ha->host_no, __func__);
5425
5426 ret = qla4xxx_wait_for_hba_online(ha);
5427 if (ret != QLA_SUCCESS) {
5428 ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to "
5429 "resume I/O from slot/link_reset\n", ha->host_no,
5430 __func__);
5431 }
5432
5433 pci_cleanup_aer_uncorrect_error_status(pdev);
5434 clear_bit(AF_EEH_BUSY, &ha->flags);
5435}
5436
5437static struct pci_error_handlers qla4xxx_err_handler = {
5438 .error_detected = qla4xxx_pci_error_detected,
5439 .mmio_enabled = qla4xxx_pci_mmio_enabled,
5440 .slot_reset = qla4xxx_pci_slot_reset,
5441 .resume = qla4xxx_pci_resume,
5442};
5443
David Somayajuluafaf5a22006-09-19 10:28:00 -07005444static struct pci_device_id qla4xxx_pci_tbl[] = {
5445 {
5446 .vendor = PCI_VENDOR_ID_QLOGIC,
5447 .device = PCI_DEVICE_ID_QLOGIC_ISP4010,
5448 .subvendor = PCI_ANY_ID,
5449 .subdevice = PCI_ANY_ID,
5450 },
5451 {
5452 .vendor = PCI_VENDOR_ID_QLOGIC,
5453 .device = PCI_DEVICE_ID_QLOGIC_ISP4022,
5454 .subvendor = PCI_ANY_ID,
5455 .subdevice = PCI_ANY_ID,
5456 },
David C Somayajulud9150582006-11-15 17:38:40 -08005457 {
5458 .vendor = PCI_VENDOR_ID_QLOGIC,
5459 .device = PCI_DEVICE_ID_QLOGIC_ISP4032,
5460 .subvendor = PCI_ANY_ID,
5461 .subdevice = PCI_ANY_ID,
5462 },
Vikas Chaudharyf4f5df232010-07-28 15:53:44 +05305463 {
5464 .vendor = PCI_VENDOR_ID_QLOGIC,
5465 .device = PCI_DEVICE_ID_QLOGIC_ISP8022,
5466 .subvendor = PCI_ANY_ID,
5467 .subdevice = PCI_ANY_ID,
5468 },
David Somayajuluafaf5a22006-09-19 10:28:00 -07005469 {0, 0},
5470};
5471MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
5472
Adrian Bunk47975472007-04-26 00:35:16 -07005473static struct pci_driver qla4xxx_pci_driver = {
David Somayajuluafaf5a22006-09-19 10:28:00 -07005474 .name = DRIVER_NAME,
5475 .id_table = qla4xxx_pci_tbl,
5476 .probe = qla4xxx_probe_adapter,
5477 .remove = qla4xxx_remove_adapter,
Lalit Chandivade2232be02010-07-30 14:38:47 +05305478 .err_handler = &qla4xxx_err_handler,
David Somayajuluafaf5a22006-09-19 10:28:00 -07005479};
5480
5481static int __init qla4xxx_module_init(void)
5482{
5483 int ret;
5484
5485 /* Allocate cache for SRBs. */
5486 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09005487 SLAB_HWCACHE_ALIGN, NULL);
David Somayajuluafaf5a22006-09-19 10:28:00 -07005488 if (srb_cachep == NULL) {
5489 printk(KERN_ERR
5490 "%s: Unable to allocate SRB cache..."
5491 "Failing load!\n", DRIVER_NAME);
5492 ret = -ENOMEM;
5493 goto no_srp_cache;
5494 }
5495
5496 /* Derive version string. */
5497 strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07005498 if (ql4xextended_error_logging)
David Somayajuluafaf5a22006-09-19 10:28:00 -07005499 strcat(qla4xxx_version_str, "-debug");
5500
5501 qla4xxx_scsi_transport =
5502 iscsi_register_transport(&qla4xxx_iscsi_transport);
5503 if (!qla4xxx_scsi_transport){
5504 ret = -ENODEV;
5505 goto release_srb_cache;
5506 }
5507
David Somayajuluafaf5a22006-09-19 10:28:00 -07005508 ret = pci_register_driver(&qla4xxx_pci_driver);
5509 if (ret)
5510 goto unregister_transport;
5511
5512 printk(KERN_INFO "QLogic iSCSI HBA Driver\n");
5513 return 0;
Doug Maxey5ae16db2006-10-05 23:50:07 -05005514
David Somayajuluafaf5a22006-09-19 10:28:00 -07005515unregister_transport:
5516 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
5517release_srb_cache:
5518 kmem_cache_destroy(srb_cachep);
5519no_srp_cache:
5520 return ret;
5521}
5522
5523static void __exit qla4xxx_module_exit(void)
5524{
David Somayajuluafaf5a22006-09-19 10:28:00 -07005525 pci_unregister_driver(&qla4xxx_pci_driver);
5526 iscsi_unregister_transport(&qla4xxx_iscsi_transport);
5527 kmem_cache_destroy(srb_cachep);
5528}
5529
5530module_init(qla4xxx_module_init);
5531module_exit(qla4xxx_module_exit);
5532
5533MODULE_AUTHOR("QLogic Corporation");
5534MODULE_DESCRIPTION("QLogic iSCSI HBA Driver");
5535MODULE_LICENSE("GPL");
5536MODULE_VERSION(QLA4XXX_DRIVER_VERSION);