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_port *);
39 static void zfcp_erp_adisc_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
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_xport(struct zfcp_erp_action *);
86 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
87 struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
90 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
93 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
94 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
97 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
98 struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
101 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
104 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
105 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
106 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
108 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
109 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
110 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
111 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
113 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
114 struct zfcp_port *, struct zfcp_unit *);
115 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
116 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
117 struct zfcp_port *, struct zfcp_unit *,
120 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
121 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
124 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
126 static void zfcp_erp_memwait_handler(unsigned long);
127 static void zfcp_erp_timeout_handler(unsigned long);
128 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
131 * zfcp_fsf_request_timeout_handler - called if a request timed out
132 * @data: pointer to adapter for handler function
134 * This function needs to be called if requests (ELS, Generic Service,
135 * or SCSI commands) exceed a certain time limit. The assumption is
136 * that after the time limit the adapter get stuck. So we trigger a reopen of
137 * the adapter. This should not be used for error recovery, SCSI abort
138 * commands and SCSI requests from SCSI mid-layer.
141 zfcp_fsf_request_timeout_handler(unsigned long data)
143 struct zfcp_adapter *adapter;
145 adapter = (struct zfcp_adapter *) data;
147 zfcp_erp_adapter_reopen(adapter, 0);
151 * function: zfcp_fsf_scsi_er_timeout_handler
153 * purpose: This function needs to be called whenever a SCSI error recovery
154 * action (abort/reset) does not return.
155 * Re-opening the adapter means that the command can be returned
156 * by zfcp (it is guarranteed that it does not return via the
157 * adapter anymore). The buffer can then be used again.
162 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
164 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
166 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
167 "Restarting all operations on the adapter %s\n",
168 zfcp_get_busid_by_adapter(adapter));
169 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
170 zfcp_erp_adapter_reopen(adapter, 0);
178 * purpose: called if an adapter failed,
179 * initiates adapter recovery which is done
182 * returns: 0 - initiated action succesfully
183 * <0 - failed to initiate action
186 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
190 debug_text_event(adapter->erp_dbf, 5, "a_ro");
191 ZFCP_LOG_DEBUG("reopen adapter %s\n",
192 zfcp_get_busid_by_adapter(adapter));
194 zfcp_erp_adapter_block(adapter, clear_mask);
196 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
197 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
198 zfcp_get_busid_by_adapter(adapter));
199 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
200 /* ensure propagation of failed status to new devices */
201 zfcp_erp_adapter_failed(adapter);
205 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
206 adapter, NULL, NULL);
215 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
216 * used to ensure the correct locking
218 * returns: 0 - initiated action succesfully
219 * <0 - failed to initiate action
222 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
227 read_lock_irqsave(&zfcp_data.config_lock, flags);
228 write_lock(&adapter->erp_lock);
229 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
230 write_unlock(&adapter->erp_lock);
231 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
244 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
248 retval = zfcp_erp_adapter_reopen(adapter,
249 ZFCP_STATUS_COMMON_RUNNING |
250 ZFCP_STATUS_COMMON_ERP_FAILED |
264 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
268 retval = zfcp_erp_port_reopen(port,
269 ZFCP_STATUS_COMMON_RUNNING |
270 ZFCP_STATUS_COMMON_ERP_FAILED |
284 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
288 retval = zfcp_erp_unit_reopen(unit,
289 ZFCP_STATUS_COMMON_RUNNING |
290 ZFCP_STATUS_COMMON_ERP_FAILED |
298 * zfcp_erp_adisc - send ADISC ELS command
299 * @port: port structure
302 zfcp_erp_adisc(struct zfcp_port *port)
304 struct zfcp_adapter *adapter = port->adapter;
305 struct zfcp_send_els *send_els;
306 struct zfcp_ls_adisc *adisc;
307 void *address = NULL;
309 struct timer_list *timer;
311 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
312 if (send_els == NULL)
314 memset(send_els, 0, sizeof(*send_els));
316 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
317 if (send_els->req == NULL)
319 memset(send_els->req, 0, sizeof(*send_els->req));
321 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
322 if (send_els->resp == NULL)
324 memset(send_els->resp, 0, sizeof(*send_els->resp));
326 address = (void *) get_zeroed_page(GFP_ATOMIC);
330 zfcp_address_to_sg(address, send_els->req);
331 address += PAGE_SIZE >> 1;
332 zfcp_address_to_sg(address, send_els->resp);
333 send_els->req_count = send_els->resp_count = 1;
335 send_els->adapter = adapter;
336 send_els->port = port;
337 send_els->d_id = port->d_id;
338 send_els->handler = zfcp_erp_adisc_handler;
339 send_els->handler_data = (unsigned long) send_els;
341 adisc = zfcp_sg_to_address(send_els->req);
342 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
344 send_els->req->length = sizeof(struct zfcp_ls_adisc);
345 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
347 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
348 without FC-AL-2 capability, so we don't set it */
349 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
350 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
351 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
352 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
353 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
354 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
355 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
356 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
359 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
364 timer->function = zfcp_fsf_request_timeout_handler;
365 timer->data = (unsigned long) adapter;
366 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
367 send_els->timer = timer;
369 retval = zfcp_fsf_send_els(send_els);
371 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
372 "0x%08x on adapter %s\n", send_els->d_id,
373 zfcp_get_busid_by_adapter(adapter));
374 del_timer(send_els->timer);
384 __free_pages(send_els->req->page, 0);
385 if (send_els != NULL) {
386 kfree(send_els->timer);
387 kfree(send_els->req);
388 kfree(send_els->resp);
397 * zfcp_erp_adisc_handler - handler for ADISC ELS command
398 * @data: pointer to struct zfcp_send_els
400 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
403 zfcp_erp_adisc_handler(unsigned long data)
405 struct zfcp_send_els *send_els;
406 struct zfcp_port *port;
407 struct zfcp_adapter *adapter;
409 struct zfcp_ls_adisc_acc *adisc;
411 send_els = (struct zfcp_send_els *) data;
413 del_timer(send_els->timer);
415 adapter = send_els->adapter;
416 port = send_els->port;
417 d_id = send_els->d_id;
419 /* request rejected or timed out */
420 if (send_els->status != 0) {
421 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
422 "force physical port reopen "
423 "(adapter %s, port d_id=0x%08x)\n",
424 zfcp_get_busid_by_adapter(adapter), d_id);
425 debug_text_event(adapter->erp_dbf, 3, "forcreop");
426 if (zfcp_erp_port_forced_reopen(port, 0))
427 ZFCP_LOG_NORMAL("failed reopen of port "
428 "(adapter %s, wwpn=0x%016Lx)\n",
429 zfcp_get_busid_by_port(port),
434 adisc = zfcp_sg_to_address(send_els->resp);
436 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
437 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
438 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
439 d_id, fc_host_port_id(adapter->scsi_host),
440 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
441 adisc->hard_nport_id, adisc->nport_id);
443 /* set wwnn for port */
445 port->wwnn = adisc->wwnn;
447 if (port->wwpn != adisc->wwpn) {
448 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
449 "port (adapter %s, wwpn=0x%016Lx, "
450 "adisc_resp_wwpn=0x%016Lx)\n",
451 zfcp_get_busid_by_port(port),
452 port->wwpn, (wwn_t) adisc->wwpn);
453 if (zfcp_erp_port_reopen(port, 0))
454 ZFCP_LOG_NORMAL("failed reopen of port "
455 "(adapter %s, wwpn=0x%016Lx)\n",
456 zfcp_get_busid_by_port(port),
462 __free_pages(send_els->req->page, 0);
463 kfree(send_els->timer);
464 kfree(send_els->req);
465 kfree(send_els->resp);
471 * zfcp_test_link - lightweight link test procedure
472 * @port: port to be tested
474 * Test status of a link to a remote port using the ELS command ADISC.
477 zfcp_test_link(struct zfcp_port *port)
482 retval = zfcp_erp_adisc(port);
485 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
486 "on adapter %s\n ", port->wwpn,
487 zfcp_get_busid_by_port(port));
488 retval = zfcp_erp_port_forced_reopen(port, 0);
490 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
491 "on adapter %s failed\n", port->wwpn,
492 zfcp_get_busid_by_port(port));
504 * purpose: called if a port failed to be opened normally
505 * initiates Forced Reopen recovery which is done
508 * returns: 0 - initiated action succesfully
509 * <0 - failed to initiate action
512 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
515 struct zfcp_adapter *adapter = port->adapter;
517 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
518 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
520 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
521 port->wwpn, zfcp_get_busid_by_port(port));
523 zfcp_erp_port_block(port, clear_mask);
525 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
526 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
527 "on adapter %s\n", port->wwpn,
528 zfcp_get_busid_by_port(port));
529 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
530 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
535 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
536 port->adapter, port, NULL);
545 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
546 * used to ensure the correct locking
548 * returns: 0 - initiated action succesfully
549 * <0 - failed to initiate action
552 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
556 struct zfcp_adapter *adapter;
558 adapter = port->adapter;
559 read_lock_irqsave(&zfcp_data.config_lock, flags);
560 write_lock(&adapter->erp_lock);
561 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
562 write_unlock(&adapter->erp_lock);
563 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
571 * purpose: called if a port is to be opened
572 * initiates Reopen recovery which is done
575 * returns: 0 - initiated action succesfully
576 * <0 - failed to initiate action
579 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
582 struct zfcp_adapter *adapter = port->adapter;
584 debug_text_event(adapter->erp_dbf, 5, "p_ro");
585 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
587 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
588 port->wwpn, zfcp_get_busid_by_port(port));
590 zfcp_erp_port_block(port, clear_mask);
592 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
593 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
594 "on adapter %s\n", port->wwpn,
595 zfcp_get_busid_by_port(port));
596 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
597 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
598 /* ensure propagation of failed status to new devices */
599 zfcp_erp_port_failed(port);
604 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
605 port->adapter, port, NULL);
612 * zfcp_erp_port_reopen - initiate reopen of a remote port
613 * @port: port to be reopened
614 * @clear_mask: specifies flags in port status to be cleared
615 * Return: 0 on success, < 0 on error
617 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
618 * correct locking. An error recovery task is initiated to do the reopen.
619 * To wait for the completion of the reopen zfcp_erp_wait should be used.
622 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
626 struct zfcp_adapter *adapter = port->adapter;
628 read_lock_irqsave(&zfcp_data.config_lock, flags);
629 write_lock(&adapter->erp_lock);
630 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
631 write_unlock(&adapter->erp_lock);
632 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
640 * purpose: called if a unit is to be opened
641 * initiates Reopen recovery which is done
644 * returns: 0 - initiated action succesfully
645 * <0 - failed to initiate action
648 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
651 struct zfcp_adapter *adapter = unit->port->adapter;
653 debug_text_event(adapter->erp_dbf, 5, "u_ro");
654 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
655 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
656 "on adapter %s\n", unit->fcp_lun,
657 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
659 zfcp_erp_unit_block(unit, clear_mask);
661 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
662 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
663 "on port 0x%016Lx on adapter %s\n",
664 unit->fcp_lun, unit->port->wwpn,
665 zfcp_get_busid_by_unit(unit));
666 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
667 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
673 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
674 unit->port->adapter, unit->port, unit);
680 * zfcp_erp_unit_reopen - initiate reopen of a unit
681 * @unit: unit to be reopened
682 * @clear_mask: specifies flags in unit status to be cleared
683 * Return: 0 on success, < 0 on error
685 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
686 * locking. An error recovery task is initiated to do the reopen.
687 * To wait for the completion of the reopen zfcp_erp_wait should be used.
690 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
694 struct zfcp_adapter *adapter;
695 struct zfcp_port *port;
698 adapter = port->adapter;
700 read_lock_irqsave(&zfcp_data.config_lock, flags);
701 write_lock(&adapter->erp_lock);
702 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
703 write_unlock(&adapter->erp_lock);
704 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
712 * purpose: disable I/O,
713 * return any open requests and clean them up,
714 * aim: no pending and incoming I/O
719 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
721 debug_text_event(adapter->erp_dbf, 6, "a_bl");
722 zfcp_erp_modify_adapter_status(adapter,
723 ZFCP_STATUS_COMMON_UNBLOCKED |
724 clear_mask, ZFCP_CLEAR);
730 * purpose: enable I/O
735 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
737 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
738 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
744 * purpose: disable I/O,
745 * return any open requests and clean them up,
746 * aim: no pending and incoming I/O
751 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
753 struct zfcp_adapter *adapter = port->adapter;
755 debug_text_event(adapter->erp_dbf, 6, "p_bl");
756 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
757 zfcp_erp_modify_port_status(port,
758 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
765 * purpose: enable I/O
770 zfcp_erp_port_unblock(struct zfcp_port *port)
772 struct zfcp_adapter *adapter = port->adapter;
774 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
775 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
776 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
782 * purpose: disable I/O,
783 * return any open requests and clean them up,
784 * aim: no pending and incoming I/O
789 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
791 struct zfcp_adapter *adapter = unit->port->adapter;
793 debug_text_event(adapter->erp_dbf, 6, "u_bl");
794 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
795 zfcp_erp_modify_unit_status(unit,
796 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
803 * purpose: enable I/O
808 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
810 struct zfcp_adapter *adapter = unit->port->adapter;
812 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
813 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
814 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
825 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
827 struct zfcp_adapter *adapter = erp_action->adapter;
829 debug_text_event(adapter->erp_dbf, 4, "a_ar");
830 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
832 zfcp_erp_action_to_ready(erp_action);
833 up(&adapter->erp_ready_sem);
841 * returns: <0 erp_action not found in any list
842 * ZFCP_ERP_ACTION_READY erp_action is in ready list
843 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
845 * locks: erp_lock must be held
848 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
850 int retval = -EINVAL;
851 struct list_head *entry;
852 struct zfcp_erp_action *entry_erp_action;
853 struct zfcp_adapter *adapter = erp_action->adapter;
855 /* search in running list */
856 list_for_each(entry, &adapter->erp_running_head) {
858 list_entry(entry, struct zfcp_erp_action, list);
859 if (entry_erp_action == erp_action) {
860 retval = ZFCP_ERP_ACTION_RUNNING;
864 /* search in ready list */
865 list_for_each(entry, &adapter->erp_ready_head) {
867 list_entry(entry, struct zfcp_erp_action, list);
868 if (entry_erp_action == erp_action) {
869 retval = ZFCP_ERP_ACTION_READY;
879 * purpose: checks current status of action (timed out, dismissed, ...)
880 * and does appropriate preparations (dismiss fsf request, ...)
882 * locks: called under erp_lock (disabled interrupts)
887 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
890 struct zfcp_fsf_req *fsf_req = NULL;
891 struct zfcp_adapter *adapter = erp_action->adapter;
893 if (erp_action->fsf_req) {
894 /* take lock to ensure that request is not being deleted meanwhile */
895 spin_lock(&adapter->fsf_req_list_lock);
896 /* check whether fsf req does still exist */
897 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
898 if (fsf_req == erp_action->fsf_req)
900 if (fsf_req && (fsf_req->erp_action == erp_action)) {
901 /* fsf_req still exists */
902 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
903 debug_event(adapter->erp_dbf, 3, &fsf_req,
904 sizeof (unsigned long));
905 /* dismiss fsf_req of timed out or dismissed erp_action */
906 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
907 ZFCP_STATUS_ERP_TIMEDOUT)) {
908 debug_text_event(adapter->erp_dbf, 3,
910 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
912 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
913 ZFCP_LOG_NORMAL("error: erp step timed out "
914 "(action=%d, fsf_req=%p)\n ",
916 erp_action->fsf_req);
919 * If fsf_req is neither dismissed nor completed
920 * then keep it running asynchronously and don't mess
921 * with the association of erp_action and fsf_req.
923 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
924 ZFCP_STATUS_FSFREQ_DISMISSED)) {
925 /* forget about association between fsf_req
927 fsf_req->erp_action = NULL;
928 erp_action->fsf_req = NULL;
931 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
933 * even if this fsf_req has gone, forget about
934 * association between erp_action and fsf_req
936 erp_action->fsf_req = NULL;
938 spin_unlock(&adapter->fsf_req_list_lock);
940 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
946 * purpose: generic handler for asynchronous events related to erp_action events
947 * (normal completion, time-out, dismissing, retry after
948 * low memory condition)
950 * note: deletion of timer is not required (e.g. in case of a time-out),
951 * but a second try does no harm,
952 * we leave it in here to allow for greater simplification
954 * returns: 0 - there was an action to handle
958 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
959 unsigned long set_mask)
962 struct zfcp_adapter *adapter = erp_action->adapter;
964 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
965 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
966 debug_event(adapter->erp_dbf, 2, &erp_action->action,
968 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
969 del_timer(&erp_action->timer);
970 erp_action->status |= set_mask;
971 zfcp_erp_action_ready(erp_action);
974 /* action is ready or gone - nothing to do */
975 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
976 debug_event(adapter->erp_dbf, 3, &erp_action->action,
985 * purpose: generic handler for asynchronous events related to erp_action
986 * events (normal completion, time-out, dismissing, retry after
987 * low memory condition)
989 * note: deletion of timer is not required (e.g. in case of a time-out),
990 * but a second try does no harm,
991 * we leave it in here to allow for greater simplification
993 * returns: 0 - there was an action to handle
997 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
998 unsigned long set_mask)
1000 struct zfcp_adapter *adapter = erp_action->adapter;
1001 unsigned long flags;
1004 write_lock_irqsave(&adapter->erp_lock, flags);
1005 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1006 write_unlock_irqrestore(&adapter->erp_lock, flags);
1012 * purpose: is called for erp_action which was slept waiting for
1013 * memory becoming avaliable,
1014 * will trigger that this action will be continued
1017 zfcp_erp_memwait_handler(unsigned long data)
1019 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1020 struct zfcp_adapter *adapter = erp_action->adapter;
1022 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1023 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1025 zfcp_erp_async_handler(erp_action, 0);
1029 * purpose: is called if an asynchronous erp step timed out,
1030 * action gets an appropriate flag and will be processed
1034 zfcp_erp_timeout_handler(unsigned long data)
1036 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1037 struct zfcp_adapter *adapter = erp_action->adapter;
1039 debug_text_event(adapter->erp_dbf, 2, "a_th");
1040 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1042 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1046 * purpose: is called for an erp_action which needs to be ended
1047 * though not being done,
1048 * this is usually required if an higher is generated,
1049 * action gets an appropriate flag and will be processed
1052 * locks: erp_lock held (thus we need to call another handler variant)
1055 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1057 struct zfcp_adapter *adapter = erp_action->adapter;
1059 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1060 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1062 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1068 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1072 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1074 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1076 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1078 zfcp_get_busid_by_adapter(adapter));
1079 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1081 wait_event(adapter->erp_thread_wqh,
1082 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1084 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1087 return (retval < 0);
1097 * context: process (i.e. proc-fs or rmmod/insmod)
1099 * note: The caller of this routine ensures that the specified
1100 * adapter has been shut down and that this operation
1101 * has been completed. Thus, there are no pending erp_actions
1102 * which would need to be handled here.
1105 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1109 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1110 up(&adapter->erp_ready_sem);
1112 wait_event(adapter->erp_thread_wqh,
1113 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1116 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1119 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1125 * purpose: is run as a kernel thread,
1126 * goes through list of error recovery actions of associated adapter
1127 * and delegates single action to execution
1132 zfcp_erp_thread(void *data)
1134 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1135 struct list_head *next;
1136 struct zfcp_erp_action *erp_action;
1137 unsigned long flags;
1139 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1140 /* Block all signals */
1141 siginitsetinv(¤t->blocked, 0);
1142 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1143 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1144 wake_up(&adapter->erp_thread_wqh);
1146 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1147 &adapter->status)) {
1149 write_lock_irqsave(&adapter->erp_lock, flags);
1150 next = adapter->erp_ready_head.prev;
1151 write_unlock_irqrestore(&adapter->erp_lock, flags);
1153 if (next != &adapter->erp_ready_head) {
1155 list_entry(next, struct zfcp_erp_action, list);
1157 * process action (incl. [re]moving it
1158 * from 'ready' queue)
1160 zfcp_erp_strategy(erp_action);
1164 * sleep as long as there is nothing to do, i.e.
1165 * no action in 'ready' queue to be processed and
1166 * thread is not to be killed
1168 down_interruptible(&adapter->erp_ready_sem);
1169 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1172 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1173 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1174 wake_up(&adapter->erp_thread_wqh);
1182 * purpose: drives single error recovery action and schedules higher and
1183 * subordinate actions, if necessary
1185 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1186 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1187 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1188 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1189 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1192 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1195 struct zfcp_adapter *adapter = erp_action->adapter;
1196 struct zfcp_port *port = erp_action->port;
1197 struct zfcp_unit *unit = erp_action->unit;
1198 int action = erp_action->action;
1199 u32 status = erp_action->status;
1200 unsigned long flags;
1202 /* serialise dismissing, timing out, moving, enqueueing */
1203 read_lock_irqsave(&zfcp_data.config_lock, flags);
1204 write_lock(&adapter->erp_lock);
1206 /* dequeue dismissed action and leave, if required */
1207 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1208 if (retval == ZFCP_ERP_DISMISSED) {
1209 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1214 * move action to 'running' queue before processing it
1215 * (to avoid a race condition regarding moving the
1216 * action to the 'running' queue and back)
1218 zfcp_erp_action_to_running(erp_action);
1221 * try to process action as far as possible,
1222 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1223 * afterwards the lock is required again for the following reasons:
1224 * - dequeueing of finished action and enqueueing of
1225 * follow-up actions must be atomic so that any other
1226 * reopen-routine does not believe there is nothing to do
1227 * and that it is safe to enqueue something else,
1228 * - we want to force any control thread which is dismissing
1229 * actions to finish this before we decide about
1230 * necessary steps to be taken here further
1232 write_unlock(&adapter->erp_lock);
1233 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1234 retval = zfcp_erp_strategy_do_action(erp_action);
1235 read_lock_irqsave(&zfcp_data.config_lock, flags);
1236 write_lock(&adapter->erp_lock);
1239 * check for dismissed status again to avoid follow-up actions,
1240 * failing of targets and so on for dismissed actions
1242 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1245 case ZFCP_ERP_DISMISSED:
1246 /* leave since this action has ridden to its ancestors */
1247 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1249 case ZFCP_ERP_NOMEM:
1250 /* no memory to continue immediately, let it sleep */
1251 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1252 ++adapter->erp_low_mem_count;
1253 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1255 /* This condition is true if there is no memory available
1256 for any erp_action on this adapter. This implies that there
1257 are no elements in the memory pool(s) left for erp_actions.
1258 This might happen if an erp_action that used a memory pool
1259 element was timed out.
1261 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1262 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1263 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1264 "restarting I/O on adapter %s "
1265 "to free mempool\n",
1266 zfcp_get_busid_by_adapter(adapter));
1267 zfcp_erp_adapter_reopen_internal(adapter, 0);
1269 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1270 retval = zfcp_erp_strategy_memwait(erp_action);
1273 case ZFCP_ERP_CONTINUES:
1274 /* leave since this action runs asynchronously */
1275 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1276 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1277 --adapter->erp_low_mem_count;
1278 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1282 /* ok, finished action (whatever its result is) */
1284 /* check for unrecoverable targets */
1285 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1287 /* action must be dequeued (here to allow for further ones) */
1288 zfcp_erp_action_dequeue(erp_action);
1291 * put this target through the erp mill again if someone has
1292 * requested to change the status of a target being online
1293 * to offline or the other way around
1294 * (old retval is preserved if nothing has to be done here)
1296 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1297 port, unit, retval);
1300 * leave if target is in permanent error state or if
1301 * action is repeated in order to process state change
1303 if (retval == ZFCP_ERP_EXIT) {
1304 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1308 /* trigger follow up actions */
1309 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1312 write_unlock(&adapter->erp_lock);
1313 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1315 if (retval != ZFCP_ERP_CONTINUES)
1316 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1319 * a few tasks remain when the erp queues are empty
1320 * (don't do that if the last action evaluated was dismissed
1321 * since this clearly indicates that there is more to come) :
1322 * - close the name server port if it is open yet
1323 * (enqueues another [probably] final action)
1324 * - otherwise, wake up whoever wants to be woken when we are
1327 if (retval != ZFCP_ERP_DISMISSED)
1328 zfcp_erp_strategy_check_queues(adapter);
1330 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1340 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1341 * retval - otherwise
1344 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1346 struct zfcp_adapter *adapter = erp_action->adapter;
1348 zfcp_erp_strategy_check_fsfreq(erp_action);
1350 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1351 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1352 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1353 zfcp_erp_action_dequeue(erp_action);
1354 retval = ZFCP_ERP_DISMISSED;
1356 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1369 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1371 int retval = ZFCP_ERP_FAILED;
1372 struct zfcp_adapter *adapter = erp_action->adapter;
1375 * try to execute/continue action as far as possible,
1376 * note: no lock in subsequent strategy routines
1377 * (this allows these routine to call schedule, e.g.
1378 * kmalloc with such flags or qdio_initialize & friends)
1379 * Note: in case of timeout, the seperate strategies will fail
1380 * anyhow. No need for a special action. Even worse, a nameserver
1381 * failure would not wake up waiting ports without the call.
1383 switch (erp_action->action) {
1385 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1386 retval = zfcp_erp_adapter_strategy(erp_action);
1389 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1390 retval = zfcp_erp_port_forced_strategy(erp_action);
1393 case ZFCP_ERP_ACTION_REOPEN_PORT:
1394 retval = zfcp_erp_port_strategy(erp_action);
1397 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1398 retval = zfcp_erp_unit_strategy(erp_action);
1402 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1403 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1405 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1406 "adapter %s (action=%d)\n",
1407 zfcp_get_busid_by_adapter(erp_action->adapter),
1408 erp_action->action);
1417 * purpose: triggers retry of this action after a certain amount of time
1418 * by means of timer provided by erp_action
1420 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1423 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1425 int retval = ZFCP_ERP_CONTINUES;
1426 struct zfcp_adapter *adapter = erp_action->adapter;
1428 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1429 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1430 init_timer(&erp_action->timer);
1431 erp_action->timer.function = zfcp_erp_memwait_handler;
1432 erp_action->timer.data = (unsigned long) erp_action;
1433 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1434 add_timer(&erp_action->timer);
1440 * function: zfcp_erp_adapter_failed
1442 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1446 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1448 zfcp_erp_modify_adapter_status(adapter,
1449 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1450 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1451 zfcp_get_busid_by_adapter(adapter));
1452 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1456 * function: zfcp_erp_port_failed
1458 * purpose: sets the port and all underlying devices to ERP_FAILED
1462 zfcp_erp_port_failed(struct zfcp_port *port)
1464 zfcp_erp_modify_port_status(port,
1465 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1467 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1468 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1469 "port d_id=0x%08x)\n",
1470 zfcp_get_busid_by_port(port), port->d_id);
1472 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1473 zfcp_get_busid_by_port(port), port->wwpn);
1475 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1476 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1480 * function: zfcp_erp_unit_failed
1482 * purpose: sets the unit to ERP_FAILED
1486 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1488 zfcp_erp_modify_unit_status(unit,
1489 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1491 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1492 " on adapter %s\n", unit->fcp_lun,
1493 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1494 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1495 debug_event(unit->port->adapter->erp_dbf, 2,
1496 &unit->fcp_lun, sizeof (fcp_lun_t));
1500 * function: zfcp_erp_strategy_check_target
1502 * purpose: increments the erp action count on the device currently in
1503 * recovery if the action failed or resets the count in case of
1504 * success. If a maximum count is exceeded the device is marked
1506 * The 'blocked' state of a target which has been recovered
1507 * successfully is reset.
1509 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1510 * ZFCP_ERP_SUCCEEDED - action finished successfully
1511 * ZFCP_ERP_EXIT - action failed and will not continue
1514 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1516 struct zfcp_adapter *adapter = erp_action->adapter;
1517 struct zfcp_port *port = erp_action->port;
1518 struct zfcp_unit *unit = erp_action->unit;
1520 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1521 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1522 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1524 switch (erp_action->action) {
1526 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1527 result = zfcp_erp_strategy_check_unit(unit, result);
1530 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1531 case ZFCP_ERP_ACTION_REOPEN_PORT:
1532 result = zfcp_erp_strategy_check_port(port, result);
1535 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1536 result = zfcp_erp_strategy_check_adapter(adapter, result);
1551 zfcp_erp_strategy_statechange(int action,
1553 struct zfcp_adapter *adapter,
1554 struct zfcp_port *port,
1555 struct zfcp_unit *unit, int retval)
1557 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1558 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1562 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1563 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1565 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1566 retval = ZFCP_ERP_EXIT;
1570 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1571 case ZFCP_ERP_ACTION_REOPEN_PORT:
1572 if (zfcp_erp_strategy_statechange_detected(&port->status,
1574 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1575 retval = ZFCP_ERP_EXIT;
1579 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1580 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1582 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1583 retval = ZFCP_ERP_EXIT;
1599 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1602 /* take it online */
1603 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1604 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1605 /* take it offline */
1606 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1607 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1618 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1620 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1621 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1622 sizeof (fcp_lun_t));
1625 case ZFCP_ERP_SUCCEEDED :
1626 atomic_set(&unit->erp_counter, 0);
1627 zfcp_erp_unit_unblock(unit);
1629 case ZFCP_ERP_FAILED :
1630 atomic_inc(&unit->erp_counter);
1631 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1632 zfcp_erp_unit_failed(unit);
1634 case ZFCP_ERP_EXIT :
1639 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1640 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1641 result = ZFCP_ERP_EXIT;
1655 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1657 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1658 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1661 case ZFCP_ERP_SUCCEEDED :
1662 atomic_set(&port->erp_counter, 0);
1663 zfcp_erp_port_unblock(port);
1665 case ZFCP_ERP_FAILED :
1666 atomic_inc(&port->erp_counter);
1667 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1668 zfcp_erp_port_failed(port);
1670 case ZFCP_ERP_EXIT :
1675 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1676 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1677 result = ZFCP_ERP_EXIT;
1691 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1693 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1696 case ZFCP_ERP_SUCCEEDED :
1697 atomic_set(&adapter->erp_counter, 0);
1698 zfcp_erp_adapter_unblock(adapter);
1700 case ZFCP_ERP_FAILED :
1701 atomic_inc(&adapter->erp_counter);
1702 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1703 zfcp_erp_adapter_failed(adapter);
1705 case ZFCP_ERP_EXIT :
1710 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1711 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1712 result = ZFCP_ERP_EXIT;
1721 * purpose: remaining things in good cases,
1722 * escalation in bad cases
1727 zfcp_erp_strategy_followup_actions(int action,
1728 struct zfcp_adapter *adapter,
1729 struct zfcp_port *port,
1730 struct zfcp_unit *unit, int status)
1732 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1733 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1735 /* initiate follow-up actions depending on success of finished action */
1738 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1739 if (status == ZFCP_ERP_SUCCEEDED)
1740 zfcp_erp_port_reopen_all_internal(adapter, 0);
1742 zfcp_erp_adapter_reopen_internal(adapter, 0);
1745 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1746 if (status == ZFCP_ERP_SUCCEEDED)
1747 zfcp_erp_port_reopen_internal(port, 0);
1749 zfcp_erp_adapter_reopen_internal(adapter, 0);
1752 case ZFCP_ERP_ACTION_REOPEN_PORT:
1753 if (status == ZFCP_ERP_SUCCEEDED)
1754 zfcp_erp_unit_reopen_all_internal(port, 0);
1756 zfcp_erp_port_forced_reopen_internal(port, 0);
1759 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1760 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1762 zfcp_erp_port_reopen_internal(unit->port, 0);
1777 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1779 unsigned long flags;
1781 read_lock_irqsave(&zfcp_data.config_lock, flags);
1782 read_lock(&adapter->erp_lock);
1783 if (list_empty(&adapter->erp_ready_head) &&
1784 list_empty(&adapter->erp_running_head)) {
1785 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1786 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1788 wake_up(&adapter->erp_done_wqh);
1790 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1791 read_unlock(&adapter->erp_lock);
1792 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1798 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1799 * @adapter: adapter for which to wait for completion of its error recovery
1803 zfcp_erp_wait(struct zfcp_adapter *adapter)
1807 wait_event(adapter->erp_done_wqh,
1808 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1815 * function: zfcp_erp_modify_adapter_status
1821 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1822 u32 mask, int set_or_clear)
1824 struct zfcp_port *port;
1825 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1827 if (set_or_clear == ZFCP_SET) {
1828 atomic_set_mask(mask, &adapter->status);
1829 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1831 atomic_clear_mask(mask, &adapter->status);
1832 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1833 atomic_set(&adapter->erp_counter, 0);
1834 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1836 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1838 /* Deal with all underlying devices, only pass common_mask */
1840 list_for_each_entry(port, &adapter->port_list_head, list)
1841 zfcp_erp_modify_port_status(port, common_mask,
1846 * function: zfcp_erp_modify_port_status
1848 * purpose: sets the port and all underlying devices to ERP_FAILED
1852 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1854 struct zfcp_unit *unit;
1855 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1857 if (set_or_clear == ZFCP_SET) {
1858 atomic_set_mask(mask, &port->status);
1859 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1861 atomic_clear_mask(mask, &port->status);
1862 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1863 atomic_set(&port->erp_counter, 0);
1864 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1866 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1867 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1869 /* Modify status of all underlying devices, only pass common mask */
1871 list_for_each_entry(unit, &port->unit_list_head, list)
1872 zfcp_erp_modify_unit_status(unit, common_mask,
1877 * function: zfcp_erp_modify_unit_status
1879 * purpose: sets the unit to ERP_FAILED
1883 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1885 if (set_or_clear == ZFCP_SET) {
1886 atomic_set_mask(mask, &unit->status);
1887 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1889 atomic_clear_mask(mask, &unit->status);
1890 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1891 atomic_set(&unit->erp_counter, 0);
1893 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1895 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1896 sizeof (fcp_lun_t));
1897 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1903 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1904 * used to ensure the correct locking
1906 * returns: 0 - initiated action succesfully
1907 * <0 - failed to initiate action
1910 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1913 unsigned long flags;
1915 read_lock_irqsave(&zfcp_data.config_lock, flags);
1916 write_lock(&adapter->erp_lock);
1917 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1918 write_unlock(&adapter->erp_lock);
1919 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1932 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1935 struct zfcp_port *port;
1937 list_for_each_entry(port, &adapter->port_list_head, list)
1938 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1939 zfcp_erp_port_reopen_internal(port, clear_mask);
1952 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1955 struct zfcp_unit *unit;
1957 list_for_each_entry(unit, &port->unit_list_head, list)
1958 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1966 * purpose: this routine executes the 'Reopen Adapter' action
1967 * (the entire action is processed synchronously, since
1968 * there are no actions which might be run concurrently
1971 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1972 * ZFCP_ERP_FAILED - action finished unsuccessfully
1975 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1978 struct zfcp_adapter *adapter = erp_action->adapter;
1980 retval = zfcp_erp_adapter_strategy_close(erp_action);
1981 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1982 retval = ZFCP_ERP_EXIT;
1984 retval = zfcp_erp_adapter_strategy_open(erp_action);
1986 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1987 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1988 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1990 if (retval == ZFCP_ERP_FAILED) {
1991 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1992 "to recover itself\n",
1993 zfcp_get_busid_by_adapter(adapter));
1994 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2005 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2006 * ZFCP_ERP_FAILED - action finished unsuccessfully
2009 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2013 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2014 &erp_action->adapter->status);
2015 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2016 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2017 &erp_action->adapter->status);
2027 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2028 * ZFCP_ERP_FAILED - action finished unsuccessfully
2031 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2035 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2036 &erp_action->adapter->status);
2037 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2038 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2039 &erp_action->adapter->status);
2045 * function: zfcp_register_adapter
2047 * purpose: allocate the irq associated with this devno and register
2048 * the FSF adapter with the SCSI stack
2053 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2055 int retval = ZFCP_ERP_SUCCEEDED;
2060 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2061 if (retval != ZFCP_ERP_SUCCEEDED)
2064 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2065 if (retval != ZFCP_ERP_SUCCEEDED)
2066 goto failed_openfcp;
2068 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2072 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2073 &erp_action->adapter->status);
2076 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2077 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2084 * function: zfcp_qdio_init
2086 * purpose: setup QDIO operation for specified adapter
2088 * returns: 0 - successful setup
2092 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2096 volatile struct qdio_buffer_element *sbale;
2097 struct zfcp_adapter *adapter = erp_action->adapter;
2099 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2100 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2102 zfcp_get_busid_by_adapter(adapter));
2106 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2107 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2109 zfcp_get_busid_by_adapter(adapter));
2110 goto failed_qdio_establish;
2112 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2114 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2115 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2117 zfcp_get_busid_by_adapter(adapter));
2118 goto failed_qdio_activate;
2120 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2123 * put buffers into response queue,
2125 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2126 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2128 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2132 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2133 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2134 zfcp_get_busid_by_adapter(adapter),
2135 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2137 retval = do_QDIO(adapter->ccw_device,
2138 QDIO_FLAG_SYNC_INPUT,
2139 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2142 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2144 goto failed_do_qdio;
2146 adapter->response_queue.free_index = 0;
2147 atomic_set(&adapter->response_queue.free_count, 0);
2148 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2149 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2151 /* set index of first avalable SBALS / number of available SBALS */
2152 adapter->request_queue.free_index = 0;
2153 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2154 adapter->request_queue.distance_from_int = 0;
2156 /* initialize waitqueue used to wait for free SBALs in requests queue */
2157 init_waitqueue_head(&adapter->request_wq);
2159 /* ok, we did it - skip all cleanups for different failures */
2160 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2161 retval = ZFCP_ERP_SUCCEEDED;
2167 failed_qdio_activate:
2168 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2169 while (qdio_shutdown(adapter->ccw_device,
2170 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2172 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2174 failed_qdio_establish:
2176 retval = ZFCP_ERP_FAILED;
2183 * function: zfcp_qdio_cleanup
2185 * purpose: cleans up QDIO operation for the specified adapter
2187 * returns: 0 - successful cleanup
2188 * !0 - failed cleanup
2191 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2193 int retval = ZFCP_ERP_SUCCEEDED;
2196 struct zfcp_adapter *adapter = erp_action->adapter;
2198 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2199 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2200 "queues on adapter %s\n",
2201 zfcp_get_busid_by_adapter(adapter));
2202 retval = ZFCP_ERP_FAILED;
2207 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2208 * do_QDIO won't be called while qdio_shutdown is in progress.
2211 write_lock_irq(&adapter->request_queue.queue_lock);
2212 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2213 write_unlock_irq(&adapter->request_queue.queue_lock);
2215 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2216 while (qdio_shutdown(adapter->ccw_device,
2217 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2219 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2222 * First we had to stop QDIO operation.
2223 * Now it is safe to take the following actions.
2226 /* Cleanup only necessary when there are unacknowledged buffers */
2227 if (atomic_read(&adapter->request_queue.free_count)
2228 < QDIO_MAX_BUFFERS_PER_Q) {
2229 first_used = (adapter->request_queue.free_index +
2230 atomic_read(&adapter->request_queue.free_count))
2231 % QDIO_MAX_BUFFERS_PER_Q;
2232 used_count = QDIO_MAX_BUFFERS_PER_Q -
2233 atomic_read(&adapter->request_queue.free_count);
2234 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2235 first_used, used_count);
2237 adapter->response_queue.free_index = 0;
2238 atomic_set(&adapter->response_queue.free_count, 0);
2239 adapter->request_queue.free_index = 0;
2240 atomic_set(&adapter->request_queue.free_count, 0);
2241 adapter->request_queue.distance_from_int = 0;
2247 * function: zfcp_fsf_init
2249 * purpose: initializes FSF operation for the specified adapter
2251 * returns: 0 - succesful initialization of FSF operation
2252 * !0 - failed to initialize FSF operation
2255 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2259 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2260 &erp_action->adapter->status)) {
2261 zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2262 atomic_set(&erp_action->adapter->erp_counter, 0);
2263 return ZFCP_ERP_FAILED;
2266 xconfig = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2267 xport = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2268 if ((xconfig == ZFCP_ERP_FAILED) || (xport == ZFCP_ERP_FAILED))
2269 return ZFCP_ERP_FAILED;
2271 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2282 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2284 int retval = ZFCP_ERP_SUCCEEDED;
2286 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2287 struct zfcp_adapter *adapter = erp_action->adapter;
2289 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2291 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2292 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2294 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2295 write_lock(&adapter->erp_lock);
2296 zfcp_erp_action_to_running(erp_action);
2297 write_unlock(&adapter->erp_lock);
2298 zfcp_erp_timeout_init(erp_action);
2299 if (zfcp_fsf_exchange_config_data(erp_action)) {
2300 retval = ZFCP_ERP_FAILED;
2301 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2302 ZFCP_LOG_INFO("error: initiation of exchange of "
2303 "configuration data failed for "
2305 zfcp_get_busid_by_adapter(adapter));
2308 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2309 ZFCP_LOG_DEBUG("Xchange underway\n");
2313 * Both the normal completion handler as well as the timeout
2314 * handler will do an 'up' when the 'exchange config data'
2315 * request completes or times out. Thus, the signal to go on
2316 * won't be lost utilizing this semaphore.
2317 * Furthermore, this 'adapter_reopen' action is
2318 * guaranteed to be the only action being there (highest action
2319 * which prevents other actions from being created).
2320 * Resulting from that, the wake signal recognized here
2321 * _must_ be the one belonging to the 'exchange config
2324 down(&adapter->erp_ready_sem);
2325 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2326 ZFCP_LOG_INFO("error: exchange of configuration data "
2327 "for adapter %s timed out\n",
2328 zfcp_get_busid_by_adapter(adapter));
2332 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2336 ZFCP_LOG_DEBUG("host connection still initialising... "
2337 "waiting and retrying...\n");
2338 /* sleep a little bit before retry */
2339 msleep(jiffies_to_msecs(sleep));
2343 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2344 &adapter->status)) {
2345 ZFCP_LOG_INFO("error: exchange of configuration data for "
2346 "adapter %s failed\n",
2347 zfcp_get_busid_by_adapter(adapter));
2348 retval = ZFCP_ERP_FAILED;
2355 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2357 int retval = ZFCP_ERP_SUCCEEDED;
2360 struct zfcp_adapter *adapter = erp_action->adapter;
2362 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2364 for (retries = 0; ; retries++) {
2365 ZFCP_LOG_DEBUG("Doing exchange port data\n");
2366 zfcp_erp_action_to_running(erp_action);
2367 zfcp_erp_timeout_init(erp_action);
2368 if (zfcp_fsf_exchange_port_data(erp_action, adapter, NULL)) {
2369 retval = ZFCP_ERP_FAILED;
2370 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2371 ZFCP_LOG_INFO("error: initiation of exchange of "
2372 "port data failed for adapter %s\n",
2373 zfcp_get_busid_by_adapter(adapter));
2376 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2377 ZFCP_LOG_DEBUG("Xchange underway\n");
2381 * Both the normal completion handler as well as the timeout
2382 * handler will do an 'up' when the 'exchange port data'
2383 * request completes or times out. Thus, the signal to go on
2384 * won't be lost utilizing this semaphore.
2385 * Furthermore, this 'adapter_reopen' action is
2386 * guaranteed to be the only action being there (highest action
2387 * which prevents other actions from being created).
2388 * Resulting from that, the wake signal recognized here
2389 * _must_ be the one belonging to the 'exchange port
2392 down(&adapter->erp_ready_sem);
2393 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2394 ZFCP_LOG_INFO("error: exchange of port data "
2395 "for adapter %s timed out\n",
2396 zfcp_get_busid_by_adapter(adapter));
2400 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2404 ZFCP_LOG_DEBUG("host connection still initialising... "
2405 "waiting and retrying...\n");
2406 /* sleep a little bit before retry */
2407 sleep = retries < ZFCP_EXCHANGE_PORT_DATA_SHORT_RETRIES ?
2408 ZFCP_EXCHANGE_PORT_DATA_SHORT_SLEEP :
2409 ZFCP_EXCHANGE_PORT_DATA_LONG_SLEEP;
2410 msleep(jiffies_to_msecs(sleep));
2413 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2414 &adapter->status)) {
2415 ZFCP_LOG_INFO("error: exchange of port data for "
2416 "adapter %s failed\n",
2417 zfcp_get_busid_by_adapter(adapter));
2418 retval = ZFCP_ERP_FAILED;
2432 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2435 int retval = ZFCP_ERP_SUCCEEDED;
2437 struct zfcp_adapter *adapter = erp_action->adapter;
2440 adapter->status_read_failed = 0;
2441 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2442 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2444 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2445 "notification failed on adapter %s\n",
2446 zfcp_get_busid_by_adapter(adapter));
2447 retval = ZFCP_ERP_FAILED;
2457 * function: zfcp_fsf_cleanup
2459 * purpose: cleanup FSF operation for specified adapter
2461 * returns: 0 - FSF operation successfully cleaned up
2462 * !0 - failed to cleanup FSF operation for this adapter
2465 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2467 int retval = ZFCP_ERP_SUCCEEDED;
2468 struct zfcp_adapter *adapter = erp_action->adapter;
2471 * wake waiting initiators of requests,
2472 * return SCSI commands (with error status),
2473 * clean up all requests (synchronously)
2475 zfcp_fsf_req_dismiss_all(adapter);
2476 /* reset FSF request sequence number */
2477 adapter->fsf_req_seq_no = 0;
2478 /* all ports and units are closed */
2479 zfcp_erp_modify_adapter_status(adapter,
2480 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2488 * purpose: this routine executes the 'Reopen Physical Port' action
2490 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2491 * ZFCP_ERP_SUCCEEDED - action finished successfully
2492 * ZFCP_ERP_FAILED - action finished unsuccessfully
2495 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2497 int retval = ZFCP_ERP_FAILED;
2498 struct zfcp_port *port = erp_action->port;
2499 struct zfcp_adapter *adapter = erp_action->adapter;
2501 switch (erp_action->step) {
2505 * the ULP spec. begs for waiting for oustanding commands
2507 case ZFCP_ERP_STEP_UNINITIALIZED:
2508 zfcp_erp_port_strategy_clearstati(port);
2510 * it would be sufficient to test only the normal open flag
2511 * since the phys. open flag cannot be set if the normal
2512 * open flag is unset - however, this is for readabilty ...
2514 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2515 ZFCP_STATUS_COMMON_OPEN),
2517 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2518 "close physical\n", port->wwpn);
2520 zfcp_erp_port_forced_strategy_close(erp_action);
2522 retval = ZFCP_ERP_FAILED;
2525 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2526 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2528 ZFCP_LOG_DEBUG("close physical failed for port "
2529 "0x%016Lx\n", port->wwpn);
2530 retval = ZFCP_ERP_FAILED;
2532 retval = ZFCP_ERP_SUCCEEDED;
2536 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2537 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2538 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2539 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2547 * purpose: this routine executes the 'Reopen Port' action
2549 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2550 * ZFCP_ERP_SUCCEEDED - action finished successfully
2551 * ZFCP_ERP_FAILED - action finished unsuccessfully
2554 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2556 int retval = ZFCP_ERP_FAILED;
2557 struct zfcp_port *port = erp_action->port;
2558 struct zfcp_adapter *adapter = erp_action->adapter;
2560 switch (erp_action->step) {
2564 * the ULP spec. begs for waiting for oustanding commands
2566 case ZFCP_ERP_STEP_UNINITIALIZED:
2567 zfcp_erp_port_strategy_clearstati(port);
2568 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2569 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2570 "close\n", port->wwpn);
2571 retval = zfcp_erp_port_strategy_close(erp_action);
2573 } /* else it's already closed, open it */
2576 case ZFCP_ERP_STEP_PORT_CLOSING:
2577 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2578 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2580 retval = ZFCP_ERP_FAILED;
2582 } /* else it's closed now, open it */
2585 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2586 retval = ZFCP_ERP_EXIT;
2588 retval = zfcp_erp_port_strategy_open(erp_action);
2591 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2592 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2593 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2594 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2607 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2611 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2612 &erp_action->port->status))
2613 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2615 retval = zfcp_erp_port_strategy_open_common(erp_action);
2627 * FIXME(design): currently only prepared for fabric (nameserver!)
2630 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2633 struct zfcp_adapter *adapter = erp_action->adapter;
2634 struct zfcp_port *port = erp_action->port;
2636 switch (erp_action->step) {
2638 case ZFCP_ERP_STEP_UNINITIALIZED:
2639 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2640 case ZFCP_ERP_STEP_PORT_CLOSING:
2641 if (adapter->fc_topology == FSF_TOPO_P2P) {
2642 if (port->wwpn != adapter->peer_wwpn) {
2643 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2644 "on adapter %s.\nPeer WWPN "
2645 "0x%016Lx does not match\n",
2647 zfcp_get_busid_by_adapter(adapter),
2648 adapter->peer_wwpn);
2649 zfcp_erp_port_failed(port);
2650 retval = ZFCP_ERP_FAILED;
2653 port->d_id = adapter->peer_d_id;
2654 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2655 retval = zfcp_erp_port_strategy_open_port(erp_action);
2658 if (!(adapter->nameserver_port)) {
2659 retval = zfcp_nameserver_enqueue(adapter);
2661 ZFCP_LOG_NORMAL("error: nameserver port "
2662 "unavailable for adapter %s\n",
2663 zfcp_get_busid_by_adapter(adapter));
2664 retval = ZFCP_ERP_FAILED;
2668 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2669 &adapter->nameserver_port->status)) {
2670 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2671 "nameserver port\n");
2672 /* nameserver port may live again */
2673 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2674 &adapter->nameserver_port->status);
2675 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2678 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2679 retval = ZFCP_ERP_CONTINUES;
2681 retval = ZFCP_ERP_FAILED;
2684 /* else nameserver port is already open, fall through */
2685 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2686 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2687 &adapter->nameserver_port->status)) {
2688 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2689 retval = ZFCP_ERP_FAILED;
2691 ZFCP_LOG_DEBUG("nameserver port is open -> "
2692 "nameserver look-up for port 0x%016Lx\n",
2694 retval = zfcp_erp_port_strategy_open_common_lookup
2699 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2700 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2701 if (atomic_test_mask
2702 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2703 ZFCP_LOG_DEBUG("nameserver look-up failed "
2704 "for port 0x%016Lx "
2705 "(misconfigured WWPN?)\n",
2707 zfcp_erp_port_failed(port);
2708 retval = ZFCP_ERP_EXIT;
2710 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2711 "port 0x%016Lx\n", port->wwpn);
2712 retval = ZFCP_ERP_FAILED;
2715 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2716 "trying open\n", port->wwpn, port->d_id);
2717 retval = zfcp_erp_port_strategy_open_port(erp_action);
2721 case ZFCP_ERP_STEP_PORT_OPENING:
2722 /* D_ID might have changed during open */
2723 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2724 ZFCP_STATUS_PORT_DID_DID),
2726 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2727 retval = ZFCP_ERP_SUCCEEDED;
2729 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2731 retval = ZFCP_ERP_FAILED;
2736 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2738 retval = ZFCP_ERP_FAILED;
2752 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2755 struct zfcp_port *port = erp_action->port;
2757 switch (erp_action->step) {
2759 case ZFCP_ERP_STEP_UNINITIALIZED:
2760 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2761 case ZFCP_ERP_STEP_PORT_CLOSING:
2762 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2763 port->wwpn, port->d_id);
2764 retval = zfcp_erp_port_strategy_open_port(erp_action);
2767 case ZFCP_ERP_STEP_PORT_OPENING:
2768 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2769 ZFCP_LOG_DEBUG("WKA port is open\n");
2770 retval = ZFCP_ERP_SUCCEEDED;
2772 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2773 retval = ZFCP_ERP_FAILED;
2775 /* this is needed anyway (dont care for retval of wakeup) */
2776 ZFCP_LOG_DEBUG("continue other open port operations\n");
2777 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2781 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2783 retval = ZFCP_ERP_FAILED;
2792 * purpose: makes the erp thread continue with reopen (physical) port
2793 * actions which have been paused until the name server port
2794 * is opened (or failed)
2796 * returns: 0 (a kind of void retval, its not used)
2799 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2803 unsigned long flags;
2804 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2805 struct zfcp_erp_action *erp_action, *tmp;
2807 read_lock_irqsave(&adapter->erp_lock, flags);
2808 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2810 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2811 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2813 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2814 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2815 debug_event(adapter->erp_dbf, 3,
2816 &erp_action->port->wwpn, sizeof (wwn_t));
2817 if (atomic_test_mask(
2818 ZFCP_STATUS_COMMON_ERP_FAILED,
2819 &adapter->nameserver_port->status))
2820 zfcp_erp_port_failed(erp_action->port);
2821 zfcp_erp_action_ready(erp_action);
2824 read_unlock_irqrestore(&adapter->erp_lock, flags);
2834 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2835 * ZFCP_ERP_FAILED - action finished unsuccessfully
2838 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2841 struct zfcp_adapter *adapter = erp_action->adapter;
2842 struct zfcp_port *port = erp_action->port;
2844 zfcp_erp_timeout_init(erp_action);
2845 retval = zfcp_fsf_close_physical_port(erp_action);
2846 if (retval == -ENOMEM) {
2847 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2848 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2849 retval = ZFCP_ERP_NOMEM;
2852 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2854 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2855 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2856 /* could not send 'open', fail */
2857 retval = ZFCP_ERP_FAILED;
2860 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2861 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2862 retval = ZFCP_ERP_CONTINUES;
2875 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2878 struct zfcp_adapter *adapter = port->adapter;
2880 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2881 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2883 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2884 ZFCP_STATUS_COMMON_CLOSING |
2885 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2886 ZFCP_STATUS_PORT_DID_DID |
2887 ZFCP_STATUS_PORT_PHYS_CLOSING |
2888 ZFCP_STATUS_PORT_INVALID_WWPN,
2898 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2899 * ZFCP_ERP_FAILED - action finished unsuccessfully
2902 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2905 struct zfcp_adapter *adapter = erp_action->adapter;
2906 struct zfcp_port *port = erp_action->port;
2908 zfcp_erp_timeout_init(erp_action);
2909 retval = zfcp_fsf_close_port(erp_action);
2910 if (retval == -ENOMEM) {
2911 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2912 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2913 retval = ZFCP_ERP_NOMEM;
2916 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2918 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2919 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2920 /* could not send 'close', fail */
2921 retval = ZFCP_ERP_FAILED;
2924 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2925 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2926 retval = ZFCP_ERP_CONTINUES;
2936 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2937 * ZFCP_ERP_FAILED - action finished unsuccessfully
2940 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2943 struct zfcp_adapter *adapter = erp_action->adapter;
2944 struct zfcp_port *port = erp_action->port;
2946 zfcp_erp_timeout_init(erp_action);
2947 retval = zfcp_fsf_open_port(erp_action);
2948 if (retval == -ENOMEM) {
2949 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2950 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2951 retval = ZFCP_ERP_NOMEM;
2954 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2956 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2957 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2958 /* could not send 'open', fail */
2959 retval = ZFCP_ERP_FAILED;
2962 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2963 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2964 retval = ZFCP_ERP_CONTINUES;
2974 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2975 * ZFCP_ERP_FAILED - action finished unsuccessfully
2978 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2981 struct zfcp_adapter *adapter = erp_action->adapter;
2982 struct zfcp_port *port = erp_action->port;
2984 zfcp_erp_timeout_init(erp_action);
2985 retval = zfcp_ns_gid_pn_request(erp_action);
2986 if (retval == -ENOMEM) {
2987 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2988 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2989 retval = ZFCP_ERP_NOMEM;
2992 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2994 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2995 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2996 /* could not send nameserver request, fail */
2997 retval = ZFCP_ERP_FAILED;
3000 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3001 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3002 retval = ZFCP_ERP_CONTINUES;
3010 * purpose: this routine executes the 'Reopen Unit' action
3011 * currently no retries
3013 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3014 * ZFCP_ERP_SUCCEEDED - action finished successfully
3015 * ZFCP_ERP_FAILED - action finished unsuccessfully
3018 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3020 int retval = ZFCP_ERP_FAILED;
3021 struct zfcp_unit *unit = erp_action->unit;
3022 struct zfcp_adapter *adapter = erp_action->adapter;
3024 switch (erp_action->step) {
3028 * the ULP spec. begs for waiting for oustanding commands
3030 case ZFCP_ERP_STEP_UNINITIALIZED:
3031 zfcp_erp_unit_strategy_clearstati(unit);
3032 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3033 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3034 "trying close\n", unit->fcp_lun);
3035 retval = zfcp_erp_unit_strategy_close(erp_action);
3038 /* else it's already closed, fall through */
3039 case ZFCP_ERP_STEP_UNIT_CLOSING:
3040 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3041 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3043 retval = ZFCP_ERP_FAILED;
3045 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3046 retval = ZFCP_ERP_EXIT;
3048 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3049 "trying open\n", unit->fcp_lun);
3051 zfcp_erp_unit_strategy_open(erp_action);
3056 case ZFCP_ERP_STEP_UNIT_OPENING:
3057 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3058 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3060 retval = ZFCP_ERP_SUCCEEDED;
3062 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3064 retval = ZFCP_ERP_FAILED;
3069 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3070 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3071 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3072 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3084 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3087 struct zfcp_adapter *adapter = unit->port->adapter;
3089 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3090 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3092 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3093 ZFCP_STATUS_COMMON_CLOSING |
3094 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3095 ZFCP_STATUS_UNIT_SHARED |
3096 ZFCP_STATUS_UNIT_READONLY,
3107 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3108 * ZFCP_ERP_FAILED - action finished unsuccessfully
3111 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3114 struct zfcp_adapter *adapter = erp_action->adapter;
3115 struct zfcp_unit *unit = erp_action->unit;
3117 zfcp_erp_timeout_init(erp_action);
3118 retval = zfcp_fsf_close_unit(erp_action);
3119 if (retval == -ENOMEM) {
3120 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3121 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3122 sizeof (fcp_lun_t));
3123 retval = ZFCP_ERP_NOMEM;
3126 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3128 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3129 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3130 sizeof (fcp_lun_t));
3131 /* could not send 'close', fail */
3132 retval = ZFCP_ERP_FAILED;
3135 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3136 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3137 retval = ZFCP_ERP_CONTINUES;
3148 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3149 * ZFCP_ERP_FAILED - action finished unsuccessfully
3152 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3155 struct zfcp_adapter *adapter = erp_action->adapter;
3156 struct zfcp_unit *unit = erp_action->unit;
3158 zfcp_erp_timeout_init(erp_action);
3159 retval = zfcp_fsf_open_unit(erp_action);
3160 if (retval == -ENOMEM) {
3161 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3162 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3163 sizeof (fcp_lun_t));
3164 retval = ZFCP_ERP_NOMEM;
3167 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3169 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3170 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3171 sizeof (fcp_lun_t));
3172 /* could not send 'open', fail */
3173 retval = ZFCP_ERP_FAILED;
3176 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3177 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3178 retval = ZFCP_ERP_CONTINUES;
3191 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3193 init_timer(&erp_action->timer);
3194 erp_action->timer.function = zfcp_erp_timeout_handler;
3195 erp_action->timer.data = (unsigned long) erp_action;
3196 /* jiffies will be added in zfcp_fsf_req_send */
3197 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3203 * purpose: enqueue the specified error recovery action, if needed
3208 zfcp_erp_action_enqueue(int action,
3209 struct zfcp_adapter *adapter,
3210 struct zfcp_port *port, struct zfcp_unit *unit)
3213 struct zfcp_erp_action *erp_action = NULL;
3214 int stronger_action = 0;
3218 * We need some rules here which check whether we really need
3219 * this action or whether we should just drop it.
3220 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3221 * 'Reopen Unit' request for an associated unit since we can't
3222 * satisfy this request now. A 'Reopen Port' action will trigger
3223 * 'Reopen Unit' actions when it completes.
3224 * Thus, there are only actions in the queue which can immediately be
3225 * executed. This makes the processing of the action queue more
3229 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3233 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3234 /* check whether we really need this */
3236 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3237 if (atomic_test_mask
3238 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3239 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3240 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3242 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3243 sizeof (fcp_lun_t));
3246 if (!atomic_test_mask
3247 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3249 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3252 if (!atomic_test_mask
3253 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3254 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3257 /* fall through !!! */
3259 case ZFCP_ERP_ACTION_REOPEN_PORT:
3260 if (atomic_test_mask
3261 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3262 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3263 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3267 /* fall through !!! */
3269 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3270 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3272 if (port->erp_action.action !=
3273 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3274 ZFCP_LOG_INFO("dropped erp action %i (port "
3275 "0x%016Lx, action in use: %i)\n",
3277 port->erp_action.action);
3278 debug_text_event(adapter->erp_dbf, 4,
3281 debug_text_event(adapter->erp_dbf, 4,
3283 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3287 if (!atomic_test_mask
3288 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3290 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3293 if (!atomic_test_mask
3294 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3295 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3298 /* fall through !!! */
3300 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3301 if (atomic_test_mask
3302 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3303 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3309 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3310 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3311 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3312 "on adapter %s (action=%d)\n",
3313 zfcp_get_busid_by_adapter(adapter), action);
3317 /* check whether we need something stronger first */
3318 if (stronger_action) {
3319 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3320 debug_event(adapter->erp_dbf, 4, &stronger_action,
3322 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3323 "erp action %d on adapter %s\n",
3324 stronger_action, action,
3325 zfcp_get_busid_by_adapter(adapter));
3326 action = stronger_action;
3329 /* mark adapter to have some error recovery pending */
3330 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3332 /* setup error recovery action */
3335 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3336 zfcp_unit_get(unit);
3337 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3338 erp_action = &unit->erp_action;
3339 if (!atomic_test_mask
3340 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3341 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3344 case ZFCP_ERP_ACTION_REOPEN_PORT:
3345 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3346 zfcp_port_get(port);
3347 zfcp_erp_action_dismiss_port(port);
3348 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3349 erp_action = &port->erp_action;
3350 if (!atomic_test_mask
3351 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3352 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3355 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3356 zfcp_adapter_get(adapter);
3357 zfcp_erp_action_dismiss_adapter(adapter);
3358 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3359 erp_action = &adapter->erp_action;
3360 if (!atomic_test_mask
3361 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3362 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3366 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3368 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3369 erp_action->adapter = adapter;
3370 erp_action->port = port;
3371 erp_action->unit = unit;
3372 erp_action->action = action;
3373 erp_action->status = status;
3375 ++adapter->erp_total_count;
3377 /* finally put it into 'ready' queue and kick erp thread */
3378 list_add(&erp_action->list, &adapter->erp_ready_head);
3379 up(&adapter->erp_ready_sem);
3393 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3396 struct zfcp_adapter *adapter = erp_action->adapter;
3398 --adapter->erp_total_count;
3399 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3400 --adapter->erp_low_mem_count;
3401 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3404 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3405 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3406 list_del(&erp_action->list);
3407 switch (erp_action->action) {
3408 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3409 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3410 &erp_action->unit->status);
3412 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3413 case ZFCP_ERP_ACTION_REOPEN_PORT:
3414 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3415 &erp_action->port->status);
3417 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3418 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3419 &erp_action->adapter->status);
3429 * zfcp_erp_action_cleanup
3431 * Register unit with scsi stack if appropiate and fix reference counts.
3432 * Note: Temporary units are not registered with scsi stack.
3435 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3436 struct zfcp_port *port, struct zfcp_unit *unit,
3440 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3441 if ((result == ZFCP_ERP_SUCCEEDED)
3442 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3446 scsi_add_device(port->adapter->scsi_host, 0,
3447 port->rport->scsi_target_id,
3449 zfcp_unit_put(unit);
3451 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3452 case ZFCP_ERP_ACTION_REOPEN_PORT:
3453 if ((result == ZFCP_ERP_SUCCEEDED)
3454 && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3457 struct fc_rport_identifiers ids;
3458 ids.node_name = port->wwnn;
3459 ids.port_name = port->wwpn;
3460 ids.port_id = port->d_id;
3461 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3463 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3465 ZFCP_LOG_NORMAL("failed registration of rport"
3466 "(adapter %s, wwpn=0x%016Lx)\n",
3467 zfcp_get_busid_by_port(port),
3470 zfcp_port_put(port);
3472 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3473 zfcp_adapter_put(adapter);
3489 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3492 struct zfcp_port *port;
3494 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3495 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3496 zfcp_erp_action_dismiss(&adapter->erp_action);
3498 list_for_each_entry(port, &adapter->port_list_head, list)
3499 zfcp_erp_action_dismiss_port(port);
3512 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3515 struct zfcp_unit *unit;
3516 struct zfcp_adapter *adapter = port->adapter;
3518 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3519 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3520 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3521 zfcp_erp_action_dismiss(&port->erp_action);
3523 list_for_each_entry(unit, &port->unit_list_head, list)
3524 zfcp_erp_action_dismiss_unit(unit);
3537 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3540 struct zfcp_adapter *adapter = unit->port->adapter;
3542 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3543 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3544 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3545 zfcp_erp_action_dismiss(&unit->erp_action);
3553 * purpose: moves erp_action to 'erp running list'
3558 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3560 struct zfcp_adapter *adapter = erp_action->adapter;
3562 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3563 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3564 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3570 * purpose: moves erp_action to 'erp ready list'
3575 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3577 struct zfcp_adapter *adapter = erp_action->adapter;
3579 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3580 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3581 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3585 * function: zfcp_erp_port_boxed
3590 zfcp_erp_port_boxed(struct zfcp_port *port)
3592 struct zfcp_adapter *adapter = port->adapter;
3593 unsigned long flags;
3595 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3596 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3597 read_lock_irqsave(&zfcp_data.config_lock, flags);
3598 zfcp_erp_modify_port_status(port,
3599 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3601 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3602 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3606 * function: zfcp_erp_unit_boxed
3611 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3613 struct zfcp_adapter *adapter = unit->port->adapter;
3615 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3616 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3617 zfcp_erp_modify_unit_status(unit,
3618 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3620 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3624 * function: zfcp_erp_port_access_denied
3629 zfcp_erp_port_access_denied(struct zfcp_port *port)
3631 struct zfcp_adapter *adapter = port->adapter;
3632 unsigned long flags;
3634 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3635 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3636 read_lock_irqsave(&zfcp_data.config_lock, flags);
3637 zfcp_erp_modify_port_status(port,
3638 ZFCP_STATUS_COMMON_ERP_FAILED |
3639 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3641 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3645 * function: zfcp_erp_unit_access_denied
3650 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3652 struct zfcp_adapter *adapter = unit->port->adapter;
3654 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3655 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3656 zfcp_erp_modify_unit_status(unit,
3657 ZFCP_STATUS_COMMON_ERP_FAILED |
3658 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3663 * function: zfcp_erp_adapter_access_changed
3668 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3670 struct zfcp_port *port;
3671 unsigned long flags;
3673 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3676 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3677 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3679 read_lock_irqsave(&zfcp_data.config_lock, flags);
3680 if (adapter->nameserver_port)
3681 zfcp_erp_port_access_changed(adapter->nameserver_port);
3682 list_for_each_entry(port, &adapter->port_list_head, list)
3683 if (port != adapter->nameserver_port)
3684 zfcp_erp_port_access_changed(port);
3685 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3689 * function: zfcp_erp_port_access_changed
3694 zfcp_erp_port_access_changed(struct zfcp_port *port)
3696 struct zfcp_adapter *adapter = port->adapter;
3697 struct zfcp_unit *unit;
3699 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3700 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3702 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3704 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3706 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3707 list_for_each_entry(unit, &port->unit_list_head, list)
3708 zfcp_erp_unit_access_changed(unit);
3712 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3713 "(due to ACT update)\n",
3714 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3715 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3716 ZFCP_LOG_NORMAL("failed reopen of port"
3717 "(adapter %s, wwpn=0x%016Lx)\n",
3718 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3722 * function: zfcp_erp_unit_access_changed
3727 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3729 struct zfcp_adapter *adapter = unit->port->adapter;
3731 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3732 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3734 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3736 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3740 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3741 " on adapter %s (due to ACT update)\n",
3742 unit->fcp_lun, unit->port->wwpn,
3743 zfcp_get_busid_by_adapter(adapter));
3744 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3745 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3746 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3747 zfcp_get_busid_by_adapter(adapter),
3748 unit->port->wwpn, unit->fcp_lun);
3751 #undef ZFCP_LOG_AREA