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_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
130 * zfcp_fsf_request_timeout_handler - called if a request timed out
131 * @data: pointer to adapter for handler function
133 * This function needs to be called if requests (ELS, Generic Service,
134 * or SCSI commands) exceed a certain time limit. The assumption is
135 * that after the time limit the adapter get stuck. So we trigger a reopen of
136 * the adapter. This should not be used for error recovery, SCSI abort
137 * commands and SCSI requests from SCSI mid-layer.
140 zfcp_fsf_request_timeout_handler(unsigned long data)
142 struct zfcp_adapter *adapter;
144 adapter = (struct zfcp_adapter *) data;
146 zfcp_erp_adapter_reopen(adapter, 0);
150 * function: zfcp_fsf_scsi_er_timeout_handler
152 * purpose: This function needs to be called whenever a SCSI error recovery
153 * action (abort/reset) does not return.
154 * Re-opening the adapter means that the command can be returned
155 * by zfcp (it is guarranteed that it does not return via the
156 * adapter anymore). The buffer can then be used again.
161 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
163 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
165 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
166 "Restarting all operations on the adapter %s\n",
167 zfcp_get_busid_by_adapter(adapter));
168 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
169 zfcp_erp_adapter_reopen(adapter, 0);
177 * purpose: called if an adapter failed,
178 * initiates adapter recovery which is done
181 * returns: 0 - initiated action succesfully
182 * <0 - failed to initiate action
185 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
189 debug_text_event(adapter->erp_dbf, 5, "a_ro");
190 ZFCP_LOG_DEBUG("reopen adapter %s\n",
191 zfcp_get_busid_by_adapter(adapter));
193 zfcp_erp_adapter_block(adapter, clear_mask);
195 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
196 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
197 zfcp_get_busid_by_adapter(adapter));
198 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
199 /* ensure propagation of failed status to new devices */
200 zfcp_erp_adapter_failed(adapter);
204 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
205 adapter, NULL, NULL);
214 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
215 * used to ensure the correct locking
217 * returns: 0 - initiated action succesfully
218 * <0 - failed to initiate action
221 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
226 read_lock_irqsave(&zfcp_data.config_lock, flags);
227 write_lock(&adapter->erp_lock);
228 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
229 write_unlock(&adapter->erp_lock);
230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
243 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
247 retval = zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_RUNNING |
249 ZFCP_STATUS_COMMON_ERP_FAILED |
263 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
267 retval = zfcp_erp_port_reopen(port,
268 ZFCP_STATUS_COMMON_RUNNING |
269 ZFCP_STATUS_COMMON_ERP_FAILED |
283 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
287 retval = zfcp_erp_unit_reopen(unit,
288 ZFCP_STATUS_COMMON_RUNNING |
289 ZFCP_STATUS_COMMON_ERP_FAILED |
297 * zfcp_erp_adisc - send ADISC ELS command
298 * @port: port structure
301 zfcp_erp_adisc(struct zfcp_port *port)
303 struct zfcp_adapter *adapter = port->adapter;
304 struct zfcp_send_els *send_els;
305 struct zfcp_ls_adisc *adisc;
306 void *address = NULL;
308 struct timer_list *timer;
310 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
311 if (send_els == NULL)
313 memset(send_els, 0, sizeof(*send_els));
315 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->req == NULL)
318 memset(send_els->req, 0, sizeof(*send_els->req));
320 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
321 if (send_els->resp == NULL)
323 memset(send_els->resp, 0, sizeof(*send_els->resp));
325 address = (void *) get_zeroed_page(GFP_ATOMIC);
329 zfcp_address_to_sg(address, send_els->req);
330 address += PAGE_SIZE >> 1;
331 zfcp_address_to_sg(address, send_els->resp);
332 send_els->req_count = send_els->resp_count = 1;
334 send_els->adapter = adapter;
335 send_els->port = port;
336 send_els->d_id = port->d_id;
337 send_els->handler = zfcp_erp_adisc_handler;
338 send_els->handler_data = (unsigned long) send_els;
340 adisc = zfcp_sg_to_address(send_els->req);
341 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
343 send_els->req->length = sizeof(struct zfcp_ls_adisc);
344 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
346 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
347 without FC-AL-2 capability, so we don't set it */
348 adisc->wwpn = adapter->wwpn;
349 adisc->wwnn = adapter->wwnn;
350 adisc->nport_id = adapter->s_id;
351 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
352 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
353 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
354 adapter->s_id, send_els->d_id, (wwn_t) adisc->wwpn,
355 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
358 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
363 timer->function = zfcp_fsf_request_timeout_handler;
364 timer->data = (unsigned long) adapter;
365 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
366 send_els->timer = timer;
368 retval = zfcp_fsf_send_els(send_els);
370 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
371 "0x%08x on adapter %s\n", send_els->d_id,
372 zfcp_get_busid_by_adapter(adapter));
373 del_timer(send_els->timer);
383 __free_pages(send_els->req->page, 0);
384 if (send_els != NULL) {
385 kfree(send_els->timer);
386 kfree(send_els->req);
387 kfree(send_els->resp);
396 * zfcp_erp_adisc_handler - handler for ADISC ELS command
397 * @data: pointer to struct zfcp_send_els
399 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
402 zfcp_erp_adisc_handler(unsigned long data)
404 struct zfcp_send_els *send_els;
405 struct zfcp_port *port;
406 struct zfcp_adapter *adapter;
408 struct zfcp_ls_adisc_acc *adisc;
410 send_els = (struct zfcp_send_els *) data;
412 del_timer(send_els->timer);
414 adapter = send_els->adapter;
415 port = send_els->port;
416 d_id = send_els->d_id;
418 /* request rejected or timed out */
419 if (send_els->status != 0) {
420 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
421 "force physical port reopen "
422 "(adapter %s, port d_id=0x%08x)\n",
423 zfcp_get_busid_by_adapter(adapter), d_id);
424 debug_text_event(adapter->erp_dbf, 3, "forcreop");
425 if (zfcp_erp_port_forced_reopen(port, 0))
426 ZFCP_LOG_NORMAL("failed reopen of port "
427 "(adapter %s, wwpn=0x%016Lx)\n",
428 zfcp_get_busid_by_port(port),
433 adisc = zfcp_sg_to_address(send_els->resp);
435 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
436 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
437 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
438 d_id, adapter->s_id, (wwn_t) adisc->wwpn,
439 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
442 /* set wwnn for port */
444 port->wwnn = adisc->wwnn;
446 if (port->wwpn != adisc->wwpn) {
447 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
448 "port (adapter %s, wwpn=0x%016Lx, "
449 "adisc_resp_wwpn=0x%016Lx)\n",
450 zfcp_get_busid_by_port(port),
451 port->wwpn, (wwn_t) adisc->wwpn);
452 if (zfcp_erp_port_reopen(port, 0))
453 ZFCP_LOG_NORMAL("failed reopen of port "
454 "(adapter %s, wwpn=0x%016Lx)\n",
455 zfcp_get_busid_by_port(port),
461 __free_pages(send_els->req->page, 0);
462 kfree(send_els->timer);
463 kfree(send_els->req);
464 kfree(send_els->resp);
470 * zfcp_test_link - lightweight link test procedure
471 * @port: port to be tested
473 * Test status of a link to a remote port using the ELS command ADISC.
476 zfcp_test_link(struct zfcp_port *port)
481 retval = zfcp_erp_adisc(port);
484 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
485 "on adapter %s\n ", port->wwpn,
486 zfcp_get_busid_by_port(port));
487 retval = zfcp_erp_port_forced_reopen(port, 0);
489 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
490 "on adapter %s failed\n", port->wwpn,
491 zfcp_get_busid_by_port(port));
503 * purpose: called if a port failed to be opened normally
504 * initiates Forced Reopen recovery which is done
507 * returns: 0 - initiated action succesfully
508 * <0 - failed to initiate action
511 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
514 struct zfcp_adapter *adapter = port->adapter;
516 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
517 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
519 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
520 port->wwpn, zfcp_get_busid_by_port(port));
522 zfcp_erp_port_block(port, clear_mask);
524 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
525 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
526 "on adapter %s\n", port->wwpn,
527 zfcp_get_busid_by_port(port));
528 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
529 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
534 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
535 port->adapter, port, NULL);
544 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
545 * used to ensure the correct locking
547 * returns: 0 - initiated action succesfully
548 * <0 - failed to initiate action
551 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
555 struct zfcp_adapter *adapter;
557 adapter = port->adapter;
558 read_lock_irqsave(&zfcp_data.config_lock, flags);
559 write_lock(&adapter->erp_lock);
560 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
561 write_unlock(&adapter->erp_lock);
562 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
570 * purpose: called if a port is to be opened
571 * initiates Reopen recovery which is done
574 * returns: 0 - initiated action succesfully
575 * <0 - failed to initiate action
578 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
581 struct zfcp_adapter *adapter = port->adapter;
583 debug_text_event(adapter->erp_dbf, 5, "p_ro");
584 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
586 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
587 port->wwpn, zfcp_get_busid_by_port(port));
589 zfcp_erp_port_block(port, clear_mask);
591 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
592 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
593 "on adapter %s\n", port->wwpn,
594 zfcp_get_busid_by_port(port));
595 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
596 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
597 /* ensure propagation of failed status to new devices */
598 zfcp_erp_port_failed(port);
603 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
604 port->adapter, port, NULL);
611 * zfcp_erp_port_reopen - initiate reopen of a remote port
612 * @port: port to be reopened
613 * @clear_mask: specifies flags in port status to be cleared
614 * Return: 0 on success, < 0 on error
616 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
617 * correct locking. An error recovery task is initiated to do the reopen.
618 * To wait for the completion of the reopen zfcp_erp_wait should be used.
621 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
625 struct zfcp_adapter *adapter = port->adapter;
627 read_lock_irqsave(&zfcp_data.config_lock, flags);
628 write_lock(&adapter->erp_lock);
629 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
630 write_unlock(&adapter->erp_lock);
631 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
639 * purpose: called if a unit is to be opened
640 * initiates Reopen recovery which is done
643 * returns: 0 - initiated action succesfully
644 * <0 - failed to initiate action
647 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
650 struct zfcp_adapter *adapter = unit->port->adapter;
652 debug_text_event(adapter->erp_dbf, 5, "u_ro");
653 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
654 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
655 "on adapter %s\n", unit->fcp_lun,
656 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
658 zfcp_erp_unit_block(unit, clear_mask);
660 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
661 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
662 "on port 0x%016Lx on adapter %s\n",
663 unit->fcp_lun, unit->port->wwpn,
664 zfcp_get_busid_by_unit(unit));
665 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
666 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
672 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
673 unit->port->adapter, unit->port, unit);
679 * zfcp_erp_unit_reopen - initiate reopen of a unit
680 * @unit: unit to be reopened
681 * @clear_mask: specifies flags in unit status to be cleared
682 * Return: 0 on success, < 0 on error
684 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
685 * locking. An error recovery task is initiated to do the reopen.
686 * To wait for the completion of the reopen zfcp_erp_wait should be used.
689 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
693 struct zfcp_adapter *adapter;
694 struct zfcp_port *port;
697 adapter = port->adapter;
699 read_lock_irqsave(&zfcp_data.config_lock, flags);
700 write_lock(&adapter->erp_lock);
701 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
702 write_unlock(&adapter->erp_lock);
703 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
711 * purpose: disable I/O,
712 * return any open requests and clean them up,
713 * aim: no pending and incoming I/O
718 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
720 debug_text_event(adapter->erp_dbf, 6, "a_bl");
721 zfcp_erp_modify_adapter_status(adapter,
722 ZFCP_STATUS_COMMON_UNBLOCKED |
723 clear_mask, ZFCP_CLEAR);
729 * purpose: enable I/O
734 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
736 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
737 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
743 * purpose: disable I/O,
744 * return any open requests and clean them up,
745 * aim: no pending and incoming I/O
750 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
752 struct zfcp_adapter *adapter = port->adapter;
754 debug_text_event(adapter->erp_dbf, 6, "p_bl");
755 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
756 zfcp_erp_modify_port_status(port,
757 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
764 * purpose: enable I/O
769 zfcp_erp_port_unblock(struct zfcp_port *port)
771 struct zfcp_adapter *adapter = port->adapter;
773 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
774 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
775 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
781 * purpose: disable I/O,
782 * return any open requests and clean them up,
783 * aim: no pending and incoming I/O
788 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
790 struct zfcp_adapter *adapter = unit->port->adapter;
792 debug_text_event(adapter->erp_dbf, 6, "u_bl");
793 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
794 zfcp_erp_modify_unit_status(unit,
795 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
802 * purpose: enable I/O
807 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
809 struct zfcp_adapter *adapter = unit->port->adapter;
811 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
812 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
813 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
824 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
826 struct zfcp_adapter *adapter = erp_action->adapter;
828 debug_text_event(adapter->erp_dbf, 4, "a_ar");
829 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
831 zfcp_erp_action_to_ready(erp_action);
832 up(&adapter->erp_ready_sem);
840 * returns: <0 erp_action not found in any list
841 * ZFCP_ERP_ACTION_READY erp_action is in ready list
842 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
844 * locks: erp_lock must be held
847 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
849 int retval = -EINVAL;
850 struct list_head *entry;
851 struct zfcp_erp_action *entry_erp_action;
852 struct zfcp_adapter *adapter = erp_action->adapter;
854 /* search in running list */
855 list_for_each(entry, &adapter->erp_running_head) {
857 list_entry(entry, struct zfcp_erp_action, list);
858 if (entry_erp_action == erp_action) {
859 retval = ZFCP_ERP_ACTION_RUNNING;
863 /* search in ready list */
864 list_for_each(entry, &adapter->erp_ready_head) {
866 list_entry(entry, struct zfcp_erp_action, list);
867 if (entry_erp_action == erp_action) {
868 retval = ZFCP_ERP_ACTION_READY;
878 * purpose: checks current status of action (timed out, dismissed, ...)
879 * and does appropriate preparations (dismiss fsf request, ...)
881 * locks: called under erp_lock (disabled interrupts)
886 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
889 struct zfcp_fsf_req *fsf_req;
890 struct zfcp_adapter *adapter = erp_action->adapter;
892 if (erp_action->fsf_req) {
893 /* take lock to ensure that request is not being deleted meanwhile */
894 spin_lock(&adapter->fsf_req_list_lock);
895 /* check whether fsf req does still exist */
896 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
897 if (fsf_req == erp_action->fsf_req)
899 if (fsf_req == erp_action->fsf_req) {
900 /* fsf_req still exists */
901 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
902 debug_event(adapter->erp_dbf, 3, &fsf_req,
903 sizeof (unsigned long));
904 /* dismiss fsf_req of timed out or dismissed erp_action */
905 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
906 ZFCP_STATUS_ERP_TIMEDOUT)) {
907 debug_text_event(adapter->erp_dbf, 3,
909 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
911 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
912 ZFCP_LOG_NORMAL("error: erp step timed out "
913 "(action=%d, fsf_req=%p)\n ",
915 erp_action->fsf_req);
918 * If fsf_req is neither dismissed nor completed
919 * then keep it running asynchronously and don't mess
920 * with the association of erp_action and fsf_req.
922 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
923 ZFCP_STATUS_FSFREQ_DISMISSED)) {
924 /* forget about association between fsf_req
926 fsf_req->erp_action = NULL;
927 erp_action->fsf_req = NULL;
930 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
932 * even if this fsf_req has gone, forget about
933 * association between erp_action and fsf_req
935 erp_action->fsf_req = NULL;
937 spin_unlock(&adapter->fsf_req_list_lock);
939 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
945 * purpose: generic handler for asynchronous events related to erp_action events
946 * (normal completion, time-out, dismissing, retry after
947 * low memory condition)
949 * note: deletion of timer is not required (e.g. in case of a time-out),
950 * but a second try does no harm,
951 * we leave it in here to allow for greater simplification
953 * returns: 0 - there was an action to handle
957 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
958 unsigned long set_mask)
961 struct zfcp_adapter *adapter = erp_action->adapter;
963 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
964 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
965 debug_event(adapter->erp_dbf, 2, &erp_action->action,
967 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
968 del_timer(&erp_action->timer);
969 erp_action->status |= set_mask;
970 zfcp_erp_action_ready(erp_action);
973 /* action is ready or gone - nothing to do */
974 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
975 debug_event(adapter->erp_dbf, 3, &erp_action->action,
984 * purpose: generic handler for asynchronous events related to erp_action
985 * events (normal completion, time-out, dismissing, retry after
986 * low memory condition)
988 * note: deletion of timer is not required (e.g. in case of a time-out),
989 * but a second try does no harm,
990 * we leave it in here to allow for greater simplification
992 * returns: 0 - there was an action to handle
996 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
997 unsigned long set_mask)
999 struct zfcp_adapter *adapter = erp_action->adapter;
1000 unsigned long flags;
1003 write_lock_irqsave(&adapter->erp_lock, flags);
1004 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1005 write_unlock_irqrestore(&adapter->erp_lock, flags);
1011 * purpose: is called for erp_action which was slept waiting for
1012 * memory becoming avaliable,
1013 * will trigger that this action will be continued
1016 zfcp_erp_memwait_handler(unsigned long data)
1018 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1019 struct zfcp_adapter *adapter = erp_action->adapter;
1021 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1022 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1024 zfcp_erp_async_handler(erp_action, 0);
1028 * purpose: is called if an asynchronous erp step timed out,
1029 * action gets an appropriate flag and will be processed
1033 zfcp_erp_timeout_handler(unsigned long data)
1035 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1036 struct zfcp_adapter *adapter = erp_action->adapter;
1038 debug_text_event(adapter->erp_dbf, 2, "a_th");
1039 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1041 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1045 * purpose: is called for an erp_action which needs to be ended
1046 * though not being done,
1047 * this is usually required if an higher is generated,
1048 * action gets an appropriate flag and will be processed
1051 * locks: erp_lock held (thus we need to call another handler variant)
1054 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1056 struct zfcp_adapter *adapter = erp_action->adapter;
1058 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1059 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1061 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1067 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1071 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1073 rwlock_init(&adapter->erp_lock);
1074 INIT_LIST_HEAD(&adapter->erp_ready_head);
1075 INIT_LIST_HEAD(&adapter->erp_running_head);
1076 sema_init(&adapter->erp_ready_sem, 0);
1078 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1080 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1082 zfcp_get_busid_by_adapter(adapter));
1083 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1085 wait_event(adapter->erp_thread_wqh,
1086 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1088 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1091 return (retval < 0);
1101 * context: process (i.e. proc-fs or rmmod/insmod)
1103 * note: The caller of this routine ensures that the specified
1104 * adapter has been shut down and that this operation
1105 * has been completed. Thus, there are no pending erp_actions
1106 * which would need to be handled here.
1109 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1113 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1114 up(&adapter->erp_ready_sem);
1116 wait_event(adapter->erp_thread_wqh,
1117 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1120 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1123 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1129 * purpose: is run as a kernel thread,
1130 * goes through list of error recovery actions of associated adapter
1131 * and delegates single action to execution
1136 zfcp_erp_thread(void *data)
1138 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1139 struct list_head *next;
1140 struct zfcp_erp_action *erp_action;
1141 unsigned long flags;
1143 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1144 /* Block all signals */
1145 siginitsetinv(¤t->blocked, 0);
1146 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1147 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1148 wake_up(&adapter->erp_thread_wqh);
1150 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1151 &adapter->status)) {
1153 write_lock_irqsave(&adapter->erp_lock, flags);
1154 next = adapter->erp_ready_head.prev;
1155 write_unlock_irqrestore(&adapter->erp_lock, flags);
1157 if (next != &adapter->erp_ready_head) {
1159 list_entry(next, struct zfcp_erp_action, list);
1161 * process action (incl. [re]moving it
1162 * from 'ready' queue)
1164 zfcp_erp_strategy(erp_action);
1168 * sleep as long as there is nothing to do, i.e.
1169 * no action in 'ready' queue to be processed and
1170 * thread is not to be killed
1172 down_interruptible(&adapter->erp_ready_sem);
1173 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1176 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1177 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1178 wake_up(&adapter->erp_thread_wqh);
1186 * purpose: drives single error recovery action and schedules higher and
1187 * subordinate actions, if necessary
1189 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1190 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1191 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1192 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1193 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1196 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1199 struct zfcp_adapter *adapter = erp_action->adapter;
1200 struct zfcp_port *port = erp_action->port;
1201 struct zfcp_unit *unit = erp_action->unit;
1202 int action = erp_action->action;
1203 u32 status = erp_action->status;
1204 unsigned long flags;
1206 /* serialise dismissing, timing out, moving, enqueueing */
1207 read_lock_irqsave(&zfcp_data.config_lock, flags);
1208 write_lock(&adapter->erp_lock);
1210 /* dequeue dismissed action and leave, if required */
1211 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1212 if (retval == ZFCP_ERP_DISMISSED) {
1213 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1218 * move action to 'running' queue before processing it
1219 * (to avoid a race condition regarding moving the
1220 * action to the 'running' queue and back)
1222 zfcp_erp_action_to_running(erp_action);
1225 * try to process action as far as possible,
1226 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1227 * afterwards the lock is required again for the following reasons:
1228 * - dequeueing of finished action and enqueueing of
1229 * follow-up actions must be atomic so that any other
1230 * reopen-routine does not believe there is nothing to do
1231 * and that it is safe to enqueue something else,
1232 * - we want to force any control thread which is dismissing
1233 * actions to finish this before we decide about
1234 * necessary steps to be taken here further
1236 write_unlock(&adapter->erp_lock);
1237 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1238 retval = zfcp_erp_strategy_do_action(erp_action);
1239 read_lock_irqsave(&zfcp_data.config_lock, flags);
1240 write_lock(&adapter->erp_lock);
1243 * check for dismissed status again to avoid follow-up actions,
1244 * failing of targets and so on for dismissed actions
1246 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1249 case ZFCP_ERP_DISMISSED:
1250 /* leave since this action has ridden to its ancestors */
1251 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1253 case ZFCP_ERP_NOMEM:
1254 /* no memory to continue immediately, let it sleep */
1255 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1256 ++adapter->erp_low_mem_count;
1257 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1259 /* This condition is true if there is no memory available
1260 for any erp_action on this adapter. This implies that there
1261 are no elements in the memory pool(s) left for erp_actions.
1262 This might happen if an erp_action that used a memory pool
1263 element was timed out.
1265 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1266 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1267 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1268 "restarting I/O on adapter %s "
1269 "to free mempool\n",
1270 zfcp_get_busid_by_adapter(adapter));
1271 zfcp_erp_adapter_reopen_internal(adapter, 0);
1273 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1274 retval = zfcp_erp_strategy_memwait(erp_action);
1277 case ZFCP_ERP_CONTINUES:
1278 /* leave since this action runs asynchronously */
1279 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1280 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1281 --adapter->erp_low_mem_count;
1282 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1286 /* ok, finished action (whatever its result is) */
1288 /* check for unrecoverable targets */
1289 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1291 /* action must be dequeued (here to allow for further ones) */
1292 zfcp_erp_action_dequeue(erp_action);
1295 * put this target through the erp mill again if someone has
1296 * requested to change the status of a target being online
1297 * to offline or the other way around
1298 * (old retval is preserved if nothing has to be done here)
1300 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1301 port, unit, retval);
1304 * leave if target is in permanent error state or if
1305 * action is repeated in order to process state change
1307 if (retval == ZFCP_ERP_EXIT) {
1308 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1312 /* trigger follow up actions */
1313 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1316 write_unlock(&adapter->erp_lock);
1317 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1319 if (retval != ZFCP_ERP_CONTINUES)
1320 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1323 * a few tasks remain when the erp queues are empty
1324 * (don't do that if the last action evaluated was dismissed
1325 * since this clearly indicates that there is more to come) :
1326 * - close the name server port if it is open yet
1327 * (enqueues another [probably] final action)
1328 * - otherwise, wake up whoever wants to be woken when we are
1331 if (retval != ZFCP_ERP_DISMISSED)
1332 zfcp_erp_strategy_check_queues(adapter);
1334 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1344 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1345 * retval - otherwise
1348 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1350 struct zfcp_adapter *adapter = erp_action->adapter;
1352 zfcp_erp_strategy_check_fsfreq(erp_action);
1354 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1355 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1356 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1357 zfcp_erp_action_dequeue(erp_action);
1358 retval = ZFCP_ERP_DISMISSED;
1360 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1373 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1375 int retval = ZFCP_ERP_FAILED;
1376 struct zfcp_adapter *adapter = erp_action->adapter;
1379 * try to execute/continue action as far as possible,
1380 * note: no lock in subsequent strategy routines
1381 * (this allows these routine to call schedule, e.g.
1382 * kmalloc with such flags or qdio_initialize & friends)
1383 * Note: in case of timeout, the seperate strategies will fail
1384 * anyhow. No need for a special action. Even worse, a nameserver
1385 * failure would not wake up waiting ports without the call.
1387 switch (erp_action->action) {
1389 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1390 retval = zfcp_erp_adapter_strategy(erp_action);
1393 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1394 retval = zfcp_erp_port_forced_strategy(erp_action);
1397 case ZFCP_ERP_ACTION_REOPEN_PORT:
1398 retval = zfcp_erp_port_strategy(erp_action);
1401 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1402 retval = zfcp_erp_unit_strategy(erp_action);
1406 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1407 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1409 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1410 "adapter %s (action=%d)\n",
1411 zfcp_get_busid_by_adapter(erp_action->adapter),
1412 erp_action->action);
1421 * purpose: triggers retry of this action after a certain amount of time
1422 * by means of timer provided by erp_action
1424 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1427 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1429 int retval = ZFCP_ERP_CONTINUES;
1430 struct zfcp_adapter *adapter = erp_action->adapter;
1432 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1433 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1434 init_timer(&erp_action->timer);
1435 erp_action->timer.function = zfcp_erp_memwait_handler;
1436 erp_action->timer.data = (unsigned long) erp_action;
1437 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1438 add_timer(&erp_action->timer);
1444 * function: zfcp_erp_adapter_failed
1446 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1450 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1452 zfcp_erp_modify_adapter_status(adapter,
1453 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1454 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1455 zfcp_get_busid_by_adapter(adapter));
1456 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1460 * function: zfcp_erp_port_failed
1462 * purpose: sets the port and all underlying devices to ERP_FAILED
1466 zfcp_erp_port_failed(struct zfcp_port *port)
1468 zfcp_erp_modify_port_status(port,
1469 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1471 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1472 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1473 "port d_id=0x%08x)\n",
1474 zfcp_get_busid_by_port(port), port->d_id);
1476 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1477 zfcp_get_busid_by_port(port), port->wwpn);
1479 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1480 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1484 * function: zfcp_erp_unit_failed
1486 * purpose: sets the unit to ERP_FAILED
1490 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1492 zfcp_erp_modify_unit_status(unit,
1493 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1495 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1496 " on adapter %s\n", unit->fcp_lun,
1497 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1498 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1499 debug_event(unit->port->adapter->erp_dbf, 2,
1500 &unit->fcp_lun, sizeof (fcp_lun_t));
1504 * function: zfcp_erp_strategy_check_target
1506 * purpose: increments the erp action count on the device currently in
1507 * recovery if the action failed or resets the count in case of
1508 * success. If a maximum count is exceeded the device is marked
1510 * The 'blocked' state of a target which has been recovered
1511 * successfully is reset.
1513 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1514 * ZFCP_ERP_SUCCEEDED - action finished successfully
1515 * ZFCP_ERP_EXIT - action failed and will not continue
1518 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1520 struct zfcp_adapter *adapter = erp_action->adapter;
1521 struct zfcp_port *port = erp_action->port;
1522 struct zfcp_unit *unit = erp_action->unit;
1524 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1525 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1526 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1528 switch (erp_action->action) {
1530 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1531 result = zfcp_erp_strategy_check_unit(unit, result);
1534 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1535 case ZFCP_ERP_ACTION_REOPEN_PORT:
1536 result = zfcp_erp_strategy_check_port(port, result);
1539 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1540 result = zfcp_erp_strategy_check_adapter(adapter, result);
1555 zfcp_erp_strategy_statechange(int action,
1557 struct zfcp_adapter *adapter,
1558 struct zfcp_port *port,
1559 struct zfcp_unit *unit, int retval)
1561 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1562 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1566 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1567 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1569 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1570 retval = ZFCP_ERP_EXIT;
1574 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1575 case ZFCP_ERP_ACTION_REOPEN_PORT:
1576 if (zfcp_erp_strategy_statechange_detected(&port->status,
1578 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1579 retval = ZFCP_ERP_EXIT;
1583 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1584 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1586 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1587 retval = ZFCP_ERP_EXIT;
1603 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1606 /* take it online */
1607 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1608 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1609 /* take it offline */
1610 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1611 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1622 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1624 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1625 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1626 sizeof (fcp_lun_t));
1629 case ZFCP_ERP_SUCCEEDED :
1630 atomic_set(&unit->erp_counter, 0);
1631 zfcp_erp_unit_unblock(unit);
1633 case ZFCP_ERP_FAILED :
1634 atomic_inc(&unit->erp_counter);
1635 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1636 zfcp_erp_unit_failed(unit);
1638 case ZFCP_ERP_EXIT :
1643 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1644 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1645 result = ZFCP_ERP_EXIT;
1659 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1661 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1662 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1665 case ZFCP_ERP_SUCCEEDED :
1666 atomic_set(&port->erp_counter, 0);
1667 zfcp_erp_port_unblock(port);
1669 case ZFCP_ERP_FAILED :
1670 atomic_inc(&port->erp_counter);
1671 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1672 zfcp_erp_port_failed(port);
1674 case ZFCP_ERP_EXIT :
1679 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1680 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1681 result = ZFCP_ERP_EXIT;
1695 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1697 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1700 case ZFCP_ERP_SUCCEEDED :
1701 atomic_set(&adapter->erp_counter, 0);
1702 zfcp_erp_adapter_unblock(adapter);
1704 case ZFCP_ERP_FAILED :
1705 atomic_inc(&adapter->erp_counter);
1706 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1707 zfcp_erp_adapter_failed(adapter);
1709 case ZFCP_ERP_EXIT :
1714 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1715 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1716 result = ZFCP_ERP_EXIT;
1725 * purpose: remaining things in good cases,
1726 * escalation in bad cases
1731 zfcp_erp_strategy_followup_actions(int action,
1732 struct zfcp_adapter *adapter,
1733 struct zfcp_port *port,
1734 struct zfcp_unit *unit, int status)
1736 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1737 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1739 /* initiate follow-up actions depending on success of finished action */
1742 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1743 if (status == ZFCP_ERP_SUCCEEDED)
1744 zfcp_erp_port_reopen_all_internal(adapter, 0);
1746 zfcp_erp_adapter_reopen_internal(adapter, 0);
1749 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1750 if (status == ZFCP_ERP_SUCCEEDED)
1751 zfcp_erp_port_reopen_internal(port, 0);
1753 zfcp_erp_adapter_reopen_internal(adapter, 0);
1756 case ZFCP_ERP_ACTION_REOPEN_PORT:
1757 if (status == ZFCP_ERP_SUCCEEDED)
1758 zfcp_erp_unit_reopen_all_internal(port, 0);
1760 zfcp_erp_port_forced_reopen_internal(port, 0);
1763 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1764 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1766 zfcp_erp_port_reopen_internal(unit->port, 0);
1781 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1783 unsigned long flags;
1785 read_lock_irqsave(&zfcp_data.config_lock, flags);
1786 read_lock(&adapter->erp_lock);
1787 if (list_empty(&adapter->erp_ready_head) &&
1788 list_empty(&adapter->erp_running_head)) {
1789 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1790 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1792 wake_up(&adapter->erp_done_wqh);
1794 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1795 read_unlock(&adapter->erp_lock);
1796 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1802 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1803 * @adapter: adapter for which to wait for completion of its error recovery
1807 zfcp_erp_wait(struct zfcp_adapter *adapter)
1811 wait_event(adapter->erp_done_wqh,
1812 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1819 * function: zfcp_erp_modify_adapter_status
1825 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1826 u32 mask, int set_or_clear)
1828 struct zfcp_port *port;
1829 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1831 if (set_or_clear == ZFCP_SET) {
1832 atomic_set_mask(mask, &adapter->status);
1833 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1835 atomic_clear_mask(mask, &adapter->status);
1836 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1837 atomic_set(&adapter->erp_counter, 0);
1838 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1840 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1842 /* Deal with all underlying devices, only pass common_mask */
1844 list_for_each_entry(port, &adapter->port_list_head, list)
1845 zfcp_erp_modify_port_status(port, common_mask,
1850 * function: zfcp_erp_modify_port_status
1852 * purpose: sets the port and all underlying devices to ERP_FAILED
1856 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1858 struct zfcp_unit *unit;
1859 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1861 if (set_or_clear == ZFCP_SET) {
1862 atomic_set_mask(mask, &port->status);
1863 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1865 atomic_clear_mask(mask, &port->status);
1866 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1867 atomic_set(&port->erp_counter, 0);
1868 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1870 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1871 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1873 /* Modify status of all underlying devices, only pass common mask */
1875 list_for_each_entry(unit, &port->unit_list_head, list)
1876 zfcp_erp_modify_unit_status(unit, common_mask,
1881 * function: zfcp_erp_modify_unit_status
1883 * purpose: sets the unit to ERP_FAILED
1887 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1889 if (set_or_clear == ZFCP_SET) {
1890 atomic_set_mask(mask, &unit->status);
1891 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1893 atomic_clear_mask(mask, &unit->status);
1894 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1895 atomic_set(&unit->erp_counter, 0);
1897 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1899 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1900 sizeof (fcp_lun_t));
1901 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1907 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1908 * used to ensure the correct locking
1910 * returns: 0 - initiated action succesfully
1911 * <0 - failed to initiate action
1914 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1917 unsigned long flags;
1919 read_lock_irqsave(&zfcp_data.config_lock, flags);
1920 write_lock(&adapter->erp_lock);
1921 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1922 write_unlock(&adapter->erp_lock);
1923 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1936 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1939 struct zfcp_port *port;
1941 list_for_each_entry(port, &adapter->port_list_head, list)
1942 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1943 zfcp_erp_port_reopen_internal(port, clear_mask);
1956 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1959 struct zfcp_unit *unit;
1961 list_for_each_entry(unit, &port->unit_list_head, list)
1962 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1970 * purpose: this routine executes the 'Reopen Adapter' action
1971 * (the entire action is processed synchronously, since
1972 * there are no actions which might be run concurrently
1975 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1976 * ZFCP_ERP_FAILED - action finished unsuccessfully
1979 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1982 struct zfcp_adapter *adapter = erp_action->adapter;
1984 retval = zfcp_erp_adapter_strategy_close(erp_action);
1985 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1986 retval = ZFCP_ERP_EXIT;
1988 retval = zfcp_erp_adapter_strategy_open(erp_action);
1990 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1991 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1992 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1994 if (retval == ZFCP_ERP_FAILED) {
1995 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1996 "to recover itself\n",
1997 zfcp_get_busid_by_adapter(adapter));
1998 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2009 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2010 * ZFCP_ERP_FAILED - action finished unsuccessfully
2013 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2017 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2018 &erp_action->adapter->status);
2019 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2020 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2021 &erp_action->adapter->status);
2031 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2032 * ZFCP_ERP_FAILED - action finished unsuccessfully
2035 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2039 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2040 &erp_action->adapter->status);
2041 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2042 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2043 &erp_action->adapter->status);
2049 * function: zfcp_register_adapter
2051 * purpose: allocate the irq associated with this devno and register
2052 * the FSF adapter with the SCSI stack
2057 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2059 int retval = ZFCP_ERP_SUCCEEDED;
2064 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2065 if (retval != ZFCP_ERP_SUCCEEDED)
2068 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2069 if (retval != ZFCP_ERP_SUCCEEDED)
2070 goto failed_openfcp;
2072 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2076 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2077 &erp_action->adapter->status);
2080 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2081 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2088 * function: zfcp_qdio_init
2090 * purpose: setup QDIO operation for specified adapter
2092 * returns: 0 - successful setup
2096 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2100 volatile struct qdio_buffer_element *sbale;
2101 struct zfcp_adapter *adapter = erp_action->adapter;
2103 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2104 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2106 zfcp_get_busid_by_adapter(adapter));
2110 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2111 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2113 zfcp_get_busid_by_adapter(adapter));
2114 goto failed_qdio_establish;
2116 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2118 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2119 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2121 zfcp_get_busid_by_adapter(adapter));
2122 goto failed_qdio_activate;
2124 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2127 * put buffers into response queue,
2129 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2130 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2132 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2136 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2137 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2138 zfcp_get_busid_by_adapter(adapter),
2139 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2141 retval = do_QDIO(adapter->ccw_device,
2142 QDIO_FLAG_SYNC_INPUT,
2143 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2146 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2148 goto failed_do_qdio;
2150 adapter->response_queue.free_index = 0;
2151 atomic_set(&adapter->response_queue.free_count, 0);
2152 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2153 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2155 /* set index of first avalable SBALS / number of available SBALS */
2156 adapter->request_queue.free_index = 0;
2157 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2158 adapter->request_queue.distance_from_int = 0;
2160 /* initialize waitqueue used to wait for free SBALs in requests queue */
2161 init_waitqueue_head(&adapter->request_wq);
2163 /* ok, we did it - skip all cleanups for different failures */
2164 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2165 retval = ZFCP_ERP_SUCCEEDED;
2171 failed_qdio_activate:
2172 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2173 while (qdio_shutdown(adapter->ccw_device,
2174 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2176 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2178 failed_qdio_establish:
2180 retval = ZFCP_ERP_FAILED;
2187 * function: zfcp_qdio_cleanup
2189 * purpose: cleans up QDIO operation for the specified adapter
2191 * returns: 0 - successful cleanup
2192 * !0 - failed cleanup
2195 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2197 int retval = ZFCP_ERP_SUCCEEDED;
2200 struct zfcp_adapter *adapter = erp_action->adapter;
2202 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2203 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2204 "queues on adapter %s\n",
2205 zfcp_get_busid_by_adapter(adapter));
2206 retval = ZFCP_ERP_FAILED;
2211 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2212 * do_QDIO won't be called while qdio_shutdown is in progress.
2215 write_lock_irq(&adapter->request_queue.queue_lock);
2216 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2217 write_unlock_irq(&adapter->request_queue.queue_lock);
2219 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2220 while (qdio_shutdown(adapter->ccw_device,
2221 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2223 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2226 * First we had to stop QDIO operation.
2227 * Now it is safe to take the following actions.
2230 /* Cleanup only necessary when there are unacknowledged buffers */
2231 if (atomic_read(&adapter->request_queue.free_count)
2232 < QDIO_MAX_BUFFERS_PER_Q) {
2233 first_used = (adapter->request_queue.free_index +
2234 atomic_read(&adapter->request_queue.free_count))
2235 % QDIO_MAX_BUFFERS_PER_Q;
2236 used_count = QDIO_MAX_BUFFERS_PER_Q -
2237 atomic_read(&adapter->request_queue.free_count);
2238 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2239 first_used, used_count);
2241 adapter->response_queue.free_index = 0;
2242 atomic_set(&adapter->response_queue.free_count, 0);
2243 adapter->request_queue.free_index = 0;
2244 atomic_set(&adapter->request_queue.free_count, 0);
2245 adapter->request_queue.distance_from_int = 0;
2251 * function: zfcp_fsf_init
2253 * purpose: initializes FSF operation for the specified adapter
2255 * returns: 0 - succesful initialization of FSF operation
2256 * !0 - failed to initialize FSF operation
2259 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2263 /* do 'exchange configuration data' */
2264 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2265 if (retval == ZFCP_ERP_FAILED)
2268 /* start the desired number of Status Reads */
2269 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2281 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2283 int retval = ZFCP_ERP_SUCCEEDED;
2285 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2286 struct zfcp_adapter *adapter = erp_action->adapter;
2288 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2290 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2291 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2293 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2294 zfcp_erp_action_to_running(erp_action);
2295 zfcp_erp_timeout_init(erp_action);
2296 if (zfcp_fsf_exchange_config_data(erp_action)) {
2297 retval = ZFCP_ERP_FAILED;
2298 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2299 ZFCP_LOG_INFO("error: initiation of exchange of "
2300 "configuration data failed for "
2302 zfcp_get_busid_by_adapter(adapter));
2305 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2306 ZFCP_LOG_DEBUG("Xchange underway\n");
2310 * Both the normal completion handler as well as the timeout
2311 * handler will do an 'up' when the 'exchange config data'
2312 * request completes or times out. Thus, the signal to go on
2313 * won't be lost utilizing this semaphore.
2314 * Furthermore, this 'adapter_reopen' action is
2315 * guaranteed to be the only action being there (highest action
2316 * which prevents other actions from being created).
2317 * Resulting from that, the wake signal recognized here
2318 * _must_ be the one belonging to the 'exchange config
2321 down(&adapter->erp_ready_sem);
2322 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2323 ZFCP_LOG_INFO("error: exchange of configuration data "
2324 "for adapter %s timed out\n",
2325 zfcp_get_busid_by_adapter(adapter));
2329 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2333 ZFCP_LOG_DEBUG("host connection still initialising... "
2334 "waiting and retrying...\n");
2335 /* sleep a little bit before retry */
2336 msleep(jiffies_to_msecs(sleep));
2340 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2341 &adapter->status)) {
2342 ZFCP_LOG_INFO("error: exchange of configuration data for "
2343 "adapter %s failed\n",
2344 zfcp_get_busid_by_adapter(adapter));
2345 retval = ZFCP_ERP_FAILED;
2359 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2362 int retval = ZFCP_ERP_SUCCEEDED;
2364 struct zfcp_adapter *adapter = erp_action->adapter;
2367 adapter->status_read_failed = 0;
2368 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2369 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2371 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2372 "notification failed on adapter %s\n",
2373 zfcp_get_busid_by_adapter(adapter));
2374 retval = ZFCP_ERP_FAILED;
2384 * function: zfcp_fsf_cleanup
2386 * purpose: cleanup FSF operation for specified adapter
2388 * returns: 0 - FSF operation successfully cleaned up
2389 * !0 - failed to cleanup FSF operation for this adapter
2392 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2394 int retval = ZFCP_ERP_SUCCEEDED;
2395 struct zfcp_adapter *adapter = erp_action->adapter;
2398 * wake waiting initiators of requests,
2399 * return SCSI commands (with error status),
2400 * clean up all requests (synchronously)
2402 zfcp_fsf_req_dismiss_all(adapter);
2403 /* reset FSF request sequence number */
2404 adapter->fsf_req_seq_no = 0;
2405 /* all ports and units are closed */
2406 zfcp_erp_modify_adapter_status(adapter,
2407 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2415 * purpose: this routine executes the 'Reopen Physical Port' action
2417 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2418 * ZFCP_ERP_SUCCEEDED - action finished successfully
2419 * ZFCP_ERP_FAILED - action finished unsuccessfully
2422 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2424 int retval = ZFCP_ERP_FAILED;
2425 struct zfcp_port *port = erp_action->port;
2426 struct zfcp_adapter *adapter = erp_action->adapter;
2428 switch (erp_action->step) {
2432 * the ULP spec. begs for waiting for oustanding commands
2434 case ZFCP_ERP_STEP_UNINITIALIZED:
2435 zfcp_erp_port_strategy_clearstati(port);
2437 * it would be sufficient to test only the normal open flag
2438 * since the phys. open flag cannot be set if the normal
2439 * open flag is unset - however, this is for readabilty ...
2441 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2442 ZFCP_STATUS_COMMON_OPEN),
2444 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2445 "close physical\n", port->wwpn);
2447 zfcp_erp_port_forced_strategy_close(erp_action);
2449 retval = ZFCP_ERP_FAILED;
2452 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2453 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2455 ZFCP_LOG_DEBUG("close physical failed for port "
2456 "0x%016Lx\n", port->wwpn);
2457 retval = ZFCP_ERP_FAILED;
2459 retval = ZFCP_ERP_SUCCEEDED;
2463 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2464 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2465 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2466 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2474 * purpose: this routine executes the 'Reopen Port' action
2476 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2477 * ZFCP_ERP_SUCCEEDED - action finished successfully
2478 * ZFCP_ERP_FAILED - action finished unsuccessfully
2481 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2483 int retval = ZFCP_ERP_FAILED;
2484 struct zfcp_port *port = erp_action->port;
2485 struct zfcp_adapter *adapter = erp_action->adapter;
2487 switch (erp_action->step) {
2491 * the ULP spec. begs for waiting for oustanding commands
2493 case ZFCP_ERP_STEP_UNINITIALIZED:
2494 zfcp_erp_port_strategy_clearstati(port);
2495 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2496 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2497 "close\n", port->wwpn);
2498 retval = zfcp_erp_port_strategy_close(erp_action);
2500 } /* else it's already closed, open it */
2503 case ZFCP_ERP_STEP_PORT_CLOSING:
2504 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2505 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2507 retval = ZFCP_ERP_FAILED;
2509 } /* else it's closed now, open it */
2512 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2513 retval = ZFCP_ERP_EXIT;
2515 retval = zfcp_erp_port_strategy_open(erp_action);
2518 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2519 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2520 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2521 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2534 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2538 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2539 &erp_action->port->status))
2540 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2542 retval = zfcp_erp_port_strategy_open_common(erp_action);
2554 * FIXME(design): currently only prepared for fabric (nameserver!)
2557 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2560 struct zfcp_adapter *adapter = erp_action->adapter;
2561 struct zfcp_port *port = erp_action->port;
2563 switch (erp_action->step) {
2565 case ZFCP_ERP_STEP_UNINITIALIZED:
2566 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2567 case ZFCP_ERP_STEP_PORT_CLOSING:
2568 if (adapter->fc_topology == FSF_TOPO_P2P) {
2569 if (port->wwpn != adapter->peer_wwpn) {
2570 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2571 "on adapter %s.\nPeer WWPN "
2572 "0x%016Lx does not match\n",
2574 zfcp_get_busid_by_adapter(adapter),
2575 adapter->peer_wwpn);
2576 zfcp_erp_port_failed(port);
2577 retval = ZFCP_ERP_FAILED;
2580 port->d_id = adapter->peer_d_id;
2581 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2582 retval = zfcp_erp_port_strategy_open_port(erp_action);
2585 if (!(adapter->nameserver_port)) {
2586 retval = zfcp_nameserver_enqueue(adapter);
2588 ZFCP_LOG_NORMAL("error: nameserver port "
2589 "unavailable for adapter %s\n",
2590 zfcp_get_busid_by_adapter(adapter));
2591 retval = ZFCP_ERP_FAILED;
2595 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2596 &adapter->nameserver_port->status)) {
2597 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2598 "nameserver port\n");
2599 /* nameserver port may live again */
2600 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2601 &adapter->nameserver_port->status);
2602 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2605 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2606 retval = ZFCP_ERP_CONTINUES;
2608 retval = ZFCP_ERP_FAILED;
2611 /* else nameserver port is already open, fall through */
2612 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2613 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2614 &adapter->nameserver_port->status)) {
2615 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2616 retval = ZFCP_ERP_FAILED;
2618 ZFCP_LOG_DEBUG("nameserver port is open -> "
2619 "nameserver look-up for port 0x%016Lx\n",
2621 retval = zfcp_erp_port_strategy_open_common_lookup
2626 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2627 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2628 if (atomic_test_mask
2629 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2630 ZFCP_LOG_DEBUG("nameserver look-up failed "
2631 "for port 0x%016Lx "
2632 "(misconfigured WWPN?)\n",
2634 zfcp_erp_port_failed(port);
2635 retval = ZFCP_ERP_EXIT;
2637 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2638 "port 0x%016Lx\n", port->wwpn);
2639 retval = ZFCP_ERP_FAILED;
2642 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2643 "trying open\n", port->wwpn, port->d_id);
2644 retval = zfcp_erp_port_strategy_open_port(erp_action);
2648 case ZFCP_ERP_STEP_PORT_OPENING:
2649 /* D_ID might have changed during open */
2650 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2651 ZFCP_STATUS_PORT_DID_DID),
2653 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2654 retval = ZFCP_ERP_SUCCEEDED;
2656 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2658 retval = ZFCP_ERP_FAILED;
2663 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2665 retval = ZFCP_ERP_FAILED;
2679 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2682 struct zfcp_port *port = erp_action->port;
2684 switch (erp_action->step) {
2686 case ZFCP_ERP_STEP_UNINITIALIZED:
2687 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2688 case ZFCP_ERP_STEP_PORT_CLOSING:
2689 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2690 port->wwpn, port->d_id);
2691 retval = zfcp_erp_port_strategy_open_port(erp_action);
2694 case ZFCP_ERP_STEP_PORT_OPENING:
2695 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2696 ZFCP_LOG_DEBUG("WKA port is open\n");
2697 retval = ZFCP_ERP_SUCCEEDED;
2699 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2700 retval = ZFCP_ERP_FAILED;
2702 /* this is needed anyway (dont care for retval of wakeup) */
2703 ZFCP_LOG_DEBUG("continue other open port operations\n");
2704 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2708 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2710 retval = ZFCP_ERP_FAILED;
2719 * purpose: makes the erp thread continue with reopen (physical) port
2720 * actions which have been paused until the name server port
2721 * is opened (or failed)
2723 * returns: 0 (a kind of void retval, its not used)
2726 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2730 unsigned long flags;
2731 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2732 struct zfcp_erp_action *erp_action, *tmp;
2734 read_lock_irqsave(&adapter->erp_lock, flags);
2735 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2737 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2738 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2740 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2741 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2742 debug_event(adapter->erp_dbf, 3,
2743 &erp_action->port->wwpn, sizeof (wwn_t));
2744 if (atomic_test_mask(
2745 ZFCP_STATUS_COMMON_ERP_FAILED,
2746 &adapter->nameserver_port->status))
2747 zfcp_erp_port_failed(erp_action->port);
2748 zfcp_erp_action_ready(erp_action);
2751 read_unlock_irqrestore(&adapter->erp_lock, flags);
2761 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2762 * ZFCP_ERP_FAILED - action finished unsuccessfully
2765 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2768 struct zfcp_adapter *adapter = erp_action->adapter;
2769 struct zfcp_port *port = erp_action->port;
2771 zfcp_erp_timeout_init(erp_action);
2772 retval = zfcp_fsf_close_physical_port(erp_action);
2773 if (retval == -ENOMEM) {
2774 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2775 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2776 retval = ZFCP_ERP_NOMEM;
2779 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2781 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2782 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2783 /* could not send 'open', fail */
2784 retval = ZFCP_ERP_FAILED;
2787 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2788 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2789 retval = ZFCP_ERP_CONTINUES;
2802 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2805 struct zfcp_adapter *adapter = port->adapter;
2807 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2808 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2810 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2811 ZFCP_STATUS_COMMON_CLOSING |
2812 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2813 ZFCP_STATUS_PORT_DID_DID |
2814 ZFCP_STATUS_PORT_PHYS_CLOSING |
2815 ZFCP_STATUS_PORT_INVALID_WWPN,
2825 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2826 * ZFCP_ERP_FAILED - action finished unsuccessfully
2829 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2832 struct zfcp_adapter *adapter = erp_action->adapter;
2833 struct zfcp_port *port = erp_action->port;
2835 zfcp_erp_timeout_init(erp_action);
2836 retval = zfcp_fsf_close_port(erp_action);
2837 if (retval == -ENOMEM) {
2838 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2839 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2840 retval = ZFCP_ERP_NOMEM;
2843 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2845 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2846 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2847 /* could not send 'close', fail */
2848 retval = ZFCP_ERP_FAILED;
2851 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2852 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2853 retval = ZFCP_ERP_CONTINUES;
2863 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2864 * ZFCP_ERP_FAILED - action finished unsuccessfully
2867 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2870 struct zfcp_adapter *adapter = erp_action->adapter;
2871 struct zfcp_port *port = erp_action->port;
2873 zfcp_erp_timeout_init(erp_action);
2874 retval = zfcp_fsf_open_port(erp_action);
2875 if (retval == -ENOMEM) {
2876 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2877 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2878 retval = ZFCP_ERP_NOMEM;
2881 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2883 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2884 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2885 /* could not send 'open', fail */
2886 retval = ZFCP_ERP_FAILED;
2889 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2890 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2891 retval = ZFCP_ERP_CONTINUES;
2901 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2902 * ZFCP_ERP_FAILED - action finished unsuccessfully
2905 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2908 struct zfcp_adapter *adapter = erp_action->adapter;
2909 struct zfcp_port *port = erp_action->port;
2911 zfcp_erp_timeout_init(erp_action);
2912 retval = zfcp_ns_gid_pn_request(erp_action);
2913 if (retval == -ENOMEM) {
2914 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2915 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2916 retval = ZFCP_ERP_NOMEM;
2919 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2921 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2922 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2923 /* could not send nameserver request, fail */
2924 retval = ZFCP_ERP_FAILED;
2927 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2928 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2929 retval = ZFCP_ERP_CONTINUES;
2937 * purpose: this routine executes the 'Reopen Unit' action
2938 * currently no retries
2940 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2941 * ZFCP_ERP_SUCCEEDED - action finished successfully
2942 * ZFCP_ERP_FAILED - action finished unsuccessfully
2945 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2947 int retval = ZFCP_ERP_FAILED;
2948 struct zfcp_unit *unit = erp_action->unit;
2949 struct zfcp_adapter *adapter = erp_action->adapter;
2951 switch (erp_action->step) {
2955 * the ULP spec. begs for waiting for oustanding commands
2957 case ZFCP_ERP_STEP_UNINITIALIZED:
2958 zfcp_erp_unit_strategy_clearstati(unit);
2959 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2960 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2961 "trying close\n", unit->fcp_lun);
2962 retval = zfcp_erp_unit_strategy_close(erp_action);
2965 /* else it's already closed, fall through */
2966 case ZFCP_ERP_STEP_UNIT_CLOSING:
2967 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2968 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2970 retval = ZFCP_ERP_FAILED;
2972 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2973 retval = ZFCP_ERP_EXIT;
2975 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2976 "trying open\n", unit->fcp_lun);
2978 zfcp_erp_unit_strategy_open(erp_action);
2983 case ZFCP_ERP_STEP_UNIT_OPENING:
2984 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2985 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2987 retval = ZFCP_ERP_SUCCEEDED;
2989 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2991 retval = ZFCP_ERP_FAILED;
2996 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2997 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2998 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2999 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3011 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3014 struct zfcp_adapter *adapter = unit->port->adapter;
3016 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3017 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3019 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3020 ZFCP_STATUS_COMMON_CLOSING |
3021 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3022 ZFCP_STATUS_UNIT_SHARED |
3023 ZFCP_STATUS_UNIT_READONLY,
3034 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3035 * ZFCP_ERP_FAILED - action finished unsuccessfully
3038 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3041 struct zfcp_adapter *adapter = erp_action->adapter;
3042 struct zfcp_unit *unit = erp_action->unit;
3044 zfcp_erp_timeout_init(erp_action);
3045 retval = zfcp_fsf_close_unit(erp_action);
3046 if (retval == -ENOMEM) {
3047 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3048 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3049 sizeof (fcp_lun_t));
3050 retval = ZFCP_ERP_NOMEM;
3053 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3055 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3056 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3057 sizeof (fcp_lun_t));
3058 /* could not send 'close', fail */
3059 retval = ZFCP_ERP_FAILED;
3062 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3063 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3064 retval = ZFCP_ERP_CONTINUES;
3075 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3076 * ZFCP_ERP_FAILED - action finished unsuccessfully
3079 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3082 struct zfcp_adapter *adapter = erp_action->adapter;
3083 struct zfcp_unit *unit = erp_action->unit;
3085 zfcp_erp_timeout_init(erp_action);
3086 retval = zfcp_fsf_open_unit(erp_action);
3087 if (retval == -ENOMEM) {
3088 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3089 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3090 sizeof (fcp_lun_t));
3091 retval = ZFCP_ERP_NOMEM;
3094 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3096 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3097 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3098 sizeof (fcp_lun_t));
3099 /* could not send 'open', fail */
3100 retval = ZFCP_ERP_FAILED;
3103 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3104 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3105 retval = ZFCP_ERP_CONTINUES;
3118 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3120 init_timer(&erp_action->timer);
3121 erp_action->timer.function = zfcp_erp_timeout_handler;
3122 erp_action->timer.data = (unsigned long) erp_action;
3123 /* jiffies will be added in zfcp_fsf_req_send */
3124 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3130 * purpose: enqueue the specified error recovery action, if needed
3135 zfcp_erp_action_enqueue(int action,
3136 struct zfcp_adapter *adapter,
3137 struct zfcp_port *port, struct zfcp_unit *unit)
3140 struct zfcp_erp_action *erp_action = NULL;
3141 int stronger_action = 0;
3145 * We need some rules here which check whether we really need
3146 * this action or whether we should just drop it.
3147 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3148 * 'Reopen Unit' request for an associated unit since we can't
3149 * satisfy this request now. A 'Reopen Port' action will trigger
3150 * 'Reopen Unit' actions when it completes.
3151 * Thus, there are only actions in the queue which can immediately be
3152 * executed. This makes the processing of the action queue more
3156 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3160 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3161 /* check whether we really need this */
3163 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3164 if (atomic_test_mask
3165 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3166 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3167 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3169 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3170 sizeof (fcp_lun_t));
3173 if (!atomic_test_mask
3174 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3176 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3179 if (!atomic_test_mask
3180 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3181 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3184 /* fall through !!! */
3186 case ZFCP_ERP_ACTION_REOPEN_PORT:
3187 if (atomic_test_mask
3188 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3189 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3190 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3194 /* fall through !!! */
3196 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3197 if (atomic_test_mask
3198 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3199 && port->erp_action.action ==
3200 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3201 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3202 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3206 if (!atomic_test_mask
3207 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3209 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3212 if (!atomic_test_mask
3213 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3214 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3217 /* fall through !!! */
3219 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3220 if (atomic_test_mask
3221 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3222 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3228 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3229 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3230 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3231 "on adapter %s (action=%d)\n",
3232 zfcp_get_busid_by_adapter(adapter), action);
3236 /* check whether we need something stronger first */
3237 if (stronger_action) {
3238 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3239 debug_event(adapter->erp_dbf, 4, &stronger_action,
3241 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3242 "erp action %d on adapter %s\n",
3243 stronger_action, action,
3244 zfcp_get_busid_by_adapter(adapter));
3245 action = stronger_action;
3248 /* mark adapter to have some error recovery pending */
3249 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3251 /* setup error recovery action */
3254 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3255 zfcp_unit_get(unit);
3256 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3257 erp_action = &unit->erp_action;
3258 if (!atomic_test_mask
3259 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3260 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3263 case ZFCP_ERP_ACTION_REOPEN_PORT:
3264 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3265 zfcp_port_get(port);
3266 zfcp_erp_action_dismiss_port(port);
3267 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3268 erp_action = &port->erp_action;
3269 if (!atomic_test_mask
3270 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3271 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3274 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3275 zfcp_adapter_get(adapter);
3276 zfcp_erp_action_dismiss_adapter(adapter);
3277 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3278 erp_action = &adapter->erp_action;
3279 if (!atomic_test_mask
3280 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3281 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3285 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3287 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3288 erp_action->adapter = adapter;
3289 erp_action->port = port;
3290 erp_action->unit = unit;
3291 erp_action->action = action;
3292 erp_action->status = status;
3294 ++adapter->erp_total_count;
3296 /* finally put it into 'ready' queue and kick erp thread */
3297 list_add(&erp_action->list, &adapter->erp_ready_head);
3298 up(&adapter->erp_ready_sem);
3312 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3315 struct zfcp_adapter *adapter = erp_action->adapter;
3317 --adapter->erp_total_count;
3318 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3319 --adapter->erp_low_mem_count;
3320 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3323 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3324 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3325 list_del(&erp_action->list);
3326 switch (erp_action->action) {
3327 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3328 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3329 &erp_action->unit->status);
3331 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3332 case ZFCP_ERP_ACTION_REOPEN_PORT:
3333 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3334 &erp_action->port->status);
3336 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3337 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3338 &erp_action->adapter->status);
3348 * zfcp_erp_action_cleanup
3350 * Register unit with scsi stack if appropiate and fix reference counts.
3351 * Note: Temporary units are not registered with scsi stack.
3354 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3355 struct zfcp_port *port, struct zfcp_unit *unit,
3359 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3360 if ((result == ZFCP_ERP_SUCCEEDED)
3361 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3365 scsi_add_device(port->adapter->scsi_host, 0,
3366 port->rport->scsi_target_id,
3368 zfcp_unit_put(unit);
3370 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3371 case ZFCP_ERP_ACTION_REOPEN_PORT:
3372 if ((result == ZFCP_ERP_SUCCEEDED)
3373 && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3376 struct fc_rport_identifiers ids;
3377 ids.node_name = port->wwnn;
3378 ids.port_name = port->wwpn;
3379 ids.port_id = port->d_id;
3380 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3382 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3384 ZFCP_LOG_NORMAL("failed registration of rport"
3385 "(adapter %s, wwpn=0x%016Lx)\n",
3386 zfcp_get_busid_by_port(port),
3389 zfcp_port_put(port);
3391 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3392 zfcp_adapter_put(adapter);
3408 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3411 struct zfcp_port *port;
3413 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3414 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3415 zfcp_erp_action_dismiss(&adapter->erp_action);
3417 list_for_each_entry(port, &adapter->port_list_head, list)
3418 zfcp_erp_action_dismiss_port(port);
3431 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3434 struct zfcp_unit *unit;
3435 struct zfcp_adapter *adapter = port->adapter;
3437 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3438 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3439 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3440 zfcp_erp_action_dismiss(&port->erp_action);
3442 list_for_each_entry(unit, &port->unit_list_head, list)
3443 zfcp_erp_action_dismiss_unit(unit);
3456 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3459 struct zfcp_adapter *adapter = unit->port->adapter;
3461 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3462 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3463 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3464 zfcp_erp_action_dismiss(&unit->erp_action);
3472 * purpose: moves erp_action to 'erp running list'
3477 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3479 struct zfcp_adapter *adapter = erp_action->adapter;
3481 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3482 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3483 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3489 * purpose: moves erp_action to 'erp ready list'
3494 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3496 struct zfcp_adapter *adapter = erp_action->adapter;
3498 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3499 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3500 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3504 * function: zfcp_erp_port_boxed
3509 zfcp_erp_port_boxed(struct zfcp_port *port)
3511 struct zfcp_adapter *adapter = port->adapter;
3512 unsigned long flags;
3514 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3515 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3516 read_lock_irqsave(&zfcp_data.config_lock, flags);
3517 zfcp_erp_modify_port_status(port,
3518 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3520 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3521 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3525 * function: zfcp_erp_unit_boxed
3530 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3532 struct zfcp_adapter *adapter = unit->port->adapter;
3534 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3535 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3536 zfcp_erp_modify_unit_status(unit,
3537 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3539 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3543 * function: zfcp_erp_port_access_denied
3548 zfcp_erp_port_access_denied(struct zfcp_port *port)
3550 struct zfcp_adapter *adapter = port->adapter;
3551 unsigned long flags;
3553 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3554 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3555 read_lock_irqsave(&zfcp_data.config_lock, flags);
3556 zfcp_erp_modify_port_status(port,
3557 ZFCP_STATUS_COMMON_ERP_FAILED |
3558 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3560 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3564 * function: zfcp_erp_unit_access_denied
3569 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3571 struct zfcp_adapter *adapter = unit->port->adapter;
3573 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3574 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3575 zfcp_erp_modify_unit_status(unit,
3576 ZFCP_STATUS_COMMON_ERP_FAILED |
3577 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3582 * function: zfcp_erp_adapter_access_changed
3587 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3589 struct zfcp_port *port;
3590 unsigned long flags;
3592 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3593 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3595 read_lock_irqsave(&zfcp_data.config_lock, flags);
3596 if (adapter->nameserver_port)
3597 zfcp_erp_port_access_changed(adapter->nameserver_port);
3598 list_for_each_entry(port, &adapter->port_list_head, list)
3599 if (port != adapter->nameserver_port)
3600 zfcp_erp_port_access_changed(port);
3601 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3605 * function: zfcp_erp_port_access_changed
3610 zfcp_erp_port_access_changed(struct zfcp_port *port)
3612 struct zfcp_adapter *adapter = port->adapter;
3613 struct zfcp_unit *unit;
3615 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3616 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3618 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3620 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3622 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3623 list_for_each_entry(unit, &port->unit_list_head, list)
3624 zfcp_erp_unit_access_changed(unit);
3628 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3629 "(due to ACT update)\n",
3630 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3631 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3632 ZFCP_LOG_NORMAL("failed reopen of port"
3633 "(adapter %s, wwpn=0x%016Lx)\n",
3634 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3638 * function: zfcp_erp_unit_access_changed
3643 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3645 struct zfcp_adapter *adapter = unit->port->adapter;
3647 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3648 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3650 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3652 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3656 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3657 " on adapter %s (due to ACT update)\n",
3658 unit->fcp_lun, unit->port->wwpn,
3659 zfcp_get_busid_by_adapter(adapter));
3660 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3661 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3662 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3663 zfcp_get_busid_by_adapter(adapter),
3664 unit->port->wwpn, unit->fcp_lun);
3667 #undef ZFCP_LOG_AREA