[SCSI] zfcp: add additional fc_host attributes
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / s390 / scsi / zfcp_erp.c
blob023f4e558ae426aa2fd9bc349aaecca53686715d
1 /*
2 *
3 * linux/drivers/s390/scsi/zfcp_erp.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
34 #define ZFCP_ERP_REVISION "$Revision: 1.86 $"
36 #include "zfcp_ext.h"
38 static int zfcp_erp_adisc(struct zfcp_port *);
39 static void zfcp_erp_adisc_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
67 struct zfcp_port *,
68 struct zfcp_unit *, int);
69 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
71 struct zfcp_port *,
72 struct zfcp_unit *, int);
73 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
76 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
86 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
87 struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
90 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
93 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
94 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
97 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
98 struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
101 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
104 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
105 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
106 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
108 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
109 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
110 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
111 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
113 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
114 struct zfcp_port *, struct zfcp_unit *);
115 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
116 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
117 struct zfcp_port *, struct zfcp_unit *,
118 int);
120 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
121 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
124 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
126 static void zfcp_erp_memwait_handler(unsigned long);
127 static void zfcp_erp_timeout_handler(unsigned long);
128 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
131 * zfcp_fsf_request_timeout_handler - called if a request timed out
132 * @data: pointer to adapter for handler function
134 * This function needs to be called if requests (ELS, Generic Service,
135 * or SCSI commands) exceed a certain time limit. The assumption is
136 * that after the time limit the adapter get stuck. So we trigger a reopen of
137 * the adapter. This should not be used for error recovery, SCSI abort
138 * commands and SCSI requests from SCSI mid-layer.
140 void
141 zfcp_fsf_request_timeout_handler(unsigned long data)
143 struct zfcp_adapter *adapter;
145 adapter = (struct zfcp_adapter *) data;
147 zfcp_erp_adapter_reopen(adapter, 0);
151 * function: zfcp_fsf_scsi_er_timeout_handler
153 * purpose: This function needs to be called whenever a SCSI error recovery
154 * action (abort/reset) does not return.
155 * Re-opening the adapter means that the command can be returned
156 * by zfcp (it is guarranteed that it does not return via the
157 * adapter anymore). The buffer can then be used again.
159 * returns: sod all
161 void
162 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
164 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
166 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
167 "Restarting all operations on the adapter %s\n",
168 zfcp_get_busid_by_adapter(adapter));
169 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
170 zfcp_erp_adapter_reopen(adapter, 0);
172 return;
176 * function:
178 * purpose: called if an adapter failed,
179 * initiates adapter recovery which is done
180 * asynchronously
182 * returns: 0 - initiated action succesfully
183 * <0 - failed to initiate action
186 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
188 int retval;
190 debug_text_event(adapter->erp_dbf, 5, "a_ro");
191 ZFCP_LOG_DEBUG("reopen adapter %s\n",
192 zfcp_get_busid_by_adapter(adapter));
194 zfcp_erp_adapter_block(adapter, clear_mask);
196 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
197 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
198 zfcp_get_busid_by_adapter(adapter));
199 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
200 /* ensure propagation of failed status to new devices */
201 zfcp_erp_adapter_failed(adapter);
202 retval = -EIO;
203 goto out;
205 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
206 adapter, NULL, NULL);
208 out:
209 return retval;
213 * function:
215 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
216 * used to ensure the correct locking
218 * returns: 0 - initiated action succesfully
219 * <0 - failed to initiate action
222 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
224 int retval;
225 unsigned long flags;
227 read_lock_irqsave(&zfcp_data.config_lock, flags);
228 write_lock(&adapter->erp_lock);
229 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
230 write_unlock(&adapter->erp_lock);
231 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
233 return retval;
237 * function:
239 * purpose:
241 * returns:
244 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
246 int retval;
248 retval = zfcp_erp_adapter_reopen(adapter,
249 ZFCP_STATUS_COMMON_RUNNING |
250 ZFCP_STATUS_COMMON_ERP_FAILED |
251 clear_mask);
253 return retval;
257 * function:
259 * purpose:
261 * returns:
264 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
266 int retval;
268 retval = zfcp_erp_port_reopen(port,
269 ZFCP_STATUS_COMMON_RUNNING |
270 ZFCP_STATUS_COMMON_ERP_FAILED |
271 clear_mask);
273 return retval;
277 * function:
279 * purpose:
281 * returns:
284 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
286 int retval;
288 retval = zfcp_erp_unit_reopen(unit,
289 ZFCP_STATUS_COMMON_RUNNING |
290 ZFCP_STATUS_COMMON_ERP_FAILED |
291 clear_mask);
293 return retval;
298 * zfcp_erp_adisc - send ADISC ELS command
299 * @port: port structure
302 zfcp_erp_adisc(struct zfcp_port *port)
304 struct zfcp_adapter *adapter = port->adapter;
305 struct zfcp_send_els *send_els;
306 struct zfcp_ls_adisc *adisc;
307 void *address = NULL;
308 int retval = 0;
309 struct timer_list *timer;
311 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
312 if (send_els == NULL)
313 goto nomem;
314 memset(send_els, 0, sizeof(*send_els));
316 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
317 if (send_els->req == NULL)
318 goto nomem;
319 memset(send_els->req, 0, sizeof(*send_els->req));
321 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
322 if (send_els->resp == NULL)
323 goto nomem;
324 memset(send_els->resp, 0, sizeof(*send_els->resp));
326 address = (void *) get_zeroed_page(GFP_ATOMIC);
327 if (address == NULL)
328 goto nomem;
330 zfcp_address_to_sg(address, send_els->req);
331 address += PAGE_SIZE >> 1;
332 zfcp_address_to_sg(address, send_els->resp);
333 send_els->req_count = send_els->resp_count = 1;
335 send_els->adapter = adapter;
336 send_els->port = port;
337 send_els->d_id = port->d_id;
338 send_els->handler = zfcp_erp_adisc_handler;
339 send_els->handler_data = (unsigned long) send_els;
341 adisc = zfcp_sg_to_address(send_els->req);
342 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
344 send_els->req->length = sizeof(struct zfcp_ls_adisc);
345 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
347 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
348 without FC-AL-2 capability, so we don't set it */
349 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
350 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
351 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
352 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
353 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
354 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
355 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
356 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
357 adisc->nport_id);
359 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
360 if (!timer)
361 goto nomem;
363 init_timer(timer);
364 timer->function = zfcp_fsf_request_timeout_handler;
365 timer->data = (unsigned long) adapter;
366 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
367 send_els->timer = timer;
369 retval = zfcp_fsf_send_els(send_els);
370 if (retval != 0) {
371 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
372 "0x%08x on adapter %s\n", send_els->d_id,
373 zfcp_get_busid_by_adapter(adapter));
374 del_timer(send_els->timer);
375 goto freemem;
378 goto out;
380 nomem:
381 retval = -ENOMEM;
382 freemem:
383 if (address != NULL)
384 __free_pages(send_els->req->page, 0);
385 if (send_els != NULL) {
386 kfree(send_els->timer);
387 kfree(send_els->req);
388 kfree(send_els->resp);
389 kfree(send_els);
391 out:
392 return retval;
397 * zfcp_erp_adisc_handler - handler for ADISC ELS command
398 * @data: pointer to struct zfcp_send_els
400 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
402 void
403 zfcp_erp_adisc_handler(unsigned long data)
405 struct zfcp_send_els *send_els;
406 struct zfcp_port *port;
407 struct zfcp_adapter *adapter;
408 u32 d_id;
409 struct zfcp_ls_adisc_acc *adisc;
411 send_els = (struct zfcp_send_els *) data;
413 del_timer(send_els->timer);
415 adapter = send_els->adapter;
416 port = send_els->port;
417 d_id = send_els->d_id;
419 /* request rejected or timed out */
420 if (send_els->status != 0) {
421 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
422 "force physical port reopen "
423 "(adapter %s, port d_id=0x%08x)\n",
424 zfcp_get_busid_by_adapter(adapter), d_id);
425 debug_text_event(adapter->erp_dbf, 3, "forcreop");
426 if (zfcp_erp_port_forced_reopen(port, 0))
427 ZFCP_LOG_NORMAL("failed reopen of port "
428 "(adapter %s, wwpn=0x%016Lx)\n",
429 zfcp_get_busid_by_port(port),
430 port->wwpn);
431 goto out;
434 adisc = zfcp_sg_to_address(send_els->resp);
436 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
437 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
438 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
439 d_id, fc_host_port_id(adapter->scsi_host),
440 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
441 adisc->hard_nport_id, adisc->nport_id);
443 /* set wwnn for port */
444 if (port->wwnn == 0)
445 port->wwnn = adisc->wwnn;
447 if (port->wwpn != adisc->wwpn) {
448 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
449 "port (adapter %s, wwpn=0x%016Lx, "
450 "adisc_resp_wwpn=0x%016Lx)\n",
451 zfcp_get_busid_by_port(port),
452 port->wwpn, (wwn_t) adisc->wwpn);
453 if (zfcp_erp_port_reopen(port, 0))
454 ZFCP_LOG_NORMAL("failed reopen of port "
455 "(adapter %s, wwpn=0x%016Lx)\n",
456 zfcp_get_busid_by_port(port),
457 port->wwpn);
460 out:
461 zfcp_port_put(port);
462 __free_pages(send_els->req->page, 0);
463 kfree(send_els->timer);
464 kfree(send_els->req);
465 kfree(send_els->resp);
466 kfree(send_els);
471 * zfcp_test_link - lightweight link test procedure
472 * @port: port to be tested
474 * Test status of a link to a remote port using the ELS command ADISC.
477 zfcp_test_link(struct zfcp_port *port)
479 int retval;
481 zfcp_port_get(port);
482 retval = zfcp_erp_adisc(port);
483 if (retval != 0) {
484 zfcp_port_put(port);
485 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
486 "on adapter %s\n ", port->wwpn,
487 zfcp_get_busid_by_port(port));
488 retval = zfcp_erp_port_forced_reopen(port, 0);
489 if (retval != 0) {
490 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
491 "on adapter %s failed\n", port->wwpn,
492 zfcp_get_busid_by_port(port));
493 retval = -EPERM;
497 return retval;
502 * function:
504 * purpose: called if a port failed to be opened normally
505 * initiates Forced Reopen recovery which is done
506 * asynchronously
508 * returns: 0 - initiated action succesfully
509 * <0 - failed to initiate action
511 static int
512 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
514 int retval;
515 struct zfcp_adapter *adapter = port->adapter;
517 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
518 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
520 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
521 port->wwpn, zfcp_get_busid_by_port(port));
523 zfcp_erp_port_block(port, clear_mask);
525 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
526 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
527 "on adapter %s\n", port->wwpn,
528 zfcp_get_busid_by_port(port));
529 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
530 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
531 retval = -EIO;
532 goto out;
535 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
536 port->adapter, port, NULL);
538 out:
539 return retval;
543 * function:
545 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
546 * used to ensure the correct locking
548 * returns: 0 - initiated action succesfully
549 * <0 - failed to initiate action
552 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
554 int retval;
555 unsigned long flags;
556 struct zfcp_adapter *adapter;
558 adapter = port->adapter;
559 read_lock_irqsave(&zfcp_data.config_lock, flags);
560 write_lock(&adapter->erp_lock);
561 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
562 write_unlock(&adapter->erp_lock);
563 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
565 return retval;
569 * function:
571 * purpose: called if a port is to be opened
572 * initiates Reopen recovery which is done
573 * asynchronously
575 * returns: 0 - initiated action succesfully
576 * <0 - failed to initiate action
578 static int
579 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
581 int retval;
582 struct zfcp_adapter *adapter = port->adapter;
584 debug_text_event(adapter->erp_dbf, 5, "p_ro");
585 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
587 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
588 port->wwpn, zfcp_get_busid_by_port(port));
590 zfcp_erp_port_block(port, clear_mask);
592 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
593 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
594 "on adapter %s\n", port->wwpn,
595 zfcp_get_busid_by_port(port));
596 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
597 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
598 /* ensure propagation of failed status to new devices */
599 zfcp_erp_port_failed(port);
600 retval = -EIO;
601 goto out;
604 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
605 port->adapter, port, NULL);
607 out:
608 return retval;
612 * zfcp_erp_port_reopen - initiate reopen of a remote port
613 * @port: port to be reopened
614 * @clear_mask: specifies flags in port status to be cleared
615 * Return: 0 on success, < 0 on error
617 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
618 * correct locking. An error recovery task is initiated to do the reopen.
619 * To wait for the completion of the reopen zfcp_erp_wait should be used.
622 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
624 int retval;
625 unsigned long flags;
626 struct zfcp_adapter *adapter = port->adapter;
628 read_lock_irqsave(&zfcp_data.config_lock, flags);
629 write_lock(&adapter->erp_lock);
630 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
631 write_unlock(&adapter->erp_lock);
632 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
634 return retval;
638 * function:
640 * purpose: called if a unit is to be opened
641 * initiates Reopen recovery which is done
642 * asynchronously
644 * returns: 0 - initiated action succesfully
645 * <0 - failed to initiate action
647 static int
648 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
650 int retval;
651 struct zfcp_adapter *adapter = unit->port->adapter;
653 debug_text_event(adapter->erp_dbf, 5, "u_ro");
654 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
655 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
656 "on adapter %s\n", unit->fcp_lun,
657 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
659 zfcp_erp_unit_block(unit, clear_mask);
661 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
662 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
663 "on port 0x%016Lx on adapter %s\n",
664 unit->fcp_lun, unit->port->wwpn,
665 zfcp_get_busid_by_unit(unit));
666 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
667 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
668 sizeof (fcp_lun_t));
669 retval = -EIO;
670 goto out;
673 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
674 unit->port->adapter, unit->port, unit);
675 out:
676 return retval;
680 * zfcp_erp_unit_reopen - initiate reopen of a unit
681 * @unit: unit to be reopened
682 * @clear_mask: specifies flags in unit status to be cleared
683 * Return: 0 on success, < 0 on error
685 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
686 * locking. An error recovery task is initiated to do the reopen.
687 * To wait for the completion of the reopen zfcp_erp_wait should be used.
690 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
692 int retval;
693 unsigned long flags;
694 struct zfcp_adapter *adapter;
695 struct zfcp_port *port;
697 port = unit->port;
698 adapter = port->adapter;
700 read_lock_irqsave(&zfcp_data.config_lock, flags);
701 write_lock(&adapter->erp_lock);
702 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
703 write_unlock(&adapter->erp_lock);
704 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
706 return retval;
710 * function:
712 * purpose: disable I/O,
713 * return any open requests and clean them up,
714 * aim: no pending and incoming I/O
716 * returns:
718 static void
719 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
721 debug_text_event(adapter->erp_dbf, 6, "a_bl");
722 zfcp_erp_modify_adapter_status(adapter,
723 ZFCP_STATUS_COMMON_UNBLOCKED |
724 clear_mask, ZFCP_CLEAR);
728 * function:
730 * purpose: enable I/O
732 * returns:
734 static void
735 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
737 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
738 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
742 * function:
744 * purpose: disable I/O,
745 * return any open requests and clean them up,
746 * aim: no pending and incoming I/O
748 * returns:
750 static void
751 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
753 struct zfcp_adapter *adapter = port->adapter;
755 debug_text_event(adapter->erp_dbf, 6, "p_bl");
756 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
757 zfcp_erp_modify_port_status(port,
758 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
759 ZFCP_CLEAR);
763 * function:
765 * purpose: enable I/O
767 * returns:
769 static void
770 zfcp_erp_port_unblock(struct zfcp_port *port)
772 struct zfcp_adapter *adapter = port->adapter;
774 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
775 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
776 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
780 * function:
782 * purpose: disable I/O,
783 * return any open requests and clean them up,
784 * aim: no pending and incoming I/O
786 * returns:
788 static void
789 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
791 struct zfcp_adapter *adapter = unit->port->adapter;
793 debug_text_event(adapter->erp_dbf, 6, "u_bl");
794 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
795 zfcp_erp_modify_unit_status(unit,
796 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
797 ZFCP_CLEAR);
801 * function:
803 * purpose: enable I/O
805 * returns:
807 static void
808 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
810 struct zfcp_adapter *adapter = unit->port->adapter;
812 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
813 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
814 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
818 * function:
820 * purpose:
822 * returns:
824 static void
825 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
827 struct zfcp_adapter *adapter = erp_action->adapter;
829 debug_text_event(adapter->erp_dbf, 4, "a_ar");
830 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
832 zfcp_erp_action_to_ready(erp_action);
833 up(&adapter->erp_ready_sem);
837 * function:
839 * purpose:
841 * returns: <0 erp_action not found in any list
842 * ZFCP_ERP_ACTION_READY erp_action is in ready list
843 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
845 * locks: erp_lock must be held
847 static int
848 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
850 int retval = -EINVAL;
851 struct list_head *entry;
852 struct zfcp_erp_action *entry_erp_action;
853 struct zfcp_adapter *adapter = erp_action->adapter;
855 /* search in running list */
856 list_for_each(entry, &adapter->erp_running_head) {
857 entry_erp_action =
858 list_entry(entry, struct zfcp_erp_action, list);
859 if (entry_erp_action == erp_action) {
860 retval = ZFCP_ERP_ACTION_RUNNING;
861 goto out;
864 /* search in ready list */
865 list_for_each(entry, &adapter->erp_ready_head) {
866 entry_erp_action =
867 list_entry(entry, struct zfcp_erp_action, list);
868 if (entry_erp_action == erp_action) {
869 retval = ZFCP_ERP_ACTION_READY;
870 goto out;
874 out:
875 return retval;
879 * purpose: checks current status of action (timed out, dismissed, ...)
880 * and does appropriate preparations (dismiss fsf request, ...)
882 * locks: called under erp_lock (disabled interrupts)
884 * returns: 0
886 static int
887 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
889 int retval = 0;
890 struct zfcp_fsf_req *fsf_req = NULL;
891 struct zfcp_adapter *adapter = erp_action->adapter;
893 if (erp_action->fsf_req) {
894 /* take lock to ensure that request is not being deleted meanwhile */
895 spin_lock(&adapter->fsf_req_list_lock);
896 /* check whether fsf req does still exist */
897 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
898 if (fsf_req == erp_action->fsf_req)
899 break;
900 if (fsf_req && (fsf_req->erp_action == erp_action)) {
901 /* fsf_req still exists */
902 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
903 debug_event(adapter->erp_dbf, 3, &fsf_req,
904 sizeof (unsigned long));
905 /* dismiss fsf_req of timed out or dismissed erp_action */
906 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
907 ZFCP_STATUS_ERP_TIMEDOUT)) {
908 debug_text_event(adapter->erp_dbf, 3,
909 "a_ca_disreq");
910 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
912 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
913 ZFCP_LOG_NORMAL("error: erp step timed out "
914 "(action=%d, fsf_req=%p)\n ",
915 erp_action->action,
916 erp_action->fsf_req);
919 * If fsf_req is neither dismissed nor completed
920 * then keep it running asynchronously and don't mess
921 * with the association of erp_action and fsf_req.
923 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
924 ZFCP_STATUS_FSFREQ_DISMISSED)) {
925 /* forget about association between fsf_req
926 and erp_action */
927 fsf_req->erp_action = NULL;
928 erp_action->fsf_req = NULL;
930 } else {
931 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
933 * even if this fsf_req has gone, forget about
934 * association between erp_action and fsf_req
936 erp_action->fsf_req = NULL;
938 spin_unlock(&adapter->fsf_req_list_lock);
939 } else
940 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
942 return retval;
946 * purpose: generic handler for asynchronous events related to erp_action events
947 * (normal completion, time-out, dismissing, retry after
948 * low memory condition)
950 * note: deletion of timer is not required (e.g. in case of a time-out),
951 * but a second try does no harm,
952 * we leave it in here to allow for greater simplification
954 * returns: 0 - there was an action to handle
955 * !0 - otherwise
957 static int
958 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
959 unsigned long set_mask)
961 int retval;
962 struct zfcp_adapter *adapter = erp_action->adapter;
964 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
965 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
966 debug_event(adapter->erp_dbf, 2, &erp_action->action,
967 sizeof (int));
968 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
969 del_timer(&erp_action->timer);
970 erp_action->status |= set_mask;
971 zfcp_erp_action_ready(erp_action);
972 retval = 0;
973 } else {
974 /* action is ready or gone - nothing to do */
975 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
976 debug_event(adapter->erp_dbf, 3, &erp_action->action,
977 sizeof (int));
978 retval = 1;
981 return retval;
985 * purpose: generic handler for asynchronous events related to erp_action
986 * events (normal completion, time-out, dismissing, retry after
987 * low memory condition)
989 * note: deletion of timer is not required (e.g. in case of a time-out),
990 * but a second try does no harm,
991 * we leave it in here to allow for greater simplification
993 * returns: 0 - there was an action to handle
994 * !0 - otherwise
997 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
998 unsigned long set_mask)
1000 struct zfcp_adapter *adapter = erp_action->adapter;
1001 unsigned long flags;
1002 int retval;
1004 write_lock_irqsave(&adapter->erp_lock, flags);
1005 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1006 write_unlock_irqrestore(&adapter->erp_lock, flags);
1008 return retval;
1012 * purpose: is called for erp_action which was slept waiting for
1013 * memory becoming avaliable,
1014 * will trigger that this action will be continued
1016 static void
1017 zfcp_erp_memwait_handler(unsigned long data)
1019 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1020 struct zfcp_adapter *adapter = erp_action->adapter;
1022 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1023 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1025 zfcp_erp_async_handler(erp_action, 0);
1029 * purpose: is called if an asynchronous erp step timed out,
1030 * action gets an appropriate flag and will be processed
1031 * accordingly
1033 static void
1034 zfcp_erp_timeout_handler(unsigned long data)
1036 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1037 struct zfcp_adapter *adapter = erp_action->adapter;
1039 debug_text_event(adapter->erp_dbf, 2, "a_th");
1040 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1042 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1046 * purpose: is called for an erp_action which needs to be ended
1047 * though not being done,
1048 * this is usually required if an higher is generated,
1049 * action gets an appropriate flag and will be processed
1050 * accordingly
1052 * locks: erp_lock held (thus we need to call another handler variant)
1054 static int
1055 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1057 struct zfcp_adapter *adapter = erp_action->adapter;
1059 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1060 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1062 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1064 return 0;
1068 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1070 int retval = 0;
1072 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1074 rwlock_init(&adapter->erp_lock);
1075 INIT_LIST_HEAD(&adapter->erp_ready_head);
1076 INIT_LIST_HEAD(&adapter->erp_running_head);
1077 sema_init(&adapter->erp_ready_sem, 0);
1079 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1080 if (retval < 0) {
1081 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1082 "adapter %s\n",
1083 zfcp_get_busid_by_adapter(adapter));
1084 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1085 } else {
1086 wait_event(adapter->erp_thread_wqh,
1087 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1088 &adapter->status));
1089 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1092 return (retval < 0);
1096 * function:
1098 * purpose:
1100 * returns:
1102 * context: process (i.e. proc-fs or rmmod/insmod)
1104 * note: The caller of this routine ensures that the specified
1105 * adapter has been shut down and that this operation
1106 * has been completed. Thus, there are no pending erp_actions
1107 * which would need to be handled here.
1110 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1112 int retval = 0;
1114 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1115 up(&adapter->erp_ready_sem);
1117 wait_event(adapter->erp_thread_wqh,
1118 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1119 &adapter->status));
1121 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1122 &adapter->status);
1124 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1126 return retval;
1130 * purpose: is run as a kernel thread,
1131 * goes through list of error recovery actions of associated adapter
1132 * and delegates single action to execution
1134 * returns: 0
1136 static int
1137 zfcp_erp_thread(void *data)
1139 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1140 struct list_head *next;
1141 struct zfcp_erp_action *erp_action;
1142 unsigned long flags;
1144 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1145 /* Block all signals */
1146 siginitsetinv(&current->blocked, 0);
1147 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1148 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1149 wake_up(&adapter->erp_thread_wqh);
1151 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1152 &adapter->status)) {
1154 write_lock_irqsave(&adapter->erp_lock, flags);
1155 next = adapter->erp_ready_head.prev;
1156 write_unlock_irqrestore(&adapter->erp_lock, flags);
1158 if (next != &adapter->erp_ready_head) {
1159 erp_action =
1160 list_entry(next, struct zfcp_erp_action, list);
1162 * process action (incl. [re]moving it
1163 * from 'ready' queue)
1165 zfcp_erp_strategy(erp_action);
1169 * sleep as long as there is nothing to do, i.e.
1170 * no action in 'ready' queue to be processed and
1171 * thread is not to be killed
1173 down_interruptible(&adapter->erp_ready_sem);
1174 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1177 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1178 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1179 wake_up(&adapter->erp_thread_wqh);
1181 return 0;
1185 * function:
1187 * purpose: drives single error recovery action and schedules higher and
1188 * subordinate actions, if necessary
1190 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1191 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1192 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1193 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1194 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1196 static int
1197 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1199 int retval = 0;
1200 struct zfcp_adapter *adapter = erp_action->adapter;
1201 struct zfcp_port *port = erp_action->port;
1202 struct zfcp_unit *unit = erp_action->unit;
1203 int action = erp_action->action;
1204 u32 status = erp_action->status;
1205 unsigned long flags;
1207 /* serialise dismissing, timing out, moving, enqueueing */
1208 read_lock_irqsave(&zfcp_data.config_lock, flags);
1209 write_lock(&adapter->erp_lock);
1211 /* dequeue dismissed action and leave, if required */
1212 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1213 if (retval == ZFCP_ERP_DISMISSED) {
1214 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1215 goto unlock;
1219 * move action to 'running' queue before processing it
1220 * (to avoid a race condition regarding moving the
1221 * action to the 'running' queue and back)
1223 zfcp_erp_action_to_running(erp_action);
1226 * try to process action as far as possible,
1227 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1228 * afterwards the lock is required again for the following reasons:
1229 * - dequeueing of finished action and enqueueing of
1230 * follow-up actions must be atomic so that any other
1231 * reopen-routine does not believe there is nothing to do
1232 * and that it is safe to enqueue something else,
1233 * - we want to force any control thread which is dismissing
1234 * actions to finish this before we decide about
1235 * necessary steps to be taken here further
1237 write_unlock(&adapter->erp_lock);
1238 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1239 retval = zfcp_erp_strategy_do_action(erp_action);
1240 read_lock_irqsave(&zfcp_data.config_lock, flags);
1241 write_lock(&adapter->erp_lock);
1244 * check for dismissed status again to avoid follow-up actions,
1245 * failing of targets and so on for dismissed actions
1247 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1249 switch (retval) {
1250 case ZFCP_ERP_DISMISSED:
1251 /* leave since this action has ridden to its ancestors */
1252 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1253 goto unlock;
1254 case ZFCP_ERP_NOMEM:
1255 /* no memory to continue immediately, let it sleep */
1256 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1257 ++adapter->erp_low_mem_count;
1258 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1260 /* This condition is true if there is no memory available
1261 for any erp_action on this adapter. This implies that there
1262 are no elements in the memory pool(s) left for erp_actions.
1263 This might happen if an erp_action that used a memory pool
1264 element was timed out.
1266 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1267 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1268 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1269 "restarting I/O on adapter %s "
1270 "to free mempool\n",
1271 zfcp_get_busid_by_adapter(adapter));
1272 zfcp_erp_adapter_reopen_internal(adapter, 0);
1273 } else {
1274 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1275 retval = zfcp_erp_strategy_memwait(erp_action);
1277 goto unlock;
1278 case ZFCP_ERP_CONTINUES:
1279 /* leave since this action runs asynchronously */
1280 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1281 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1282 --adapter->erp_low_mem_count;
1283 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1285 goto unlock;
1287 /* ok, finished action (whatever its result is) */
1289 /* check for unrecoverable targets */
1290 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1292 /* action must be dequeued (here to allow for further ones) */
1293 zfcp_erp_action_dequeue(erp_action);
1296 * put this target through the erp mill again if someone has
1297 * requested to change the status of a target being online
1298 * to offline or the other way around
1299 * (old retval is preserved if nothing has to be done here)
1301 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1302 port, unit, retval);
1305 * leave if target is in permanent error state or if
1306 * action is repeated in order to process state change
1308 if (retval == ZFCP_ERP_EXIT) {
1309 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1310 goto unlock;
1313 /* trigger follow up actions */
1314 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1316 unlock:
1317 write_unlock(&adapter->erp_lock);
1318 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1320 if (retval != ZFCP_ERP_CONTINUES)
1321 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1324 * a few tasks remain when the erp queues are empty
1325 * (don't do that if the last action evaluated was dismissed
1326 * since this clearly indicates that there is more to come) :
1327 * - close the name server port if it is open yet
1328 * (enqueues another [probably] final action)
1329 * - otherwise, wake up whoever wants to be woken when we are
1330 * done with erp
1332 if (retval != ZFCP_ERP_DISMISSED)
1333 zfcp_erp_strategy_check_queues(adapter);
1335 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1337 return retval;
1341 * function:
1343 * purpose:
1345 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1346 * retval - otherwise
1348 static int
1349 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1351 struct zfcp_adapter *adapter = erp_action->adapter;
1353 zfcp_erp_strategy_check_fsfreq(erp_action);
1355 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1356 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1357 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1358 zfcp_erp_action_dequeue(erp_action);
1359 retval = ZFCP_ERP_DISMISSED;
1360 } else
1361 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1363 return retval;
1367 * function:
1369 * purpose:
1371 * returns:
1373 static int
1374 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1376 int retval = ZFCP_ERP_FAILED;
1377 struct zfcp_adapter *adapter = erp_action->adapter;
1380 * try to execute/continue action as far as possible,
1381 * note: no lock in subsequent strategy routines
1382 * (this allows these routine to call schedule, e.g.
1383 * kmalloc with such flags or qdio_initialize & friends)
1384 * Note: in case of timeout, the seperate strategies will fail
1385 * anyhow. No need for a special action. Even worse, a nameserver
1386 * failure would not wake up waiting ports without the call.
1388 switch (erp_action->action) {
1390 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1391 retval = zfcp_erp_adapter_strategy(erp_action);
1392 break;
1394 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1395 retval = zfcp_erp_port_forced_strategy(erp_action);
1396 break;
1398 case ZFCP_ERP_ACTION_REOPEN_PORT:
1399 retval = zfcp_erp_port_strategy(erp_action);
1400 break;
1402 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1403 retval = zfcp_erp_unit_strategy(erp_action);
1404 break;
1406 default:
1407 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1408 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1409 sizeof (int));
1410 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1411 "adapter %s (action=%d)\n",
1412 zfcp_get_busid_by_adapter(erp_action->adapter),
1413 erp_action->action);
1416 return retval;
1420 * function:
1422 * purpose: triggers retry of this action after a certain amount of time
1423 * by means of timer provided by erp_action
1425 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1427 static int
1428 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1430 int retval = ZFCP_ERP_CONTINUES;
1431 struct zfcp_adapter *adapter = erp_action->adapter;
1433 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1434 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1435 init_timer(&erp_action->timer);
1436 erp_action->timer.function = zfcp_erp_memwait_handler;
1437 erp_action->timer.data = (unsigned long) erp_action;
1438 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1439 add_timer(&erp_action->timer);
1441 return retval;
1445 * function: zfcp_erp_adapter_failed
1447 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1450 void
1451 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1453 zfcp_erp_modify_adapter_status(adapter,
1454 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1455 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1456 zfcp_get_busid_by_adapter(adapter));
1457 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1461 * function: zfcp_erp_port_failed
1463 * purpose: sets the port and all underlying devices to ERP_FAILED
1466 void
1467 zfcp_erp_port_failed(struct zfcp_port *port)
1469 zfcp_erp_modify_port_status(port,
1470 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1472 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1473 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1474 "port d_id=0x%08x)\n",
1475 zfcp_get_busid_by_port(port), port->d_id);
1476 else
1477 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1478 zfcp_get_busid_by_port(port), port->wwpn);
1480 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1481 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1485 * function: zfcp_erp_unit_failed
1487 * purpose: sets the unit to ERP_FAILED
1490 void
1491 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1493 zfcp_erp_modify_unit_status(unit,
1494 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1496 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1497 " on adapter %s\n", unit->fcp_lun,
1498 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1499 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1500 debug_event(unit->port->adapter->erp_dbf, 2,
1501 &unit->fcp_lun, sizeof (fcp_lun_t));
1505 * function: zfcp_erp_strategy_check_target
1507 * purpose: increments the erp action count on the device currently in
1508 * recovery if the action failed or resets the count in case of
1509 * success. If a maximum count is exceeded the device is marked
1510 * as ERP_FAILED.
1511 * The 'blocked' state of a target which has been recovered
1512 * successfully is reset.
1514 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1515 * ZFCP_ERP_SUCCEEDED - action finished successfully
1516 * ZFCP_ERP_EXIT - action failed and will not continue
1518 static int
1519 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1521 struct zfcp_adapter *adapter = erp_action->adapter;
1522 struct zfcp_port *port = erp_action->port;
1523 struct zfcp_unit *unit = erp_action->unit;
1525 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1526 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1527 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1529 switch (erp_action->action) {
1531 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1532 result = zfcp_erp_strategy_check_unit(unit, result);
1533 break;
1535 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1536 case ZFCP_ERP_ACTION_REOPEN_PORT:
1537 result = zfcp_erp_strategy_check_port(port, result);
1538 break;
1540 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1541 result = zfcp_erp_strategy_check_adapter(adapter, result);
1542 break;
1545 return result;
1549 * function:
1551 * purpose:
1553 * returns:
1555 static int
1556 zfcp_erp_strategy_statechange(int action,
1557 u32 status,
1558 struct zfcp_adapter *adapter,
1559 struct zfcp_port *port,
1560 struct zfcp_unit *unit, int retval)
1562 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1563 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1565 switch (action) {
1567 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1568 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1569 status)) {
1570 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1571 retval = ZFCP_ERP_EXIT;
1573 break;
1575 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1576 case ZFCP_ERP_ACTION_REOPEN_PORT:
1577 if (zfcp_erp_strategy_statechange_detected(&port->status,
1578 status)) {
1579 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1580 retval = ZFCP_ERP_EXIT;
1582 break;
1584 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1585 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1586 status)) {
1587 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1588 retval = ZFCP_ERP_EXIT;
1590 break;
1593 return retval;
1597 * function:
1599 * purpose:
1601 * returns:
1603 static inline int
1604 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1606 return
1607 /* take it online */
1608 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1609 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1610 /* take it offline */
1611 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1612 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1616 * function:
1618 * purpose:
1620 * returns:
1622 static int
1623 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1625 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1626 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1627 sizeof (fcp_lun_t));
1629 switch (result) {
1630 case ZFCP_ERP_SUCCEEDED :
1631 atomic_set(&unit->erp_counter, 0);
1632 zfcp_erp_unit_unblock(unit);
1633 break;
1634 case ZFCP_ERP_FAILED :
1635 atomic_inc(&unit->erp_counter);
1636 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1637 zfcp_erp_unit_failed(unit);
1638 break;
1639 case ZFCP_ERP_EXIT :
1640 /* nothing */
1641 break;
1644 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1645 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1646 result = ZFCP_ERP_EXIT;
1649 return result;
1653 * function:
1655 * purpose:
1657 * returns:
1659 static int
1660 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1662 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1663 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1665 switch (result) {
1666 case ZFCP_ERP_SUCCEEDED :
1667 atomic_set(&port->erp_counter, 0);
1668 zfcp_erp_port_unblock(port);
1669 break;
1670 case ZFCP_ERP_FAILED :
1671 atomic_inc(&port->erp_counter);
1672 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1673 zfcp_erp_port_failed(port);
1674 break;
1675 case ZFCP_ERP_EXIT :
1676 /* nothing */
1677 break;
1680 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1681 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1682 result = ZFCP_ERP_EXIT;
1685 return result;
1689 * function:
1691 * purpose:
1693 * returns:
1695 static int
1696 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1698 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1700 switch (result) {
1701 case ZFCP_ERP_SUCCEEDED :
1702 atomic_set(&adapter->erp_counter, 0);
1703 zfcp_erp_adapter_unblock(adapter);
1704 break;
1705 case ZFCP_ERP_FAILED :
1706 atomic_inc(&adapter->erp_counter);
1707 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1708 zfcp_erp_adapter_failed(adapter);
1709 break;
1710 case ZFCP_ERP_EXIT :
1711 /* nothing */
1712 break;
1715 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1716 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1717 result = ZFCP_ERP_EXIT;
1720 return result;
1724 * function:
1726 * purpose: remaining things in good cases,
1727 * escalation in bad cases
1729 * returns:
1731 static int
1732 zfcp_erp_strategy_followup_actions(int action,
1733 struct zfcp_adapter *adapter,
1734 struct zfcp_port *port,
1735 struct zfcp_unit *unit, int status)
1737 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1738 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1740 /* initiate follow-up actions depending on success of finished action */
1741 switch (action) {
1743 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1744 if (status == ZFCP_ERP_SUCCEEDED)
1745 zfcp_erp_port_reopen_all_internal(adapter, 0);
1746 else
1747 zfcp_erp_adapter_reopen_internal(adapter, 0);
1748 break;
1750 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1751 if (status == ZFCP_ERP_SUCCEEDED)
1752 zfcp_erp_port_reopen_internal(port, 0);
1753 else
1754 zfcp_erp_adapter_reopen_internal(adapter, 0);
1755 break;
1757 case ZFCP_ERP_ACTION_REOPEN_PORT:
1758 if (status == ZFCP_ERP_SUCCEEDED)
1759 zfcp_erp_unit_reopen_all_internal(port, 0);
1760 else
1761 zfcp_erp_port_forced_reopen_internal(port, 0);
1762 break;
1764 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1765 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1766 else
1767 zfcp_erp_port_reopen_internal(unit->port, 0);
1768 break;
1771 return 0;
1775 * function:
1777 * purpose:
1779 * returns:
1781 static int
1782 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1784 unsigned long flags;
1786 read_lock_irqsave(&zfcp_data.config_lock, flags);
1787 read_lock(&adapter->erp_lock);
1788 if (list_empty(&adapter->erp_ready_head) &&
1789 list_empty(&adapter->erp_running_head)) {
1790 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1791 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1792 &adapter->status);
1793 wake_up(&adapter->erp_done_wqh);
1794 } else
1795 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1796 read_unlock(&adapter->erp_lock);
1797 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1799 return 0;
1803 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1804 * @adapter: adapter for which to wait for completion of its error recovery
1805 * Return: 0
1808 zfcp_erp_wait(struct zfcp_adapter *adapter)
1810 int retval = 0;
1812 wait_event(adapter->erp_done_wqh,
1813 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1814 &adapter->status));
1816 return retval;
1820 * function: zfcp_erp_modify_adapter_status
1822 * purpose:
1825 void
1826 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1827 u32 mask, int set_or_clear)
1829 struct zfcp_port *port;
1830 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1832 if (set_or_clear == ZFCP_SET) {
1833 atomic_set_mask(mask, &adapter->status);
1834 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1835 } else {
1836 atomic_clear_mask(mask, &adapter->status);
1837 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1838 atomic_set(&adapter->erp_counter, 0);
1839 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1841 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1843 /* Deal with all underlying devices, only pass common_mask */
1844 if (common_mask)
1845 list_for_each_entry(port, &adapter->port_list_head, list)
1846 zfcp_erp_modify_port_status(port, common_mask,
1847 set_or_clear);
1851 * function: zfcp_erp_modify_port_status
1853 * purpose: sets the port and all underlying devices to ERP_FAILED
1856 void
1857 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1859 struct zfcp_unit *unit;
1860 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1862 if (set_or_clear == ZFCP_SET) {
1863 atomic_set_mask(mask, &port->status);
1864 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1865 } else {
1866 atomic_clear_mask(mask, &port->status);
1867 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1868 atomic_set(&port->erp_counter, 0);
1869 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1871 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1872 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1874 /* Modify status of all underlying devices, only pass common mask */
1875 if (common_mask)
1876 list_for_each_entry(unit, &port->unit_list_head, list)
1877 zfcp_erp_modify_unit_status(unit, common_mask,
1878 set_or_clear);
1882 * function: zfcp_erp_modify_unit_status
1884 * purpose: sets the unit to ERP_FAILED
1887 void
1888 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1890 if (set_or_clear == ZFCP_SET) {
1891 atomic_set_mask(mask, &unit->status);
1892 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1893 } else {
1894 atomic_clear_mask(mask, &unit->status);
1895 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1896 atomic_set(&unit->erp_counter, 0);
1898 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1900 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1901 sizeof (fcp_lun_t));
1902 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1906 * function:
1908 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1909 * used to ensure the correct locking
1911 * returns: 0 - initiated action succesfully
1912 * <0 - failed to initiate action
1915 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1917 int retval;
1918 unsigned long flags;
1920 read_lock_irqsave(&zfcp_data.config_lock, flags);
1921 write_lock(&adapter->erp_lock);
1922 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1923 write_unlock(&adapter->erp_lock);
1924 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1926 return retval;
1930 * function:
1932 * purpose:
1934 * returns: FIXME
1936 static int
1937 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1939 int retval = 0;
1940 struct zfcp_port *port;
1942 list_for_each_entry(port, &adapter->port_list_head, list)
1943 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1944 zfcp_erp_port_reopen_internal(port, clear_mask);
1946 return retval;
1950 * function:
1952 * purpose:
1954 * returns: FIXME
1956 static int
1957 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1959 int retval = 0;
1960 struct zfcp_unit *unit;
1962 list_for_each_entry(unit, &port->unit_list_head, list)
1963 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1965 return retval;
1969 * function:
1971 * purpose: this routine executes the 'Reopen Adapter' action
1972 * (the entire action is processed synchronously, since
1973 * there are no actions which might be run concurrently
1974 * per definition)
1976 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1977 * ZFCP_ERP_FAILED - action finished unsuccessfully
1979 static int
1980 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1982 int retval;
1983 struct zfcp_adapter *adapter = erp_action->adapter;
1985 retval = zfcp_erp_adapter_strategy_close(erp_action);
1986 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1987 retval = ZFCP_ERP_EXIT;
1988 else
1989 retval = zfcp_erp_adapter_strategy_open(erp_action);
1991 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1992 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1993 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1995 if (retval == ZFCP_ERP_FAILED) {
1996 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1997 "to recover itself\n",
1998 zfcp_get_busid_by_adapter(adapter));
1999 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2002 return retval;
2006 * function:
2008 * purpose:
2010 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2011 * ZFCP_ERP_FAILED - action finished unsuccessfully
2013 static int
2014 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2016 int retval;
2018 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2019 &erp_action->adapter->status);
2020 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2021 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2022 &erp_action->adapter->status);
2024 return retval;
2028 * function:
2030 * purpose:
2032 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2033 * ZFCP_ERP_FAILED - action finished unsuccessfully
2035 static int
2036 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2038 int retval;
2040 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2041 &erp_action->adapter->status);
2042 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2043 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2044 &erp_action->adapter->status);
2046 return retval;
2050 * function: zfcp_register_adapter
2052 * purpose: allocate the irq associated with this devno and register
2053 * the FSF adapter with the SCSI stack
2055 * returns:
2057 static int
2058 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2060 int retval = ZFCP_ERP_SUCCEEDED;
2062 if (close)
2063 goto close_only;
2065 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2066 if (retval != ZFCP_ERP_SUCCEEDED)
2067 goto failed_qdio;
2069 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2070 if (retval != ZFCP_ERP_SUCCEEDED)
2071 goto failed_openfcp;
2073 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2074 goto out;
2076 close_only:
2077 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2078 &erp_action->adapter->status);
2080 failed_openfcp:
2081 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2082 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2083 failed_qdio:
2084 out:
2085 return retval;
2089 * function: zfcp_qdio_init
2091 * purpose: setup QDIO operation for specified adapter
2093 * returns: 0 - successful setup
2094 * !0 - failed setup
2097 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2099 int retval;
2100 int i;
2101 volatile struct qdio_buffer_element *sbale;
2102 struct zfcp_adapter *adapter = erp_action->adapter;
2104 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2105 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2106 "adapter %s\n",
2107 zfcp_get_busid_by_adapter(adapter));
2108 goto failed_sanity;
2111 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2112 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2113 "on adapter %s\n",
2114 zfcp_get_busid_by_adapter(adapter));
2115 goto failed_qdio_establish;
2117 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2119 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2120 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2121 "on adapter %s\n",
2122 zfcp_get_busid_by_adapter(adapter));
2123 goto failed_qdio_activate;
2125 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2128 * put buffers into response queue,
2130 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2131 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2132 sbale->length = 0;
2133 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2134 sbale->addr = 0;
2137 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2138 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2139 zfcp_get_busid_by_adapter(adapter),
2140 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2142 retval = do_QDIO(adapter->ccw_device,
2143 QDIO_FLAG_SYNC_INPUT,
2144 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2146 if (retval) {
2147 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2148 retval);
2149 goto failed_do_qdio;
2150 } else {
2151 adapter->response_queue.free_index = 0;
2152 atomic_set(&adapter->response_queue.free_count, 0);
2153 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2154 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2156 /* set index of first avalable SBALS / number of available SBALS */
2157 adapter->request_queue.free_index = 0;
2158 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2159 adapter->request_queue.distance_from_int = 0;
2161 /* initialize waitqueue used to wait for free SBALs in requests queue */
2162 init_waitqueue_head(&adapter->request_wq);
2164 /* ok, we did it - skip all cleanups for different failures */
2165 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2166 retval = ZFCP_ERP_SUCCEEDED;
2167 goto out;
2169 failed_do_qdio:
2170 /* NOP */
2172 failed_qdio_activate:
2173 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2174 while (qdio_shutdown(adapter->ccw_device,
2175 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2176 msleep(1000);
2177 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2179 failed_qdio_establish:
2180 failed_sanity:
2181 retval = ZFCP_ERP_FAILED;
2183 out:
2184 return retval;
2188 * function: zfcp_qdio_cleanup
2190 * purpose: cleans up QDIO operation for the specified adapter
2192 * returns: 0 - successful cleanup
2193 * !0 - failed cleanup
2196 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2198 int retval = ZFCP_ERP_SUCCEEDED;
2199 int first_used;
2200 int used_count;
2201 struct zfcp_adapter *adapter = erp_action->adapter;
2203 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2204 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2205 "queues on adapter %s\n",
2206 zfcp_get_busid_by_adapter(adapter));
2207 retval = ZFCP_ERP_FAILED;
2208 goto out;
2212 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2213 * do_QDIO won't be called while qdio_shutdown is in progress.
2216 write_lock_irq(&adapter->request_queue.queue_lock);
2217 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2218 write_unlock_irq(&adapter->request_queue.queue_lock);
2220 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2221 while (qdio_shutdown(adapter->ccw_device,
2222 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2223 msleep(1000);
2224 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2227 * First we had to stop QDIO operation.
2228 * Now it is safe to take the following actions.
2231 /* Cleanup only necessary when there are unacknowledged buffers */
2232 if (atomic_read(&adapter->request_queue.free_count)
2233 < QDIO_MAX_BUFFERS_PER_Q) {
2234 first_used = (adapter->request_queue.free_index +
2235 atomic_read(&adapter->request_queue.free_count))
2236 % QDIO_MAX_BUFFERS_PER_Q;
2237 used_count = QDIO_MAX_BUFFERS_PER_Q -
2238 atomic_read(&adapter->request_queue.free_count);
2239 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2240 first_used, used_count);
2242 adapter->response_queue.free_index = 0;
2243 atomic_set(&adapter->response_queue.free_count, 0);
2244 adapter->request_queue.free_index = 0;
2245 atomic_set(&adapter->request_queue.free_count, 0);
2246 adapter->request_queue.distance_from_int = 0;
2247 out:
2248 return retval;
2252 * function: zfcp_fsf_init
2254 * purpose: initializes FSF operation for the specified adapter
2256 * returns: 0 - succesful initialization of FSF operation
2257 * !0 - failed to initialize FSF operation
2259 static int
2260 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2262 int xconfig, xport;
2264 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2265 &erp_action->adapter->status)) {
2266 zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2267 atomic_set(&erp_action->adapter->erp_counter, 0);
2268 return ZFCP_ERP_FAILED;
2271 xconfig = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2272 xport = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2273 if ((xconfig == ZFCP_ERP_FAILED) || (xport == ZFCP_ERP_FAILED))
2274 return ZFCP_ERP_FAILED;
2276 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2280 * function:
2282 * purpose:
2284 * returns:
2286 static int
2287 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2289 int retval = ZFCP_ERP_SUCCEEDED;
2290 int retries;
2291 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2292 struct zfcp_adapter *adapter = erp_action->adapter;
2294 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2296 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2297 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2298 &adapter->status);
2299 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2300 write_lock(&adapter->erp_lock);
2301 zfcp_erp_action_to_running(erp_action);
2302 write_unlock(&adapter->erp_lock);
2303 zfcp_erp_timeout_init(erp_action);
2304 if (zfcp_fsf_exchange_config_data(erp_action)) {
2305 retval = ZFCP_ERP_FAILED;
2306 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2307 ZFCP_LOG_INFO("error: initiation of exchange of "
2308 "configuration data failed for "
2309 "adapter %s\n",
2310 zfcp_get_busid_by_adapter(adapter));
2311 break;
2313 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2314 ZFCP_LOG_DEBUG("Xchange underway\n");
2317 * Why this works:
2318 * Both the normal completion handler as well as the timeout
2319 * handler will do an 'up' when the 'exchange config data'
2320 * request completes or times out. Thus, the signal to go on
2321 * won't be lost utilizing this semaphore.
2322 * Furthermore, this 'adapter_reopen' action is
2323 * guaranteed to be the only action being there (highest action
2324 * which prevents other actions from being created).
2325 * Resulting from that, the wake signal recognized here
2326 * _must_ be the one belonging to the 'exchange config
2327 * data' request.
2329 down(&adapter->erp_ready_sem);
2330 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2331 ZFCP_LOG_INFO("error: exchange of configuration data "
2332 "for adapter %s timed out\n",
2333 zfcp_get_busid_by_adapter(adapter));
2334 break;
2337 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2338 &adapter->status))
2339 break;
2341 ZFCP_LOG_DEBUG("host connection still initialising... "
2342 "waiting and retrying...\n");
2343 /* sleep a little bit before retry */
2344 msleep(jiffies_to_msecs(sleep));
2345 sleep *= 2;
2348 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2349 &adapter->status)) {
2350 ZFCP_LOG_INFO("error: exchange of configuration data for "
2351 "adapter %s failed\n",
2352 zfcp_get_busid_by_adapter(adapter));
2353 retval = ZFCP_ERP_FAILED;
2356 return retval;
2359 static int
2360 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2362 int retval = ZFCP_ERP_SUCCEEDED;
2363 int retries;
2364 int sleep;
2365 struct zfcp_adapter *adapter = erp_action->adapter;
2367 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2369 for (retries = 0; ; retries++) {
2370 ZFCP_LOG_DEBUG("Doing exchange port data\n");
2371 zfcp_erp_action_to_running(erp_action);
2372 zfcp_erp_timeout_init(erp_action);
2373 if (zfcp_fsf_exchange_port_data(erp_action, adapter, NULL)) {
2374 retval = ZFCP_ERP_FAILED;
2375 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2376 ZFCP_LOG_INFO("error: initiation of exchange of "
2377 "port data failed for adapter %s\n",
2378 zfcp_get_busid_by_adapter(adapter));
2379 break;
2381 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2382 ZFCP_LOG_DEBUG("Xchange underway\n");
2385 * Why this works:
2386 * Both the normal completion handler as well as the timeout
2387 * handler will do an 'up' when the 'exchange port data'
2388 * request completes or times out. Thus, the signal to go on
2389 * won't be lost utilizing this semaphore.
2390 * Furthermore, this 'adapter_reopen' action is
2391 * guaranteed to be the only action being there (highest action
2392 * which prevents other actions from being created).
2393 * Resulting from that, the wake signal recognized here
2394 * _must_ be the one belonging to the 'exchange port
2395 * data' request.
2397 down(&adapter->erp_ready_sem);
2398 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2399 ZFCP_LOG_INFO("error: exchange of port data "
2400 "for adapter %s timed out\n",
2401 zfcp_get_busid_by_adapter(adapter));
2402 break;
2405 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2406 &adapter->status))
2407 break;
2409 ZFCP_LOG_DEBUG("host connection still initialising... "
2410 "waiting and retrying...\n");
2411 /* sleep a little bit before retry */
2412 sleep = retries < ZFCP_EXCHANGE_PORT_DATA_SHORT_RETRIES ?
2413 ZFCP_EXCHANGE_PORT_DATA_SHORT_SLEEP :
2414 ZFCP_EXCHANGE_PORT_DATA_LONG_SLEEP;
2415 msleep(jiffies_to_msecs(sleep));
2418 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2419 &adapter->status)) {
2420 ZFCP_LOG_INFO("error: exchange of port data for "
2421 "adapter %s failed\n",
2422 zfcp_get_busid_by_adapter(adapter));
2423 retval = ZFCP_ERP_FAILED;
2426 return retval;
2430 * function:
2432 * purpose:
2434 * returns:
2436 static int
2437 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2438 *erp_action)
2440 int retval = ZFCP_ERP_SUCCEEDED;
2441 int temp_ret;
2442 struct zfcp_adapter *adapter = erp_action->adapter;
2443 int i;
2445 adapter->status_read_failed = 0;
2446 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2447 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2448 if (temp_ret < 0) {
2449 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2450 "notification failed on adapter %s\n",
2451 zfcp_get_busid_by_adapter(adapter));
2452 retval = ZFCP_ERP_FAILED;
2453 i--;
2454 break;
2458 return retval;
2462 * function: zfcp_fsf_cleanup
2464 * purpose: cleanup FSF operation for specified adapter
2466 * returns: 0 - FSF operation successfully cleaned up
2467 * !0 - failed to cleanup FSF operation for this adapter
2469 static int
2470 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2472 int retval = ZFCP_ERP_SUCCEEDED;
2473 struct zfcp_adapter *adapter = erp_action->adapter;
2476 * wake waiting initiators of requests,
2477 * return SCSI commands (with error status),
2478 * clean up all requests (synchronously)
2480 zfcp_fsf_req_dismiss_all(adapter);
2481 /* reset FSF request sequence number */
2482 adapter->fsf_req_seq_no = 0;
2483 /* all ports and units are closed */
2484 zfcp_erp_modify_adapter_status(adapter,
2485 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2487 return retval;
2491 * function:
2493 * purpose: this routine executes the 'Reopen Physical Port' action
2495 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2496 * ZFCP_ERP_SUCCEEDED - action finished successfully
2497 * ZFCP_ERP_FAILED - action finished unsuccessfully
2499 static int
2500 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2502 int retval = ZFCP_ERP_FAILED;
2503 struct zfcp_port *port = erp_action->port;
2504 struct zfcp_adapter *adapter = erp_action->adapter;
2506 switch (erp_action->step) {
2509 * FIXME:
2510 * the ULP spec. begs for waiting for oustanding commands
2512 case ZFCP_ERP_STEP_UNINITIALIZED:
2513 zfcp_erp_port_strategy_clearstati(port);
2515 * it would be sufficient to test only the normal open flag
2516 * since the phys. open flag cannot be set if the normal
2517 * open flag is unset - however, this is for readabilty ...
2519 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2520 ZFCP_STATUS_COMMON_OPEN),
2521 &port->status)) {
2522 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2523 "close physical\n", port->wwpn);
2524 retval =
2525 zfcp_erp_port_forced_strategy_close(erp_action);
2526 } else
2527 retval = ZFCP_ERP_FAILED;
2528 break;
2530 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2531 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2532 &port->status)) {
2533 ZFCP_LOG_DEBUG("close physical failed for port "
2534 "0x%016Lx\n", port->wwpn);
2535 retval = ZFCP_ERP_FAILED;
2536 } else
2537 retval = ZFCP_ERP_SUCCEEDED;
2538 break;
2541 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2542 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2543 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2544 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2546 return retval;
2550 * function:
2552 * purpose: this routine executes the 'Reopen Port' action
2554 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2555 * ZFCP_ERP_SUCCEEDED - action finished successfully
2556 * ZFCP_ERP_FAILED - action finished unsuccessfully
2558 static int
2559 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2561 int retval = ZFCP_ERP_FAILED;
2562 struct zfcp_port *port = erp_action->port;
2563 struct zfcp_adapter *adapter = erp_action->adapter;
2565 switch (erp_action->step) {
2568 * FIXME:
2569 * the ULP spec. begs for waiting for oustanding commands
2571 case ZFCP_ERP_STEP_UNINITIALIZED:
2572 zfcp_erp_port_strategy_clearstati(port);
2573 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2574 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2575 "close\n", port->wwpn);
2576 retval = zfcp_erp_port_strategy_close(erp_action);
2577 goto out;
2578 } /* else it's already closed, open it */
2579 break;
2581 case ZFCP_ERP_STEP_PORT_CLOSING:
2582 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2583 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2584 port->wwpn);
2585 retval = ZFCP_ERP_FAILED;
2586 goto out;
2587 } /* else it's closed now, open it */
2588 break;
2590 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2591 retval = ZFCP_ERP_EXIT;
2592 else
2593 retval = zfcp_erp_port_strategy_open(erp_action);
2595 out:
2596 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2597 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2598 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2599 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2601 return retval;
2605 * function:
2607 * purpose:
2609 * returns:
2611 static int
2612 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2614 int retval;
2616 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2617 &erp_action->port->status))
2618 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2619 else
2620 retval = zfcp_erp_port_strategy_open_common(erp_action);
2622 return retval;
2626 * function:
2628 * purpose:
2630 * returns:
2632 * FIXME(design): currently only prepared for fabric (nameserver!)
2634 static int
2635 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2637 int retval = 0;
2638 struct zfcp_adapter *adapter = erp_action->adapter;
2639 struct zfcp_port *port = erp_action->port;
2641 switch (erp_action->step) {
2643 case ZFCP_ERP_STEP_UNINITIALIZED:
2644 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2645 case ZFCP_ERP_STEP_PORT_CLOSING:
2646 if (adapter->fc_topology == FSF_TOPO_P2P) {
2647 if (port->wwpn != adapter->peer_wwpn) {
2648 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2649 "on adapter %s.\nPeer WWPN "
2650 "0x%016Lx does not match\n",
2651 port->wwpn,
2652 zfcp_get_busid_by_adapter(adapter),
2653 adapter->peer_wwpn);
2654 zfcp_erp_port_failed(port);
2655 retval = ZFCP_ERP_FAILED;
2656 break;
2658 port->d_id = adapter->peer_d_id;
2659 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2660 retval = zfcp_erp_port_strategy_open_port(erp_action);
2661 break;
2663 if (!(adapter->nameserver_port)) {
2664 retval = zfcp_nameserver_enqueue(adapter);
2665 if (retval != 0) {
2666 ZFCP_LOG_NORMAL("error: nameserver port "
2667 "unavailable for adapter %s\n",
2668 zfcp_get_busid_by_adapter(adapter));
2669 retval = ZFCP_ERP_FAILED;
2670 break;
2673 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2674 &adapter->nameserver_port->status)) {
2675 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2676 "nameserver port\n");
2677 /* nameserver port may live again */
2678 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2679 &adapter->nameserver_port->status);
2680 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2681 >= 0) {
2682 erp_action->step =
2683 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2684 retval = ZFCP_ERP_CONTINUES;
2685 } else
2686 retval = ZFCP_ERP_FAILED;
2687 break;
2689 /* else nameserver port is already open, fall through */
2690 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2691 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2692 &adapter->nameserver_port->status)) {
2693 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2694 retval = ZFCP_ERP_FAILED;
2695 } else {
2696 ZFCP_LOG_DEBUG("nameserver port is open -> "
2697 "nameserver look-up for port 0x%016Lx\n",
2698 port->wwpn);
2699 retval = zfcp_erp_port_strategy_open_common_lookup
2700 (erp_action);
2702 break;
2704 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2705 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2706 if (atomic_test_mask
2707 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2708 ZFCP_LOG_DEBUG("nameserver look-up failed "
2709 "for port 0x%016Lx "
2710 "(misconfigured WWPN?)\n",
2711 port->wwpn);
2712 zfcp_erp_port_failed(port);
2713 retval = ZFCP_ERP_EXIT;
2714 } else {
2715 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2716 "port 0x%016Lx\n", port->wwpn);
2717 retval = ZFCP_ERP_FAILED;
2719 } else {
2720 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2721 "trying open\n", port->wwpn, port->d_id);
2722 retval = zfcp_erp_port_strategy_open_port(erp_action);
2724 break;
2726 case ZFCP_ERP_STEP_PORT_OPENING:
2727 /* D_ID might have changed during open */
2728 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2729 ZFCP_STATUS_PORT_DID_DID),
2730 &port->status)) {
2731 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2732 retval = ZFCP_ERP_SUCCEEDED;
2733 } else {
2734 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2735 port->wwpn);
2736 retval = ZFCP_ERP_FAILED;
2738 break;
2740 default:
2741 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2742 erp_action->step);
2743 retval = ZFCP_ERP_FAILED;
2746 return retval;
2750 * function:
2752 * purpose:
2754 * returns:
2756 static int
2757 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2759 int retval;
2760 struct zfcp_port *port = erp_action->port;
2762 switch (erp_action->step) {
2764 case ZFCP_ERP_STEP_UNINITIALIZED:
2765 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2766 case ZFCP_ERP_STEP_PORT_CLOSING:
2767 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2768 port->wwpn, port->d_id);
2769 retval = zfcp_erp_port_strategy_open_port(erp_action);
2770 break;
2772 case ZFCP_ERP_STEP_PORT_OPENING:
2773 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2774 ZFCP_LOG_DEBUG("WKA port is open\n");
2775 retval = ZFCP_ERP_SUCCEEDED;
2776 } else {
2777 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2778 retval = ZFCP_ERP_FAILED;
2780 /* this is needed anyway (dont care for retval of wakeup) */
2781 ZFCP_LOG_DEBUG("continue other open port operations\n");
2782 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2783 break;
2785 default:
2786 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2787 erp_action->step);
2788 retval = ZFCP_ERP_FAILED;
2791 return retval;
2795 * function:
2797 * purpose: makes the erp thread continue with reopen (physical) port
2798 * actions which have been paused until the name server port
2799 * is opened (or failed)
2801 * returns: 0 (a kind of void retval, its not used)
2803 static int
2804 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2805 *ns_erp_action)
2807 int retval = 0;
2808 unsigned long flags;
2809 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2810 struct zfcp_erp_action *erp_action, *tmp;
2812 read_lock_irqsave(&adapter->erp_lock, flags);
2813 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2814 list) {
2815 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2816 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2817 sizeof (wwn_t));
2818 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2819 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2820 debug_event(adapter->erp_dbf, 3,
2821 &erp_action->port->wwpn, sizeof (wwn_t));
2822 if (atomic_test_mask(
2823 ZFCP_STATUS_COMMON_ERP_FAILED,
2824 &adapter->nameserver_port->status))
2825 zfcp_erp_port_failed(erp_action->port);
2826 zfcp_erp_action_ready(erp_action);
2829 read_unlock_irqrestore(&adapter->erp_lock, flags);
2831 return retval;
2835 * function:
2837 * purpose:
2839 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2840 * ZFCP_ERP_FAILED - action finished unsuccessfully
2842 static int
2843 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2845 int retval;
2846 struct zfcp_adapter *adapter = erp_action->adapter;
2847 struct zfcp_port *port = erp_action->port;
2849 zfcp_erp_timeout_init(erp_action);
2850 retval = zfcp_fsf_close_physical_port(erp_action);
2851 if (retval == -ENOMEM) {
2852 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2853 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2854 retval = ZFCP_ERP_NOMEM;
2855 goto out;
2857 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2858 if (retval != 0) {
2859 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2860 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2861 /* could not send 'open', fail */
2862 retval = ZFCP_ERP_FAILED;
2863 goto out;
2865 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2866 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2867 retval = ZFCP_ERP_CONTINUES;
2868 out:
2869 return retval;
2873 * function:
2875 * purpose:
2877 * returns:
2879 static int
2880 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2882 int retval = 0;
2883 struct zfcp_adapter *adapter = port->adapter;
2885 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2886 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2888 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2889 ZFCP_STATUS_COMMON_CLOSING |
2890 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2891 ZFCP_STATUS_PORT_DID_DID |
2892 ZFCP_STATUS_PORT_PHYS_CLOSING |
2893 ZFCP_STATUS_PORT_INVALID_WWPN,
2894 &port->status);
2895 return retval;
2899 * function:
2901 * purpose:
2903 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2904 * ZFCP_ERP_FAILED - action finished unsuccessfully
2906 static int
2907 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2909 int retval;
2910 struct zfcp_adapter *adapter = erp_action->adapter;
2911 struct zfcp_port *port = erp_action->port;
2913 zfcp_erp_timeout_init(erp_action);
2914 retval = zfcp_fsf_close_port(erp_action);
2915 if (retval == -ENOMEM) {
2916 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2917 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2918 retval = ZFCP_ERP_NOMEM;
2919 goto out;
2921 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2922 if (retval != 0) {
2923 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2924 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2925 /* could not send 'close', fail */
2926 retval = ZFCP_ERP_FAILED;
2927 goto out;
2929 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2930 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2931 retval = ZFCP_ERP_CONTINUES;
2932 out:
2933 return retval;
2937 * function:
2939 * purpose:
2941 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2942 * ZFCP_ERP_FAILED - action finished unsuccessfully
2944 static int
2945 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2947 int retval;
2948 struct zfcp_adapter *adapter = erp_action->adapter;
2949 struct zfcp_port *port = erp_action->port;
2951 zfcp_erp_timeout_init(erp_action);
2952 retval = zfcp_fsf_open_port(erp_action);
2953 if (retval == -ENOMEM) {
2954 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2955 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2956 retval = ZFCP_ERP_NOMEM;
2957 goto out;
2959 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2960 if (retval != 0) {
2961 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2962 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2963 /* could not send 'open', fail */
2964 retval = ZFCP_ERP_FAILED;
2965 goto out;
2967 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2968 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2969 retval = ZFCP_ERP_CONTINUES;
2970 out:
2971 return retval;
2975 * function:
2977 * purpose:
2979 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2980 * ZFCP_ERP_FAILED - action finished unsuccessfully
2982 static int
2983 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2985 int retval;
2986 struct zfcp_adapter *adapter = erp_action->adapter;
2987 struct zfcp_port *port = erp_action->port;
2989 zfcp_erp_timeout_init(erp_action);
2990 retval = zfcp_ns_gid_pn_request(erp_action);
2991 if (retval == -ENOMEM) {
2992 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2993 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2994 retval = ZFCP_ERP_NOMEM;
2995 goto out;
2997 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2998 if (retval != 0) {
2999 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
3000 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3001 /* could not send nameserver request, fail */
3002 retval = ZFCP_ERP_FAILED;
3003 goto out;
3005 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3006 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3007 retval = ZFCP_ERP_CONTINUES;
3008 out:
3009 return retval;
3013 * function:
3015 * purpose: this routine executes the 'Reopen Unit' action
3016 * currently no retries
3018 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3019 * ZFCP_ERP_SUCCEEDED - action finished successfully
3020 * ZFCP_ERP_FAILED - action finished unsuccessfully
3022 static int
3023 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3025 int retval = ZFCP_ERP_FAILED;
3026 struct zfcp_unit *unit = erp_action->unit;
3027 struct zfcp_adapter *adapter = erp_action->adapter;
3029 switch (erp_action->step) {
3032 * FIXME:
3033 * the ULP spec. begs for waiting for oustanding commands
3035 case ZFCP_ERP_STEP_UNINITIALIZED:
3036 zfcp_erp_unit_strategy_clearstati(unit);
3037 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3038 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3039 "trying close\n", unit->fcp_lun);
3040 retval = zfcp_erp_unit_strategy_close(erp_action);
3041 break;
3043 /* else it's already closed, fall through */
3044 case ZFCP_ERP_STEP_UNIT_CLOSING:
3045 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3046 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3047 unit->fcp_lun);
3048 retval = ZFCP_ERP_FAILED;
3049 } else {
3050 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3051 retval = ZFCP_ERP_EXIT;
3052 else {
3053 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3054 "trying open\n", unit->fcp_lun);
3055 retval =
3056 zfcp_erp_unit_strategy_open(erp_action);
3059 break;
3061 case ZFCP_ERP_STEP_UNIT_OPENING:
3062 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3063 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3064 unit->fcp_lun);
3065 retval = ZFCP_ERP_SUCCEEDED;
3066 } else {
3067 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3068 unit->fcp_lun);
3069 retval = ZFCP_ERP_FAILED;
3071 break;
3074 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3075 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3076 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3077 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3078 return retval;
3082 * function:
3084 * purpose:
3086 * returns:
3088 static int
3089 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3091 int retval = 0;
3092 struct zfcp_adapter *adapter = unit->port->adapter;
3094 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3095 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3097 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3098 ZFCP_STATUS_COMMON_CLOSING |
3099 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3100 ZFCP_STATUS_UNIT_SHARED |
3101 ZFCP_STATUS_UNIT_READONLY,
3102 &unit->status);
3104 return retval;
3108 * function:
3110 * purpose:
3112 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3113 * ZFCP_ERP_FAILED - action finished unsuccessfully
3115 static int
3116 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3118 int retval;
3119 struct zfcp_adapter *adapter = erp_action->adapter;
3120 struct zfcp_unit *unit = erp_action->unit;
3122 zfcp_erp_timeout_init(erp_action);
3123 retval = zfcp_fsf_close_unit(erp_action);
3124 if (retval == -ENOMEM) {
3125 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3126 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3127 sizeof (fcp_lun_t));
3128 retval = ZFCP_ERP_NOMEM;
3129 goto out;
3131 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3132 if (retval != 0) {
3133 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3134 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3135 sizeof (fcp_lun_t));
3136 /* could not send 'close', fail */
3137 retval = ZFCP_ERP_FAILED;
3138 goto out;
3140 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3141 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3142 retval = ZFCP_ERP_CONTINUES;
3144 out:
3145 return retval;
3149 * function:
3151 * purpose:
3153 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3154 * ZFCP_ERP_FAILED - action finished unsuccessfully
3156 static int
3157 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3159 int retval;
3160 struct zfcp_adapter *adapter = erp_action->adapter;
3161 struct zfcp_unit *unit = erp_action->unit;
3163 zfcp_erp_timeout_init(erp_action);
3164 retval = zfcp_fsf_open_unit(erp_action);
3165 if (retval == -ENOMEM) {
3166 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3167 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3168 sizeof (fcp_lun_t));
3169 retval = ZFCP_ERP_NOMEM;
3170 goto out;
3172 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3173 if (retval != 0) {
3174 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3175 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3176 sizeof (fcp_lun_t));
3177 /* could not send 'open', fail */
3178 retval = ZFCP_ERP_FAILED;
3179 goto out;
3181 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3182 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3183 retval = ZFCP_ERP_CONTINUES;
3184 out:
3185 return retval;
3189 * function:
3191 * purpose:
3193 * returns:
3195 static inline void
3196 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3198 init_timer(&erp_action->timer);
3199 erp_action->timer.function = zfcp_erp_timeout_handler;
3200 erp_action->timer.data = (unsigned long) erp_action;
3201 /* jiffies will be added in zfcp_fsf_req_send */
3202 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3206 * function:
3208 * purpose: enqueue the specified error recovery action, if needed
3210 * returns:
3212 static int
3213 zfcp_erp_action_enqueue(int action,
3214 struct zfcp_adapter *adapter,
3215 struct zfcp_port *port, struct zfcp_unit *unit)
3217 int retval = 1;
3218 struct zfcp_erp_action *erp_action = NULL;
3219 int stronger_action = 0;
3220 u32 status = 0;
3223 * We need some rules here which check whether we really need
3224 * this action or whether we should just drop it.
3225 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3226 * 'Reopen Unit' request for an associated unit since we can't
3227 * satisfy this request now. A 'Reopen Port' action will trigger
3228 * 'Reopen Unit' actions when it completes.
3229 * Thus, there are only actions in the queue which can immediately be
3230 * executed. This makes the processing of the action queue more
3231 * efficient.
3234 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3235 &adapter->status))
3236 return -EIO;
3238 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3239 /* check whether we really need this */
3240 switch (action) {
3241 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3242 if (atomic_test_mask
3243 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3244 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3245 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3246 sizeof (wwn_t));
3247 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3248 sizeof (fcp_lun_t));
3249 goto out;
3251 if (!atomic_test_mask
3252 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3253 atomic_test_mask
3254 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3255 goto out;
3257 if (!atomic_test_mask
3258 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3259 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3260 unit = NULL;
3262 /* fall through !!! */
3264 case ZFCP_ERP_ACTION_REOPEN_PORT:
3265 if (atomic_test_mask
3266 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3267 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3268 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3269 sizeof (wwn_t));
3270 goto out;
3272 /* fall through !!! */
3274 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3275 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3276 &port->status)) {
3277 if (port->erp_action.action !=
3278 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3279 ZFCP_LOG_INFO("dropped erp action %i (port "
3280 "0x%016Lx, action in use: %i)\n",
3281 action, port->wwpn,
3282 port->erp_action.action);
3283 debug_text_event(adapter->erp_dbf, 4,
3284 "pf_actenq_drp");
3285 } else
3286 debug_text_event(adapter->erp_dbf, 4,
3287 "pf_actenq_drpcp");
3288 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3289 sizeof (wwn_t));
3290 goto out;
3292 if (!atomic_test_mask
3293 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3294 atomic_test_mask
3295 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3296 goto out;
3298 if (!atomic_test_mask
3299 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3300 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3301 port = NULL;
3303 /* fall through !!! */
3305 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3306 if (atomic_test_mask
3307 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3308 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3309 goto out;
3311 break;
3313 default:
3314 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3315 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3316 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3317 "on adapter %s (action=%d)\n",
3318 zfcp_get_busid_by_adapter(adapter), action);
3319 goto out;
3322 /* check whether we need something stronger first */
3323 if (stronger_action) {
3324 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3325 debug_event(adapter->erp_dbf, 4, &stronger_action,
3326 sizeof (int));
3327 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3328 "erp action %d on adapter %s\n",
3329 stronger_action, action,
3330 zfcp_get_busid_by_adapter(adapter));
3331 action = stronger_action;
3334 /* mark adapter to have some error recovery pending */
3335 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3337 /* setup error recovery action */
3338 switch (action) {
3340 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3341 zfcp_unit_get(unit);
3342 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3343 erp_action = &unit->erp_action;
3344 if (!atomic_test_mask
3345 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3346 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3347 break;
3349 case ZFCP_ERP_ACTION_REOPEN_PORT:
3350 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3351 zfcp_port_get(port);
3352 zfcp_erp_action_dismiss_port(port);
3353 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3354 erp_action = &port->erp_action;
3355 if (!atomic_test_mask
3356 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3357 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3358 break;
3360 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3361 zfcp_adapter_get(adapter);
3362 zfcp_erp_action_dismiss_adapter(adapter);
3363 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3364 erp_action = &adapter->erp_action;
3365 if (!atomic_test_mask
3366 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3367 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3368 break;
3371 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3373 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3374 erp_action->adapter = adapter;
3375 erp_action->port = port;
3376 erp_action->unit = unit;
3377 erp_action->action = action;
3378 erp_action->status = status;
3380 ++adapter->erp_total_count;
3382 /* finally put it into 'ready' queue and kick erp thread */
3383 list_add(&erp_action->list, &adapter->erp_ready_head);
3384 up(&adapter->erp_ready_sem);
3385 retval = 0;
3386 out:
3387 return retval;
3391 * function:
3393 * purpose:
3395 * returns:
3397 static int
3398 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3400 int retval = 0;
3401 struct zfcp_adapter *adapter = erp_action->adapter;
3403 --adapter->erp_total_count;
3404 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3405 --adapter->erp_low_mem_count;
3406 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3409 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3410 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3411 list_del(&erp_action->list);
3412 switch (erp_action->action) {
3413 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3414 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3415 &erp_action->unit->status);
3416 break;
3417 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3418 case ZFCP_ERP_ACTION_REOPEN_PORT:
3419 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3420 &erp_action->port->status);
3421 break;
3422 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3423 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3424 &erp_action->adapter->status);
3425 break;
3426 default:
3427 /* bug */
3428 break;
3430 return retval;
3434 * zfcp_erp_action_cleanup
3436 * Register unit with scsi stack if appropiate and fix reference counts.
3437 * Note: Temporary units are not registered with scsi stack.
3439 static void
3440 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3441 struct zfcp_port *port, struct zfcp_unit *unit,
3442 int result)
3444 switch (action) {
3445 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3446 if ((result == ZFCP_ERP_SUCCEEDED)
3447 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3448 &unit->status))
3449 && !unit->device
3450 && port->rport)
3451 scsi_add_device(port->adapter->scsi_host, 0,
3452 port->rport->scsi_target_id,
3453 unit->scsi_lun);
3454 zfcp_unit_put(unit);
3455 break;
3456 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3457 case ZFCP_ERP_ACTION_REOPEN_PORT:
3458 if ((result == ZFCP_ERP_SUCCEEDED)
3459 && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3460 &port->status)
3461 && !port->rport) {
3462 struct fc_rport_identifiers ids;
3463 ids.node_name = port->wwnn;
3464 ids.port_name = port->wwpn;
3465 ids.port_id = port->d_id;
3466 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3467 port->rport =
3468 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3469 if (!port->rport)
3470 ZFCP_LOG_NORMAL("failed registration of rport"
3471 "(adapter %s, wwpn=0x%016Lx)\n",
3472 zfcp_get_busid_by_port(port),
3473 port->wwpn);
3475 zfcp_port_put(port);
3476 break;
3477 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3478 zfcp_adapter_put(adapter);
3479 break;
3480 default:
3481 break;
3487 * function:
3489 * purpose:
3491 * returns: FIXME
3493 static int
3494 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3496 int retval = 0;
3497 struct zfcp_port *port;
3499 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3500 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3501 zfcp_erp_action_dismiss(&adapter->erp_action);
3502 else
3503 list_for_each_entry(port, &adapter->port_list_head, list)
3504 zfcp_erp_action_dismiss_port(port);
3506 return retval;
3510 * function:
3512 * purpose:
3514 * returns: FIXME
3516 static int
3517 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3519 int retval = 0;
3520 struct zfcp_unit *unit;
3521 struct zfcp_adapter *adapter = port->adapter;
3523 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3524 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3525 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3526 zfcp_erp_action_dismiss(&port->erp_action);
3527 else
3528 list_for_each_entry(unit, &port->unit_list_head, list)
3529 zfcp_erp_action_dismiss_unit(unit);
3531 return retval;
3535 * function:
3537 * purpose:
3539 * returns: FIXME
3541 static int
3542 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3544 int retval = 0;
3545 struct zfcp_adapter *adapter = unit->port->adapter;
3547 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3548 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3549 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3550 zfcp_erp_action_dismiss(&unit->erp_action);
3552 return retval;
3556 * function:
3558 * purpose: moves erp_action to 'erp running list'
3560 * returns:
3562 static inline void
3563 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3565 struct zfcp_adapter *adapter = erp_action->adapter;
3567 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3568 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3569 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3573 * function:
3575 * purpose: moves erp_action to 'erp ready list'
3577 * returns:
3579 static inline void
3580 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3582 struct zfcp_adapter *adapter = erp_action->adapter;
3584 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3585 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3586 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3590 * function: zfcp_erp_port_boxed
3592 * purpose:
3594 void
3595 zfcp_erp_port_boxed(struct zfcp_port *port)
3597 struct zfcp_adapter *adapter = port->adapter;
3598 unsigned long flags;
3600 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3601 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3602 read_lock_irqsave(&zfcp_data.config_lock, flags);
3603 zfcp_erp_modify_port_status(port,
3604 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3605 ZFCP_SET);
3606 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3607 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3611 * function: zfcp_erp_unit_boxed
3613 * purpose:
3615 void
3616 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3618 struct zfcp_adapter *adapter = unit->port->adapter;
3620 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3621 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3622 zfcp_erp_modify_unit_status(unit,
3623 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3624 ZFCP_SET);
3625 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3629 * function: zfcp_erp_port_access_denied
3631 * purpose:
3633 void
3634 zfcp_erp_port_access_denied(struct zfcp_port *port)
3636 struct zfcp_adapter *adapter = port->adapter;
3637 unsigned long flags;
3639 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3640 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3641 read_lock_irqsave(&zfcp_data.config_lock, flags);
3642 zfcp_erp_modify_port_status(port,
3643 ZFCP_STATUS_COMMON_ERP_FAILED |
3644 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3645 ZFCP_SET);
3646 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3650 * function: zfcp_erp_unit_access_denied
3652 * purpose:
3654 void
3655 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3657 struct zfcp_adapter *adapter = unit->port->adapter;
3659 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3660 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3661 zfcp_erp_modify_unit_status(unit,
3662 ZFCP_STATUS_COMMON_ERP_FAILED |
3663 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3664 ZFCP_SET);
3668 * function: zfcp_erp_adapter_access_changed
3670 * purpose:
3672 void
3673 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3675 struct zfcp_port *port;
3676 unsigned long flags;
3678 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3679 return;
3681 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3682 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3684 read_lock_irqsave(&zfcp_data.config_lock, flags);
3685 if (adapter->nameserver_port)
3686 zfcp_erp_port_access_changed(adapter->nameserver_port);
3687 list_for_each_entry(port, &adapter->port_list_head, list)
3688 if (port != adapter->nameserver_port)
3689 zfcp_erp_port_access_changed(port);
3690 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3694 * function: zfcp_erp_port_access_changed
3696 * purpose:
3698 void
3699 zfcp_erp_port_access_changed(struct zfcp_port *port)
3701 struct zfcp_adapter *adapter = port->adapter;
3702 struct zfcp_unit *unit;
3704 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3705 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3707 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3708 &port->status) &&
3709 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3710 &port->status)) {
3711 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3712 list_for_each_entry(unit, &port->unit_list_head, list)
3713 zfcp_erp_unit_access_changed(unit);
3714 return;
3717 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3718 "(due to ACT update)\n",
3719 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3720 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3721 ZFCP_LOG_NORMAL("failed reopen of port"
3722 "(adapter %s, wwpn=0x%016Lx)\n",
3723 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3727 * function: zfcp_erp_unit_access_changed
3729 * purpose:
3731 void
3732 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3734 struct zfcp_adapter *adapter = unit->port->adapter;
3736 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3737 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3739 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3740 &unit->status) &&
3741 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3742 &unit->status))
3743 return;
3745 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3746 " on adapter %s (due to ACT update)\n",
3747 unit->fcp_lun, unit->port->wwpn,
3748 zfcp_get_busid_by_adapter(adapter));
3749 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3750 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3751 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3752 zfcp_get_busid_by_adapter(adapter),
3753 unit->port->wwpn, unit->fcp_lun);
3756 #undef ZFCP_LOG_AREA