3 * linux/drivers/s390/scsi/zfcp_erp.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
33 /* this drivers version (do not edit !!! generated and updated by cvs) */
34 #define ZFCP_ERP_REVISION "$Revision: 1.56 $"
38 static int zfcp_els(struct zfcp_port *, u8);
39 static int zfcp_els_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
68 struct zfcp_unit *, int);
69 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
72 struct zfcp_unit *, int);
73 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
76 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
131 * function: zfcp_fsf_scsi_er_timeout_handler
133 * purpose: This function needs to be called whenever a SCSI error recovery
134 * action (abort/reset) does not return.
135 * Re-opening the adapter means that the command can be returned
136 * by zfcp (it is guarranteed that it does not return via the
137 * adapter anymore). The buffer can then be used again.
142 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
144 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
146 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
147 "Restarting all operations on the adapter %s\n",
148 zfcp_get_busid_by_adapter(adapter));
149 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
150 zfcp_erp_adapter_reopen(adapter, 0);
158 * purpose: called if an adapter failed,
159 * initiates adapter recovery which is done
162 * returns: 0 - initiated action succesfully
163 * <0 - failed to initiate action
166 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
170 debug_text_event(adapter->erp_dbf, 5, "a_ro");
171 ZFCP_LOG_DEBUG("reopen adapter %s\n",
172 zfcp_get_busid_by_adapter(adapter));
174 zfcp_erp_adapter_block(adapter, clear_mask);
176 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
177 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
178 zfcp_get_busid_by_adapter(adapter));
179 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
180 /* ensure propagation of failed status to new devices */
181 zfcp_erp_adapter_failed(adapter);
185 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
186 adapter, NULL, NULL);
195 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
196 * used to ensure the correct locking
198 * returns: 0 - initiated action succesfully
199 * <0 - failed to initiate action
202 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
207 read_lock_irqsave(&zfcp_data.config_lock, flags);
208 write_lock(&adapter->erp_lock);
209 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
210 write_unlock(&adapter->erp_lock);
211 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
224 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
228 retval = zfcp_erp_adapter_reopen(adapter,
229 ZFCP_STATUS_COMMON_RUNNING |
230 ZFCP_STATUS_COMMON_ERP_FAILED |
244 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
248 retval = zfcp_erp_port_reopen(port,
249 ZFCP_STATUS_COMMON_RUNNING |
250 ZFCP_STATUS_COMMON_ERP_FAILED |
264 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
268 retval = zfcp_erp_unit_reopen(unit,
269 ZFCP_STATUS_COMMON_RUNNING |
270 ZFCP_STATUS_COMMON_ERP_FAILED |
280 * purpose: Originator of the ELS commands
282 * returns: 0 - Operation completed successfuly
283 * -EINVAL - Unknown IOCTL command or invalid sense data record
284 * -ENOMEM - Insufficient memory
285 * -EPERM - Cannot create or queue FSF request
288 zfcp_els(struct zfcp_port *port, u8 ls_code)
290 struct zfcp_send_els *send_els;
291 struct zfcp_ls_rls *rls;
292 struct zfcp_ls_pdisc *pdisc;
293 struct zfcp_ls_adisc *adisc;
294 struct page *page = NULL;
298 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
299 if (send_els == NULL)
302 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
303 if (send_els->req == NULL)
305 send_els->req_count = 1;
307 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
308 if (send_els->resp == NULL)
310 send_els->resp_count = 1;
312 page = alloc_pages(GFP_ATOMIC, 0);
315 send_els->req->page = page;
316 send_els->resp->page = page;
317 send_els->req->offset = 0;
318 send_els->resp->offset = PAGE_SIZE >> 1;
320 send_els->port = port;
321 send_els->ls_code = ls_code;
322 send_els->handler = zfcp_els_handler;
323 send_els->handler_data = (unsigned long)send_els;
324 send_els->completion = NULL;
326 req = zfcp_sg_to_address(send_els->req);
334 send_els->req->length = sizeof(struct zfcp_ls_rtv);
335 send_els->resp->length = sizeof(struct zfcp_ls_rtv_acc);
336 ZFCP_LOG_INFO("RTV request from s_id 0x%08x to d_id 0x%08x\n",
337 port->adapter->s_id, port->d_id);
341 send_els->req->length = sizeof(struct zfcp_ls_rls);
342 send_els->resp->length = sizeof(struct zfcp_ls_rls_acc);
343 rls = (struct zfcp_ls_rls*)req;
344 rls->port_id = port->adapter->s_id;
345 ZFCP_LOG_INFO("RLS request from s_id 0x%08x to d_id 0x%08x "
346 "(port_id=0x%08x)\n",
347 port->adapter->s_id, port->d_id, rls->port_id);
351 send_els->req->length = sizeof(struct zfcp_ls_pdisc);
352 send_els->resp->length = sizeof(struct zfcp_ls_pdisc_acc);
353 pdisc = (struct zfcp_ls_pdisc*)req;
354 pdisc->wwpn = port->adapter->wwpn;
355 pdisc->wwnn = port->adapter->wwnn;
356 ZFCP_LOG_INFO("PDISC request from s_id 0x%08x to d_id 0x%08x "
357 "(wwpn=0x%016Lx, wwnn=0x%016Lx)\n",
358 port->adapter->s_id, port->d_id,
359 pdisc->wwpn, pdisc->wwnn);
363 send_els->req->length = sizeof(struct zfcp_ls_adisc);
364 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
365 adisc = (struct zfcp_ls_adisc*)req;
366 adisc->hard_nport_id = port->adapter->s_id;
367 adisc->wwpn = port->adapter->wwpn;
368 adisc->wwnn = port->adapter->wwnn;
369 adisc->nport_id = port->adapter->s_id;
370 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
371 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
372 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
373 port->adapter->s_id, port->d_id,
374 adisc->wwpn, adisc->wwnn,
375 adisc->hard_nport_id, adisc->nport_id);
379 ZFCP_LOG_NORMAL("ELS command code 0x%02x is not supported\n",
382 goto invalid_ls_code;
385 retval = zfcp_fsf_send_els(send_els);
387 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
388 "0x%016Lx on adapter %s\n",
389 port->wwpn, zfcp_get_busid_by_port(port));
396 ZFCP_LOG_DEBUG("out of memory\n");
401 __free_pages(page, 0);
402 if (send_els != NULL) {
403 if (send_els->req != NULL)
404 kfree(send_els->req);
405 if (send_els->resp != NULL)
406 kfree(send_els->resp);
416 * function: zfcp_els_handler
418 * purpose: Handler for all kind of ELSs
420 * returns: 0 - Operation completed successfuly
421 * -ENXIO - ELS has been rejected
422 * -EPERM - Port forced reopen failed
425 zfcp_els_handler(unsigned long data)
427 struct zfcp_send_els *send_els = (struct zfcp_send_els*)data;
428 struct zfcp_port *port = send_els->port;
429 struct zfcp_ls_rjt *rjt;
430 struct zfcp_ls_rtv_acc *rtv;
431 struct zfcp_ls_rls_acc *rls;
432 struct zfcp_ls_pdisc_acc *pdisc;
433 struct zfcp_ls_adisc_acc *adisc;
435 u8 req_code, resp_code;
438 if (send_els->status != 0) {
439 ZFCP_LOG_NORMAL("ELS request timed out, physical port reopen "
440 "of port 0x%016Lx on adapter %s failed\n",
441 port->wwpn, zfcp_get_busid_by_port(port));
442 debug_text_event(port->adapter->erp_dbf, 3, "forcreop");
443 retval = zfcp_erp_port_forced_reopen(port, 0);
445 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
446 "on adapter %s failed\n", port->wwpn,
447 zfcp_get_busid_by_port(port));
453 req = (void*)((page_to_pfn(send_els->req->page) << PAGE_SHIFT) + send_els->req->offset);
454 resp = (void*)((page_to_pfn(send_els->resp->page) << PAGE_SHIFT) + send_els->resp->offset);
455 req_code = *(u8*)req;
456 resp_code = *(u8*)resp;
461 rjt = (struct zfcp_ls_rjt*)resp;
463 switch (rjt->reason_code) {
465 case ZFCP_LS_RJT_INVALID_COMMAND_CODE:
466 ZFCP_LOG_INFO("invalid LS command code "
467 "(wwpn=0x%016Lx, command=0x%02x)\n",
468 port->wwpn, req_code);
471 case ZFCP_LS_RJT_LOGICAL_ERROR:
472 ZFCP_LOG_INFO("logical error (wwpn=0x%016Lx, "
473 "reason_expl=0x%02x)\n",
474 port->wwpn, rjt->reason_expl);
477 case ZFCP_LS_RJT_LOGICAL_BUSY:
478 ZFCP_LOG_INFO("logical busy (wwpn=0x%016Lx, "
479 "reason_expl=0x%02x)\n",
480 port->wwpn, rjt->reason_expl);
483 case ZFCP_LS_RJT_PROTOCOL_ERROR:
484 ZFCP_LOG_INFO("protocol error (wwpn=0x%016Lx, "
485 "reason_expl=0x%02x)\n",
486 port->wwpn, rjt->reason_expl);
489 case ZFCP_LS_RJT_UNABLE_TO_PERFORM:
490 ZFCP_LOG_INFO("unable to perform command requested "
491 "(wwpn=0x%016Lx, reason_expl=0x%02x)\n",
492 port->wwpn, rjt->reason_expl);
495 case ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED:
496 ZFCP_LOG_INFO("command not supported (wwpn=0x%016Lx, "
498 port->wwpn, req_code);
501 case ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR:
502 ZFCP_LOG_INFO("vendor specific error (wwpn=0x%016Lx, "
503 "vendor_unique=0x%02x)\n",
504 port->wwpn, rjt->vendor_unique);
508 ZFCP_LOG_NORMAL("ELS rejected by remote port 0x%016Lx "
509 "on adapter %s (reason_code=0x%02x)\n",
511 zfcp_get_busid_by_port(port),
521 rtv = (struct zfcp_ls_rtv_acc*)resp;
522 ZFCP_LOG_INFO("RTV response from d_id 0x%08x to s_id "
523 "0x%08x (R_A_TOV=%ds E_D_TOV=%d%cs)\n",
524 port->d_id, port->adapter->s_id,
525 rtv->r_a_tov, rtv->e_d_tov,
527 ZFCP_LS_RTV_E_D_TOV_FLAG ? 'n' : 'm');
531 rls = (struct zfcp_ls_rls_acc*)resp;
532 ZFCP_LOG_INFO("RLS response from d_id 0x%08x to s_id "
533 "0x%08x (link_failure_count=%u, "
534 "loss_of_sync_count=%u, "
535 "loss_of_signal_count=%u, "
536 "primitive_sequence_protocol_error=%u, "
537 "invalid_transmition_word=%u, "
538 "invalid_crc_count=%u)\n",
539 port->d_id, port->adapter->s_id,
540 rls->link_failure_count,
541 rls->loss_of_sync_count,
542 rls->loss_of_signal_count,
543 rls->prim_seq_prot_error,
544 rls->invalid_transmition_word,
545 rls->invalid_crc_count);
549 pdisc = (struct zfcp_ls_pdisc_acc*)resp;
550 ZFCP_LOG_INFO("PDISC response from d_id 0x%08x to s_id "
551 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
552 "vendor='%-16s')\n", port->d_id,
553 port->adapter->s_id, pdisc->wwpn,
554 pdisc->wwnn, pdisc->vendor_version);
558 adisc = (struct zfcp_ls_adisc_acc*)resp;
559 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
560 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
561 "hard_nport_id=0x%08x, "
562 "nport_id=0x%08x)\n", port->d_id,
563 port->adapter->s_id, adisc->wwpn,
564 adisc->wwnn, adisc->hard_nport_id,
566 /* FIXME: set wwnn in during open port */
568 port->wwnn = adisc->wwnn;
574 ZFCP_LOG_NORMAL("unknown payload code 0x%02x received for "
575 "request 0x%02x to d_id 0x%08x, reopen needed "
576 "for port 0x%016Lx on adapter %s\n", resp_code,
577 req_code, port->d_id, port->wwpn,
578 zfcp_get_busid_by_port(port));
579 retval = zfcp_erp_port_forced_reopen(port, 0);
581 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx on "
582 "adapter %s failed\n", port->wwpn,
583 zfcp_get_busid_by_port(port));
589 __free_pages(send_els->req->page, 0);
590 kfree(send_els->req);
591 kfree(send_els->resp);
598 * function: zfcp_test_link
600 * purpose: Test a status of a link to a remote port using the ELS command ADISC
602 * returns: 0 - Link is OK
603 * -EPERM - Port forced reopen failed
606 zfcp_test_link(struct zfcp_port *port)
610 retval = zfcp_els(port, ZFCP_LS_ADISC);
612 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
613 "on adapter %s\n ", port->wwpn,
614 zfcp_get_busid_by_port(port));
615 retval = zfcp_erp_port_forced_reopen(port, 0);
617 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
618 "on adapter %s failed\n", port->wwpn,
619 zfcp_get_busid_by_port(port));
631 * purpose: called if a port failed to be opened normally
632 * initiates Forced Reopen recovery which is done
635 * returns: 0 - initiated action succesfully
636 * <0 - failed to initiate action
639 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
642 struct zfcp_adapter *adapter = port->adapter;
644 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
645 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
647 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
648 port->wwpn, zfcp_get_busid_by_port(port));
650 zfcp_erp_port_block(port, clear_mask);
652 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
653 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
654 "on adapter %s\n", port->wwpn,
655 zfcp_get_busid_by_port(port));
656 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
657 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
662 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
663 port->adapter, port, NULL);
672 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
673 * used to ensure the correct locking
675 * returns: 0 - initiated action succesfully
676 * <0 - failed to initiate action
679 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
683 struct zfcp_adapter *adapter;
685 adapter = port->adapter;
686 read_lock_irqsave(&zfcp_data.config_lock, flags);
687 write_lock(&adapter->erp_lock);
688 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
689 write_unlock(&adapter->erp_lock);
690 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
698 * purpose: called if a port is to be opened
699 * initiates Reopen recovery which is done
702 * returns: 0 - initiated action succesfully
703 * <0 - failed to initiate action
706 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
709 struct zfcp_adapter *adapter = port->adapter;
711 debug_text_event(adapter->erp_dbf, 5, "p_ro");
712 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
714 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
715 port->wwpn, zfcp_get_busid_by_port(port));
717 zfcp_erp_port_block(port, clear_mask);
719 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
720 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
721 "on adapter %s\n", port->wwpn,
722 zfcp_get_busid_by_port(port));
723 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
724 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
725 /* ensure propagation of failed status to new devices */
726 zfcp_erp_port_failed(port);
731 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
732 port->adapter, port, NULL);
741 * purpose: Wrappper for zfcp_erp_port_reopen_internal
742 * used to ensure the correct locking
744 * returns: 0 - initiated action succesfully
745 * <0 - failed to initiate action
748 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
752 struct zfcp_adapter *adapter = port->adapter;
754 read_lock_irqsave(&zfcp_data.config_lock, flags);
755 write_lock(&adapter->erp_lock);
756 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
757 write_unlock(&adapter->erp_lock);
758 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
766 * purpose: called if a unit is to be opened
767 * initiates Reopen recovery which is done
770 * returns: 0 - initiated action succesfully
771 * <0 - failed to initiate action
774 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
777 struct zfcp_adapter *adapter = unit->port->adapter;
779 debug_text_event(adapter->erp_dbf, 5, "u_ro");
780 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
781 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
782 "on adapter %s\n", unit->fcp_lun,
783 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
785 zfcp_erp_unit_block(unit, clear_mask);
787 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
788 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
789 "on port 0x%016Lx on adapter %s\n",
790 unit->fcp_lun, unit->port->wwpn,
791 zfcp_get_busid_by_unit(unit));
792 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
793 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
799 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
800 unit->port->adapter, unit->port, unit);
808 * purpose: Wrappper for zfcp_erp_unit_reopen_internal
809 * used to ensure the correct locking
811 * returns: 0 - initiated action succesfully
812 * <0 - failed to initiate action
815 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
819 struct zfcp_adapter *adapter;
820 struct zfcp_port *port;
823 adapter = port->adapter;
825 read_lock_irqsave(&zfcp_data.config_lock, flags);
826 write_lock(&adapter->erp_lock);
827 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
828 write_unlock(&adapter->erp_lock);
829 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
837 * purpose: disable I/O,
838 * return any open requests and clean them up,
839 * aim: no pending and incoming I/O
844 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
846 debug_text_event(adapter->erp_dbf, 6, "a_bl");
847 zfcp_erp_modify_adapter_status(adapter,
848 ZFCP_STATUS_COMMON_UNBLOCKED |
849 clear_mask, ZFCP_CLEAR);
855 * purpose: enable I/O
860 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
862 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
863 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
869 * purpose: disable I/O,
870 * return any open requests and clean them up,
871 * aim: no pending and incoming I/O
876 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
878 struct zfcp_adapter *adapter = port->adapter;
880 debug_text_event(adapter->erp_dbf, 6, "p_bl");
881 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
882 zfcp_erp_modify_port_status(port,
883 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
890 * purpose: enable I/O
895 zfcp_erp_port_unblock(struct zfcp_port *port)
897 struct zfcp_adapter *adapter = port->adapter;
899 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
900 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
901 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
907 * purpose: disable I/O,
908 * return any open requests and clean them up,
909 * aim: no pending and incoming I/O
914 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
916 struct zfcp_adapter *adapter = unit->port->adapter;
918 debug_text_event(adapter->erp_dbf, 6, "u_bl");
919 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
920 zfcp_erp_modify_unit_status(unit,
921 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
928 * purpose: enable I/O
933 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
935 struct zfcp_adapter *adapter = unit->port->adapter;
937 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
938 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
939 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
950 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
952 struct zfcp_adapter *adapter = erp_action->adapter;
954 debug_text_event(adapter->erp_dbf, 4, "a_ar");
955 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
957 zfcp_erp_action_to_ready(erp_action);
958 up(&adapter->erp_ready_sem);
966 * returns: <0 erp_action not found in any list
967 * ZFCP_ERP_ACTION_READY erp_action is in ready list
968 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
970 * locks: erp_lock must be held
973 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
975 int retval = -EINVAL;
976 struct list_head *entry;
977 struct zfcp_erp_action *entry_erp_action;
978 struct zfcp_adapter *adapter = erp_action->adapter;
980 /* search in running list */
981 list_for_each(entry, &adapter->erp_running_head) {
983 list_entry(entry, struct zfcp_erp_action, list);
984 if (entry_erp_action == erp_action) {
985 retval = ZFCP_ERP_ACTION_RUNNING;
989 /* search in ready list */
990 list_for_each(entry, &adapter->erp_ready_head) {
992 list_entry(entry, struct zfcp_erp_action, list);
993 if (entry_erp_action == erp_action) {
994 retval = ZFCP_ERP_ACTION_READY;
1004 * purpose: checks current status of action (timed out, dismissed, ...)
1005 * and does appropriate preparations (dismiss fsf request, ...)
1007 * locks: called under erp_lock (disabled interrupts)
1012 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
1015 struct zfcp_fsf_req *fsf_req;
1016 struct zfcp_adapter *adapter = erp_action->adapter;
1018 if (erp_action->fsf_req) {
1019 /* take lock to ensure that request is not being deleted meanwhile */
1020 write_lock(&adapter->fsf_req_list_lock);
1021 /* check whether fsf req does still exist */
1022 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
1023 if (fsf_req == erp_action->fsf_req)
1025 if (fsf_req == erp_action->fsf_req) {
1026 /* fsf_req still exists */
1027 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
1028 debug_event(adapter->erp_dbf, 3, &fsf_req,
1029 sizeof (unsigned long));
1030 /* dismiss fsf_req of timed out or dismissed erp_action */
1031 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
1032 ZFCP_STATUS_ERP_TIMEDOUT)) {
1033 debug_text_event(adapter->erp_dbf, 3,
1035 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
1037 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1038 ZFCP_LOG_NORMAL("error: erp step timed out "
1039 "(action=%d, fsf_req=%p)\n ",
1041 erp_action->fsf_req);
1044 * If fsf_req is neither dismissed nor completed
1045 * then keep it running asynchronously and don't mess
1046 * with the association of erp_action and fsf_req.
1048 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
1049 ZFCP_STATUS_FSFREQ_DISMISSED)) {
1050 /* forget about association between fsf_req
1052 fsf_req->erp_action = NULL;
1053 erp_action->fsf_req = NULL;
1056 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
1058 * even if this fsf_req has gone, forget about
1059 * association between erp_action and fsf_req
1061 erp_action->fsf_req = NULL;
1063 write_unlock(&adapter->fsf_req_list_lock);
1065 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
1071 * purpose: generic handler for asynchronous events related to erp_action events
1072 * (normal completion, time-out, dismissing, retry after
1073 * low memory condition)
1075 * note: deletion of timer is not required (e.g. in case of a time-out),
1076 * but a second try does no harm,
1077 * we leave it in here to allow for greater simplification
1079 * returns: 0 - there was an action to handle
1083 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
1084 unsigned long set_mask)
1087 struct zfcp_adapter *adapter = erp_action->adapter;
1089 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
1090 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
1091 debug_event(adapter->erp_dbf, 2, &erp_action->action,
1093 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
1094 del_timer_sync(&erp_action->timer);
1095 erp_action->status |= set_mask;
1096 zfcp_erp_action_ready(erp_action);
1099 /* action is ready or gone - nothing to do */
1100 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
1101 debug_event(adapter->erp_dbf, 3, &erp_action->action,
1110 * purpose: generic handler for asynchronous events related to erp_action
1111 * events (normal completion, time-out, dismissing, retry after
1112 * low memory condition)
1114 * note: deletion of timer is not required (e.g. in case of a time-out),
1115 * but a second try does no harm,
1116 * we leave it in here to allow for greater simplification
1118 * returns: 0 - there was an action to handle
1122 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1123 unsigned long set_mask)
1125 struct zfcp_adapter *adapter = erp_action->adapter;
1126 unsigned long flags;
1129 write_lock_irqsave(&adapter->erp_lock, flags);
1130 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1131 write_unlock_irqrestore(&adapter->erp_lock, flags);
1137 * purpose: is called for erp_action which was slept waiting for
1138 * memory becoming avaliable,
1139 * will trigger that this action will be continued
1142 zfcp_erp_memwait_handler(unsigned long data)
1144 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1145 struct zfcp_adapter *adapter = erp_action->adapter;
1147 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1148 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1150 zfcp_erp_async_handler(erp_action, 0);
1154 * purpose: is called if an asynchronous erp step timed out,
1155 * action gets an appropriate flag and will be processed
1159 zfcp_erp_timeout_handler(unsigned long data)
1161 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1162 struct zfcp_adapter *adapter = erp_action->adapter;
1164 debug_text_event(adapter->erp_dbf, 2, "a_th");
1165 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1167 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1171 * purpose: is called for an erp_action which needs to be ended
1172 * though not being done,
1173 * this is usually required if an higher is generated,
1174 * action gets an appropriate flag and will be processed
1177 * locks: erp_lock held (thus we need to call another handler variant)
1180 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1182 struct zfcp_adapter *adapter = erp_action->adapter;
1184 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1185 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1187 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1193 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1197 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1199 rwlock_init(&adapter->erp_lock);
1200 INIT_LIST_HEAD(&adapter->erp_ready_head);
1201 INIT_LIST_HEAD(&adapter->erp_running_head);
1202 sema_init(&adapter->erp_ready_sem, 0);
1204 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1206 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1208 zfcp_get_busid_by_adapter(adapter));
1209 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1211 wait_event(adapter->erp_thread_wqh,
1212 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1214 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1217 return (retval < 0);
1227 * context: process (i.e. proc-fs or rmmod/insmod)
1229 * note: The caller of this routine ensures that the specified
1230 * adapter has been shut down and that this operation
1231 * has been completed. Thus, there are no pending erp_actions
1232 * which would need to be handled here.
1235 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1239 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1240 up(&adapter->erp_ready_sem);
1242 wait_event(adapter->erp_thread_wqh,
1243 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1246 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1249 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1255 * purpose: is run as a kernel thread,
1256 * goes through list of error recovery actions of associated adapter
1257 * and delegates single action to execution
1262 zfcp_erp_thread(void *data)
1264 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1265 struct list_head *next;
1266 struct zfcp_erp_action *erp_action;
1267 unsigned long flags;
1269 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1270 /* Block all signals */
1271 siginitsetinv(¤t->blocked, 0);
1272 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1273 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1274 wake_up(&adapter->erp_thread_wqh);
1276 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1277 &adapter->status)) {
1279 write_lock_irqsave(&adapter->erp_lock, flags);
1280 next = adapter->erp_ready_head.prev;
1281 write_unlock_irqrestore(&adapter->erp_lock, flags);
1283 if (next != &adapter->erp_ready_head) {
1285 list_entry(next, struct zfcp_erp_action, list);
1287 * process action (incl. [re]moving it
1288 * from 'ready' queue)
1290 zfcp_erp_strategy(erp_action);
1294 * sleep as long as there is nothing to do, i.e.
1295 * no action in 'ready' queue to be processed and
1296 * thread is not to be killed
1298 down_interruptible(&adapter->erp_ready_sem);
1299 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1302 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1303 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1304 wake_up(&adapter->erp_thread_wqh);
1312 * purpose: drives single error recovery action and schedules higher and
1313 * subordinate actions, if necessary
1315 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1316 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1317 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1318 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1319 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1322 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1325 struct zfcp_adapter *adapter = erp_action->adapter;
1326 struct zfcp_port *port = erp_action->port;
1327 struct zfcp_unit *unit = erp_action->unit;
1328 int action = erp_action->action;
1329 u32 status = erp_action->status;
1330 unsigned long flags;
1332 /* serialise dismissing, timing out, moving, enqueueing */
1333 read_lock_irqsave(&zfcp_data.config_lock, flags);
1334 write_lock(&adapter->erp_lock);
1336 /* dequeue dismissed action and leave, if required */
1337 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1338 if (retval == ZFCP_ERP_DISMISSED) {
1339 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1344 * move action to 'running' queue before processing it
1345 * (to avoid a race condition regarding moving the
1346 * action to the 'running' queue and back)
1348 zfcp_erp_action_to_running(erp_action);
1351 * try to process action as far as possible,
1352 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1353 * afterwards the lock is required again for the following reasons:
1354 * - dequeueing of finished action and enqueueing of
1355 * follow-up actions must be atomic so that any other
1356 * reopen-routine does not believe there is nothing to do
1357 * and that it is safe to enqueue something else,
1358 * - we want to force any control thread which is dismissing
1359 * actions to finish this before we decide about
1360 * necessary steps to be taken here further
1362 write_unlock(&adapter->erp_lock);
1363 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1364 retval = zfcp_erp_strategy_do_action(erp_action);
1365 read_lock_irqsave(&zfcp_data.config_lock, flags);
1366 write_lock(&adapter->erp_lock);
1369 * check for dismissed status again to avoid follow-up actions,
1370 * failing of targets and so on for dismissed actions
1372 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1375 case ZFCP_ERP_DISMISSED:
1376 /* leave since this action has ridden to its ancestors */
1377 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1379 case ZFCP_ERP_NOMEM:
1380 /* no memory to continue immediately, let it sleep */
1381 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1382 ++adapter->erp_low_mem_count;
1383 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1385 /* This condition is true if there is no memory available
1386 for any erp_action on this adapter. This implies that there
1387 are no elements in the memory pool(s) left for erp_actions.
1388 This might happen if an erp_action that used a memory pool
1389 element was timed out.
1391 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1392 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1393 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1394 "restarting I/O on adapter %s "
1395 "to free mempool\n",
1396 zfcp_get_busid_by_adapter(adapter));
1397 zfcp_erp_adapter_reopen_internal(adapter, 0);
1399 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1400 retval = zfcp_erp_strategy_memwait(erp_action);
1403 case ZFCP_ERP_CONTINUES:
1404 /* leave since this action runs asynchronously */
1405 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1406 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1407 --adapter->erp_low_mem_count;
1408 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1412 /* ok, finished action (whatever its result is) */
1414 /* check for unrecoverable targets */
1415 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1417 /* action must be dequeued (here to allow for further ones) */
1418 zfcp_erp_action_dequeue(erp_action);
1421 * put this target through the erp mill again if someone has
1422 * requested to change the status of a target being online
1423 * to offline or the other way around
1424 * (old retval is preserved if nothing has to be done here)
1426 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1427 port, unit, retval);
1430 * leave if target is in permanent error state or if
1431 * action is repeated in order to process state change
1433 if (retval == ZFCP_ERP_EXIT) {
1434 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1438 /* trigger follow up actions */
1439 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1442 write_unlock(&adapter->erp_lock);
1443 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1445 if (retval != ZFCP_ERP_CONTINUES)
1446 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1449 * a few tasks remain when the erp queues are empty
1450 * (don't do that if the last action evaluated was dismissed
1451 * since this clearly indicates that there is more to come) :
1452 * - close the name server port if it is open yet
1453 * (enqueues another [probably] final action)
1454 * - otherwise, wake up whoever wants to be woken when we are
1457 if (retval != ZFCP_ERP_DISMISSED)
1458 zfcp_erp_strategy_check_queues(adapter);
1460 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1470 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1471 * retval - otherwise
1474 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1476 struct zfcp_adapter *adapter = erp_action->adapter;
1478 zfcp_erp_strategy_check_fsfreq(erp_action);
1480 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1481 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1482 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1483 zfcp_erp_action_dequeue(erp_action);
1484 retval = ZFCP_ERP_DISMISSED;
1486 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1499 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1501 int retval = ZFCP_ERP_FAILED;
1502 struct zfcp_adapter *adapter = erp_action->adapter;
1505 * try to execute/continue action as far as possible,
1506 * note: no lock in subsequent strategy routines
1507 * (this allows these routine to call schedule, e.g.
1508 * kmalloc with such flags or qdio_initialize & friends)
1509 * Note: in case of timeout, the seperate strategies will fail
1510 * anyhow. No need for a special action. Even worse, a nameserver
1511 * failure would not wake up waiting ports without the call.
1513 switch (erp_action->action) {
1515 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1516 retval = zfcp_erp_adapter_strategy(erp_action);
1519 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1520 retval = zfcp_erp_port_forced_strategy(erp_action);
1523 case ZFCP_ERP_ACTION_REOPEN_PORT:
1524 retval = zfcp_erp_port_strategy(erp_action);
1527 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1528 retval = zfcp_erp_unit_strategy(erp_action);
1532 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1533 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1535 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1536 "adapter %s (action=%d)\n",
1537 zfcp_get_busid_by_adapter(erp_action->adapter),
1538 erp_action->action);
1547 * purpose: triggers retry of this action after a certain amount of time
1548 * by means of timer provided by erp_action
1550 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1553 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1555 int retval = ZFCP_ERP_CONTINUES;
1556 struct zfcp_adapter *adapter = erp_action->adapter;
1558 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1559 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1560 init_timer(&erp_action->timer);
1561 erp_action->timer.function = zfcp_erp_memwait_handler;
1562 erp_action->timer.data = (unsigned long) erp_action;
1563 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1564 add_timer(&erp_action->timer);
1570 * function: zfcp_erp_adapter_failed
1572 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1576 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1578 zfcp_erp_modify_adapter_status(adapter,
1579 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1580 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1581 zfcp_get_busid_by_adapter(adapter));
1582 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1586 * function: zfcp_erp_port_failed
1588 * purpose: sets the port and all underlying devices to ERP_FAILED
1592 zfcp_erp_port_failed(struct zfcp_port *port)
1594 zfcp_erp_modify_port_status(port,
1595 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1597 ZFCP_LOG_NORMAL("port erp failed on port 0x%016Lx on adapter %s\n",
1598 port->wwpn, zfcp_get_busid_by_port(port));
1599 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1600 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1604 * function: zfcp_erp_unit_failed
1606 * purpose: sets the unit to ERP_FAILED
1610 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1612 zfcp_erp_modify_unit_status(unit,
1613 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1615 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1616 " on adapter %s\n", unit->fcp_lun,
1617 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1618 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1619 debug_event(unit->port->adapter->erp_dbf, 2,
1620 &unit->fcp_lun, sizeof (fcp_lun_t));
1624 * function: zfcp_erp_strategy_check_target
1626 * purpose: increments the erp action count on the device currently in
1627 * recovery if the action failed or resets the count in case of
1628 * success. If a maximum count is exceeded the device is marked
1630 * The 'blocked' state of a target which has been recovered
1631 * successfully is reset.
1633 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1634 * ZFCP_ERP_SUCCEEDED - action finished successfully
1635 * ZFCP_ERP_EXIT - action failed and will not continue
1638 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1640 struct zfcp_adapter *adapter = erp_action->adapter;
1641 struct zfcp_port *port = erp_action->port;
1642 struct zfcp_unit *unit = erp_action->unit;
1644 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1645 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1646 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1648 switch (erp_action->action) {
1650 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1651 result = zfcp_erp_strategy_check_unit(unit, result);
1654 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1655 case ZFCP_ERP_ACTION_REOPEN_PORT:
1656 result = zfcp_erp_strategy_check_port(port, result);
1659 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1660 result = zfcp_erp_strategy_check_adapter(adapter, result);
1675 zfcp_erp_strategy_statechange(int action,
1677 struct zfcp_adapter *adapter,
1678 struct zfcp_port *port,
1679 struct zfcp_unit *unit, int retval)
1681 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1682 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1686 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1687 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1689 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1690 retval = ZFCP_ERP_EXIT;
1694 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1695 case ZFCP_ERP_ACTION_REOPEN_PORT:
1696 if (zfcp_erp_strategy_statechange_detected(&port->status,
1698 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1699 retval = ZFCP_ERP_EXIT;
1703 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1704 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1706 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1707 retval = ZFCP_ERP_EXIT;
1723 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1726 /* take it online */
1727 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1728 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1729 /* take it offline */
1730 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1731 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1735 * zfcp_erp_scsi_add_device
1736 * @data: pointer to a struct zfcp_unit
1738 * Registers a logical unit with the SCSI stack.
1741 zfcp_erp_scsi_add_device(void *data)
1744 struct zfcp_unit *unit;
1745 struct work_struct work;
1749 scsi_add_device(p->unit->port->adapter->scsi_host,
1750 0, p->unit->port->scsi_id, p->unit->scsi_lun);
1751 atomic_set(&p->unit->scsi_add_work, 0);
1752 wake_up(&p->unit->scsi_add_wq);
1753 zfcp_unit_put(p->unit);
1758 * zfcp_erp_schedule_work
1759 * @unit: pointer to unit which should be registered with SCSI stack
1761 * Schedules work which registers a unit with the SCSI stack
1764 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1767 struct zfcp_unit * unit;
1768 struct work_struct work;
1771 if (atomic_compare_and_swap(0, 1, &unit->scsi_add_work))
1774 if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
1775 ZFCP_LOG_NORMAL("error: registration at SCSI stack failed for "
1776 "unit 0x%016Lx on port 0x%016Lx on "
1777 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
1778 zfcp_get_busid_by_unit(unit));
1779 atomic_set(&unit->scsi_add_work, 0);
1783 zfcp_unit_get(unit);
1784 memset(p, 0, sizeof(*p));
1785 INIT_WORK(&p->work, zfcp_erp_scsi_add_device, p);
1787 schedule_work(&p->work);
1799 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1801 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1802 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1803 sizeof (fcp_lun_t));
1806 case ZFCP_ERP_SUCCEEDED :
1807 atomic_set(&unit->erp_counter, 0);
1808 zfcp_erp_unit_unblock(unit);
1810 case ZFCP_ERP_FAILED :
1811 atomic_inc(&unit->erp_counter);
1812 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1813 zfcp_erp_unit_failed(unit);
1815 case ZFCP_ERP_EXIT :
1820 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1821 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1822 result = ZFCP_ERP_EXIT;
1836 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1838 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1839 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1842 case ZFCP_ERP_SUCCEEDED :
1843 atomic_set(&port->erp_counter, 0);
1844 zfcp_erp_port_unblock(port);
1846 case ZFCP_ERP_FAILED :
1847 atomic_inc(&port->erp_counter);
1848 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1849 zfcp_erp_port_failed(port);
1851 case ZFCP_ERP_EXIT :
1856 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1857 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1858 result = ZFCP_ERP_EXIT;
1872 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1874 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1877 case ZFCP_ERP_SUCCEEDED :
1878 atomic_set(&adapter->erp_counter, 0);
1879 zfcp_erp_adapter_unblock(adapter);
1881 case ZFCP_ERP_FAILED :
1882 atomic_inc(&adapter->erp_counter);
1883 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1884 zfcp_erp_adapter_failed(adapter);
1886 case ZFCP_ERP_EXIT :
1891 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1892 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1893 result = ZFCP_ERP_EXIT;
1902 * purpose: remaining things in good cases,
1903 * escalation in bad cases
1908 zfcp_erp_strategy_followup_actions(int action,
1909 struct zfcp_adapter *adapter,
1910 struct zfcp_port *port,
1911 struct zfcp_unit *unit, int status)
1913 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1914 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1916 /* initiate follow-up actions depending on success of finished action */
1919 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1920 if (status == ZFCP_ERP_SUCCEEDED)
1921 zfcp_erp_port_reopen_all_internal(adapter, 0);
1923 zfcp_erp_adapter_reopen_internal(adapter, 0);
1926 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1927 if (status == ZFCP_ERP_SUCCEEDED)
1928 zfcp_erp_port_reopen_internal(port, 0);
1930 zfcp_erp_adapter_reopen_internal(adapter, 0);
1933 case ZFCP_ERP_ACTION_REOPEN_PORT:
1934 if (status == ZFCP_ERP_SUCCEEDED)
1935 zfcp_erp_unit_reopen_all_internal(port, 0);
1937 zfcp_erp_port_forced_reopen_internal(port, 0);
1940 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1941 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1943 zfcp_erp_port_reopen_internal(unit->port, 0);
1958 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1961 unsigned long flags;
1962 struct zfcp_port *nport = adapter->nameserver_port;
1964 read_lock_irqsave(&zfcp_data.config_lock, flags);
1965 read_lock(&adapter->erp_lock);
1966 if (list_empty(&adapter->erp_ready_head) &&
1967 list_empty(&adapter->erp_running_head)) {
1969 && atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
1971 debug_text_event(adapter->erp_dbf, 4, "a_cq_nspsd");
1972 /* taking down nameserver port */
1973 zfcp_erp_port_reopen_internal(nport,
1974 ZFCP_STATUS_COMMON_RUNNING |
1975 ZFCP_STATUS_COMMON_ERP_FAILED);
1977 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1978 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1980 wake_up(&adapter->erp_done_wqh);
1983 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1984 read_unlock(&adapter->erp_lock);
1985 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1998 zfcp_erp_wait(struct zfcp_adapter *adapter)
2002 wait_event(adapter->erp_done_wqh,
2003 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
2010 * function: zfcp_erp_modify_adapter_status
2016 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
2017 u32 mask, int set_or_clear)
2019 struct zfcp_port *port;
2020 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2022 if (set_or_clear == ZFCP_SET) {
2023 atomic_set_mask(mask, &adapter->status);
2024 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
2026 atomic_clear_mask(mask, &adapter->status);
2027 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2028 atomic_set(&adapter->erp_counter, 0);
2029 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
2031 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
2033 /* Deal with all underlying devices, only pass common_mask */
2035 list_for_each_entry(port, &adapter->port_list_head, list)
2036 zfcp_erp_modify_port_status(port, common_mask,
2041 * function: zfcp_erp_modify_port_status
2043 * purpose: sets the port and all underlying devices to ERP_FAILED
2047 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
2049 struct zfcp_unit *unit;
2050 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2052 if (set_or_clear == ZFCP_SET) {
2053 atomic_set_mask(mask, &port->status);
2054 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
2056 atomic_clear_mask(mask, &port->status);
2057 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2058 atomic_set(&port->erp_counter, 0);
2059 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
2061 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2062 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2064 /* Modify status of all underlying devices, only pass common mask */
2066 list_for_each_entry(unit, &port->unit_list_head, list)
2067 zfcp_erp_modify_unit_status(unit, common_mask,
2072 * function: zfcp_erp_modify_unit_status
2074 * purpose: sets the unit to ERP_FAILED
2078 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
2080 if (set_or_clear == ZFCP_SET) {
2081 atomic_set_mask(mask, &unit->status);
2082 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
2084 atomic_clear_mask(mask, &unit->status);
2085 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
2086 atomic_set(&unit->erp_counter, 0);
2088 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
2090 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
2091 sizeof (fcp_lun_t));
2092 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2098 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
2099 * used to ensure the correct locking
2101 * returns: 0 - initiated action succesfully
2102 * <0 - failed to initiate action
2105 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
2108 unsigned long flags;
2110 read_lock_irqsave(&zfcp_data.config_lock, flags);
2111 write_lock(&adapter->erp_lock);
2112 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
2113 write_unlock(&adapter->erp_lock);
2114 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2127 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
2130 struct zfcp_port *port;
2132 list_for_each_entry(port, &adapter->port_list_head, list)
2133 if (!atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER, &port->status))
2134 zfcp_erp_port_reopen_internal(port, clear_mask);
2147 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
2150 struct zfcp_unit *unit;
2152 list_for_each_entry(unit, &port->unit_list_head, list)
2153 zfcp_erp_unit_reopen_internal(unit, clear_mask);
2161 * purpose: this routine executes the 'Reopen Adapter' action
2162 * (the entire action is processed synchronously, since
2163 * there are no actions which might be run concurrently
2166 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2167 * ZFCP_ERP_FAILED - action finished unsuccessfully
2170 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
2173 unsigned long timeout;
2174 struct zfcp_adapter *adapter = erp_action->adapter;
2176 retval = zfcp_erp_adapter_strategy_close(erp_action);
2177 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2178 retval = ZFCP_ERP_EXIT;
2180 retval = zfcp_erp_adapter_strategy_open(erp_action);
2182 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
2183 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2184 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2186 if (retval == ZFCP_ERP_FAILED) {
2187 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2188 "to recover itself\n",
2189 zfcp_get_busid_by_adapter(adapter));
2191 * SUGGESTION: substitute by
2192 * timeout = ZFCP_TYPE2_RECOVERY_TIME;
2193 * __ZFCP_WAIT_EVENT_TIMEOUT(timeout, 0);
2195 timeout = ZFCP_TYPE2_RECOVERY_TIME;
2196 set_current_state(TASK_UNINTERRUPTIBLE);
2197 schedule_timeout(timeout);
2208 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2209 * ZFCP_ERP_FAILED - action finished unsuccessfully
2212 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2216 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2217 &erp_action->adapter->status);
2218 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2219 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2220 &erp_action->adapter->status);
2230 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2231 * ZFCP_ERP_FAILED - action finished unsuccessfully
2234 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2238 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2239 &erp_action->adapter->status);
2240 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2241 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2242 &erp_action->adapter->status);
2248 * function: zfcp_register_adapter
2250 * purpose: allocate the irq associated with this devno and register
2251 * the FSF adapter with the SCSI stack
2256 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2258 int retval = ZFCP_ERP_SUCCEEDED;
2263 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2264 if (retval != ZFCP_ERP_SUCCEEDED)
2267 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2268 if (retval != ZFCP_ERP_SUCCEEDED)
2269 goto failed_openfcp;
2271 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2275 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2276 &erp_action->adapter->status);
2279 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2280 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2287 * function: zfcp_qdio_init
2289 * purpose: setup QDIO operation for specified adapter
2291 * returns: 0 - successful setup
2295 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2299 volatile struct qdio_buffer_element *sbale;
2300 struct zfcp_adapter *adapter = erp_action->adapter;
2302 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2303 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2305 zfcp_get_busid_by_adapter(adapter));
2309 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2310 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2312 zfcp_get_busid_by_adapter(adapter));
2313 goto failed_qdio_establish;
2315 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2317 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2318 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2320 zfcp_get_busid_by_adapter(adapter));
2321 goto failed_qdio_activate;
2323 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2326 * put buffers into response queue,
2328 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2329 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2331 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2335 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2336 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2337 zfcp_get_busid_by_adapter(adapter),
2338 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2340 retval = do_QDIO(adapter->ccw_device,
2341 QDIO_FLAG_SYNC_INPUT,
2342 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2345 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2347 goto failed_do_qdio;
2349 adapter->response_queue.free_index = 0;
2350 atomic_set(&adapter->response_queue.free_count, 0);
2351 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2352 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2354 /* set index of first avalable SBALS / number of available SBALS */
2355 adapter->request_queue.free_index = 0;
2356 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2357 adapter->request_queue.distance_from_int = 0;
2359 /* initialize waitqueue used to wait for free SBALs in requests queue */
2360 init_waitqueue_head(&adapter->request_wq);
2362 /* ok, we did it - skip all cleanups for different failures */
2363 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2364 retval = ZFCP_ERP_SUCCEEDED;
2370 failed_qdio_activate:
2371 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2372 while (qdio_shutdown(adapter->ccw_device,
2373 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS) {
2374 set_current_state(TASK_UNINTERRUPTIBLE);
2375 schedule_timeout(HZ);
2377 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2379 failed_qdio_establish:
2381 retval = ZFCP_ERP_FAILED;
2388 * function: zfcp_qdio_cleanup
2390 * purpose: cleans up QDIO operation for the specified adapter
2392 * returns: 0 - successful cleanup
2393 * !0 - failed cleanup
2396 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2398 int retval = ZFCP_ERP_SUCCEEDED;
2401 struct zfcp_adapter *adapter = erp_action->adapter;
2403 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2404 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2405 "queues on adapter %s\n",
2406 zfcp_get_busid_by_adapter(adapter));
2407 retval = ZFCP_ERP_FAILED;
2412 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2413 * do_QDIO won't be called while qdio_shutdown is in progress.
2416 write_lock_irq(&adapter->request_queue.queue_lock);
2417 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2418 write_unlock_irq(&adapter->request_queue.queue_lock);
2420 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2421 while (qdio_shutdown(adapter->ccw_device,
2422 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS) {
2423 set_current_state(TASK_UNINTERRUPTIBLE);
2424 schedule_timeout(HZ);
2426 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2429 * First we had to stop QDIO operation.
2430 * Now it is safe to take the following actions.
2433 /* Cleanup only necessary when there are unacknowledged buffers */
2434 if (atomic_read(&adapter->request_queue.free_count)
2435 < QDIO_MAX_BUFFERS_PER_Q) {
2436 first_used = (adapter->request_queue.free_index +
2437 atomic_read(&adapter->request_queue.free_count))
2438 % QDIO_MAX_BUFFERS_PER_Q;
2439 used_count = QDIO_MAX_BUFFERS_PER_Q -
2440 atomic_read(&adapter->request_queue.free_count);
2441 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2442 first_used, used_count);
2444 adapter->response_queue.free_index = 0;
2445 atomic_set(&adapter->response_queue.free_count, 0);
2446 adapter->request_queue.free_index = 0;
2447 atomic_set(&adapter->request_queue.free_count, 0);
2448 adapter->request_queue.distance_from_int = 0;
2454 * function: zfcp_fsf_init
2456 * purpose: initializes FSF operation for the specified adapter
2458 * returns: 0 - succesful initialization of FSF operation
2459 * !0 - failed to initialize FSF operation
2462 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2466 /* do 'exchange configuration data' */
2467 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2468 if (retval == ZFCP_ERP_FAILED)
2471 /* start the desired number of Status Reads */
2472 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2484 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2486 int retval = ZFCP_ERP_SUCCEEDED;
2488 struct zfcp_adapter *adapter = erp_action->adapter;
2490 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2491 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2494 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2496 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2497 zfcp_erp_action_to_running(erp_action);
2498 zfcp_erp_timeout_init(erp_action);
2499 if (zfcp_fsf_exchange_config_data(erp_action)) {
2500 retval = ZFCP_ERP_FAILED;
2501 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2502 ZFCP_LOG_INFO("error: initiation of exchange of "
2503 "configuration data failed for "
2505 zfcp_get_busid_by_adapter(adapter));
2508 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2509 ZFCP_LOG_DEBUG("Xchange underway\n");
2513 * Both the normal completion handler as well as the timeout
2514 * handler will do an 'up' when the 'exchange config data'
2515 * request completes or times out. Thus, the signal to go on
2516 * won't be lost utilizing this semaphore.
2517 * Furthermore, this 'adapter_reopen' action is
2518 * guaranteed to be the only action being there (highest action
2519 * which prevents other actions from being created).
2520 * Resulting from that, the wake signal recognized here
2521 * _must_ be the one belonging to the 'exchange config
2524 down(&adapter->erp_ready_sem);
2525 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2526 ZFCP_LOG_INFO("error: exchange of configuration data "
2527 "for adapter %s timed out\n",
2528 zfcp_get_busid_by_adapter(adapter));
2531 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2532 &adapter->status)) {
2533 ZFCP_LOG_DEBUG("host connection still initialising... "
2534 "waiting and retrying...\n");
2535 /* sleep a little bit before retry */
2536 set_current_state(TASK_INTERRUPTIBLE);
2537 schedule_timeout(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP);
2539 } while ((retries--) &&
2540 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2543 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2544 &adapter->status)) {
2545 ZFCP_LOG_INFO("error: exchange of configuration data for "
2546 "adapter %s failed\n",
2547 zfcp_get_busid_by_adapter(adapter));
2548 retval = ZFCP_ERP_FAILED;
2562 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2565 int retval = ZFCP_ERP_SUCCEEDED;
2567 struct zfcp_adapter *adapter = erp_action->adapter;
2570 adapter->status_read_failed = 0;
2571 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2572 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2574 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2575 "notification failed on adapter %s\n",
2576 zfcp_get_busid_by_adapter(adapter));
2577 retval = ZFCP_ERP_FAILED;
2587 * function: zfcp_fsf_cleanup
2589 * purpose: cleanup FSF operation for specified adapter
2591 * returns: 0 - FSF operation successfully cleaned up
2592 * !0 - failed to cleanup FSF operation for this adapter
2595 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2597 int retval = ZFCP_ERP_SUCCEEDED;
2598 struct zfcp_adapter *adapter = erp_action->adapter;
2601 * wake waiting initiators of requests,
2602 * return SCSI commands (with error status),
2603 * clean up all requests (synchronously)
2605 zfcp_fsf_req_dismiss_all(adapter);
2606 /* reset FSF request sequence number */
2607 adapter->fsf_req_seq_no = 0;
2608 /* all ports and units are closed */
2609 zfcp_erp_modify_adapter_status(adapter,
2610 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2618 * purpose: this routine executes the 'Reopen Physical Port' action
2620 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2621 * ZFCP_ERP_SUCCEEDED - action finished successfully
2622 * ZFCP_ERP_FAILED - action finished unsuccessfully
2625 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2627 int retval = ZFCP_ERP_FAILED;
2628 struct zfcp_port *port = erp_action->port;
2629 struct zfcp_adapter *adapter = erp_action->adapter;
2631 switch (erp_action->step) {
2635 * the ULP spec. begs for waiting for oustanding commands
2637 case ZFCP_ERP_STEP_UNINITIALIZED:
2638 zfcp_erp_port_strategy_clearstati(port);
2640 * it would be sufficient to test only the normal open flag
2641 * since the phys. open flag cannot be set if the normal
2642 * open flag is unset - however, this is for readabilty ...
2644 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2645 ZFCP_STATUS_COMMON_OPEN),
2647 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2648 "close physical\n", port->wwpn);
2650 zfcp_erp_port_forced_strategy_close(erp_action);
2652 retval = ZFCP_ERP_FAILED;
2655 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2656 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2658 ZFCP_LOG_DEBUG("close physical failed for port "
2659 "0x%016Lx\n", port->wwpn);
2660 retval = ZFCP_ERP_FAILED;
2662 retval = ZFCP_ERP_SUCCEEDED;
2666 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2667 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2668 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2669 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2677 * purpose: this routine executes the 'Reopen Port' action
2679 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2680 * ZFCP_ERP_SUCCEEDED - action finished successfully
2681 * ZFCP_ERP_FAILED - action finished unsuccessfully
2684 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2686 int retval = ZFCP_ERP_FAILED;
2687 struct zfcp_port *port = erp_action->port;
2688 struct zfcp_adapter *adapter = erp_action->adapter;
2690 switch (erp_action->step) {
2694 * the ULP spec. begs for waiting for oustanding commands
2696 case ZFCP_ERP_STEP_UNINITIALIZED:
2697 zfcp_erp_port_strategy_clearstati(port);
2698 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2699 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2700 "close\n", port->wwpn);
2701 retval = zfcp_erp_port_strategy_close(erp_action);
2703 } /* else it's already closed, open it */
2706 case ZFCP_ERP_STEP_PORT_CLOSING:
2707 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2708 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2710 retval = ZFCP_ERP_FAILED;
2712 } /* else it's closed now, open it */
2715 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2716 retval = ZFCP_ERP_EXIT;
2718 retval = zfcp_erp_port_strategy_open(erp_action);
2721 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2722 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2723 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2724 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2737 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2741 if (atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER,
2742 &erp_action->port->status))
2743 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2745 retval = zfcp_erp_port_strategy_open_common(erp_action);
2757 * FIXME(design): currently only prepared for fabric (nameserver!)
2760 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2763 struct zfcp_adapter *adapter = erp_action->adapter;
2764 struct zfcp_port *port = erp_action->port;
2766 switch (erp_action->step) {
2768 case ZFCP_ERP_STEP_UNINITIALIZED:
2769 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2770 case ZFCP_ERP_STEP_PORT_CLOSING:
2771 if (!(adapter->nameserver_port)) {
2772 retval = zfcp_nameserver_enqueue(adapter);
2774 ZFCP_LOG_NORMAL("error: nameserver port "
2775 "unavailable for adapter %s\n",
2776 zfcp_get_busid_by_adapter(adapter));
2777 retval = ZFCP_ERP_FAILED;
2781 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2782 &adapter->nameserver_port->status)) {
2783 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2784 "nameserver port\n");
2785 /* nameserver port may live again */
2786 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2787 &adapter->nameserver_port->status);
2788 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0) >= 0) {
2789 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_OPEN;
2790 retval = ZFCP_ERP_CONTINUES;
2791 } else retval = ZFCP_ERP_FAILED;
2794 /* else nameserver port is already open, fall through */
2795 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2796 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2797 &adapter->nameserver_port->status)) {
2798 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2799 retval = ZFCP_ERP_FAILED;
2801 ZFCP_LOG_DEBUG("nameserver port is open -> "
2802 "nameserver look-up for port 0x%016Lx\n",
2804 retval = zfcp_erp_port_strategy_open_common_lookup
2809 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2810 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2811 if (atomic_test_mask
2812 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2813 ZFCP_LOG_DEBUG("nameserver look-up failed "
2814 "for port 0x%016Lx "
2815 "(misconfigured WWPN?)\n",
2817 zfcp_erp_port_failed(port);
2818 retval = ZFCP_ERP_EXIT;
2820 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2821 "port 0x%016Lx\n", port->wwpn);
2822 retval = ZFCP_ERP_FAILED;
2825 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2826 "trying open\n", port->wwpn, port->d_id);
2827 retval = zfcp_erp_port_strategy_open_port(erp_action);
2831 case ZFCP_ERP_STEP_PORT_OPENING:
2832 /* D_ID might have changed during open */
2833 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2834 ZFCP_STATUS_PORT_DID_DID),
2836 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2837 retval = ZFCP_ERP_SUCCEEDED;
2839 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2841 retval = ZFCP_ERP_FAILED;
2846 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2848 retval = ZFCP_ERP_FAILED;
2862 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2865 struct zfcp_port *port = erp_action->port;
2867 switch (erp_action->step) {
2869 case ZFCP_ERP_STEP_UNINITIALIZED:
2870 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2871 case ZFCP_ERP_STEP_PORT_CLOSING:
2872 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2873 port->wwpn, port->d_id);
2874 retval = zfcp_erp_port_strategy_open_port(erp_action);
2877 case ZFCP_ERP_STEP_PORT_OPENING:
2878 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2879 ZFCP_LOG_DEBUG("nameserver port is open\n");
2880 retval = ZFCP_ERP_SUCCEEDED;
2882 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2883 retval = ZFCP_ERP_FAILED;
2885 /* this is needed anyway (dont care for retval of wakeup) */
2886 ZFCP_LOG_DEBUG("continue other open port operations\n");
2887 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2891 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2893 retval = ZFCP_ERP_FAILED;
2902 * purpose: makes the erp thread continue with reopen (physical) port
2903 * actions which have been paused until the name server port
2904 * is opened (or failed)
2906 * returns: 0 (a kind of void retval, its not used)
2909 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2913 unsigned long flags;
2914 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2915 struct zfcp_erp_action *erp_action, *tmp;
2917 read_lock_irqsave(&adapter->erp_lock, flags);
2918 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2920 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2921 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2923 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2924 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2925 debug_event(adapter->erp_dbf, 3,
2926 &erp_action->port->wwpn, sizeof (wwn_t));
2927 if (atomic_test_mask(
2928 ZFCP_STATUS_COMMON_ERP_FAILED,
2929 &adapter->nameserver_port->status))
2930 zfcp_erp_port_failed(erp_action->port);
2931 zfcp_erp_action_ready(erp_action);
2934 read_unlock_irqrestore(&adapter->erp_lock, flags);
2944 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2945 * ZFCP_ERP_FAILED - action finished unsuccessfully
2948 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2951 struct zfcp_adapter *adapter = erp_action->adapter;
2952 struct zfcp_port *port = erp_action->port;
2954 zfcp_erp_timeout_init(erp_action);
2955 retval = zfcp_fsf_close_physical_port(erp_action);
2956 if (retval == -ENOMEM) {
2957 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2958 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2959 retval = ZFCP_ERP_NOMEM;
2962 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2964 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2965 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2966 /* could not send 'open', fail */
2967 retval = ZFCP_ERP_FAILED;
2970 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2971 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2972 retval = ZFCP_ERP_CONTINUES;
2985 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2988 struct zfcp_adapter *adapter = port->adapter;
2990 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2991 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2993 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2994 ZFCP_STATUS_COMMON_CLOSING |
2995 ZFCP_STATUS_PORT_DID_DID |
2996 ZFCP_STATUS_PORT_PHYS_CLOSING |
2997 ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
3006 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3007 * ZFCP_ERP_FAILED - action finished unsuccessfully
3010 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
3013 struct zfcp_adapter *adapter = erp_action->adapter;
3014 struct zfcp_port *port = erp_action->port;
3016 zfcp_erp_timeout_init(erp_action);
3017 retval = zfcp_fsf_close_port(erp_action);
3018 if (retval == -ENOMEM) {
3019 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
3020 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3021 retval = ZFCP_ERP_NOMEM;
3024 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
3026 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
3027 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3028 /* could not send 'close', fail */
3029 retval = ZFCP_ERP_FAILED;
3032 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
3033 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3034 retval = ZFCP_ERP_CONTINUES;
3044 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3045 * ZFCP_ERP_FAILED - action finished unsuccessfully
3048 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
3051 struct zfcp_adapter *adapter = erp_action->adapter;
3052 struct zfcp_port *port = erp_action->port;
3054 zfcp_erp_timeout_init(erp_action);
3055 retval = zfcp_fsf_open_port(erp_action);
3056 if (retval == -ENOMEM) {
3057 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
3058 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3059 retval = ZFCP_ERP_NOMEM;
3062 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
3064 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
3065 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3066 /* could not send 'open', fail */
3067 retval = ZFCP_ERP_FAILED;
3070 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
3071 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3072 retval = ZFCP_ERP_CONTINUES;
3082 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3083 * ZFCP_ERP_FAILED - action finished unsuccessfully
3086 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
3089 struct zfcp_adapter *adapter = erp_action->adapter;
3090 struct zfcp_port *port = erp_action->port;
3092 zfcp_erp_timeout_init(erp_action);
3093 retval = zfcp_ns_gid_pn_request(erp_action);
3094 if (retval == -ENOMEM) {
3095 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
3096 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3097 retval = ZFCP_ERP_NOMEM;
3100 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
3102 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
3103 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3104 /* could not send nameserver request, fail */
3105 retval = ZFCP_ERP_FAILED;
3108 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3109 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3110 retval = ZFCP_ERP_CONTINUES;
3118 * purpose: this routine executes the 'Reopen Unit' action
3119 * currently no retries
3121 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3122 * ZFCP_ERP_SUCCEEDED - action finished successfully
3123 * ZFCP_ERP_FAILED - action finished unsuccessfully
3126 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3128 int retval = ZFCP_ERP_FAILED;
3129 struct zfcp_unit *unit = erp_action->unit;
3130 struct zfcp_adapter *adapter = erp_action->adapter;
3132 switch (erp_action->step) {
3136 * the ULP spec. begs for waiting for oustanding commands
3138 case ZFCP_ERP_STEP_UNINITIALIZED:
3139 zfcp_erp_unit_strategy_clearstati(unit);
3140 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3141 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3142 "trying close\n", unit->fcp_lun);
3143 retval = zfcp_erp_unit_strategy_close(erp_action);
3146 /* else it's already closed, fall through */
3147 case ZFCP_ERP_STEP_UNIT_CLOSING:
3148 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3149 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3151 retval = ZFCP_ERP_FAILED;
3153 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3154 retval = ZFCP_ERP_EXIT;
3156 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3157 "trying open\n", unit->fcp_lun);
3159 zfcp_erp_unit_strategy_open(erp_action);
3164 case ZFCP_ERP_STEP_UNIT_OPENING:
3165 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3166 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3168 retval = ZFCP_ERP_SUCCEEDED;
3170 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3172 retval = ZFCP_ERP_FAILED;
3177 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3178 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3179 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3180 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3192 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3195 struct zfcp_adapter *adapter = unit->port->adapter;
3197 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3198 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3200 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3201 ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3211 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3212 * ZFCP_ERP_FAILED - action finished unsuccessfully
3215 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3218 struct zfcp_adapter *adapter = erp_action->adapter;
3219 struct zfcp_unit *unit = erp_action->unit;
3221 zfcp_erp_timeout_init(erp_action);
3222 retval = zfcp_fsf_close_unit(erp_action);
3223 if (retval == -ENOMEM) {
3224 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3225 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3226 sizeof (fcp_lun_t));
3227 retval = ZFCP_ERP_NOMEM;
3230 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3232 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3233 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3234 sizeof (fcp_lun_t));
3235 /* could not send 'close', fail */
3236 retval = ZFCP_ERP_FAILED;
3239 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3240 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3241 retval = ZFCP_ERP_CONTINUES;
3252 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3253 * ZFCP_ERP_FAILED - action finished unsuccessfully
3256 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3259 struct zfcp_adapter *adapter = erp_action->adapter;
3260 struct zfcp_unit *unit = erp_action->unit;
3262 zfcp_erp_timeout_init(erp_action);
3263 retval = zfcp_fsf_open_unit(erp_action);
3264 if (retval == -ENOMEM) {
3265 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3266 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3267 sizeof (fcp_lun_t));
3268 retval = ZFCP_ERP_NOMEM;
3271 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3273 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3274 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3275 sizeof (fcp_lun_t));
3276 /* could not send 'open', fail */
3277 retval = ZFCP_ERP_FAILED;
3280 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3281 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3282 retval = ZFCP_ERP_CONTINUES;
3295 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3297 init_timer(&erp_action->timer);
3298 erp_action->timer.function = zfcp_erp_timeout_handler;
3299 erp_action->timer.data = (unsigned long) erp_action;
3300 /* jiffies will be added in zfcp_fsf_req_send */
3301 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3307 * purpose: enqueue the specified error recovery action, if needed
3312 zfcp_erp_action_enqueue(int action,
3313 struct zfcp_adapter *adapter,
3314 struct zfcp_port *port, struct zfcp_unit *unit)
3317 struct zfcp_erp_action *erp_action = NULL;
3318 int stronger_action = 0;
3322 * We need some rules here which check whether we really need
3323 * this action or whether we should just drop it.
3324 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3325 * 'Reopen Unit' request for an associated unit since we can't
3326 * satisfy this request now. A 'Reopen Port' action will trigger
3327 * 'Reopen Unit' actions when it completes.
3328 * Thus, there are only actions in the queue which can immediately be
3329 * executed. This makes the processing of the action queue more
3333 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3337 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3338 /* check whether we really need this */
3340 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3341 if (atomic_test_mask
3342 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3343 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3344 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3346 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3347 sizeof (fcp_lun_t));
3350 if (!atomic_test_mask
3351 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3353 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3356 if (!atomic_test_mask
3357 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3358 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3361 /* fall through !!! */
3363 case ZFCP_ERP_ACTION_REOPEN_PORT:
3364 if (atomic_test_mask
3365 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3366 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3367 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3371 /* fall through !!! */
3373 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3374 if (atomic_test_mask
3375 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3376 && port->erp_action.action ==
3377 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3378 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3379 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3383 if (!atomic_test_mask
3384 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3386 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3389 if (!atomic_test_mask
3390 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3391 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3394 /* fall through !!! */
3396 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3397 if (atomic_test_mask
3398 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3399 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3405 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3406 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3407 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3408 "on adapter %s (action=%d)\n",
3409 zfcp_get_busid_by_adapter(adapter), action);
3413 /* check whether we need something stronger first */
3414 if (stronger_action) {
3415 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3416 debug_event(adapter->erp_dbf, 4, &stronger_action,
3418 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3419 "erp action %d on adapter %s\n",
3420 stronger_action, action,
3421 zfcp_get_busid_by_adapter(adapter));
3422 action = stronger_action;
3425 /* mark adapter to have some error recovery pending */
3426 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3428 /* setup error recovery action */
3431 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3432 zfcp_unit_get(unit);
3433 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3434 erp_action = &unit->erp_action;
3435 if (!atomic_test_mask
3436 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3437 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3440 case ZFCP_ERP_ACTION_REOPEN_PORT:
3441 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3442 zfcp_port_get(port);
3443 zfcp_erp_action_dismiss_port(port);
3444 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3445 erp_action = &port->erp_action;
3446 if (!atomic_test_mask
3447 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3448 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3451 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3452 zfcp_adapter_get(adapter);
3453 zfcp_erp_action_dismiss_adapter(adapter);
3454 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3455 erp_action = &adapter->erp_action;
3456 if (!atomic_test_mask
3457 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3458 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3462 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3464 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3465 erp_action->adapter = adapter;
3466 erp_action->port = port;
3467 erp_action->unit = unit;
3468 erp_action->action = action;
3469 erp_action->status = status;
3471 ++adapter->erp_total_count;
3473 /* finally put it into 'ready' queue and kick erp thread */
3474 list_add(&erp_action->list, &adapter->erp_ready_head);
3475 up(&adapter->erp_ready_sem);
3489 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3492 struct zfcp_adapter *adapter = erp_action->adapter;
3494 --adapter->erp_total_count;
3495 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3496 --adapter->erp_low_mem_count;
3497 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3500 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3501 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3502 list_del(&erp_action->list);
3503 switch (erp_action->action) {
3504 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3505 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3506 &erp_action->unit->status);
3508 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3509 case ZFCP_ERP_ACTION_REOPEN_PORT:
3510 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3511 &erp_action->port->status);
3513 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3514 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3515 &erp_action->adapter->status);
3525 * zfcp_erp_action_cleanup
3527 * registers unit with scsi stack if appropiate and fixes reference counts
3531 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3532 struct zfcp_port *port, struct zfcp_unit *unit,
3535 if ((action == ZFCP_ERP_ACTION_REOPEN_UNIT)
3536 && (result == ZFCP_ERP_SUCCEEDED)
3537 && (!unit->device)) {
3538 zfcp_erp_schedule_work(unit);
3541 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3542 zfcp_unit_put(unit);
3544 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3545 case ZFCP_ERP_ACTION_REOPEN_PORT:
3546 zfcp_port_put(port);
3548 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3549 zfcp_adapter_put(adapter);
3565 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3568 struct zfcp_port *port;
3570 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3571 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3572 zfcp_erp_action_dismiss(&adapter->erp_action);
3574 list_for_each_entry(port, &adapter->port_list_head, list)
3575 zfcp_erp_action_dismiss_port(port);
3588 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3591 struct zfcp_unit *unit;
3592 struct zfcp_adapter *adapter = port->adapter;
3594 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3595 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3596 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3597 zfcp_erp_action_dismiss(&port->erp_action);
3599 list_for_each_entry(unit, &port->unit_list_head, list)
3600 zfcp_erp_action_dismiss_unit(unit);
3613 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3616 struct zfcp_adapter *adapter = unit->port->adapter;
3618 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3619 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3620 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3621 zfcp_erp_action_dismiss(&unit->erp_action);
3629 * purpose: moves erp_action to 'erp running list'
3634 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3636 struct zfcp_adapter *adapter = erp_action->adapter;
3638 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3639 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3640 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3646 * purpose: moves erp_action to 'erp ready list'
3651 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3653 struct zfcp_adapter *adapter = erp_action->adapter;
3655 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3656 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3657 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3660 #undef ZFCP_LOG_AREA