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.51 $"
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 *);
130 * function: zfcp_erp_adapter_shutdown_all
132 * purpose: recursively calls zfcp_erp_adapter_shutdown to stop all
133 * IO on each adapter, return all outstanding packets and
134 * relinquish all IRQs
135 * Note: This function waits for completion of all shutdowns
137 * returns: 0 in all cases
140 zfcp_erp_adapter_shutdown_all(void)
144 struct zfcp_adapter *adapter;
146 read_lock_irqsave(&zfcp_data.config_lock, flags);
147 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
148 zfcp_erp_adapter_shutdown(adapter, 0);
149 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
152 * FIXME : need to take config_lock but cannot, since we schedule here.
154 /* start all shutdowns first before any waiting to allow for concurreny */
155 list_for_each_entry(adapter, &zfcp_data.adapter_list_head, list)
156 zfcp_erp_wait(adapter);
162 * function: zfcp_fsf_scsi_er_timeout_handler
164 * purpose: This function needs to be called whenever a SCSI error recovery
165 * action (abort/reset) does not return.
166 * Re-opening the adapter means that the command can be returned
167 * by zfcp (it is guarranteed that it does not return via the
168 * adapter anymore). The buffer can then be used again.
173 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
175 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
177 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
178 "Restarting all operations on the adapter %s\n",
179 zfcp_get_busid_by_adapter(adapter));
180 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
181 zfcp_erp_adapter_reopen(adapter, 0);
189 * purpose: called if an adapter failed,
190 * initiates adapter recovery which is done
193 * returns: 0 - initiated action succesfully
194 * <0 - failed to initiate action
197 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
201 debug_text_event(adapter->erp_dbf, 5, "a_ro");
202 ZFCP_LOG_DEBUG("reopen adapter %s\n",
203 zfcp_get_busid_by_adapter(adapter));
205 zfcp_erp_adapter_block(adapter, clear_mask);
207 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
208 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
209 zfcp_get_busid_by_adapter(adapter));
210 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
211 /* ensure propagation of failed status to new devices */
212 zfcp_erp_adapter_failed(adapter);
216 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
217 adapter, NULL, NULL);
226 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
227 * used to ensure the correct locking
229 * returns: 0 - initiated action succesfully
230 * <0 - failed to initiate action
233 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
238 read_lock_irqsave(&zfcp_data.config_lock, flags);
239 write_lock(&adapter->erp_lock);
240 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
241 write_unlock(&adapter->erp_lock);
242 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
255 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
259 retval = zfcp_erp_adapter_reopen(adapter,
260 ZFCP_STATUS_COMMON_RUNNING |
261 ZFCP_STATUS_COMMON_ERP_FAILED |
275 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
279 retval = zfcp_erp_port_reopen(port,
280 ZFCP_STATUS_COMMON_RUNNING |
281 ZFCP_STATUS_COMMON_ERP_FAILED |
295 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
299 retval = zfcp_erp_unit_reopen(unit,
300 ZFCP_STATUS_COMMON_RUNNING |
301 ZFCP_STATUS_COMMON_ERP_FAILED |
311 * purpose: Originator of the ELS commands
313 * returns: 0 - Operation completed successfuly
314 * -EINVAL - Unknown IOCTL command or invalid sense data record
315 * -ENOMEM - Insufficient memory
316 * -EPERM - Cannot create or queue FSF request
319 zfcp_els(struct zfcp_port *port, u8 ls_code)
321 struct zfcp_send_els *send_els;
322 struct zfcp_ls_rls *rls;
323 struct zfcp_ls_pdisc *pdisc;
324 struct zfcp_ls_adisc *adisc;
325 struct page *page = NULL;
329 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
330 if (send_els == NULL)
333 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
334 if (send_els->req == NULL)
336 send_els->req_count = 1;
338 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
339 if (send_els->resp == NULL)
341 send_els->resp_count = 1;
343 page = alloc_pages(GFP_ATOMIC, 0);
346 send_els->req->page = page;
347 send_els->resp->page = page;
348 send_els->req->offset = 0;
349 send_els->resp->offset = PAGE_SIZE >> 1;
351 send_els->port = port;
352 send_els->ls_code = ls_code;
353 send_els->handler = zfcp_els_handler;
354 send_els->handler_data = (unsigned long)send_els;
355 send_els->completion = NULL;
357 req = zfcp_sg_to_address(send_els->req);
365 send_els->req->length = sizeof(struct zfcp_ls_rtv);
366 send_els->resp->length = sizeof(struct zfcp_ls_rtv_acc);
367 ZFCP_LOG_INFO("RTV request from s_id 0x%08x to d_id 0x%08x\n",
368 port->adapter->s_id, port->d_id);
372 send_els->req->length = sizeof(struct zfcp_ls_rls);
373 send_els->resp->length = sizeof(struct zfcp_ls_rls_acc);
374 rls = (struct zfcp_ls_rls*)req;
375 rls->port_id = port->adapter->s_id;
376 ZFCP_LOG_INFO("RLS request from s_id 0x%08x to d_id 0x%08x "
377 "(port_id=0x%08x)\n",
378 port->adapter->s_id, port->d_id, rls->port_id);
382 send_els->req->length = sizeof(struct zfcp_ls_pdisc);
383 send_els->resp->length = sizeof(struct zfcp_ls_pdisc_acc);
384 pdisc = (struct zfcp_ls_pdisc*)req;
385 pdisc->wwpn = port->adapter->wwpn;
386 pdisc->wwnn = port->adapter->wwnn;
387 ZFCP_LOG_INFO("PDISC request from s_id 0x%08x to d_id 0x%08x "
388 "(wwpn=0x%016Lx, wwnn=0x%016Lx)\n",
389 port->adapter->s_id, port->d_id,
390 pdisc->wwpn, pdisc->wwnn);
394 send_els->req->length = sizeof(struct zfcp_ls_adisc);
395 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
396 adisc = (struct zfcp_ls_adisc*)req;
397 adisc->hard_nport_id = port->adapter->s_id;
398 adisc->wwpn = port->adapter->wwpn;
399 adisc->wwnn = port->adapter->wwnn;
400 adisc->nport_id = port->adapter->s_id;
401 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
402 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
403 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
404 port->adapter->s_id, port->d_id,
405 adisc->wwpn, adisc->wwnn,
406 adisc->hard_nport_id, adisc->nport_id);
410 ZFCP_LOG_NORMAL("ELS command code 0x%02x is not supported\n",
413 goto invalid_ls_code;
416 retval = zfcp_fsf_send_els(send_els);
418 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
419 "0x%016Lx on adapter %s\n",
420 port->wwpn, zfcp_get_busid_by_port(port));
427 ZFCP_LOG_DEBUG("out of memory\n");
432 __free_pages(page, 0);
433 if (send_els != NULL) {
434 if (send_els->req != NULL)
435 kfree(send_els->req);
436 if (send_els->resp != NULL)
437 kfree(send_els->resp);
447 * function: zfcp_els_handler
449 * purpose: Handler for all kind of ELSs
451 * returns: 0 - Operation completed successfuly
452 * -ENXIO - ELS has been rejected
453 * -EPERM - Port forced reopen failed
456 zfcp_els_handler(unsigned long data)
458 struct zfcp_send_els *send_els = (struct zfcp_send_els*)data;
459 struct zfcp_port *port = send_els->port;
460 struct zfcp_ls_rjt *rjt;
461 struct zfcp_ls_rtv_acc *rtv;
462 struct zfcp_ls_rls_acc *rls;
463 struct zfcp_ls_pdisc_acc *pdisc;
464 struct zfcp_ls_adisc_acc *adisc;
466 u8 req_code, resp_code;
469 if (send_els->status != 0)
472 req = (void*)((page_to_pfn(send_els->req->page) << PAGE_SHIFT) + send_els->req->offset);
473 resp = (void*)((page_to_pfn(send_els->resp->page) << PAGE_SHIFT) + send_els->resp->offset);
474 req_code = *(u8*)req;
475 resp_code = *(u8*)resp;
480 rjt = (struct zfcp_ls_rjt*)resp;
482 switch (rjt->reason_code) {
484 case ZFCP_LS_RJT_INVALID_COMMAND_CODE:
485 ZFCP_LOG_INFO("invalid LS command code "
486 "(wwpn=0x%016Lx, command=0x%02x)\n",
487 port->wwpn, req_code);
490 case ZFCP_LS_RJT_LOGICAL_ERROR:
491 ZFCP_LOG_INFO("logical error (wwpn=0x%016Lx, "
492 "reason_expl=0x%02x)\n",
493 port->wwpn, rjt->reason_expl);
496 case ZFCP_LS_RJT_LOGICAL_BUSY:
497 ZFCP_LOG_INFO("logical busy (wwpn=0x%016Lx, "
498 "reason_expl=0x%02x)\n",
499 port->wwpn, rjt->reason_expl);
502 case ZFCP_LS_RJT_PROTOCOL_ERROR:
503 ZFCP_LOG_INFO("protocol error (wwpn=0x%016Lx, "
504 "reason_expl=0x%02x)\n",
505 port->wwpn, rjt->reason_expl);
508 case ZFCP_LS_RJT_UNABLE_TO_PERFORM:
509 ZFCP_LOG_INFO("unable to perform command requested "
510 "(wwpn=0x%016Lx, reason_expl=0x%02x)\n",
511 port->wwpn, rjt->reason_expl);
514 case ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED:
515 ZFCP_LOG_INFO("command not supported (wwpn=0x%016Lx, "
517 port->wwpn, req_code);
520 case ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR:
521 ZFCP_LOG_INFO("vendor specific error (wwpn=0x%016Lx, "
522 "vendor_unique=0x%02x)\n",
523 port->wwpn, rjt->vendor_unique);
527 ZFCP_LOG_NORMAL("ELS rejected by remote port 0x%016Lx "
528 "on adapter %s (reason_code=0x%02x)\n",
530 zfcp_get_busid_by_port(port),
540 rtv = (struct zfcp_ls_rtv_acc*)resp;
541 ZFCP_LOG_INFO("RTV response from d_id 0x%08x to s_id "
542 "0x%08x (R_A_TOV=%ds E_D_TOV=%d%cs)\n",
543 port->d_id, port->adapter->s_id,
544 rtv->r_a_tov, rtv->e_d_tov,
546 ZFCP_LS_RTV_E_D_TOV_FLAG ? 'n' : 'm');
550 rls = (struct zfcp_ls_rls_acc*)resp;
551 ZFCP_LOG_INFO("RLS response from d_id 0x%08x to s_id "
552 "0x%08x (link_failure_count=%u, "
553 "loss_of_sync_count=%u, "
554 "loss_of_signal_count=%u, "
555 "primitive_sequence_protocol_error=%u, "
556 "invalid_transmition_word=%u, "
557 "invalid_crc_count=%u)\n",
558 port->d_id, port->adapter->s_id,
559 rls->link_failure_count,
560 rls->loss_of_sync_count,
561 rls->loss_of_signal_count,
562 rls->prim_seq_prot_error,
563 rls->invalid_transmition_word,
564 rls->invalid_crc_count);
568 pdisc = (struct zfcp_ls_pdisc_acc*)resp;
569 ZFCP_LOG_INFO("PDISC response from d_id 0x%08x to s_id "
570 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
571 "vendor='%-16s')\n", port->d_id,
572 port->adapter->s_id, pdisc->wwpn,
573 pdisc->wwnn, pdisc->vendor_version);
577 adisc = (struct zfcp_ls_adisc_acc*)resp;
578 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
579 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
580 "hard_nport_id=0x%08x, "
581 "nport_id=0x%08x)\n", port->d_id,
582 port->adapter->s_id, adisc->wwpn,
583 adisc->wwnn, adisc->hard_nport_id,
585 /* FIXME: set wwnn in during open port */
587 port->wwnn = adisc->wwnn;
593 ZFCP_LOG_NORMAL("unknown payload code 0x%02x received for "
594 "request 0x%02x to d_id 0x%08x, reopen needed "
595 "for port 0x%016Lx on adapter %s\n", resp_code,
596 req_code, port->d_id, port->wwpn,
597 zfcp_get_busid_by_port(port));
598 retval = zfcp_erp_port_forced_reopen(port, 0);
600 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx on "
601 "adapter %s failed\n", port->wwpn,
602 zfcp_get_busid_by_port(port));
608 __free_pages(send_els->req->page, 0);
609 kfree(send_els->req);
610 kfree(send_els->resp);
617 * function: zfcp_test_link
619 * purpose: Test a status of a link to a remote port using the ELS command ADISC
621 * returns: 0 - Link is OK
622 * -EPERM - Port forced reopen failed
625 zfcp_test_link(struct zfcp_port *port)
629 retval = zfcp_els(port, ZFCP_LS_ADISC);
631 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
632 "on adapter %s\n ", port->wwpn,
633 zfcp_get_busid_by_port(port));
634 retval = zfcp_erp_port_forced_reopen(port, 0);
636 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
637 "on adapter %s failed\n", port->wwpn,
638 zfcp_get_busid_by_port(port));
650 * purpose: called if a port failed to be opened normally
651 * initiates Forced Reopen recovery which is done
654 * returns: 0 - initiated action succesfully
655 * <0 - failed to initiate action
658 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
661 struct zfcp_adapter *adapter = port->adapter;
663 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
664 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
666 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
667 port->wwpn, zfcp_get_busid_by_port(port));
669 zfcp_erp_port_block(port, clear_mask);
671 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
672 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
673 "on adapter %s\n", port->wwpn,
674 zfcp_get_busid_by_port(port));
675 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
676 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
681 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
682 port->adapter, port, NULL);
691 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
692 * used to ensure the correct locking
694 * returns: 0 - initiated action succesfully
695 * <0 - failed to initiate action
698 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
702 struct zfcp_adapter *adapter;
704 adapter = port->adapter;
705 read_lock_irqsave(&zfcp_data.config_lock, flags);
706 write_lock(&adapter->erp_lock);
707 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
708 write_unlock(&adapter->erp_lock);
709 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
717 * purpose: called if a port is to be opened
718 * initiates Reopen recovery which is done
721 * returns: 0 - initiated action succesfully
722 * <0 - failed to initiate action
725 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
728 struct zfcp_adapter *adapter = port->adapter;
730 debug_text_event(adapter->erp_dbf, 5, "p_ro");
731 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
733 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
734 port->wwpn, zfcp_get_busid_by_port(port));
736 zfcp_erp_port_block(port, clear_mask);
738 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
739 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
740 "on adapter %s\n", port->wwpn,
741 zfcp_get_busid_by_port(port));
742 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
743 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
744 /* ensure propagation of failed status to new devices */
745 zfcp_erp_port_failed(port);
750 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
751 port->adapter, port, NULL);
760 * purpose: Wrappper for zfcp_erp_port_reopen_internal
761 * used to ensure the correct locking
763 * returns: 0 - initiated action succesfully
764 * <0 - failed to initiate action
767 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
771 struct zfcp_adapter *adapter = port->adapter;
773 read_lock_irqsave(&zfcp_data.config_lock, flags);
774 write_lock(&adapter->erp_lock);
775 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
776 write_unlock(&adapter->erp_lock);
777 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
785 * purpose: called if a unit is to be opened
786 * initiates Reopen recovery which is done
789 * returns: 0 - initiated action succesfully
790 * <0 - failed to initiate action
793 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
796 struct zfcp_adapter *adapter = unit->port->adapter;
798 debug_text_event(adapter->erp_dbf, 5, "u_ro");
799 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
800 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
801 "on adapter %s\n", unit->fcp_lun,
802 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
804 zfcp_erp_unit_block(unit, clear_mask);
806 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
807 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
808 "on port 0x%016Lx on adapter %s\n",
809 unit->fcp_lun, unit->port->wwpn,
810 zfcp_get_busid_by_unit(unit));
811 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
812 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
818 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
819 unit->port->adapter, unit->port, unit);
827 * purpose: Wrappper for zfcp_erp_unit_reopen_internal
828 * used to ensure the correct locking
830 * returns: 0 - initiated action succesfully
831 * <0 - failed to initiate action
834 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
838 struct zfcp_adapter *adapter;
839 struct zfcp_port *port;
842 adapter = port->adapter;
844 read_lock_irqsave(&zfcp_data.config_lock, flags);
845 write_lock(&adapter->erp_lock);
846 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
847 write_unlock(&adapter->erp_lock);
848 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
856 * purpose: disable I/O,
857 * return any open requests and clean them up,
858 * aim: no pending and incoming I/O
863 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
865 debug_text_event(adapter->erp_dbf, 6, "a_bl");
866 zfcp_erp_modify_adapter_status(adapter,
867 ZFCP_STATUS_COMMON_UNBLOCKED |
868 clear_mask, ZFCP_CLEAR);
874 * purpose: enable I/O
879 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
881 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
882 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
888 * purpose: disable I/O,
889 * return any open requests and clean them up,
890 * aim: no pending and incoming I/O
895 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
897 struct zfcp_adapter *adapter = port->adapter;
899 debug_text_event(adapter->erp_dbf, 6, "p_bl");
900 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
901 zfcp_erp_modify_port_status(port,
902 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
909 * purpose: enable I/O
914 zfcp_erp_port_unblock(struct zfcp_port *port)
916 struct zfcp_adapter *adapter = port->adapter;
918 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
919 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
920 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
926 * purpose: disable I/O,
927 * return any open requests and clean them up,
928 * aim: no pending and incoming I/O
933 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
935 struct zfcp_adapter *adapter = unit->port->adapter;
937 debug_text_event(adapter->erp_dbf, 6, "u_bl");
938 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
939 zfcp_erp_modify_unit_status(unit,
940 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
947 * purpose: enable I/O
952 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
954 struct zfcp_adapter *adapter = unit->port->adapter;
956 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
957 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
958 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
969 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
971 struct zfcp_adapter *adapter = erp_action->adapter;
973 debug_text_event(adapter->erp_dbf, 4, "a_ar");
974 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
976 zfcp_erp_action_to_ready(erp_action);
977 up(&adapter->erp_ready_sem);
985 * returns: <0 erp_action not found in any list
986 * ZFCP_ERP_ACTION_READY erp_action is in ready list
987 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
989 * locks: erp_lock must be held
992 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
994 int retval = -EINVAL;
995 struct list_head *entry;
996 struct zfcp_erp_action *entry_erp_action;
997 struct zfcp_adapter *adapter = erp_action->adapter;
999 /* search in running list */
1000 list_for_each(entry, &adapter->erp_running_head) {
1002 list_entry(entry, struct zfcp_erp_action, list);
1003 if (entry_erp_action == erp_action) {
1004 retval = ZFCP_ERP_ACTION_RUNNING;
1008 /* search in ready list */
1009 list_for_each(entry, &adapter->erp_ready_head) {
1011 list_entry(entry, struct zfcp_erp_action, list);
1012 if (entry_erp_action == erp_action) {
1013 retval = ZFCP_ERP_ACTION_READY;
1023 * purpose: checks current status of action (timed out, dismissed, ...)
1024 * and does appropriate preparations (dismiss fsf request, ...)
1026 * locks: called under erp_lock (disabled interrupts)
1031 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
1034 struct zfcp_fsf_req *fsf_req;
1035 struct zfcp_adapter *adapter = erp_action->adapter;
1037 if (erp_action->fsf_req) {
1038 /* take lock to ensure that request is not being deleted meanwhile */
1039 write_lock(&adapter->fsf_req_list_lock);
1040 /* check whether fsf req does still exist */
1041 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
1042 if (fsf_req == erp_action->fsf_req)
1044 if (fsf_req == erp_action->fsf_req) {
1045 /* fsf_req still exists */
1046 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
1047 debug_event(adapter->erp_dbf, 3, &fsf_req,
1048 sizeof (unsigned long));
1049 /* dismiss fsf_req of timed out or dismissed erp_action */
1050 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
1051 ZFCP_STATUS_ERP_TIMEDOUT)) {
1052 debug_text_event(adapter->erp_dbf, 3,
1054 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
1056 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1057 ZFCP_LOG_NORMAL("error: erp step timed out "
1058 "(action=%d, fsf_req=%p)\n ",
1060 erp_action->fsf_req);
1063 * If fsf_req is neither dismissed nor completed
1064 * then keep it running asynchronously and don't mess
1065 * with the association of erp_action and fsf_req.
1067 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
1068 ZFCP_STATUS_FSFREQ_DISMISSED)) {
1069 /* forget about association between fsf_req
1071 fsf_req->erp_action = NULL;
1072 erp_action->fsf_req = NULL;
1075 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
1077 * even if this fsf_req has gone, forget about
1078 * association between erp_action and fsf_req
1080 erp_action->fsf_req = NULL;
1082 write_unlock(&adapter->fsf_req_list_lock);
1084 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
1090 * purpose: generic handler for asynchronous events related to erp_action events
1091 * (normal completion, time-out, dismissing, retry after
1092 * low memory condition)
1094 * note: deletion of timer is not required (e.g. in case of a time-out),
1095 * but a second try does no harm,
1096 * we leave it in here to allow for greater simplification
1098 * returns: 0 - there was an action to handle
1102 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
1103 unsigned long set_mask)
1106 struct zfcp_adapter *adapter = erp_action->adapter;
1108 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
1109 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
1110 debug_event(adapter->erp_dbf, 2, &erp_action->action,
1112 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
1113 del_timer_sync(&erp_action->timer);
1114 erp_action->status |= set_mask;
1115 zfcp_erp_action_ready(erp_action);
1118 /* action is ready or gone - nothing to do */
1119 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
1120 debug_event(adapter->erp_dbf, 3, &erp_action->action,
1129 * purpose: generic handler for asynchronous events related to erp_action
1130 * events (normal completion, time-out, dismissing, retry after
1131 * low memory condition)
1133 * note: deletion of timer is not required (e.g. in case of a time-out),
1134 * but a second try does no harm,
1135 * we leave it in here to allow for greater simplification
1137 * returns: 0 - there was an action to handle
1141 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1142 unsigned long set_mask)
1144 struct zfcp_adapter *adapter = erp_action->adapter;
1145 unsigned long flags;
1148 write_lock_irqsave(&adapter->erp_lock, flags);
1149 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1150 write_unlock_irqrestore(&adapter->erp_lock, flags);
1156 * purpose: is called for erp_action which was slept waiting for
1157 * memory becoming avaliable,
1158 * will trigger that this action will be continued
1161 zfcp_erp_memwait_handler(unsigned long data)
1163 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1164 struct zfcp_adapter *adapter = erp_action->adapter;
1166 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1167 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1169 zfcp_erp_async_handler(erp_action, 0);
1173 * purpose: is called if an asynchronous erp step timed out,
1174 * action gets an appropriate flag and will be processed
1178 zfcp_erp_timeout_handler(unsigned long data)
1180 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1181 struct zfcp_adapter *adapter = erp_action->adapter;
1183 debug_text_event(adapter->erp_dbf, 2, "a_th");
1184 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1186 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1190 * purpose: is called for an erp_action which needs to be ended
1191 * though not being done,
1192 * this is usually required if an higher is generated,
1193 * action gets an appropriate flag and will be processed
1196 * locks: erp_lock held (thus we need to call another handler variant)
1199 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1201 struct zfcp_adapter *adapter = erp_action->adapter;
1203 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1204 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1206 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1212 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1216 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1218 rwlock_init(&adapter->erp_lock);
1219 INIT_LIST_HEAD(&adapter->erp_ready_head);
1220 INIT_LIST_HEAD(&adapter->erp_running_head);
1221 sema_init(&adapter->erp_ready_sem, 0);
1223 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1225 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1227 zfcp_get_busid_by_adapter(adapter));
1228 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1230 wait_event(adapter->erp_thread_wqh,
1231 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1233 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1236 return (retval < 0);
1246 * context: process (i.e. proc-fs or rmmod/insmod)
1248 * note: The caller of this routine ensures that the specified
1249 * adapter has been shut down and that this operation
1250 * has been completed. Thus, there are no pending erp_actions
1251 * which would need to be handled here.
1254 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1258 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1259 up(&adapter->erp_ready_sem);
1261 wait_event(adapter->erp_thread_wqh,
1262 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1265 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1268 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1274 * purpose: is run as a kernel thread,
1275 * goes through list of error recovery actions of associated adapter
1276 * and delegates single action to execution
1281 zfcp_erp_thread(void *data)
1283 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1284 struct list_head *next;
1285 struct zfcp_erp_action *erp_action;
1286 unsigned long flags;
1288 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1289 /* Block all signals */
1290 siginitsetinv(¤t->blocked, 0);
1291 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1292 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1293 wake_up(&adapter->erp_thread_wqh);
1295 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1296 &adapter->status)) {
1298 write_lock_irqsave(&adapter->erp_lock, flags);
1299 next = adapter->erp_ready_head.prev;
1300 write_unlock_irqrestore(&adapter->erp_lock, flags);
1302 if (next != &adapter->erp_ready_head) {
1304 list_entry(next, struct zfcp_erp_action, list);
1306 * process action (incl. [re]moving it
1307 * from 'ready' queue)
1309 zfcp_erp_strategy(erp_action);
1313 * sleep as long as there is nothing to do, i.e.
1314 * no action in 'ready' queue to be processed and
1315 * thread is not to be killed
1317 down_interruptible(&adapter->erp_ready_sem);
1318 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1321 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1322 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1323 wake_up(&adapter->erp_thread_wqh);
1331 * purpose: drives single error recovery action and schedules higher and
1332 * subordinate actions, if necessary
1334 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1335 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1336 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1337 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1338 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1341 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1344 struct zfcp_adapter *adapter = erp_action->adapter;
1345 struct zfcp_port *port = erp_action->port;
1346 struct zfcp_unit *unit = erp_action->unit;
1347 int action = erp_action->action;
1348 u32 status = erp_action->status;
1349 unsigned long flags;
1351 /* serialise dismissing, timing out, moving, enqueueing */
1352 read_lock_irqsave(&zfcp_data.config_lock, flags);
1353 write_lock(&adapter->erp_lock);
1355 /* dequeue dismissed action and leave, if required */
1356 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1357 if (retval == ZFCP_ERP_DISMISSED) {
1358 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1363 * move action to 'running' queue before processing it
1364 * (to avoid a race condition regarding moving the
1365 * action to the 'running' queue and back)
1367 zfcp_erp_action_to_running(erp_action);
1370 * try to process action as far as possible,
1371 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1372 * afterwards the lock is required again for the following reasons:
1373 * - dequeueing of finished action and enqueueing of
1374 * follow-up actions must be atomic so that any other
1375 * reopen-routine does not believe there is nothing to do
1376 * and that it is safe to enqueue something else,
1377 * - we want to force any control thread which is dismissing
1378 * actions to finish this before we decide about
1379 * necessary steps to be taken here further
1381 write_unlock(&adapter->erp_lock);
1382 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1383 retval = zfcp_erp_strategy_do_action(erp_action);
1384 read_lock_irqsave(&zfcp_data.config_lock, flags);
1385 write_lock(&adapter->erp_lock);
1388 * check for dismissed status again to avoid follow-up actions,
1389 * failing of targets and so on for dismissed actions
1391 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1394 case ZFCP_ERP_DISMISSED:
1395 /* leave since this action has ridden to its ancestors */
1396 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1398 case ZFCP_ERP_NOMEM:
1399 /* no memory to continue immediately, let it sleep */
1400 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1401 ++adapter->erp_low_mem_count;
1402 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1404 /* This condition is true if there is no memory available
1405 for any erp_action on this adapter. This implies that there
1406 are no elements in the memory pool(s) left for erp_actions.
1407 This might happen if an erp_action that used a memory pool
1408 element was timed out.
1410 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1411 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1412 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1413 "restarting I/O on adapter %s "
1414 "to free mempool\n",
1415 zfcp_get_busid_by_adapter(adapter));
1416 zfcp_erp_adapter_reopen_internal(adapter, 0);
1418 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1419 retval = zfcp_erp_strategy_memwait(erp_action);
1422 case ZFCP_ERP_CONTINUES:
1423 /* leave since this action runs asynchronously */
1424 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1425 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1426 --adapter->erp_low_mem_count;
1427 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1431 /* ok, finished action (whatever its result is) */
1433 /* check for unrecoverable targets */
1434 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1436 /* action must be dequeued (here to allow for further ones) */
1437 zfcp_erp_action_dequeue(erp_action);
1440 * put this target through the erp mill again if someone has
1441 * requested to change the status of a target being online
1442 * to offline or the other way around
1443 * (old retval is preserved if nothing has to be done here)
1445 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1446 port, unit, retval);
1449 * leave if target is in permanent error state or if
1450 * action is repeated in order to process state change
1452 if (retval == ZFCP_ERP_EXIT) {
1453 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1457 /* trigger follow up actions */
1458 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1461 write_unlock(&adapter->erp_lock);
1462 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1464 if (retval != ZFCP_ERP_CONTINUES)
1465 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1468 * a few tasks remain when the erp queues are empty
1469 * (don't do that if the last action evaluated was dismissed
1470 * since this clearly indicates that there is more to come) :
1471 * - close the name server port if it is open yet
1472 * (enqueues another [probably] final action)
1473 * - otherwise, wake up whoever wants to be woken when we are
1476 if (retval != ZFCP_ERP_DISMISSED)
1477 zfcp_erp_strategy_check_queues(adapter);
1479 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1489 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1490 * retval - otherwise
1493 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1495 struct zfcp_adapter *adapter = erp_action->adapter;
1497 zfcp_erp_strategy_check_fsfreq(erp_action);
1499 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1500 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1501 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1502 zfcp_erp_action_dequeue(erp_action);
1503 retval = ZFCP_ERP_DISMISSED;
1505 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1518 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1520 int retval = ZFCP_ERP_FAILED;
1521 struct zfcp_adapter *adapter = erp_action->adapter;
1524 * try to execute/continue action as far as possible,
1525 * note: no lock in subsequent strategy routines
1526 * (this allows these routine to call schedule, e.g.
1527 * kmalloc with such flags or qdio_initialize & friends)
1528 * Note: in case of timeout, the seperate strategies will fail
1529 * anyhow. No need for a special action. Even worse, a nameserver
1530 * failure would not wake up waiting ports without the call.
1532 switch (erp_action->action) {
1534 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1535 retval = zfcp_erp_adapter_strategy(erp_action);
1538 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1539 retval = zfcp_erp_port_forced_strategy(erp_action);
1542 case ZFCP_ERP_ACTION_REOPEN_PORT:
1543 retval = zfcp_erp_port_strategy(erp_action);
1546 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1547 retval = zfcp_erp_unit_strategy(erp_action);
1551 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1552 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1554 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1555 "adapter %s (action=%d)\n",
1556 zfcp_get_busid_by_adapter(erp_action->adapter),
1557 erp_action->action);
1566 * purpose: triggers retry of this action after a certain amount of time
1567 * by means of timer provided by erp_action
1569 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1572 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1574 int retval = ZFCP_ERP_CONTINUES;
1575 struct zfcp_adapter *adapter = erp_action->adapter;
1577 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1578 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1579 init_timer(&erp_action->timer);
1580 erp_action->timer.function = zfcp_erp_memwait_handler;
1581 erp_action->timer.data = (unsigned long) erp_action;
1582 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1583 add_timer(&erp_action->timer);
1589 * function: zfcp_erp_adapter_failed
1591 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1595 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1597 zfcp_erp_modify_adapter_status(adapter,
1598 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1599 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1600 zfcp_get_busid_by_adapter(adapter));
1601 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1605 * function: zfcp_erp_port_failed
1607 * purpose: sets the port and all underlying devices to ERP_FAILED
1611 zfcp_erp_port_failed(struct zfcp_port *port)
1613 zfcp_erp_modify_port_status(port,
1614 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1616 ZFCP_LOG_NORMAL("port erp failed on port 0x%016Lx on adapter %s\n",
1617 port->wwpn, zfcp_get_busid_by_port(port));
1618 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1619 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1623 * function: zfcp_erp_unit_failed
1625 * purpose: sets the unit to ERP_FAILED
1629 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1631 zfcp_erp_modify_unit_status(unit,
1632 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1634 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1635 " on adapter %s\n", unit->fcp_lun,
1636 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1637 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1638 debug_event(unit->port->adapter->erp_dbf, 2,
1639 &unit->fcp_lun, sizeof (fcp_lun_t));
1643 * function: zfcp_erp_strategy_check_target
1645 * purpose: increments the erp action count on the device currently in
1646 * recovery if the action failed or resets the count in case of
1647 * success. If a maximum count is exceeded the device is marked
1649 * The 'blocked' state of a target which has been recovered
1650 * successfully is reset.
1652 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1653 * ZFCP_ERP_SUCCEEDED - action finished successfully
1654 * ZFCP_ERP_EXIT - action failed and will not continue
1657 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1659 struct zfcp_adapter *adapter = erp_action->adapter;
1660 struct zfcp_port *port = erp_action->port;
1661 struct zfcp_unit *unit = erp_action->unit;
1663 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1664 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1665 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1667 switch (erp_action->action) {
1669 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1670 result = zfcp_erp_strategy_check_unit(unit, result);
1673 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1674 case ZFCP_ERP_ACTION_REOPEN_PORT:
1675 result = zfcp_erp_strategy_check_port(port, result);
1678 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1679 result = zfcp_erp_strategy_check_adapter(adapter, result);
1694 zfcp_erp_strategy_statechange(int action,
1696 struct zfcp_adapter *adapter,
1697 struct zfcp_port *port,
1698 struct zfcp_unit *unit, int retval)
1700 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1701 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1705 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1706 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1708 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1709 retval = ZFCP_ERP_EXIT;
1713 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1714 case ZFCP_ERP_ACTION_REOPEN_PORT:
1715 if (zfcp_erp_strategy_statechange_detected(&port->status,
1717 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1718 retval = ZFCP_ERP_EXIT;
1722 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1723 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1725 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1726 retval = ZFCP_ERP_EXIT;
1742 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1745 /* take it online */
1746 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1747 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1748 /* take it offline */
1749 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1750 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1754 * zfcp_erp_scsi_add_device
1755 * @data: pointer to a struct zfcp_unit
1757 * Registers a logical unit with the SCSI stack.
1760 zfcp_erp_scsi_add_device(void *data)
1763 struct zfcp_unit *unit;
1764 struct work_struct work;
1768 scsi_add_device(p->unit->port->adapter->scsi_host,
1769 0, p->unit->port->scsi_id, p->unit->scsi_lun);
1770 atomic_set(&p->unit->scsi_add_work, 0);
1771 wake_up(&p->unit->scsi_add_wq);
1772 zfcp_unit_put(p->unit);
1777 * zfcp_erp_schedule_work
1778 * @unit: pointer to unit which should be registered with SCSI stack
1780 * Schedules work which registers a unit with the SCSI stack
1783 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1786 struct zfcp_unit * unit;
1787 struct work_struct work;
1790 if (atomic_compare_and_swap(0, 1, &unit->scsi_add_work))
1793 if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
1794 ZFCP_LOG_NORMAL("error: registration at SCSI stack failed for "
1795 "unit 0x%016Lx on port 0x%016Lx on "
1796 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
1797 zfcp_get_busid_by_unit(unit));
1798 atomic_set(&unit->scsi_add_work, 0);
1802 zfcp_unit_get(unit);
1803 memset(p, 0, sizeof(*p));
1804 INIT_WORK(&p->work, zfcp_erp_scsi_add_device, p);
1806 schedule_work(&p->work);
1818 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1820 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1821 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1822 sizeof (fcp_lun_t));
1825 case ZFCP_ERP_SUCCEEDED :
1826 atomic_set(&unit->erp_counter, 0);
1827 zfcp_erp_unit_unblock(unit);
1829 case ZFCP_ERP_FAILED :
1830 atomic_inc(&unit->erp_counter);
1831 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1832 zfcp_erp_unit_failed(unit);
1834 case ZFCP_ERP_EXIT :
1839 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1840 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1841 result = ZFCP_ERP_EXIT;
1855 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1857 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1858 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1861 case ZFCP_ERP_SUCCEEDED :
1862 atomic_set(&port->erp_counter, 0);
1863 zfcp_erp_port_unblock(port);
1865 case ZFCP_ERP_FAILED :
1866 atomic_inc(&port->erp_counter);
1867 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1868 zfcp_erp_port_failed(port);
1870 case ZFCP_ERP_EXIT :
1875 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1876 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1877 result = ZFCP_ERP_EXIT;
1891 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1893 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1896 case ZFCP_ERP_SUCCEEDED :
1897 atomic_set(&adapter->erp_counter, 0);
1898 zfcp_erp_adapter_unblock(adapter);
1900 case ZFCP_ERP_FAILED :
1901 atomic_inc(&adapter->erp_counter);
1902 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1903 zfcp_erp_adapter_failed(adapter);
1905 case ZFCP_ERP_EXIT :
1910 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1911 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1912 result = ZFCP_ERP_EXIT;
1921 * purpose: remaining things in good cases,
1922 * escalation in bad cases
1927 zfcp_erp_strategy_followup_actions(int action,
1928 struct zfcp_adapter *adapter,
1929 struct zfcp_port *port,
1930 struct zfcp_unit *unit, int status)
1932 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1933 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1935 /* initiate follow-up actions depending on success of finished action */
1938 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1939 if (status == ZFCP_ERP_SUCCEEDED)
1940 zfcp_erp_port_reopen_all_internal(adapter, 0);
1942 zfcp_erp_adapter_reopen_internal(adapter, 0);
1945 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1946 if (status == ZFCP_ERP_SUCCEEDED)
1947 zfcp_erp_port_reopen_internal(port, 0);
1949 zfcp_erp_adapter_reopen_internal(adapter, 0);
1952 case ZFCP_ERP_ACTION_REOPEN_PORT:
1953 if (status == ZFCP_ERP_SUCCEEDED)
1954 zfcp_erp_unit_reopen_all_internal(port, 0);
1956 zfcp_erp_port_forced_reopen_internal(port, 0);
1959 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1960 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1962 zfcp_erp_port_reopen_internal(unit->port, 0);
1977 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1980 unsigned long flags;
1981 struct zfcp_port *nport = adapter->nameserver_port;
1983 read_lock_irqsave(&zfcp_data.config_lock, flags);
1984 read_lock(&adapter->erp_lock);
1985 if (list_empty(&adapter->erp_ready_head) &&
1986 list_empty(&adapter->erp_running_head)) {
1988 && atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
1990 debug_text_event(adapter->erp_dbf, 4, "a_cq_nspsd");
1991 /* taking down nameserver port */
1992 zfcp_erp_port_reopen_internal(nport,
1993 ZFCP_STATUS_COMMON_RUNNING |
1994 ZFCP_STATUS_COMMON_ERP_FAILED);
1996 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1997 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1999 wake_up(&adapter->erp_done_wqh);
2002 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
2003 read_unlock(&adapter->erp_lock);
2004 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2017 zfcp_erp_wait(struct zfcp_adapter *adapter)
2021 wait_event(adapter->erp_done_wqh,
2022 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
2029 * function: zfcp_erp_modify_adapter_status
2035 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
2036 u32 mask, int set_or_clear)
2038 struct zfcp_port *port;
2039 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2041 if (set_or_clear == ZFCP_SET) {
2042 atomic_set_mask(mask, &adapter->status);
2043 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
2045 atomic_clear_mask(mask, &adapter->status);
2046 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2047 atomic_set(&adapter->erp_counter, 0);
2048 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
2050 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
2052 /* Deal with all underlying devices, only pass common_mask */
2054 list_for_each_entry(port, &adapter->port_list_head, list)
2055 zfcp_erp_modify_port_status(port, common_mask,
2060 * function: zfcp_erp_modify_port_status
2062 * purpose: sets the port and all underlying devices to ERP_FAILED
2066 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
2068 struct zfcp_unit *unit;
2069 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2071 if (set_or_clear == ZFCP_SET) {
2072 atomic_set_mask(mask, &port->status);
2073 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
2075 atomic_clear_mask(mask, &port->status);
2076 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2077 atomic_set(&port->erp_counter, 0);
2078 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
2080 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2081 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2083 /* Modify status of all underlying devices, only pass common mask */
2085 list_for_each_entry(unit, &port->unit_list_head, list)
2086 zfcp_erp_modify_unit_status(unit, common_mask,
2091 * function: zfcp_erp_modify_unit_status
2093 * purpose: sets the unit to ERP_FAILED
2097 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
2099 if (set_or_clear == ZFCP_SET) {
2100 atomic_set_mask(mask, &unit->status);
2101 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
2103 atomic_clear_mask(mask, &unit->status);
2104 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
2105 atomic_set(&unit->erp_counter, 0);
2107 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
2109 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
2110 sizeof (fcp_lun_t));
2111 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2117 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
2118 * used to ensure the correct locking
2120 * returns: 0 - initiated action succesfully
2121 * <0 - failed to initiate action
2124 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
2127 unsigned long flags;
2129 read_lock_irqsave(&zfcp_data.config_lock, flags);
2130 write_lock(&adapter->erp_lock);
2131 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
2132 write_unlock(&adapter->erp_lock);
2133 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2146 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
2149 struct zfcp_port *port;
2151 list_for_each_entry(port, &adapter->port_list_head, list)
2152 if (!atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER, &port->status))
2153 zfcp_erp_port_reopen_internal(port, clear_mask);
2166 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
2169 struct zfcp_unit *unit;
2171 list_for_each_entry(unit, &port->unit_list_head, list)
2172 zfcp_erp_unit_reopen_internal(unit, clear_mask);
2180 * purpose: this routine executes the 'Reopen Adapter' action
2181 * (the entire action is processed synchronously, since
2182 * there are no actions which might be run concurrently
2185 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2186 * ZFCP_ERP_FAILED - action finished unsuccessfully
2189 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
2192 unsigned long timeout;
2193 struct zfcp_adapter *adapter = erp_action->adapter;
2195 retval = zfcp_erp_adapter_strategy_close(erp_action);
2196 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2197 retval = ZFCP_ERP_EXIT;
2199 retval = zfcp_erp_adapter_strategy_open(erp_action);
2201 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
2202 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2203 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2205 if (retval == ZFCP_ERP_FAILED) {
2206 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2207 "to recover itself\n",
2208 zfcp_get_busid_by_adapter(adapter));
2210 * SUGGESTION: substitute by
2211 * timeout = ZFCP_TYPE2_RECOVERY_TIME;
2212 * __ZFCP_WAIT_EVENT_TIMEOUT(timeout, 0);
2214 timeout = ZFCP_TYPE2_RECOVERY_TIME;
2215 set_current_state(TASK_UNINTERRUPTIBLE);
2216 schedule_timeout(timeout);
2227 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2228 * ZFCP_ERP_FAILED - action finished unsuccessfully
2231 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2235 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2236 &erp_action->adapter->status);
2237 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2238 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2239 &erp_action->adapter->status);
2249 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2250 * ZFCP_ERP_FAILED - action finished unsuccessfully
2253 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2257 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2258 &erp_action->adapter->status);
2259 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2260 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2261 &erp_action->adapter->status);
2267 * function: zfcp_register_adapter
2269 * purpose: allocate the irq associated with this devno and register
2270 * the FSF adapter with the SCSI stack
2275 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2277 int retval = ZFCP_ERP_SUCCEEDED;
2282 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2283 if (retval != ZFCP_ERP_SUCCEEDED)
2286 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2287 if (retval != ZFCP_ERP_SUCCEEDED)
2288 goto failed_openfcp;
2290 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2294 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2295 &erp_action->adapter->status);
2298 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2299 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2306 * function: zfcp_qdio_init
2308 * purpose: setup QDIO operation for specified adapter
2310 * returns: 0 - successful setup
2314 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2318 volatile struct qdio_buffer_element *sbale;
2319 struct zfcp_adapter *adapter = erp_action->adapter;
2320 int retval_cleanup = 0;
2322 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2323 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2325 zfcp_get_busid_by_adapter(adapter));
2329 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2330 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2332 zfcp_get_busid_by_adapter(adapter));
2333 goto failed_qdio_establish;
2335 ZFCP_LOG_DEBUG("queues established\n");
2337 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2338 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2340 zfcp_get_busid_by_adapter(adapter));
2341 goto failed_qdio_activate;
2343 ZFCP_LOG_DEBUG("queues activated\n");
2346 * put buffers into response queue,
2348 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2349 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2351 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2355 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2356 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2357 zfcp_get_busid_by_adapter(adapter),
2358 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2360 retval = do_QDIO(adapter->ccw_device,
2361 QDIO_FLAG_SYNC_INPUT,
2362 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2365 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2367 goto failed_do_qdio;
2369 adapter->response_queue.free_index = 0;
2370 atomic_set(&adapter->response_queue.free_count, 0);
2371 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2372 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2374 /* set index of first avalable SBALS / number of available SBALS */
2375 adapter->request_queue.free_index = 0;
2376 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2377 adapter->request_queue.distance_from_int = 0;
2379 /* initialize waitqueue used to wait for free SBALs in requests queue */
2380 init_waitqueue_head(&adapter->request_wq);
2382 /* ok, we did it - skip all cleanups for different failures */
2383 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2384 retval = ZFCP_ERP_SUCCEEDED;
2390 failed_qdio_activate:
2392 //__ZFCP_WAIT_EVENT_TIMEOUT(timeout, 0);
2393 /* cleanup queues previously established */
2394 retval_cleanup = qdio_shutdown(adapter->ccw_device,
2395 QDIO_FLAG_CLEANUP_USING_CLEAR);
2396 if (retval_cleanup) {
2397 ZFCP_LOG_NORMAL("bug: shutdown of QDIO queues failed "
2398 "(retval=%d)\n", retval_cleanup);
2401 failed_qdio_establish:
2402 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2405 retval = ZFCP_ERP_FAILED;
2412 * function: zfcp_qdio_cleanup
2414 * purpose: cleans up QDIO operation for the specified adapter
2416 * returns: 0 - successful cleanup
2417 * !0 - failed cleanup
2420 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2422 int retval = ZFCP_ERP_SUCCEEDED;
2425 struct zfcp_adapter *adapter = erp_action->adapter;
2427 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2428 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2429 "queues on adapter %s\n",
2430 zfcp_get_busid_by_adapter(adapter));
2431 retval = ZFCP_ERP_FAILED;
2435 /* cleanup queues previously established */
2438 * MUST NOT LOCK - qdio_cleanup might call schedule
2439 * FIXME: need another way to make cleanup safe
2442 * We need the request_queue lock here, otherwise there exists the
2445 * queuecommand calls create_fcp_commmand_task...calls req_create,
2446 * gets sbal x to x+y - meanwhile adapter reopen is called, completes
2447 * - req_send calls do_QDIO for sbal x to x+y, i.e. wrong indices.
2450 * queuecommand calls create_fcp_commmand_task...calls req_create,
2451 * gets sbal x to x+y - meanwhile adapter reopen is called, waits
2452 * - req_send calls do_QDIO for sbal x to x+y, i.e. wrong indices
2453 * but do_QDIO fails as adapter_reopen is still waiting for the lock
2455 * queuecommand calls create_fcp_commmand_task...calls req_create
2456 * - meanwhile adapter reopen is called...completes,
2457 * - gets sbal 0 to 0+y, - req_send calls do_QDIO for sbal 0 to 0+y,
2458 * i.e. correct indices...though an fcp command is called before
2459 * exchange config data...that should be fine, however
2461 if (qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR)) {
2464 * What went wrong? What to do best? Proper retval?
2466 ZFCP_LOG_NORMAL("bug: shutdown of QDIO queues failed on "
2468 zfcp_get_busid_by_adapter(adapter));
2470 ZFCP_LOG_DEBUG("queues cleaned up\n");
2473 * First we had to stop QDIO operation.
2474 * Now it is safe to take the following actions.
2477 /* Cleanup only necessary when there are unacknowledged buffers */
2478 if (atomic_read(&adapter->request_queue.free_count)
2479 < QDIO_MAX_BUFFERS_PER_Q) {
2480 first_used = (adapter->request_queue.free_index +
2481 atomic_read(&adapter->request_queue.free_count))
2482 % QDIO_MAX_BUFFERS_PER_Q;
2483 used_count = QDIO_MAX_BUFFERS_PER_Q -
2484 atomic_read(&adapter->request_queue.free_count);
2485 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2486 first_used, used_count);
2488 adapter->response_queue.free_index = 0;
2489 atomic_set(&adapter->response_queue.free_count, 0);
2490 adapter->request_queue.free_index = 0;
2491 atomic_set(&adapter->request_queue.free_count, 0);
2492 adapter->request_queue.distance_from_int = 0;
2494 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2500 * function: zfcp_fsf_init
2502 * purpose: initializes FSF operation for the specified adapter
2504 * returns: 0 - succesful initialization of FSF operation
2505 * !0 - failed to initialize FSF operation
2508 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2512 /* do 'exchange configuration data' */
2513 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2514 if (retval == ZFCP_ERP_FAILED)
2517 /* start the desired number of Status Reads */
2518 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2530 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2532 int retval = ZFCP_ERP_SUCCEEDED;
2534 struct zfcp_adapter *adapter = erp_action->adapter;
2536 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2537 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2540 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2542 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2543 zfcp_erp_timeout_init(erp_action);
2544 if (zfcp_fsf_exchange_config_data(erp_action)) {
2545 retval = ZFCP_ERP_FAILED;
2546 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2547 ZFCP_LOG_INFO("error: initiation of exchange of "
2548 "configuration data failed for "
2550 zfcp_get_busid_by_adapter(adapter));
2553 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2554 ZFCP_LOG_DEBUG("Xchange underway\n");
2558 * Both the normal completion handler as well as the timeout
2559 * handler will do an 'up' when the 'exchange config data'
2560 * request completes or times out. Thus, the signal to go on
2561 * won't be lost utilizing this semaphore.
2562 * Furthermore, this 'adapter_reopen' action is
2563 * guaranteed to be the only action being there (highest action
2564 * which prevents other actions from being created).
2565 * Resulting from that, the wake signal recognized here
2566 * _must_ be the one belonging to the 'exchange config
2569 down_interruptible(&adapter->erp_ready_sem);
2570 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2571 ZFCP_LOG_INFO("error: exchange of configuration data "
2572 "for adapter %s timed out\n",
2573 zfcp_get_busid_by_adapter(adapter));
2576 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2577 &adapter->status)) {
2578 ZFCP_LOG_DEBUG("host connection still initialising... "
2579 "waiting and retrying...\n");
2580 /* sleep a little bit before retry */
2581 set_current_state(TASK_INTERRUPTIBLE);
2582 schedule_timeout(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP);
2584 } while ((retries--) &&
2585 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2588 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2589 &adapter->status)) {
2590 ZFCP_LOG_INFO("error: exchange of configuration data for "
2591 "adapter %s failed\n",
2592 zfcp_get_busid_by_adapter(adapter));
2593 retval = ZFCP_ERP_FAILED;
2607 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2610 int retval = ZFCP_ERP_SUCCEEDED;
2612 struct zfcp_adapter *adapter = erp_action->adapter;
2615 adapter->status_read_failed = 0;
2616 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2617 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2619 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2620 "notification failed on adapter %s\n",
2621 zfcp_get_busid_by_adapter(adapter));
2622 retval = ZFCP_ERP_FAILED;
2632 * function: zfcp_fsf_cleanup
2634 * purpose: cleanup FSF operation for specified adapter
2636 * returns: 0 - FSF operation successfully cleaned up
2637 * !0 - failed to cleanup FSF operation for this adapter
2640 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2642 int retval = ZFCP_ERP_SUCCEEDED;
2643 struct zfcp_adapter *adapter = erp_action->adapter;
2646 * wake waiting initiators of requests,
2647 * return SCSI commands (with error status),
2648 * clean up all requests (synchronously)
2650 zfcp_fsf_req_dismiss_all(adapter);
2651 /* reset FSF request sequence number */
2652 adapter->fsf_req_seq_no = 0;
2653 /* all ports and units are closed */
2654 zfcp_erp_modify_adapter_status(adapter,
2655 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2663 * purpose: this routine executes the 'Reopen Physical Port' action
2665 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2666 * ZFCP_ERP_SUCCEEDED - action finished successfully
2667 * ZFCP_ERP_FAILED - action finished unsuccessfully
2670 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2672 int retval = ZFCP_ERP_FAILED;
2673 struct zfcp_port *port = erp_action->port;
2674 struct zfcp_adapter *adapter = erp_action->adapter;
2676 switch (erp_action->step) {
2680 * the ULP spec. begs for waiting for oustanding commands
2682 case ZFCP_ERP_STEP_UNINITIALIZED:
2683 zfcp_erp_port_strategy_clearstati(port);
2685 * it would be sufficient to test only the normal open flag
2686 * since the phys. open flag cannot be set if the normal
2687 * open flag is unset - however, this is for readabilty ...
2689 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2690 ZFCP_STATUS_COMMON_OPEN),
2692 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2693 "close physical\n", port->wwpn);
2695 zfcp_erp_port_forced_strategy_close(erp_action);
2697 retval = ZFCP_ERP_FAILED;
2700 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2701 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2703 ZFCP_LOG_DEBUG("close physical failed for port "
2704 "0x%016Lx\n", port->wwpn);
2705 retval = ZFCP_ERP_FAILED;
2707 retval = ZFCP_ERP_SUCCEEDED;
2711 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2712 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2713 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2714 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2722 * purpose: this routine executes the 'Reopen Port' action
2724 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2725 * ZFCP_ERP_SUCCEEDED - action finished successfully
2726 * ZFCP_ERP_FAILED - action finished unsuccessfully
2729 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2731 int retval = ZFCP_ERP_FAILED;
2732 struct zfcp_port *port = erp_action->port;
2733 struct zfcp_adapter *adapter = erp_action->adapter;
2735 switch (erp_action->step) {
2739 * the ULP spec. begs for waiting for oustanding commands
2741 case ZFCP_ERP_STEP_UNINITIALIZED:
2742 zfcp_erp_port_strategy_clearstati(port);
2743 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2744 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2745 "close\n", port->wwpn);
2746 retval = zfcp_erp_port_strategy_close(erp_action);
2748 } /* else it's already closed, open it */
2751 case ZFCP_ERP_STEP_PORT_CLOSING:
2752 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2753 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2755 retval = ZFCP_ERP_FAILED;
2757 } /* else it's closed now, open it */
2760 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2761 retval = ZFCP_ERP_EXIT;
2763 retval = zfcp_erp_port_strategy_open(erp_action);
2766 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2767 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2768 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2769 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2782 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2786 if (atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER,
2787 &erp_action->port->status))
2788 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2790 retval = zfcp_erp_port_strategy_open_common(erp_action);
2802 * FIXME(design): currently only prepared for fabric (nameserver!)
2805 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2808 struct zfcp_adapter *adapter = erp_action->adapter;
2809 struct zfcp_port *port = erp_action->port;
2811 switch (erp_action->step) {
2813 case ZFCP_ERP_STEP_UNINITIALIZED:
2814 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2815 case ZFCP_ERP_STEP_PORT_CLOSING:
2816 if (!(adapter->nameserver_port)) {
2817 retval = zfcp_nameserver_enqueue(adapter);
2819 ZFCP_LOG_NORMAL("error: nameserver port "
2820 "unavailable for adapter %s\n",
2821 zfcp_get_busid_by_adapter(adapter));
2822 retval = ZFCP_ERP_FAILED;
2826 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2827 &adapter->nameserver_port->status)) {
2828 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2829 "nameserver port\n");
2830 /* nameserver port may live again */
2831 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2832 &adapter->nameserver_port->status);
2833 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0) >= 0) {
2834 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_OPEN;
2835 retval = ZFCP_ERP_CONTINUES;
2836 } else retval = ZFCP_ERP_FAILED;
2839 /* else nameserver port is already open, fall through */
2840 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2841 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2842 &adapter->nameserver_port->status)) {
2843 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2844 retval = ZFCP_ERP_FAILED;
2846 ZFCP_LOG_DEBUG("nameserver port is open -> "
2847 "nameserver look-up for port 0x%016Lx\n",
2849 retval = zfcp_erp_port_strategy_open_common_lookup
2854 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2855 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2856 if (atomic_test_mask
2857 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2858 ZFCP_LOG_DEBUG("nameserver look-up failed "
2859 "for port 0x%016Lx "
2860 "(misconfigured WWPN?)\n",
2862 zfcp_erp_port_failed(port);
2863 retval = ZFCP_ERP_EXIT;
2865 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2866 "port 0x%016Lx\n", port->wwpn);
2867 retval = ZFCP_ERP_FAILED;
2870 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2871 "trying open\n", port->wwpn, port->d_id);
2872 retval = zfcp_erp_port_strategy_open_port(erp_action);
2876 case ZFCP_ERP_STEP_PORT_OPENING:
2877 /* D_ID might have changed during open */
2878 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2879 ZFCP_STATUS_PORT_DID_DID),
2881 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2882 retval = ZFCP_ERP_SUCCEEDED;
2884 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2886 retval = ZFCP_ERP_FAILED;
2891 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2893 retval = ZFCP_ERP_FAILED;
2907 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2910 struct zfcp_port *port = erp_action->port;
2912 switch (erp_action->step) {
2914 case ZFCP_ERP_STEP_UNINITIALIZED:
2915 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2916 case ZFCP_ERP_STEP_PORT_CLOSING:
2917 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2918 port->wwpn, port->d_id);
2919 retval = zfcp_erp_port_strategy_open_port(erp_action);
2922 case ZFCP_ERP_STEP_PORT_OPENING:
2923 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2924 ZFCP_LOG_DEBUG("nameserver port is open\n");
2925 retval = ZFCP_ERP_SUCCEEDED;
2927 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2928 retval = ZFCP_ERP_FAILED;
2930 /* this is needed anyway (dont care for retval of wakeup) */
2931 ZFCP_LOG_DEBUG("continue other open port operations\n");
2932 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2936 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2938 retval = ZFCP_ERP_FAILED;
2947 * purpose: makes the erp thread continue with reopen (physical) port
2948 * actions which have been paused until the name server port
2949 * is opened (or failed)
2951 * returns: 0 (a kind of void retval, its not used)
2954 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2958 unsigned long flags;
2959 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2960 struct zfcp_erp_action *erp_action, *tmp;
2962 read_lock_irqsave(&adapter->erp_lock, flags);
2963 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2965 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2966 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2968 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2969 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2970 debug_event(adapter->erp_dbf, 3,
2971 &erp_action->port->wwpn, sizeof (wwn_t));
2972 if (atomic_test_mask(
2973 ZFCP_STATUS_COMMON_ERP_FAILED,
2974 &adapter->nameserver_port->status))
2975 zfcp_erp_port_failed(erp_action->port);
2976 zfcp_erp_action_ready(erp_action);
2979 read_unlock_irqrestore(&adapter->erp_lock, flags);
2989 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2990 * ZFCP_ERP_FAILED - action finished unsuccessfully
2993 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2996 struct zfcp_adapter *adapter = erp_action->adapter;
2997 struct zfcp_port *port = erp_action->port;
2999 zfcp_erp_timeout_init(erp_action);
3000 retval = zfcp_fsf_close_physical_port(erp_action);
3001 if (retval == -ENOMEM) {
3002 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
3003 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3004 retval = ZFCP_ERP_NOMEM;
3007 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
3009 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
3010 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3011 /* could not send 'open', fail */
3012 retval = ZFCP_ERP_FAILED;
3015 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
3016 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3017 retval = ZFCP_ERP_CONTINUES;
3030 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
3033 struct zfcp_adapter *adapter = port->adapter;
3035 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
3036 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3038 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3039 ZFCP_STATUS_COMMON_CLOSING |
3040 ZFCP_STATUS_PORT_DID_DID |
3041 ZFCP_STATUS_PORT_PHYS_CLOSING |
3042 ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
3051 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3052 * ZFCP_ERP_FAILED - action finished unsuccessfully
3055 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
3058 struct zfcp_adapter *adapter = erp_action->adapter;
3059 struct zfcp_port *port = erp_action->port;
3061 zfcp_erp_timeout_init(erp_action);
3062 retval = zfcp_fsf_close_port(erp_action);
3063 if (retval == -ENOMEM) {
3064 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
3065 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3066 retval = ZFCP_ERP_NOMEM;
3069 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
3071 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
3072 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3073 /* could not send 'close', fail */
3074 retval = ZFCP_ERP_FAILED;
3077 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
3078 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3079 retval = ZFCP_ERP_CONTINUES;
3089 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3090 * ZFCP_ERP_FAILED - action finished unsuccessfully
3093 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
3096 struct zfcp_adapter *adapter = erp_action->adapter;
3097 struct zfcp_port *port = erp_action->port;
3099 zfcp_erp_timeout_init(erp_action);
3100 retval = zfcp_fsf_open_port(erp_action);
3101 if (retval == -ENOMEM) {
3102 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
3103 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3104 retval = ZFCP_ERP_NOMEM;
3107 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
3109 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
3110 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3111 /* could not send 'open', fail */
3112 retval = ZFCP_ERP_FAILED;
3115 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
3116 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3117 retval = ZFCP_ERP_CONTINUES;
3127 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3128 * ZFCP_ERP_FAILED - action finished unsuccessfully
3131 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
3134 struct zfcp_adapter *adapter = erp_action->adapter;
3135 struct zfcp_port *port = erp_action->port;
3137 zfcp_erp_timeout_init(erp_action);
3138 retval = zfcp_ns_gid_pn_request(erp_action);
3139 if (retval == -ENOMEM) {
3140 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
3141 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3142 retval = ZFCP_ERP_NOMEM;
3145 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
3147 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
3148 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3149 /* could not send nameserver request, fail */
3150 retval = ZFCP_ERP_FAILED;
3153 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3154 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3155 retval = ZFCP_ERP_CONTINUES;
3163 * purpose: this routine executes the 'Reopen Unit' action
3164 * currently no retries
3166 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3167 * ZFCP_ERP_SUCCEEDED - action finished successfully
3168 * ZFCP_ERP_FAILED - action finished unsuccessfully
3171 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3173 int retval = ZFCP_ERP_FAILED;
3174 struct zfcp_unit *unit = erp_action->unit;
3175 struct zfcp_adapter *adapter = erp_action->adapter;
3177 switch (erp_action->step) {
3181 * the ULP spec. begs for waiting for oustanding commands
3183 case ZFCP_ERP_STEP_UNINITIALIZED:
3184 zfcp_erp_unit_strategy_clearstati(unit);
3185 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3186 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3187 "trying close\n", unit->fcp_lun);
3188 retval = zfcp_erp_unit_strategy_close(erp_action);
3191 /* else it's already closed, fall through */
3192 case ZFCP_ERP_STEP_UNIT_CLOSING:
3193 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3194 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3196 retval = ZFCP_ERP_FAILED;
3198 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3199 retval = ZFCP_ERP_EXIT;
3201 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3202 "trying open\n", unit->fcp_lun);
3204 zfcp_erp_unit_strategy_open(erp_action);
3209 case ZFCP_ERP_STEP_UNIT_OPENING:
3210 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3211 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3213 retval = ZFCP_ERP_SUCCEEDED;
3215 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3217 retval = ZFCP_ERP_FAILED;
3222 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3223 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3224 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3225 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3237 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3240 struct zfcp_adapter *adapter = unit->port->adapter;
3242 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3243 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3245 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3246 ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3256 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3257 * ZFCP_ERP_FAILED - action finished unsuccessfully
3260 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3263 struct zfcp_adapter *adapter = erp_action->adapter;
3264 struct zfcp_unit *unit = erp_action->unit;
3266 zfcp_erp_timeout_init(erp_action);
3267 retval = zfcp_fsf_close_unit(erp_action);
3268 if (retval == -ENOMEM) {
3269 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3270 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3271 sizeof (fcp_lun_t));
3272 retval = ZFCP_ERP_NOMEM;
3275 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3277 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3278 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3279 sizeof (fcp_lun_t));
3280 /* could not send 'close', fail */
3281 retval = ZFCP_ERP_FAILED;
3284 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3285 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3286 retval = ZFCP_ERP_CONTINUES;
3297 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3298 * ZFCP_ERP_FAILED - action finished unsuccessfully
3301 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3304 struct zfcp_adapter *adapter = erp_action->adapter;
3305 struct zfcp_unit *unit = erp_action->unit;
3307 zfcp_erp_timeout_init(erp_action);
3308 retval = zfcp_fsf_open_unit(erp_action);
3309 if (retval == -ENOMEM) {
3310 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3311 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3312 sizeof (fcp_lun_t));
3313 retval = ZFCP_ERP_NOMEM;
3316 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3318 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3319 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3320 sizeof (fcp_lun_t));
3321 /* could not send 'open', fail */
3322 retval = ZFCP_ERP_FAILED;
3325 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3326 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3327 retval = ZFCP_ERP_CONTINUES;
3340 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3342 init_timer(&erp_action->timer);
3343 erp_action->timer.function = zfcp_erp_timeout_handler;
3344 erp_action->timer.data = (unsigned long) erp_action;
3345 /* jiffies will be added in zfcp_fsf_req_send */
3346 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3352 * purpose: enqueue the specified error recovery action, if needed
3357 zfcp_erp_action_enqueue(int action,
3358 struct zfcp_adapter *adapter,
3359 struct zfcp_port *port, struct zfcp_unit *unit)
3362 struct zfcp_erp_action *erp_action = NULL;
3363 int stronger_action = 0;
3367 * We need some rules here which check whether we really need
3368 * this action or whether we should just drop it.
3369 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3370 * 'Reopen Unit' request for an associated unit since we can't
3371 * satisfy this request now. A 'Reopen Port' action will trigger
3372 * 'Reopen Unit' actions when it completes.
3373 * Thus, there are only actions in the queue which can immediately be
3374 * executed. This makes the processing of the action queue more
3378 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3382 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3383 /* check whether we really need this */
3385 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3386 if (atomic_test_mask
3387 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3388 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3389 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3391 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3392 sizeof (fcp_lun_t));
3395 if (!atomic_test_mask
3396 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3398 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3401 if (!atomic_test_mask
3402 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3403 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3406 /* fall through !!! */
3408 case ZFCP_ERP_ACTION_REOPEN_PORT:
3409 if (atomic_test_mask
3410 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3411 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3412 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3416 /* fall through !!! */
3418 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3419 if (atomic_test_mask
3420 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3421 && port->erp_action.action ==
3422 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3423 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3424 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3428 if (!atomic_test_mask
3429 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3431 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3434 if (!atomic_test_mask
3435 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3436 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3439 /* fall through !!! */
3441 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3442 if (atomic_test_mask
3443 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3444 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3450 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3451 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3452 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3453 "on adapter %s (action=%d)\n",
3454 zfcp_get_busid_by_adapter(adapter), action);
3458 /* check whether we need something stronger first */
3459 if (stronger_action) {
3460 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3461 debug_event(adapter->erp_dbf, 4, &stronger_action,
3463 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3464 "erp action %d on adapter %s\n",
3465 stronger_action, action,
3466 zfcp_get_busid_by_adapter(adapter));
3467 action = stronger_action;
3470 /* mark adapter to have some error recovery pending */
3471 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3473 /* setup error recovery action */
3476 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3477 zfcp_unit_get(unit);
3478 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3479 erp_action = &unit->erp_action;
3480 if (!atomic_test_mask
3481 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3482 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3485 case ZFCP_ERP_ACTION_REOPEN_PORT:
3486 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3487 zfcp_port_get(port);
3488 zfcp_erp_action_dismiss_port(port);
3489 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3490 erp_action = &port->erp_action;
3491 if (!atomic_test_mask
3492 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3493 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3496 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3497 zfcp_adapter_get(adapter);
3498 zfcp_erp_action_dismiss_adapter(adapter);
3499 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3500 erp_action = &adapter->erp_action;
3501 if (!atomic_test_mask
3502 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3503 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3507 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3509 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3510 erp_action->adapter = adapter;
3511 erp_action->port = port;
3512 erp_action->unit = unit;
3513 erp_action->action = action;
3514 erp_action->status = status;
3516 ++adapter->erp_total_count;
3518 /* finally put it into 'ready' queue and kick erp thread */
3519 list_add(&erp_action->list, &adapter->erp_ready_head);
3520 up(&adapter->erp_ready_sem);
3534 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3537 struct zfcp_adapter *adapter = erp_action->adapter;
3539 --adapter->erp_total_count;
3540 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3541 --adapter->erp_low_mem_count;
3542 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3545 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3546 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3547 list_del(&erp_action->list);
3548 switch (erp_action->action) {
3549 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3550 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3551 &erp_action->unit->status);
3553 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3554 case ZFCP_ERP_ACTION_REOPEN_PORT:
3555 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3556 &erp_action->port->status);
3558 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3559 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3560 &erp_action->adapter->status);
3570 * zfcp_erp_action_cleanup
3572 * registers unit with scsi stack if appropiate and fixes reference counts
3576 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3577 struct zfcp_port *port, struct zfcp_unit *unit,
3580 if ((action == ZFCP_ERP_ACTION_REOPEN_UNIT)
3581 && (result == ZFCP_ERP_SUCCEEDED)
3582 && (!unit->device)) {
3583 zfcp_erp_schedule_work(unit);
3586 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3587 zfcp_unit_put(unit);
3589 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3590 case ZFCP_ERP_ACTION_REOPEN_PORT:
3591 zfcp_port_put(port);
3593 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3594 zfcp_adapter_put(adapter);
3610 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3613 struct zfcp_port *port;
3615 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3616 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3617 zfcp_erp_action_dismiss(&adapter->erp_action);
3619 list_for_each_entry(port, &adapter->port_list_head, list)
3620 zfcp_erp_action_dismiss_port(port);
3633 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3636 struct zfcp_unit *unit;
3637 struct zfcp_adapter *adapter = port->adapter;
3639 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3640 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3641 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3642 zfcp_erp_action_dismiss(&port->erp_action);
3644 list_for_each_entry(unit, &port->unit_list_head, list)
3645 zfcp_erp_action_dismiss_unit(unit);
3658 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3661 struct zfcp_adapter *adapter = unit->port->adapter;
3663 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3664 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3665 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3666 zfcp_erp_action_dismiss(&unit->erp_action);
3674 * purpose: moves erp_action to 'erp running list'
3679 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3681 struct zfcp_adapter *adapter = erp_action->adapter;
3683 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3684 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3685 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3691 * purpose: moves erp_action to 'erp ready list'
3696 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3698 struct zfcp_adapter *adapter = erp_action->adapter;
3700 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3701 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3702 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3705 #undef ZFCP_LOG_AREA