]>
Commit | Line | Data |
---|---|---|
afaf5a2d DS |
1 | /* |
2 | * QLogic iSCSI HBA Driver | |
7d01d069 | 3 | * Copyright (c) 2003-2010 QLogic Corporation |
afaf5a2d DS |
4 | * |
5 | * See LICENSE.qla4xxx for copyright and licensing details. | |
6 | */ | |
7 | #include <linux/moduleparam.h> | |
5a0e3ad6 | 8 | #include <linux/slab.h> |
afaf5a2d DS |
9 | |
10 | #include <scsi/scsi_tcq.h> | |
11 | #include <scsi/scsicam.h> | |
12 | ||
13 | #include "ql4_def.h" | |
bee4fe8e DS |
14 | #include "ql4_version.h" |
15 | #include "ql4_glbl.h" | |
16 | #include "ql4_dbg.h" | |
17 | #include "ql4_inline.h" | |
afaf5a2d DS |
18 | |
19 | /* | |
20 | * Driver version | |
21 | */ | |
47975477 | 22 | static char qla4xxx_version_str[40]; |
afaf5a2d DS |
23 | |
24 | /* | |
25 | * SRB allocation cache | |
26 | */ | |
e18b890b | 27 | static struct kmem_cache *srb_cachep; |
afaf5a2d DS |
28 | |
29 | /* | |
30 | * Module parameter information and variables | |
31 | */ | |
afaf5a2d | 32 | int ql4xdontresethba = 0; |
f4f5df23 | 33 | module_param(ql4xdontresethba, int, S_IRUGO | S_IWUSR); |
afaf5a2d | 34 | MODULE_PARM_DESC(ql4xdontresethba, |
f4f5df23 VC |
35 | "Don't reset the HBA for driver recovery \n" |
36 | " 0 - It will reset HBA (Default)\n" | |
37 | " 1 - It will NOT reset HBA"); | |
afaf5a2d | 38 | |
11010fec | 39 | int ql4xextended_error_logging = 0; /* 0 = off, 1 = log errors */ |
f4f5df23 | 40 | module_param(ql4xextended_error_logging, int, S_IRUGO | S_IWUSR); |
11010fec | 41 | MODULE_PARM_DESC(ql4xextended_error_logging, |
afaf5a2d DS |
42 | "Option to enable extended error logging, " |
43 | "Default is 0 - no logging, 1 - debug logging"); | |
44 | ||
f4f5df23 VC |
45 | int ql4xenablemsix = 1; |
46 | module_param(ql4xenablemsix, int, S_IRUGO|S_IWUSR); | |
47 | MODULE_PARM_DESC(ql4xenablemsix, | |
48 | "Set to enable MSI or MSI-X interrupt mechanism.\n" | |
49 | " 0 = enable INTx interrupt mechanism.\n" | |
50 | " 1 = enable MSI-X interrupt mechanism (Default).\n" | |
51 | " 2 = enable MSI interrupt mechanism."); | |
477ffb9d | 52 | |
d510d965 | 53 | #define QL4_DEF_QDEPTH 32 |
8bb4033d VC |
54 | static int ql4xmaxqdepth = QL4_DEF_QDEPTH; |
55 | module_param(ql4xmaxqdepth, int, S_IRUGO | S_IWUSR); | |
56 | MODULE_PARM_DESC(ql4xmaxqdepth, | |
57 | "Maximum queue depth to report for target devices.\n" | |
58 | " Default: 32."); | |
d510d965 | 59 | |
3038727c VC |
60 | static int ql4xsess_recovery_tmo = QL4_SESS_RECOVERY_TMO; |
61 | module_param(ql4xsess_recovery_tmo, int, S_IRUGO); | |
62 | MODULE_PARM_DESC(ql4xsess_recovery_tmo, | |
63 | "Target Session Recovery Timeout.\n" | |
64 | " Default: 30 sec."); | |
65 | ||
afaf5a2d DS |
66 | /* |
67 | * SCSI host template entry points | |
68 | */ | |
47975477 | 69 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha); |
afaf5a2d DS |
70 | |
71 | /* | |
72 | * iSCSI template entry points | |
73 | */ | |
2174a04e MC |
74 | static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost, |
75 | enum iscsi_tgt_dscvr type, uint32_t enable, | |
76 | struct sockaddr *dst_addr); | |
afaf5a2d DS |
77 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, |
78 | enum iscsi_param param, char *buf); | |
79 | static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess, | |
80 | enum iscsi_param param, char *buf); | |
aa1e93a2 MC |
81 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
82 | enum iscsi_host_param param, char *buf); | |
d00efe3f MC |
83 | static int qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, |
84 | int count); | |
ed1086e0 VC |
85 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
86 | enum iscsi_param_type param_type, | |
87 | int param, char *buf); | |
afaf5a2d | 88 | static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session); |
5c656af7 | 89 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc); |
afaf5a2d DS |
90 | |
91 | /* | |
92 | * SCSI host template entry points | |
93 | */ | |
f281233d | 94 | static int qla4xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd); |
09a0f719 | 95 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd); |
afaf5a2d | 96 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd); |
ce545039 | 97 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); |
afaf5a2d DS |
98 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); |
99 | static int qla4xxx_slave_alloc(struct scsi_device *device); | |
100 | static int qla4xxx_slave_configure(struct scsi_device *device); | |
101 | static void qla4xxx_slave_destroy(struct scsi_device *sdev); | |
024f801f | 102 | static void qla4xxx_scan_start(struct Scsi_Host *shost); |
3128c6c7 | 103 | static mode_t ql4_attr_is_visible(int param_type, int param); |
afaf5a2d | 104 | |
f4f5df23 VC |
105 | static struct qla4_8xxx_legacy_intr_set legacy_intr[] = |
106 | QLA82XX_LEGACY_INTR_CONFIG; | |
107 | ||
afaf5a2d DS |
108 | static struct scsi_host_template qla4xxx_driver_template = { |
109 | .module = THIS_MODULE, | |
110 | .name = DRIVER_NAME, | |
111 | .proc_name = DRIVER_NAME, | |
112 | .queuecommand = qla4xxx_queuecommand, | |
113 | ||
09a0f719 | 114 | .eh_abort_handler = qla4xxx_eh_abort, |
afaf5a2d | 115 | .eh_device_reset_handler = qla4xxx_eh_device_reset, |
ce545039 | 116 | .eh_target_reset_handler = qla4xxx_eh_target_reset, |
afaf5a2d | 117 | .eh_host_reset_handler = qla4xxx_eh_host_reset, |
5c656af7 | 118 | .eh_timed_out = qla4xxx_eh_cmd_timed_out, |
afaf5a2d DS |
119 | |
120 | .slave_configure = qla4xxx_slave_configure, | |
121 | .slave_alloc = qla4xxx_slave_alloc, | |
122 | .slave_destroy = qla4xxx_slave_destroy, | |
123 | ||
921601b7 | 124 | .scan_finished = iscsi_scan_finished, |
024f801f | 125 | .scan_start = qla4xxx_scan_start, |
921601b7 | 126 | |
afaf5a2d DS |
127 | .this_id = -1, |
128 | .cmd_per_lun = 3, | |
129 | .use_clustering = ENABLE_CLUSTERING, | |
130 | .sg_tablesize = SG_ALL, | |
131 | ||
132 | .max_sectors = 0xFFFF, | |
7ad633c0 | 133 | .shost_attrs = qla4xxx_host_attrs, |
afaf5a2d DS |
134 | }; |
135 | ||
136 | static struct iscsi_transport qla4xxx_iscsi_transport = { | |
137 | .owner = THIS_MODULE, | |
138 | .name = DRIVER_NAME, | |
d8196ed2 MC |
139 | .caps = CAP_FW_DB | CAP_SENDTARGETS_OFFLOAD | |
140 | CAP_DATA_PATH_OFFLOAD, | |
3128c6c7 | 141 | .param_mask = ISCSI_TARGET_NAME | ISCSI_TPGT | |
3b2bef1f | 142 | ISCSI_TARGET_ALIAS, |
8ad5781a | 143 | .host_param_mask = ISCSI_HOST_HWADDRESS | |
22236961 | 144 | ISCSI_HOST_IPADDRESS | |
8ad5781a | 145 | ISCSI_HOST_INITIATOR_NAME, |
ed1086e0 VC |
146 | .iface_param_mask = ISCSI_NET_IPV4_ADDR | |
147 | ISCSI_NET_IPV4_SUBNET | | |
148 | ISCSI_NET_IPV4_GW | | |
149 | ISCSI_NET_IPV4_BOOTPROTO | | |
150 | ISCSI_NET_IFACE_ENABLE | | |
151 | ISCSI_NET_IPV6_LINKLOCAL | | |
152 | ISCSI_NET_IPV6_ADDR | | |
153 | ISCSI_NET_IPV6_ROUTER | | |
154 | ISCSI_NET_IPV6_ADDR_AUTOCFG | | |
155 | ISCSI_NET_IPV6_LINKLOCAL_AUTOCFG | | |
156 | ISCSI_NET_IFACE_ENABLE, | |
afaf5a2d | 157 | .tgt_dscvr = qla4xxx_tgt_dscvr, |
3128c6c7 | 158 | .attr_is_visible = ql4_attr_is_visible, |
afaf5a2d DS |
159 | .get_conn_param = qla4xxx_conn_get_param, |
160 | .get_session_param = qla4xxx_sess_get_param, | |
aa1e93a2 | 161 | .get_host_param = qla4xxx_host_get_param, |
d00efe3f | 162 | .set_iface_param = qla4xxx_iface_set_param, |
afaf5a2d | 163 | .session_recovery_timedout = qla4xxx_recovery_timedout, |
ed1086e0 | 164 | .get_iface_param = qla4xxx_get_iface_param, |
afaf5a2d DS |
165 | }; |
166 | ||
167 | static struct scsi_transport_template *qla4xxx_scsi_transport; | |
168 | ||
3128c6c7 MC |
169 | static mode_t ql4_attr_is_visible(int param_type, int param) |
170 | { | |
171 | switch (param_type) { | |
172 | case ISCSI_PARAM: | |
173 | switch (param) { | |
174 | case ISCSI_PARAM_CONN_ADDRESS: | |
175 | case ISCSI_PARAM_CONN_PORT: | |
176 | return S_IRUGO; | |
177 | default: | |
178 | return 0; | |
179 | } | |
180 | } | |
181 | ||
182 | return 0; | |
183 | } | |
184 | ||
ed1086e0 VC |
185 | static int qla4xxx_get_iface_param(struct iscsi_iface *iface, |
186 | enum iscsi_param_type param_type, | |
187 | int param, char *buf) | |
188 | { | |
189 | struct Scsi_Host *shost = iscsi_iface_to_shost(iface); | |
190 | struct scsi_qla_host *ha = to_qla_host(shost); | |
191 | int len = -ENOSYS; | |
192 | ||
193 | if (param_type != ISCSI_NET_PARAM) | |
194 | return -ENOSYS; | |
195 | ||
196 | switch (param) { | |
197 | case ISCSI_NET_PARAM_IPV4_ADDR: | |
198 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); | |
199 | break; | |
200 | case ISCSI_NET_PARAM_IPV4_SUBNET: | |
201 | len = sprintf(buf, "%pI4\n", &ha->ip_config.subnet_mask); | |
202 | break; | |
203 | case ISCSI_NET_PARAM_IPV4_GW: | |
204 | len = sprintf(buf, "%pI4\n", &ha->ip_config.gateway); | |
205 | break; | |
206 | case ISCSI_NET_PARAM_IFACE_ENABLE: | |
207 | if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) | |
208 | len = sprintf(buf, "%s\n", | |
209 | (ha->ip_config.ipv4_options & | |
210 | IPOPT_IPV4_PROTOCOL_ENABLE) ? | |
211 | "enabled" : "disabled"); | |
212 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) | |
213 | len = sprintf(buf, "%s\n", | |
214 | (ha->ip_config.ipv6_options & | |
215 | IPV6_OPT_IPV6_PROTOCOL_ENABLE) ? | |
216 | "enabled" : "disabled"); | |
217 | break; | |
218 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: | |
219 | len = sprintf(buf, "%s\n", | |
220 | (ha->ip_config.tcp_options & TCPOPT_DHCP_ENABLE) ? | |
221 | "dhcp" : "static"); | |
222 | break; | |
223 | case ISCSI_NET_PARAM_IPV6_ADDR: | |
224 | if (iface->iface_num == 0) | |
225 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr0); | |
226 | if (iface->iface_num == 1) | |
227 | len = sprintf(buf, "%pI6\n", &ha->ip_config.ipv6_addr1); | |
228 | break; | |
229 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: | |
230 | len = sprintf(buf, "%pI6\n", | |
231 | &ha->ip_config.ipv6_link_local_addr); | |
232 | break; | |
233 | case ISCSI_NET_PARAM_IPV6_ROUTER: | |
234 | len = sprintf(buf, "%pI6\n", | |
235 | &ha->ip_config.ipv6_default_router_addr); | |
236 | break; | |
237 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: | |
238 | len = sprintf(buf, "%s\n", | |
239 | (ha->ip_config.ipv6_addl_options & | |
240 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE) ? | |
241 | "nd" : "static"); | |
242 | break; | |
243 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: | |
244 | len = sprintf(buf, "%s\n", | |
245 | (ha->ip_config.ipv6_addl_options & | |
246 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR) ? | |
247 | "auto" : "static"); | |
248 | break; | |
249 | default: | |
250 | len = -ENOSYS; | |
251 | } | |
252 | ||
253 | return len; | |
254 | } | |
255 | ||
5c656af7 MC |
256 | static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc) |
257 | { | |
258 | struct iscsi_cls_session *session; | |
259 | struct ddb_entry *ddb_entry; | |
260 | ||
261 | session = starget_to_session(scsi_target(sc->device)); | |
262 | ddb_entry = session->dd_data; | |
263 | ||
264 | /* if we are not logged in then the LLD is going to clean up the cmd */ | |
265 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) | |
266 | return BLK_EH_RESET_TIMER; | |
267 | else | |
268 | return BLK_EH_NOT_HANDLED; | |
269 | } | |
270 | ||
afaf5a2d DS |
271 | static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session) |
272 | { | |
273 | struct ddb_entry *ddb_entry = session->dd_data; | |
274 | struct scsi_qla_host *ha = ddb_entry->ha; | |
275 | ||
568d303b MC |
276 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { |
277 | atomic_set(&ddb_entry->state, DDB_STATE_DEAD); | |
278 | ||
3013cea8 | 279 | DEBUG2(printk("scsi%ld: %s: ddb [%d] session recovery timeout " |
568d303b MC |
280 | "of (%d) secs exhausted, marking device DEAD.\n", |
281 | ha->host_no, __func__, ddb_entry->fw_ddb_index, | |
3038727c | 282 | ddb_entry->sess->recovery_tmo)); |
568d303b | 283 | } |
afaf5a2d DS |
284 | } |
285 | ||
aa1e93a2 MC |
286 | static int qla4xxx_host_get_param(struct Scsi_Host *shost, |
287 | enum iscsi_host_param param, char *buf) | |
288 | { | |
289 | struct scsi_qla_host *ha = to_qla_host(shost); | |
290 | int len; | |
291 | ||
292 | switch (param) { | |
293 | case ISCSI_HOST_PARAM_HWADDRESS: | |
7ffc49a6 | 294 | len = sysfs_format_mac(buf, ha->my_mac, MAC_ADDR_LEN); |
8ad5781a | 295 | break; |
22236961 | 296 | case ISCSI_HOST_PARAM_IPADDRESS: |
2bab08fc | 297 | len = sprintf(buf, "%pI4\n", &ha->ip_config.ip_address); |
22236961 | 298 | break; |
8ad5781a | 299 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
22236961 | 300 | len = sprintf(buf, "%s\n", ha->name_string); |
aa1e93a2 MC |
301 | break; |
302 | default: | |
303 | return -ENOSYS; | |
304 | } | |
305 | ||
306 | return len; | |
307 | } | |
308 | ||
ed1086e0 VC |
309 | static void qla4xxx_create_ipv4_iface(struct scsi_qla_host *ha) |
310 | { | |
311 | if (ha->iface_ipv4) | |
312 | return; | |
313 | ||
314 | /* IPv4 */ | |
315 | ha->iface_ipv4 = iscsi_create_iface(ha->host, | |
316 | &qla4xxx_iscsi_transport, | |
317 | ISCSI_IFACE_TYPE_IPV4, 0, 0); | |
318 | if (!ha->iface_ipv4) | |
319 | ql4_printk(KERN_ERR, ha, "Could not create IPv4 iSCSI " | |
320 | "iface0.\n"); | |
321 | } | |
322 | ||
323 | static void qla4xxx_create_ipv6_iface(struct scsi_qla_host *ha) | |
324 | { | |
325 | if (!ha->iface_ipv6_0) | |
326 | /* IPv6 iface-0 */ | |
327 | ha->iface_ipv6_0 = iscsi_create_iface(ha->host, | |
328 | &qla4xxx_iscsi_transport, | |
329 | ISCSI_IFACE_TYPE_IPV6, 0, | |
330 | 0); | |
331 | if (!ha->iface_ipv6_0) | |
332 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " | |
333 | "iface0.\n"); | |
334 | ||
335 | if (!ha->iface_ipv6_1) | |
336 | /* IPv6 iface-1 */ | |
337 | ha->iface_ipv6_1 = iscsi_create_iface(ha->host, | |
338 | &qla4xxx_iscsi_transport, | |
339 | ISCSI_IFACE_TYPE_IPV6, 1, | |
340 | 0); | |
341 | if (!ha->iface_ipv6_1) | |
342 | ql4_printk(KERN_ERR, ha, "Could not create IPv6 iSCSI " | |
343 | "iface1.\n"); | |
344 | } | |
345 | ||
346 | static void qla4xxx_create_ifaces(struct scsi_qla_host *ha) | |
347 | { | |
348 | if (ha->ip_config.ipv4_options & IPOPT_IPV4_PROTOCOL_ENABLE) | |
349 | qla4xxx_create_ipv4_iface(ha); | |
350 | ||
351 | if (ha->ip_config.ipv6_options & IPV6_OPT_IPV6_PROTOCOL_ENABLE) | |
352 | qla4xxx_create_ipv6_iface(ha); | |
353 | } | |
354 | ||
355 | static void qla4xxx_destroy_ipv4_iface(struct scsi_qla_host *ha) | |
356 | { | |
357 | if (ha->iface_ipv4) { | |
358 | iscsi_destroy_iface(ha->iface_ipv4); | |
359 | ha->iface_ipv4 = NULL; | |
360 | } | |
361 | } | |
362 | ||
363 | static void qla4xxx_destroy_ipv6_iface(struct scsi_qla_host *ha) | |
364 | { | |
365 | if (ha->iface_ipv6_0) { | |
366 | iscsi_destroy_iface(ha->iface_ipv6_0); | |
367 | ha->iface_ipv6_0 = NULL; | |
368 | } | |
369 | if (ha->iface_ipv6_1) { | |
370 | iscsi_destroy_iface(ha->iface_ipv6_1); | |
371 | ha->iface_ipv6_1 = NULL; | |
372 | } | |
373 | } | |
374 | ||
375 | static void qla4xxx_destroy_ifaces(struct scsi_qla_host *ha) | |
376 | { | |
377 | qla4xxx_destroy_ipv4_iface(ha); | |
378 | qla4xxx_destroy_ipv6_iface(ha); | |
379 | } | |
380 | ||
d00efe3f MC |
381 | static void qla4xxx_set_ipv6(struct scsi_qla_host *ha, |
382 | struct iscsi_iface_param_info *iface_param, | |
383 | struct addr_ctrl_blk *init_fw_cb) | |
384 | { | |
385 | /* | |
386 | * iface_num 0 is valid for IPv6 Addr, linklocal, router, autocfg. | |
387 | * iface_num 1 is valid only for IPv6 Addr. | |
388 | */ | |
389 | switch (iface_param->param) { | |
390 | case ISCSI_NET_PARAM_IPV6_ADDR: | |
391 | if (iface_param->iface_num & 0x1) | |
392 | /* IPv6 Addr 1 */ | |
393 | memcpy(init_fw_cb->ipv6_addr1, iface_param->value, | |
394 | sizeof(init_fw_cb->ipv6_addr1)); | |
395 | else | |
396 | /* IPv6 Addr 0 */ | |
397 | memcpy(init_fw_cb->ipv6_addr0, iface_param->value, | |
398 | sizeof(init_fw_cb->ipv6_addr0)); | |
399 | break; | |
400 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL: | |
401 | if (iface_param->iface_num & 0x1) | |
402 | break; | |
403 | memcpy(init_fw_cb->ipv6_if_id, &iface_param->value[8], | |
404 | sizeof(init_fw_cb->ipv6_if_id)); | |
405 | break; | |
406 | case ISCSI_NET_PARAM_IPV6_ROUTER: | |
407 | if (iface_param->iface_num & 0x1) | |
408 | break; | |
409 | memcpy(init_fw_cb->ipv6_dflt_rtr_addr, iface_param->value, | |
410 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); | |
411 | break; | |
412 | case ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG: | |
413 | /* Autocfg applies to even interface */ | |
414 | if (iface_param->iface_num & 0x1) | |
415 | break; | |
416 | ||
417 | if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_DISABLE) | |
418 | init_fw_cb->ipv6_addtl_opts &= | |
419 | cpu_to_le16( | |
420 | ~IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); | |
421 | else if (iface_param->value[0] == ISCSI_IPV6_AUTOCFG_ND_ENABLE) | |
422 | init_fw_cb->ipv6_addtl_opts |= | |
423 | cpu_to_le16( | |
424 | IPV6_ADDOPT_NEIGHBOR_DISCOVERY_ADDR_ENABLE); | |
425 | else | |
426 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " | |
427 | "IPv6 addr\n"); | |
428 | break; | |
429 | case ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG: | |
430 | /* Autocfg applies to even interface */ | |
431 | if (iface_param->iface_num & 0x1) | |
432 | break; | |
433 | ||
434 | if (iface_param->value[0] == | |
435 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_ENABLE) | |
436 | init_fw_cb->ipv6_addtl_opts |= cpu_to_le16( | |
437 | IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); | |
438 | else if (iface_param->value[0] == | |
439 | ISCSI_IPV6_LINKLOCAL_AUTOCFG_DISABLE) | |
440 | init_fw_cb->ipv6_addtl_opts &= cpu_to_le16( | |
441 | ~IPV6_ADDOPT_AUTOCONFIG_LINK_LOCAL_ADDR); | |
442 | else | |
443 | ql4_printk(KERN_ERR, ha, "Invalid autocfg setting for " | |
444 | "IPv6 linklocal addr\n"); | |
445 | break; | |
446 | case ISCSI_NET_PARAM_IPV6_ROUTER_AUTOCFG: | |
447 | /* Autocfg applies to even interface */ | |
448 | if (iface_param->iface_num & 0x1) | |
449 | break; | |
450 | ||
451 | if (iface_param->value[0] == ISCSI_IPV6_ROUTER_AUTOCFG_ENABLE) | |
452 | memset(init_fw_cb->ipv6_dflt_rtr_addr, 0, | |
453 | sizeof(init_fw_cb->ipv6_dflt_rtr_addr)); | |
454 | break; | |
455 | case ISCSI_NET_PARAM_IFACE_ENABLE: | |
ed1086e0 | 456 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
d00efe3f MC |
457 | init_fw_cb->ipv6_opts |= |
458 | cpu_to_le16(IPV6_OPT_IPV6_PROTOCOL_ENABLE); | |
ed1086e0 VC |
459 | qla4xxx_create_ipv6_iface(ha); |
460 | } else { | |
d00efe3f MC |
461 | init_fw_cb->ipv6_opts &= |
462 | cpu_to_le16(~IPV6_OPT_IPV6_PROTOCOL_ENABLE & | |
463 | 0xFFFF); | |
ed1086e0 VC |
464 | qla4xxx_destroy_ipv6_iface(ha); |
465 | } | |
d00efe3f MC |
466 | break; |
467 | case ISCSI_NET_PARAM_VLAN_ID: | |
468 | if (iface_param->len != sizeof(init_fw_cb->ipv6_vlan_tag)) | |
469 | break; | |
470 | init_fw_cb->ipv6_vlan_tag = *(uint16_t *)iface_param->value; | |
471 | break; | |
472 | default: | |
473 | ql4_printk(KERN_ERR, ha, "Unknown IPv6 param = %d\n", | |
474 | iface_param->param); | |
475 | break; | |
476 | } | |
477 | } | |
478 | ||
479 | static void qla4xxx_set_ipv4(struct scsi_qla_host *ha, | |
480 | struct iscsi_iface_param_info *iface_param, | |
481 | struct addr_ctrl_blk *init_fw_cb) | |
482 | { | |
483 | switch (iface_param->param) { | |
484 | case ISCSI_NET_PARAM_IPV4_ADDR: | |
485 | memcpy(init_fw_cb->ipv4_addr, iface_param->value, | |
486 | sizeof(init_fw_cb->ipv4_addr)); | |
487 | break; | |
488 | case ISCSI_NET_PARAM_IPV4_SUBNET: | |
489 | memcpy(init_fw_cb->ipv4_subnet, iface_param->value, | |
490 | sizeof(init_fw_cb->ipv4_subnet)); | |
491 | break; | |
492 | case ISCSI_NET_PARAM_IPV4_GW: | |
493 | memcpy(init_fw_cb->ipv4_gw_addr, iface_param->value, | |
494 | sizeof(init_fw_cb->ipv4_gw_addr)); | |
495 | break; | |
496 | case ISCSI_NET_PARAM_IPV4_BOOTPROTO: | |
497 | if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP) | |
498 | init_fw_cb->ipv4_tcp_opts |= | |
499 | cpu_to_le16(TCPOPT_DHCP_ENABLE); | |
500 | else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC) | |
501 | init_fw_cb->ipv4_tcp_opts &= | |
502 | cpu_to_le16(~TCPOPT_DHCP_ENABLE); | |
503 | else | |
504 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 bootproto\n"); | |
505 | break; | |
506 | case ISCSI_NET_PARAM_IFACE_ENABLE: | |
ed1086e0 | 507 | if (iface_param->value[0] == ISCSI_IFACE_ENABLE) { |
d00efe3f | 508 | init_fw_cb->ipv4_ip_opts |= |
2bab08fc | 509 | cpu_to_le16(IPOPT_IPV4_PROTOCOL_ENABLE); |
ed1086e0 VC |
510 | qla4xxx_create_ipv4_iface(ha); |
511 | } else { | |
d00efe3f | 512 | init_fw_cb->ipv4_ip_opts &= |
2bab08fc | 513 | cpu_to_le16(~IPOPT_IPV4_PROTOCOL_ENABLE & |
d00efe3f | 514 | 0xFFFF); |
ed1086e0 VC |
515 | qla4xxx_destroy_ipv4_iface(ha); |
516 | } | |
d00efe3f MC |
517 | break; |
518 | case ISCSI_NET_PARAM_VLAN_ID: | |
519 | if (iface_param->len != sizeof(init_fw_cb->ipv4_vlan_tag)) | |
520 | break; | |
521 | init_fw_cb->ipv4_vlan_tag = *(uint16_t *)iface_param->value; | |
522 | break; | |
523 | default: | |
524 | ql4_printk(KERN_ERR, ha, "Unknown IPv4 param = %d\n", | |
525 | iface_param->param); | |
526 | break; | |
527 | } | |
528 | } | |
529 | ||
530 | static void | |
531 | qla4xxx_initcb_to_acb(struct addr_ctrl_blk *init_fw_cb) | |
532 | { | |
533 | struct addr_ctrl_blk_def *acb; | |
534 | acb = (struct addr_ctrl_blk_def *)init_fw_cb; | |
535 | memset(acb->reserved1, 0, sizeof(acb->reserved1)); | |
536 | memset(acb->reserved2, 0, sizeof(acb->reserved2)); | |
537 | memset(acb->reserved3, 0, sizeof(acb->reserved3)); | |
538 | memset(acb->reserved4, 0, sizeof(acb->reserved4)); | |
539 | memset(acb->reserved5, 0, sizeof(acb->reserved5)); | |
540 | memset(acb->reserved6, 0, sizeof(acb->reserved6)); | |
541 | memset(acb->reserved7, 0, sizeof(acb->reserved7)); | |
542 | memset(acb->reserved8, 0, sizeof(acb->reserved8)); | |
543 | memset(acb->reserved9, 0, sizeof(acb->reserved9)); | |
544 | memset(acb->reserved10, 0, sizeof(acb->reserved10)); | |
545 | memset(acb->reserved11, 0, sizeof(acb->reserved11)); | |
546 | memset(acb->reserved12, 0, sizeof(acb->reserved12)); | |
547 | memset(acb->reserved13, 0, sizeof(acb->reserved13)); | |
548 | memset(acb->reserved14, 0, sizeof(acb->reserved14)); | |
549 | memset(acb->reserved15, 0, sizeof(acb->reserved15)); | |
550 | } | |
551 | ||
552 | static int | |
553 | qla4xxx_iface_set_param(struct Scsi_Host *shost, char *data, int count) | |
554 | { | |
555 | struct scsi_qla_host *ha = to_qla_host(shost); | |
556 | int rval = 0; | |
557 | struct iscsi_iface_param_info *iface_param = NULL; | |
558 | struct addr_ctrl_blk *init_fw_cb = NULL; | |
559 | dma_addr_t init_fw_cb_dma; | |
560 | uint32_t mbox_cmd[MBOX_REG_COUNT]; | |
561 | uint32_t mbox_sts[MBOX_REG_COUNT]; | |
562 | uint32_t total_param_count; | |
563 | uint32_t length; | |
564 | ||
565 | init_fw_cb = dma_alloc_coherent(&ha->pdev->dev, | |
566 | sizeof(struct addr_ctrl_blk), | |
567 | &init_fw_cb_dma, GFP_KERNEL); | |
568 | if (!init_fw_cb) { | |
569 | ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n", | |
570 | __func__); | |
571 | return -ENOMEM; | |
572 | } | |
573 | ||
574 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); | |
575 | memset(&mbox_cmd, 0, sizeof(mbox_cmd)); | |
576 | memset(&mbox_sts, 0, sizeof(mbox_sts)); | |
577 | ||
578 | if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma)) { | |
579 | ql4_printk(KERN_ERR, ha, "%s: get ifcb failed\n", __func__); | |
580 | rval = -EIO; | |
581 | goto exit_init_fw_cb; | |
582 | } | |
583 | ||
584 | total_param_count = count; | |
585 | iface_param = (struct iscsi_iface_param_info *)data; | |
586 | ||
587 | for ( ; total_param_count != 0; total_param_count--) { | |
588 | length = iface_param->len; | |
589 | ||
590 | if (iface_param->param_type != ISCSI_NET_PARAM) | |
591 | continue; | |
592 | ||
593 | switch (iface_param->iface_type) { | |
594 | case ISCSI_IFACE_TYPE_IPV4: | |
595 | switch (iface_param->iface_num) { | |
596 | case 0: | |
597 | qla4xxx_set_ipv4(ha, iface_param, init_fw_cb); | |
598 | break; | |
599 | default: | |
600 | /* Cannot have more than one IPv4 interface */ | |
601 | ql4_printk(KERN_ERR, ha, "Invalid IPv4 iface " | |
602 | "number = %d\n", | |
603 | iface_param->iface_num); | |
604 | break; | |
605 | } | |
606 | break; | |
607 | case ISCSI_IFACE_TYPE_IPV6: | |
608 | switch (iface_param->iface_num) { | |
609 | case 0: | |
610 | case 1: | |
611 | qla4xxx_set_ipv6(ha, iface_param, init_fw_cb); | |
612 | break; | |
613 | default: | |
614 | /* Cannot have more than two IPv6 interface */ | |
615 | ql4_printk(KERN_ERR, ha, "Invalid IPv6 iface " | |
616 | "number = %d\n", | |
617 | iface_param->iface_num); | |
618 | break; | |
619 | } | |
620 | break; | |
621 | default: | |
622 | ql4_printk(KERN_ERR, ha, "Invalid iface type\n"); | |
623 | break; | |
624 | } | |
625 | ||
626 | iface_param = (struct iscsi_iface_param_info *) | |
627 | ((uint8_t *)iface_param + | |
628 | sizeof(struct iscsi_iface_param_info) + length); | |
629 | } | |
630 | ||
631 | init_fw_cb->cookie = cpu_to_le32(0x11BEAD5A); | |
632 | ||
633 | rval = qla4xxx_set_flash(ha, init_fw_cb_dma, FLASH_SEGMENT_IFCB, | |
634 | sizeof(struct addr_ctrl_blk), | |
635 | FLASH_OPT_RMW_COMMIT); | |
636 | if (rval != QLA_SUCCESS) { | |
637 | ql4_printk(KERN_ERR, ha, "%s: set flash mbx failed\n", | |
638 | __func__); | |
639 | rval = -EIO; | |
640 | goto exit_init_fw_cb; | |
641 | } | |
642 | ||
643 | qla4xxx_disable_acb(ha); | |
644 | ||
645 | qla4xxx_initcb_to_acb(init_fw_cb); | |
646 | ||
647 | rval = qla4xxx_set_acb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma); | |
648 | if (rval != QLA_SUCCESS) { | |
649 | ql4_printk(KERN_ERR, ha, "%s: set acb mbx failed\n", | |
650 | __func__); | |
651 | rval = -EIO; | |
652 | goto exit_init_fw_cb; | |
653 | } | |
654 | ||
655 | memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk)); | |
656 | qla4xxx_update_local_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb, | |
657 | init_fw_cb_dma); | |
658 | ||
659 | exit_init_fw_cb: | |
660 | dma_free_coherent(&ha->pdev->dev, sizeof(struct addr_ctrl_blk), | |
661 | init_fw_cb, init_fw_cb_dma); | |
662 | ||
663 | return rval; | |
664 | } | |
665 | ||
afaf5a2d DS |
666 | static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess, |
667 | enum iscsi_param param, char *buf) | |
668 | { | |
669 | struct ddb_entry *ddb_entry = sess->dd_data; | |
670 | int len; | |
671 | ||
672 | switch (param) { | |
673 | case ISCSI_PARAM_TARGET_NAME: | |
674 | len = snprintf(buf, PAGE_SIZE - 1, "%s\n", | |
675 | ddb_entry->iscsi_name); | |
676 | break; | |
677 | case ISCSI_PARAM_TPGT: | |
678 | len = sprintf(buf, "%u\n", ddb_entry->tpgt); | |
679 | break; | |
3b2bef1f VC |
680 | case ISCSI_PARAM_TARGET_ALIAS: |
681 | len = snprintf(buf, PAGE_SIZE - 1, "%s\n", | |
682 | ddb_entry->iscsi_alias); | |
683 | break; | |
afaf5a2d DS |
684 | default: |
685 | return -ENOSYS; | |
686 | } | |
687 | ||
688 | return len; | |
689 | } | |
690 | ||
691 | static int qla4xxx_conn_get_param(struct iscsi_cls_conn *conn, | |
692 | enum iscsi_param param, char *buf) | |
693 | { | |
694 | struct iscsi_cls_session *session; | |
695 | struct ddb_entry *ddb_entry; | |
696 | int len; | |
697 | ||
698 | session = iscsi_dev_to_session(conn->dev.parent); | |
699 | ddb_entry = session->dd_data; | |
700 | ||
701 | switch (param) { | |
702 | case ISCSI_PARAM_CONN_PORT: | |
703 | len = sprintf(buf, "%hu\n", ddb_entry->port); | |
704 | break; | |
705 | case ISCSI_PARAM_CONN_ADDRESS: | |
706 | /* TODO: what are the ipv6 bits */ | |
63779436 | 707 | len = sprintf(buf, "%pI4\n", &ddb_entry->ip_addr); |
afaf5a2d DS |
708 | break; |
709 | default: | |
710 | return -ENOSYS; | |
711 | } | |
712 | ||
713 | return len; | |
714 | } | |
715 | ||
2174a04e MC |
716 | static int qla4xxx_tgt_dscvr(struct Scsi_Host *shost, |
717 | enum iscsi_tgt_dscvr type, uint32_t enable, | |
718 | struct sockaddr *dst_addr) | |
afaf5a2d DS |
719 | { |
720 | struct scsi_qla_host *ha; | |
afaf5a2d DS |
721 | struct sockaddr_in *addr; |
722 | struct sockaddr_in6 *addr6; | |
723 | int ret = 0; | |
724 | ||
afaf5a2d DS |
725 | ha = (struct scsi_qla_host *) shost->hostdata; |
726 | ||
727 | switch (type) { | |
728 | case ISCSI_TGT_DSCVR_SEND_TARGETS: | |
729 | if (dst_addr->sa_family == AF_INET) { | |
730 | addr = (struct sockaddr_in *)dst_addr; | |
731 | if (qla4xxx_send_tgts(ha, (char *)&addr->sin_addr, | |
732 | addr->sin_port) != QLA_SUCCESS) | |
733 | ret = -EIO; | |
734 | } else if (dst_addr->sa_family == AF_INET6) { | |
735 | /* | |
736 | * TODO: fix qla4xxx_send_tgts | |
737 | */ | |
738 | addr6 = (struct sockaddr_in6 *)dst_addr; | |
739 | if (qla4xxx_send_tgts(ha, (char *)&addr6->sin6_addr, | |
740 | addr6->sin6_port) != QLA_SUCCESS) | |
741 | ret = -EIO; | |
742 | } else | |
743 | ret = -ENOSYS; | |
744 | break; | |
745 | default: | |
746 | ret = -ENOSYS; | |
747 | } | |
afaf5a2d DS |
748 | return ret; |
749 | } | |
750 | ||
751 | void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry) | |
752 | { | |
753 | if (!ddb_entry->sess) | |
754 | return; | |
755 | ||
756 | if (ddb_entry->conn) { | |
26974789 | 757 | atomic_set(&ddb_entry->state, DDB_STATE_DEAD); |
afaf5a2d DS |
758 | iscsi_remove_session(ddb_entry->sess); |
759 | } | |
760 | iscsi_free_session(ddb_entry->sess); | |
761 | } | |
762 | ||
763 | int qla4xxx_add_sess(struct ddb_entry *ddb_entry) | |
764 | { | |
765 | int err; | |
766 | ||
3038727c | 767 | ddb_entry->sess->recovery_tmo = ql4xsess_recovery_tmo; |
3013cea8 | 768 | |
afaf5a2d DS |
769 | err = iscsi_add_session(ddb_entry->sess, ddb_entry->fw_ddb_index); |
770 | if (err) { | |
771 | DEBUG2(printk(KERN_ERR "Could not add session.\n")); | |
772 | return err; | |
773 | } | |
774 | ||
5d91e209 | 775 | ddb_entry->conn = iscsi_create_conn(ddb_entry->sess, 0, 0); |
afaf5a2d DS |
776 | if (!ddb_entry->conn) { |
777 | iscsi_remove_session(ddb_entry->sess); | |
778 | DEBUG2(printk(KERN_ERR "Could not add connection.\n")); | |
779 | return -ENOMEM; | |
780 | } | |
b635930d MC |
781 | |
782 | /* finally ready to go */ | |
783 | iscsi_unblock_session(ddb_entry->sess); | |
afaf5a2d DS |
784 | return 0; |
785 | } | |
786 | ||
787 | struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha) | |
788 | { | |
789 | struct ddb_entry *ddb_entry; | |
790 | struct iscsi_cls_session *sess; | |
791 | ||
5d91e209 MC |
792 | sess = iscsi_alloc_session(ha->host, &qla4xxx_iscsi_transport, |
793 | sizeof(struct ddb_entry)); | |
afaf5a2d DS |
794 | if (!sess) |
795 | return NULL; | |
796 | ||
797 | ddb_entry = sess->dd_data; | |
798 | memset(ddb_entry, 0, sizeof(*ddb_entry)); | |
799 | ddb_entry->ha = ha; | |
800 | ddb_entry->sess = sess; | |
801 | return ddb_entry; | |
802 | } | |
803 | ||
024f801f MC |
804 | static void qla4xxx_scan_start(struct Scsi_Host *shost) |
805 | { | |
806 | struct scsi_qla_host *ha = shost_priv(shost); | |
807 | struct ddb_entry *ddb_entry, *ddbtemp; | |
808 | ||
809 | /* finish setup of sessions that were already setup in firmware */ | |
810 | list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) { | |
811 | if (ddb_entry->fw_ddb_device_state == DDB_DS_SESSION_ACTIVE) | |
812 | qla4xxx_add_sess(ddb_entry); | |
813 | } | |
814 | } | |
815 | ||
afaf5a2d DS |
816 | /* |
817 | * Timer routines | |
818 | */ | |
819 | ||
820 | static void qla4xxx_start_timer(struct scsi_qla_host *ha, void *func, | |
821 | unsigned long interval) | |
822 | { | |
823 | DEBUG(printk("scsi: %s: Starting timer thread for adapter %d\n", | |
824 | __func__, ha->host->host_no)); | |
825 | init_timer(&ha->timer); | |
826 | ha->timer.expires = jiffies + interval * HZ; | |
827 | ha->timer.data = (unsigned long)ha; | |
828 | ha->timer.function = (void (*)(unsigned long))func; | |
829 | add_timer(&ha->timer); | |
830 | ha->timer_active = 1; | |
831 | } | |
832 | ||
833 | static void qla4xxx_stop_timer(struct scsi_qla_host *ha) | |
834 | { | |
835 | del_timer_sync(&ha->timer); | |
836 | ha->timer_active = 0; | |
837 | } | |
838 | ||
839 | /*** | |
840 | * qla4xxx_mark_device_missing - mark a device as missing. | |
841 | * @ha: Pointer to host adapter structure. | |
842 | * @ddb_entry: Pointer to device database entry | |
843 | * | |
f4f5df23 | 844 | * This routine marks a device missing and close connection. |
afaf5a2d DS |
845 | **/ |
846 | void qla4xxx_mark_device_missing(struct scsi_qla_host *ha, | |
847 | struct ddb_entry *ddb_entry) | |
848 | { | |
f4f5df23 VC |
849 | if ((atomic_read(&ddb_entry->state) != DDB_STATE_DEAD)) { |
850 | atomic_set(&ddb_entry->state, DDB_STATE_MISSING); | |
851 | DEBUG2(printk("scsi%ld: ddb [%d] marked MISSING\n", | |
852 | ha->host_no, ddb_entry->fw_ddb_index)); | |
853 | } else | |
854 | DEBUG2(printk("scsi%ld: ddb [%d] DEAD\n", ha->host_no, | |
855 | ddb_entry->fw_ddb_index)) | |
856 | ||
b635930d | 857 | iscsi_block_session(ddb_entry->sess); |
e5bd7b54 | 858 | iscsi_conn_error_event(ddb_entry->conn, ISCSI_ERR_CONN_FAILED); |
afaf5a2d DS |
859 | } |
860 | ||
f4f5df23 VC |
861 | /** |
862 | * qla4xxx_mark_all_devices_missing - mark all devices as missing. | |
863 | * @ha: Pointer to host adapter structure. | |
864 | * | |
865 | * This routine marks a device missing and resets the relogin retry count. | |
866 | **/ | |
867 | void qla4xxx_mark_all_devices_missing(struct scsi_qla_host *ha) | |
868 | { | |
869 | struct ddb_entry *ddb_entry, *ddbtemp; | |
870 | list_for_each_entry_safe(ddb_entry, ddbtemp, &ha->ddb_list, list) { | |
871 | qla4xxx_mark_device_missing(ha, ddb_entry); | |
872 | } | |
873 | } | |
874 | ||
afaf5a2d DS |
875 | static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, |
876 | struct ddb_entry *ddb_entry, | |
8f0722ca | 877 | struct scsi_cmnd *cmd) |
afaf5a2d DS |
878 | { |
879 | struct srb *srb; | |
880 | ||
881 | srb = mempool_alloc(ha->srb_mempool, GFP_ATOMIC); | |
882 | if (!srb) | |
883 | return srb; | |
884 | ||
09a0f719 | 885 | kref_init(&srb->srb_ref); |
afaf5a2d DS |
886 | srb->ha = ha; |
887 | srb->ddb = ddb_entry; | |
888 | srb->cmd = cmd; | |
889 | srb->flags = 0; | |
5369887a | 890 | CMD_SP(cmd) = (void *)srb; |
afaf5a2d DS |
891 | |
892 | return srb; | |
893 | } | |
894 | ||
895 | static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) | |
896 | { | |
897 | struct scsi_cmnd *cmd = srb->cmd; | |
898 | ||
899 | if (srb->flags & SRB_DMA_VALID) { | |
5f7186c8 | 900 | scsi_dma_unmap(cmd); |
afaf5a2d DS |
901 | srb->flags &= ~SRB_DMA_VALID; |
902 | } | |
5369887a | 903 | CMD_SP(cmd) = NULL; |
afaf5a2d DS |
904 | } |
905 | ||
09a0f719 | 906 | void qla4xxx_srb_compl(struct kref *ref) |
afaf5a2d | 907 | { |
09a0f719 | 908 | struct srb *srb = container_of(ref, struct srb, srb_ref); |
afaf5a2d | 909 | struct scsi_cmnd *cmd = srb->cmd; |
09a0f719 | 910 | struct scsi_qla_host *ha = srb->ha; |
afaf5a2d DS |
911 | |
912 | qla4xxx_srb_free_dma(ha, srb); | |
913 | ||
914 | mempool_free(srb, ha->srb_mempool); | |
915 | ||
916 | cmd->scsi_done(cmd); | |
917 | } | |
918 | ||
919 | /** | |
920 | * qla4xxx_queuecommand - scsi layer issues scsi command to driver. | |
8f0722ca | 921 | * @host: scsi host |
afaf5a2d | 922 | * @cmd: Pointer to Linux's SCSI command structure |
afaf5a2d DS |
923 | * |
924 | * Remarks: | |
925 | * This routine is invoked by Linux to send a SCSI command to the driver. | |
926 | * The mid-level driver tries to ensure that queuecommand never gets | |
927 | * invoked concurrently with itself or the interrupt handler (although | |
928 | * the interrupt handler may call this routine as part of request- | |
929 | * completion handling). Unfortunely, it sometimes calls the scheduler | |
930 | * in interrupt context which is a big NO! NO!. | |
931 | **/ | |
8f0722ca | 932 | static int qla4xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) |
afaf5a2d | 933 | { |
8f0722ca | 934 | struct scsi_qla_host *ha = to_qla_host(host); |
afaf5a2d | 935 | struct ddb_entry *ddb_entry = cmd->device->hostdata; |
7fb1921b | 936 | struct iscsi_cls_session *sess = ddb_entry->sess; |
afaf5a2d DS |
937 | struct srb *srb; |
938 | int rval; | |
939 | ||
2232be0d LC |
940 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
941 | if (test_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags)) | |
942 | cmd->result = DID_NO_CONNECT << 16; | |
943 | else | |
944 | cmd->result = DID_REQUEUE << 16; | |
945 | goto qc_fail_command; | |
946 | } | |
947 | ||
7fb1921b MC |
948 | if (!sess) { |
949 | cmd->result = DID_IMM_RETRY << 16; | |
950 | goto qc_fail_command; | |
951 | } | |
952 | ||
953 | rval = iscsi_session_chkready(sess); | |
954 | if (rval) { | |
955 | cmd->result = rval; | |
956 | goto qc_fail_command; | |
957 | } | |
958 | ||
afaf5a2d DS |
959 | if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { |
960 | if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) { | |
961 | cmd->result = DID_NO_CONNECT << 16; | |
962 | goto qc_fail_command; | |
963 | } | |
c5e98e91 | 964 | return SCSI_MLQUEUE_TARGET_BUSY; |
afaf5a2d DS |
965 | } |
966 | ||
f4f5df23 VC |
967 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
968 | test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || | |
969 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || | |
970 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || | |
971 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || | |
972 | !test_bit(AF_ONLINE, &ha->flags) || | |
973 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) | |
477ffb9d DS |
974 | goto qc_host_busy; |
975 | ||
8f0722ca | 976 | srb = qla4xxx_get_new_srb(ha, ddb_entry, cmd); |
afaf5a2d | 977 | if (!srb) |
8f0722ca | 978 | goto qc_host_busy; |
afaf5a2d DS |
979 | |
980 | rval = qla4xxx_send_command_to_isp(ha, srb); | |
981 | if (rval != QLA_SUCCESS) | |
982 | goto qc_host_busy_free_sp; | |
983 | ||
afaf5a2d DS |
984 | return 0; |
985 | ||
986 | qc_host_busy_free_sp: | |
987 | qla4xxx_srb_free_dma(ha, srb); | |
988 | mempool_free(srb, ha->srb_mempool); | |
989 | ||
afaf5a2d DS |
990 | qc_host_busy: |
991 | return SCSI_MLQUEUE_HOST_BUSY; | |
992 | ||
993 | qc_fail_command: | |
8f0722ca | 994 | cmd->scsi_done(cmd); |
afaf5a2d DS |
995 | |
996 | return 0; | |
997 | } | |
998 | ||
999 | /** | |
1000 | * qla4xxx_mem_free - frees memory allocated to adapter | |
1001 | * @ha: Pointer to host adapter structure. | |
1002 | * | |
1003 | * Frees memory previously allocated by qla4xxx_mem_alloc | |
1004 | **/ | |
1005 | static void qla4xxx_mem_free(struct scsi_qla_host *ha) | |
1006 | { | |
1007 | if (ha->queues) | |
1008 | dma_free_coherent(&ha->pdev->dev, ha->queues_len, ha->queues, | |
1009 | ha->queues_dma); | |
1010 | ||
1011 | ha->queues_len = 0; | |
1012 | ha->queues = NULL; | |
1013 | ha->queues_dma = 0; | |
1014 | ha->request_ring = NULL; | |
1015 | ha->request_dma = 0; | |
1016 | ha->response_ring = NULL; | |
1017 | ha->response_dma = 0; | |
1018 | ha->shadow_regs = NULL; | |
1019 | ha->shadow_regs_dma = 0; | |
1020 | ||
1021 | /* Free srb pool. */ | |
1022 | if (ha->srb_mempool) | |
1023 | mempool_destroy(ha->srb_mempool); | |
1024 | ||
1025 | ha->srb_mempool = NULL; | |
1026 | ||
1027 | /* release io space registers */ | |
f4f5df23 VC |
1028 | if (is_qla8022(ha)) { |
1029 | if (ha->nx_pcibase) | |
1030 | iounmap( | |
1031 | (struct device_reg_82xx __iomem *)ha->nx_pcibase); | |
f4f5df23 | 1032 | } else if (ha->reg) |
afaf5a2d DS |
1033 | iounmap(ha->reg); |
1034 | pci_release_regions(ha->pdev); | |
1035 | } | |
1036 | ||
1037 | /** | |
1038 | * qla4xxx_mem_alloc - allocates memory for use by adapter. | |
1039 | * @ha: Pointer to host adapter structure | |
1040 | * | |
1041 | * Allocates DMA memory for request and response queues. Also allocates memory | |
1042 | * for srbs. | |
1043 | **/ | |
1044 | static int qla4xxx_mem_alloc(struct scsi_qla_host *ha) | |
1045 | { | |
1046 | unsigned long align; | |
1047 | ||
1048 | /* Allocate contiguous block of DMA memory for queues. */ | |
1049 | ha->queues_len = ((REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + | |
1050 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE) + | |
1051 | sizeof(struct shadow_regs) + | |
1052 | MEM_ALIGN_VALUE + | |
1053 | (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1); | |
1054 | ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len, | |
1055 | &ha->queues_dma, GFP_KERNEL); | |
1056 | if (ha->queues == NULL) { | |
c2660df3 VC |
1057 | ql4_printk(KERN_WARNING, ha, |
1058 | "Memory Allocation failed - queues.\n"); | |
afaf5a2d DS |
1059 | |
1060 | goto mem_alloc_error_exit; | |
1061 | } | |
1062 | memset(ha->queues, 0, ha->queues_len); | |
1063 | ||
1064 | /* | |
1065 | * As per RISC alignment requirements -- the bus-address must be a | |
1066 | * multiple of the request-ring size (in bytes). | |
1067 | */ | |
1068 | align = 0; | |
1069 | if ((unsigned long)ha->queues_dma & (MEM_ALIGN_VALUE - 1)) | |
1070 | align = MEM_ALIGN_VALUE - ((unsigned long)ha->queues_dma & | |
1071 | (MEM_ALIGN_VALUE - 1)); | |
1072 | ||
1073 | /* Update request and response queue pointers. */ | |
1074 | ha->request_dma = ha->queues_dma + align; | |
1075 | ha->request_ring = (struct queue_entry *) (ha->queues + align); | |
1076 | ha->response_dma = ha->queues_dma + align + | |
1077 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE); | |
1078 | ha->response_ring = (struct queue_entry *) (ha->queues + align + | |
1079 | (REQUEST_QUEUE_DEPTH * | |
1080 | QUEUE_SIZE)); | |
1081 | ha->shadow_regs_dma = ha->queues_dma + align + | |
1082 | (REQUEST_QUEUE_DEPTH * QUEUE_SIZE) + | |
1083 | (RESPONSE_QUEUE_DEPTH * QUEUE_SIZE); | |
1084 | ha->shadow_regs = (struct shadow_regs *) (ha->queues + align + | |
1085 | (REQUEST_QUEUE_DEPTH * | |
1086 | QUEUE_SIZE) + | |
1087 | (RESPONSE_QUEUE_DEPTH * | |
1088 | QUEUE_SIZE)); | |
1089 | ||
1090 | /* Allocate memory for srb pool. */ | |
1091 | ha->srb_mempool = mempool_create(SRB_MIN_REQ, mempool_alloc_slab, | |
1092 | mempool_free_slab, srb_cachep); | |
1093 | if (ha->srb_mempool == NULL) { | |
c2660df3 VC |
1094 | ql4_printk(KERN_WARNING, ha, |
1095 | "Memory Allocation failed - SRB Pool.\n"); | |
afaf5a2d DS |
1096 | |
1097 | goto mem_alloc_error_exit; | |
1098 | } | |
1099 | ||
1100 | return QLA_SUCCESS; | |
1101 | ||
1102 | mem_alloc_error_exit: | |
1103 | qla4xxx_mem_free(ha); | |
1104 | return QLA_ERROR; | |
1105 | } | |
1106 | ||
f4f5df23 VC |
1107 | /** |
1108 | * qla4_8xxx_check_fw_alive - Check firmware health | |
1109 | * @ha: Pointer to host adapter structure. | |
1110 | * | |
1111 | * Context: Interrupt | |
1112 | **/ | |
1113 | static void qla4_8xxx_check_fw_alive(struct scsi_qla_host *ha) | |
1114 | { | |
1115 | uint32_t fw_heartbeat_counter, halt_status; | |
1116 | ||
1117 | fw_heartbeat_counter = qla4_8xxx_rd_32(ha, QLA82XX_PEG_ALIVE_COUNTER); | |
2232be0d LC |
1118 | /* If PEG_ALIVE_COUNTER is 0xffffffff, AER/EEH is in progress, ignore */ |
1119 | if (fw_heartbeat_counter == 0xffffffff) { | |
1120 | DEBUG2(printk(KERN_WARNING "scsi%ld: %s: Device in frozen " | |
1121 | "state, QLA82XX_PEG_ALIVE_COUNTER is 0xffffffff\n", | |
1122 | ha->host_no, __func__)); | |
1123 | return; | |
1124 | } | |
f4f5df23 VC |
1125 | |
1126 | if (ha->fw_heartbeat_counter == fw_heartbeat_counter) { | |
1127 | ha->seconds_since_last_heartbeat++; | |
1128 | /* FW not alive after 2 seconds */ | |
1129 | if (ha->seconds_since_last_heartbeat == 2) { | |
1130 | ha->seconds_since_last_heartbeat = 0; | |
1131 | halt_status = qla4_8xxx_rd_32(ha, | |
68d92ebf VC |
1132 | QLA82XX_PEG_HALT_STATUS1); |
1133 | ||
1134 | ql4_printk(KERN_INFO, ha, | |
1135 | "scsi(%ld): %s, Dumping hw/fw registers:\n " | |
1136 | " PEG_HALT_STATUS1: 0x%x, PEG_HALT_STATUS2:" | |
1137 | " 0x%x,\n PEG_NET_0_PC: 0x%x, PEG_NET_1_PC:" | |
1138 | " 0x%x,\n PEG_NET_2_PC: 0x%x, PEG_NET_3_PC:" | |
1139 | " 0x%x,\n PEG_NET_4_PC: 0x%x\n", | |
1140 | ha->host_no, __func__, halt_status, | |
1141 | qla4_8xxx_rd_32(ha, | |
1142 | QLA82XX_PEG_HALT_STATUS2), | |
1143 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_0 + | |
1144 | 0x3c), | |
1145 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_1 + | |
1146 | 0x3c), | |
1147 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_2 + | |
1148 | 0x3c), | |
1149 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_3 + | |
1150 | 0x3c), | |
1151 | qla4_8xxx_rd_32(ha, QLA82XX_CRB_PEG_NET_4 + | |
1152 | 0x3c)); | |
21033639 | 1153 | |
f4f5df23 VC |
1154 | /* Since we cannot change dev_state in interrupt |
1155 | * context, set appropriate DPC flag then wakeup | |
1156 | * DPC */ | |
1157 | if (halt_status & HALT_STATUS_UNRECOVERABLE) | |
1158 | set_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags); | |
1159 | else { | |
1160 | printk("scsi%ld: %s: detect abort needed!\n", | |
1161 | ha->host_no, __func__); | |
1162 | set_bit(DPC_RESET_HA, &ha->dpc_flags); | |
1163 | } | |
1164 | qla4xxx_wake_dpc(ha); | |
21033639 | 1165 | qla4xxx_mailbox_premature_completion(ha); |
f4f5df23 | 1166 | } |
99457d75 LC |
1167 | } else |
1168 | ha->seconds_since_last_heartbeat = 0; | |
1169 | ||
f4f5df23 VC |
1170 | ha->fw_heartbeat_counter = fw_heartbeat_counter; |
1171 | } | |
1172 | ||
1173 | /** | |
1174 | * qla4_8xxx_watchdog - Poll dev state | |
1175 | * @ha: Pointer to host adapter structure. | |
1176 | * | |
1177 | * Context: Interrupt | |
1178 | **/ | |
1179 | void qla4_8xxx_watchdog(struct scsi_qla_host *ha) | |
1180 | { | |
1181 | uint32_t dev_state; | |
1182 | ||
1183 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); | |
1184 | ||
1185 | /* don't poll if reset is going on */ | |
d56a1f7b LC |
1186 | if (!(test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) || |
1187 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || | |
977f46a4 | 1188 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags))) { |
f4f5df23 VC |
1189 | if (dev_state == QLA82XX_DEV_NEED_RESET && |
1190 | !test_bit(DPC_RESET_HA, &ha->dpc_flags)) { | |
3930b8c1 VC |
1191 | if (!ql4xdontresethba) { |
1192 | ql4_printk(KERN_INFO, ha, "%s: HW State: " | |
1193 | "NEED RESET!\n", __func__); | |
1194 | set_bit(DPC_RESET_HA, &ha->dpc_flags); | |
1195 | qla4xxx_wake_dpc(ha); | |
1196 | qla4xxx_mailbox_premature_completion(ha); | |
1197 | } | |
f4f5df23 VC |
1198 | } else if (dev_state == QLA82XX_DEV_NEED_QUIESCENT && |
1199 | !test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { | |
3930b8c1 VC |
1200 | ql4_printk(KERN_INFO, ha, "%s: HW State: NEED QUIES!\n", |
1201 | __func__); | |
f4f5df23 VC |
1202 | set_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags); |
1203 | qla4xxx_wake_dpc(ha); | |
1204 | } else { | |
1205 | /* Check firmware health */ | |
1206 | qla4_8xxx_check_fw_alive(ha); | |
1207 | } | |
1208 | } | |
1209 | } | |
1210 | ||
afaf5a2d DS |
1211 | /** |
1212 | * qla4xxx_timer - checks every second for work to do. | |
1213 | * @ha: Pointer to host adapter structure. | |
1214 | **/ | |
1215 | static void qla4xxx_timer(struct scsi_qla_host *ha) | |
1216 | { | |
1217 | struct ddb_entry *ddb_entry, *dtemp; | |
1218 | int start_dpc = 0; | |
2232be0d LC |
1219 | uint16_t w; |
1220 | ||
1221 | /* If we are in the middle of AER/EEH processing | |
1222 | * skip any processing and reschedule the timer | |
1223 | */ | |
1224 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { | |
1225 | mod_timer(&ha->timer, jiffies + HZ); | |
1226 | return; | |
1227 | } | |
1228 | ||
1229 | /* Hardware read to trigger an EEH error during mailbox waits. */ | |
1230 | if (!pci_channel_offline(ha->pdev)) | |
1231 | pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w); | |
afaf5a2d | 1232 | |
f4f5df23 VC |
1233 | if (is_qla8022(ha)) { |
1234 | qla4_8xxx_watchdog(ha); | |
1235 | } | |
1236 | ||
afaf5a2d DS |
1237 | /* Search for relogin's to time-out and port down retry. */ |
1238 | list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) { | |
1239 | /* Count down time between sending relogins */ | |
1240 | if (adapter_up(ha) && | |
1241 | !test_bit(DF_RELOGIN, &ddb_entry->flags) && | |
1242 | atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) { | |
1243 | if (atomic_read(&ddb_entry->retry_relogin_timer) != | |
1244 | INVALID_ENTRY) { | |
1245 | if (atomic_read(&ddb_entry->retry_relogin_timer) | |
1246 | == 0) { | |
1247 | atomic_set(&ddb_entry-> | |
1248 | retry_relogin_timer, | |
1249 | INVALID_ENTRY); | |
1250 | set_bit(DPC_RELOGIN_DEVICE, | |
1251 | &ha->dpc_flags); | |
1252 | set_bit(DF_RELOGIN, &ddb_entry->flags); | |
f4f5df23 | 1253 | DEBUG2(printk("scsi%ld: %s: ddb [%d]" |
afaf5a2d DS |
1254 | " login device\n", |
1255 | ha->host_no, __func__, | |
1256 | ddb_entry->fw_ddb_index)); | |
1257 | } else | |
1258 | atomic_dec(&ddb_entry-> | |
1259 | retry_relogin_timer); | |
1260 | } | |
1261 | } | |
1262 | ||
1263 | /* Wait for relogin to timeout */ | |
1264 | if (atomic_read(&ddb_entry->relogin_timer) && | |
1265 | (atomic_dec_and_test(&ddb_entry->relogin_timer) != 0)) { | |
1266 | /* | |
1267 | * If the relogin times out and the device is | |
1268 | * still NOT ONLINE then try and relogin again. | |
1269 | */ | |
1270 | if (atomic_read(&ddb_entry->state) != | |
1271 | DDB_STATE_ONLINE && | |
1272 | ddb_entry->fw_ddb_device_state == | |
1273 | DDB_DS_SESSION_FAILED) { | |
1274 | /* Reset retry relogin timer */ | |
1275 | atomic_inc(&ddb_entry->relogin_retry_count); | |
f4f5df23 | 1276 | DEBUG2(printk("scsi%ld: ddb [%d] relogin" |
afaf5a2d DS |
1277 | " timed out-retrying" |
1278 | " relogin (%d)\n", | |
1279 | ha->host_no, | |
1280 | ddb_entry->fw_ddb_index, | |
1281 | atomic_read(&ddb_entry-> | |
1282 | relogin_retry_count)) | |
1283 | ); | |
1284 | start_dpc++; | |
f4f5df23 | 1285 | DEBUG(printk("scsi%ld:%d:%d: ddb [%d] " |
cd09b2c3 | 1286 | "initiate relogin after" |
afaf5a2d DS |
1287 | " %d seconds\n", |
1288 | ha->host_no, ddb_entry->bus, | |
1289 | ddb_entry->target, | |
1290 | ddb_entry->fw_ddb_index, | |
1291 | ddb_entry->default_time2wait + 4) | |
1292 | ); | |
1293 | ||
1294 | atomic_set(&ddb_entry->retry_relogin_timer, | |
1295 | ddb_entry->default_time2wait + 4); | |
1296 | } | |
1297 | } | |
1298 | } | |
1299 | ||
f4f5df23 VC |
1300 | if (!is_qla8022(ha)) { |
1301 | /* Check for heartbeat interval. */ | |
1302 | if (ha->firmware_options & FWOPT_HEARTBEAT_ENABLE && | |
1303 | ha->heartbeat_interval != 0) { | |
1304 | ha->seconds_since_last_heartbeat++; | |
1305 | if (ha->seconds_since_last_heartbeat > | |
1306 | ha->heartbeat_interval + 2) | |
1307 | set_bit(DPC_RESET_HA, &ha->dpc_flags); | |
1308 | } | |
afaf5a2d DS |
1309 | } |
1310 | ||
afaf5a2d | 1311 | /* Wakeup the dpc routine for this adapter, if needed. */ |
1b46807e | 1312 | if (start_dpc || |
afaf5a2d DS |
1313 | test_bit(DPC_RESET_HA, &ha->dpc_flags) || |
1314 | test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags) || | |
1315 | test_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags) || | |
f4f5df23 | 1316 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || |
afaf5a2d DS |
1317 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
1318 | test_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags) || | |
065aa1b4 | 1319 | test_bit(DPC_LINK_CHANGED, &ha->dpc_flags) || |
f4f5df23 VC |
1320 | test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags) || |
1321 | test_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags) || | |
1b46807e | 1322 | test_bit(DPC_AEN, &ha->dpc_flags)) { |
afaf5a2d DS |
1323 | DEBUG2(printk("scsi%ld: %s: scheduling dpc routine" |
1324 | " - dpc flags = 0x%lx\n", | |
1325 | ha->host_no, __func__, ha->dpc_flags)); | |
f4f5df23 | 1326 | qla4xxx_wake_dpc(ha); |
afaf5a2d DS |
1327 | } |
1328 | ||
1329 | /* Reschedule timer thread to call us back in one second */ | |
1330 | mod_timer(&ha->timer, jiffies + HZ); | |
1331 | ||
1332 | DEBUG2(ha->seconds_since_last_intr++); | |
1333 | } | |
1334 | ||
1335 | /** | |
1336 | * qla4xxx_cmd_wait - waits for all outstanding commands to complete | |
1337 | * @ha: Pointer to host adapter structure. | |
1338 | * | |
1339 | * This routine stalls the driver until all outstanding commands are returned. | |
1340 | * Caller must release the Hardware Lock prior to calling this routine. | |
1341 | **/ | |
1342 | static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) | |
1343 | { | |
1344 | uint32_t index = 0; | |
afaf5a2d DS |
1345 | unsigned long flags; |
1346 | struct scsi_cmnd *cmd; | |
afaf5a2d | 1347 | |
f4f5df23 VC |
1348 | unsigned long wtime = jiffies + (WAIT_CMD_TOV * HZ); |
1349 | ||
1350 | DEBUG2(ql4_printk(KERN_INFO, ha, "Wait up to %d seconds for cmds to " | |
1351 | "complete\n", WAIT_CMD_TOV)); | |
1352 | ||
1353 | while (!time_after_eq(jiffies, wtime)) { | |
afaf5a2d DS |
1354 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1355 | /* Find a command that hasn't completed. */ | |
1356 | for (index = 0; index < ha->host->can_queue; index++) { | |
1357 | cmd = scsi_host_find_tag(ha->host, index); | |
a1e0063d MC |
1358 | /* |
1359 | * We cannot just check if the index is valid, | |
1360 | * becase if we are run from the scsi eh, then | |
1361 | * the scsi/block layer is going to prevent | |
1362 | * the tag from being released. | |
1363 | */ | |
1364 | if (cmd != NULL && CMD_SP(cmd)) | |
afaf5a2d DS |
1365 | break; |
1366 | } | |
1367 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1368 | ||
1369 | /* If No Commands are pending, wait is complete */ | |
f4f5df23 VC |
1370 | if (index == ha->host->can_queue) |
1371 | return QLA_SUCCESS; | |
afaf5a2d | 1372 | |
f4f5df23 VC |
1373 | msleep(1000); |
1374 | } | |
1375 | /* If we timed out on waiting for commands to come back | |
1376 | * return ERROR. */ | |
1377 | return QLA_ERROR; | |
afaf5a2d DS |
1378 | } |
1379 | ||
f4f5df23 | 1380 | int qla4xxx_hw_reset(struct scsi_qla_host *ha) |
afaf5a2d | 1381 | { |
afaf5a2d | 1382 | uint32_t ctrl_status; |
477ffb9d DS |
1383 | unsigned long flags = 0; |
1384 | ||
1385 | DEBUG2(printk(KERN_ERR "scsi%ld: %s\n", ha->host_no, __func__)); | |
afaf5a2d | 1386 | |
f4f5df23 VC |
1387 | if (ql4xxx_lock_drvr_wait(ha) != QLA_SUCCESS) |
1388 | return QLA_ERROR; | |
1389 | ||
afaf5a2d DS |
1390 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1391 | ||
1392 | /* | |
1393 | * If the SCSI Reset Interrupt bit is set, clear it. | |
1394 | * Otherwise, the Soft Reset won't work. | |
1395 | */ | |
1396 | ctrl_status = readw(&ha->reg->ctrl_status); | |
1397 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) | |
1398 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); | |
1399 | ||
1400 | /* Issue Soft Reset */ | |
1401 | writel(set_rmask(CSR_SOFT_RESET), &ha->reg->ctrl_status); | |
1402 | readl(&ha->reg->ctrl_status); | |
1403 | ||
1404 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
f4f5df23 | 1405 | return QLA_SUCCESS; |
477ffb9d DS |
1406 | } |
1407 | ||
1408 | /** | |
1409 | * qla4xxx_soft_reset - performs soft reset. | |
1410 | * @ha: Pointer to host adapter structure. | |
1411 | **/ | |
1412 | int qla4xxx_soft_reset(struct scsi_qla_host *ha) | |
1413 | { | |
1414 | uint32_t max_wait_time; | |
1415 | unsigned long flags = 0; | |
f931c534 | 1416 | int status; |
477ffb9d DS |
1417 | uint32_t ctrl_status; |
1418 | ||
f931c534 VC |
1419 | status = qla4xxx_hw_reset(ha); |
1420 | if (status != QLA_SUCCESS) | |
1421 | return status; | |
afaf5a2d | 1422 | |
f931c534 | 1423 | status = QLA_ERROR; |
afaf5a2d DS |
1424 | /* Wait until the Network Reset Intr bit is cleared */ |
1425 | max_wait_time = RESET_INTR_TOV; | |
1426 | do { | |
1427 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1428 | ctrl_status = readw(&ha->reg->ctrl_status); | |
1429 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1430 | ||
1431 | if ((ctrl_status & CSR_NET_RESET_INTR) == 0) | |
1432 | break; | |
1433 | ||
1434 | msleep(1000); | |
1435 | } while ((--max_wait_time)); | |
1436 | ||
1437 | if ((ctrl_status & CSR_NET_RESET_INTR) != 0) { | |
1438 | DEBUG2(printk(KERN_WARNING | |
1439 | "scsi%ld: Network Reset Intr not cleared by " | |
1440 | "Network function, clearing it now!\n", | |
1441 | ha->host_no)); | |
1442 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1443 | writel(set_rmask(CSR_NET_RESET_INTR), &ha->reg->ctrl_status); | |
1444 | readl(&ha->reg->ctrl_status); | |
1445 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1446 | } | |
1447 | ||
1448 | /* Wait until the firmware tells us the Soft Reset is done */ | |
1449 | max_wait_time = SOFT_RESET_TOV; | |
1450 | do { | |
1451 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1452 | ctrl_status = readw(&ha->reg->ctrl_status); | |
1453 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1454 | ||
1455 | if ((ctrl_status & CSR_SOFT_RESET) == 0) { | |
1456 | status = QLA_SUCCESS; | |
1457 | break; | |
1458 | } | |
1459 | ||
1460 | msleep(1000); | |
1461 | } while ((--max_wait_time)); | |
1462 | ||
1463 | /* | |
1464 | * Also, make sure that the SCSI Reset Interrupt bit has been cleared | |
1465 | * after the soft reset has taken place. | |
1466 | */ | |
1467 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1468 | ctrl_status = readw(&ha->reg->ctrl_status); | |
1469 | if ((ctrl_status & CSR_SCSI_RESET_INTR) != 0) { | |
1470 | writel(set_rmask(CSR_SCSI_RESET_INTR), &ha->reg->ctrl_status); | |
1471 | readl(&ha->reg->ctrl_status); | |
1472 | } | |
1473 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1474 | ||
1475 | /* If soft reset fails then most probably the bios on other | |
1476 | * function is also enabled. | |
1477 | * Since the initialization is sequential the other fn | |
1478 | * wont be able to acknowledge the soft reset. | |
1479 | * Issue a force soft reset to workaround this scenario. | |
1480 | */ | |
1481 | if (max_wait_time == 0) { | |
1482 | /* Issue Force Soft Reset */ | |
1483 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1484 | writel(set_rmask(CSR_FORCE_SOFT_RESET), &ha->reg->ctrl_status); | |
1485 | readl(&ha->reg->ctrl_status); | |
1486 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1487 | /* Wait until the firmware tells us the Soft Reset is done */ | |
1488 | max_wait_time = SOFT_RESET_TOV; | |
1489 | do { | |
1490 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1491 | ctrl_status = readw(&ha->reg->ctrl_status); | |
1492 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
1493 | ||
1494 | if ((ctrl_status & CSR_FORCE_SOFT_RESET) == 0) { | |
1495 | status = QLA_SUCCESS; | |
1496 | break; | |
1497 | } | |
1498 | ||
1499 | msleep(1000); | |
1500 | } while ((--max_wait_time)); | |
1501 | } | |
1502 | ||
1503 | return status; | |
1504 | } | |
1505 | ||
afaf5a2d | 1506 | /** |
f4f5df23 | 1507 | * qla4xxx_abort_active_cmds - returns all outstanding i/o requests to O.S. |
afaf5a2d | 1508 | * @ha: Pointer to host adapter structure. |
f4f5df23 | 1509 | * @res: returned scsi status |
afaf5a2d DS |
1510 | * |
1511 | * This routine is called just prior to a HARD RESET to return all | |
1512 | * outstanding commands back to the Operating System. | |
1513 | * Caller should make sure that the following locks are released | |
1514 | * before this calling routine: Hardware lock, and io_request_lock. | |
1515 | **/ | |
f4f5df23 | 1516 | static void qla4xxx_abort_active_cmds(struct scsi_qla_host *ha, int res) |
afaf5a2d DS |
1517 | { |
1518 | struct srb *srb; | |
1519 | int i; | |
1520 | unsigned long flags; | |
1521 | ||
1522 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
1523 | for (i = 0; i < ha->host->can_queue; i++) { | |
1524 | srb = qla4xxx_del_from_active_array(ha, i); | |
1525 | if (srb != NULL) { | |
f4f5df23 | 1526 | srb->cmd->result = res; |
09a0f719 | 1527 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); |
afaf5a2d DS |
1528 | } |
1529 | } | |
1530 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
afaf5a2d DS |
1531 | } |
1532 | ||
f4f5df23 VC |
1533 | void qla4xxx_dead_adapter_cleanup(struct scsi_qla_host *ha) |
1534 | { | |
1535 | clear_bit(AF_ONLINE, &ha->flags); | |
1536 | ||
1537 | /* Disable the board */ | |
1538 | ql4_printk(KERN_INFO, ha, "Disabling the board\n"); | |
f4f5df23 VC |
1539 | |
1540 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); | |
1541 | qla4xxx_mark_all_devices_missing(ha); | |
1542 | clear_bit(AF_INIT_DONE, &ha->flags); | |
1543 | } | |
1544 | ||
afaf5a2d DS |
1545 | /** |
1546 | * qla4xxx_recover_adapter - recovers adapter after a fatal error | |
1547 | * @ha: Pointer to host adapter structure. | |
afaf5a2d | 1548 | **/ |
f4f5df23 | 1549 | static int qla4xxx_recover_adapter(struct scsi_qla_host *ha) |
afaf5a2d | 1550 | { |
f4f5df23 VC |
1551 | int status = QLA_ERROR; |
1552 | uint8_t reset_chip = 0; | |
afaf5a2d DS |
1553 | |
1554 | /* Stall incoming I/O until we are done */ | |
f4f5df23 | 1555 | scsi_block_requests(ha->host); |
afaf5a2d | 1556 | clear_bit(AF_ONLINE, &ha->flags); |
50a29aec | 1557 | |
f4f5df23 | 1558 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: adapter OFFLINE\n", __func__)); |
afaf5a2d | 1559 | |
f4f5df23 | 1560 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); |
afaf5a2d | 1561 | |
f4f5df23 VC |
1562 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) |
1563 | reset_chip = 1; | |
afaf5a2d | 1564 | |
f4f5df23 VC |
1565 | /* For the DPC_RESET_HA_INTR case (ISP-4xxx specific) |
1566 | * do not reset adapter, jump to initialize_adapter */ | |
1567 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { | |
1568 | status = QLA_SUCCESS; | |
1569 | goto recover_ha_init_adapter; | |
1570 | } | |
afaf5a2d | 1571 | |
f4f5df23 VC |
1572 | /* For the ISP-82xx adapter, issue a stop_firmware if invoked |
1573 | * from eh_host_reset or ioctl module */ | |
1574 | if (is_qla8022(ha) && !reset_chip && | |
1575 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags)) { | |
1576 | ||
1577 | DEBUG2(ql4_printk(KERN_INFO, ha, | |
1578 | "scsi%ld: %s - Performing stop_firmware...\n", | |
1579 | ha->host_no, __func__)); | |
1580 | status = ha->isp_ops->reset_firmware(ha); | |
1581 | if (status == QLA_SUCCESS) { | |
2bd1e2be NJ |
1582 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
1583 | qla4xxx_cmd_wait(ha); | |
f4f5df23 VC |
1584 | ha->isp_ops->disable_intrs(ha); |
1585 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); | |
1586 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); | |
1587 | } else { | |
1588 | /* If the stop_firmware fails then | |
1589 | * reset the entire chip */ | |
1590 | reset_chip = 1; | |
1591 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); | |
1592 | set_bit(DPC_RESET_HA, &ha->dpc_flags); | |
1593 | } | |
1594 | } | |
dca05c4c | 1595 | |
f4f5df23 VC |
1596 | /* Issue full chip reset if recovering from a catastrophic error, |
1597 | * or if stop_firmware fails for ISP-82xx. | |
1598 | * This is the default case for ISP-4xxx */ | |
1599 | if (!is_qla8022(ha) || reset_chip) { | |
2bd1e2be NJ |
1600 | if (!test_bit(AF_FW_RECOVERY, &ha->flags)) |
1601 | qla4xxx_cmd_wait(ha); | |
f4f5df23 VC |
1602 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); |
1603 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); | |
1604 | DEBUG2(ql4_printk(KERN_INFO, ha, | |
1605 | "scsi%ld: %s - Performing chip reset..\n", | |
1606 | ha->host_no, __func__)); | |
1607 | status = ha->isp_ops->reset_chip(ha); | |
1608 | } | |
afaf5a2d DS |
1609 | |
1610 | /* Flush any pending ddb changed AENs */ | |
1611 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); | |
1612 | ||
f4f5df23 VC |
1613 | recover_ha_init_adapter: |
1614 | /* Upon successful firmware/chip reset, re-initialize the adapter */ | |
afaf5a2d | 1615 | if (status == QLA_SUCCESS) { |
f4f5df23 VC |
1616 | /* For ISP-4xxx, force function 1 to always initialize |
1617 | * before function 3 to prevent both funcions from | |
1618 | * stepping on top of the other */ | |
1619 | if (!is_qla8022(ha) && (ha->mac_index == 3)) | |
1620 | ssleep(6); | |
1621 | ||
1622 | /* NOTE: AF_ONLINE flag set upon successful completion of | |
1623 | * qla4xxx_initialize_adapter */ | |
1624 | status = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST); | |
afaf5a2d DS |
1625 | } |
1626 | ||
f4f5df23 VC |
1627 | /* Retry failed adapter initialization, if necessary |
1628 | * Do not retry initialize_adapter for RESET_HA_INTR (ISP-4xxx specific) | |
1629 | * case to prevent ping-pong resets between functions */ | |
1630 | if (!test_bit(AF_ONLINE, &ha->flags) && | |
1631 | !test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { | |
afaf5a2d | 1632 | /* Adapter initialization failed, see if we can retry |
f4f5df23 VC |
1633 | * resetting the ha. |
1634 | * Since we don't want to block the DPC for too long | |
1635 | * with multiple resets in the same thread, | |
1636 | * utilize DPC to retry */ | |
afaf5a2d DS |
1637 | if (!test_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags)) { |
1638 | ha->retry_reset_ha_cnt = MAX_RESET_HA_RETRIES; | |
1639 | DEBUG2(printk("scsi%ld: recover adapter - retrying " | |
1640 | "(%d) more times\n", ha->host_no, | |
1641 | ha->retry_reset_ha_cnt)); | |
1642 | set_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); | |
1643 | status = QLA_ERROR; | |
1644 | } else { | |
1645 | if (ha->retry_reset_ha_cnt > 0) { | |
1646 | /* Schedule another Reset HA--DPC will retry */ | |
1647 | ha->retry_reset_ha_cnt--; | |
1648 | DEBUG2(printk("scsi%ld: recover adapter - " | |
1649 | "retry remaining %d\n", | |
1650 | ha->host_no, | |
1651 | ha->retry_reset_ha_cnt)); | |
1652 | status = QLA_ERROR; | |
1653 | } | |
1654 | ||
1655 | if (ha->retry_reset_ha_cnt == 0) { | |
1656 | /* Recover adapter retries have been exhausted. | |
1657 | * Adapter DEAD */ | |
1658 | DEBUG2(printk("scsi%ld: recover adapter " | |
1659 | "failed - board disabled\n", | |
1660 | ha->host_no)); | |
f4f5df23 | 1661 | qla4xxx_dead_adapter_cleanup(ha); |
afaf5a2d DS |
1662 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
1663 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); | |
f4f5df23 | 1664 | clear_bit(DPC_RESET_HA_FW_CONTEXT, |
afaf5a2d DS |
1665 | &ha->dpc_flags); |
1666 | status = QLA_ERROR; | |
1667 | } | |
1668 | } | |
1669 | } else { | |
1670 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); | |
f4f5df23 | 1671 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); |
afaf5a2d DS |
1672 | clear_bit(DPC_RETRY_RESET_HA, &ha->dpc_flags); |
1673 | } | |
1674 | ||
1675 | ha->adapter_error_count++; | |
1676 | ||
f4f5df23 VC |
1677 | if (test_bit(AF_ONLINE, &ha->flags)) |
1678 | ha->isp_ops->enable_intrs(ha); | |
1679 | ||
1680 | scsi_unblock_requests(ha->host); | |
1681 | ||
1682 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); | |
1683 | DEBUG2(printk("scsi%ld: recover adapter: %s\n", ha->host_no, | |
25985edc | 1684 | status == QLA_ERROR ? "FAILED" : "SUCCEEDED")); |
afaf5a2d | 1685 | |
afaf5a2d DS |
1686 | return status; |
1687 | } | |
1688 | ||
2d7924e6 VC |
1689 | static void qla4xxx_relogin_all_devices(struct scsi_qla_host *ha) |
1690 | { | |
1691 | struct ddb_entry *ddb_entry, *dtemp; | |
1692 | ||
1693 | list_for_each_entry_safe(ddb_entry, dtemp, &ha->ddb_list, list) { | |
1694 | if ((atomic_read(&ddb_entry->state) == DDB_STATE_MISSING) || | |
1695 | (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD)) { | |
1696 | if (ddb_entry->fw_ddb_device_state == | |
1697 | DDB_DS_SESSION_ACTIVE) { | |
1698 | atomic_set(&ddb_entry->state, DDB_STATE_ONLINE); | |
1699 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: ddb[%d]" | |
1700 | " marked ONLINE\n", ha->host_no, __func__, | |
1701 | ddb_entry->fw_ddb_index); | |
1702 | ||
1703 | iscsi_unblock_session(ddb_entry->sess); | |
1704 | } else | |
1705 | qla4xxx_relogin_device(ha, ddb_entry); | |
1706 | } | |
1707 | } | |
1708 | } | |
1709 | ||
f4f5df23 VC |
1710 | void qla4xxx_wake_dpc(struct scsi_qla_host *ha) |
1711 | { | |
1b46807e | 1712 | if (ha->dpc_thread) |
f4f5df23 | 1713 | queue_work(ha->dpc_thread, &ha->dpc_work); |
f4f5df23 VC |
1714 | } |
1715 | ||
afaf5a2d DS |
1716 | /** |
1717 | * qla4xxx_do_dpc - dpc routine | |
1718 | * @data: in our case pointer to adapter structure | |
1719 | * | |
1720 | * This routine is a task that is schedule by the interrupt handler | |
1721 | * to perform the background processing for interrupts. We put it | |
1722 | * on a task queue that is consumed whenever the scheduler runs; that's | |
1723 | * so you can do anything (i.e. put the process to sleep etc). In fact, | |
1724 | * the mid-level tries to sleep when it reaches the driver threshold | |
1725 | * "host->can_queue". This can cause a panic if we were in our interrupt code. | |
1726 | **/ | |
c4028958 | 1727 | static void qla4xxx_do_dpc(struct work_struct *work) |
afaf5a2d | 1728 | { |
c4028958 DH |
1729 | struct scsi_qla_host *ha = |
1730 | container_of(work, struct scsi_qla_host, dpc_work); | |
afaf5a2d | 1731 | struct ddb_entry *ddb_entry, *dtemp; |
477ffb9d | 1732 | int status = QLA_ERROR; |
afaf5a2d | 1733 | |
f26b9044 | 1734 | DEBUG2(printk("scsi%ld: %s: DPC handler waking up." |
f4f5df23 VC |
1735 | "flags = 0x%08lx, dpc_flags = 0x%08lx\n", |
1736 | ha->host_no, __func__, ha->flags, ha->dpc_flags)) | |
afaf5a2d DS |
1737 | |
1738 | /* Initialization not yet finished. Don't do anything yet. */ | |
1739 | if (!test_bit(AF_INIT_DONE, &ha->flags)) | |
1b46807e | 1740 | return; |
afaf5a2d | 1741 | |
2232be0d LC |
1742 | if (test_bit(AF_EEH_BUSY, &ha->flags)) { |
1743 | DEBUG2(printk(KERN_INFO "scsi%ld: %s: flags = %lx\n", | |
1744 | ha->host_no, __func__, ha->flags)); | |
1b46807e | 1745 | return; |
2232be0d LC |
1746 | } |
1747 | ||
f4f5df23 VC |
1748 | if (is_qla8022(ha)) { |
1749 | if (test_bit(DPC_HA_UNRECOVERABLE, &ha->dpc_flags)) { | |
1750 | qla4_8xxx_idc_lock(ha); | |
1751 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
1752 | QLA82XX_DEV_FAILED); | |
1753 | qla4_8xxx_idc_unlock(ha); | |
1754 | ql4_printk(KERN_INFO, ha, "HW State: FAILED\n"); | |
1755 | qla4_8xxx_device_state_handler(ha); | |
1756 | } | |
1757 | if (test_and_clear_bit(DPC_HA_NEED_QUIESCENT, &ha->dpc_flags)) { | |
1758 | qla4_8xxx_need_qsnt_handler(ha); | |
1759 | } | |
1760 | } | |
1761 | ||
1762 | if (!test_bit(DPC_RESET_ACTIVE, &ha->dpc_flags) && | |
1763 | (test_bit(DPC_RESET_HA, &ha->dpc_flags) || | |
afaf5a2d | 1764 | test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags) || |
f4f5df23 VC |
1765 | test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags))) { |
1766 | if (ql4xdontresethba) { | |
1767 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", | |
1768 | ha->host_no, __func__)); | |
1769 | clear_bit(DPC_RESET_HA, &ha->dpc_flags); | |
1770 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); | |
1771 | clear_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); | |
1772 | goto dpc_post_reset_ha; | |
1773 | } | |
1774 | if (test_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags) || | |
1775 | test_bit(DPC_RESET_HA, &ha->dpc_flags)) | |
1776 | qla4xxx_recover_adapter(ha); | |
afaf5a2d | 1777 | |
477ffb9d | 1778 | if (test_bit(DPC_RESET_HA_INTR, &ha->dpc_flags)) { |
afaf5a2d | 1779 | uint8_t wait_time = RESET_INTR_TOV; |
afaf5a2d | 1780 | |
afaf5a2d DS |
1781 | while ((readw(&ha->reg->ctrl_status) & |
1782 | (CSR_SOFT_RESET | CSR_FORCE_SOFT_RESET)) != 0) { | |
1783 | if (--wait_time == 0) | |
1784 | break; | |
afaf5a2d | 1785 | msleep(1000); |
afaf5a2d | 1786 | } |
afaf5a2d DS |
1787 | if (wait_time == 0) |
1788 | DEBUG2(printk("scsi%ld: %s: SR|FSR " | |
1789 | "bit not cleared-- resetting\n", | |
1790 | ha->host_no, __func__)); | |
f4f5df23 | 1791 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); |
477ffb9d DS |
1792 | if (ql4xxx_lock_drvr_wait(ha) == QLA_SUCCESS) { |
1793 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); | |
f4f5df23 | 1794 | status = qla4xxx_recover_adapter(ha); |
477ffb9d DS |
1795 | } |
1796 | clear_bit(DPC_RESET_HA_INTR, &ha->dpc_flags); | |
1797 | if (status == QLA_SUCCESS) | |
f4f5df23 | 1798 | ha->isp_ops->enable_intrs(ha); |
afaf5a2d DS |
1799 | } |
1800 | } | |
1801 | ||
f4f5df23 | 1802 | dpc_post_reset_ha: |
afaf5a2d DS |
1803 | /* ---- process AEN? --- */ |
1804 | if (test_and_clear_bit(DPC_AEN, &ha->dpc_flags)) | |
1805 | qla4xxx_process_aen(ha, PROCESS_ALL_AENS); | |
1806 | ||
1807 | /* ---- Get DHCP IP Address? --- */ | |
1808 | if (test_and_clear_bit(DPC_GET_DHCP_IP_ADDR, &ha->dpc_flags)) | |
1809 | qla4xxx_get_dhcp_ip_address(ha); | |
1810 | ||
065aa1b4 VC |
1811 | /* ---- link change? --- */ |
1812 | if (test_and_clear_bit(DPC_LINK_CHANGED, &ha->dpc_flags)) { | |
1813 | if (!test_bit(AF_LINK_UP, &ha->flags)) { | |
1814 | /* ---- link down? --- */ | |
2d7924e6 | 1815 | qla4xxx_mark_all_devices_missing(ha); |
065aa1b4 VC |
1816 | } else { |
1817 | /* ---- link up? --- * | |
1818 | * F/W will auto login to all devices ONLY ONCE after | |
1819 | * link up during driver initialization and runtime | |
1820 | * fatal error recovery. Therefore, the driver must | |
1821 | * manually relogin to devices when recovering from | |
1822 | * connection failures, logouts, expired KATO, etc. */ | |
1823 | ||
2d7924e6 | 1824 | qla4xxx_relogin_all_devices(ha); |
065aa1b4 VC |
1825 | } |
1826 | } | |
1827 | ||
afaf5a2d DS |
1828 | /* ---- relogin device? --- */ |
1829 | if (adapter_up(ha) && | |
1830 | test_and_clear_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags)) { | |
1831 | list_for_each_entry_safe(ddb_entry, dtemp, | |
1832 | &ha->ddb_list, list) { | |
1833 | if (test_and_clear_bit(DF_RELOGIN, &ddb_entry->flags) && | |
1834 | atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) | |
1835 | qla4xxx_relogin_device(ha, ddb_entry); | |
1836 | ||
1837 | /* | |
1838 | * If mbx cmd times out there is no point | |
1839 | * in continuing further. | |
1840 | * With large no of targets this can hang | |
1841 | * the system. | |
1842 | */ | |
1843 | if (test_bit(DPC_RESET_HA, &ha->dpc_flags)) { | |
1844 | printk(KERN_WARNING "scsi%ld: %s: " | |
1845 | "need to reset hba\n", | |
1846 | ha->host_no, __func__); | |
1847 | break; | |
1848 | } | |
1849 | } | |
1850 | } | |
0753b487 | 1851 | |
afaf5a2d DS |
1852 | } |
1853 | ||
1854 | /** | |
1855 | * qla4xxx_free_adapter - release the adapter | |
1856 | * @ha: pointer to adapter structure | |
1857 | **/ | |
1858 | static void qla4xxx_free_adapter(struct scsi_qla_host *ha) | |
1859 | { | |
1860 | ||
1861 | if (test_bit(AF_INTERRUPTS_ON, &ha->flags)) { | |
1862 | /* Turn-off interrupts on the card. */ | |
f4f5df23 | 1863 | ha->isp_ops->disable_intrs(ha); |
afaf5a2d DS |
1864 | } |
1865 | ||
f4f5df23 VC |
1866 | /* Remove timer thread, if present */ |
1867 | if (ha->timer_active) | |
1868 | qla4xxx_stop_timer(ha); | |
1869 | ||
afaf5a2d DS |
1870 | /* Kill the kernel thread for this host */ |
1871 | if (ha->dpc_thread) | |
1872 | destroy_workqueue(ha->dpc_thread); | |
1873 | ||
f4f5df23 VC |
1874 | /* Put firmware in known state */ |
1875 | ha->isp_ops->reset_firmware(ha); | |
afaf5a2d | 1876 | |
f4f5df23 VC |
1877 | if (is_qla8022(ha)) { |
1878 | qla4_8xxx_idc_lock(ha); | |
1879 | qla4_8xxx_clear_drv_active(ha); | |
1880 | qla4_8xxx_idc_unlock(ha); | |
1881 | } | |
afaf5a2d | 1882 | |
afaf5a2d DS |
1883 | /* Detach interrupts */ |
1884 | if (test_and_clear_bit(AF_IRQ_ATTACHED, &ha->flags)) | |
f4f5df23 | 1885 | qla4xxx_free_irqs(ha); |
afaf5a2d | 1886 | |
bee4fe8e DS |
1887 | /* free extra memory */ |
1888 | qla4xxx_mem_free(ha); | |
f4f5df23 VC |
1889 | } |
1890 | ||
1891 | int qla4_8xxx_iospace_config(struct scsi_qla_host *ha) | |
1892 | { | |
1893 | int status = 0; | |
1894 | uint8_t revision_id; | |
1895 | unsigned long mem_base, mem_len, db_base, db_len; | |
1896 | struct pci_dev *pdev = ha->pdev; | |
1897 | ||
1898 | status = pci_request_regions(pdev, DRIVER_NAME); | |
1899 | if (status) { | |
1900 | printk(KERN_WARNING | |
1901 | "scsi(%ld) Failed to reserve PIO regions (%s) " | |
1902 | "status=%d\n", ha->host_no, pci_name(pdev), status); | |
1903 | goto iospace_error_exit; | |
1904 | } | |
1905 | ||
1906 | pci_read_config_byte(pdev, PCI_REVISION_ID, &revision_id); | |
1907 | DEBUG2(printk(KERN_INFO "%s: revision-id=%d\n", | |
1908 | __func__, revision_id)); | |
1909 | ha->revision_id = revision_id; | |
bee4fe8e | 1910 | |
f4f5df23 VC |
1911 | /* remap phys address */ |
1912 | mem_base = pci_resource_start(pdev, 0); /* 0 is for BAR 0 */ | |
1913 | mem_len = pci_resource_len(pdev, 0); | |
1914 | DEBUG2(printk(KERN_INFO "%s: ioremap from %lx a size of %lx\n", | |
1915 | __func__, mem_base, mem_len)); | |
afaf5a2d | 1916 | |
f4f5df23 VC |
1917 | /* mapping of pcibase pointer */ |
1918 | ha->nx_pcibase = (unsigned long)ioremap(mem_base, mem_len); | |
1919 | if (!ha->nx_pcibase) { | |
1920 | printk(KERN_ERR | |
1921 | "cannot remap MMIO (%s), aborting\n", pci_name(pdev)); | |
1922 | pci_release_regions(ha->pdev); | |
1923 | goto iospace_error_exit; | |
1924 | } | |
1925 | ||
1926 | /* Mapping of IO base pointer, door bell read and write pointer */ | |
1927 | ||
1928 | /* mapping of IO base pointer */ | |
1929 | ha->qla4_8xxx_reg = | |
1930 | (struct device_reg_82xx __iomem *)((uint8_t *)ha->nx_pcibase + | |
1931 | 0xbc000 + (ha->pdev->devfn << 11)); | |
1932 | ||
1933 | db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */ | |
1934 | db_len = pci_resource_len(pdev, 4); | |
1935 | ||
2657c800 SS |
1936 | ha->nx_db_wr_ptr = (ha->pdev->devfn == 4 ? QLA82XX_CAM_RAM_DB1 : |
1937 | QLA82XX_CAM_RAM_DB2); | |
f4f5df23 | 1938 | |
2657c800 | 1939 | return 0; |
f4f5df23 VC |
1940 | iospace_error_exit: |
1941 | return -ENOMEM; | |
afaf5a2d DS |
1942 | } |
1943 | ||
1944 | /*** | |
1945 | * qla4xxx_iospace_config - maps registers | |
1946 | * @ha: pointer to adapter structure | |
1947 | * | |
1948 | * This routines maps HBA's registers from the pci address space | |
1949 | * into the kernel virtual address space for memory mapped i/o. | |
1950 | **/ | |
f4f5df23 | 1951 | int qla4xxx_iospace_config(struct scsi_qla_host *ha) |
afaf5a2d DS |
1952 | { |
1953 | unsigned long pio, pio_len, pio_flags; | |
1954 | unsigned long mmio, mmio_len, mmio_flags; | |
1955 | ||
1956 | pio = pci_resource_start(ha->pdev, 0); | |
1957 | pio_len = pci_resource_len(ha->pdev, 0); | |
1958 | pio_flags = pci_resource_flags(ha->pdev, 0); | |
1959 | if (pio_flags & IORESOURCE_IO) { | |
1960 | if (pio_len < MIN_IOBASE_LEN) { | |
c2660df3 | 1961 | ql4_printk(KERN_WARNING, ha, |
afaf5a2d DS |
1962 | "Invalid PCI I/O region size\n"); |
1963 | pio = 0; | |
1964 | } | |
1965 | } else { | |
c2660df3 | 1966 | ql4_printk(KERN_WARNING, ha, "region #0 not a PIO resource\n"); |
afaf5a2d DS |
1967 | pio = 0; |
1968 | } | |
1969 | ||
1970 | /* Use MMIO operations for all accesses. */ | |
1971 | mmio = pci_resource_start(ha->pdev, 1); | |
1972 | mmio_len = pci_resource_len(ha->pdev, 1); | |
1973 | mmio_flags = pci_resource_flags(ha->pdev, 1); | |
1974 | ||
1975 | if (!(mmio_flags & IORESOURCE_MEM)) { | |
c2660df3 VC |
1976 | ql4_printk(KERN_ERR, ha, |
1977 | "region #0 not an MMIO resource, aborting\n"); | |
afaf5a2d DS |
1978 | |
1979 | goto iospace_error_exit; | |
1980 | } | |
c2660df3 | 1981 | |
afaf5a2d | 1982 | if (mmio_len < MIN_IOBASE_LEN) { |
c2660df3 VC |
1983 | ql4_printk(KERN_ERR, ha, |
1984 | "Invalid PCI mem region size, aborting\n"); | |
afaf5a2d DS |
1985 | goto iospace_error_exit; |
1986 | } | |
1987 | ||
1988 | if (pci_request_regions(ha->pdev, DRIVER_NAME)) { | |
c2660df3 VC |
1989 | ql4_printk(KERN_WARNING, ha, |
1990 | "Failed to reserve PIO/MMIO regions\n"); | |
afaf5a2d DS |
1991 | |
1992 | goto iospace_error_exit; | |
1993 | } | |
1994 | ||
1995 | ha->pio_address = pio; | |
1996 | ha->pio_length = pio_len; | |
1997 | ha->reg = ioremap(mmio, MIN_IOBASE_LEN); | |
1998 | if (!ha->reg) { | |
c2660df3 VC |
1999 | ql4_printk(KERN_ERR, ha, |
2000 | "cannot remap MMIO, aborting\n"); | |
afaf5a2d DS |
2001 | |
2002 | goto iospace_error_exit; | |
2003 | } | |
2004 | ||
2005 | return 0; | |
2006 | ||
2007 | iospace_error_exit: | |
2008 | return -ENOMEM; | |
2009 | } | |
2010 | ||
f4f5df23 VC |
2011 | static struct isp_operations qla4xxx_isp_ops = { |
2012 | .iospace_config = qla4xxx_iospace_config, | |
2013 | .pci_config = qla4xxx_pci_config, | |
2014 | .disable_intrs = qla4xxx_disable_intrs, | |
2015 | .enable_intrs = qla4xxx_enable_intrs, | |
2016 | .start_firmware = qla4xxx_start_firmware, | |
2017 | .intr_handler = qla4xxx_intr_handler, | |
2018 | .interrupt_service_routine = qla4xxx_interrupt_service_routine, | |
2019 | .reset_chip = qla4xxx_soft_reset, | |
2020 | .reset_firmware = qla4xxx_hw_reset, | |
2021 | .queue_iocb = qla4xxx_queue_iocb, | |
2022 | .complete_iocb = qla4xxx_complete_iocb, | |
2023 | .rd_shdw_req_q_out = qla4xxx_rd_shdw_req_q_out, | |
2024 | .rd_shdw_rsp_q_in = qla4xxx_rd_shdw_rsp_q_in, | |
2025 | .get_sys_info = qla4xxx_get_sys_info, | |
2026 | }; | |
2027 | ||
2028 | static struct isp_operations qla4_8xxx_isp_ops = { | |
2029 | .iospace_config = qla4_8xxx_iospace_config, | |
2030 | .pci_config = qla4_8xxx_pci_config, | |
2031 | .disable_intrs = qla4_8xxx_disable_intrs, | |
2032 | .enable_intrs = qla4_8xxx_enable_intrs, | |
2033 | .start_firmware = qla4_8xxx_load_risc, | |
2034 | .intr_handler = qla4_8xxx_intr_handler, | |
2035 | .interrupt_service_routine = qla4_8xxx_interrupt_service_routine, | |
2036 | .reset_chip = qla4_8xxx_isp_reset, | |
2037 | .reset_firmware = qla4_8xxx_stop_firmware, | |
2038 | .queue_iocb = qla4_8xxx_queue_iocb, | |
2039 | .complete_iocb = qla4_8xxx_complete_iocb, | |
2040 | .rd_shdw_req_q_out = qla4_8xxx_rd_shdw_req_q_out, | |
2041 | .rd_shdw_rsp_q_in = qla4_8xxx_rd_shdw_rsp_q_in, | |
2042 | .get_sys_info = qla4_8xxx_get_sys_info, | |
2043 | }; | |
2044 | ||
2045 | uint16_t qla4xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) | |
2046 | { | |
2047 | return (uint16_t)le32_to_cpu(ha->shadow_regs->req_q_out); | |
2048 | } | |
2049 | ||
2050 | uint16_t qla4_8xxx_rd_shdw_req_q_out(struct scsi_qla_host *ha) | |
2051 | { | |
2052 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->req_q_out)); | |
2053 | } | |
2054 | ||
2055 | uint16_t qla4xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) | |
2056 | { | |
2057 | return (uint16_t)le32_to_cpu(ha->shadow_regs->rsp_q_in); | |
2058 | } | |
2059 | ||
2060 | uint16_t qla4_8xxx_rd_shdw_rsp_q_in(struct scsi_qla_host *ha) | |
2061 | { | |
2062 | return (uint16_t)le32_to_cpu(readl(&ha->qla4_8xxx_reg->rsp_q_in)); | |
2063 | } | |
2064 | ||
afaf5a2d DS |
2065 | /** |
2066 | * qla4xxx_probe_adapter - callback function to probe HBA | |
2067 | * @pdev: pointer to pci_dev structure | |
2068 | * @pci_device_id: pointer to pci_device entry | |
2069 | * | |
2070 | * This routine will probe for Qlogic 4xxx iSCSI host adapters. | |
2071 | * It returns zero if successful. It also initializes all data necessary for | |
2072 | * the driver. | |
2073 | **/ | |
2074 | static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev, | |
2075 | const struct pci_device_id *ent) | |
2076 | { | |
2077 | int ret = -ENODEV, status; | |
2078 | struct Scsi_Host *host; | |
2079 | struct scsi_qla_host *ha; | |
afaf5a2d DS |
2080 | uint8_t init_retry_count = 0; |
2081 | char buf[34]; | |
f4f5df23 | 2082 | struct qla4_8xxx_legacy_intr_set *nx_legacy_intr; |
f9880e76 | 2083 | uint32_t dev_state; |
afaf5a2d DS |
2084 | |
2085 | if (pci_enable_device(pdev)) | |
2086 | return -1; | |
2087 | ||
2088 | host = scsi_host_alloc(&qla4xxx_driver_template, sizeof(*ha)); | |
2089 | if (host == NULL) { | |
2090 | printk(KERN_WARNING | |
2091 | "qla4xxx: Couldn't allocate host from scsi layer!\n"); | |
2092 | goto probe_disable_device; | |
2093 | } | |
2094 | ||
2095 | /* Clear our data area */ | |
2096 | ha = (struct scsi_qla_host *) host->hostdata; | |
2097 | memset(ha, 0, sizeof(*ha)); | |
2098 | ||
2099 | /* Save the information from PCI BIOS. */ | |
2100 | ha->pdev = pdev; | |
2101 | ha->host = host; | |
2102 | ha->host_no = host->host_no; | |
2103 | ||
2232be0d LC |
2104 | pci_enable_pcie_error_reporting(pdev); |
2105 | ||
f4f5df23 VC |
2106 | /* Setup Runtime configurable options */ |
2107 | if (is_qla8022(ha)) { | |
2108 | ha->isp_ops = &qla4_8xxx_isp_ops; | |
2109 | rwlock_init(&ha->hw_lock); | |
2110 | ha->qdr_sn_window = -1; | |
2111 | ha->ddr_mn_window = -1; | |
2112 | ha->curr_window = 255; | |
2113 | ha->func_num = PCI_FUNC(ha->pdev->devfn); | |
2114 | nx_legacy_intr = &legacy_intr[ha->func_num]; | |
2115 | ha->nx_legacy_intr.int_vec_bit = nx_legacy_intr->int_vec_bit; | |
2116 | ha->nx_legacy_intr.tgt_status_reg = | |
2117 | nx_legacy_intr->tgt_status_reg; | |
2118 | ha->nx_legacy_intr.tgt_mask_reg = nx_legacy_intr->tgt_mask_reg; | |
2119 | ha->nx_legacy_intr.pci_int_reg = nx_legacy_intr->pci_int_reg; | |
2120 | } else { | |
2121 | ha->isp_ops = &qla4xxx_isp_ops; | |
2122 | } | |
2123 | ||
2232be0d LC |
2124 | /* Set EEH reset type to fundamental if required by hba */ |
2125 | if (is_qla8022(ha)) | |
2126 | pdev->needs_freset = 1; | |
2127 | ||
afaf5a2d | 2128 | /* Configure PCI I/O space. */ |
f4f5df23 | 2129 | ret = ha->isp_ops->iospace_config(ha); |
afaf5a2d | 2130 | if (ret) |
f4f5df23 | 2131 | goto probe_failed_ioconfig; |
afaf5a2d | 2132 | |
c2660df3 | 2133 | ql4_printk(KERN_INFO, ha, "Found an ISP%04x, irq %d, iobase 0x%p\n", |
afaf5a2d DS |
2134 | pdev->device, pdev->irq, ha->reg); |
2135 | ||
2136 | qla4xxx_config_dma_addressing(ha); | |
2137 | ||
2138 | /* Initialize lists and spinlocks. */ | |
2139 | INIT_LIST_HEAD(&ha->ddb_list); | |
2140 | INIT_LIST_HEAD(&ha->free_srb_q); | |
2141 | ||
2142 | mutex_init(&ha->mbox_sem); | |
f4f5df23 | 2143 | init_completion(&ha->mbx_intr_comp); |
afaf5a2d DS |
2144 | |
2145 | spin_lock_init(&ha->hardware_lock); | |
afaf5a2d DS |
2146 | |
2147 | /* Allocate dma buffers */ | |
2148 | if (qla4xxx_mem_alloc(ha)) { | |
c2660df3 VC |
2149 | ql4_printk(KERN_WARNING, ha, |
2150 | "[ERROR] Failed to allocate memory for adapter\n"); | |
afaf5a2d DS |
2151 | |
2152 | ret = -ENOMEM; | |
2153 | goto probe_failed; | |
2154 | } | |
2155 | ||
f4f5df23 VC |
2156 | if (is_qla8022(ha)) |
2157 | (void) qla4_8xxx_get_flash_info(ha); | |
2158 | ||
afaf5a2d DS |
2159 | /* |
2160 | * Initialize the Host adapter request/response queues and | |
2161 | * firmware | |
2162 | * NOTE: interrupts enabled upon successful completion | |
2163 | */ | |
2164 | status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST); | |
f4f5df23 VC |
2165 | while ((!test_bit(AF_ONLINE, &ha->flags)) && |
2166 | init_retry_count++ < MAX_INIT_RETRIES) { | |
f9880e76 PM |
2167 | |
2168 | if (is_qla8022(ha)) { | |
2169 | qla4_8xxx_idc_lock(ha); | |
2170 | dev_state = qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE); | |
2171 | qla4_8xxx_idc_unlock(ha); | |
2172 | if (dev_state == QLA82XX_DEV_FAILED) { | |
2173 | ql4_printk(KERN_WARNING, ha, "%s: don't retry " | |
2174 | "initialize adapter. H/W is in failed state\n", | |
2175 | __func__); | |
2176 | break; | |
2177 | } | |
2178 | } | |
afaf5a2d DS |
2179 | DEBUG2(printk("scsi: %s: retrying adapter initialization " |
2180 | "(%d)\n", __func__, init_retry_count)); | |
f4f5df23 VC |
2181 | |
2182 | if (ha->isp_ops->reset_chip(ha) == QLA_ERROR) | |
2183 | continue; | |
2184 | ||
afaf5a2d DS |
2185 | status = qla4xxx_initialize_adapter(ha, REBUILD_DDB_LIST); |
2186 | } | |
f4f5df23 VC |
2187 | |
2188 | if (!test_bit(AF_ONLINE, &ha->flags)) { | |
c2660df3 | 2189 | ql4_printk(KERN_WARNING, ha, "Failed to initialize adapter\n"); |
afaf5a2d | 2190 | |
fe998527 LC |
2191 | if (is_qla8022(ha) && ql4xdontresethba) { |
2192 | /* Put the device in failed state. */ | |
2193 | DEBUG2(printk(KERN_ERR "HW STATE: FAILED\n")); | |
2194 | qla4_8xxx_idc_lock(ha); | |
2195 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
2196 | QLA82XX_DEV_FAILED); | |
2197 | qla4_8xxx_idc_unlock(ha); | |
2198 | } | |
afaf5a2d DS |
2199 | ret = -ENODEV; |
2200 | goto probe_failed; | |
2201 | } | |
2202 | ||
2203 | host->cmd_per_lun = 3; | |
2204 | host->max_channel = 0; | |
2205 | host->max_lun = MAX_LUNS - 1; | |
2206 | host->max_id = MAX_TARGETS; | |
2207 | host->max_cmd_len = IOCB_MAX_CDB_LEN; | |
2208 | host->can_queue = MAX_SRBS ; | |
2209 | host->transportt = qla4xxx_scsi_transport; | |
2210 | ||
2211 | ret = scsi_init_shared_tag_map(host, MAX_SRBS); | |
2212 | if (ret) { | |
c2660df3 VC |
2213 | ql4_printk(KERN_WARNING, ha, |
2214 | "scsi_init_shared_tag_map failed\n"); | |
2215 | goto probe_failed; | |
afaf5a2d DS |
2216 | } |
2217 | ||
2218 | /* Startup the kernel thread for this host adapter. */ | |
2219 | DEBUG2(printk("scsi: %s: Starting kernel thread for " | |
2220 | "qla4xxx_dpc\n", __func__)); | |
2221 | sprintf(buf, "qla4xxx_%lu_dpc", ha->host_no); | |
2222 | ha->dpc_thread = create_singlethread_workqueue(buf); | |
2223 | if (!ha->dpc_thread) { | |
c2660df3 | 2224 | ql4_printk(KERN_WARNING, ha, "Unable to start DPC thread!\n"); |
afaf5a2d DS |
2225 | ret = -ENODEV; |
2226 | goto probe_failed; | |
2227 | } | |
c4028958 | 2228 | INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); |
afaf5a2d | 2229 | |
f4f5df23 VC |
2230 | /* For ISP-82XX, request_irqs is called in qla4_8xxx_load_risc |
2231 | * (which is called indirectly by qla4xxx_initialize_adapter), | |
2232 | * so that irqs will be registered after crbinit but before | |
2233 | * mbx_intr_enable. | |
2234 | */ | |
2235 | if (!is_qla8022(ha)) { | |
2236 | ret = qla4xxx_request_irqs(ha); | |
2237 | if (ret) { | |
2238 | ql4_printk(KERN_WARNING, ha, "Failed to reserve " | |
2239 | "interrupt %d already in use.\n", pdev->irq); | |
2240 | goto probe_failed; | |
2241 | } | |
afaf5a2d | 2242 | } |
afaf5a2d | 2243 | |
2232be0d | 2244 | pci_save_state(ha->pdev); |
f4f5df23 | 2245 | ha->isp_ops->enable_intrs(ha); |
afaf5a2d DS |
2246 | |
2247 | /* Start timer thread. */ | |
2248 | qla4xxx_start_timer(ha, qla4xxx_timer, 1); | |
2249 | ||
2250 | set_bit(AF_INIT_DONE, &ha->flags); | |
2251 | ||
2252 | pci_set_drvdata(pdev, ha); | |
2253 | ||
2254 | ret = scsi_add_host(host, &pdev->dev); | |
2255 | if (ret) | |
2256 | goto probe_failed; | |
2257 | ||
afaf5a2d DS |
2258 | printk(KERN_INFO |
2259 | " QLogic iSCSI HBA Driver version: %s\n" | |
2260 | " QLogic ISP%04x @ %s, host#=%ld, fw=%02d.%02d.%02d.%02d\n", | |
2261 | qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev), | |
2262 | ha->host_no, ha->firmware_version[0], ha->firmware_version[1], | |
2263 | ha->patch_number, ha->build_number); | |
921601b7 | 2264 | scsi_scan_host(host); |
ed1086e0 VC |
2265 | |
2266 | qla4xxx_create_ifaces(ha); | |
afaf5a2d DS |
2267 | return 0; |
2268 | ||
afaf5a2d DS |
2269 | probe_failed: |
2270 | qla4xxx_free_adapter(ha); | |
f4f5df23 VC |
2271 | |
2272 | probe_failed_ioconfig: | |
2232be0d | 2273 | pci_disable_pcie_error_reporting(pdev); |
afaf5a2d DS |
2274 | scsi_host_put(ha->host); |
2275 | ||
2276 | probe_disable_device: | |
2277 | pci_disable_device(pdev); | |
2278 | ||
2279 | return ret; | |
2280 | } | |
2281 | ||
7eece5a0 KH |
2282 | /** |
2283 | * qla4xxx_prevent_other_port_reinit - prevent other port from re-initialize | |
2284 | * @ha: pointer to adapter structure | |
2285 | * | |
2286 | * Mark the other ISP-4xxx port to indicate that the driver is being removed, | |
2287 | * so that the other port will not re-initialize while in the process of | |
2288 | * removing the ha due to driver unload or hba hotplug. | |
2289 | **/ | |
2290 | static void qla4xxx_prevent_other_port_reinit(struct scsi_qla_host *ha) | |
2291 | { | |
2292 | struct scsi_qla_host *other_ha = NULL; | |
2293 | struct pci_dev *other_pdev = NULL; | |
2294 | int fn = ISP4XXX_PCI_FN_2; | |
2295 | ||
2296 | /*iscsi function numbers for ISP4xxx is 1 and 3*/ | |
2297 | if (PCI_FUNC(ha->pdev->devfn) & BIT_1) | |
2298 | fn = ISP4XXX_PCI_FN_1; | |
2299 | ||
2300 | other_pdev = | |
2301 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), | |
2302 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), | |
2303 | fn)); | |
2304 | ||
2305 | /* Get other_ha if other_pdev is valid and state is enable*/ | |
2306 | if (other_pdev) { | |
2307 | if (atomic_read(&other_pdev->enable_cnt)) { | |
2308 | other_ha = pci_get_drvdata(other_pdev); | |
2309 | if (other_ha) { | |
2310 | set_bit(AF_HA_REMOVAL, &other_ha->flags); | |
2311 | DEBUG2(ql4_printk(KERN_INFO, ha, "%s: " | |
2312 | "Prevent %s reinit\n", __func__, | |
2313 | dev_name(&other_ha->pdev->dev))); | |
2314 | } | |
2315 | } | |
2316 | pci_dev_put(other_pdev); | |
2317 | } | |
2318 | } | |
2319 | ||
afaf5a2d DS |
2320 | /** |
2321 | * qla4xxx_remove_adapter - calback function to remove adapter. | |
2322 | * @pci_dev: PCI device pointer | |
2323 | **/ | |
2324 | static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev) | |
2325 | { | |
2326 | struct scsi_qla_host *ha; | |
2327 | ||
2328 | ha = pci_get_drvdata(pdev); | |
2329 | ||
7eece5a0 KH |
2330 | if (!is_qla8022(ha)) |
2331 | qla4xxx_prevent_other_port_reinit(ha); | |
bee4fe8e | 2332 | |
afaf5a2d DS |
2333 | /* remove devs from iscsi_sessions to scsi_devices */ |
2334 | qla4xxx_free_ddb_list(ha); | |
2335 | ||
ed1086e0 VC |
2336 | /* destroy iface from sysfs */ |
2337 | qla4xxx_destroy_ifaces(ha); | |
2338 | ||
afaf5a2d DS |
2339 | scsi_remove_host(ha->host); |
2340 | ||
2341 | qla4xxx_free_adapter(ha); | |
2342 | ||
2343 | scsi_host_put(ha->host); | |
2344 | ||
2232be0d | 2345 | pci_disable_pcie_error_reporting(pdev); |
f4f5df23 | 2346 | pci_disable_device(pdev); |
afaf5a2d DS |
2347 | pci_set_drvdata(pdev, NULL); |
2348 | } | |
2349 | ||
2350 | /** | |
2351 | * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method. | |
2352 | * @ha: HA context | |
2353 | * | |
2354 | * At exit, the @ha's flags.enable_64bit_addressing set to indicated | |
2355 | * supported addressing method. | |
2356 | */ | |
47975477 | 2357 | static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) |
afaf5a2d DS |
2358 | { |
2359 | int retval; | |
2360 | ||
2361 | /* Update our PCI device dma_mask for full 64 bit mask */ | |
6a35528a YH |
2362 | if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) { |
2363 | if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) { | |
afaf5a2d DS |
2364 | dev_dbg(&ha->pdev->dev, |
2365 | "Failed to set 64 bit PCI consistent mask; " | |
2366 | "using 32 bit.\n"); | |
2367 | retval = pci_set_consistent_dma_mask(ha->pdev, | |
284901a9 | 2368 | DMA_BIT_MASK(32)); |
afaf5a2d DS |
2369 | } |
2370 | } else | |
284901a9 | 2371 | retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32)); |
afaf5a2d DS |
2372 | } |
2373 | ||
2374 | static int qla4xxx_slave_alloc(struct scsi_device *sdev) | |
2375 | { | |
2376 | struct iscsi_cls_session *sess = starget_to_session(sdev->sdev_target); | |
2377 | struct ddb_entry *ddb = sess->dd_data; | |
8bb4033d | 2378 | int queue_depth = QL4_DEF_QDEPTH; |
afaf5a2d DS |
2379 | |
2380 | sdev->hostdata = ddb; | |
2381 | sdev->tagged_supported = 1; | |
8bb4033d VC |
2382 | |
2383 | if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) | |
2384 | queue_depth = ql4xmaxqdepth; | |
2385 | ||
2386 | scsi_activate_tcq(sdev, queue_depth); | |
afaf5a2d DS |
2387 | return 0; |
2388 | } | |
2389 | ||
2390 | static int qla4xxx_slave_configure(struct scsi_device *sdev) | |
2391 | { | |
2392 | sdev->tagged_supported = 1; | |
2393 | return 0; | |
2394 | } | |
2395 | ||
2396 | static void qla4xxx_slave_destroy(struct scsi_device *sdev) | |
2397 | { | |
2398 | scsi_deactivate_tcq(sdev, 1); | |
2399 | } | |
2400 | ||
2401 | /** | |
2402 | * qla4xxx_del_from_active_array - returns an active srb | |
2403 | * @ha: Pointer to host adapter structure. | |
fd589a8f | 2404 | * @index: index into the active_array |
afaf5a2d DS |
2405 | * |
2406 | * This routine removes and returns the srb at the specified index | |
2407 | **/ | |
f4f5df23 VC |
2408 | struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, |
2409 | uint32_t index) | |
afaf5a2d DS |
2410 | { |
2411 | struct srb *srb = NULL; | |
5369887a | 2412 | struct scsi_cmnd *cmd = NULL; |
afaf5a2d | 2413 | |
5369887a VC |
2414 | cmd = scsi_host_find_tag(ha->host, index); |
2415 | if (!cmd) | |
afaf5a2d DS |
2416 | return srb; |
2417 | ||
5369887a VC |
2418 | srb = (struct srb *)CMD_SP(cmd); |
2419 | if (!srb) | |
afaf5a2d DS |
2420 | return srb; |
2421 | ||
2422 | /* update counters */ | |
2423 | if (srb->flags & SRB_DMA_VALID) { | |
2424 | ha->req_q_count += srb->iocb_cnt; | |
2425 | ha->iocb_cnt -= srb->iocb_cnt; | |
2426 | if (srb->cmd) | |
5369887a VC |
2427 | srb->cmd->host_scribble = |
2428 | (unsigned char *)(unsigned long) MAX_SRBS; | |
afaf5a2d DS |
2429 | } |
2430 | return srb; | |
2431 | } | |
2432 | ||
afaf5a2d DS |
2433 | /** |
2434 | * qla4xxx_eh_wait_on_command - waits for command to be returned by firmware | |
09a0f719 | 2435 | * @ha: Pointer to host adapter structure. |
afaf5a2d DS |
2436 | * @cmd: Scsi Command to wait on. |
2437 | * | |
2438 | * This routine waits for the command to be returned by the Firmware | |
2439 | * for some max time. | |
2440 | **/ | |
2441 | static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, | |
2442 | struct scsi_cmnd *cmd) | |
2443 | { | |
2444 | int done = 0; | |
2445 | struct srb *rp; | |
2446 | uint32_t max_wait_time = EH_WAIT_CMD_TOV; | |
2232be0d LC |
2447 | int ret = SUCCESS; |
2448 | ||
2449 | /* Dont wait on command if PCI error is being handled | |
2450 | * by PCI AER driver | |
2451 | */ | |
2452 | if (unlikely(pci_channel_offline(ha->pdev)) || | |
2453 | (test_bit(AF_EEH_BUSY, &ha->flags))) { | |
2454 | ql4_printk(KERN_WARNING, ha, "scsi%ld: Return from %s\n", | |
2455 | ha->host_no, __func__); | |
2456 | return ret; | |
2457 | } | |
afaf5a2d DS |
2458 | |
2459 | do { | |
2460 | /* Checking to see if its returned to OS */ | |
5369887a | 2461 | rp = (struct srb *) CMD_SP(cmd); |
afaf5a2d DS |
2462 | if (rp == NULL) { |
2463 | done++; | |
2464 | break; | |
2465 | } | |
2466 | ||
2467 | msleep(2000); | |
2468 | } while (max_wait_time--); | |
2469 | ||
2470 | return done; | |
2471 | } | |
2472 | ||
2473 | /** | |
2474 | * qla4xxx_wait_for_hba_online - waits for HBA to come online | |
2475 | * @ha: Pointer to host adapter structure | |
2476 | **/ | |
2477 | static int qla4xxx_wait_for_hba_online(struct scsi_qla_host *ha) | |
2478 | { | |
2479 | unsigned long wait_online; | |
2480 | ||
f581a3f7 | 2481 | wait_online = jiffies + (HBA_ONLINE_TOV * HZ); |
afaf5a2d DS |
2482 | while (time_before(jiffies, wait_online)) { |
2483 | ||
2484 | if (adapter_up(ha)) | |
2485 | return QLA_SUCCESS; | |
afaf5a2d DS |
2486 | |
2487 | msleep(2000); | |
2488 | } | |
2489 | ||
2490 | return QLA_ERROR; | |
2491 | } | |
2492 | ||
2493 | /** | |
ce545039 | 2494 | * qla4xxx_eh_wait_for_commands - wait for active cmds to finish. |
fd589a8f | 2495 | * @ha: pointer to HBA |
afaf5a2d DS |
2496 | * @t: target id |
2497 | * @l: lun id | |
2498 | * | |
2499 | * This function waits for all outstanding commands to a lun to complete. It | |
2500 | * returns 0 if all pending commands are returned and 1 otherwise. | |
2501 | **/ | |
ce545039 MC |
2502 | static int qla4xxx_eh_wait_for_commands(struct scsi_qla_host *ha, |
2503 | struct scsi_target *stgt, | |
2504 | struct scsi_device *sdev) | |
afaf5a2d DS |
2505 | { |
2506 | int cnt; | |
2507 | int status = 0; | |
2508 | struct scsi_cmnd *cmd; | |
2509 | ||
2510 | /* | |
ce545039 MC |
2511 | * Waiting for all commands for the designated target or dev |
2512 | * in the active array | |
afaf5a2d DS |
2513 | */ |
2514 | for (cnt = 0; cnt < ha->host->can_queue; cnt++) { | |
2515 | cmd = scsi_host_find_tag(ha->host, cnt); | |
ce545039 MC |
2516 | if (cmd && stgt == scsi_target(cmd->device) && |
2517 | (!sdev || sdev == cmd->device)) { | |
afaf5a2d DS |
2518 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { |
2519 | status++; | |
2520 | break; | |
2521 | } | |
2522 | } | |
2523 | } | |
2524 | return status; | |
2525 | } | |
2526 | ||
09a0f719 VC |
2527 | /** |
2528 | * qla4xxx_eh_abort - callback for abort task. | |
2529 | * @cmd: Pointer to Linux's SCSI command structure | |
2530 | * | |
2531 | * This routine is called by the Linux OS to abort the specified | |
2532 | * command. | |
2533 | **/ | |
2534 | static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) | |
2535 | { | |
2536 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); | |
2537 | unsigned int id = cmd->device->id; | |
2538 | unsigned int lun = cmd->device->lun; | |
92b3e5bb | 2539 | unsigned long flags; |
09a0f719 VC |
2540 | struct srb *srb = NULL; |
2541 | int ret = SUCCESS; | |
2542 | int wait = 0; | |
2543 | ||
c2660df3 | 2544 | ql4_printk(KERN_INFO, ha, |
5cd049a5 CH |
2545 | "scsi%ld:%d:%d: Abort command issued cmd=%p\n", |
2546 | ha->host_no, id, lun, cmd); | |
09a0f719 | 2547 | |
92b3e5bb | 2548 | spin_lock_irqsave(&ha->hardware_lock, flags); |
09a0f719 | 2549 | srb = (struct srb *) CMD_SP(cmd); |
92b3e5bb MC |
2550 | if (!srb) { |
2551 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
09a0f719 | 2552 | return SUCCESS; |
92b3e5bb | 2553 | } |
09a0f719 | 2554 | kref_get(&srb->srb_ref); |
92b3e5bb | 2555 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
09a0f719 VC |
2556 | |
2557 | if (qla4xxx_abort_task(ha, srb) != QLA_SUCCESS) { | |
2558 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx failed.\n", | |
2559 | ha->host_no, id, lun)); | |
2560 | ret = FAILED; | |
2561 | } else { | |
2562 | DEBUG3(printk("scsi%ld:%d:%d: Abort_task mbx success.\n", | |
2563 | ha->host_no, id, lun)); | |
2564 | wait = 1; | |
2565 | } | |
2566 | ||
2567 | kref_put(&srb->srb_ref, qla4xxx_srb_compl); | |
2568 | ||
2569 | /* Wait for command to complete */ | |
2570 | if (wait) { | |
2571 | if (!qla4xxx_eh_wait_on_command(ha, cmd)) { | |
2572 | DEBUG2(printk("scsi%ld:%d:%d: Abort handler timed out\n", | |
2573 | ha->host_no, id, lun)); | |
2574 | ret = FAILED; | |
2575 | } | |
2576 | } | |
2577 | ||
c2660df3 | 2578 | ql4_printk(KERN_INFO, ha, |
09a0f719 | 2579 | "scsi%ld:%d:%d: Abort command - %s\n", |
25985edc | 2580 | ha->host_no, id, lun, (ret == SUCCESS) ? "succeeded" : "failed"); |
09a0f719 VC |
2581 | |
2582 | return ret; | |
2583 | } | |
2584 | ||
afaf5a2d DS |
2585 | /** |
2586 | * qla4xxx_eh_device_reset - callback for target reset. | |
2587 | * @cmd: Pointer to Linux's SCSI command structure | |
2588 | * | |
2589 | * This routine is called by the Linux OS to reset all luns on the | |
2590 | * specified target. | |
2591 | **/ | |
2592 | static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd) | |
2593 | { | |
2594 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); | |
2595 | struct ddb_entry *ddb_entry = cmd->device->hostdata; | |
afaf5a2d DS |
2596 | int ret = FAILED, stat; |
2597 | ||
612f7348 | 2598 | if (!ddb_entry) |
afaf5a2d DS |
2599 | return ret; |
2600 | ||
c01be6dc MC |
2601 | ret = iscsi_block_scsi_eh(cmd); |
2602 | if (ret) | |
2603 | return ret; | |
2604 | ret = FAILED; | |
2605 | ||
c2660df3 | 2606 | ql4_printk(KERN_INFO, ha, |
afaf5a2d DS |
2607 | "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no, |
2608 | cmd->device->channel, cmd->device->id, cmd->device->lun); | |
2609 | ||
2610 | DEBUG2(printk(KERN_INFO | |
2611 | "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x," | |
2612 | "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no, | |
242f9dcb | 2613 | cmd, jiffies, cmd->request->timeout / HZ, |
afaf5a2d DS |
2614 | ha->dpc_flags, cmd->result, cmd->allowed)); |
2615 | ||
2616 | /* FIXME: wait for hba to go online */ | |
2617 | stat = qla4xxx_reset_lun(ha, ddb_entry, cmd->device->lun); | |
2618 | if (stat != QLA_SUCCESS) { | |
c2660df3 | 2619 | ql4_printk(KERN_INFO, ha, "DEVICE RESET FAILED. %d\n", stat); |
afaf5a2d DS |
2620 | goto eh_dev_reset_done; |
2621 | } | |
2622 | ||
ce545039 MC |
2623 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
2624 | cmd->device)) { | |
c2660df3 | 2625 | ql4_printk(KERN_INFO, ha, |
ce545039 MC |
2626 | "DEVICE RESET FAILED - waiting for " |
2627 | "commands.\n"); | |
2628 | goto eh_dev_reset_done; | |
afaf5a2d DS |
2629 | } |
2630 | ||
9d562913 DS |
2631 | /* Send marker. */ |
2632 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, | |
2633 | MM_LUN_RESET) != QLA_SUCCESS) | |
2634 | goto eh_dev_reset_done; | |
2635 | ||
c2660df3 | 2636 | ql4_printk(KERN_INFO, ha, |
afaf5a2d DS |
2637 | "scsi(%ld:%d:%d:%d): DEVICE RESET SUCCEEDED.\n", |
2638 | ha->host_no, cmd->device->channel, cmd->device->id, | |
2639 | cmd->device->lun); | |
2640 | ||
2641 | ret = SUCCESS; | |
2642 | ||
2643 | eh_dev_reset_done: | |
2644 | ||
2645 | return ret; | |
2646 | } | |
2647 | ||
ce545039 MC |
2648 | /** |
2649 | * qla4xxx_eh_target_reset - callback for target reset. | |
2650 | * @cmd: Pointer to Linux's SCSI command structure | |
2651 | * | |
2652 | * This routine is called by the Linux OS to reset the target. | |
2653 | **/ | |
2654 | static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd) | |
2655 | { | |
2656 | struct scsi_qla_host *ha = to_qla_host(cmd->device->host); | |
2657 | struct ddb_entry *ddb_entry = cmd->device->hostdata; | |
c01be6dc | 2658 | int stat, ret; |
ce545039 MC |
2659 | |
2660 | if (!ddb_entry) | |
2661 | return FAILED; | |
2662 | ||
c01be6dc MC |
2663 | ret = iscsi_block_scsi_eh(cmd); |
2664 | if (ret) | |
2665 | return ret; | |
2666 | ||
ce545039 MC |
2667 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
2668 | "WARM TARGET RESET ISSUED.\n"); | |
2669 | ||
2670 | DEBUG2(printk(KERN_INFO | |
2671 | "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, " | |
2672 | "to=%x,dpc_flags=%lx, status=%x allowed=%d\n", | |
242f9dcb | 2673 | ha->host_no, cmd, jiffies, cmd->request->timeout / HZ, |
ce545039 MC |
2674 | ha->dpc_flags, cmd->result, cmd->allowed)); |
2675 | ||
2676 | stat = qla4xxx_reset_target(ha, ddb_entry); | |
2677 | if (stat != QLA_SUCCESS) { | |
2678 | starget_printk(KERN_INFO, scsi_target(cmd->device), | |
2679 | "WARM TARGET RESET FAILED.\n"); | |
2680 | return FAILED; | |
2681 | } | |
2682 | ||
ce545039 MC |
2683 | if (qla4xxx_eh_wait_for_commands(ha, scsi_target(cmd->device), |
2684 | NULL)) { | |
2685 | starget_printk(KERN_INFO, scsi_target(cmd->device), | |
2686 | "WARM TARGET DEVICE RESET FAILED - " | |
2687 | "waiting for commands.\n"); | |
2688 | return FAILED; | |
2689 | } | |
2690 | ||
9d562913 DS |
2691 | /* Send marker. */ |
2692 | if (qla4xxx_send_marker_iocb(ha, ddb_entry, cmd->device->lun, | |
2693 | MM_TGT_WARM_RESET) != QLA_SUCCESS) { | |
2694 | starget_printk(KERN_INFO, scsi_target(cmd->device), | |
2695 | "WARM TARGET DEVICE RESET FAILED - " | |
2696 | "marker iocb failed.\n"); | |
2697 | return FAILED; | |
2698 | } | |
2699 | ||
ce545039 MC |
2700 | starget_printk(KERN_INFO, scsi_target(cmd->device), |
2701 | "WARM TARGET RESET SUCCEEDED.\n"); | |
2702 | return SUCCESS; | |
2703 | } | |
2704 | ||
afaf5a2d DS |
2705 | /** |
2706 | * qla4xxx_eh_host_reset - kernel callback | |
2707 | * @cmd: Pointer to Linux's SCSI command structure | |
2708 | * | |
2709 | * This routine is invoked by the Linux kernel to perform fatal error | |
2710 | * recovery on the specified adapter. | |
2711 | **/ | |
2712 | static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd) | |
2713 | { | |
2714 | int return_status = FAILED; | |
2715 | struct scsi_qla_host *ha; | |
2716 | ||
2717 | ha = (struct scsi_qla_host *) cmd->device->host->hostdata; | |
2718 | ||
f4f5df23 VC |
2719 | if (ql4xdontresethba) { |
2720 | DEBUG2(printk("scsi%ld: %s: Don't Reset HBA\n", | |
2721 | ha->host_no, __func__)); | |
2722 | return FAILED; | |
2723 | } | |
2724 | ||
c2660df3 | 2725 | ql4_printk(KERN_INFO, ha, |
dca05c4c | 2726 | "scsi(%ld:%d:%d:%d): HOST RESET ISSUED.\n", ha->host_no, |
afaf5a2d DS |
2727 | cmd->device->channel, cmd->device->id, cmd->device->lun); |
2728 | ||
2729 | if (qla4xxx_wait_for_hba_online(ha) != QLA_SUCCESS) { | |
2730 | DEBUG2(printk("scsi%ld:%d: %s: Unable to reset host. Adapter " | |
2731 | "DEAD.\n", ha->host_no, cmd->device->channel, | |
2732 | __func__)); | |
2733 | ||
2734 | return FAILED; | |
2735 | } | |
2736 | ||
f4f5df23 VC |
2737 | if (!test_bit(DPC_RESET_HA, &ha->dpc_flags)) { |
2738 | if (is_qla8022(ha)) | |
2739 | set_bit(DPC_RESET_HA_FW_CONTEXT, &ha->dpc_flags); | |
2740 | else | |
2741 | set_bit(DPC_RESET_HA, &ha->dpc_flags); | |
2742 | } | |
50a29aec | 2743 | |
f4f5df23 | 2744 | if (qla4xxx_recover_adapter(ha) == QLA_SUCCESS) |
afaf5a2d | 2745 | return_status = SUCCESS; |
afaf5a2d | 2746 | |
c2660df3 | 2747 | ql4_printk(KERN_INFO, ha, "HOST RESET %s.\n", |
25985edc | 2748 | return_status == FAILED ? "FAILED" : "SUCCEEDED"); |
afaf5a2d DS |
2749 | |
2750 | return return_status; | |
2751 | } | |
2752 | ||
2232be0d LC |
2753 | /* PCI AER driver recovers from all correctable errors w/o |
2754 | * driver intervention. For uncorrectable errors PCI AER | |
2755 | * driver calls the following device driver's callbacks | |
2756 | * | |
2757 | * - Fatal Errors - link_reset | |
2758 | * - Non-Fatal Errors - driver's pci_error_detected() which | |
2759 | * returns CAN_RECOVER, NEED_RESET or DISCONNECT. | |
2760 | * | |
2761 | * PCI AER driver calls | |
2762 | * CAN_RECOVER - driver's pci_mmio_enabled(), mmio_enabled | |
2763 | * returns RECOVERED or NEED_RESET if fw_hung | |
2764 | * NEED_RESET - driver's slot_reset() | |
2765 | * DISCONNECT - device is dead & cannot recover | |
2766 | * RECOVERED - driver's pci_resume() | |
2767 | */ | |
2768 | static pci_ers_result_t | |
2769 | qla4xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
2770 | { | |
2771 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); | |
2772 | ||
2773 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: error detected:state %x\n", | |
2774 | ha->host_no, __func__, state); | |
2775 | ||
2776 | if (!is_aer_supported(ha)) | |
2777 | return PCI_ERS_RESULT_NONE; | |
2778 | ||
2779 | switch (state) { | |
2780 | case pci_channel_io_normal: | |
2781 | clear_bit(AF_EEH_BUSY, &ha->flags); | |
2782 | return PCI_ERS_RESULT_CAN_RECOVER; | |
2783 | case pci_channel_io_frozen: | |
2784 | set_bit(AF_EEH_BUSY, &ha->flags); | |
2785 | qla4xxx_mailbox_premature_completion(ha); | |
2786 | qla4xxx_free_irqs(ha); | |
2787 | pci_disable_device(pdev); | |
7b3595df VC |
2788 | /* Return back all IOs */ |
2789 | qla4xxx_abort_active_cmds(ha, DID_RESET << 16); | |
2232be0d LC |
2790 | return PCI_ERS_RESULT_NEED_RESET; |
2791 | case pci_channel_io_perm_failure: | |
2792 | set_bit(AF_EEH_BUSY, &ha->flags); | |
2793 | set_bit(AF_PCI_CHANNEL_IO_PERM_FAILURE, &ha->flags); | |
2794 | qla4xxx_abort_active_cmds(ha, DID_NO_CONNECT << 16); | |
2795 | return PCI_ERS_RESULT_DISCONNECT; | |
2796 | } | |
2797 | return PCI_ERS_RESULT_NEED_RESET; | |
2798 | } | |
2799 | ||
2800 | /** | |
2801 | * qla4xxx_pci_mmio_enabled() gets called if | |
2802 | * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER | |
2803 | * and read/write to the device still works. | |
2804 | **/ | |
2805 | static pci_ers_result_t | |
2806 | qla4xxx_pci_mmio_enabled(struct pci_dev *pdev) | |
2807 | { | |
2808 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); | |
2809 | ||
2810 | if (!is_aer_supported(ha)) | |
2811 | return PCI_ERS_RESULT_NONE; | |
2812 | ||
7b3595df | 2813 | return PCI_ERS_RESULT_RECOVERED; |
2232be0d LC |
2814 | } |
2815 | ||
7b3595df | 2816 | static uint32_t qla4_8xxx_error_recovery(struct scsi_qla_host *ha) |
2232be0d LC |
2817 | { |
2818 | uint32_t rval = QLA_ERROR; | |
7b3595df | 2819 | uint32_t ret = 0; |
2232be0d LC |
2820 | int fn; |
2821 | struct pci_dev *other_pdev = NULL; | |
2822 | ||
2823 | ql4_printk(KERN_WARNING, ha, "scsi%ld: In %s\n", ha->host_no, __func__); | |
2824 | ||
2825 | set_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); | |
2826 | ||
2827 | if (test_bit(AF_ONLINE, &ha->flags)) { | |
2828 | clear_bit(AF_ONLINE, &ha->flags); | |
2829 | qla4xxx_mark_all_devices_missing(ha); | |
2830 | qla4xxx_process_aen(ha, FLUSH_DDB_CHANGED_AENS); | |
2232be0d LC |
2831 | } |
2832 | ||
2833 | fn = PCI_FUNC(ha->pdev->devfn); | |
2834 | while (fn > 0) { | |
2835 | fn--; | |
2836 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Finding PCI device at " | |
2837 | "func %x\n", ha->host_no, __func__, fn); | |
2838 | /* Get the pci device given the domain, bus, | |
2839 | * slot/function number */ | |
2840 | other_pdev = | |
2841 | pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus), | |
2842 | ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn), | |
2843 | fn)); | |
2844 | ||
2845 | if (!other_pdev) | |
2846 | continue; | |
2847 | ||
2848 | if (atomic_read(&other_pdev->enable_cnt)) { | |
2849 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: Found PCI " | |
2850 | "func in enabled state%x\n", ha->host_no, | |
2851 | __func__, fn); | |
2852 | pci_dev_put(other_pdev); | |
2853 | break; | |
2854 | } | |
2855 | pci_dev_put(other_pdev); | |
2856 | } | |
2857 | ||
2858 | /* The first function on the card, the reset owner will | |
2859 | * start & initialize the firmware. The other functions | |
2860 | * on the card will reset the firmware context | |
2861 | */ | |
2862 | if (!fn) { | |
2863 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn being reset " | |
2864 | "0x%x is the owner\n", ha->host_no, __func__, | |
2865 | ha->pdev->devfn); | |
2866 | ||
2867 | qla4_8xxx_idc_lock(ha); | |
2868 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
2869 | QLA82XX_DEV_COLD); | |
2870 | ||
2871 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION, | |
2872 | QLA82XX_IDC_VERSION); | |
2873 | ||
2874 | qla4_8xxx_idc_unlock(ha); | |
2875 | clear_bit(AF_FW_RECOVERY, &ha->flags); | |
2876 | rval = qla4xxx_initialize_adapter(ha, PRESERVE_DDB_LIST); | |
2877 | qla4_8xxx_idc_lock(ha); | |
2878 | ||
2879 | if (rval != QLA_SUCCESS) { | |
2880 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " | |
2881 | "FAILED\n", ha->host_no, __func__); | |
2882 | qla4_8xxx_clear_drv_active(ha); | |
2883 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
2884 | QLA82XX_DEV_FAILED); | |
2885 | } else { | |
2886 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: HW State: " | |
2887 | "READY\n", ha->host_no, __func__); | |
2888 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DEV_STATE, | |
2889 | QLA82XX_DEV_READY); | |
2890 | /* Clear driver state register */ | |
2891 | qla4_8xxx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0); | |
2892 | qla4_8xxx_set_drv_active(ha); | |
7b3595df VC |
2893 | ret = qla4xxx_request_irqs(ha); |
2894 | if (ret) { | |
2895 | ql4_printk(KERN_WARNING, ha, "Failed to " | |
2896 | "reserve interrupt %d already in use.\n", | |
2897 | ha->pdev->irq); | |
2898 | rval = QLA_ERROR; | |
2899 | } else { | |
2900 | ha->isp_ops->enable_intrs(ha); | |
2901 | rval = QLA_SUCCESS; | |
2902 | } | |
2232be0d LC |
2903 | } |
2904 | qla4_8xxx_idc_unlock(ha); | |
2905 | } else { | |
2906 | ql4_printk(KERN_INFO, ha, "scsi%ld: %s: devfn 0x%x is not " | |
2907 | "the reset owner\n", ha->host_no, __func__, | |
2908 | ha->pdev->devfn); | |
2909 | if ((qla4_8xxx_rd_32(ha, QLA82XX_CRB_DEV_STATE) == | |
2910 | QLA82XX_DEV_READY)) { | |
2911 | clear_bit(AF_FW_RECOVERY, &ha->flags); | |
2912 | rval = qla4xxx_initialize_adapter(ha, | |
2913 | PRESERVE_DDB_LIST); | |
7b3595df VC |
2914 | if (rval == QLA_SUCCESS) { |
2915 | ret = qla4xxx_request_irqs(ha); | |
2916 | if (ret) { | |
2917 | ql4_printk(KERN_WARNING, ha, "Failed to" | |
2918 | " reserve interrupt %d already in" | |
2919 | " use.\n", ha->pdev->irq); | |
2920 | rval = QLA_ERROR; | |
2921 | } else { | |
2922 | ha->isp_ops->enable_intrs(ha); | |
2923 | rval = QLA_SUCCESS; | |
2924 | } | |
2925 | } | |
2232be0d LC |
2926 | qla4_8xxx_idc_lock(ha); |
2927 | qla4_8xxx_set_drv_active(ha); | |
2928 | qla4_8xxx_idc_unlock(ha); | |
2929 | } | |
2930 | } | |
2931 | clear_bit(DPC_RESET_ACTIVE, &ha->dpc_flags); | |
2932 | return rval; | |
2933 | } | |
2934 | ||
2935 | static pci_ers_result_t | |
2936 | qla4xxx_pci_slot_reset(struct pci_dev *pdev) | |
2937 | { | |
2938 | pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT; | |
2939 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); | |
2940 | int rc; | |
2941 | ||
2942 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: slot_reset\n", | |
2943 | ha->host_no, __func__); | |
2944 | ||
2945 | if (!is_aer_supported(ha)) | |
2946 | return PCI_ERS_RESULT_NONE; | |
2947 | ||
2948 | /* Restore the saved state of PCIe device - | |
2949 | * BAR registers, PCI Config space, PCIX, MSI, | |
2950 | * IOV states | |
2951 | */ | |
2952 | pci_restore_state(pdev); | |
2953 | ||
2954 | /* pci_restore_state() clears the saved_state flag of the device | |
2955 | * save restored state which resets saved_state flag | |
2956 | */ | |
2957 | pci_save_state(pdev); | |
2958 | ||
2959 | /* Initialize device or resume if in suspended state */ | |
2960 | rc = pci_enable_device(pdev); | |
2961 | if (rc) { | |
25985edc | 2962 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Can't re-enable " |
2232be0d LC |
2963 | "device after reset\n", ha->host_no, __func__); |
2964 | goto exit_slot_reset; | |
2965 | } | |
2966 | ||
7b3595df | 2967 | ha->isp_ops->disable_intrs(ha); |
2232be0d LC |
2968 | |
2969 | if (is_qla8022(ha)) { | |
2970 | if (qla4_8xxx_error_recovery(ha) == QLA_SUCCESS) { | |
2971 | ret = PCI_ERS_RESULT_RECOVERED; | |
2972 | goto exit_slot_reset; | |
2973 | } else | |
2974 | goto exit_slot_reset; | |
2975 | } | |
2976 | ||
2977 | exit_slot_reset: | |
2978 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: Return=%x\n" | |
2979 | "device after reset\n", ha->host_no, __func__, ret); | |
2980 | return ret; | |
2981 | } | |
2982 | ||
2983 | static void | |
2984 | qla4xxx_pci_resume(struct pci_dev *pdev) | |
2985 | { | |
2986 | struct scsi_qla_host *ha = pci_get_drvdata(pdev); | |
2987 | int ret; | |
2988 | ||
2989 | ql4_printk(KERN_WARNING, ha, "scsi%ld: %s: pci_resume\n", | |
2990 | ha->host_no, __func__); | |
2991 | ||
2992 | ret = qla4xxx_wait_for_hba_online(ha); | |
2993 | if (ret != QLA_SUCCESS) { | |
2994 | ql4_printk(KERN_ERR, ha, "scsi%ld: %s: the device failed to " | |
2995 | "resume I/O from slot/link_reset\n", ha->host_no, | |
2996 | __func__); | |
2997 | } | |
2998 | ||
2999 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
3000 | clear_bit(AF_EEH_BUSY, &ha->flags); | |
3001 | } | |
3002 | ||
3003 | static struct pci_error_handlers qla4xxx_err_handler = { | |
3004 | .error_detected = qla4xxx_pci_error_detected, | |
3005 | .mmio_enabled = qla4xxx_pci_mmio_enabled, | |
3006 | .slot_reset = qla4xxx_pci_slot_reset, | |
3007 | .resume = qla4xxx_pci_resume, | |
3008 | }; | |
3009 | ||
afaf5a2d DS |
3010 | static struct pci_device_id qla4xxx_pci_tbl[] = { |
3011 | { | |
3012 | .vendor = PCI_VENDOR_ID_QLOGIC, | |
3013 | .device = PCI_DEVICE_ID_QLOGIC_ISP4010, | |
3014 | .subvendor = PCI_ANY_ID, | |
3015 | .subdevice = PCI_ANY_ID, | |
3016 | }, | |
3017 | { | |
3018 | .vendor = PCI_VENDOR_ID_QLOGIC, | |
3019 | .device = PCI_DEVICE_ID_QLOGIC_ISP4022, | |
3020 | .subvendor = PCI_ANY_ID, | |
3021 | .subdevice = PCI_ANY_ID, | |
3022 | }, | |
d915058f DS |
3023 | { |
3024 | .vendor = PCI_VENDOR_ID_QLOGIC, | |
3025 | .device = PCI_DEVICE_ID_QLOGIC_ISP4032, | |
3026 | .subvendor = PCI_ANY_ID, | |
3027 | .subdevice = PCI_ANY_ID, | |
3028 | }, | |
f4f5df23 VC |
3029 | { |
3030 | .vendor = PCI_VENDOR_ID_QLOGIC, | |
3031 | .device = PCI_DEVICE_ID_QLOGIC_ISP8022, | |
3032 | .subvendor = PCI_ANY_ID, | |
3033 | .subdevice = PCI_ANY_ID, | |
3034 | }, | |
afaf5a2d DS |
3035 | {0, 0}, |
3036 | }; | |
3037 | MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); | |
3038 | ||
47975477 | 3039 | static struct pci_driver qla4xxx_pci_driver = { |
afaf5a2d DS |
3040 | .name = DRIVER_NAME, |
3041 | .id_table = qla4xxx_pci_tbl, | |
3042 | .probe = qla4xxx_probe_adapter, | |
3043 | .remove = qla4xxx_remove_adapter, | |
2232be0d | 3044 | .err_handler = &qla4xxx_err_handler, |
afaf5a2d DS |
3045 | }; |
3046 | ||
3047 | static int __init qla4xxx_module_init(void) | |
3048 | { | |
3049 | int ret; | |
3050 | ||
3051 | /* Allocate cache for SRBs. */ | |
3052 | srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, | |
20c2df83 | 3053 | SLAB_HWCACHE_ALIGN, NULL); |
afaf5a2d DS |
3054 | if (srb_cachep == NULL) { |
3055 | printk(KERN_ERR | |
3056 | "%s: Unable to allocate SRB cache..." | |
3057 | "Failing load!\n", DRIVER_NAME); | |
3058 | ret = -ENOMEM; | |
3059 | goto no_srp_cache; | |
3060 | } | |
3061 | ||
3062 | /* Derive version string. */ | |
3063 | strcpy(qla4xxx_version_str, QLA4XXX_DRIVER_VERSION); | |
11010fec | 3064 | if (ql4xextended_error_logging) |
afaf5a2d DS |
3065 | strcat(qla4xxx_version_str, "-debug"); |
3066 | ||
3067 | qla4xxx_scsi_transport = | |
3068 | iscsi_register_transport(&qla4xxx_iscsi_transport); | |
3069 | if (!qla4xxx_scsi_transport){ | |
3070 | ret = -ENODEV; | |
3071 | goto release_srb_cache; | |
3072 | } | |
3073 | ||
afaf5a2d DS |
3074 | ret = pci_register_driver(&qla4xxx_pci_driver); |
3075 | if (ret) | |
3076 | goto unregister_transport; | |
3077 | ||
3078 | printk(KERN_INFO "QLogic iSCSI HBA Driver\n"); | |
3079 | return 0; | |
5ae16db3 | 3080 | |
afaf5a2d DS |
3081 | unregister_transport: |
3082 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); | |
3083 | release_srb_cache: | |
3084 | kmem_cache_destroy(srb_cachep); | |
3085 | no_srp_cache: | |
3086 | return ret; | |
3087 | } | |
3088 | ||
3089 | static void __exit qla4xxx_module_exit(void) | |
3090 | { | |
3091 | pci_unregister_driver(&qla4xxx_pci_driver); | |
3092 | iscsi_unregister_transport(&qla4xxx_iscsi_transport); | |
3093 | kmem_cache_destroy(srb_cachep); | |
3094 | } | |
3095 | ||
3096 | module_init(qla4xxx_module_init); | |
3097 | module_exit(qla4xxx_module_exit); | |
3098 | ||
3099 | MODULE_AUTHOR("QLogic Corporation"); | |
3100 | MODULE_DESCRIPTION("QLogic iSCSI HBA Driver"); | |
3101 | MODULE_LICENSE("GPL"); | |
3102 | MODULE_VERSION(QLA4XXX_DRIVER_VERSION); |