[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / s390 / scsi / zfcp_erp.c
blob53ebc1cdfe2de995e4ea39bc75076549cab847e8
1 /*
2 *
3 * linux/drivers/s390/scsi/zfcp_erp.c
4 *
5 * FCP adapter driver for IBM eServer zSeries
6 *
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
11 * Aron Zeh
12 * Wolfgang Taphorn
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
34 #define ZFCP_ERP_REVISION "$Revision: 1.86 $"
36 #include "zfcp_ext.h"
38 static int zfcp_erp_adisc(struct zfcp_adapter *, fc_id_t);
39 static void zfcp_erp_adisc_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
67 struct zfcp_port *,
68 struct zfcp_unit *, int);
69 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
71 struct zfcp_port *,
72 struct zfcp_unit *, int);
73 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
76 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
117 int);
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
130 * zfcp_fsf_request_timeout_handler - called if a request timed out
131 * @data: pointer to adapter for handler function
133 * This function needs to be called if requests (ELS, Generic Service,
134 * or SCSI commands) exceed a certain time limit. The assumption is
135 * that after the time limit the adapter get stuck. So we trigger a reopen of
136 * the adapter. This should not be used for error recovery, SCSI abort
137 * commands and SCSI requests from SCSI mid-layer.
139 void
140 zfcp_fsf_request_timeout_handler(unsigned long data)
142 struct zfcp_adapter *adapter;
144 adapter = (struct zfcp_adapter *) data;
146 zfcp_erp_adapter_reopen(adapter, 0);
150 * function: zfcp_fsf_scsi_er_timeout_handler
152 * purpose: This function needs to be called whenever a SCSI error recovery
153 * action (abort/reset) does not return.
154 * Re-opening the adapter means that the command can be returned
155 * by zfcp (it is guarranteed that it does not return via the
156 * adapter anymore). The buffer can then be used again.
158 * returns: sod all
160 void
161 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
163 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
165 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
166 "Restarting all operations on the adapter %s\n",
167 zfcp_get_busid_by_adapter(adapter));
168 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
169 zfcp_erp_adapter_reopen(adapter, 0);
171 return;
175 * function:
177 * purpose: called if an adapter failed,
178 * initiates adapter recovery which is done
179 * asynchronously
181 * returns: 0 - initiated action succesfully
182 * <0 - failed to initiate action
185 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
187 int retval;
189 debug_text_event(adapter->erp_dbf, 5, "a_ro");
190 ZFCP_LOG_DEBUG("reopen adapter %s\n",
191 zfcp_get_busid_by_adapter(adapter));
193 zfcp_erp_adapter_block(adapter, clear_mask);
195 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
196 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
197 zfcp_get_busid_by_adapter(adapter));
198 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
199 /* ensure propagation of failed status to new devices */
200 zfcp_erp_adapter_failed(adapter);
201 retval = -EIO;
202 goto out;
204 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
205 adapter, NULL, NULL);
207 out:
208 return retval;
212 * function:
214 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
215 * used to ensure the correct locking
217 * returns: 0 - initiated action succesfully
218 * <0 - failed to initiate action
221 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
223 int retval;
224 unsigned long flags;
226 read_lock_irqsave(&zfcp_data.config_lock, flags);
227 write_lock(&adapter->erp_lock);
228 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
229 write_unlock(&adapter->erp_lock);
230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
232 return retval;
236 * function:
238 * purpose:
240 * returns:
243 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
245 int retval;
247 retval = zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_RUNNING |
249 ZFCP_STATUS_COMMON_ERP_FAILED |
250 clear_mask);
252 return retval;
256 * function:
258 * purpose:
260 * returns:
263 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
265 int retval;
267 retval = zfcp_erp_port_reopen(port,
268 ZFCP_STATUS_COMMON_RUNNING |
269 ZFCP_STATUS_COMMON_ERP_FAILED |
270 clear_mask);
272 return retval;
276 * function:
278 * purpose:
280 * returns:
283 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
285 int retval;
287 retval = zfcp_erp_unit_reopen(unit,
288 ZFCP_STATUS_COMMON_RUNNING |
289 ZFCP_STATUS_COMMON_ERP_FAILED |
290 clear_mask);
292 return retval;
297 * zfcp_erp_adisc - send ADISC ELS command
298 * @adapter: adapter structure
299 * @d_id: d_id of port where ADISC is sent to
302 zfcp_erp_adisc(struct zfcp_adapter *adapter, fc_id_t d_id)
304 struct zfcp_send_els *send_els;
305 struct zfcp_ls_adisc *adisc;
306 void *address = NULL;
307 int retval = 0;
308 struct timer_list *timer;
310 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
311 if (send_els == NULL)
312 goto nomem;
313 memset(send_els, 0, sizeof(*send_els));
315 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->req == NULL)
317 goto nomem;
318 memset(send_els->req, 0, sizeof(*send_els->req));
320 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
321 if (send_els->resp == NULL)
322 goto nomem;
323 memset(send_els->resp, 0, sizeof(*send_els->resp));
325 address = (void *) get_zeroed_page(GFP_ATOMIC);
326 if (address == NULL)
327 goto nomem;
329 zfcp_address_to_sg(address, send_els->req);
330 address += PAGE_SIZE >> 1;
331 zfcp_address_to_sg(address, send_els->resp);
332 send_els->req_count = send_els->resp_count = 1;
334 send_els->adapter = adapter;
335 send_els->d_id = d_id;
336 send_els->handler = zfcp_erp_adisc_handler;
337 send_els->handler_data = (unsigned long) send_els;
339 adisc = zfcp_sg_to_address(send_els->req);
340 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
342 send_els->req->length = sizeof(struct zfcp_ls_adisc);
343 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
345 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
346 without FC-AL-2 capability, so we don't set it */
347 adisc->wwpn = adapter->wwpn;
348 adisc->wwnn = adapter->wwnn;
349 adisc->nport_id = adapter->s_id;
350 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
351 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
352 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
353 adapter->s_id, d_id, (wwn_t) adisc->wwpn,
354 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
355 adisc->nport_id);
357 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
358 if (!timer)
359 goto nomem;
361 init_timer(timer);
362 timer->function = zfcp_fsf_request_timeout_handler;
363 timer->data = (unsigned long) adapter;
364 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
365 send_els->timer = timer;
367 retval = zfcp_fsf_send_els(send_els);
368 if (retval != 0) {
369 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
370 "0x%08x on adapter %s\n", d_id,
371 zfcp_get_busid_by_adapter(adapter));
372 del_timer(send_els->timer);
373 goto freemem;
376 goto out;
378 nomem:
379 retval = -ENOMEM;
380 freemem:
381 if (address != NULL)
382 __free_pages(send_els->req->page, 0);
383 if (send_els != NULL) {
384 kfree(send_els->timer);
385 kfree(send_els->req);
386 kfree(send_els->resp);
387 kfree(send_els);
389 out:
390 return retval;
395 * zfcp_erp_adisc_handler - handler for ADISC ELS command
396 * @data: pointer to struct zfcp_send_els
398 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
400 void
401 zfcp_erp_adisc_handler(unsigned long data)
403 struct zfcp_send_els *send_els;
404 struct zfcp_port *port;
405 struct zfcp_adapter *adapter;
406 fc_id_t d_id;
407 struct zfcp_ls_adisc_acc *adisc;
409 send_els = (struct zfcp_send_els *) data;
411 del_timer(send_els->timer);
413 adapter = send_els->adapter;
414 d_id = send_els->d_id;
416 read_lock(&zfcp_data.config_lock);
417 port = zfcp_get_port_by_did(send_els->adapter, send_els->d_id);
418 read_unlock(&zfcp_data.config_lock);
420 BUG_ON(port == NULL);
422 /* request rejected or timed out */
423 if (send_els->status != 0) {
424 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
425 "force physical port reopen "
426 "(adapter %s, port d_id=0x%08x)\n",
427 zfcp_get_busid_by_adapter(adapter), d_id);
428 debug_text_event(adapter->erp_dbf, 3, "forcreop");
429 if (zfcp_erp_port_forced_reopen(port, 0))
430 ZFCP_LOG_NORMAL("failed reopen of port "
431 "(adapter %s, wwpn=0x%016Lx)\n",
432 zfcp_get_busid_by_port(port),
433 port->wwpn);
434 goto out;
437 adisc = zfcp_sg_to_address(send_els->resp);
439 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
440 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
441 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
442 d_id, adapter->s_id, (wwn_t) adisc->wwpn,
443 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
444 adisc->nport_id);
446 /* set wwnn for port */
447 if (port->wwnn == 0)
448 port->wwnn = adisc->wwnn;
450 if (port->wwpn != adisc->wwpn) {
451 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
452 "port (adapter %s, wwpn=0x%016Lx, "
453 "adisc_resp_wwpn=0x%016Lx)\n",
454 zfcp_get_busid_by_port(port),
455 port->wwpn, (wwn_t) adisc->wwpn);
456 if (zfcp_erp_port_reopen(port, 0))
457 ZFCP_LOG_NORMAL("failed reopen of port "
458 "(adapter %s, wwpn=0x%016Lx)\n",
459 zfcp_get_busid_by_port(port),
460 port->wwpn);
463 out:
464 zfcp_port_put(port);
465 __free_pages(send_els->req->page, 0);
466 kfree(send_els->timer);
467 kfree(send_els->req);
468 kfree(send_els->resp);
469 kfree(send_els);
474 * zfcp_test_link - lightweight link test procedure
475 * @port: port to be tested
477 * Test status of a link to a remote port using the ELS command ADISC.
480 zfcp_test_link(struct zfcp_port *port)
482 int retval;
484 zfcp_port_get(port);
485 retval = zfcp_erp_adisc(port->adapter, port->d_id);
486 if (retval != 0) {
487 zfcp_port_put(port);
488 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
489 "on adapter %s\n ", port->wwpn,
490 zfcp_get_busid_by_port(port));
491 retval = zfcp_erp_port_forced_reopen(port, 0);
492 if (retval != 0) {
493 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
494 "on adapter %s failed\n", port->wwpn,
495 zfcp_get_busid_by_port(port));
496 retval = -EPERM;
500 return retval;
505 * function:
507 * purpose: called if a port failed to be opened normally
508 * initiates Forced Reopen recovery which is done
509 * asynchronously
511 * returns: 0 - initiated action succesfully
512 * <0 - failed to initiate action
514 static int
515 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
517 int retval;
518 struct zfcp_adapter *adapter = port->adapter;
520 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
521 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
523 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
524 port->wwpn, zfcp_get_busid_by_port(port));
526 zfcp_erp_port_block(port, clear_mask);
528 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
529 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
530 "on adapter %s\n", port->wwpn,
531 zfcp_get_busid_by_port(port));
532 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
533 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
534 retval = -EIO;
535 goto out;
538 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
539 port->adapter, port, NULL);
541 out:
542 return retval;
546 * function:
548 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
549 * used to ensure the correct locking
551 * returns: 0 - initiated action succesfully
552 * <0 - failed to initiate action
555 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
557 int retval;
558 unsigned long flags;
559 struct zfcp_adapter *adapter;
561 adapter = port->adapter;
562 read_lock_irqsave(&zfcp_data.config_lock, flags);
563 write_lock(&adapter->erp_lock);
564 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
565 write_unlock(&adapter->erp_lock);
566 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
568 return retval;
572 * function:
574 * purpose: called if a port is to be opened
575 * initiates Reopen recovery which is done
576 * asynchronously
578 * returns: 0 - initiated action succesfully
579 * <0 - failed to initiate action
581 static int
582 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
584 int retval;
585 struct zfcp_adapter *adapter = port->adapter;
587 debug_text_event(adapter->erp_dbf, 5, "p_ro");
588 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
590 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
591 port->wwpn, zfcp_get_busid_by_port(port));
593 zfcp_erp_port_block(port, clear_mask);
595 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
596 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
597 "on adapter %s\n", port->wwpn,
598 zfcp_get_busid_by_port(port));
599 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
600 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
601 /* ensure propagation of failed status to new devices */
602 zfcp_erp_port_failed(port);
603 retval = -EIO;
604 goto out;
607 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
608 port->adapter, port, NULL);
610 out:
611 return retval;
615 * zfcp_erp_port_reopen - initiate reopen of a remote port
616 * @port: port to be reopened
617 * @clear_mask: specifies flags in port status to be cleared
618 * Return: 0 on success, < 0 on error
620 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
621 * correct locking. An error recovery task is initiated to do the reopen.
622 * To wait for the completion of the reopen zfcp_erp_wait should be used.
625 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
627 int retval;
628 unsigned long flags;
629 struct zfcp_adapter *adapter = port->adapter;
631 read_lock_irqsave(&zfcp_data.config_lock, flags);
632 write_lock(&adapter->erp_lock);
633 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
634 write_unlock(&adapter->erp_lock);
635 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
637 return retval;
641 * function:
643 * purpose: called if a unit is to be opened
644 * initiates Reopen recovery which is done
645 * asynchronously
647 * returns: 0 - initiated action succesfully
648 * <0 - failed to initiate action
650 static int
651 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
653 int retval;
654 struct zfcp_adapter *adapter = unit->port->adapter;
656 debug_text_event(adapter->erp_dbf, 5, "u_ro");
657 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
658 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
659 "on adapter %s\n", unit->fcp_lun,
660 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
662 zfcp_erp_unit_block(unit, clear_mask);
664 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
665 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
666 "on port 0x%016Lx on adapter %s\n",
667 unit->fcp_lun, unit->port->wwpn,
668 zfcp_get_busid_by_unit(unit));
669 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
670 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
671 sizeof (fcp_lun_t));
672 retval = -EIO;
673 goto out;
676 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
677 unit->port->adapter, unit->port, unit);
678 out:
679 return retval;
683 * zfcp_erp_unit_reopen - initiate reopen of a unit
684 * @unit: unit to be reopened
685 * @clear_mask: specifies flags in unit status to be cleared
686 * Return: 0 on success, < 0 on error
688 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
689 * locking. An error recovery task is initiated to do the reopen.
690 * To wait for the completion of the reopen zfcp_erp_wait should be used.
693 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
695 int retval;
696 unsigned long flags;
697 struct zfcp_adapter *adapter;
698 struct zfcp_port *port;
700 port = unit->port;
701 adapter = port->adapter;
703 read_lock_irqsave(&zfcp_data.config_lock, flags);
704 write_lock(&adapter->erp_lock);
705 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
706 write_unlock(&adapter->erp_lock);
707 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
709 return retval;
713 * function:
715 * purpose: disable I/O,
716 * return any open requests and clean them up,
717 * aim: no pending and incoming I/O
719 * returns:
721 static void
722 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
724 debug_text_event(adapter->erp_dbf, 6, "a_bl");
725 zfcp_erp_modify_adapter_status(adapter,
726 ZFCP_STATUS_COMMON_UNBLOCKED |
727 clear_mask, ZFCP_CLEAR);
731 * function:
733 * purpose: enable I/O
735 * returns:
737 static void
738 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
740 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
741 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
745 * function:
747 * purpose: disable I/O,
748 * return any open requests and clean them up,
749 * aim: no pending and incoming I/O
751 * returns:
753 static void
754 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
756 struct zfcp_adapter *adapter = port->adapter;
758 debug_text_event(adapter->erp_dbf, 6, "p_bl");
759 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
760 zfcp_erp_modify_port_status(port,
761 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
762 ZFCP_CLEAR);
766 * function:
768 * purpose: enable I/O
770 * returns:
772 static void
773 zfcp_erp_port_unblock(struct zfcp_port *port)
775 struct zfcp_adapter *adapter = port->adapter;
777 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
778 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
779 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
783 * function:
785 * purpose: disable I/O,
786 * return any open requests and clean them up,
787 * aim: no pending and incoming I/O
789 * returns:
791 static void
792 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
794 struct zfcp_adapter *adapter = unit->port->adapter;
796 debug_text_event(adapter->erp_dbf, 6, "u_bl");
797 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
798 zfcp_erp_modify_unit_status(unit,
799 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
800 ZFCP_CLEAR);
804 * function:
806 * purpose: enable I/O
808 * returns:
810 static void
811 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
813 struct zfcp_adapter *adapter = unit->port->adapter;
815 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
816 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
817 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
821 * function:
823 * purpose:
825 * returns:
827 static void
828 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
830 struct zfcp_adapter *adapter = erp_action->adapter;
832 debug_text_event(adapter->erp_dbf, 4, "a_ar");
833 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
835 zfcp_erp_action_to_ready(erp_action);
836 up(&adapter->erp_ready_sem);
840 * function:
842 * purpose:
844 * returns: <0 erp_action not found in any list
845 * ZFCP_ERP_ACTION_READY erp_action is in ready list
846 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
848 * locks: erp_lock must be held
850 static int
851 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
853 int retval = -EINVAL;
854 struct list_head *entry;
855 struct zfcp_erp_action *entry_erp_action;
856 struct zfcp_adapter *adapter = erp_action->adapter;
858 /* search in running list */
859 list_for_each(entry, &adapter->erp_running_head) {
860 entry_erp_action =
861 list_entry(entry, struct zfcp_erp_action, list);
862 if (entry_erp_action == erp_action) {
863 retval = ZFCP_ERP_ACTION_RUNNING;
864 goto out;
867 /* search in ready list */
868 list_for_each(entry, &adapter->erp_ready_head) {
869 entry_erp_action =
870 list_entry(entry, struct zfcp_erp_action, list);
871 if (entry_erp_action == erp_action) {
872 retval = ZFCP_ERP_ACTION_READY;
873 goto out;
877 out:
878 return retval;
882 * purpose: checks current status of action (timed out, dismissed, ...)
883 * and does appropriate preparations (dismiss fsf request, ...)
885 * locks: called under erp_lock (disabled interrupts)
887 * returns: 0
889 static int
890 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
892 int retval = 0;
893 struct zfcp_fsf_req *fsf_req;
894 struct zfcp_adapter *adapter = erp_action->adapter;
896 if (erp_action->fsf_req) {
897 /* take lock to ensure that request is not being deleted meanwhile */
898 write_lock(&adapter->fsf_req_list_lock);
899 /* check whether fsf req does still exist */
900 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
901 if (fsf_req == erp_action->fsf_req)
902 break;
903 if (fsf_req == erp_action->fsf_req) {
904 /* fsf_req still exists */
905 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
906 debug_event(adapter->erp_dbf, 3, &fsf_req,
907 sizeof (unsigned long));
908 /* dismiss fsf_req of timed out or dismissed erp_action */
909 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
910 ZFCP_STATUS_ERP_TIMEDOUT)) {
911 debug_text_event(adapter->erp_dbf, 3,
912 "a_ca_disreq");
913 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
915 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
916 ZFCP_LOG_NORMAL("error: erp step timed out "
917 "(action=%d, fsf_req=%p)\n ",
918 erp_action->action,
919 erp_action->fsf_req);
922 * If fsf_req is neither dismissed nor completed
923 * then keep it running asynchronously and don't mess
924 * with the association of erp_action and fsf_req.
926 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
927 ZFCP_STATUS_FSFREQ_DISMISSED)) {
928 /* forget about association between fsf_req
929 and erp_action */
930 fsf_req->erp_action = NULL;
931 erp_action->fsf_req = NULL;
933 } else {
934 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
936 * even if this fsf_req has gone, forget about
937 * association between erp_action and fsf_req
939 erp_action->fsf_req = NULL;
941 write_unlock(&adapter->fsf_req_list_lock);
942 } else
943 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
945 return retval;
949 * purpose: generic handler for asynchronous events related to erp_action events
950 * (normal completion, time-out, dismissing, retry after
951 * low memory condition)
953 * note: deletion of timer is not required (e.g. in case of a time-out),
954 * but a second try does no harm,
955 * we leave it in here to allow for greater simplification
957 * returns: 0 - there was an action to handle
958 * !0 - otherwise
960 static int
961 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
962 unsigned long set_mask)
964 int retval;
965 struct zfcp_adapter *adapter = erp_action->adapter;
967 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
968 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
969 debug_event(adapter->erp_dbf, 2, &erp_action->action,
970 sizeof (int));
971 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
972 del_timer(&erp_action->timer);
973 erp_action->status |= set_mask;
974 zfcp_erp_action_ready(erp_action);
975 retval = 0;
976 } else {
977 /* action is ready or gone - nothing to do */
978 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
979 debug_event(adapter->erp_dbf, 3, &erp_action->action,
980 sizeof (int));
981 retval = 1;
984 return retval;
988 * purpose: generic handler for asynchronous events related to erp_action
989 * events (normal completion, time-out, dismissing, retry after
990 * low memory condition)
992 * note: deletion of timer is not required (e.g. in case of a time-out),
993 * but a second try does no harm,
994 * we leave it in here to allow for greater simplification
996 * returns: 0 - there was an action to handle
997 * !0 - otherwise
1000 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1001 unsigned long set_mask)
1003 struct zfcp_adapter *adapter = erp_action->adapter;
1004 unsigned long flags;
1005 int retval;
1007 write_lock_irqsave(&adapter->erp_lock, flags);
1008 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1009 write_unlock_irqrestore(&adapter->erp_lock, flags);
1011 return retval;
1015 * purpose: is called for erp_action which was slept waiting for
1016 * memory becoming avaliable,
1017 * will trigger that this action will be continued
1019 static void
1020 zfcp_erp_memwait_handler(unsigned long data)
1022 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1023 struct zfcp_adapter *adapter = erp_action->adapter;
1025 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1026 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1028 zfcp_erp_async_handler(erp_action, 0);
1032 * purpose: is called if an asynchronous erp step timed out,
1033 * action gets an appropriate flag and will be processed
1034 * accordingly
1036 static void
1037 zfcp_erp_timeout_handler(unsigned long data)
1039 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1040 struct zfcp_adapter *adapter = erp_action->adapter;
1042 debug_text_event(adapter->erp_dbf, 2, "a_th");
1043 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1045 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1049 * purpose: is called for an erp_action which needs to be ended
1050 * though not being done,
1051 * this is usually required if an higher is generated,
1052 * action gets an appropriate flag and will be processed
1053 * accordingly
1055 * locks: erp_lock held (thus we need to call another handler variant)
1057 static int
1058 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1060 struct zfcp_adapter *adapter = erp_action->adapter;
1062 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1063 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1065 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1067 return 0;
1071 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1073 int retval = 0;
1075 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1077 rwlock_init(&adapter->erp_lock);
1078 INIT_LIST_HEAD(&adapter->erp_ready_head);
1079 INIT_LIST_HEAD(&adapter->erp_running_head);
1080 sema_init(&adapter->erp_ready_sem, 0);
1082 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1083 if (retval < 0) {
1084 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1085 "adapter %s\n",
1086 zfcp_get_busid_by_adapter(adapter));
1087 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1088 } else {
1089 wait_event(adapter->erp_thread_wqh,
1090 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1091 &adapter->status));
1092 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1095 return (retval < 0);
1099 * function:
1101 * purpose:
1103 * returns:
1105 * context: process (i.e. proc-fs or rmmod/insmod)
1107 * note: The caller of this routine ensures that the specified
1108 * adapter has been shut down and that this operation
1109 * has been completed. Thus, there are no pending erp_actions
1110 * which would need to be handled here.
1113 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1115 int retval = 0;
1117 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1118 up(&adapter->erp_ready_sem);
1120 wait_event(adapter->erp_thread_wqh,
1121 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1122 &adapter->status));
1124 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1125 &adapter->status);
1127 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1129 return retval;
1133 * purpose: is run as a kernel thread,
1134 * goes through list of error recovery actions of associated adapter
1135 * and delegates single action to execution
1137 * returns: 0
1139 static int
1140 zfcp_erp_thread(void *data)
1142 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1143 struct list_head *next;
1144 struct zfcp_erp_action *erp_action;
1145 unsigned long flags;
1147 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1148 /* Block all signals */
1149 siginitsetinv(&current->blocked, 0);
1150 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1151 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1152 wake_up(&adapter->erp_thread_wqh);
1154 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1155 &adapter->status)) {
1157 write_lock_irqsave(&adapter->erp_lock, flags);
1158 next = adapter->erp_ready_head.prev;
1159 write_unlock_irqrestore(&adapter->erp_lock, flags);
1161 if (next != &adapter->erp_ready_head) {
1162 erp_action =
1163 list_entry(next, struct zfcp_erp_action, list);
1165 * process action (incl. [re]moving it
1166 * from 'ready' queue)
1168 zfcp_erp_strategy(erp_action);
1172 * sleep as long as there is nothing to do, i.e.
1173 * no action in 'ready' queue to be processed and
1174 * thread is not to be killed
1176 down_interruptible(&adapter->erp_ready_sem);
1177 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1180 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1181 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1182 wake_up(&adapter->erp_thread_wqh);
1184 return 0;
1188 * function:
1190 * purpose: drives single error recovery action and schedules higher and
1191 * subordinate actions, if necessary
1193 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1194 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1195 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1196 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1197 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1199 static int
1200 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1202 int retval = 0;
1203 struct zfcp_adapter *adapter = erp_action->adapter;
1204 struct zfcp_port *port = erp_action->port;
1205 struct zfcp_unit *unit = erp_action->unit;
1206 int action = erp_action->action;
1207 u32 status = erp_action->status;
1208 unsigned long flags;
1210 /* serialise dismissing, timing out, moving, enqueueing */
1211 read_lock_irqsave(&zfcp_data.config_lock, flags);
1212 write_lock(&adapter->erp_lock);
1214 /* dequeue dismissed action and leave, if required */
1215 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1216 if (retval == ZFCP_ERP_DISMISSED) {
1217 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1218 goto unlock;
1222 * move action to 'running' queue before processing it
1223 * (to avoid a race condition regarding moving the
1224 * action to the 'running' queue and back)
1226 zfcp_erp_action_to_running(erp_action);
1229 * try to process action as far as possible,
1230 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1231 * afterwards the lock is required again for the following reasons:
1232 * - dequeueing of finished action and enqueueing of
1233 * follow-up actions must be atomic so that any other
1234 * reopen-routine does not believe there is nothing to do
1235 * and that it is safe to enqueue something else,
1236 * - we want to force any control thread which is dismissing
1237 * actions to finish this before we decide about
1238 * necessary steps to be taken here further
1240 write_unlock(&adapter->erp_lock);
1241 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1242 retval = zfcp_erp_strategy_do_action(erp_action);
1243 read_lock_irqsave(&zfcp_data.config_lock, flags);
1244 write_lock(&adapter->erp_lock);
1247 * check for dismissed status again to avoid follow-up actions,
1248 * failing of targets and so on for dismissed actions
1250 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1252 switch (retval) {
1253 case ZFCP_ERP_DISMISSED:
1254 /* leave since this action has ridden to its ancestors */
1255 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1256 goto unlock;
1257 case ZFCP_ERP_NOMEM:
1258 /* no memory to continue immediately, let it sleep */
1259 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1260 ++adapter->erp_low_mem_count;
1261 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1263 /* This condition is true if there is no memory available
1264 for any erp_action on this adapter. This implies that there
1265 are no elements in the memory pool(s) left for erp_actions.
1266 This might happen if an erp_action that used a memory pool
1267 element was timed out.
1269 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1270 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1271 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1272 "restarting I/O on adapter %s "
1273 "to free mempool\n",
1274 zfcp_get_busid_by_adapter(adapter));
1275 zfcp_erp_adapter_reopen_internal(adapter, 0);
1276 } else {
1277 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1278 retval = zfcp_erp_strategy_memwait(erp_action);
1280 goto unlock;
1281 case ZFCP_ERP_CONTINUES:
1282 /* leave since this action runs asynchronously */
1283 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1284 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1285 --adapter->erp_low_mem_count;
1286 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1288 goto unlock;
1290 /* ok, finished action (whatever its result is) */
1292 /* check for unrecoverable targets */
1293 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1295 /* action must be dequeued (here to allow for further ones) */
1296 zfcp_erp_action_dequeue(erp_action);
1299 * put this target through the erp mill again if someone has
1300 * requested to change the status of a target being online
1301 * to offline or the other way around
1302 * (old retval is preserved if nothing has to be done here)
1304 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1305 port, unit, retval);
1308 * leave if target is in permanent error state or if
1309 * action is repeated in order to process state change
1311 if (retval == ZFCP_ERP_EXIT) {
1312 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1313 goto unlock;
1316 /* trigger follow up actions */
1317 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1319 unlock:
1320 write_unlock(&adapter->erp_lock);
1321 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1323 if (retval != ZFCP_ERP_CONTINUES)
1324 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1327 * a few tasks remain when the erp queues are empty
1328 * (don't do that if the last action evaluated was dismissed
1329 * since this clearly indicates that there is more to come) :
1330 * - close the name server port if it is open yet
1331 * (enqueues another [probably] final action)
1332 * - otherwise, wake up whoever wants to be woken when we are
1333 * done with erp
1335 if (retval != ZFCP_ERP_DISMISSED)
1336 zfcp_erp_strategy_check_queues(adapter);
1338 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1340 return retval;
1344 * function:
1346 * purpose:
1348 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1349 * retval - otherwise
1351 static int
1352 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1354 struct zfcp_adapter *adapter = erp_action->adapter;
1356 zfcp_erp_strategy_check_fsfreq(erp_action);
1358 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1359 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1360 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1361 zfcp_erp_action_dequeue(erp_action);
1362 retval = ZFCP_ERP_DISMISSED;
1363 } else
1364 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1366 return retval;
1370 * function:
1372 * purpose:
1374 * returns:
1376 static int
1377 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1379 int retval = ZFCP_ERP_FAILED;
1380 struct zfcp_adapter *adapter = erp_action->adapter;
1383 * try to execute/continue action as far as possible,
1384 * note: no lock in subsequent strategy routines
1385 * (this allows these routine to call schedule, e.g.
1386 * kmalloc with such flags or qdio_initialize & friends)
1387 * Note: in case of timeout, the seperate strategies will fail
1388 * anyhow. No need for a special action. Even worse, a nameserver
1389 * failure would not wake up waiting ports without the call.
1391 switch (erp_action->action) {
1393 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1394 retval = zfcp_erp_adapter_strategy(erp_action);
1395 break;
1397 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1398 retval = zfcp_erp_port_forced_strategy(erp_action);
1399 break;
1401 case ZFCP_ERP_ACTION_REOPEN_PORT:
1402 retval = zfcp_erp_port_strategy(erp_action);
1403 break;
1405 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1406 retval = zfcp_erp_unit_strategy(erp_action);
1407 break;
1409 default:
1410 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1411 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1412 sizeof (int));
1413 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1414 "adapter %s (action=%d)\n",
1415 zfcp_get_busid_by_adapter(erp_action->adapter),
1416 erp_action->action);
1419 return retval;
1423 * function:
1425 * purpose: triggers retry of this action after a certain amount of time
1426 * by means of timer provided by erp_action
1428 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1430 static int
1431 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1433 int retval = ZFCP_ERP_CONTINUES;
1434 struct zfcp_adapter *adapter = erp_action->adapter;
1436 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1437 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1438 init_timer(&erp_action->timer);
1439 erp_action->timer.function = zfcp_erp_memwait_handler;
1440 erp_action->timer.data = (unsigned long) erp_action;
1441 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1442 add_timer(&erp_action->timer);
1444 return retval;
1448 * function: zfcp_erp_adapter_failed
1450 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1453 void
1454 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1456 zfcp_erp_modify_adapter_status(adapter,
1457 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1458 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1459 zfcp_get_busid_by_adapter(adapter));
1460 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1464 * function: zfcp_erp_port_failed
1466 * purpose: sets the port and all underlying devices to ERP_FAILED
1469 void
1470 zfcp_erp_port_failed(struct zfcp_port *port)
1472 zfcp_erp_modify_port_status(port,
1473 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1475 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1476 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1477 "port d_id=0x%08x)\n",
1478 zfcp_get_busid_by_port(port), port->d_id);
1479 else
1480 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1481 zfcp_get_busid_by_port(port), port->wwpn);
1483 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1484 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1488 * function: zfcp_erp_unit_failed
1490 * purpose: sets the unit to ERP_FAILED
1493 void
1494 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1496 zfcp_erp_modify_unit_status(unit,
1497 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1499 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1500 " on adapter %s\n", unit->fcp_lun,
1501 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1502 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1503 debug_event(unit->port->adapter->erp_dbf, 2,
1504 &unit->fcp_lun, sizeof (fcp_lun_t));
1508 * function: zfcp_erp_strategy_check_target
1510 * purpose: increments the erp action count on the device currently in
1511 * recovery if the action failed or resets the count in case of
1512 * success. If a maximum count is exceeded the device is marked
1513 * as ERP_FAILED.
1514 * The 'blocked' state of a target which has been recovered
1515 * successfully is reset.
1517 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1518 * ZFCP_ERP_SUCCEEDED - action finished successfully
1519 * ZFCP_ERP_EXIT - action failed and will not continue
1521 static int
1522 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1524 struct zfcp_adapter *adapter = erp_action->adapter;
1525 struct zfcp_port *port = erp_action->port;
1526 struct zfcp_unit *unit = erp_action->unit;
1528 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1529 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1530 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1532 switch (erp_action->action) {
1534 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1535 result = zfcp_erp_strategy_check_unit(unit, result);
1536 break;
1538 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1539 case ZFCP_ERP_ACTION_REOPEN_PORT:
1540 result = zfcp_erp_strategy_check_port(port, result);
1541 break;
1543 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1544 result = zfcp_erp_strategy_check_adapter(adapter, result);
1545 break;
1548 return result;
1552 * function:
1554 * purpose:
1556 * returns:
1558 static int
1559 zfcp_erp_strategy_statechange(int action,
1560 u32 status,
1561 struct zfcp_adapter *adapter,
1562 struct zfcp_port *port,
1563 struct zfcp_unit *unit, int retval)
1565 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1566 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1568 switch (action) {
1570 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1571 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1572 status)) {
1573 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1574 retval = ZFCP_ERP_EXIT;
1576 break;
1578 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1579 case ZFCP_ERP_ACTION_REOPEN_PORT:
1580 if (zfcp_erp_strategy_statechange_detected(&port->status,
1581 status)) {
1582 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1583 retval = ZFCP_ERP_EXIT;
1585 break;
1587 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1588 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1589 status)) {
1590 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1591 retval = ZFCP_ERP_EXIT;
1593 break;
1596 return retval;
1600 * function:
1602 * purpose:
1604 * returns:
1606 static inline int
1607 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1609 return
1610 /* take it online */
1611 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1612 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1613 /* take it offline */
1614 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1615 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1619 * function:
1621 * purpose:
1623 * returns:
1625 static int
1626 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1628 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1629 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1630 sizeof (fcp_lun_t));
1632 switch (result) {
1633 case ZFCP_ERP_SUCCEEDED :
1634 atomic_set(&unit->erp_counter, 0);
1635 zfcp_erp_unit_unblock(unit);
1636 break;
1637 case ZFCP_ERP_FAILED :
1638 atomic_inc(&unit->erp_counter);
1639 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1640 zfcp_erp_unit_failed(unit);
1641 break;
1642 case ZFCP_ERP_EXIT :
1643 /* nothing */
1644 break;
1647 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1648 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1649 result = ZFCP_ERP_EXIT;
1652 return result;
1656 * function:
1658 * purpose:
1660 * returns:
1662 static int
1663 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1665 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1666 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1668 switch (result) {
1669 case ZFCP_ERP_SUCCEEDED :
1670 atomic_set(&port->erp_counter, 0);
1671 zfcp_erp_port_unblock(port);
1672 break;
1673 case ZFCP_ERP_FAILED :
1674 atomic_inc(&port->erp_counter);
1675 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1676 zfcp_erp_port_failed(port);
1677 break;
1678 case ZFCP_ERP_EXIT :
1679 /* nothing */
1680 break;
1683 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1684 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1685 result = ZFCP_ERP_EXIT;
1688 return result;
1692 * function:
1694 * purpose:
1696 * returns:
1698 static int
1699 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1701 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1703 switch (result) {
1704 case ZFCP_ERP_SUCCEEDED :
1705 atomic_set(&adapter->erp_counter, 0);
1706 zfcp_erp_adapter_unblock(adapter);
1707 break;
1708 case ZFCP_ERP_FAILED :
1709 atomic_inc(&adapter->erp_counter);
1710 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1711 zfcp_erp_adapter_failed(adapter);
1712 break;
1713 case ZFCP_ERP_EXIT :
1714 /* nothing */
1715 break;
1718 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1719 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1720 result = ZFCP_ERP_EXIT;
1723 return result;
1727 * function:
1729 * purpose: remaining things in good cases,
1730 * escalation in bad cases
1732 * returns:
1734 static int
1735 zfcp_erp_strategy_followup_actions(int action,
1736 struct zfcp_adapter *adapter,
1737 struct zfcp_port *port,
1738 struct zfcp_unit *unit, int status)
1740 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1741 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1743 /* initiate follow-up actions depending on success of finished action */
1744 switch (action) {
1746 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1747 if (status == ZFCP_ERP_SUCCEEDED)
1748 zfcp_erp_port_reopen_all_internal(adapter, 0);
1749 else
1750 zfcp_erp_adapter_reopen_internal(adapter, 0);
1751 break;
1753 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1754 if (status == ZFCP_ERP_SUCCEEDED)
1755 zfcp_erp_port_reopen_internal(port, 0);
1756 else
1757 zfcp_erp_adapter_reopen_internal(adapter, 0);
1758 break;
1760 case ZFCP_ERP_ACTION_REOPEN_PORT:
1761 if (status == ZFCP_ERP_SUCCEEDED)
1762 zfcp_erp_unit_reopen_all_internal(port, 0);
1763 else
1764 zfcp_erp_port_forced_reopen_internal(port, 0);
1765 break;
1767 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1768 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1769 else
1770 zfcp_erp_port_reopen_internal(unit->port, 0);
1771 break;
1774 return 0;
1778 * function:
1780 * purpose:
1782 * returns:
1784 static int
1785 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1787 unsigned long flags;
1789 read_lock_irqsave(&zfcp_data.config_lock, flags);
1790 read_lock(&adapter->erp_lock);
1791 if (list_empty(&adapter->erp_ready_head) &&
1792 list_empty(&adapter->erp_running_head)) {
1793 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1794 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1795 &adapter->status);
1796 wake_up(&adapter->erp_done_wqh);
1797 } else
1798 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1799 read_unlock(&adapter->erp_lock);
1800 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1802 return 0;
1806 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1807 * @adapter: adapter for which to wait for completion of its error recovery
1808 * Return: 0
1811 zfcp_erp_wait(struct zfcp_adapter *adapter)
1813 int retval = 0;
1815 wait_event(adapter->erp_done_wqh,
1816 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1817 &adapter->status));
1819 return retval;
1823 * function: zfcp_erp_modify_adapter_status
1825 * purpose:
1828 void
1829 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1830 u32 mask, int set_or_clear)
1832 struct zfcp_port *port;
1833 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1835 if (set_or_clear == ZFCP_SET) {
1836 atomic_set_mask(mask, &adapter->status);
1837 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1838 } else {
1839 atomic_clear_mask(mask, &adapter->status);
1840 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1841 atomic_set(&adapter->erp_counter, 0);
1842 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1844 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1846 /* Deal with all underlying devices, only pass common_mask */
1847 if (common_mask)
1848 list_for_each_entry(port, &adapter->port_list_head, list)
1849 zfcp_erp_modify_port_status(port, common_mask,
1850 set_or_clear);
1854 * function: zfcp_erp_modify_port_status
1856 * purpose: sets the port and all underlying devices to ERP_FAILED
1859 void
1860 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1862 struct zfcp_unit *unit;
1863 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1865 if (set_or_clear == ZFCP_SET) {
1866 atomic_set_mask(mask, &port->status);
1867 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1868 } else {
1869 atomic_clear_mask(mask, &port->status);
1870 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1871 atomic_set(&port->erp_counter, 0);
1872 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1874 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1875 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1877 /* Modify status of all underlying devices, only pass common mask */
1878 if (common_mask)
1879 list_for_each_entry(unit, &port->unit_list_head, list)
1880 zfcp_erp_modify_unit_status(unit, common_mask,
1881 set_or_clear);
1885 * function: zfcp_erp_modify_unit_status
1887 * purpose: sets the unit to ERP_FAILED
1890 void
1891 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1893 if (set_or_clear == ZFCP_SET) {
1894 atomic_set_mask(mask, &unit->status);
1895 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1896 } else {
1897 atomic_clear_mask(mask, &unit->status);
1898 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1899 atomic_set(&unit->erp_counter, 0);
1901 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1903 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1904 sizeof (fcp_lun_t));
1905 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1909 * function:
1911 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1912 * used to ensure the correct locking
1914 * returns: 0 - initiated action succesfully
1915 * <0 - failed to initiate action
1918 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1920 int retval;
1921 unsigned long flags;
1923 read_lock_irqsave(&zfcp_data.config_lock, flags);
1924 write_lock(&adapter->erp_lock);
1925 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1926 write_unlock(&adapter->erp_lock);
1927 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1929 return retval;
1933 * function:
1935 * purpose:
1937 * returns: FIXME
1939 static int
1940 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1942 int retval = 0;
1943 struct zfcp_port *port;
1945 list_for_each_entry(port, &adapter->port_list_head, list)
1946 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1947 zfcp_erp_port_reopen_internal(port, clear_mask);
1949 return retval;
1953 * function:
1955 * purpose:
1957 * returns: FIXME
1959 static int
1960 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1962 int retval = 0;
1963 struct zfcp_unit *unit;
1965 list_for_each_entry(unit, &port->unit_list_head, list)
1966 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1968 return retval;
1972 * function:
1974 * purpose: this routine executes the 'Reopen Adapter' action
1975 * (the entire action is processed synchronously, since
1976 * there are no actions which might be run concurrently
1977 * per definition)
1979 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1980 * ZFCP_ERP_FAILED - action finished unsuccessfully
1982 static int
1983 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1985 int retval;
1986 struct zfcp_adapter *adapter = erp_action->adapter;
1988 retval = zfcp_erp_adapter_strategy_close(erp_action);
1989 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1990 retval = ZFCP_ERP_EXIT;
1991 else
1992 retval = zfcp_erp_adapter_strategy_open(erp_action);
1994 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1995 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1996 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1998 if (retval == ZFCP_ERP_FAILED) {
1999 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2000 "to recover itself\n",
2001 zfcp_get_busid_by_adapter(adapter));
2002 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2005 return retval;
2009 * function:
2011 * purpose:
2013 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2014 * ZFCP_ERP_FAILED - action finished unsuccessfully
2016 static int
2017 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2019 int retval;
2021 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2022 &erp_action->adapter->status);
2023 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2024 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2025 &erp_action->adapter->status);
2027 return retval;
2031 * function:
2033 * purpose:
2035 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2036 * ZFCP_ERP_FAILED - action finished unsuccessfully
2038 static int
2039 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2041 int retval;
2043 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2044 &erp_action->adapter->status);
2045 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2046 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2047 &erp_action->adapter->status);
2049 return retval;
2053 * function: zfcp_register_adapter
2055 * purpose: allocate the irq associated with this devno and register
2056 * the FSF adapter with the SCSI stack
2058 * returns:
2060 static int
2061 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2063 int retval = ZFCP_ERP_SUCCEEDED;
2065 if (close)
2066 goto close_only;
2068 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2069 if (retval != ZFCP_ERP_SUCCEEDED)
2070 goto failed_qdio;
2072 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2073 if (retval != ZFCP_ERP_SUCCEEDED)
2074 goto failed_openfcp;
2076 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2077 goto out;
2079 close_only:
2080 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2081 &erp_action->adapter->status);
2083 failed_openfcp:
2084 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2085 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2086 failed_qdio:
2087 out:
2088 return retval;
2092 * function: zfcp_qdio_init
2094 * purpose: setup QDIO operation for specified adapter
2096 * returns: 0 - successful setup
2097 * !0 - failed setup
2100 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2102 int retval;
2103 int i;
2104 volatile struct qdio_buffer_element *sbale;
2105 struct zfcp_adapter *adapter = erp_action->adapter;
2107 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2108 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2109 "adapter %s\n",
2110 zfcp_get_busid_by_adapter(adapter));
2111 goto failed_sanity;
2114 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2115 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2116 "on adapter %s\n",
2117 zfcp_get_busid_by_adapter(adapter));
2118 goto failed_qdio_establish;
2120 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2122 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2123 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2124 "on adapter %s\n",
2125 zfcp_get_busid_by_adapter(adapter));
2126 goto failed_qdio_activate;
2128 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2131 * put buffers into response queue,
2133 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2134 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2135 sbale->length = 0;
2136 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2137 sbale->addr = 0;
2140 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2141 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2142 zfcp_get_busid_by_adapter(adapter),
2143 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2145 retval = do_QDIO(adapter->ccw_device,
2146 QDIO_FLAG_SYNC_INPUT,
2147 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2149 if (retval) {
2150 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2151 retval);
2152 goto failed_do_qdio;
2153 } else {
2154 adapter->response_queue.free_index = 0;
2155 atomic_set(&adapter->response_queue.free_count, 0);
2156 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2157 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2159 /* set index of first avalable SBALS / number of available SBALS */
2160 adapter->request_queue.free_index = 0;
2161 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2162 adapter->request_queue.distance_from_int = 0;
2164 /* initialize waitqueue used to wait for free SBALs in requests queue */
2165 init_waitqueue_head(&adapter->request_wq);
2167 /* ok, we did it - skip all cleanups for different failures */
2168 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2169 retval = ZFCP_ERP_SUCCEEDED;
2170 goto out;
2172 failed_do_qdio:
2173 /* NOP */
2175 failed_qdio_activate:
2176 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2177 while (qdio_shutdown(adapter->ccw_device,
2178 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2179 msleep(1000);
2180 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2182 failed_qdio_establish:
2183 failed_sanity:
2184 retval = ZFCP_ERP_FAILED;
2186 out:
2187 return retval;
2191 * function: zfcp_qdio_cleanup
2193 * purpose: cleans up QDIO operation for the specified adapter
2195 * returns: 0 - successful cleanup
2196 * !0 - failed cleanup
2199 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2201 int retval = ZFCP_ERP_SUCCEEDED;
2202 int first_used;
2203 int used_count;
2204 struct zfcp_adapter *adapter = erp_action->adapter;
2206 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2207 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2208 "queues on adapter %s\n",
2209 zfcp_get_busid_by_adapter(adapter));
2210 retval = ZFCP_ERP_FAILED;
2211 goto out;
2215 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2216 * do_QDIO won't be called while qdio_shutdown is in progress.
2219 write_lock_irq(&adapter->request_queue.queue_lock);
2220 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2221 write_unlock_irq(&adapter->request_queue.queue_lock);
2223 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2224 while (qdio_shutdown(adapter->ccw_device,
2225 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2226 msleep(1000);
2227 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2230 * First we had to stop QDIO operation.
2231 * Now it is safe to take the following actions.
2234 /* Cleanup only necessary when there are unacknowledged buffers */
2235 if (atomic_read(&adapter->request_queue.free_count)
2236 < QDIO_MAX_BUFFERS_PER_Q) {
2237 first_used = (adapter->request_queue.free_index +
2238 atomic_read(&adapter->request_queue.free_count))
2239 % QDIO_MAX_BUFFERS_PER_Q;
2240 used_count = QDIO_MAX_BUFFERS_PER_Q -
2241 atomic_read(&adapter->request_queue.free_count);
2242 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2243 first_used, used_count);
2245 adapter->response_queue.free_index = 0;
2246 atomic_set(&adapter->response_queue.free_count, 0);
2247 adapter->request_queue.free_index = 0;
2248 atomic_set(&adapter->request_queue.free_count, 0);
2249 adapter->request_queue.distance_from_int = 0;
2250 out:
2251 return retval;
2255 * function: zfcp_fsf_init
2257 * purpose: initializes FSF operation for the specified adapter
2259 * returns: 0 - succesful initialization of FSF operation
2260 * !0 - failed to initialize FSF operation
2262 static int
2263 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2265 int retval;
2267 /* do 'exchange configuration data' */
2268 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2269 if (retval == ZFCP_ERP_FAILED)
2270 return retval;
2272 /* start the desired number of Status Reads */
2273 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2274 return retval;
2278 * function:
2280 * purpose:
2282 * returns:
2284 static int
2285 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2287 int retval = ZFCP_ERP_SUCCEEDED;
2288 int retries;
2289 struct zfcp_adapter *adapter = erp_action->adapter;
2291 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2292 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2294 do {
2295 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2296 &adapter->status);
2297 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2298 zfcp_erp_action_to_running(erp_action);
2299 zfcp_erp_timeout_init(erp_action);
2300 if (zfcp_fsf_exchange_config_data(erp_action)) {
2301 retval = ZFCP_ERP_FAILED;
2302 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2303 ZFCP_LOG_INFO("error: initiation of exchange of "
2304 "configuration data failed for "
2305 "adapter %s\n",
2306 zfcp_get_busid_by_adapter(adapter));
2307 break;
2309 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2310 ZFCP_LOG_DEBUG("Xchange underway\n");
2313 * Why this works:
2314 * Both the normal completion handler as well as the timeout
2315 * handler will do an 'up' when the 'exchange config data'
2316 * request completes or times out. Thus, the signal to go on
2317 * won't be lost utilizing this semaphore.
2318 * Furthermore, this 'adapter_reopen' action is
2319 * guaranteed to be the only action being there (highest action
2320 * which prevents other actions from being created).
2321 * Resulting from that, the wake signal recognized here
2322 * _must_ be the one belonging to the 'exchange config
2323 * data' request.
2325 down(&adapter->erp_ready_sem);
2326 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2327 ZFCP_LOG_INFO("error: exchange of configuration data "
2328 "for adapter %s timed out\n",
2329 zfcp_get_busid_by_adapter(adapter));
2330 break;
2332 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2333 &adapter->status)) {
2334 ZFCP_LOG_DEBUG("host connection still initialising... "
2335 "waiting and retrying...\n");
2336 /* sleep a little bit before retry */
2337 msleep(jiffies_to_msecs(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP));
2339 } while ((retries--) &&
2340 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2341 &adapter->status));
2343 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2344 &adapter->status)) {
2345 ZFCP_LOG_INFO("error: exchange of configuration data for "
2346 "adapter %s failed\n",
2347 zfcp_get_busid_by_adapter(adapter));
2348 retval = ZFCP_ERP_FAILED;
2351 return retval;
2355 * function:
2357 * purpose:
2359 * returns:
2361 static int
2362 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2363 *erp_action)
2365 int retval = ZFCP_ERP_SUCCEEDED;
2366 int temp_ret;
2367 struct zfcp_adapter *adapter = erp_action->adapter;
2368 int i;
2370 adapter->status_read_failed = 0;
2371 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2372 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2373 if (temp_ret < 0) {
2374 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2375 "notification failed on adapter %s\n",
2376 zfcp_get_busid_by_adapter(adapter));
2377 retval = ZFCP_ERP_FAILED;
2378 i--;
2379 break;
2383 return retval;
2387 * function: zfcp_fsf_cleanup
2389 * purpose: cleanup FSF operation for specified adapter
2391 * returns: 0 - FSF operation successfully cleaned up
2392 * !0 - failed to cleanup FSF operation for this adapter
2394 static int
2395 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2397 int retval = ZFCP_ERP_SUCCEEDED;
2398 struct zfcp_adapter *adapter = erp_action->adapter;
2401 * wake waiting initiators of requests,
2402 * return SCSI commands (with error status),
2403 * clean up all requests (synchronously)
2405 zfcp_fsf_req_dismiss_all(adapter);
2406 /* reset FSF request sequence number */
2407 adapter->fsf_req_seq_no = 0;
2408 /* all ports and units are closed */
2409 zfcp_erp_modify_adapter_status(adapter,
2410 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2412 return retval;
2416 * function:
2418 * purpose: this routine executes the 'Reopen Physical Port' action
2420 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2421 * ZFCP_ERP_SUCCEEDED - action finished successfully
2422 * ZFCP_ERP_FAILED - action finished unsuccessfully
2424 static int
2425 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2427 int retval = ZFCP_ERP_FAILED;
2428 struct zfcp_port *port = erp_action->port;
2429 struct zfcp_adapter *adapter = erp_action->adapter;
2431 switch (erp_action->step) {
2434 * FIXME:
2435 * the ULP spec. begs for waiting for oustanding commands
2437 case ZFCP_ERP_STEP_UNINITIALIZED:
2438 zfcp_erp_port_strategy_clearstati(port);
2440 * it would be sufficient to test only the normal open flag
2441 * since the phys. open flag cannot be set if the normal
2442 * open flag is unset - however, this is for readabilty ...
2444 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2445 ZFCP_STATUS_COMMON_OPEN),
2446 &port->status)) {
2447 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2448 "close physical\n", port->wwpn);
2449 retval =
2450 zfcp_erp_port_forced_strategy_close(erp_action);
2451 } else
2452 retval = ZFCP_ERP_FAILED;
2453 break;
2455 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2456 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2457 &port->status)) {
2458 ZFCP_LOG_DEBUG("close physical failed for port "
2459 "0x%016Lx\n", port->wwpn);
2460 retval = ZFCP_ERP_FAILED;
2461 } else
2462 retval = ZFCP_ERP_SUCCEEDED;
2463 break;
2466 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2467 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2468 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2469 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2471 return retval;
2475 * function:
2477 * purpose: this routine executes the 'Reopen Port' action
2479 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2480 * ZFCP_ERP_SUCCEEDED - action finished successfully
2481 * ZFCP_ERP_FAILED - action finished unsuccessfully
2483 static int
2484 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2486 int retval = ZFCP_ERP_FAILED;
2487 struct zfcp_port *port = erp_action->port;
2488 struct zfcp_adapter *adapter = erp_action->adapter;
2490 switch (erp_action->step) {
2493 * FIXME:
2494 * the ULP spec. begs for waiting for oustanding commands
2496 case ZFCP_ERP_STEP_UNINITIALIZED:
2497 zfcp_erp_port_strategy_clearstati(port);
2498 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2499 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2500 "close\n", port->wwpn);
2501 retval = zfcp_erp_port_strategy_close(erp_action);
2502 goto out;
2503 } /* else it's already closed, open it */
2504 break;
2506 case ZFCP_ERP_STEP_PORT_CLOSING:
2507 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2508 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2509 port->wwpn);
2510 retval = ZFCP_ERP_FAILED;
2511 goto out;
2512 } /* else it's closed now, open it */
2513 break;
2515 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2516 retval = ZFCP_ERP_EXIT;
2517 else
2518 retval = zfcp_erp_port_strategy_open(erp_action);
2520 out:
2521 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2522 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2523 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2524 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2526 return retval;
2530 * function:
2532 * purpose:
2534 * returns:
2536 static int
2537 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2539 int retval;
2541 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2542 &erp_action->port->status))
2543 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2544 else
2545 retval = zfcp_erp_port_strategy_open_common(erp_action);
2547 return retval;
2551 * function:
2553 * purpose:
2555 * returns:
2557 * FIXME(design): currently only prepared for fabric (nameserver!)
2559 static int
2560 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2562 int retval = 0;
2563 struct zfcp_adapter *adapter = erp_action->adapter;
2564 struct zfcp_port *port = erp_action->port;
2566 switch (erp_action->step) {
2568 case ZFCP_ERP_STEP_UNINITIALIZED:
2569 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2570 case ZFCP_ERP_STEP_PORT_CLOSING:
2571 if (adapter->fc_topology == FSF_TOPO_P2P) {
2572 if (port->wwpn != adapter->peer_wwpn) {
2573 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2574 "on adapter %s.\nPeer WWPN "
2575 "0x%016Lx does not match\n",
2576 port->wwpn,
2577 zfcp_get_busid_by_adapter(adapter),
2578 adapter->peer_wwpn);
2579 zfcp_erp_port_failed(port);
2580 retval = ZFCP_ERP_FAILED;
2581 break;
2583 port->d_id = adapter->peer_d_id;
2584 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2585 retval = zfcp_erp_port_strategy_open_port(erp_action);
2586 break;
2588 if (!(adapter->nameserver_port)) {
2589 retval = zfcp_nameserver_enqueue(adapter);
2590 if (retval != 0) {
2591 ZFCP_LOG_NORMAL("error: nameserver port "
2592 "unavailable for adapter %s\n",
2593 zfcp_get_busid_by_adapter(adapter));
2594 retval = ZFCP_ERP_FAILED;
2595 break;
2598 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2599 &adapter->nameserver_port->status)) {
2600 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2601 "nameserver port\n");
2602 /* nameserver port may live again */
2603 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2604 &adapter->nameserver_port->status);
2605 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2606 >= 0) {
2607 erp_action->step =
2608 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2609 retval = ZFCP_ERP_CONTINUES;
2610 } else
2611 retval = ZFCP_ERP_FAILED;
2612 break;
2614 /* else nameserver port is already open, fall through */
2615 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2616 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2617 &adapter->nameserver_port->status)) {
2618 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2619 retval = ZFCP_ERP_FAILED;
2620 } else {
2621 ZFCP_LOG_DEBUG("nameserver port is open -> "
2622 "nameserver look-up for port 0x%016Lx\n",
2623 port->wwpn);
2624 retval = zfcp_erp_port_strategy_open_common_lookup
2625 (erp_action);
2627 break;
2629 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2630 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2631 if (atomic_test_mask
2632 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2633 ZFCP_LOG_DEBUG("nameserver look-up failed "
2634 "for port 0x%016Lx "
2635 "(misconfigured WWPN?)\n",
2636 port->wwpn);
2637 zfcp_erp_port_failed(port);
2638 retval = ZFCP_ERP_EXIT;
2639 } else {
2640 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2641 "port 0x%016Lx\n", port->wwpn);
2642 retval = ZFCP_ERP_FAILED;
2644 } else {
2645 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2646 "trying open\n", port->wwpn, port->d_id);
2647 retval = zfcp_erp_port_strategy_open_port(erp_action);
2649 break;
2651 case ZFCP_ERP_STEP_PORT_OPENING:
2652 /* D_ID might have changed during open */
2653 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2654 ZFCP_STATUS_PORT_DID_DID),
2655 &port->status)) {
2656 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2657 retval = ZFCP_ERP_SUCCEEDED;
2658 } else {
2659 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2660 port->wwpn);
2661 retval = ZFCP_ERP_FAILED;
2663 break;
2665 default:
2666 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2667 erp_action->step);
2668 retval = ZFCP_ERP_FAILED;
2671 return retval;
2675 * function:
2677 * purpose:
2679 * returns:
2681 static int
2682 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2684 int retval;
2685 struct zfcp_port *port = erp_action->port;
2687 switch (erp_action->step) {
2689 case ZFCP_ERP_STEP_UNINITIALIZED:
2690 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2691 case ZFCP_ERP_STEP_PORT_CLOSING:
2692 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2693 port->wwpn, port->d_id);
2694 retval = zfcp_erp_port_strategy_open_port(erp_action);
2695 break;
2697 case ZFCP_ERP_STEP_PORT_OPENING:
2698 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2699 ZFCP_LOG_DEBUG("WKA port is open\n");
2700 retval = ZFCP_ERP_SUCCEEDED;
2701 } else {
2702 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2703 retval = ZFCP_ERP_FAILED;
2705 /* this is needed anyway (dont care for retval of wakeup) */
2706 ZFCP_LOG_DEBUG("continue other open port operations\n");
2707 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2708 break;
2710 default:
2711 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2712 erp_action->step);
2713 retval = ZFCP_ERP_FAILED;
2716 return retval;
2720 * function:
2722 * purpose: makes the erp thread continue with reopen (physical) port
2723 * actions which have been paused until the name server port
2724 * is opened (or failed)
2726 * returns: 0 (a kind of void retval, its not used)
2728 static int
2729 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2730 *ns_erp_action)
2732 int retval = 0;
2733 unsigned long flags;
2734 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2735 struct zfcp_erp_action *erp_action, *tmp;
2737 read_lock_irqsave(&adapter->erp_lock, flags);
2738 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2739 list) {
2740 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2741 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2742 sizeof (wwn_t));
2743 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2744 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2745 debug_event(adapter->erp_dbf, 3,
2746 &erp_action->port->wwpn, sizeof (wwn_t));
2747 if (atomic_test_mask(
2748 ZFCP_STATUS_COMMON_ERP_FAILED,
2749 &adapter->nameserver_port->status))
2750 zfcp_erp_port_failed(erp_action->port);
2751 zfcp_erp_action_ready(erp_action);
2754 read_unlock_irqrestore(&adapter->erp_lock, flags);
2756 return retval;
2760 * function:
2762 * purpose:
2764 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2765 * ZFCP_ERP_FAILED - action finished unsuccessfully
2767 static int
2768 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2770 int retval;
2771 struct zfcp_adapter *adapter = erp_action->adapter;
2772 struct zfcp_port *port = erp_action->port;
2774 zfcp_erp_timeout_init(erp_action);
2775 retval = zfcp_fsf_close_physical_port(erp_action);
2776 if (retval == -ENOMEM) {
2777 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2778 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2779 retval = ZFCP_ERP_NOMEM;
2780 goto out;
2782 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2783 if (retval != 0) {
2784 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2785 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2786 /* could not send 'open', fail */
2787 retval = ZFCP_ERP_FAILED;
2788 goto out;
2790 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2791 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2792 retval = ZFCP_ERP_CONTINUES;
2793 out:
2794 return retval;
2798 * function:
2800 * purpose:
2802 * returns:
2804 static int
2805 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2807 int retval = 0;
2808 struct zfcp_adapter *adapter = port->adapter;
2810 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2811 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2813 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2814 ZFCP_STATUS_COMMON_CLOSING |
2815 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2816 ZFCP_STATUS_PORT_DID_DID |
2817 ZFCP_STATUS_PORT_PHYS_CLOSING |
2818 ZFCP_STATUS_PORT_INVALID_WWPN,
2819 &port->status);
2820 return retval;
2824 * function:
2826 * purpose:
2828 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2829 * ZFCP_ERP_FAILED - action finished unsuccessfully
2831 static int
2832 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2834 int retval;
2835 struct zfcp_adapter *adapter = erp_action->adapter;
2836 struct zfcp_port *port = erp_action->port;
2838 zfcp_erp_timeout_init(erp_action);
2839 retval = zfcp_fsf_close_port(erp_action);
2840 if (retval == -ENOMEM) {
2841 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2842 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2843 retval = ZFCP_ERP_NOMEM;
2844 goto out;
2846 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2847 if (retval != 0) {
2848 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2849 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2850 /* could not send 'close', fail */
2851 retval = ZFCP_ERP_FAILED;
2852 goto out;
2854 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2855 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2856 retval = ZFCP_ERP_CONTINUES;
2857 out:
2858 return retval;
2862 * function:
2864 * purpose:
2866 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2867 * ZFCP_ERP_FAILED - action finished unsuccessfully
2869 static int
2870 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2872 int retval;
2873 struct zfcp_adapter *adapter = erp_action->adapter;
2874 struct zfcp_port *port = erp_action->port;
2876 zfcp_erp_timeout_init(erp_action);
2877 retval = zfcp_fsf_open_port(erp_action);
2878 if (retval == -ENOMEM) {
2879 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2880 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2881 retval = ZFCP_ERP_NOMEM;
2882 goto out;
2884 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2885 if (retval != 0) {
2886 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2887 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2888 /* could not send 'open', fail */
2889 retval = ZFCP_ERP_FAILED;
2890 goto out;
2892 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2893 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2894 retval = ZFCP_ERP_CONTINUES;
2895 out:
2896 return retval;
2900 * function:
2902 * purpose:
2904 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2905 * ZFCP_ERP_FAILED - action finished unsuccessfully
2907 static int
2908 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2910 int retval;
2911 struct zfcp_adapter *adapter = erp_action->adapter;
2912 struct zfcp_port *port = erp_action->port;
2914 zfcp_erp_timeout_init(erp_action);
2915 retval = zfcp_ns_gid_pn_request(erp_action);
2916 if (retval == -ENOMEM) {
2917 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2918 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2919 retval = ZFCP_ERP_NOMEM;
2920 goto out;
2922 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2923 if (retval != 0) {
2924 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2925 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2926 /* could not send nameserver request, fail */
2927 retval = ZFCP_ERP_FAILED;
2928 goto out;
2930 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2931 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2932 retval = ZFCP_ERP_CONTINUES;
2933 out:
2934 return retval;
2938 * function:
2940 * purpose: this routine executes the 'Reopen Unit' action
2941 * currently no retries
2943 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2944 * ZFCP_ERP_SUCCEEDED - action finished successfully
2945 * ZFCP_ERP_FAILED - action finished unsuccessfully
2947 static int
2948 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2950 int retval = ZFCP_ERP_FAILED;
2951 struct zfcp_unit *unit = erp_action->unit;
2952 struct zfcp_adapter *adapter = erp_action->adapter;
2954 switch (erp_action->step) {
2957 * FIXME:
2958 * the ULP spec. begs for waiting for oustanding commands
2960 case ZFCP_ERP_STEP_UNINITIALIZED:
2961 zfcp_erp_unit_strategy_clearstati(unit);
2962 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2963 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2964 "trying close\n", unit->fcp_lun);
2965 retval = zfcp_erp_unit_strategy_close(erp_action);
2966 break;
2968 /* else it's already closed, fall through */
2969 case ZFCP_ERP_STEP_UNIT_CLOSING:
2970 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2971 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2972 unit->fcp_lun);
2973 retval = ZFCP_ERP_FAILED;
2974 } else {
2975 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2976 retval = ZFCP_ERP_EXIT;
2977 else {
2978 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2979 "trying open\n", unit->fcp_lun);
2980 retval =
2981 zfcp_erp_unit_strategy_open(erp_action);
2984 break;
2986 case ZFCP_ERP_STEP_UNIT_OPENING:
2987 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2988 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2989 unit->fcp_lun);
2990 retval = ZFCP_ERP_SUCCEEDED;
2991 } else {
2992 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2993 unit->fcp_lun);
2994 retval = ZFCP_ERP_FAILED;
2996 break;
2999 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3000 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3001 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3002 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3003 return retval;
3007 * function:
3009 * purpose:
3011 * returns:
3013 static int
3014 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3016 int retval = 0;
3017 struct zfcp_adapter *adapter = unit->port->adapter;
3019 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3020 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3022 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3023 ZFCP_STATUS_COMMON_CLOSING |
3024 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3025 ZFCP_STATUS_UNIT_SHARED |
3026 ZFCP_STATUS_UNIT_READONLY,
3027 &unit->status);
3029 return retval;
3033 * function:
3035 * purpose:
3037 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3038 * ZFCP_ERP_FAILED - action finished unsuccessfully
3040 static int
3041 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3043 int retval;
3044 struct zfcp_adapter *adapter = erp_action->adapter;
3045 struct zfcp_unit *unit = erp_action->unit;
3047 zfcp_erp_timeout_init(erp_action);
3048 retval = zfcp_fsf_close_unit(erp_action);
3049 if (retval == -ENOMEM) {
3050 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3051 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3052 sizeof (fcp_lun_t));
3053 retval = ZFCP_ERP_NOMEM;
3054 goto out;
3056 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3057 if (retval != 0) {
3058 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3059 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3060 sizeof (fcp_lun_t));
3061 /* could not send 'close', fail */
3062 retval = ZFCP_ERP_FAILED;
3063 goto out;
3065 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3066 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3067 retval = ZFCP_ERP_CONTINUES;
3069 out:
3070 return retval;
3074 * function:
3076 * purpose:
3078 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3079 * ZFCP_ERP_FAILED - action finished unsuccessfully
3081 static int
3082 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3084 int retval;
3085 struct zfcp_adapter *adapter = erp_action->adapter;
3086 struct zfcp_unit *unit = erp_action->unit;
3088 zfcp_erp_timeout_init(erp_action);
3089 retval = zfcp_fsf_open_unit(erp_action);
3090 if (retval == -ENOMEM) {
3091 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3092 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3093 sizeof (fcp_lun_t));
3094 retval = ZFCP_ERP_NOMEM;
3095 goto out;
3097 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3098 if (retval != 0) {
3099 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3100 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3101 sizeof (fcp_lun_t));
3102 /* could not send 'open', fail */
3103 retval = ZFCP_ERP_FAILED;
3104 goto out;
3106 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3107 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3108 retval = ZFCP_ERP_CONTINUES;
3109 out:
3110 return retval;
3114 * function:
3116 * purpose:
3118 * returns:
3120 static inline void
3121 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3123 init_timer(&erp_action->timer);
3124 erp_action->timer.function = zfcp_erp_timeout_handler;
3125 erp_action->timer.data = (unsigned long) erp_action;
3126 /* jiffies will be added in zfcp_fsf_req_send */
3127 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3131 * function:
3133 * purpose: enqueue the specified error recovery action, if needed
3135 * returns:
3137 static int
3138 zfcp_erp_action_enqueue(int action,
3139 struct zfcp_adapter *adapter,
3140 struct zfcp_port *port, struct zfcp_unit *unit)
3142 int retval = 1;
3143 struct zfcp_erp_action *erp_action = NULL;
3144 int stronger_action = 0;
3145 u32 status = 0;
3148 * We need some rules here which check whether we really need
3149 * this action or whether we should just drop it.
3150 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3151 * 'Reopen Unit' request for an associated unit since we can't
3152 * satisfy this request now. A 'Reopen Port' action will trigger
3153 * 'Reopen Unit' actions when it completes.
3154 * Thus, there are only actions in the queue which can immediately be
3155 * executed. This makes the processing of the action queue more
3156 * efficient.
3159 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3160 &adapter->status))
3161 return -EIO;
3163 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3164 /* check whether we really need this */
3165 switch (action) {
3166 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3167 if (atomic_test_mask
3168 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3169 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3170 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3171 sizeof (wwn_t));
3172 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3173 sizeof (fcp_lun_t));
3174 goto out;
3176 if (!atomic_test_mask
3177 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3178 atomic_test_mask
3179 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3180 goto out;
3182 if (!atomic_test_mask
3183 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3184 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3185 unit = NULL;
3187 /* fall through !!! */
3189 case ZFCP_ERP_ACTION_REOPEN_PORT:
3190 if (atomic_test_mask
3191 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3192 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3193 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3194 sizeof (wwn_t));
3195 goto out;
3197 /* fall through !!! */
3199 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3200 if (atomic_test_mask
3201 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3202 && port->erp_action.action ==
3203 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3204 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3205 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3206 sizeof (wwn_t));
3207 goto out;
3209 if (!atomic_test_mask
3210 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3211 atomic_test_mask
3212 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3213 goto out;
3215 if (!atomic_test_mask
3216 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3217 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3218 port = NULL;
3220 /* fall through !!! */
3222 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3223 if (atomic_test_mask
3224 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3225 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3226 goto out;
3228 break;
3230 default:
3231 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3232 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3233 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3234 "on adapter %s (action=%d)\n",
3235 zfcp_get_busid_by_adapter(adapter), action);
3236 goto out;
3239 /* check whether we need something stronger first */
3240 if (stronger_action) {
3241 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3242 debug_event(adapter->erp_dbf, 4, &stronger_action,
3243 sizeof (int));
3244 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3245 "erp action %d on adapter %s\n",
3246 stronger_action, action,
3247 zfcp_get_busid_by_adapter(adapter));
3248 action = stronger_action;
3251 /* mark adapter to have some error recovery pending */
3252 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3254 /* setup error recovery action */
3255 switch (action) {
3257 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3258 zfcp_unit_get(unit);
3259 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3260 erp_action = &unit->erp_action;
3261 if (!atomic_test_mask
3262 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3263 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3264 break;
3266 case ZFCP_ERP_ACTION_REOPEN_PORT:
3267 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3268 zfcp_port_get(port);
3269 zfcp_erp_action_dismiss_port(port);
3270 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3271 erp_action = &port->erp_action;
3272 if (!atomic_test_mask
3273 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3274 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3275 break;
3277 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3278 zfcp_adapter_get(adapter);
3279 zfcp_erp_action_dismiss_adapter(adapter);
3280 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3281 erp_action = &adapter->erp_action;
3282 if (!atomic_test_mask
3283 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3284 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3285 break;
3288 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3290 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3291 erp_action->adapter = adapter;
3292 erp_action->port = port;
3293 erp_action->unit = unit;
3294 erp_action->action = action;
3295 erp_action->status = status;
3297 ++adapter->erp_total_count;
3299 /* finally put it into 'ready' queue and kick erp thread */
3300 list_add(&erp_action->list, &adapter->erp_ready_head);
3301 up(&adapter->erp_ready_sem);
3302 retval = 0;
3303 out:
3304 return retval;
3308 * function:
3310 * purpose:
3312 * returns:
3314 static int
3315 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3317 int retval = 0;
3318 struct zfcp_adapter *adapter = erp_action->adapter;
3320 --adapter->erp_total_count;
3321 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3322 --adapter->erp_low_mem_count;
3323 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3326 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3327 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3328 list_del(&erp_action->list);
3329 switch (erp_action->action) {
3330 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3331 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3332 &erp_action->unit->status);
3333 break;
3334 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3335 case ZFCP_ERP_ACTION_REOPEN_PORT:
3336 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3337 &erp_action->port->status);
3338 break;
3339 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3340 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3341 &erp_action->adapter->status);
3342 break;
3343 default:
3344 /* bug */
3345 break;
3347 return retval;
3351 * zfcp_erp_action_cleanup
3353 * Register unit with scsi stack if appropiate and fix reference counts.
3354 * Note: Temporary units are not registered with scsi stack.
3356 static void
3357 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3358 struct zfcp_port *port, struct zfcp_unit *unit,
3359 int result)
3361 switch (action) {
3362 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3363 if ((result == ZFCP_ERP_SUCCEEDED)
3364 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3365 &unit->status))
3366 && (!unit->device))
3367 scsi_add_device(unit->port->adapter->scsi_host, 0,
3368 unit->port->scsi_id, unit->scsi_lun);
3369 zfcp_unit_put(unit);
3370 break;
3371 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3372 case ZFCP_ERP_ACTION_REOPEN_PORT:
3373 zfcp_port_put(port);
3374 break;
3375 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3376 zfcp_adapter_put(adapter);
3377 break;
3378 default:
3379 break;
3385 * function:
3387 * purpose:
3389 * returns: FIXME
3391 static int
3392 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3394 int retval = 0;
3395 struct zfcp_port *port;
3397 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3398 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3399 zfcp_erp_action_dismiss(&adapter->erp_action);
3400 else
3401 list_for_each_entry(port, &adapter->port_list_head, list)
3402 zfcp_erp_action_dismiss_port(port);
3404 return retval;
3408 * function:
3410 * purpose:
3412 * returns: FIXME
3414 static int
3415 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3417 int retval = 0;
3418 struct zfcp_unit *unit;
3419 struct zfcp_adapter *adapter = port->adapter;
3421 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3422 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3423 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3424 zfcp_erp_action_dismiss(&port->erp_action);
3425 else
3426 list_for_each_entry(unit, &port->unit_list_head, list)
3427 zfcp_erp_action_dismiss_unit(unit);
3429 return retval;
3433 * function:
3435 * purpose:
3437 * returns: FIXME
3439 static int
3440 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3442 int retval = 0;
3443 struct zfcp_adapter *adapter = unit->port->adapter;
3445 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3446 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3447 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3448 zfcp_erp_action_dismiss(&unit->erp_action);
3450 return retval;
3454 * function:
3456 * purpose: moves erp_action to 'erp running list'
3458 * returns:
3460 static inline void
3461 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3463 struct zfcp_adapter *adapter = erp_action->adapter;
3465 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3466 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3467 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3471 * function:
3473 * purpose: moves erp_action to 'erp ready list'
3475 * returns:
3477 static inline void
3478 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3480 struct zfcp_adapter *adapter = erp_action->adapter;
3482 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3483 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3484 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3488 * function: zfcp_erp_port_access_denied
3490 * purpose:
3492 void
3493 zfcp_erp_port_access_denied(struct zfcp_port *port)
3495 struct zfcp_adapter *adapter = port->adapter;
3496 unsigned long flags;
3498 debug_text_event(adapter->erp_dbf, 3, "p_access_block");
3499 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3500 read_lock_irqsave(&zfcp_data.config_lock, flags);
3501 zfcp_erp_modify_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED |
3502 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3503 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3507 * function: zfcp_erp_unit_access_denied
3509 * purpose:
3511 void
3512 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3514 struct zfcp_adapter *adapter = unit->port->adapter;
3516 debug_text_event(adapter->erp_dbf, 3, "u_access_block");
3517 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3518 zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_ERP_FAILED |
3519 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3523 * function: zfcp_erp_adapter_access_changed
3525 * purpose:
3527 void
3528 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3530 struct zfcp_port *port;
3531 unsigned long flags;
3533 debug_text_event(adapter->erp_dbf, 3, "a_access_unblock");
3534 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3536 read_lock_irqsave(&zfcp_data.config_lock, flags);
3537 if (adapter->nameserver_port)
3538 zfcp_erp_port_access_changed(adapter->nameserver_port);
3539 list_for_each_entry(port, &adapter->port_list_head, list)
3540 if (port != adapter->nameserver_port)
3541 zfcp_erp_port_access_changed(port);
3542 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3546 * function: zfcp_erp_port_access_changed
3548 * purpose:
3550 void
3551 zfcp_erp_port_access_changed(struct zfcp_port *port)
3553 struct zfcp_adapter *adapter = port->adapter;
3554 struct zfcp_unit *unit;
3556 debug_text_event(adapter->erp_dbf, 3, "p_access_unblock");
3557 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3559 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3560 &port->status)) {
3561 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3562 list_for_each_entry(unit, &port->unit_list_head, list)
3563 zfcp_erp_unit_access_changed(unit);
3564 return;
3567 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3568 "(due to ACT update)\n",
3569 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3570 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3571 ZFCP_LOG_NORMAL("failed reopen of port"
3572 "(adapter %s, wwpn=0x%016Lx)\n",
3573 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3577 * function: zfcp_erp_unit_access_changed
3579 * purpose:
3581 void
3582 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3584 struct zfcp_adapter *adapter = unit->port->adapter;
3586 debug_text_event(adapter->erp_dbf, 3, "u_access_unblock");
3587 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3589 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status))
3590 return;
3592 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3593 " on adapter %s (due to ACT update)\n",
3594 unit->fcp_lun, unit->port->wwpn,
3595 zfcp_get_busid_by_adapter(adapter));
3596 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3597 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3598 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3599 zfcp_get_busid_by_adapter(adapter),
3600 unit->port->wwpn, unit->fcp_lun);
3603 #undef ZFCP_LOG_AREA