2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
26 static int zfcp_erp_adisc(struct zfcp_port *);
27 static void zfcp_erp_adisc_handler(unsigned long);
29 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
30 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
31 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
32 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
34 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
35 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
37 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
38 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
39 static void zfcp_erp_port_block(struct zfcp_port *, int);
40 static void zfcp_erp_port_unblock(struct zfcp_port *);
41 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
42 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
44 static int zfcp_erp_thread(void *);
46 static int zfcp_erp_strategy(struct zfcp_erp_action *);
48 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
49 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
50 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
51 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
52 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
53 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
54 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
56 struct zfcp_unit *, int);
57 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
58 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
60 struct zfcp_unit *, int);
61 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
62 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
67 static void zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
68 static void zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
69 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
73 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
74 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
75 struct zfcp_erp_action *);
77 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
78 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
80 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
82 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
83 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
84 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
86 struct zfcp_erp_action *);
87 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
88 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
89 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
91 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
93 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
96 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
97 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
98 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
100 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
101 struct zfcp_port *, struct zfcp_unit *);
102 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
103 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
104 struct zfcp_port *, struct zfcp_unit *,
107 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
108 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
110 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
111 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
113 static void zfcp_erp_memwait_handler(unsigned long);
114 static void zfcp_erp_timeout_handler(unsigned long);
115 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
118 * zfcp_fsf_request_timeout_handler - called if a request timed out
119 * @data: pointer to adapter for handler function
121 * This function needs to be called if requests (ELS, Generic Service,
122 * or SCSI commands) exceed a certain time limit. The assumption is
123 * that after the time limit the adapter get stuck. So we trigger a reopen of
124 * the adapter. This should not be used for error recovery, SCSI abort
125 * commands and SCSI requests from SCSI mid-layer.
128 zfcp_fsf_request_timeout_handler(unsigned long data)
130 struct zfcp_adapter *adapter;
132 adapter = (struct zfcp_adapter *) data;
134 zfcp_erp_adapter_reopen(adapter, 0);
138 * zfcp_fsf_scsi_er_timeout_handler - timeout handler for scsi eh tasks
140 * This function needs to be called whenever a SCSI error recovery
141 * action (abort/reset) does not return. Re-opening the adapter means
142 * that the abort/reset command can be returned by zfcp. It won't complete
143 * via the adapter anymore (because qdio queues are closed). If ERP is
144 * already running on this adapter it will be stopped.
146 void zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
148 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
151 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
152 "Restarting all operations on the adapter %s\n",
153 zfcp_get_busid_by_adapter(adapter));
154 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
156 write_lock_irqsave(&adapter->erp_lock, flags);
157 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
159 zfcp_erp_modify_adapter_status(adapter,
160 ZFCP_STATUS_COMMON_UNBLOCKED|ZFCP_STATUS_COMMON_OPEN,
162 zfcp_erp_action_dismiss_adapter(adapter);
163 write_unlock_irqrestore(&adapter->erp_lock, flags);
164 /* dismiss all pending requests including requests for ERP */
165 zfcp_fsf_req_dismiss_all(adapter);
166 adapter->fsf_req_seq_no = 0;
168 write_unlock_irqrestore(&adapter->erp_lock, flags);
169 zfcp_erp_adapter_reopen(adapter, 0);
175 * purpose: called if an adapter failed,
176 * initiates adapter recovery which is done
179 * returns: 0 - initiated action successfully
180 * <0 - failed to initiate action
183 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
187 debug_text_event(adapter->erp_dbf, 5, "a_ro");
188 ZFCP_LOG_DEBUG("reopen adapter %s\n",
189 zfcp_get_busid_by_adapter(adapter));
191 zfcp_erp_adapter_block(adapter, clear_mask);
193 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
194 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
195 zfcp_get_busid_by_adapter(adapter));
196 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
197 /* ensure propagation of failed status to new devices */
198 zfcp_erp_adapter_failed(adapter);
202 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
203 adapter, NULL, NULL);
212 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
213 * used to ensure the correct locking
215 * returns: 0 - initiated action successfully
216 * <0 - failed to initiate action
219 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
224 read_lock_irqsave(&zfcp_data.config_lock, flags);
225 write_lock(&adapter->erp_lock);
226 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
227 write_unlock(&adapter->erp_lock);
228 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
234 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
238 retval = zfcp_erp_adapter_reopen(adapter,
239 ZFCP_STATUS_COMMON_RUNNING |
240 ZFCP_STATUS_COMMON_ERP_FAILED |
247 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
251 retval = zfcp_erp_port_reopen(port,
252 ZFCP_STATUS_COMMON_RUNNING |
253 ZFCP_STATUS_COMMON_ERP_FAILED |
260 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
264 retval = zfcp_erp_unit_reopen(unit,
265 ZFCP_STATUS_COMMON_RUNNING |
266 ZFCP_STATUS_COMMON_ERP_FAILED |
274 * zfcp_erp_adisc - send ADISC ELS command
275 * @port: port structure
278 zfcp_erp_adisc(struct zfcp_port *port)
280 struct zfcp_adapter *adapter = port->adapter;
281 struct zfcp_send_els *send_els;
282 struct zfcp_ls_adisc *adisc;
283 void *address = NULL;
285 struct timer_list *timer;
287 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
288 if (send_els == NULL)
291 send_els->req = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
292 if (send_els->req == NULL)
295 send_els->resp = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
296 if (send_els->resp == NULL)
299 address = (void *) get_zeroed_page(GFP_ATOMIC);
303 zfcp_address_to_sg(address, send_els->req);
304 address += PAGE_SIZE >> 1;
305 zfcp_address_to_sg(address, send_els->resp);
306 send_els->req_count = send_els->resp_count = 1;
308 send_els->adapter = adapter;
309 send_els->port = port;
310 send_els->d_id = port->d_id;
311 send_els->handler = zfcp_erp_adisc_handler;
312 send_els->handler_data = (unsigned long) send_els;
314 adisc = zfcp_sg_to_address(send_els->req);
315 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
317 send_els->req->length = sizeof(struct zfcp_ls_adisc);
318 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
320 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
321 without FC-AL-2 capability, so we don't set it */
322 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
323 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
324 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
325 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
326 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
327 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
328 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
329 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
332 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
337 timer->function = zfcp_fsf_request_timeout_handler;
338 timer->data = (unsigned long) adapter;
339 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
340 send_els->timer = timer;
342 retval = zfcp_fsf_send_els(send_els);
344 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
345 "0x%08x on adapter %s\n", send_els->d_id,
346 zfcp_get_busid_by_adapter(adapter));
347 del_timer(send_els->timer);
357 __free_pages(send_els->req->page, 0);
358 if (send_els != NULL) {
359 kfree(send_els->timer);
360 kfree(send_els->req);
361 kfree(send_els->resp);
370 * zfcp_erp_adisc_handler - handler for ADISC ELS command
371 * @data: pointer to struct zfcp_send_els
373 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
376 zfcp_erp_adisc_handler(unsigned long data)
378 struct zfcp_send_els *send_els;
379 struct zfcp_port *port;
380 struct zfcp_adapter *adapter;
382 struct zfcp_ls_adisc_acc *adisc;
384 send_els = (struct zfcp_send_els *) data;
386 del_timer(send_els->timer);
388 adapter = send_els->adapter;
389 port = send_els->port;
390 d_id = send_els->d_id;
392 /* request rejected or timed out */
393 if (send_els->status != 0) {
394 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
395 "force physical port reopen "
396 "(adapter %s, port d_id=0x%08x)\n",
397 zfcp_get_busid_by_adapter(adapter), d_id);
398 debug_text_event(adapter->erp_dbf, 3, "forcreop");
399 if (zfcp_erp_port_forced_reopen(port, 0))
400 ZFCP_LOG_NORMAL("failed reopen of port "
401 "(adapter %s, wwpn=0x%016Lx)\n",
402 zfcp_get_busid_by_port(port),
407 adisc = zfcp_sg_to_address(send_els->resp);
409 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
410 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
411 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
412 d_id, fc_host_port_id(adapter->scsi_host),
413 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
414 adisc->hard_nport_id, adisc->nport_id);
416 /* set wwnn for port */
418 port->wwnn = adisc->wwnn;
420 if (port->wwpn != adisc->wwpn) {
421 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
422 "port (adapter %s, wwpn=0x%016Lx, "
423 "adisc_resp_wwpn=0x%016Lx)\n",
424 zfcp_get_busid_by_port(port),
425 port->wwpn, (wwn_t) adisc->wwpn);
426 if (zfcp_erp_port_reopen(port, 0))
427 ZFCP_LOG_NORMAL("failed reopen of port "
428 "(adapter %s, wwpn=0x%016Lx)\n",
429 zfcp_get_busid_by_port(port),
435 __free_pages(send_els->req->page, 0);
436 kfree(send_els->timer);
437 kfree(send_els->req);
438 kfree(send_els->resp);
444 * zfcp_test_link - lightweight link test procedure
445 * @port: port to be tested
447 * Test status of a link to a remote port using the ELS command ADISC.
450 zfcp_test_link(struct zfcp_port *port)
455 retval = zfcp_erp_adisc(port);
458 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
459 "on adapter %s\n ", port->wwpn,
460 zfcp_get_busid_by_port(port));
461 retval = zfcp_erp_port_forced_reopen(port, 0);
463 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
464 "on adapter %s failed\n", port->wwpn,
465 zfcp_get_busid_by_port(port));
477 * purpose: called if a port failed to be opened normally
478 * initiates Forced Reopen recovery which is done
481 * returns: 0 - initiated action successfully
482 * <0 - failed to initiate action
485 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
488 struct zfcp_adapter *adapter = port->adapter;
490 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
491 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
493 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
494 port->wwpn, zfcp_get_busid_by_port(port));
496 zfcp_erp_port_block(port, clear_mask);
498 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
499 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
500 "on adapter %s\n", port->wwpn,
501 zfcp_get_busid_by_port(port));
502 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
503 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
508 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
509 port->adapter, port, NULL);
518 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
519 * used to ensure the correct locking
521 * returns: 0 - initiated action successfully
522 * <0 - failed to initiate action
525 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
529 struct zfcp_adapter *adapter;
531 adapter = port->adapter;
532 read_lock_irqsave(&zfcp_data.config_lock, flags);
533 write_lock(&adapter->erp_lock);
534 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
535 write_unlock(&adapter->erp_lock);
536 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
544 * purpose: called if a port is to be opened
545 * initiates Reopen recovery which is done
548 * returns: 0 - initiated action successfully
549 * <0 - failed to initiate action
552 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
555 struct zfcp_adapter *adapter = port->adapter;
557 debug_text_event(adapter->erp_dbf, 5, "p_ro");
558 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
560 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
561 port->wwpn, zfcp_get_busid_by_port(port));
563 zfcp_erp_port_block(port, clear_mask);
565 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
566 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
567 "on adapter %s\n", port->wwpn,
568 zfcp_get_busid_by_port(port));
569 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
570 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
571 /* ensure propagation of failed status to new devices */
572 zfcp_erp_port_failed(port);
577 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
578 port->adapter, port, NULL);
585 * zfcp_erp_port_reopen - initiate reopen of a remote port
586 * @port: port to be reopened
587 * @clear_mask: specifies flags in port status to be cleared
588 * Return: 0 on success, < 0 on error
590 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
591 * correct locking. An error recovery task is initiated to do the reopen.
592 * To wait for the completion of the reopen zfcp_erp_wait should be used.
595 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
599 struct zfcp_adapter *adapter = port->adapter;
601 read_lock_irqsave(&zfcp_data.config_lock, flags);
602 write_lock(&adapter->erp_lock);
603 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
604 write_unlock(&adapter->erp_lock);
605 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
613 * purpose: called if a unit is to be opened
614 * initiates Reopen recovery which is done
617 * returns: 0 - initiated action successfully
618 * <0 - failed to initiate action
621 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
624 struct zfcp_adapter *adapter = unit->port->adapter;
626 debug_text_event(adapter->erp_dbf, 5, "u_ro");
627 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
628 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
629 "on adapter %s\n", unit->fcp_lun,
630 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
632 zfcp_erp_unit_block(unit, clear_mask);
634 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
635 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
636 "on port 0x%016Lx on adapter %s\n",
637 unit->fcp_lun, unit->port->wwpn,
638 zfcp_get_busid_by_unit(unit));
639 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
640 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
646 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
647 unit->port->adapter, unit->port, unit);
653 * zfcp_erp_unit_reopen - initiate reopen of a unit
654 * @unit: unit to be reopened
655 * @clear_mask: specifies flags in unit status to be cleared
656 * Return: 0 on success, < 0 on error
658 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
659 * locking. An error recovery task is initiated to do the reopen.
660 * To wait for the completion of the reopen zfcp_erp_wait should be used.
663 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
667 struct zfcp_adapter *adapter;
668 struct zfcp_port *port;
671 adapter = port->adapter;
673 read_lock_irqsave(&zfcp_data.config_lock, flags);
674 write_lock(&adapter->erp_lock);
675 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
676 write_unlock(&adapter->erp_lock);
677 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
683 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
685 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
687 debug_text_event(adapter->erp_dbf, 6, "a_bl");
688 zfcp_erp_modify_adapter_status(adapter,
689 ZFCP_STATUS_COMMON_UNBLOCKED |
690 clear_mask, ZFCP_CLEAR);
694 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
696 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
698 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
699 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
705 * purpose: disable I/O,
706 * return any open requests and clean them up,
707 * aim: no pending and incoming I/O
712 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
714 struct zfcp_adapter *adapter = port->adapter;
716 debug_text_event(adapter->erp_dbf, 6, "p_bl");
717 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
718 zfcp_erp_modify_port_status(port,
719 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
726 * purpose: enable I/O
731 zfcp_erp_port_unblock(struct zfcp_port *port)
733 struct zfcp_adapter *adapter = port->adapter;
735 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
736 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
737 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->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_unit_block(struct zfcp_unit *unit, int clear_mask)
752 struct zfcp_adapter *adapter = unit->port->adapter;
754 debug_text_event(adapter->erp_dbf, 6, "u_bl");
755 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
756 zfcp_erp_modify_unit_status(unit,
757 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
764 * purpose: enable I/O
769 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
771 struct zfcp_adapter *adapter = unit->port->adapter;
773 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
774 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
775 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
779 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
781 struct zfcp_adapter *adapter = erp_action->adapter;
783 debug_text_event(adapter->erp_dbf, 4, "a_ar");
784 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
786 zfcp_erp_action_to_ready(erp_action);
787 up(&adapter->erp_ready_sem);
795 * returns: <0 erp_action not found in any list
796 * ZFCP_ERP_ACTION_READY erp_action is in ready list
797 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
799 * locks: erp_lock must be held
802 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
804 int retval = -EINVAL;
805 struct list_head *entry;
806 struct zfcp_erp_action *entry_erp_action;
807 struct zfcp_adapter *adapter = erp_action->adapter;
809 /* search in running list */
810 list_for_each(entry, &adapter->erp_running_head) {
812 list_entry(entry, struct zfcp_erp_action, list);
813 if (entry_erp_action == erp_action) {
814 retval = ZFCP_ERP_ACTION_RUNNING;
818 /* search in ready list */
819 list_for_each(entry, &adapter->erp_ready_head) {
821 list_entry(entry, struct zfcp_erp_action, list);
822 if (entry_erp_action == erp_action) {
823 retval = ZFCP_ERP_ACTION_READY;
833 * purpose: checks current status of action (timed out, dismissed, ...)
834 * and does appropriate preparations (dismiss fsf request, ...)
836 * locks: called under erp_lock (disabled interrupts)
841 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
844 struct zfcp_fsf_req *fsf_req = NULL;
845 struct zfcp_adapter *adapter = erp_action->adapter;
847 if (erp_action->fsf_req) {
848 /* take lock to ensure that request is not deleted meanwhile */
849 spin_lock(&adapter->req_list_lock);
850 if ((!zfcp_reqlist_ismember(adapter,
851 erp_action->fsf_req->req_id)) &&
852 (fsf_req->erp_action == erp_action)) {
853 /* fsf_req still exists */
854 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
855 debug_event(adapter->erp_dbf, 3, &fsf_req,
856 sizeof (unsigned long));
857 /* dismiss fsf_req of timed out/dismissed erp_action */
858 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
859 ZFCP_STATUS_ERP_TIMEDOUT)) {
860 debug_text_event(adapter->erp_dbf, 3,
862 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
864 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
865 ZFCP_LOG_NORMAL("error: erp step timed out "
866 "(action=%d, fsf_req=%p)\n ",
868 erp_action->fsf_req);
871 * If fsf_req is neither dismissed nor completed
872 * then keep it running asynchronously and don't mess
873 * with the association of erp_action and fsf_req.
875 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
876 ZFCP_STATUS_FSFREQ_DISMISSED)) {
877 /* forget about association between fsf_req
879 fsf_req->erp_action = NULL;
880 erp_action->fsf_req = NULL;
883 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
885 * even if this fsf_req has gone, forget about
886 * association between erp_action and fsf_req
888 erp_action->fsf_req = NULL;
890 spin_unlock(&adapter->req_list_lock);
892 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
898 * zfcp_erp_async_handler_nolock - complete erp_action
900 * Used for normal completion, time-out, dismissal and failure after
901 * low memory condition.
903 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
904 unsigned long set_mask)
906 struct zfcp_adapter *adapter = erp_action->adapter;
908 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
909 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
910 debug_event(adapter->erp_dbf, 2, &erp_action->action,
912 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
913 del_timer(&erp_action->timer);
914 erp_action->status |= set_mask;
915 zfcp_erp_action_ready(erp_action);
917 /* action is ready or gone - nothing to do */
918 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
919 debug_event(adapter->erp_dbf, 3, &erp_action->action,
925 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
927 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
928 unsigned long set_mask)
930 struct zfcp_adapter *adapter = erp_action->adapter;
933 write_lock_irqsave(&adapter->erp_lock, flags);
934 zfcp_erp_async_handler_nolock(erp_action, set_mask);
935 write_unlock_irqrestore(&adapter->erp_lock, flags);
939 * purpose: is called for erp_action which was slept waiting for
940 * memory becoming avaliable,
941 * will trigger that this action will be continued
944 zfcp_erp_memwait_handler(unsigned long data)
946 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
947 struct zfcp_adapter *adapter = erp_action->adapter;
949 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
950 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
952 zfcp_erp_async_handler(erp_action, 0);
956 * purpose: is called if an asynchronous erp step timed out,
957 * action gets an appropriate flag and will be processed
961 zfcp_erp_timeout_handler(unsigned long data)
963 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
964 struct zfcp_adapter *adapter = erp_action->adapter;
966 debug_text_event(adapter->erp_dbf, 2, "a_th");
967 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
969 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
973 * zfcp_erp_action_dismiss - dismiss an erp_action
975 * adapter->erp_lock must be held
977 * Dismissal of an erp_action is usually required if an erp_action of
978 * higher priority is generated.
980 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
982 struct zfcp_adapter *adapter = erp_action->adapter;
984 debug_text_event(adapter->erp_dbf, 2, "a_adis");
985 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
987 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
991 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
995 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
997 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
999 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1001 zfcp_get_busid_by_adapter(adapter));
1002 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1004 wait_event(adapter->erp_thread_wqh,
1005 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1007 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1010 return (retval < 0);
1020 * context: process (i.e. proc-fs or rmmod/insmod)
1022 * note: The caller of this routine ensures that the specified
1023 * adapter has been shut down and that this operation
1024 * has been completed. Thus, there are no pending erp_actions
1025 * which would need to be handled here.
1028 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1032 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1033 up(&adapter->erp_ready_sem);
1035 wait_event(adapter->erp_thread_wqh,
1036 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1039 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1042 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1048 * purpose: is run as a kernel thread,
1049 * goes through list of error recovery actions of associated adapter
1050 * and delegates single action to execution
1055 zfcp_erp_thread(void *data)
1057 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1058 struct list_head *next;
1059 struct zfcp_erp_action *erp_action;
1060 unsigned long flags;
1062 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1063 /* Block all signals */
1064 siginitsetinv(¤t->blocked, 0);
1065 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1066 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1067 wake_up(&adapter->erp_thread_wqh);
1069 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1070 &adapter->status)) {
1072 write_lock_irqsave(&adapter->erp_lock, flags);
1073 next = adapter->erp_ready_head.prev;
1074 write_unlock_irqrestore(&adapter->erp_lock, flags);
1076 if (next != &adapter->erp_ready_head) {
1078 list_entry(next, struct zfcp_erp_action, list);
1080 * process action (incl. [re]moving it
1081 * from 'ready' queue)
1083 zfcp_erp_strategy(erp_action);
1087 * sleep as long as there is nothing to do, i.e.
1088 * no action in 'ready' queue to be processed and
1089 * thread is not to be killed
1091 down_interruptible(&adapter->erp_ready_sem);
1092 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1095 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1096 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1097 wake_up(&adapter->erp_thread_wqh);
1105 * purpose: drives single error recovery action and schedules higher and
1106 * subordinate actions, if necessary
1108 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1109 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1110 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1111 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1112 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1115 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1118 struct zfcp_adapter *adapter = erp_action->adapter;
1119 struct zfcp_port *port = erp_action->port;
1120 struct zfcp_unit *unit = erp_action->unit;
1121 int action = erp_action->action;
1122 u32 status = erp_action->status;
1123 unsigned long flags;
1125 /* serialise dismissing, timing out, moving, enqueueing */
1126 read_lock_irqsave(&zfcp_data.config_lock, flags);
1127 write_lock(&adapter->erp_lock);
1129 /* dequeue dismissed action and leave, if required */
1130 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1131 if (retval == ZFCP_ERP_DISMISSED) {
1132 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1137 * move action to 'running' queue before processing it
1138 * (to avoid a race condition regarding moving the
1139 * action to the 'running' queue and back)
1141 zfcp_erp_action_to_running(erp_action);
1144 * try to process action as far as possible,
1145 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1146 * afterwards the lock is required again for the following reasons:
1147 * - dequeueing of finished action and enqueueing of
1148 * follow-up actions must be atomic so that any other
1149 * reopen-routine does not believe there is nothing to do
1150 * and that it is safe to enqueue something else,
1151 * - we want to force any control thread which is dismissing
1152 * actions to finish this before we decide about
1153 * necessary steps to be taken here further
1155 write_unlock(&adapter->erp_lock);
1156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1157 retval = zfcp_erp_strategy_do_action(erp_action);
1158 read_lock_irqsave(&zfcp_data.config_lock, flags);
1159 write_lock(&adapter->erp_lock);
1162 * check for dismissed status again to avoid follow-up actions,
1163 * failing of targets and so on for dismissed actions
1165 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1168 case ZFCP_ERP_DISMISSED:
1169 /* leave since this action has ridden to its ancestors */
1170 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1172 case ZFCP_ERP_NOMEM:
1173 /* no memory to continue immediately, let it sleep */
1174 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1175 ++adapter->erp_low_mem_count;
1176 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1178 /* This condition is true if there is no memory available
1179 for any erp_action on this adapter. This implies that there
1180 are no elements in the memory pool(s) left for erp_actions.
1181 This might happen if an erp_action that used a memory pool
1182 element was timed out.
1184 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1185 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1186 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1187 "restarting I/O on adapter %s "
1188 "to free mempool\n",
1189 zfcp_get_busid_by_adapter(adapter));
1190 zfcp_erp_adapter_reopen_internal(adapter, 0);
1192 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1193 retval = zfcp_erp_strategy_memwait(erp_action);
1196 case ZFCP_ERP_CONTINUES:
1197 /* leave since this action runs asynchronously */
1198 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1199 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1200 --adapter->erp_low_mem_count;
1201 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1205 /* ok, finished action (whatever its result is) */
1207 /* check for unrecoverable targets */
1208 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1210 /* action must be dequeued (here to allow for further ones) */
1211 zfcp_erp_action_dequeue(erp_action);
1214 * put this target through the erp mill again if someone has
1215 * requested to change the status of a target being online
1216 * to offline or the other way around
1217 * (old retval is preserved if nothing has to be done here)
1219 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1220 port, unit, retval);
1223 * leave if target is in permanent error state or if
1224 * action is repeated in order to process state change
1226 if (retval == ZFCP_ERP_EXIT) {
1227 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1231 /* trigger follow up actions */
1232 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1235 write_unlock(&adapter->erp_lock);
1236 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1238 if (retval != ZFCP_ERP_CONTINUES)
1239 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1242 * a few tasks remain when the erp queues are empty
1243 * (don't do that if the last action evaluated was dismissed
1244 * since this clearly indicates that there is more to come) :
1245 * - close the name server port if it is open yet
1246 * (enqueues another [probably] final action)
1247 * - otherwise, wake up whoever wants to be woken when we are
1250 if (retval != ZFCP_ERP_DISMISSED)
1251 zfcp_erp_strategy_check_queues(adapter);
1253 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1263 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1264 * retval - otherwise
1267 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1269 struct zfcp_adapter *adapter = erp_action->adapter;
1271 zfcp_erp_strategy_check_fsfreq(erp_action);
1273 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1274 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1275 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1276 zfcp_erp_action_dequeue(erp_action);
1277 retval = ZFCP_ERP_DISMISSED;
1279 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1285 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1287 int retval = ZFCP_ERP_FAILED;
1288 struct zfcp_adapter *adapter = erp_action->adapter;
1291 * try to execute/continue action as far as possible,
1292 * note: no lock in subsequent strategy routines
1293 * (this allows these routine to call schedule, e.g.
1294 * kmalloc with such flags or qdio_initialize & friends)
1295 * Note: in case of timeout, the seperate strategies will fail
1296 * anyhow. No need for a special action. Even worse, a nameserver
1297 * failure would not wake up waiting ports without the call.
1299 switch (erp_action->action) {
1301 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1302 retval = zfcp_erp_adapter_strategy(erp_action);
1305 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1306 retval = zfcp_erp_port_forced_strategy(erp_action);
1309 case ZFCP_ERP_ACTION_REOPEN_PORT:
1310 retval = zfcp_erp_port_strategy(erp_action);
1313 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1314 retval = zfcp_erp_unit_strategy(erp_action);
1318 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1319 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1321 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1322 "adapter %s (action=%d)\n",
1323 zfcp_get_busid_by_adapter(erp_action->adapter),
1324 erp_action->action);
1333 * purpose: triggers retry of this action after a certain amount of time
1334 * by means of timer provided by erp_action
1336 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1339 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1341 int retval = ZFCP_ERP_CONTINUES;
1342 struct zfcp_adapter *adapter = erp_action->adapter;
1344 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1345 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1346 init_timer(&erp_action->timer);
1347 erp_action->timer.function = zfcp_erp_memwait_handler;
1348 erp_action->timer.data = (unsigned long) erp_action;
1349 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1350 add_timer(&erp_action->timer);
1356 * function: zfcp_erp_adapter_failed
1358 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1362 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1364 zfcp_erp_modify_adapter_status(adapter,
1365 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1366 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1367 zfcp_get_busid_by_adapter(adapter));
1368 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1372 * function: zfcp_erp_port_failed
1374 * purpose: sets the port and all underlying devices to ERP_FAILED
1378 zfcp_erp_port_failed(struct zfcp_port *port)
1380 zfcp_erp_modify_port_status(port,
1381 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1383 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1384 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1385 "port d_id=0x%08x)\n",
1386 zfcp_get_busid_by_port(port), port->d_id);
1388 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1389 zfcp_get_busid_by_port(port), port->wwpn);
1391 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1392 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1396 * function: zfcp_erp_unit_failed
1398 * purpose: sets the unit to ERP_FAILED
1402 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1404 zfcp_erp_modify_unit_status(unit,
1405 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1407 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1408 " on adapter %s\n", unit->fcp_lun,
1409 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1410 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1411 debug_event(unit->port->adapter->erp_dbf, 2,
1412 &unit->fcp_lun, sizeof (fcp_lun_t));
1416 * function: zfcp_erp_strategy_check_target
1418 * purpose: increments the erp action count on the device currently in
1419 * recovery if the action failed or resets the count in case of
1420 * success. If a maximum count is exceeded the device is marked
1422 * The 'blocked' state of a target which has been recovered
1423 * successfully is reset.
1425 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1426 * ZFCP_ERP_SUCCEEDED - action finished successfully
1427 * ZFCP_ERP_EXIT - action failed and will not continue
1430 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1432 struct zfcp_adapter *adapter = erp_action->adapter;
1433 struct zfcp_port *port = erp_action->port;
1434 struct zfcp_unit *unit = erp_action->unit;
1436 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1437 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1438 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1440 switch (erp_action->action) {
1442 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1443 result = zfcp_erp_strategy_check_unit(unit, result);
1446 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1447 case ZFCP_ERP_ACTION_REOPEN_PORT:
1448 result = zfcp_erp_strategy_check_port(port, result);
1451 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1452 result = zfcp_erp_strategy_check_adapter(adapter, result);
1460 zfcp_erp_strategy_statechange(int action,
1462 struct zfcp_adapter *adapter,
1463 struct zfcp_port *port,
1464 struct zfcp_unit *unit, int retval)
1466 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1467 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1471 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1472 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1474 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1475 retval = ZFCP_ERP_EXIT;
1479 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1480 case ZFCP_ERP_ACTION_REOPEN_PORT:
1481 if (zfcp_erp_strategy_statechange_detected(&port->status,
1483 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1484 retval = ZFCP_ERP_EXIT;
1488 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1489 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1491 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1492 retval = ZFCP_ERP_EXIT;
1501 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1504 /* take it online */
1505 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1506 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1507 /* take it offline */
1508 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1509 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1513 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1515 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1516 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1517 sizeof (fcp_lun_t));
1520 case ZFCP_ERP_SUCCEEDED :
1521 atomic_set(&unit->erp_counter, 0);
1522 zfcp_erp_unit_unblock(unit);
1524 case ZFCP_ERP_FAILED :
1525 atomic_inc(&unit->erp_counter);
1526 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1527 zfcp_erp_unit_failed(unit);
1529 case ZFCP_ERP_EXIT :
1534 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1535 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1536 result = ZFCP_ERP_EXIT;
1543 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1545 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1546 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1549 case ZFCP_ERP_SUCCEEDED :
1550 atomic_set(&port->erp_counter, 0);
1551 zfcp_erp_port_unblock(port);
1553 case ZFCP_ERP_FAILED :
1554 atomic_inc(&port->erp_counter);
1555 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1556 zfcp_erp_port_failed(port);
1558 case ZFCP_ERP_EXIT :
1563 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1564 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1565 result = ZFCP_ERP_EXIT;
1572 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1574 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1577 case ZFCP_ERP_SUCCEEDED :
1578 atomic_set(&adapter->erp_counter, 0);
1579 zfcp_erp_adapter_unblock(adapter);
1581 case ZFCP_ERP_FAILED :
1582 atomic_inc(&adapter->erp_counter);
1583 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1584 zfcp_erp_adapter_failed(adapter);
1586 case ZFCP_ERP_EXIT :
1591 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1592 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1593 result = ZFCP_ERP_EXIT;
1602 * purpose: remaining things in good cases,
1603 * escalation in bad cases
1608 zfcp_erp_strategy_followup_actions(int action,
1609 struct zfcp_adapter *adapter,
1610 struct zfcp_port *port,
1611 struct zfcp_unit *unit, int status)
1613 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1614 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1616 /* initiate follow-up actions depending on success of finished action */
1619 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1620 if (status == ZFCP_ERP_SUCCEEDED)
1621 zfcp_erp_port_reopen_all_internal(adapter, 0);
1623 zfcp_erp_adapter_reopen_internal(adapter, 0);
1626 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1627 if (status == ZFCP_ERP_SUCCEEDED)
1628 zfcp_erp_port_reopen_internal(port, 0);
1630 zfcp_erp_adapter_reopen_internal(adapter, 0);
1633 case ZFCP_ERP_ACTION_REOPEN_PORT:
1634 if (status == ZFCP_ERP_SUCCEEDED)
1635 zfcp_erp_unit_reopen_all_internal(port, 0);
1637 zfcp_erp_port_forced_reopen_internal(port, 0);
1640 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1641 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1643 zfcp_erp_port_reopen_internal(unit->port, 0);
1651 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1653 unsigned long flags;
1655 read_lock_irqsave(&zfcp_data.config_lock, flags);
1656 read_lock(&adapter->erp_lock);
1657 if (list_empty(&adapter->erp_ready_head) &&
1658 list_empty(&adapter->erp_running_head)) {
1659 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1660 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1662 wake_up(&adapter->erp_done_wqh);
1664 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1665 read_unlock(&adapter->erp_lock);
1666 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1672 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1673 * @adapter: adapter for which to wait for completion of its error recovery
1677 zfcp_erp_wait(struct zfcp_adapter *adapter)
1681 wait_event(adapter->erp_done_wqh,
1682 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1689 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1690 u32 mask, int set_or_clear)
1692 struct zfcp_port *port;
1693 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1695 if (set_or_clear == ZFCP_SET) {
1696 atomic_set_mask(mask, &adapter->status);
1697 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1699 atomic_clear_mask(mask, &adapter->status);
1700 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1701 atomic_set(&adapter->erp_counter, 0);
1702 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1704 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1706 /* Deal with all underlying devices, only pass common_mask */
1708 list_for_each_entry(port, &adapter->port_list_head, list)
1709 zfcp_erp_modify_port_status(port, common_mask,
1714 * function: zfcp_erp_modify_port_status
1716 * purpose: sets the port and all underlying devices to ERP_FAILED
1720 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1722 struct zfcp_unit *unit;
1723 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1725 if (set_or_clear == ZFCP_SET) {
1726 atomic_set_mask(mask, &port->status);
1727 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1729 atomic_clear_mask(mask, &port->status);
1730 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1731 atomic_set(&port->erp_counter, 0);
1732 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1734 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1735 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1737 /* Modify status of all underlying devices, only pass common mask */
1739 list_for_each_entry(unit, &port->unit_list_head, list)
1740 zfcp_erp_modify_unit_status(unit, common_mask,
1745 * function: zfcp_erp_modify_unit_status
1747 * purpose: sets the unit to ERP_FAILED
1751 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1753 if (set_or_clear == ZFCP_SET) {
1754 atomic_set_mask(mask, &unit->status);
1755 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1757 atomic_clear_mask(mask, &unit->status);
1758 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1759 atomic_set(&unit->erp_counter, 0);
1761 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1763 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1764 sizeof (fcp_lun_t));
1765 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1771 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1772 * used to ensure the correct locking
1774 * returns: 0 - initiated action successfully
1775 * <0 - failed to initiate action
1778 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1781 unsigned long flags;
1783 read_lock_irqsave(&zfcp_data.config_lock, flags);
1784 write_lock(&adapter->erp_lock);
1785 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1786 write_unlock(&adapter->erp_lock);
1787 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1793 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1796 struct zfcp_port *port;
1798 list_for_each_entry(port, &adapter->port_list_head, list)
1799 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1800 zfcp_erp_port_reopen_internal(port, clear_mask);
1813 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1816 struct zfcp_unit *unit;
1818 list_for_each_entry(unit, &port->unit_list_head, list)
1819 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1827 * purpose: this routine executes the 'Reopen Adapter' action
1828 * (the entire action is processed synchronously, since
1829 * there are no actions which might be run concurrently
1832 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1833 * ZFCP_ERP_FAILED - action finished unsuccessfully
1836 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1839 struct zfcp_adapter *adapter = erp_action->adapter;
1841 retval = zfcp_erp_adapter_strategy_close(erp_action);
1842 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1843 retval = ZFCP_ERP_EXIT;
1845 retval = zfcp_erp_adapter_strategy_open(erp_action);
1847 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1848 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1849 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1851 if (retval == ZFCP_ERP_FAILED) {
1852 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1853 "to recover itself\n",
1854 zfcp_get_busid_by_adapter(adapter));
1855 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1866 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1867 * ZFCP_ERP_FAILED - action finished unsuccessfully
1870 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1874 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1875 &erp_action->adapter->status);
1876 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1877 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1878 &erp_action->adapter->status);
1888 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1889 * ZFCP_ERP_FAILED - action finished unsuccessfully
1892 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1896 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1897 &erp_action->adapter->status);
1898 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1899 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1900 &erp_action->adapter->status);
1906 * function: zfcp_register_adapter
1908 * purpose: allocate the irq associated with this devno and register
1909 * the FSF adapter with the SCSI stack
1914 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1916 int retval = ZFCP_ERP_SUCCEEDED;
1921 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1922 if (retval != ZFCP_ERP_SUCCEEDED)
1925 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1926 if (retval != ZFCP_ERP_SUCCEEDED)
1927 goto failed_openfcp;
1929 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1933 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1934 &erp_action->adapter->status);
1937 zfcp_erp_adapter_strategy_close_qdio(erp_action);
1938 zfcp_erp_adapter_strategy_close_fsf(erp_action);
1945 * function: zfcp_qdio_init
1947 * purpose: setup QDIO operation for specified adapter
1949 * returns: 0 - successful setup
1953 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1957 volatile struct qdio_buffer_element *sbale;
1958 struct zfcp_adapter *adapter = erp_action->adapter;
1960 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
1961 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1963 zfcp_get_busid_by_adapter(adapter));
1967 if (qdio_establish(&adapter->qdio_init_data) != 0) {
1968 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1970 zfcp_get_busid_by_adapter(adapter));
1971 goto failed_qdio_establish;
1973 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
1975 if (qdio_activate(adapter->ccw_device, 0) != 0) {
1976 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1978 zfcp_get_busid_by_adapter(adapter));
1979 goto failed_qdio_activate;
1981 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
1984 * put buffers into response queue,
1986 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
1987 sbale = &(adapter->response_queue.buffer[i]->element[0]);
1989 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
1993 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1994 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1995 zfcp_get_busid_by_adapter(adapter),
1996 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
1998 retval = do_QDIO(adapter->ccw_device,
1999 QDIO_FLAG_SYNC_INPUT,
2000 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2003 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2005 goto failed_do_qdio;
2007 adapter->response_queue.free_index = 0;
2008 atomic_set(&adapter->response_queue.free_count, 0);
2009 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2010 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2012 /* set index of first avalable SBALS / number of available SBALS */
2013 adapter->request_queue.free_index = 0;
2014 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2015 adapter->request_queue.distance_from_int = 0;
2017 /* initialize waitqueue used to wait for free SBALs in requests queue */
2018 init_waitqueue_head(&adapter->request_wq);
2020 /* ok, we did it - skip all cleanups for different failures */
2021 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2022 retval = ZFCP_ERP_SUCCEEDED;
2028 failed_qdio_activate:
2029 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2030 while (qdio_shutdown(adapter->ccw_device,
2031 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2033 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2035 failed_qdio_establish:
2037 retval = ZFCP_ERP_FAILED;
2044 * zfcp_erp_adapter_strategy_close_qdio - close qdio queues for an adapter
2047 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2051 struct zfcp_adapter *adapter = erp_action->adapter;
2053 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2054 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2055 "queues on adapter %s\n",
2056 zfcp_get_busid_by_adapter(adapter));
2061 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2062 * do_QDIO won't be called while qdio_shutdown is in progress.
2064 write_lock_irq(&adapter->request_queue.queue_lock);
2065 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2066 write_unlock_irq(&adapter->request_queue.queue_lock);
2068 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2069 while (qdio_shutdown(adapter->ccw_device,
2070 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2072 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2075 * First we had to stop QDIO operation.
2076 * Now it is safe to take the following actions.
2079 /* Cleanup only necessary when there are unacknowledged buffers */
2080 if (atomic_read(&adapter->request_queue.free_count)
2081 < QDIO_MAX_BUFFERS_PER_Q) {
2082 first_used = (adapter->request_queue.free_index +
2083 atomic_read(&adapter->request_queue.free_count))
2084 % QDIO_MAX_BUFFERS_PER_Q;
2085 used_count = QDIO_MAX_BUFFERS_PER_Q -
2086 atomic_read(&adapter->request_queue.free_count);
2087 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2088 first_used, used_count);
2090 adapter->response_queue.free_index = 0;
2091 atomic_set(&adapter->response_queue.free_count, 0);
2092 adapter->request_queue.free_index = 0;
2093 atomic_set(&adapter->request_queue.free_count, 0);
2094 adapter->request_queue.distance_from_int = 0;
2098 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2102 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2103 if (retval == ZFCP_ERP_FAILED)
2104 return ZFCP_ERP_FAILED;
2106 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2107 if (retval == ZFCP_ERP_FAILED)
2108 return ZFCP_ERP_FAILED;
2110 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2114 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2116 int retval = ZFCP_ERP_SUCCEEDED;
2118 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2119 struct zfcp_adapter *adapter = erp_action->adapter;
2121 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2123 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2124 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2126 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2127 write_lock_irq(&adapter->erp_lock);
2128 zfcp_erp_action_to_running(erp_action);
2129 write_unlock_irq(&adapter->erp_lock);
2130 zfcp_erp_timeout_init(erp_action);
2131 if (zfcp_fsf_exchange_config_data(erp_action)) {
2132 retval = ZFCP_ERP_FAILED;
2133 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2134 ZFCP_LOG_INFO("error: initiation of exchange of "
2135 "configuration data failed for "
2137 zfcp_get_busid_by_adapter(adapter));
2140 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2141 ZFCP_LOG_DEBUG("Xchange underway\n");
2145 * Both the normal completion handler as well as the timeout
2146 * handler will do an 'up' when the 'exchange config data'
2147 * request completes or times out. Thus, the signal to go on
2148 * won't be lost utilizing this semaphore.
2149 * Furthermore, this 'adapter_reopen' action is
2150 * guaranteed to be the only action being there (highest action
2151 * which prevents other actions from being created).
2152 * Resulting from that, the wake signal recognized here
2153 * _must_ be the one belonging to the 'exchange config
2156 down(&adapter->erp_ready_sem);
2157 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2158 ZFCP_LOG_INFO("error: exchange of configuration data "
2159 "for adapter %s timed out\n",
2160 zfcp_get_busid_by_adapter(adapter));
2164 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2168 ZFCP_LOG_DEBUG("host connection still initialising... "
2169 "waiting and retrying...\n");
2170 /* sleep a little bit before retry */
2171 msleep(jiffies_to_msecs(sleep));
2175 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2176 &adapter->status)) {
2177 ZFCP_LOG_INFO("error: exchange of configuration data for "
2178 "adapter %s failed\n",
2179 zfcp_get_busid_by_adapter(adapter));
2180 retval = ZFCP_ERP_FAILED;
2187 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2190 struct zfcp_adapter *adapter;
2192 adapter = erp_action->adapter;
2193 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2195 write_lock_irq(&adapter->erp_lock);
2196 zfcp_erp_action_to_running(erp_action);
2197 write_unlock_irq(&adapter->erp_lock);
2199 zfcp_erp_timeout_init(erp_action);
2200 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
2201 if (ret == -EOPNOTSUPP) {
2202 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2203 return ZFCP_ERP_SUCCEEDED;
2205 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2206 return ZFCP_ERP_FAILED;
2208 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2210 ret = ZFCP_ERP_SUCCEEDED;
2211 down(&adapter->erp_ready_sem);
2212 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2213 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2214 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2215 ret = ZFCP_ERP_FAILED;
2218 /* don't treat as error for the sake of compatibility */
2219 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2220 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2221 "%s\n", zfcp_get_busid_by_adapter(adapter));
2227 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2230 int retval = ZFCP_ERP_SUCCEEDED;
2232 struct zfcp_adapter *adapter = erp_action->adapter;
2235 adapter->status_read_failed = 0;
2236 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2237 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2239 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2240 "notification failed on adapter %s\n",
2241 zfcp_get_busid_by_adapter(adapter));
2242 retval = ZFCP_ERP_FAILED;
2252 * zfcp_erp_adapter_strategy_close_fsf - stop FSF operations for an adapter
2255 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2257 struct zfcp_adapter *adapter = erp_action->adapter;
2260 * wake waiting initiators of requests,
2261 * return SCSI commands (with error status),
2262 * clean up all requests (synchronously)
2264 zfcp_fsf_req_dismiss_all(adapter);
2265 /* reset FSF request sequence number */
2266 adapter->fsf_req_seq_no = 0;
2267 /* all ports and units are closed */
2268 zfcp_erp_modify_adapter_status(adapter,
2269 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2275 * purpose: this routine executes the 'Reopen Physical Port' action
2277 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2278 * ZFCP_ERP_SUCCEEDED - action finished successfully
2279 * ZFCP_ERP_FAILED - action finished unsuccessfully
2282 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2284 int retval = ZFCP_ERP_FAILED;
2285 struct zfcp_port *port = erp_action->port;
2286 struct zfcp_adapter *adapter = erp_action->adapter;
2288 switch (erp_action->step) {
2292 * the ULP spec. begs for waiting for oustanding commands
2294 case ZFCP_ERP_STEP_UNINITIALIZED:
2295 zfcp_erp_port_strategy_clearstati(port);
2297 * it would be sufficient to test only the normal open flag
2298 * since the phys. open flag cannot be set if the normal
2299 * open flag is unset - however, this is for readabilty ...
2301 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2302 ZFCP_STATUS_COMMON_OPEN),
2304 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2305 "close physical\n", port->wwpn);
2307 zfcp_erp_port_forced_strategy_close(erp_action);
2309 retval = ZFCP_ERP_FAILED;
2312 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2313 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2315 ZFCP_LOG_DEBUG("close physical failed for port "
2316 "0x%016Lx\n", port->wwpn);
2317 retval = ZFCP_ERP_FAILED;
2319 retval = ZFCP_ERP_SUCCEEDED;
2323 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2324 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2325 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2326 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2334 * purpose: this routine executes the 'Reopen Port' action
2336 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2337 * ZFCP_ERP_SUCCEEDED - action finished successfully
2338 * ZFCP_ERP_FAILED - action finished unsuccessfully
2341 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2343 int retval = ZFCP_ERP_FAILED;
2344 struct zfcp_port *port = erp_action->port;
2345 struct zfcp_adapter *adapter = erp_action->adapter;
2347 switch (erp_action->step) {
2351 * the ULP spec. begs for waiting for oustanding commands
2353 case ZFCP_ERP_STEP_UNINITIALIZED:
2354 zfcp_erp_port_strategy_clearstati(port);
2355 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2356 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2357 "close\n", port->wwpn);
2358 retval = zfcp_erp_port_strategy_close(erp_action);
2360 } /* else it's already closed, open it */
2363 case ZFCP_ERP_STEP_PORT_CLOSING:
2364 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2365 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2367 retval = ZFCP_ERP_FAILED;
2369 } /* else it's closed now, open it */
2372 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2373 retval = ZFCP_ERP_EXIT;
2375 retval = zfcp_erp_port_strategy_open(erp_action);
2378 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2379 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2380 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2381 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2387 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2391 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2392 &erp_action->port->status))
2393 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2395 retval = zfcp_erp_port_strategy_open_common(erp_action);
2401 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2404 struct zfcp_adapter *adapter = erp_action->adapter;
2405 struct zfcp_port *port = erp_action->port;
2407 switch (erp_action->step) {
2409 case ZFCP_ERP_STEP_UNINITIALIZED:
2410 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2411 case ZFCP_ERP_STEP_PORT_CLOSING:
2412 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2413 if (port->wwpn != adapter->peer_wwpn) {
2414 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2415 "on adapter %s.\nPeer WWPN "
2416 "0x%016Lx does not match\n",
2418 zfcp_get_busid_by_adapter(adapter),
2419 adapter->peer_wwpn);
2420 zfcp_erp_port_failed(port);
2421 retval = ZFCP_ERP_FAILED;
2424 port->d_id = adapter->peer_d_id;
2425 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2426 retval = zfcp_erp_port_strategy_open_port(erp_action);
2429 if (!(adapter->nameserver_port)) {
2430 retval = zfcp_nameserver_enqueue(adapter);
2432 ZFCP_LOG_NORMAL("error: nameserver port "
2433 "unavailable for adapter %s\n",
2434 zfcp_get_busid_by_adapter(adapter));
2435 retval = ZFCP_ERP_FAILED;
2439 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2440 &adapter->nameserver_port->status)) {
2441 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2442 "nameserver port\n");
2443 /* nameserver port may live again */
2444 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2445 &adapter->nameserver_port->status);
2446 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2449 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2450 retval = ZFCP_ERP_CONTINUES;
2452 retval = ZFCP_ERP_FAILED;
2455 /* else nameserver port is already open, fall through */
2456 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2457 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2458 &adapter->nameserver_port->status)) {
2459 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2460 retval = ZFCP_ERP_FAILED;
2462 ZFCP_LOG_DEBUG("nameserver port is open -> "
2463 "nameserver look-up for port 0x%016Lx\n",
2465 retval = zfcp_erp_port_strategy_open_common_lookup
2470 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2471 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2472 if (atomic_test_mask
2473 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2474 ZFCP_LOG_DEBUG("nameserver look-up failed "
2475 "for port 0x%016Lx "
2476 "(misconfigured WWPN?)\n",
2478 zfcp_erp_port_failed(port);
2479 retval = ZFCP_ERP_EXIT;
2481 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2482 "port 0x%016Lx\n", port->wwpn);
2483 retval = ZFCP_ERP_FAILED;
2486 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2487 "trying open\n", port->wwpn, port->d_id);
2488 retval = zfcp_erp_port_strategy_open_port(erp_action);
2492 case ZFCP_ERP_STEP_PORT_OPENING:
2493 /* D_ID might have changed during open */
2494 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2495 ZFCP_STATUS_PORT_DID_DID),
2497 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2498 retval = ZFCP_ERP_SUCCEEDED;
2500 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2502 retval = ZFCP_ERP_FAILED;
2507 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2509 retval = ZFCP_ERP_FAILED;
2516 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2519 struct zfcp_port *port = erp_action->port;
2521 switch (erp_action->step) {
2523 case ZFCP_ERP_STEP_UNINITIALIZED:
2524 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2525 case ZFCP_ERP_STEP_PORT_CLOSING:
2526 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2527 port->wwpn, port->d_id);
2528 retval = zfcp_erp_port_strategy_open_port(erp_action);
2531 case ZFCP_ERP_STEP_PORT_OPENING:
2532 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2533 ZFCP_LOG_DEBUG("WKA port is open\n");
2534 retval = ZFCP_ERP_SUCCEEDED;
2536 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2537 retval = ZFCP_ERP_FAILED;
2539 /* this is needed anyway (dont care for retval of wakeup) */
2540 ZFCP_LOG_DEBUG("continue other open port operations\n");
2541 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2545 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2547 retval = ZFCP_ERP_FAILED;
2556 * purpose: makes the erp thread continue with reopen (physical) port
2557 * actions which have been paused until the name server port
2558 * is opened (or failed)
2560 * returns: 0 (a kind of void retval, its not used)
2563 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2567 unsigned long flags;
2568 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2569 struct zfcp_erp_action *erp_action, *tmp;
2571 read_lock_irqsave(&adapter->erp_lock, flags);
2572 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2574 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2575 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2577 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2578 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2579 debug_event(adapter->erp_dbf, 3,
2580 &erp_action->port->wwpn, sizeof (wwn_t));
2581 if (atomic_test_mask(
2582 ZFCP_STATUS_COMMON_ERP_FAILED,
2583 &adapter->nameserver_port->status))
2584 zfcp_erp_port_failed(erp_action->port);
2585 zfcp_erp_action_ready(erp_action);
2588 read_unlock_irqrestore(&adapter->erp_lock, flags);
2598 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2599 * ZFCP_ERP_FAILED - action finished unsuccessfully
2602 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2605 struct zfcp_adapter *adapter = erp_action->adapter;
2606 struct zfcp_port *port = erp_action->port;
2608 zfcp_erp_timeout_init(erp_action);
2609 retval = zfcp_fsf_close_physical_port(erp_action);
2610 if (retval == -ENOMEM) {
2611 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2612 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2613 retval = ZFCP_ERP_NOMEM;
2616 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2618 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2619 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2620 /* could not send 'open', fail */
2621 retval = ZFCP_ERP_FAILED;
2624 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2625 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2626 retval = ZFCP_ERP_CONTINUES;
2632 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2635 struct zfcp_adapter *adapter = port->adapter;
2637 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2638 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2640 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2641 ZFCP_STATUS_COMMON_CLOSING |
2642 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2643 ZFCP_STATUS_PORT_DID_DID |
2644 ZFCP_STATUS_PORT_PHYS_CLOSING |
2645 ZFCP_STATUS_PORT_INVALID_WWPN,
2655 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2656 * ZFCP_ERP_FAILED - action finished unsuccessfully
2659 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2662 struct zfcp_adapter *adapter = erp_action->adapter;
2663 struct zfcp_port *port = erp_action->port;
2665 zfcp_erp_timeout_init(erp_action);
2666 retval = zfcp_fsf_close_port(erp_action);
2667 if (retval == -ENOMEM) {
2668 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2669 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2670 retval = ZFCP_ERP_NOMEM;
2673 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2675 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2676 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2677 /* could not send 'close', fail */
2678 retval = ZFCP_ERP_FAILED;
2681 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2682 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2683 retval = ZFCP_ERP_CONTINUES;
2693 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2694 * ZFCP_ERP_FAILED - action finished unsuccessfully
2697 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2700 struct zfcp_adapter *adapter = erp_action->adapter;
2701 struct zfcp_port *port = erp_action->port;
2703 zfcp_erp_timeout_init(erp_action);
2704 retval = zfcp_fsf_open_port(erp_action);
2705 if (retval == -ENOMEM) {
2706 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2707 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2708 retval = ZFCP_ERP_NOMEM;
2711 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2713 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2714 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2715 /* could not send 'open', fail */
2716 retval = ZFCP_ERP_FAILED;
2719 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2720 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2721 retval = ZFCP_ERP_CONTINUES;
2731 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2732 * ZFCP_ERP_FAILED - action finished unsuccessfully
2735 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2738 struct zfcp_adapter *adapter = erp_action->adapter;
2739 struct zfcp_port *port = erp_action->port;
2741 zfcp_erp_timeout_init(erp_action);
2742 retval = zfcp_ns_gid_pn_request(erp_action);
2743 if (retval == -ENOMEM) {
2744 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2745 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2746 retval = ZFCP_ERP_NOMEM;
2749 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2751 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2752 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2753 /* could not send nameserver request, fail */
2754 retval = ZFCP_ERP_FAILED;
2757 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2758 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2759 retval = ZFCP_ERP_CONTINUES;
2767 * purpose: this routine executes the 'Reopen Unit' action
2768 * currently no retries
2770 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2771 * ZFCP_ERP_SUCCEEDED - action finished successfully
2772 * ZFCP_ERP_FAILED - action finished unsuccessfully
2775 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2777 int retval = ZFCP_ERP_FAILED;
2778 struct zfcp_unit *unit = erp_action->unit;
2779 struct zfcp_adapter *adapter = erp_action->adapter;
2781 switch (erp_action->step) {
2785 * the ULP spec. begs for waiting for oustanding commands
2787 case ZFCP_ERP_STEP_UNINITIALIZED:
2788 zfcp_erp_unit_strategy_clearstati(unit);
2789 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2790 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2791 "trying close\n", unit->fcp_lun);
2792 retval = zfcp_erp_unit_strategy_close(erp_action);
2795 /* else it's already closed, fall through */
2796 case ZFCP_ERP_STEP_UNIT_CLOSING:
2797 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2798 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2800 retval = ZFCP_ERP_FAILED;
2802 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2803 retval = ZFCP_ERP_EXIT;
2805 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2806 "trying open\n", unit->fcp_lun);
2808 zfcp_erp_unit_strategy_open(erp_action);
2813 case ZFCP_ERP_STEP_UNIT_OPENING:
2814 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2815 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2817 retval = ZFCP_ERP_SUCCEEDED;
2819 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2821 retval = ZFCP_ERP_FAILED;
2826 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2827 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2828 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2829 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2834 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2837 struct zfcp_adapter *adapter = unit->port->adapter;
2839 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2840 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2842 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2843 ZFCP_STATUS_COMMON_CLOSING |
2844 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2845 ZFCP_STATUS_UNIT_SHARED |
2846 ZFCP_STATUS_UNIT_READONLY,
2857 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2858 * ZFCP_ERP_FAILED - action finished unsuccessfully
2861 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2864 struct zfcp_adapter *adapter = erp_action->adapter;
2865 struct zfcp_unit *unit = erp_action->unit;
2867 zfcp_erp_timeout_init(erp_action);
2868 retval = zfcp_fsf_close_unit(erp_action);
2869 if (retval == -ENOMEM) {
2870 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2871 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2872 sizeof (fcp_lun_t));
2873 retval = ZFCP_ERP_NOMEM;
2876 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2878 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2879 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2880 sizeof (fcp_lun_t));
2881 /* could not send 'close', fail */
2882 retval = ZFCP_ERP_FAILED;
2885 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2886 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2887 retval = ZFCP_ERP_CONTINUES;
2898 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2899 * ZFCP_ERP_FAILED - action finished unsuccessfully
2902 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2905 struct zfcp_adapter *adapter = erp_action->adapter;
2906 struct zfcp_unit *unit = erp_action->unit;
2908 zfcp_erp_timeout_init(erp_action);
2909 retval = zfcp_fsf_open_unit(erp_action);
2910 if (retval == -ENOMEM) {
2911 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2912 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2913 sizeof (fcp_lun_t));
2914 retval = ZFCP_ERP_NOMEM;
2917 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2919 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2920 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2921 sizeof (fcp_lun_t));
2922 /* could not send 'open', fail */
2923 retval = ZFCP_ERP_FAILED;
2926 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2927 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2928 retval = ZFCP_ERP_CONTINUES;
2934 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
2936 init_timer(&erp_action->timer);
2937 erp_action->timer.function = zfcp_erp_timeout_handler;
2938 erp_action->timer.data = (unsigned long) erp_action;
2939 /* jiffies will be added in zfcp_fsf_req_send */
2940 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
2946 * purpose: enqueue the specified error recovery action, if needed
2951 zfcp_erp_action_enqueue(int action,
2952 struct zfcp_adapter *adapter,
2953 struct zfcp_port *port, struct zfcp_unit *unit)
2956 struct zfcp_erp_action *erp_action = NULL;
2957 int stronger_action = 0;
2961 * We need some rules here which check whether we really need
2962 * this action or whether we should just drop it.
2963 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2964 * 'Reopen Unit' request for an associated unit since we can't
2965 * satisfy this request now. A 'Reopen Port' action will trigger
2966 * 'Reopen Unit' actions when it completes.
2967 * Thus, there are only actions in the queue which can immediately be
2968 * executed. This makes the processing of the action queue more
2972 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2976 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2977 /* check whether we really need this */
2979 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2980 if (atomic_test_mask
2981 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2982 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2983 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2985 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2986 sizeof (fcp_lun_t));
2989 if (!atomic_test_mask
2990 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2992 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2995 if (!atomic_test_mask
2996 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2997 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3000 /* fall through !!! */
3002 case ZFCP_ERP_ACTION_REOPEN_PORT:
3003 if (atomic_test_mask
3004 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3005 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3006 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3010 /* fall through !!! */
3012 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3013 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3015 if (port->erp_action.action !=
3016 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3017 ZFCP_LOG_INFO("dropped erp action %i (port "
3018 "0x%016Lx, action in use: %i)\n",
3020 port->erp_action.action);
3021 debug_text_event(adapter->erp_dbf, 4,
3024 debug_text_event(adapter->erp_dbf, 4,
3026 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3030 if (!atomic_test_mask
3031 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3033 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3036 if (!atomic_test_mask
3037 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3038 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3041 /* fall through !!! */
3043 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3044 if (atomic_test_mask
3045 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3046 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3052 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3053 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3054 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3055 "on adapter %s (action=%d)\n",
3056 zfcp_get_busid_by_adapter(adapter), action);
3060 /* check whether we need something stronger first */
3061 if (stronger_action) {
3062 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3063 debug_event(adapter->erp_dbf, 4, &stronger_action,
3065 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3066 "erp action %d on adapter %s\n",
3067 stronger_action, action,
3068 zfcp_get_busid_by_adapter(adapter));
3069 action = stronger_action;
3072 /* mark adapter to have some error recovery pending */
3073 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3075 /* setup error recovery action */
3078 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3079 zfcp_unit_get(unit);
3080 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3081 erp_action = &unit->erp_action;
3082 if (!atomic_test_mask
3083 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3084 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3087 case ZFCP_ERP_ACTION_REOPEN_PORT:
3088 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3089 zfcp_port_get(port);
3090 zfcp_erp_action_dismiss_port(port);
3091 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3092 erp_action = &port->erp_action;
3093 if (!atomic_test_mask
3094 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3095 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3098 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3099 zfcp_adapter_get(adapter);
3100 zfcp_erp_action_dismiss_adapter(adapter);
3101 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3102 erp_action = &adapter->erp_action;
3103 if (!atomic_test_mask
3104 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3105 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3109 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3111 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3112 erp_action->adapter = adapter;
3113 erp_action->port = port;
3114 erp_action->unit = unit;
3115 erp_action->action = action;
3116 erp_action->status = status;
3118 ++adapter->erp_total_count;
3120 /* finally put it into 'ready' queue and kick erp thread */
3121 list_add(&erp_action->list, &adapter->erp_ready_head);
3122 up(&adapter->erp_ready_sem);
3129 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3132 struct zfcp_adapter *adapter = erp_action->adapter;
3134 --adapter->erp_total_count;
3135 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3136 --adapter->erp_low_mem_count;
3137 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3140 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3141 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3142 list_del(&erp_action->list);
3143 switch (erp_action->action) {
3144 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3145 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3146 &erp_action->unit->status);
3148 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3149 case ZFCP_ERP_ACTION_REOPEN_PORT:
3150 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3151 &erp_action->port->status);
3153 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3154 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3155 &erp_action->adapter->status);
3165 * zfcp_erp_action_cleanup
3167 * Register unit with scsi stack if appropriate and fix reference counts.
3168 * Note: Temporary units are not registered with scsi stack.
3171 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3172 struct zfcp_port *port, struct zfcp_unit *unit,
3176 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3177 if ((result == ZFCP_ERP_SUCCEEDED)
3178 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3182 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3184 scsi_scan_target(&port->rport->dev, 0,
3185 port->rport->scsi_target_id,
3188 zfcp_unit_put(unit);
3190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3191 case ZFCP_ERP_ACTION_REOPEN_PORT:
3192 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3194 zfcp_port_put(port);
3198 if ((result == ZFCP_ERP_SUCCEEDED)
3200 struct fc_rport_identifiers ids;
3201 ids.node_name = port->wwnn;
3202 ids.port_name = port->wwpn;
3203 ids.port_id = port->d_id;
3204 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3206 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3208 ZFCP_LOG_NORMAL("failed registration of rport"
3209 "(adapter %s, wwpn=0x%016Lx)\n",
3210 zfcp_get_busid_by_port(port),
3213 scsi_flush_work(adapter->scsi_host);
3214 port->rport->maxframe_size = port->maxframe_size;
3215 port->rport->supported_classes =
3216 port->supported_classes;
3219 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3220 fc_remote_port_delete(port->rport);
3223 zfcp_port_put(port);
3225 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3226 if (result != ZFCP_ERP_SUCCEEDED) {
3227 struct zfcp_port *port;
3228 list_for_each_entry(port, &adapter->port_list_head, list)
3230 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3232 fc_remote_port_delete(port->rport);
3236 zfcp_adapter_put(adapter);
3244 void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3246 struct zfcp_port *port;
3248 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3249 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3250 zfcp_erp_action_dismiss(&adapter->erp_action);
3252 list_for_each_entry(port, &adapter->port_list_head, list)
3253 zfcp_erp_action_dismiss_port(port);
3256 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3258 struct zfcp_unit *unit;
3259 struct zfcp_adapter *adapter = port->adapter;
3261 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3262 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3263 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3264 zfcp_erp_action_dismiss(&port->erp_action);
3266 list_for_each_entry(unit, &port->unit_list_head, list)
3267 zfcp_erp_action_dismiss_unit(unit);
3270 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3272 struct zfcp_adapter *adapter = unit->port->adapter;
3274 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3275 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3276 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3277 zfcp_erp_action_dismiss(&unit->erp_action);
3281 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3283 struct zfcp_adapter *adapter = erp_action->adapter;
3285 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3286 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3287 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3291 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3293 struct zfcp_adapter *adapter = erp_action->adapter;
3295 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3296 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3297 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3301 zfcp_erp_port_boxed(struct zfcp_port *port)
3303 struct zfcp_adapter *adapter = port->adapter;
3304 unsigned long flags;
3306 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3307 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3308 read_lock_irqsave(&zfcp_data.config_lock, flags);
3309 zfcp_erp_modify_port_status(port,
3310 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3312 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3313 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3317 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3319 struct zfcp_adapter *adapter = unit->port->adapter;
3321 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3322 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3323 zfcp_erp_modify_unit_status(unit,
3324 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3326 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3330 zfcp_erp_port_access_denied(struct zfcp_port *port)
3332 struct zfcp_adapter *adapter = port->adapter;
3333 unsigned long flags;
3335 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3336 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3337 read_lock_irqsave(&zfcp_data.config_lock, flags);
3338 zfcp_erp_modify_port_status(port,
3339 ZFCP_STATUS_COMMON_ERP_FAILED |
3340 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3342 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3346 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3348 struct zfcp_adapter *adapter = unit->port->adapter;
3350 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3351 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3352 zfcp_erp_modify_unit_status(unit,
3353 ZFCP_STATUS_COMMON_ERP_FAILED |
3354 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3359 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3361 struct zfcp_port *port;
3362 unsigned long flags;
3364 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3367 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3368 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3370 read_lock_irqsave(&zfcp_data.config_lock, flags);
3371 if (adapter->nameserver_port)
3372 zfcp_erp_port_access_changed(adapter->nameserver_port);
3373 list_for_each_entry(port, &adapter->port_list_head, list)
3374 if (port != adapter->nameserver_port)
3375 zfcp_erp_port_access_changed(port);
3376 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3380 zfcp_erp_port_access_changed(struct zfcp_port *port)
3382 struct zfcp_adapter *adapter = port->adapter;
3383 struct zfcp_unit *unit;
3385 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3386 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3388 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3390 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3392 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3393 list_for_each_entry(unit, &port->unit_list_head, list)
3394 zfcp_erp_unit_access_changed(unit);
3398 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3399 "(due to ACT update)\n",
3400 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3401 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3402 ZFCP_LOG_NORMAL("failed reopen of port"
3403 "(adapter %s, wwpn=0x%016Lx)\n",
3404 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3408 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3410 struct zfcp_adapter *adapter = unit->port->adapter;
3412 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3413 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3415 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3417 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3421 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3422 " on adapter %s (due to ACT update)\n",
3423 unit->fcp_lun, unit->port->wwpn,
3424 zfcp_get_busid_by_adapter(adapter));
3425 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3426 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3427 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3428 zfcp_get_busid_by_adapter(adapter),
3429 unit->port->wwpn, unit->fcp_lun);
3432 #undef ZFCP_LOG_AREA