3 * linux/drivers/s390/scsi/zfcp_erp.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
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)
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 $"
38 static int zfcp_erp_adisc(struct zfcp_adapter *, fc_id_t);
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 *,
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 *,
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_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
130 * zfcp_fsf_request_timeout_handler - called if a request timed out
131 * @data: pointer to adapter for handler function
133 * This function needs to be called if requests (ELS, Generic Service,
134 * or SCSI commands) exceed a certain time limit. The assumption is
135 * that after the time limit the adapter get stuck. So we trigger a reopen of
136 * the adapter. This should not be used for error recovery, SCSI abort
137 * commands and SCSI requests from SCSI mid-layer.
140 zfcp_fsf_request_timeout_handler(unsigned long data)
142 struct zfcp_adapter *adapter;
144 adapter = (struct zfcp_adapter *) data;
146 zfcp_erp_adapter_reopen(adapter, 0);
150 * function: zfcp_fsf_scsi_er_timeout_handler
152 * purpose: This function needs to be called whenever a SCSI error recovery
153 * action (abort/reset) does not return.
154 * Re-opening the adapter means that the command can be returned
155 * by zfcp (it is guarranteed that it does not return via the
156 * adapter anymore). The buffer can then be used again.
161 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
163 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
165 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
166 "Restarting all operations on the adapter %s\n",
167 zfcp_get_busid_by_adapter(adapter));
168 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
169 zfcp_erp_adapter_reopen(adapter, 0);
177 * purpose: called if an adapter failed,
178 * initiates adapter recovery which is done
181 * returns: 0 - initiated action succesfully
182 * <0 - failed to initiate action
185 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
189 debug_text_event(adapter->erp_dbf, 5, "a_ro");
190 ZFCP_LOG_DEBUG("reopen adapter %s\n",
191 zfcp_get_busid_by_adapter(adapter));
193 zfcp_erp_adapter_block(adapter, clear_mask);
195 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
196 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
197 zfcp_get_busid_by_adapter(adapter));
198 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
199 /* ensure propagation of failed status to new devices */
200 zfcp_erp_adapter_failed(adapter);
204 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
205 adapter, NULL, NULL);
214 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
215 * used to ensure the correct locking
217 * returns: 0 - initiated action succesfully
218 * <0 - failed to initiate action
221 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
226 read_lock_irqsave(&zfcp_data.config_lock, flags);
227 write_lock(&adapter->erp_lock);
228 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
229 write_unlock(&adapter->erp_lock);
230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
243 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
247 retval = zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_RUNNING |
249 ZFCP_STATUS_COMMON_ERP_FAILED |
263 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
267 retval = zfcp_erp_port_reopen(port,
268 ZFCP_STATUS_COMMON_RUNNING |
269 ZFCP_STATUS_COMMON_ERP_FAILED |
283 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
287 retval = zfcp_erp_unit_reopen(unit,
288 ZFCP_STATUS_COMMON_RUNNING |
289 ZFCP_STATUS_COMMON_ERP_FAILED |
297 * zfcp_erp_adisc - send ADISC ELS command
298 * @adapter: adapter structure
299 * @d_id: d_id of port where ADISC is sent to
302 zfcp_erp_adisc(struct zfcp_adapter *adapter, fc_id_t d_id)
304 struct zfcp_send_els *send_els;
305 struct zfcp_ls_adisc *adisc;
306 void *address = NULL;
308 struct timer_list *timer;
310 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
311 if (send_els == NULL)
313 memset(send_els, 0, sizeof(*send_els));
315 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->req == NULL)
318 memset(send_els->req, 0, sizeof(*send_els->req));
320 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
321 if (send_els->resp == NULL)
323 memset(send_els->resp, 0, sizeof(*send_els->resp));
325 address = (void *) get_zeroed_page(GFP_ATOMIC);
329 zfcp_address_to_sg(address, send_els->req);
330 address += PAGE_SIZE >> 1;
331 zfcp_address_to_sg(address, send_els->resp);
332 send_els->req_count = send_els->resp_count = 1;
334 send_els->adapter = adapter;
335 send_els->d_id = d_id;
336 send_els->handler = zfcp_erp_adisc_handler;
337 send_els->handler_data = (unsigned long) send_els;
339 adisc = zfcp_sg_to_address(send_els->req);
340 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
342 send_els->req->length = sizeof(struct zfcp_ls_adisc);
343 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
345 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
346 without FC-AL-2 capability, so we don't set it */
347 adisc->wwpn = adapter->wwpn;
348 adisc->wwnn = adapter->wwnn;
349 adisc->nport_id = adapter->s_id;
350 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
351 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
352 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
353 adapter->s_id, d_id, (wwn_t) adisc->wwpn,
354 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
357 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
362 timer->function = zfcp_fsf_request_timeout_handler;
363 timer->data = (unsigned long) adapter;
364 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
365 send_els->timer = timer;
367 retval = zfcp_fsf_send_els(send_els);
369 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
370 "0x%08x on adapter %s\n", d_id,
371 zfcp_get_busid_by_adapter(adapter));
372 del_timer(send_els->timer);
382 __free_pages(send_els->req->page, 0);
383 if (send_els != NULL) {
384 kfree(send_els->timer);
385 kfree(send_els->req);
386 kfree(send_els->resp);
395 * zfcp_erp_adisc_handler - handler for ADISC ELS command
396 * @data: pointer to struct zfcp_send_els
398 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
401 zfcp_erp_adisc_handler(unsigned long data)
403 struct zfcp_send_els *send_els;
404 struct zfcp_port *port;
405 struct zfcp_adapter *adapter;
407 struct zfcp_ls_adisc_acc *adisc;
409 send_els = (struct zfcp_send_els *) data;
411 del_timer(send_els->timer);
413 adapter = send_els->adapter;
414 d_id = send_els->d_id;
416 read_lock(&zfcp_data.config_lock);
417 port = zfcp_get_port_by_did(send_els->adapter, send_els->d_id);
418 read_unlock(&zfcp_data.config_lock);
420 BUG_ON(port == NULL);
422 /* request rejected or timed out */
423 if (send_els->status != 0) {
424 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
425 "force physical port reopen "
426 "(adapter %s, port d_id=0x%08x)\n",
427 zfcp_get_busid_by_adapter(adapter), d_id);
428 debug_text_event(adapter->erp_dbf, 3, "forcreop");
429 if (zfcp_erp_port_forced_reopen(port, 0))
430 ZFCP_LOG_NORMAL("failed reopen of port "
431 "(adapter %s, wwpn=0x%016Lx)\n",
432 zfcp_get_busid_by_port(port),
437 adisc = zfcp_sg_to_address(send_els->resp);
439 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
440 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
441 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
442 d_id, adapter->s_id, (wwn_t) adisc->wwpn,
443 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
446 /* set wwnn for port */
448 port->wwnn = adisc->wwnn;
450 if (port->wwpn != adisc->wwpn) {
451 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
452 "port (adapter %s, wwpn=0x%016Lx, "
453 "adisc_resp_wwpn=0x%016Lx)\n",
454 zfcp_get_busid_by_port(port),
455 port->wwpn, (wwn_t) adisc->wwpn);
456 if (zfcp_erp_port_reopen(port, 0))
457 ZFCP_LOG_NORMAL("failed reopen of port "
458 "(adapter %s, wwpn=0x%016Lx)\n",
459 zfcp_get_busid_by_port(port),
465 __free_pages(send_els->req->page, 0);
466 kfree(send_els->timer);
467 kfree(send_els->req);
468 kfree(send_els->resp);
474 * zfcp_test_link - lightweight link test procedure
475 * @port: port to be tested
477 * Test status of a link to a remote port using the ELS command ADISC.
480 zfcp_test_link(struct zfcp_port *port)
485 retval = zfcp_erp_adisc(port->adapter, port->d_id);
488 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
489 "on adapter %s\n ", port->wwpn,
490 zfcp_get_busid_by_port(port));
491 retval = zfcp_erp_port_forced_reopen(port, 0);
493 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
494 "on adapter %s failed\n", port->wwpn,
495 zfcp_get_busid_by_port(port));
507 * purpose: called if a port failed to be opened normally
508 * initiates Forced Reopen recovery which is done
511 * returns: 0 - initiated action succesfully
512 * <0 - failed to initiate action
515 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
518 struct zfcp_adapter *adapter = port->adapter;
520 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
521 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
523 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
524 port->wwpn, zfcp_get_busid_by_port(port));
526 zfcp_erp_port_block(port, clear_mask);
528 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
529 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
530 "on adapter %s\n", port->wwpn,
531 zfcp_get_busid_by_port(port));
532 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
533 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
538 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
539 port->adapter, port, NULL);
548 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
549 * used to ensure the correct locking
551 * returns: 0 - initiated action succesfully
552 * <0 - failed to initiate action
555 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
559 struct zfcp_adapter *adapter;
561 adapter = port->adapter;
562 read_lock_irqsave(&zfcp_data.config_lock, flags);
563 write_lock(&adapter->erp_lock);
564 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
565 write_unlock(&adapter->erp_lock);
566 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
574 * purpose: called if a port is to be opened
575 * initiates Reopen recovery which is done
578 * returns: 0 - initiated action succesfully
579 * <0 - failed to initiate action
582 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
585 struct zfcp_adapter *adapter = port->adapter;
587 debug_text_event(adapter->erp_dbf, 5, "p_ro");
588 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
590 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
591 port->wwpn, zfcp_get_busid_by_port(port));
593 zfcp_erp_port_block(port, clear_mask);
595 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
596 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
597 "on adapter %s\n", port->wwpn,
598 zfcp_get_busid_by_port(port));
599 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
600 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
601 /* ensure propagation of failed status to new devices */
602 zfcp_erp_port_failed(port);
607 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
608 port->adapter, port, NULL);
615 * zfcp_erp_port_reopen - initiate reopen of a remote port
616 * @port: port to be reopened
617 * @clear_mask: specifies flags in port status to be cleared
618 * Return: 0 on success, < 0 on error
620 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
621 * correct locking. An error recovery task is initiated to do the reopen.
622 * To wait for the completion of the reopen zfcp_erp_wait should be used.
625 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
629 struct zfcp_adapter *adapter = port->adapter;
631 read_lock_irqsave(&zfcp_data.config_lock, flags);
632 write_lock(&adapter->erp_lock);
633 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
634 write_unlock(&adapter->erp_lock);
635 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
643 * purpose: called if a unit is to be opened
644 * initiates Reopen recovery which is done
647 * returns: 0 - initiated action succesfully
648 * <0 - failed to initiate action
651 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
654 struct zfcp_adapter *adapter = unit->port->adapter;
656 debug_text_event(adapter->erp_dbf, 5, "u_ro");
657 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
658 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
659 "on adapter %s\n", unit->fcp_lun,
660 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
662 zfcp_erp_unit_block(unit, clear_mask);
664 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
665 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
666 "on port 0x%016Lx on adapter %s\n",
667 unit->fcp_lun, unit->port->wwpn,
668 zfcp_get_busid_by_unit(unit));
669 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
670 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
676 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
677 unit->port->adapter, unit->port, unit);
683 * zfcp_erp_unit_reopen - initiate reopen of a unit
684 * @unit: unit to be reopened
685 * @clear_mask: specifies flags in unit status to be cleared
686 * Return: 0 on success, < 0 on error
688 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
689 * locking. An error recovery task is initiated to do the reopen.
690 * To wait for the completion of the reopen zfcp_erp_wait should be used.
693 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
697 struct zfcp_adapter *adapter;
698 struct zfcp_port *port;
701 adapter = port->adapter;
703 read_lock_irqsave(&zfcp_data.config_lock, flags);
704 write_lock(&adapter->erp_lock);
705 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
706 write_unlock(&adapter->erp_lock);
707 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
715 * purpose: disable I/O,
716 * return any open requests and clean them up,
717 * aim: no pending and incoming I/O
722 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
724 debug_text_event(adapter->erp_dbf, 6, "a_bl");
725 zfcp_erp_modify_adapter_status(adapter,
726 ZFCP_STATUS_COMMON_UNBLOCKED |
727 clear_mask, ZFCP_CLEAR);
733 * purpose: enable I/O
738 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
740 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
741 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
747 * purpose: disable I/O,
748 * return any open requests and clean them up,
749 * aim: no pending and incoming I/O
754 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
756 struct zfcp_adapter *adapter = port->adapter;
758 debug_text_event(adapter->erp_dbf, 6, "p_bl");
759 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
760 zfcp_erp_modify_port_status(port,
761 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
768 * purpose: enable I/O
773 zfcp_erp_port_unblock(struct zfcp_port *port)
775 struct zfcp_adapter *adapter = port->adapter;
777 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
778 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
779 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
785 * purpose: disable I/O,
786 * return any open requests and clean them up,
787 * aim: no pending and incoming I/O
792 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
794 struct zfcp_adapter *adapter = unit->port->adapter;
796 debug_text_event(adapter->erp_dbf, 6, "u_bl");
797 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
798 zfcp_erp_modify_unit_status(unit,
799 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
806 * purpose: enable I/O
811 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
813 struct zfcp_adapter *adapter = unit->port->adapter;
815 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
816 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
817 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
828 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
830 struct zfcp_adapter *adapter = erp_action->adapter;
832 debug_text_event(adapter->erp_dbf, 4, "a_ar");
833 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
835 zfcp_erp_action_to_ready(erp_action);
836 up(&adapter->erp_ready_sem);
844 * returns: <0 erp_action not found in any list
845 * ZFCP_ERP_ACTION_READY erp_action is in ready list
846 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
848 * locks: erp_lock must be held
851 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
853 int retval = -EINVAL;
854 struct list_head *entry;
855 struct zfcp_erp_action *entry_erp_action;
856 struct zfcp_adapter *adapter = erp_action->adapter;
858 /* search in running list */
859 list_for_each(entry, &adapter->erp_running_head) {
861 list_entry(entry, struct zfcp_erp_action, list);
862 if (entry_erp_action == erp_action) {
863 retval = ZFCP_ERP_ACTION_RUNNING;
867 /* search in ready list */
868 list_for_each(entry, &adapter->erp_ready_head) {
870 list_entry(entry, struct zfcp_erp_action, list);
871 if (entry_erp_action == erp_action) {
872 retval = ZFCP_ERP_ACTION_READY;
882 * purpose: checks current status of action (timed out, dismissed, ...)
883 * and does appropriate preparations (dismiss fsf request, ...)
885 * locks: called under erp_lock (disabled interrupts)
890 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
893 struct zfcp_fsf_req *fsf_req;
894 struct zfcp_adapter *adapter = erp_action->adapter;
896 if (erp_action->fsf_req) {
897 /* take lock to ensure that request is not being deleted meanwhile */
898 write_lock(&adapter->fsf_req_list_lock);
899 /* check whether fsf req does still exist */
900 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
901 if (fsf_req == erp_action->fsf_req)
903 if (fsf_req == erp_action->fsf_req) {
904 /* fsf_req still exists */
905 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
906 debug_event(adapter->erp_dbf, 3, &fsf_req,
907 sizeof (unsigned long));
908 /* dismiss fsf_req of timed out or dismissed erp_action */
909 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
910 ZFCP_STATUS_ERP_TIMEDOUT)) {
911 debug_text_event(adapter->erp_dbf, 3,
913 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
915 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
916 ZFCP_LOG_NORMAL("error: erp step timed out "
917 "(action=%d, fsf_req=%p)\n ",
919 erp_action->fsf_req);
922 * If fsf_req is neither dismissed nor completed
923 * then keep it running asynchronously and don't mess
924 * with the association of erp_action and fsf_req.
926 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
927 ZFCP_STATUS_FSFREQ_DISMISSED)) {
928 /* forget about association between fsf_req
930 fsf_req->erp_action = NULL;
931 erp_action->fsf_req = NULL;
934 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
936 * even if this fsf_req has gone, forget about
937 * association between erp_action and fsf_req
939 erp_action->fsf_req = NULL;
941 write_unlock(&adapter->fsf_req_list_lock);
943 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
949 * purpose: generic handler for asynchronous events related to erp_action events
950 * (normal completion, time-out, dismissing, retry after
951 * low memory condition)
953 * note: deletion of timer is not required (e.g. in case of a time-out),
954 * but a second try does no harm,
955 * we leave it in here to allow for greater simplification
957 * returns: 0 - there was an action to handle
961 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
962 unsigned long set_mask)
965 struct zfcp_adapter *adapter = erp_action->adapter;
967 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
968 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
969 debug_event(adapter->erp_dbf, 2, &erp_action->action,
971 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
972 del_timer(&erp_action->timer);
973 erp_action->status |= set_mask;
974 zfcp_erp_action_ready(erp_action);
977 /* action is ready or gone - nothing to do */
978 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
979 debug_event(adapter->erp_dbf, 3, &erp_action->action,
988 * purpose: generic handler for asynchronous events related to erp_action
989 * events (normal completion, time-out, dismissing, retry after
990 * low memory condition)
992 * note: deletion of timer is not required (e.g. in case of a time-out),
993 * but a second try does no harm,
994 * we leave it in here to allow for greater simplification
996 * returns: 0 - there was an action to handle
1000 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1001 unsigned long set_mask)
1003 struct zfcp_adapter *adapter = erp_action->adapter;
1004 unsigned long flags;
1007 write_lock_irqsave(&adapter->erp_lock, flags);
1008 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1009 write_unlock_irqrestore(&adapter->erp_lock, flags);
1015 * purpose: is called for erp_action which was slept waiting for
1016 * memory becoming avaliable,
1017 * will trigger that this action will be continued
1020 zfcp_erp_memwait_handler(unsigned long data)
1022 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1023 struct zfcp_adapter *adapter = erp_action->adapter;
1025 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1026 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1028 zfcp_erp_async_handler(erp_action, 0);
1032 * purpose: is called if an asynchronous erp step timed out,
1033 * action gets an appropriate flag and will be processed
1037 zfcp_erp_timeout_handler(unsigned long data)
1039 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1040 struct zfcp_adapter *adapter = erp_action->adapter;
1042 debug_text_event(adapter->erp_dbf, 2, "a_th");
1043 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1045 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1049 * purpose: is called for an erp_action which needs to be ended
1050 * though not being done,
1051 * this is usually required if an higher is generated,
1052 * action gets an appropriate flag and will be processed
1055 * locks: erp_lock held (thus we need to call another handler variant)
1058 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1060 struct zfcp_adapter *adapter = erp_action->adapter;
1062 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1063 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1065 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1071 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1075 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1077 rwlock_init(&adapter->erp_lock);
1078 INIT_LIST_HEAD(&adapter->erp_ready_head);
1079 INIT_LIST_HEAD(&adapter->erp_running_head);
1080 sema_init(&adapter->erp_ready_sem, 0);
1082 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1084 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1086 zfcp_get_busid_by_adapter(adapter));
1087 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1089 wait_event(adapter->erp_thread_wqh,
1090 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1092 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1095 return (retval < 0);
1105 * context: process (i.e. proc-fs or rmmod/insmod)
1107 * note: The caller of this routine ensures that the specified
1108 * adapter has been shut down and that this operation
1109 * has been completed. Thus, there are no pending erp_actions
1110 * which would need to be handled here.
1113 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1117 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1118 up(&adapter->erp_ready_sem);
1120 wait_event(adapter->erp_thread_wqh,
1121 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1124 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1127 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1133 * purpose: is run as a kernel thread,
1134 * goes through list of error recovery actions of associated adapter
1135 * and delegates single action to execution
1140 zfcp_erp_thread(void *data)
1142 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1143 struct list_head *next;
1144 struct zfcp_erp_action *erp_action;
1145 unsigned long flags;
1147 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1148 /* Block all signals */
1149 siginitsetinv(¤t->blocked, 0);
1150 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1151 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1152 wake_up(&adapter->erp_thread_wqh);
1154 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1155 &adapter->status)) {
1157 write_lock_irqsave(&adapter->erp_lock, flags);
1158 next = adapter->erp_ready_head.prev;
1159 write_unlock_irqrestore(&adapter->erp_lock, flags);
1161 if (next != &adapter->erp_ready_head) {
1163 list_entry(next, struct zfcp_erp_action, list);
1165 * process action (incl. [re]moving it
1166 * from 'ready' queue)
1168 zfcp_erp_strategy(erp_action);
1172 * sleep as long as there is nothing to do, i.e.
1173 * no action in 'ready' queue to be processed and
1174 * thread is not to be killed
1176 down_interruptible(&adapter->erp_ready_sem);
1177 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1180 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1181 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1182 wake_up(&adapter->erp_thread_wqh);
1190 * purpose: drives single error recovery action and schedules higher and
1191 * subordinate actions, if necessary
1193 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1194 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1195 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1196 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1197 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1200 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1203 struct zfcp_adapter *adapter = erp_action->adapter;
1204 struct zfcp_port *port = erp_action->port;
1205 struct zfcp_unit *unit = erp_action->unit;
1206 int action = erp_action->action;
1207 u32 status = erp_action->status;
1208 unsigned long flags;
1210 /* serialise dismissing, timing out, moving, enqueueing */
1211 read_lock_irqsave(&zfcp_data.config_lock, flags);
1212 write_lock(&adapter->erp_lock);
1214 /* dequeue dismissed action and leave, if required */
1215 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1216 if (retval == ZFCP_ERP_DISMISSED) {
1217 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1222 * move action to 'running' queue before processing it
1223 * (to avoid a race condition regarding moving the
1224 * action to the 'running' queue and back)
1226 zfcp_erp_action_to_running(erp_action);
1229 * try to process action as far as possible,
1230 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1231 * afterwards the lock is required again for the following reasons:
1232 * - dequeueing of finished action and enqueueing of
1233 * follow-up actions must be atomic so that any other
1234 * reopen-routine does not believe there is nothing to do
1235 * and that it is safe to enqueue something else,
1236 * - we want to force any control thread which is dismissing
1237 * actions to finish this before we decide about
1238 * necessary steps to be taken here further
1240 write_unlock(&adapter->erp_lock);
1241 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1242 retval = zfcp_erp_strategy_do_action(erp_action);
1243 read_lock_irqsave(&zfcp_data.config_lock, flags);
1244 write_lock(&adapter->erp_lock);
1247 * check for dismissed status again to avoid follow-up actions,
1248 * failing of targets and so on for dismissed actions
1250 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1253 case ZFCP_ERP_DISMISSED:
1254 /* leave since this action has ridden to its ancestors */
1255 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1257 case ZFCP_ERP_NOMEM:
1258 /* no memory to continue immediately, let it sleep */
1259 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1260 ++adapter->erp_low_mem_count;
1261 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1263 /* This condition is true if there is no memory available
1264 for any erp_action on this adapter. This implies that there
1265 are no elements in the memory pool(s) left for erp_actions.
1266 This might happen if an erp_action that used a memory pool
1267 element was timed out.
1269 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1270 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1271 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1272 "restarting I/O on adapter %s "
1273 "to free mempool\n",
1274 zfcp_get_busid_by_adapter(adapter));
1275 zfcp_erp_adapter_reopen_internal(adapter, 0);
1277 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1278 retval = zfcp_erp_strategy_memwait(erp_action);
1281 case ZFCP_ERP_CONTINUES:
1282 /* leave since this action runs asynchronously */
1283 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1284 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1285 --adapter->erp_low_mem_count;
1286 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1290 /* ok, finished action (whatever its result is) */
1292 /* check for unrecoverable targets */
1293 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1295 /* action must be dequeued (here to allow for further ones) */
1296 zfcp_erp_action_dequeue(erp_action);
1299 * put this target through the erp mill again if someone has
1300 * requested to change the status of a target being online
1301 * to offline or the other way around
1302 * (old retval is preserved if nothing has to be done here)
1304 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1305 port, unit, retval);
1308 * leave if target is in permanent error state or if
1309 * action is repeated in order to process state change
1311 if (retval == ZFCP_ERP_EXIT) {
1312 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1316 /* trigger follow up actions */
1317 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1320 write_unlock(&adapter->erp_lock);
1321 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1323 if (retval != ZFCP_ERP_CONTINUES)
1324 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1327 * a few tasks remain when the erp queues are empty
1328 * (don't do that if the last action evaluated was dismissed
1329 * since this clearly indicates that there is more to come) :
1330 * - close the name server port if it is open yet
1331 * (enqueues another [probably] final action)
1332 * - otherwise, wake up whoever wants to be woken when we are
1335 if (retval != ZFCP_ERP_DISMISSED)
1336 zfcp_erp_strategy_check_queues(adapter);
1338 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1348 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1349 * retval - otherwise
1352 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1354 struct zfcp_adapter *adapter = erp_action->adapter;
1356 zfcp_erp_strategy_check_fsfreq(erp_action);
1358 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1359 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1360 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1361 zfcp_erp_action_dequeue(erp_action);
1362 retval = ZFCP_ERP_DISMISSED;
1364 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1377 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1379 int retval = ZFCP_ERP_FAILED;
1380 struct zfcp_adapter *adapter = erp_action->adapter;
1383 * try to execute/continue action as far as possible,
1384 * note: no lock in subsequent strategy routines
1385 * (this allows these routine to call schedule, e.g.
1386 * kmalloc with such flags or qdio_initialize & friends)
1387 * Note: in case of timeout, the seperate strategies will fail
1388 * anyhow. No need for a special action. Even worse, a nameserver
1389 * failure would not wake up waiting ports without the call.
1391 switch (erp_action->action) {
1393 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1394 retval = zfcp_erp_adapter_strategy(erp_action);
1397 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1398 retval = zfcp_erp_port_forced_strategy(erp_action);
1401 case ZFCP_ERP_ACTION_REOPEN_PORT:
1402 retval = zfcp_erp_port_strategy(erp_action);
1405 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1406 retval = zfcp_erp_unit_strategy(erp_action);
1410 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1411 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1413 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1414 "adapter %s (action=%d)\n",
1415 zfcp_get_busid_by_adapter(erp_action->adapter),
1416 erp_action->action);
1425 * purpose: triggers retry of this action after a certain amount of time
1426 * by means of timer provided by erp_action
1428 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1431 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1433 int retval = ZFCP_ERP_CONTINUES;
1434 struct zfcp_adapter *adapter = erp_action->adapter;
1436 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1437 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1438 init_timer(&erp_action->timer);
1439 erp_action->timer.function = zfcp_erp_memwait_handler;
1440 erp_action->timer.data = (unsigned long) erp_action;
1441 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1442 add_timer(&erp_action->timer);
1448 * function: zfcp_erp_adapter_failed
1450 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1454 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1456 zfcp_erp_modify_adapter_status(adapter,
1457 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1458 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1459 zfcp_get_busid_by_adapter(adapter));
1460 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1464 * function: zfcp_erp_port_failed
1466 * purpose: sets the port and all underlying devices to ERP_FAILED
1470 zfcp_erp_port_failed(struct zfcp_port *port)
1472 zfcp_erp_modify_port_status(port,
1473 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1475 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1476 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1477 "port d_id=0x%08x)\n",
1478 zfcp_get_busid_by_port(port), port->d_id);
1480 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1481 zfcp_get_busid_by_port(port), port->wwpn);
1483 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1484 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1488 * function: zfcp_erp_unit_failed
1490 * purpose: sets the unit to ERP_FAILED
1494 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1496 zfcp_erp_modify_unit_status(unit,
1497 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1499 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1500 " on adapter %s\n", unit->fcp_lun,
1501 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1502 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1503 debug_event(unit->port->adapter->erp_dbf, 2,
1504 &unit->fcp_lun, sizeof (fcp_lun_t));
1508 * function: zfcp_erp_strategy_check_target
1510 * purpose: increments the erp action count on the device currently in
1511 * recovery if the action failed or resets the count in case of
1512 * success. If a maximum count is exceeded the device is marked
1514 * The 'blocked' state of a target which has been recovered
1515 * successfully is reset.
1517 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1518 * ZFCP_ERP_SUCCEEDED - action finished successfully
1519 * ZFCP_ERP_EXIT - action failed and will not continue
1522 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1524 struct zfcp_adapter *adapter = erp_action->adapter;
1525 struct zfcp_port *port = erp_action->port;
1526 struct zfcp_unit *unit = erp_action->unit;
1528 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1529 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1530 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1532 switch (erp_action->action) {
1534 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1535 result = zfcp_erp_strategy_check_unit(unit, result);
1538 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1539 case ZFCP_ERP_ACTION_REOPEN_PORT:
1540 result = zfcp_erp_strategy_check_port(port, result);
1543 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1544 result = zfcp_erp_strategy_check_adapter(adapter, result);
1559 zfcp_erp_strategy_statechange(int action,
1561 struct zfcp_adapter *adapter,
1562 struct zfcp_port *port,
1563 struct zfcp_unit *unit, int retval)
1565 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1566 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1570 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1571 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1573 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1574 retval = ZFCP_ERP_EXIT;
1578 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1579 case ZFCP_ERP_ACTION_REOPEN_PORT:
1580 if (zfcp_erp_strategy_statechange_detected(&port->status,
1582 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1583 retval = ZFCP_ERP_EXIT;
1587 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1588 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1590 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1591 retval = ZFCP_ERP_EXIT;
1607 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1610 /* take it online */
1611 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1612 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1613 /* take it offline */
1614 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1615 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1626 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1628 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1629 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1630 sizeof (fcp_lun_t));
1633 case ZFCP_ERP_SUCCEEDED :
1634 atomic_set(&unit->erp_counter, 0);
1635 zfcp_erp_unit_unblock(unit);
1637 case ZFCP_ERP_FAILED :
1638 atomic_inc(&unit->erp_counter);
1639 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1640 zfcp_erp_unit_failed(unit);
1642 case ZFCP_ERP_EXIT :
1647 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1648 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1649 result = ZFCP_ERP_EXIT;
1663 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1665 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1666 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1669 case ZFCP_ERP_SUCCEEDED :
1670 atomic_set(&port->erp_counter, 0);
1671 zfcp_erp_port_unblock(port);
1673 case ZFCP_ERP_FAILED :
1674 atomic_inc(&port->erp_counter);
1675 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1676 zfcp_erp_port_failed(port);
1678 case ZFCP_ERP_EXIT :
1683 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1684 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1685 result = ZFCP_ERP_EXIT;
1699 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1701 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1704 case ZFCP_ERP_SUCCEEDED :
1705 atomic_set(&adapter->erp_counter, 0);
1706 zfcp_erp_adapter_unblock(adapter);
1708 case ZFCP_ERP_FAILED :
1709 atomic_inc(&adapter->erp_counter);
1710 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1711 zfcp_erp_adapter_failed(adapter);
1713 case ZFCP_ERP_EXIT :
1718 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1719 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1720 result = ZFCP_ERP_EXIT;
1729 * purpose: remaining things in good cases,
1730 * escalation in bad cases
1735 zfcp_erp_strategy_followup_actions(int action,
1736 struct zfcp_adapter *adapter,
1737 struct zfcp_port *port,
1738 struct zfcp_unit *unit, int status)
1740 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1741 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1743 /* initiate follow-up actions depending on success of finished action */
1746 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1747 if (status == ZFCP_ERP_SUCCEEDED)
1748 zfcp_erp_port_reopen_all_internal(adapter, 0);
1750 zfcp_erp_adapter_reopen_internal(adapter, 0);
1753 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1754 if (status == ZFCP_ERP_SUCCEEDED)
1755 zfcp_erp_port_reopen_internal(port, 0);
1757 zfcp_erp_adapter_reopen_internal(adapter, 0);
1760 case ZFCP_ERP_ACTION_REOPEN_PORT:
1761 if (status == ZFCP_ERP_SUCCEEDED)
1762 zfcp_erp_unit_reopen_all_internal(port, 0);
1764 zfcp_erp_port_forced_reopen_internal(port, 0);
1767 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1768 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1770 zfcp_erp_port_reopen_internal(unit->port, 0);
1785 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1787 unsigned long flags;
1789 read_lock_irqsave(&zfcp_data.config_lock, flags);
1790 read_lock(&adapter->erp_lock);
1791 if (list_empty(&adapter->erp_ready_head) &&
1792 list_empty(&adapter->erp_running_head)) {
1793 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1794 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1796 wake_up(&adapter->erp_done_wqh);
1798 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1799 read_unlock(&adapter->erp_lock);
1800 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1806 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1807 * @adapter: adapter for which to wait for completion of its error recovery
1811 zfcp_erp_wait(struct zfcp_adapter *adapter)
1815 wait_event(adapter->erp_done_wqh,
1816 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1823 * function: zfcp_erp_modify_adapter_status
1829 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1830 u32 mask, int set_or_clear)
1832 struct zfcp_port *port;
1833 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1835 if (set_or_clear == ZFCP_SET) {
1836 atomic_set_mask(mask, &adapter->status);
1837 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1839 atomic_clear_mask(mask, &adapter->status);
1840 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1841 atomic_set(&adapter->erp_counter, 0);
1842 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1844 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1846 /* Deal with all underlying devices, only pass common_mask */
1848 list_for_each_entry(port, &adapter->port_list_head, list)
1849 zfcp_erp_modify_port_status(port, common_mask,
1854 * function: zfcp_erp_modify_port_status
1856 * purpose: sets the port and all underlying devices to ERP_FAILED
1860 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1862 struct zfcp_unit *unit;
1863 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1865 if (set_or_clear == ZFCP_SET) {
1866 atomic_set_mask(mask, &port->status);
1867 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1869 atomic_clear_mask(mask, &port->status);
1870 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1871 atomic_set(&port->erp_counter, 0);
1872 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1874 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1875 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1877 /* Modify status of all underlying devices, only pass common mask */
1879 list_for_each_entry(unit, &port->unit_list_head, list)
1880 zfcp_erp_modify_unit_status(unit, common_mask,
1885 * function: zfcp_erp_modify_unit_status
1887 * purpose: sets the unit to ERP_FAILED
1891 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1893 if (set_or_clear == ZFCP_SET) {
1894 atomic_set_mask(mask, &unit->status);
1895 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1897 atomic_clear_mask(mask, &unit->status);
1898 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1899 atomic_set(&unit->erp_counter, 0);
1901 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1903 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1904 sizeof (fcp_lun_t));
1905 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1911 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1912 * used to ensure the correct locking
1914 * returns: 0 - initiated action succesfully
1915 * <0 - failed to initiate action
1918 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1921 unsigned long flags;
1923 read_lock_irqsave(&zfcp_data.config_lock, flags);
1924 write_lock(&adapter->erp_lock);
1925 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1926 write_unlock(&adapter->erp_lock);
1927 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1940 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1943 struct zfcp_port *port;
1945 list_for_each_entry(port, &adapter->port_list_head, list)
1946 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1947 zfcp_erp_port_reopen_internal(port, clear_mask);
1960 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1963 struct zfcp_unit *unit;
1965 list_for_each_entry(unit, &port->unit_list_head, list)
1966 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1974 * purpose: this routine executes the 'Reopen Adapter' action
1975 * (the entire action is processed synchronously, since
1976 * there are no actions which might be run concurrently
1979 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1980 * ZFCP_ERP_FAILED - action finished unsuccessfully
1983 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1986 struct zfcp_adapter *adapter = erp_action->adapter;
1988 retval = zfcp_erp_adapter_strategy_close(erp_action);
1989 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1990 retval = ZFCP_ERP_EXIT;
1992 retval = zfcp_erp_adapter_strategy_open(erp_action);
1994 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1995 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1996 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1998 if (retval == ZFCP_ERP_FAILED) {
1999 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2000 "to recover itself\n",
2001 zfcp_get_busid_by_adapter(adapter));
2002 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2013 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2014 * ZFCP_ERP_FAILED - action finished unsuccessfully
2017 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2021 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2022 &erp_action->adapter->status);
2023 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2024 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2025 &erp_action->adapter->status);
2035 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2036 * ZFCP_ERP_FAILED - action finished unsuccessfully
2039 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2043 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2044 &erp_action->adapter->status);
2045 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2046 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2047 &erp_action->adapter->status);
2053 * function: zfcp_register_adapter
2055 * purpose: allocate the irq associated with this devno and register
2056 * the FSF adapter with the SCSI stack
2061 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2063 int retval = ZFCP_ERP_SUCCEEDED;
2068 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2069 if (retval != ZFCP_ERP_SUCCEEDED)
2072 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2073 if (retval != ZFCP_ERP_SUCCEEDED)
2074 goto failed_openfcp;
2076 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2080 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2081 &erp_action->adapter->status);
2084 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2085 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2092 * function: zfcp_qdio_init
2094 * purpose: setup QDIO operation for specified adapter
2096 * returns: 0 - successful setup
2100 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2104 volatile struct qdio_buffer_element *sbale;
2105 struct zfcp_adapter *adapter = erp_action->adapter;
2107 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2108 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2110 zfcp_get_busid_by_adapter(adapter));
2114 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2115 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2117 zfcp_get_busid_by_adapter(adapter));
2118 goto failed_qdio_establish;
2120 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2122 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2123 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2125 zfcp_get_busid_by_adapter(adapter));
2126 goto failed_qdio_activate;
2128 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2131 * put buffers into response queue,
2133 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2134 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2136 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2140 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2141 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2142 zfcp_get_busid_by_adapter(adapter),
2143 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2145 retval = do_QDIO(adapter->ccw_device,
2146 QDIO_FLAG_SYNC_INPUT,
2147 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2150 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2152 goto failed_do_qdio;
2154 adapter->response_queue.free_index = 0;
2155 atomic_set(&adapter->response_queue.free_count, 0);
2156 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2157 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2159 /* set index of first avalable SBALS / number of available SBALS */
2160 adapter->request_queue.free_index = 0;
2161 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2162 adapter->request_queue.distance_from_int = 0;
2164 /* initialize waitqueue used to wait for free SBALs in requests queue */
2165 init_waitqueue_head(&adapter->request_wq);
2167 /* ok, we did it - skip all cleanups for different failures */
2168 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2169 retval = ZFCP_ERP_SUCCEEDED;
2175 failed_qdio_activate:
2176 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2177 while (qdio_shutdown(adapter->ccw_device,
2178 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2180 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2182 failed_qdio_establish:
2184 retval = ZFCP_ERP_FAILED;
2191 * function: zfcp_qdio_cleanup
2193 * purpose: cleans up QDIO operation for the specified adapter
2195 * returns: 0 - successful cleanup
2196 * !0 - failed cleanup
2199 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2201 int retval = ZFCP_ERP_SUCCEEDED;
2204 struct zfcp_adapter *adapter = erp_action->adapter;
2206 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2207 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2208 "queues on adapter %s\n",
2209 zfcp_get_busid_by_adapter(adapter));
2210 retval = ZFCP_ERP_FAILED;
2215 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2216 * do_QDIO won't be called while qdio_shutdown is in progress.
2219 write_lock_irq(&adapter->request_queue.queue_lock);
2220 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2221 write_unlock_irq(&adapter->request_queue.queue_lock);
2223 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2224 while (qdio_shutdown(adapter->ccw_device,
2225 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2227 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2230 * First we had to stop QDIO operation.
2231 * Now it is safe to take the following actions.
2234 /* Cleanup only necessary when there are unacknowledged buffers */
2235 if (atomic_read(&adapter->request_queue.free_count)
2236 < QDIO_MAX_BUFFERS_PER_Q) {
2237 first_used = (adapter->request_queue.free_index +
2238 atomic_read(&adapter->request_queue.free_count))
2239 % QDIO_MAX_BUFFERS_PER_Q;
2240 used_count = QDIO_MAX_BUFFERS_PER_Q -
2241 atomic_read(&adapter->request_queue.free_count);
2242 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2243 first_used, used_count);
2245 adapter->response_queue.free_index = 0;
2246 atomic_set(&adapter->response_queue.free_count, 0);
2247 adapter->request_queue.free_index = 0;
2248 atomic_set(&adapter->request_queue.free_count, 0);
2249 adapter->request_queue.distance_from_int = 0;
2255 * function: zfcp_fsf_init
2257 * purpose: initializes FSF operation for the specified adapter
2259 * returns: 0 - succesful initialization of FSF operation
2260 * !0 - failed to initialize FSF operation
2263 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2267 /* do 'exchange configuration data' */
2268 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2269 if (retval == ZFCP_ERP_FAILED)
2272 /* start the desired number of Status Reads */
2273 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2285 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2287 int retval = ZFCP_ERP_SUCCEEDED;
2289 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2290 struct zfcp_adapter *adapter = erp_action->adapter;
2292 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2294 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2295 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2297 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2298 zfcp_erp_action_to_running(erp_action);
2299 zfcp_erp_timeout_init(erp_action);
2300 if (zfcp_fsf_exchange_config_data(erp_action)) {
2301 retval = ZFCP_ERP_FAILED;
2302 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2303 ZFCP_LOG_INFO("error: initiation of exchange of "
2304 "configuration data failed for "
2306 zfcp_get_busid_by_adapter(adapter));
2309 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2310 ZFCP_LOG_DEBUG("Xchange underway\n");
2314 * Both the normal completion handler as well as the timeout
2315 * handler will do an 'up' when the 'exchange config data'
2316 * request completes or times out. Thus, the signal to go on
2317 * won't be lost utilizing this semaphore.
2318 * Furthermore, this 'adapter_reopen' action is
2319 * guaranteed to be the only action being there (highest action
2320 * which prevents other actions from being created).
2321 * Resulting from that, the wake signal recognized here
2322 * _must_ be the one belonging to the 'exchange config
2325 down(&adapter->erp_ready_sem);
2326 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2327 ZFCP_LOG_INFO("error: exchange of configuration data "
2328 "for adapter %s timed out\n",
2329 zfcp_get_busid_by_adapter(adapter));
2333 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2337 ZFCP_LOG_DEBUG("host connection still initialising... "
2338 "waiting and retrying...\n");
2339 /* sleep a little bit before retry */
2340 msleep(jiffies_to_msecs(sleep));
2344 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2345 &adapter->status)) {
2346 ZFCP_LOG_INFO("error: exchange of configuration data for "
2347 "adapter %s failed\n",
2348 zfcp_get_busid_by_adapter(adapter));
2349 retval = ZFCP_ERP_FAILED;
2363 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2366 int retval = ZFCP_ERP_SUCCEEDED;
2368 struct zfcp_adapter *adapter = erp_action->adapter;
2371 adapter->status_read_failed = 0;
2372 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2373 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2375 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2376 "notification failed on adapter %s\n",
2377 zfcp_get_busid_by_adapter(adapter));
2378 retval = ZFCP_ERP_FAILED;
2388 * function: zfcp_fsf_cleanup
2390 * purpose: cleanup FSF operation for specified adapter
2392 * returns: 0 - FSF operation successfully cleaned up
2393 * !0 - failed to cleanup FSF operation for this adapter
2396 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2398 int retval = ZFCP_ERP_SUCCEEDED;
2399 struct zfcp_adapter *adapter = erp_action->adapter;
2402 * wake waiting initiators of requests,
2403 * return SCSI commands (with error status),
2404 * clean up all requests (synchronously)
2406 zfcp_fsf_req_dismiss_all(adapter);
2407 /* reset FSF request sequence number */
2408 adapter->fsf_req_seq_no = 0;
2409 /* all ports and units are closed */
2410 zfcp_erp_modify_adapter_status(adapter,
2411 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2419 * purpose: this routine executes the 'Reopen Physical Port' action
2421 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2422 * ZFCP_ERP_SUCCEEDED - action finished successfully
2423 * ZFCP_ERP_FAILED - action finished unsuccessfully
2426 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2428 int retval = ZFCP_ERP_FAILED;
2429 struct zfcp_port *port = erp_action->port;
2430 struct zfcp_adapter *adapter = erp_action->adapter;
2432 switch (erp_action->step) {
2436 * the ULP spec. begs for waiting for oustanding commands
2438 case ZFCP_ERP_STEP_UNINITIALIZED:
2439 zfcp_erp_port_strategy_clearstati(port);
2441 * it would be sufficient to test only the normal open flag
2442 * since the phys. open flag cannot be set if the normal
2443 * open flag is unset - however, this is for readabilty ...
2445 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2446 ZFCP_STATUS_COMMON_OPEN),
2448 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2449 "close physical\n", port->wwpn);
2451 zfcp_erp_port_forced_strategy_close(erp_action);
2453 retval = ZFCP_ERP_FAILED;
2456 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2457 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2459 ZFCP_LOG_DEBUG("close physical failed for port "
2460 "0x%016Lx\n", port->wwpn);
2461 retval = ZFCP_ERP_FAILED;
2463 retval = ZFCP_ERP_SUCCEEDED;
2467 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2468 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2469 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2470 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2478 * purpose: this routine executes the 'Reopen Port' action
2480 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2481 * ZFCP_ERP_SUCCEEDED - action finished successfully
2482 * ZFCP_ERP_FAILED - action finished unsuccessfully
2485 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2487 int retval = ZFCP_ERP_FAILED;
2488 struct zfcp_port *port = erp_action->port;
2489 struct zfcp_adapter *adapter = erp_action->adapter;
2491 switch (erp_action->step) {
2495 * the ULP spec. begs for waiting for oustanding commands
2497 case ZFCP_ERP_STEP_UNINITIALIZED:
2498 zfcp_erp_port_strategy_clearstati(port);
2499 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2500 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2501 "close\n", port->wwpn);
2502 retval = zfcp_erp_port_strategy_close(erp_action);
2504 } /* else it's already closed, open it */
2507 case ZFCP_ERP_STEP_PORT_CLOSING:
2508 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2509 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2511 retval = ZFCP_ERP_FAILED;
2513 } /* else it's closed now, open it */
2516 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2517 retval = ZFCP_ERP_EXIT;
2519 retval = zfcp_erp_port_strategy_open(erp_action);
2522 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2523 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2524 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2525 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2538 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2542 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2543 &erp_action->port->status))
2544 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2546 retval = zfcp_erp_port_strategy_open_common(erp_action);
2558 * FIXME(design): currently only prepared for fabric (nameserver!)
2561 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2564 struct zfcp_adapter *adapter = erp_action->adapter;
2565 struct zfcp_port *port = erp_action->port;
2567 switch (erp_action->step) {
2569 case ZFCP_ERP_STEP_UNINITIALIZED:
2570 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2571 case ZFCP_ERP_STEP_PORT_CLOSING:
2572 if (adapter->fc_topology == FSF_TOPO_P2P) {
2573 if (port->wwpn != adapter->peer_wwpn) {
2574 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2575 "on adapter %s.\nPeer WWPN "
2576 "0x%016Lx does not match\n",
2578 zfcp_get_busid_by_adapter(adapter),
2579 adapter->peer_wwpn);
2580 zfcp_erp_port_failed(port);
2581 retval = ZFCP_ERP_FAILED;
2584 port->d_id = adapter->peer_d_id;
2585 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2586 retval = zfcp_erp_port_strategy_open_port(erp_action);
2589 if (!(adapter->nameserver_port)) {
2590 retval = zfcp_nameserver_enqueue(adapter);
2592 ZFCP_LOG_NORMAL("error: nameserver port "
2593 "unavailable for adapter %s\n",
2594 zfcp_get_busid_by_adapter(adapter));
2595 retval = ZFCP_ERP_FAILED;
2599 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2600 &adapter->nameserver_port->status)) {
2601 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2602 "nameserver port\n");
2603 /* nameserver port may live again */
2604 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2605 &adapter->nameserver_port->status);
2606 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2609 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2610 retval = ZFCP_ERP_CONTINUES;
2612 retval = ZFCP_ERP_FAILED;
2615 /* else nameserver port is already open, fall through */
2616 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2617 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2618 &adapter->nameserver_port->status)) {
2619 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2620 retval = ZFCP_ERP_FAILED;
2622 ZFCP_LOG_DEBUG("nameserver port is open -> "
2623 "nameserver look-up for port 0x%016Lx\n",
2625 retval = zfcp_erp_port_strategy_open_common_lookup
2630 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2631 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2632 if (atomic_test_mask
2633 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2634 ZFCP_LOG_DEBUG("nameserver look-up failed "
2635 "for port 0x%016Lx "
2636 "(misconfigured WWPN?)\n",
2638 zfcp_erp_port_failed(port);
2639 retval = ZFCP_ERP_EXIT;
2641 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2642 "port 0x%016Lx\n", port->wwpn);
2643 retval = ZFCP_ERP_FAILED;
2646 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2647 "trying open\n", port->wwpn, port->d_id);
2648 retval = zfcp_erp_port_strategy_open_port(erp_action);
2652 case ZFCP_ERP_STEP_PORT_OPENING:
2653 /* D_ID might have changed during open */
2654 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2655 ZFCP_STATUS_PORT_DID_DID),
2657 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2658 retval = ZFCP_ERP_SUCCEEDED;
2660 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2662 retval = ZFCP_ERP_FAILED;
2667 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2669 retval = ZFCP_ERP_FAILED;
2683 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2686 struct zfcp_port *port = erp_action->port;
2688 switch (erp_action->step) {
2690 case ZFCP_ERP_STEP_UNINITIALIZED:
2691 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2692 case ZFCP_ERP_STEP_PORT_CLOSING:
2693 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2694 port->wwpn, port->d_id);
2695 retval = zfcp_erp_port_strategy_open_port(erp_action);
2698 case ZFCP_ERP_STEP_PORT_OPENING:
2699 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2700 ZFCP_LOG_DEBUG("WKA port is open\n");
2701 retval = ZFCP_ERP_SUCCEEDED;
2703 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2704 retval = ZFCP_ERP_FAILED;
2706 /* this is needed anyway (dont care for retval of wakeup) */
2707 ZFCP_LOG_DEBUG("continue other open port operations\n");
2708 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2712 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2714 retval = ZFCP_ERP_FAILED;
2723 * purpose: makes the erp thread continue with reopen (physical) port
2724 * actions which have been paused until the name server port
2725 * is opened (or failed)
2727 * returns: 0 (a kind of void retval, its not used)
2730 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2734 unsigned long flags;
2735 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2736 struct zfcp_erp_action *erp_action, *tmp;
2738 read_lock_irqsave(&adapter->erp_lock, flags);
2739 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2741 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2742 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2744 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2745 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2746 debug_event(adapter->erp_dbf, 3,
2747 &erp_action->port->wwpn, sizeof (wwn_t));
2748 if (atomic_test_mask(
2749 ZFCP_STATUS_COMMON_ERP_FAILED,
2750 &adapter->nameserver_port->status))
2751 zfcp_erp_port_failed(erp_action->port);
2752 zfcp_erp_action_ready(erp_action);
2755 read_unlock_irqrestore(&adapter->erp_lock, flags);
2765 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2766 * ZFCP_ERP_FAILED - action finished unsuccessfully
2769 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2772 struct zfcp_adapter *adapter = erp_action->adapter;
2773 struct zfcp_port *port = erp_action->port;
2775 zfcp_erp_timeout_init(erp_action);
2776 retval = zfcp_fsf_close_physical_port(erp_action);
2777 if (retval == -ENOMEM) {
2778 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2779 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2780 retval = ZFCP_ERP_NOMEM;
2783 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2785 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2786 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2787 /* could not send 'open', fail */
2788 retval = ZFCP_ERP_FAILED;
2791 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2792 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2793 retval = ZFCP_ERP_CONTINUES;
2806 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2809 struct zfcp_adapter *adapter = port->adapter;
2811 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2812 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2814 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2815 ZFCP_STATUS_COMMON_CLOSING |
2816 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2817 ZFCP_STATUS_PORT_DID_DID |
2818 ZFCP_STATUS_PORT_PHYS_CLOSING |
2819 ZFCP_STATUS_PORT_INVALID_WWPN,
2829 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2830 * ZFCP_ERP_FAILED - action finished unsuccessfully
2833 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2836 struct zfcp_adapter *adapter = erp_action->adapter;
2837 struct zfcp_port *port = erp_action->port;
2839 zfcp_erp_timeout_init(erp_action);
2840 retval = zfcp_fsf_close_port(erp_action);
2841 if (retval == -ENOMEM) {
2842 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2843 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2844 retval = ZFCP_ERP_NOMEM;
2847 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2849 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2850 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2851 /* could not send 'close', fail */
2852 retval = ZFCP_ERP_FAILED;
2855 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2856 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2857 retval = ZFCP_ERP_CONTINUES;
2867 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2868 * ZFCP_ERP_FAILED - action finished unsuccessfully
2871 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2874 struct zfcp_adapter *adapter = erp_action->adapter;
2875 struct zfcp_port *port = erp_action->port;
2877 zfcp_erp_timeout_init(erp_action);
2878 retval = zfcp_fsf_open_port(erp_action);
2879 if (retval == -ENOMEM) {
2880 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2881 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2882 retval = ZFCP_ERP_NOMEM;
2885 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2887 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2888 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2889 /* could not send 'open', fail */
2890 retval = ZFCP_ERP_FAILED;
2893 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2894 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2895 retval = ZFCP_ERP_CONTINUES;
2905 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2906 * ZFCP_ERP_FAILED - action finished unsuccessfully
2909 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2912 struct zfcp_adapter *adapter = erp_action->adapter;
2913 struct zfcp_port *port = erp_action->port;
2915 zfcp_erp_timeout_init(erp_action);
2916 retval = zfcp_ns_gid_pn_request(erp_action);
2917 if (retval == -ENOMEM) {
2918 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2919 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2920 retval = ZFCP_ERP_NOMEM;
2923 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2925 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2926 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2927 /* could not send nameserver request, fail */
2928 retval = ZFCP_ERP_FAILED;
2931 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2932 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2933 retval = ZFCP_ERP_CONTINUES;
2941 * purpose: this routine executes the 'Reopen Unit' action
2942 * currently no retries
2944 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2945 * ZFCP_ERP_SUCCEEDED - action finished successfully
2946 * ZFCP_ERP_FAILED - action finished unsuccessfully
2949 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2951 int retval = ZFCP_ERP_FAILED;
2952 struct zfcp_unit *unit = erp_action->unit;
2953 struct zfcp_adapter *adapter = erp_action->adapter;
2955 switch (erp_action->step) {
2959 * the ULP spec. begs for waiting for oustanding commands
2961 case ZFCP_ERP_STEP_UNINITIALIZED:
2962 zfcp_erp_unit_strategy_clearstati(unit);
2963 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2964 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2965 "trying close\n", unit->fcp_lun);
2966 retval = zfcp_erp_unit_strategy_close(erp_action);
2969 /* else it's already closed, fall through */
2970 case ZFCP_ERP_STEP_UNIT_CLOSING:
2971 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2972 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2974 retval = ZFCP_ERP_FAILED;
2976 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2977 retval = ZFCP_ERP_EXIT;
2979 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2980 "trying open\n", unit->fcp_lun);
2982 zfcp_erp_unit_strategy_open(erp_action);
2987 case ZFCP_ERP_STEP_UNIT_OPENING:
2988 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2989 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2991 retval = ZFCP_ERP_SUCCEEDED;
2993 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2995 retval = ZFCP_ERP_FAILED;
3000 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3001 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3002 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3003 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3015 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3018 struct zfcp_adapter *adapter = unit->port->adapter;
3020 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3021 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3023 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3024 ZFCP_STATUS_COMMON_CLOSING |
3025 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3026 ZFCP_STATUS_UNIT_SHARED |
3027 ZFCP_STATUS_UNIT_READONLY,
3038 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3039 * ZFCP_ERP_FAILED - action finished unsuccessfully
3042 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3045 struct zfcp_adapter *adapter = erp_action->adapter;
3046 struct zfcp_unit *unit = erp_action->unit;
3048 zfcp_erp_timeout_init(erp_action);
3049 retval = zfcp_fsf_close_unit(erp_action);
3050 if (retval == -ENOMEM) {
3051 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3052 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3053 sizeof (fcp_lun_t));
3054 retval = ZFCP_ERP_NOMEM;
3057 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3059 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3060 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3061 sizeof (fcp_lun_t));
3062 /* could not send 'close', fail */
3063 retval = ZFCP_ERP_FAILED;
3066 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3067 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3068 retval = ZFCP_ERP_CONTINUES;
3079 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3080 * ZFCP_ERP_FAILED - action finished unsuccessfully
3083 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3086 struct zfcp_adapter *adapter = erp_action->adapter;
3087 struct zfcp_unit *unit = erp_action->unit;
3089 zfcp_erp_timeout_init(erp_action);
3090 retval = zfcp_fsf_open_unit(erp_action);
3091 if (retval == -ENOMEM) {
3092 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3093 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3094 sizeof (fcp_lun_t));
3095 retval = ZFCP_ERP_NOMEM;
3098 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3100 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3101 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3102 sizeof (fcp_lun_t));
3103 /* could not send 'open', fail */
3104 retval = ZFCP_ERP_FAILED;
3107 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3108 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3109 retval = ZFCP_ERP_CONTINUES;
3122 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3124 init_timer(&erp_action->timer);
3125 erp_action->timer.function = zfcp_erp_timeout_handler;
3126 erp_action->timer.data = (unsigned long) erp_action;
3127 /* jiffies will be added in zfcp_fsf_req_send */
3128 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3134 * purpose: enqueue the specified error recovery action, if needed
3139 zfcp_erp_action_enqueue(int action,
3140 struct zfcp_adapter *adapter,
3141 struct zfcp_port *port, struct zfcp_unit *unit)
3144 struct zfcp_erp_action *erp_action = NULL;
3145 int stronger_action = 0;
3149 * We need some rules here which check whether we really need
3150 * this action or whether we should just drop it.
3151 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3152 * 'Reopen Unit' request for an associated unit since we can't
3153 * satisfy this request now. A 'Reopen Port' action will trigger
3154 * 'Reopen Unit' actions when it completes.
3155 * Thus, there are only actions in the queue which can immediately be
3156 * executed. This makes the processing of the action queue more
3160 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3164 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3165 /* check whether we really need this */
3167 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3168 if (atomic_test_mask
3169 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3170 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3171 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3173 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3174 sizeof (fcp_lun_t));
3177 if (!atomic_test_mask
3178 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3180 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3183 if (!atomic_test_mask
3184 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3185 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3188 /* fall through !!! */
3190 case ZFCP_ERP_ACTION_REOPEN_PORT:
3191 if (atomic_test_mask
3192 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3193 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3194 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3198 /* fall through !!! */
3200 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3201 if (atomic_test_mask
3202 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3203 && port->erp_action.action ==
3204 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3205 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3206 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3210 if (!atomic_test_mask
3211 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3213 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3216 if (!atomic_test_mask
3217 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3218 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3221 /* fall through !!! */
3223 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3224 if (atomic_test_mask
3225 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3226 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3232 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3233 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3234 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3235 "on adapter %s (action=%d)\n",
3236 zfcp_get_busid_by_adapter(adapter), action);
3240 /* check whether we need something stronger first */
3241 if (stronger_action) {
3242 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3243 debug_event(adapter->erp_dbf, 4, &stronger_action,
3245 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3246 "erp action %d on adapter %s\n",
3247 stronger_action, action,
3248 zfcp_get_busid_by_adapter(adapter));
3249 action = stronger_action;
3252 /* mark adapter to have some error recovery pending */
3253 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3255 /* setup error recovery action */
3258 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3259 zfcp_unit_get(unit);
3260 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3261 erp_action = &unit->erp_action;
3262 if (!atomic_test_mask
3263 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3264 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3267 case ZFCP_ERP_ACTION_REOPEN_PORT:
3268 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3269 zfcp_port_get(port);
3270 zfcp_erp_action_dismiss_port(port);
3271 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3272 erp_action = &port->erp_action;
3273 if (!atomic_test_mask
3274 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3275 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3278 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3279 zfcp_adapter_get(adapter);
3280 zfcp_erp_action_dismiss_adapter(adapter);
3281 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3282 erp_action = &adapter->erp_action;
3283 if (!atomic_test_mask
3284 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3285 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3289 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3291 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3292 erp_action->adapter = adapter;
3293 erp_action->port = port;
3294 erp_action->unit = unit;
3295 erp_action->action = action;
3296 erp_action->status = status;
3298 ++adapter->erp_total_count;
3300 /* finally put it into 'ready' queue and kick erp thread */
3301 list_add(&erp_action->list, &adapter->erp_ready_head);
3302 up(&adapter->erp_ready_sem);
3316 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3319 struct zfcp_adapter *adapter = erp_action->adapter;
3321 --adapter->erp_total_count;
3322 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3323 --adapter->erp_low_mem_count;
3324 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3327 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3328 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3329 list_del(&erp_action->list);
3330 switch (erp_action->action) {
3331 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3332 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3333 &erp_action->unit->status);
3335 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3336 case ZFCP_ERP_ACTION_REOPEN_PORT:
3337 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3338 &erp_action->port->status);
3340 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3341 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3342 &erp_action->adapter->status);
3352 * zfcp_erp_action_cleanup
3354 * Register unit with scsi stack if appropiate and fix reference counts.
3355 * Note: Temporary units are not registered with scsi stack.
3358 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3359 struct zfcp_port *port, struct zfcp_unit *unit,
3363 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3364 if ((result == ZFCP_ERP_SUCCEEDED)
3365 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3368 scsi_add_device(unit->port->adapter->scsi_host, 0,
3369 unit->port->scsi_id, unit->scsi_lun);
3370 zfcp_unit_put(unit);
3372 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3373 case ZFCP_ERP_ACTION_REOPEN_PORT:
3374 zfcp_port_put(port);
3376 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3377 zfcp_adapter_put(adapter);
3393 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3396 struct zfcp_port *port;
3398 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3399 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3400 zfcp_erp_action_dismiss(&adapter->erp_action);
3402 list_for_each_entry(port, &adapter->port_list_head, list)
3403 zfcp_erp_action_dismiss_port(port);
3416 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3419 struct zfcp_unit *unit;
3420 struct zfcp_adapter *adapter = port->adapter;
3422 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3423 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3424 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3425 zfcp_erp_action_dismiss(&port->erp_action);
3427 list_for_each_entry(unit, &port->unit_list_head, list)
3428 zfcp_erp_action_dismiss_unit(unit);
3441 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3444 struct zfcp_adapter *adapter = unit->port->adapter;
3446 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3447 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3448 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3449 zfcp_erp_action_dismiss(&unit->erp_action);
3457 * purpose: moves erp_action to 'erp running list'
3462 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3464 struct zfcp_adapter *adapter = erp_action->adapter;
3466 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3467 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3468 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3474 * purpose: moves erp_action to 'erp ready list'
3479 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3481 struct zfcp_adapter *adapter = erp_action->adapter;
3483 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3484 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3485 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3489 * function: zfcp_erp_port_access_denied
3494 zfcp_erp_port_access_denied(struct zfcp_port *port)
3496 struct zfcp_adapter *adapter = port->adapter;
3497 unsigned long flags;
3499 debug_text_event(adapter->erp_dbf, 3, "p_access_block");
3500 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3501 read_lock_irqsave(&zfcp_data.config_lock, flags);
3502 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED |
3503 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3504 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3508 * function: zfcp_erp_unit_access_denied
3513 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3515 struct zfcp_adapter *adapter = unit->port->adapter;
3517 debug_text_event(adapter->erp_dbf, 3, "u_access_block");
3518 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3519 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_ERP_FAILED |
3520 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3524 * function: zfcp_erp_adapter_access_changed
3529 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3531 struct zfcp_port *port;
3532 unsigned long flags;
3534 debug_text_event(adapter->erp_dbf, 3, "a_access_unblock");
3535 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3537 read_lock_irqsave(&zfcp_data.config_lock, flags);
3538 if (adapter->nameserver_port)
3539 zfcp_erp_port_access_changed(adapter->nameserver_port);
3540 list_for_each_entry(port, &adapter->port_list_head, list)
3541 if (port != adapter->nameserver_port)
3542 zfcp_erp_port_access_changed(port);
3543 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3547 * function: zfcp_erp_port_access_changed
3552 zfcp_erp_port_access_changed(struct zfcp_port *port)
3554 struct zfcp_adapter *adapter = port->adapter;
3555 struct zfcp_unit *unit;
3557 debug_text_event(adapter->erp_dbf, 3, "p_access_unblock");
3558 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3560 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3562 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3563 list_for_each_entry(unit, &port->unit_list_head, list)
3564 zfcp_erp_unit_access_changed(unit);
3568 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3569 "(due to ACT update)\n",
3570 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3571 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3572 ZFCP_LOG_NORMAL("failed reopen of port"
3573 "(adapter %s, wwpn=0x%016Lx)\n",
3574 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3578 * function: zfcp_erp_unit_access_changed
3583 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3585 struct zfcp_adapter *adapter = unit->port->adapter;
3587 debug_text_event(adapter->erp_dbf, 3, "u_access_unblock");
3588 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3590 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status))
3593 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3594 " on adapter %s (due to ACT update)\n",
3595 unit->fcp_lun, unit->port->wwpn,
3596 zfcp_get_busid_by_adapter(adapter));
3597 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3598 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3599 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3600 zfcp_get_busid_by_adapter(adapter),
3601 unit->port->wwpn, unit->fcp_lun);
3604 #undef ZFCP_LOG_AREA