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.54 $"
38 static int zfcp_els(struct zfcp_port *, u8);
39 static int zfcp_els_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
68 struct zfcp_unit *, int);
69 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
72 struct zfcp_unit *, int);
73 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
76 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
131 * function: zfcp_fsf_scsi_er_timeout_handler
133 * purpose: This function needs to be called whenever a SCSI error recovery
134 * action (abort/reset) does not return.
135 * Re-opening the adapter means that the command can be returned
136 * by zfcp (it is guarranteed that it does not return via the
137 * adapter anymore). The buffer can then be used again.
142 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
144 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
146 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
147 "Restarting all operations on the adapter %s\n",
148 zfcp_get_busid_by_adapter(adapter));
149 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
150 zfcp_erp_adapter_reopen(adapter, 0);
158 * purpose: called if an adapter failed,
159 * initiates adapter recovery which is done
162 * returns: 0 - initiated action succesfully
163 * <0 - failed to initiate action
166 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
170 debug_text_event(adapter->erp_dbf, 5, "a_ro");
171 ZFCP_LOG_DEBUG("reopen adapter %s\n",
172 zfcp_get_busid_by_adapter(adapter));
174 zfcp_erp_adapter_block(adapter, clear_mask);
176 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
177 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
178 zfcp_get_busid_by_adapter(adapter));
179 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
180 /* ensure propagation of failed status to new devices */
181 zfcp_erp_adapter_failed(adapter);
185 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
186 adapter, NULL, NULL);
195 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
196 * used to ensure the correct locking
198 * returns: 0 - initiated action succesfully
199 * <0 - failed to initiate action
202 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
207 read_lock_irqsave(&zfcp_data.config_lock, flags);
208 write_lock(&adapter->erp_lock);
209 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
210 write_unlock(&adapter->erp_lock);
211 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
224 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
228 retval = zfcp_erp_adapter_reopen(adapter,
229 ZFCP_STATUS_COMMON_RUNNING |
230 ZFCP_STATUS_COMMON_ERP_FAILED |
244 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
248 retval = zfcp_erp_port_reopen(port,
249 ZFCP_STATUS_COMMON_RUNNING |
250 ZFCP_STATUS_COMMON_ERP_FAILED |
264 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
268 retval = zfcp_erp_unit_reopen(unit,
269 ZFCP_STATUS_COMMON_RUNNING |
270 ZFCP_STATUS_COMMON_ERP_FAILED |
280 * purpose: Originator of the ELS commands
282 * returns: 0 - Operation completed successfuly
283 * -EINVAL - Unknown IOCTL command or invalid sense data record
284 * -ENOMEM - Insufficient memory
285 * -EPERM - Cannot create or queue FSF request
288 zfcp_els(struct zfcp_port *port, u8 ls_code)
290 struct zfcp_send_els *send_els;
291 struct zfcp_ls_rls *rls;
292 struct zfcp_ls_pdisc *pdisc;
293 struct zfcp_ls_adisc *adisc;
294 struct page *page = NULL;
298 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
299 if (send_els == NULL)
302 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
303 if (send_els->req == NULL)
305 send_els->req_count = 1;
307 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
308 if (send_els->resp == NULL)
310 send_els->resp_count = 1;
312 page = alloc_pages(GFP_ATOMIC, 0);
315 send_els->req->page = page;
316 send_els->resp->page = page;
317 send_els->req->offset = 0;
318 send_els->resp->offset = PAGE_SIZE >> 1;
320 send_els->port = port;
321 send_els->ls_code = ls_code;
322 send_els->handler = zfcp_els_handler;
323 send_els->handler_data = (unsigned long)send_els;
324 send_els->completion = NULL;
326 req = zfcp_sg_to_address(send_els->req);
334 send_els->req->length = sizeof(struct zfcp_ls_rtv);
335 send_els->resp->length = sizeof(struct zfcp_ls_rtv_acc);
336 ZFCP_LOG_INFO("RTV request from s_id 0x%08x to d_id 0x%08x\n",
337 port->adapter->s_id, port->d_id);
341 send_els->req->length = sizeof(struct zfcp_ls_rls);
342 send_els->resp->length = sizeof(struct zfcp_ls_rls_acc);
343 rls = (struct zfcp_ls_rls*)req;
344 rls->port_id = port->adapter->s_id;
345 ZFCP_LOG_INFO("RLS request from s_id 0x%08x to d_id 0x%08x "
346 "(port_id=0x%08x)\n",
347 port->adapter->s_id, port->d_id, rls->port_id);
351 send_els->req->length = sizeof(struct zfcp_ls_pdisc);
352 send_els->resp->length = sizeof(struct zfcp_ls_pdisc_acc);
353 pdisc = (struct zfcp_ls_pdisc*)req;
354 pdisc->wwpn = port->adapter->wwpn;
355 pdisc->wwnn = port->adapter->wwnn;
356 ZFCP_LOG_INFO("PDISC request from s_id 0x%08x to d_id 0x%08x "
357 "(wwpn=0x%016Lx, wwnn=0x%016Lx)\n",
358 port->adapter->s_id, port->d_id,
359 pdisc->wwpn, pdisc->wwnn);
363 send_els->req->length = sizeof(struct zfcp_ls_adisc);
364 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
365 adisc = (struct zfcp_ls_adisc*)req;
366 adisc->hard_nport_id = port->adapter->s_id;
367 adisc->wwpn = port->adapter->wwpn;
368 adisc->wwnn = port->adapter->wwnn;
369 adisc->nport_id = port->adapter->s_id;
370 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
371 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
372 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
373 port->adapter->s_id, port->d_id,
374 adisc->wwpn, adisc->wwnn,
375 adisc->hard_nport_id, adisc->nport_id);
379 ZFCP_LOG_NORMAL("ELS command code 0x%02x is not supported\n",
382 goto invalid_ls_code;
385 retval = zfcp_fsf_send_els(send_els);
387 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
388 "0x%016Lx on adapter %s\n",
389 port->wwpn, zfcp_get_busid_by_port(port));
396 ZFCP_LOG_DEBUG("out of memory\n");
401 __free_pages(page, 0);
402 if (send_els != NULL) {
403 if (send_els->req != NULL)
404 kfree(send_els->req);
405 if (send_els->resp != NULL)
406 kfree(send_els->resp);
416 * function: zfcp_els_handler
418 * purpose: Handler for all kind of ELSs
420 * returns: 0 - Operation completed successfuly
421 * -ENXIO - ELS has been rejected
422 * -EPERM - Port forced reopen failed
425 zfcp_els_handler(unsigned long data)
427 struct zfcp_send_els *send_els = (struct zfcp_send_els*)data;
428 struct zfcp_port *port = send_els->port;
429 struct zfcp_ls_rjt *rjt;
430 struct zfcp_ls_rtv_acc *rtv;
431 struct zfcp_ls_rls_acc *rls;
432 struct zfcp_ls_pdisc_acc *pdisc;
433 struct zfcp_ls_adisc_acc *adisc;
435 u8 req_code, resp_code;
438 if (send_els->status != 0)
441 req = (void*)((page_to_pfn(send_els->req->page) << PAGE_SHIFT) + send_els->req->offset);
442 resp = (void*)((page_to_pfn(send_els->resp->page) << PAGE_SHIFT) + send_els->resp->offset);
443 req_code = *(u8*)req;
444 resp_code = *(u8*)resp;
449 rjt = (struct zfcp_ls_rjt*)resp;
451 switch (rjt->reason_code) {
453 case ZFCP_LS_RJT_INVALID_COMMAND_CODE:
454 ZFCP_LOG_INFO("invalid LS command code "
455 "(wwpn=0x%016Lx, command=0x%02x)\n",
456 port->wwpn, req_code);
459 case ZFCP_LS_RJT_LOGICAL_ERROR:
460 ZFCP_LOG_INFO("logical error (wwpn=0x%016Lx, "
461 "reason_expl=0x%02x)\n",
462 port->wwpn, rjt->reason_expl);
465 case ZFCP_LS_RJT_LOGICAL_BUSY:
466 ZFCP_LOG_INFO("logical busy (wwpn=0x%016Lx, "
467 "reason_expl=0x%02x)\n",
468 port->wwpn, rjt->reason_expl);
471 case ZFCP_LS_RJT_PROTOCOL_ERROR:
472 ZFCP_LOG_INFO("protocol error (wwpn=0x%016Lx, "
473 "reason_expl=0x%02x)\n",
474 port->wwpn, rjt->reason_expl);
477 case ZFCP_LS_RJT_UNABLE_TO_PERFORM:
478 ZFCP_LOG_INFO("unable to perform command requested "
479 "(wwpn=0x%016Lx, reason_expl=0x%02x)\n",
480 port->wwpn, rjt->reason_expl);
483 case ZFCP_LS_RJT_COMMAND_NOT_SUPPORTED:
484 ZFCP_LOG_INFO("command not supported (wwpn=0x%016Lx, "
486 port->wwpn, req_code);
489 case ZFCP_LS_RJT_VENDOR_UNIQUE_ERROR:
490 ZFCP_LOG_INFO("vendor specific error (wwpn=0x%016Lx, "
491 "vendor_unique=0x%02x)\n",
492 port->wwpn, rjt->vendor_unique);
496 ZFCP_LOG_NORMAL("ELS rejected by remote port 0x%016Lx "
497 "on adapter %s (reason_code=0x%02x)\n",
499 zfcp_get_busid_by_port(port),
509 rtv = (struct zfcp_ls_rtv_acc*)resp;
510 ZFCP_LOG_INFO("RTV response from d_id 0x%08x to s_id "
511 "0x%08x (R_A_TOV=%ds E_D_TOV=%d%cs)\n",
512 port->d_id, port->adapter->s_id,
513 rtv->r_a_tov, rtv->e_d_tov,
515 ZFCP_LS_RTV_E_D_TOV_FLAG ? 'n' : 'm');
519 rls = (struct zfcp_ls_rls_acc*)resp;
520 ZFCP_LOG_INFO("RLS response from d_id 0x%08x to s_id "
521 "0x%08x (link_failure_count=%u, "
522 "loss_of_sync_count=%u, "
523 "loss_of_signal_count=%u, "
524 "primitive_sequence_protocol_error=%u, "
525 "invalid_transmition_word=%u, "
526 "invalid_crc_count=%u)\n",
527 port->d_id, port->adapter->s_id,
528 rls->link_failure_count,
529 rls->loss_of_sync_count,
530 rls->loss_of_signal_count,
531 rls->prim_seq_prot_error,
532 rls->invalid_transmition_word,
533 rls->invalid_crc_count);
537 pdisc = (struct zfcp_ls_pdisc_acc*)resp;
538 ZFCP_LOG_INFO("PDISC response from d_id 0x%08x to s_id "
539 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
540 "vendor='%-16s')\n", port->d_id,
541 port->adapter->s_id, pdisc->wwpn,
542 pdisc->wwnn, pdisc->vendor_version);
546 adisc = (struct zfcp_ls_adisc_acc*)resp;
547 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
548 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
549 "hard_nport_id=0x%08x, "
550 "nport_id=0x%08x)\n", port->d_id,
551 port->adapter->s_id, adisc->wwpn,
552 adisc->wwnn, adisc->hard_nport_id,
554 /* FIXME: set wwnn in during open port */
556 port->wwnn = adisc->wwnn;
562 ZFCP_LOG_NORMAL("unknown payload code 0x%02x received for "
563 "request 0x%02x to d_id 0x%08x, reopen needed "
564 "for port 0x%016Lx on adapter %s\n", resp_code,
565 req_code, port->d_id, port->wwpn,
566 zfcp_get_busid_by_port(port));
567 retval = zfcp_erp_port_forced_reopen(port, 0);
569 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx on "
570 "adapter %s failed\n", port->wwpn,
571 zfcp_get_busid_by_port(port));
577 __free_pages(send_els->req->page, 0);
578 kfree(send_els->req);
579 kfree(send_els->resp);
586 * function: zfcp_test_link
588 * purpose: Test a status of a link to a remote port using the ELS command ADISC
590 * returns: 0 - Link is OK
591 * -EPERM - Port forced reopen failed
594 zfcp_test_link(struct zfcp_port *port)
598 retval = zfcp_els(port, ZFCP_LS_ADISC);
600 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
601 "on adapter %s\n ", port->wwpn,
602 zfcp_get_busid_by_port(port));
603 retval = zfcp_erp_port_forced_reopen(port, 0);
605 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
606 "on adapter %s failed\n", port->wwpn,
607 zfcp_get_busid_by_port(port));
619 * purpose: called if a port failed to be opened normally
620 * initiates Forced Reopen recovery which is done
623 * returns: 0 - initiated action succesfully
624 * <0 - failed to initiate action
627 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
630 struct zfcp_adapter *adapter = port->adapter;
632 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
633 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
635 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
636 port->wwpn, zfcp_get_busid_by_port(port));
638 zfcp_erp_port_block(port, clear_mask);
640 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
641 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
642 "on adapter %s\n", port->wwpn,
643 zfcp_get_busid_by_port(port));
644 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
645 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
650 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
651 port->adapter, port, NULL);
660 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
661 * used to ensure the correct locking
663 * returns: 0 - initiated action succesfully
664 * <0 - failed to initiate action
667 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
671 struct zfcp_adapter *adapter;
673 adapter = port->adapter;
674 read_lock_irqsave(&zfcp_data.config_lock, flags);
675 write_lock(&adapter->erp_lock);
676 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
677 write_unlock(&adapter->erp_lock);
678 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
686 * purpose: called if a port is to be opened
687 * initiates Reopen recovery which is done
690 * returns: 0 - initiated action succesfully
691 * <0 - failed to initiate action
694 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
697 struct zfcp_adapter *adapter = port->adapter;
699 debug_text_event(adapter->erp_dbf, 5, "p_ro");
700 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
702 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
703 port->wwpn, zfcp_get_busid_by_port(port));
705 zfcp_erp_port_block(port, clear_mask);
707 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
708 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
709 "on adapter %s\n", port->wwpn,
710 zfcp_get_busid_by_port(port));
711 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
712 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
713 /* ensure propagation of failed status to new devices */
714 zfcp_erp_port_failed(port);
719 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
720 port->adapter, port, NULL);
729 * purpose: Wrappper for zfcp_erp_port_reopen_internal
730 * used to ensure the correct locking
732 * returns: 0 - initiated action succesfully
733 * <0 - failed to initiate action
736 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
740 struct zfcp_adapter *adapter = port->adapter;
742 read_lock_irqsave(&zfcp_data.config_lock, flags);
743 write_lock(&adapter->erp_lock);
744 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
745 write_unlock(&adapter->erp_lock);
746 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
754 * purpose: called if a unit is to be opened
755 * initiates Reopen recovery which is done
758 * returns: 0 - initiated action succesfully
759 * <0 - failed to initiate action
762 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
765 struct zfcp_adapter *adapter = unit->port->adapter;
767 debug_text_event(adapter->erp_dbf, 5, "u_ro");
768 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
769 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
770 "on adapter %s\n", unit->fcp_lun,
771 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
773 zfcp_erp_unit_block(unit, clear_mask);
775 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
776 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
777 "on port 0x%016Lx on adapter %s\n",
778 unit->fcp_lun, unit->port->wwpn,
779 zfcp_get_busid_by_unit(unit));
780 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
781 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
787 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
788 unit->port->adapter, unit->port, unit);
796 * purpose: Wrappper for zfcp_erp_unit_reopen_internal
797 * used to ensure the correct locking
799 * returns: 0 - initiated action succesfully
800 * <0 - failed to initiate action
803 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
807 struct zfcp_adapter *adapter;
808 struct zfcp_port *port;
811 adapter = port->adapter;
813 read_lock_irqsave(&zfcp_data.config_lock, flags);
814 write_lock(&adapter->erp_lock);
815 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
816 write_unlock(&adapter->erp_lock);
817 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
825 * purpose: disable I/O,
826 * return any open requests and clean them up,
827 * aim: no pending and incoming I/O
832 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
834 debug_text_event(adapter->erp_dbf, 6, "a_bl");
835 zfcp_erp_modify_adapter_status(adapter,
836 ZFCP_STATUS_COMMON_UNBLOCKED |
837 clear_mask, ZFCP_CLEAR);
843 * purpose: enable I/O
848 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
850 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
851 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
857 * purpose: disable I/O,
858 * return any open requests and clean them up,
859 * aim: no pending and incoming I/O
864 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
866 struct zfcp_adapter *adapter = port->adapter;
868 debug_text_event(adapter->erp_dbf, 6, "p_bl");
869 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
870 zfcp_erp_modify_port_status(port,
871 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
878 * purpose: enable I/O
883 zfcp_erp_port_unblock(struct zfcp_port *port)
885 struct zfcp_adapter *adapter = port->adapter;
887 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
888 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
889 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
895 * purpose: disable I/O,
896 * return any open requests and clean them up,
897 * aim: no pending and incoming I/O
902 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
904 struct zfcp_adapter *adapter = unit->port->adapter;
906 debug_text_event(adapter->erp_dbf, 6, "u_bl");
907 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
908 zfcp_erp_modify_unit_status(unit,
909 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
916 * purpose: enable I/O
921 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
923 struct zfcp_adapter *adapter = unit->port->adapter;
925 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
926 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
927 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
938 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
940 struct zfcp_adapter *adapter = erp_action->adapter;
942 debug_text_event(adapter->erp_dbf, 4, "a_ar");
943 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
945 zfcp_erp_action_to_ready(erp_action);
946 up(&adapter->erp_ready_sem);
954 * returns: <0 erp_action not found in any list
955 * ZFCP_ERP_ACTION_READY erp_action is in ready list
956 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
958 * locks: erp_lock must be held
961 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
963 int retval = -EINVAL;
964 struct list_head *entry;
965 struct zfcp_erp_action *entry_erp_action;
966 struct zfcp_adapter *adapter = erp_action->adapter;
968 /* search in running list */
969 list_for_each(entry, &adapter->erp_running_head) {
971 list_entry(entry, struct zfcp_erp_action, list);
972 if (entry_erp_action == erp_action) {
973 retval = ZFCP_ERP_ACTION_RUNNING;
977 /* search in ready list */
978 list_for_each(entry, &adapter->erp_ready_head) {
980 list_entry(entry, struct zfcp_erp_action, list);
981 if (entry_erp_action == erp_action) {
982 retval = ZFCP_ERP_ACTION_READY;
992 * purpose: checks current status of action (timed out, dismissed, ...)
993 * and does appropriate preparations (dismiss fsf request, ...)
995 * locks: called under erp_lock (disabled interrupts)
1000 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
1003 struct zfcp_fsf_req *fsf_req;
1004 struct zfcp_adapter *adapter = erp_action->adapter;
1006 if (erp_action->fsf_req) {
1007 /* take lock to ensure that request is not being deleted meanwhile */
1008 write_lock(&adapter->fsf_req_list_lock);
1009 /* check whether fsf req does still exist */
1010 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
1011 if (fsf_req == erp_action->fsf_req)
1013 if (fsf_req == erp_action->fsf_req) {
1014 /* fsf_req still exists */
1015 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
1016 debug_event(adapter->erp_dbf, 3, &fsf_req,
1017 sizeof (unsigned long));
1018 /* dismiss fsf_req of timed out or dismissed erp_action */
1019 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
1020 ZFCP_STATUS_ERP_TIMEDOUT)) {
1021 debug_text_event(adapter->erp_dbf, 3,
1023 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
1025 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1026 ZFCP_LOG_NORMAL("error: erp step timed out "
1027 "(action=%d, fsf_req=%p)\n ",
1029 erp_action->fsf_req);
1032 * If fsf_req is neither dismissed nor completed
1033 * then keep it running asynchronously and don't mess
1034 * with the association of erp_action and fsf_req.
1036 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
1037 ZFCP_STATUS_FSFREQ_DISMISSED)) {
1038 /* forget about association between fsf_req
1040 fsf_req->erp_action = NULL;
1041 erp_action->fsf_req = NULL;
1044 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
1046 * even if this fsf_req has gone, forget about
1047 * association between erp_action and fsf_req
1049 erp_action->fsf_req = NULL;
1051 write_unlock(&adapter->fsf_req_list_lock);
1053 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
1059 * purpose: generic handler for asynchronous events related to erp_action events
1060 * (normal completion, time-out, dismissing, retry after
1061 * low memory condition)
1063 * note: deletion of timer is not required (e.g. in case of a time-out),
1064 * but a second try does no harm,
1065 * we leave it in here to allow for greater simplification
1067 * returns: 0 - there was an action to handle
1071 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
1072 unsigned long set_mask)
1075 struct zfcp_adapter *adapter = erp_action->adapter;
1077 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
1078 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
1079 debug_event(adapter->erp_dbf, 2, &erp_action->action,
1081 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
1082 del_timer_sync(&erp_action->timer);
1083 erp_action->status |= set_mask;
1084 zfcp_erp_action_ready(erp_action);
1087 /* action is ready or gone - nothing to do */
1088 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
1089 debug_event(adapter->erp_dbf, 3, &erp_action->action,
1098 * purpose: generic handler for asynchronous events related to erp_action
1099 * events (normal completion, time-out, dismissing, retry after
1100 * low memory condition)
1102 * note: deletion of timer is not required (e.g. in case of a time-out),
1103 * but a second try does no harm,
1104 * we leave it in here to allow for greater simplification
1106 * returns: 0 - there was an action to handle
1110 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1111 unsigned long set_mask)
1113 struct zfcp_adapter *adapter = erp_action->adapter;
1114 unsigned long flags;
1117 write_lock_irqsave(&adapter->erp_lock, flags);
1118 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1119 write_unlock_irqrestore(&adapter->erp_lock, flags);
1125 * purpose: is called for erp_action which was slept waiting for
1126 * memory becoming avaliable,
1127 * will trigger that this action will be continued
1130 zfcp_erp_memwait_handler(unsigned long data)
1132 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1133 struct zfcp_adapter *adapter = erp_action->adapter;
1135 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1136 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1138 zfcp_erp_async_handler(erp_action, 0);
1142 * purpose: is called if an asynchronous erp step timed out,
1143 * action gets an appropriate flag and will be processed
1147 zfcp_erp_timeout_handler(unsigned long data)
1149 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1150 struct zfcp_adapter *adapter = erp_action->adapter;
1152 debug_text_event(adapter->erp_dbf, 2, "a_th");
1153 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1155 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1159 * purpose: is called for an erp_action which needs to be ended
1160 * though not being done,
1161 * this is usually required if an higher is generated,
1162 * action gets an appropriate flag and will be processed
1165 * locks: erp_lock held (thus we need to call another handler variant)
1168 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1170 struct zfcp_adapter *adapter = erp_action->adapter;
1172 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1173 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1175 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1181 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1185 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1187 rwlock_init(&adapter->erp_lock);
1188 INIT_LIST_HEAD(&adapter->erp_ready_head);
1189 INIT_LIST_HEAD(&adapter->erp_running_head);
1190 sema_init(&adapter->erp_ready_sem, 0);
1192 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1194 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1196 zfcp_get_busid_by_adapter(adapter));
1197 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1199 wait_event(adapter->erp_thread_wqh,
1200 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1202 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1205 return (retval < 0);
1215 * context: process (i.e. proc-fs or rmmod/insmod)
1217 * note: The caller of this routine ensures that the specified
1218 * adapter has been shut down and that this operation
1219 * has been completed. Thus, there are no pending erp_actions
1220 * which would need to be handled here.
1223 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1227 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1228 up(&adapter->erp_ready_sem);
1230 wait_event(adapter->erp_thread_wqh,
1231 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1234 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1237 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1243 * purpose: is run as a kernel thread,
1244 * goes through list of error recovery actions of associated adapter
1245 * and delegates single action to execution
1250 zfcp_erp_thread(void *data)
1252 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1253 struct list_head *next;
1254 struct zfcp_erp_action *erp_action;
1255 unsigned long flags;
1257 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1258 /* Block all signals */
1259 siginitsetinv(¤t->blocked, 0);
1260 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1261 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1262 wake_up(&adapter->erp_thread_wqh);
1264 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1265 &adapter->status)) {
1267 write_lock_irqsave(&adapter->erp_lock, flags);
1268 next = adapter->erp_ready_head.prev;
1269 write_unlock_irqrestore(&adapter->erp_lock, flags);
1271 if (next != &adapter->erp_ready_head) {
1273 list_entry(next, struct zfcp_erp_action, list);
1275 * process action (incl. [re]moving it
1276 * from 'ready' queue)
1278 zfcp_erp_strategy(erp_action);
1282 * sleep as long as there is nothing to do, i.e.
1283 * no action in 'ready' queue to be processed and
1284 * thread is not to be killed
1286 down_interruptible(&adapter->erp_ready_sem);
1287 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1290 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1291 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1292 wake_up(&adapter->erp_thread_wqh);
1300 * purpose: drives single error recovery action and schedules higher and
1301 * subordinate actions, if necessary
1303 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1304 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1305 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1306 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1307 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1310 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1313 struct zfcp_adapter *adapter = erp_action->adapter;
1314 struct zfcp_port *port = erp_action->port;
1315 struct zfcp_unit *unit = erp_action->unit;
1316 int action = erp_action->action;
1317 u32 status = erp_action->status;
1318 unsigned long flags;
1320 /* serialise dismissing, timing out, moving, enqueueing */
1321 read_lock_irqsave(&zfcp_data.config_lock, flags);
1322 write_lock(&adapter->erp_lock);
1324 /* dequeue dismissed action and leave, if required */
1325 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1326 if (retval == ZFCP_ERP_DISMISSED) {
1327 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1332 * move action to 'running' queue before processing it
1333 * (to avoid a race condition regarding moving the
1334 * action to the 'running' queue and back)
1336 zfcp_erp_action_to_running(erp_action);
1339 * try to process action as far as possible,
1340 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1341 * afterwards the lock is required again for the following reasons:
1342 * - dequeueing of finished action and enqueueing of
1343 * follow-up actions must be atomic so that any other
1344 * reopen-routine does not believe there is nothing to do
1345 * and that it is safe to enqueue something else,
1346 * - we want to force any control thread which is dismissing
1347 * actions to finish this before we decide about
1348 * necessary steps to be taken here further
1350 write_unlock(&adapter->erp_lock);
1351 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1352 retval = zfcp_erp_strategy_do_action(erp_action);
1353 read_lock_irqsave(&zfcp_data.config_lock, flags);
1354 write_lock(&adapter->erp_lock);
1357 * check for dismissed status again to avoid follow-up actions,
1358 * failing of targets and so on for dismissed actions
1360 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1363 case ZFCP_ERP_DISMISSED:
1364 /* leave since this action has ridden to its ancestors */
1365 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1367 case ZFCP_ERP_NOMEM:
1368 /* no memory to continue immediately, let it sleep */
1369 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1370 ++adapter->erp_low_mem_count;
1371 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1373 /* This condition is true if there is no memory available
1374 for any erp_action on this adapter. This implies that there
1375 are no elements in the memory pool(s) left for erp_actions.
1376 This might happen if an erp_action that used a memory pool
1377 element was timed out.
1379 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1380 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1381 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1382 "restarting I/O on adapter %s "
1383 "to free mempool\n",
1384 zfcp_get_busid_by_adapter(adapter));
1385 zfcp_erp_adapter_reopen_internal(adapter, 0);
1387 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1388 retval = zfcp_erp_strategy_memwait(erp_action);
1391 case ZFCP_ERP_CONTINUES:
1392 /* leave since this action runs asynchronously */
1393 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1394 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1395 --adapter->erp_low_mem_count;
1396 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1400 /* ok, finished action (whatever its result is) */
1402 /* check for unrecoverable targets */
1403 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1405 /* action must be dequeued (here to allow for further ones) */
1406 zfcp_erp_action_dequeue(erp_action);
1409 * put this target through the erp mill again if someone has
1410 * requested to change the status of a target being online
1411 * to offline or the other way around
1412 * (old retval is preserved if nothing has to be done here)
1414 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1415 port, unit, retval);
1418 * leave if target is in permanent error state or if
1419 * action is repeated in order to process state change
1421 if (retval == ZFCP_ERP_EXIT) {
1422 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1426 /* trigger follow up actions */
1427 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1430 write_unlock(&adapter->erp_lock);
1431 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1433 if (retval != ZFCP_ERP_CONTINUES)
1434 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1437 * a few tasks remain when the erp queues are empty
1438 * (don't do that if the last action evaluated was dismissed
1439 * since this clearly indicates that there is more to come) :
1440 * - close the name server port if it is open yet
1441 * (enqueues another [probably] final action)
1442 * - otherwise, wake up whoever wants to be woken when we are
1445 if (retval != ZFCP_ERP_DISMISSED)
1446 zfcp_erp_strategy_check_queues(adapter);
1448 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1458 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1459 * retval - otherwise
1462 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1464 struct zfcp_adapter *adapter = erp_action->adapter;
1466 zfcp_erp_strategy_check_fsfreq(erp_action);
1468 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1469 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1470 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1471 zfcp_erp_action_dequeue(erp_action);
1472 retval = ZFCP_ERP_DISMISSED;
1474 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1487 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1489 int retval = ZFCP_ERP_FAILED;
1490 struct zfcp_adapter *adapter = erp_action->adapter;
1493 * try to execute/continue action as far as possible,
1494 * note: no lock in subsequent strategy routines
1495 * (this allows these routine to call schedule, e.g.
1496 * kmalloc with such flags or qdio_initialize & friends)
1497 * Note: in case of timeout, the seperate strategies will fail
1498 * anyhow. No need for a special action. Even worse, a nameserver
1499 * failure would not wake up waiting ports without the call.
1501 switch (erp_action->action) {
1503 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1504 retval = zfcp_erp_adapter_strategy(erp_action);
1507 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1508 retval = zfcp_erp_port_forced_strategy(erp_action);
1511 case ZFCP_ERP_ACTION_REOPEN_PORT:
1512 retval = zfcp_erp_port_strategy(erp_action);
1515 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1516 retval = zfcp_erp_unit_strategy(erp_action);
1520 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1521 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1523 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1524 "adapter %s (action=%d)\n",
1525 zfcp_get_busid_by_adapter(erp_action->adapter),
1526 erp_action->action);
1535 * purpose: triggers retry of this action after a certain amount of time
1536 * by means of timer provided by erp_action
1538 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1541 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1543 int retval = ZFCP_ERP_CONTINUES;
1544 struct zfcp_adapter *adapter = erp_action->adapter;
1546 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1547 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1548 init_timer(&erp_action->timer);
1549 erp_action->timer.function = zfcp_erp_memwait_handler;
1550 erp_action->timer.data = (unsigned long) erp_action;
1551 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1552 add_timer(&erp_action->timer);
1558 * function: zfcp_erp_adapter_failed
1560 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1564 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1566 zfcp_erp_modify_adapter_status(adapter,
1567 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1568 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1569 zfcp_get_busid_by_adapter(adapter));
1570 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1574 * function: zfcp_erp_port_failed
1576 * purpose: sets the port and all underlying devices to ERP_FAILED
1580 zfcp_erp_port_failed(struct zfcp_port *port)
1582 zfcp_erp_modify_port_status(port,
1583 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1585 ZFCP_LOG_NORMAL("port erp failed on port 0x%016Lx on adapter %s\n",
1586 port->wwpn, zfcp_get_busid_by_port(port));
1587 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1588 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1592 * function: zfcp_erp_unit_failed
1594 * purpose: sets the unit to ERP_FAILED
1598 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1600 zfcp_erp_modify_unit_status(unit,
1601 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1603 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1604 " on adapter %s\n", unit->fcp_lun,
1605 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1606 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1607 debug_event(unit->port->adapter->erp_dbf, 2,
1608 &unit->fcp_lun, sizeof (fcp_lun_t));
1612 * function: zfcp_erp_strategy_check_target
1614 * purpose: increments the erp action count on the device currently in
1615 * recovery if the action failed or resets the count in case of
1616 * success. If a maximum count is exceeded the device is marked
1618 * The 'blocked' state of a target which has been recovered
1619 * successfully is reset.
1621 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1622 * ZFCP_ERP_SUCCEEDED - action finished successfully
1623 * ZFCP_ERP_EXIT - action failed and will not continue
1626 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1628 struct zfcp_adapter *adapter = erp_action->adapter;
1629 struct zfcp_port *port = erp_action->port;
1630 struct zfcp_unit *unit = erp_action->unit;
1632 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1633 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1634 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1636 switch (erp_action->action) {
1638 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1639 result = zfcp_erp_strategy_check_unit(unit, result);
1642 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1643 case ZFCP_ERP_ACTION_REOPEN_PORT:
1644 result = zfcp_erp_strategy_check_port(port, result);
1647 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1648 result = zfcp_erp_strategy_check_adapter(adapter, result);
1663 zfcp_erp_strategy_statechange(int action,
1665 struct zfcp_adapter *adapter,
1666 struct zfcp_port *port,
1667 struct zfcp_unit *unit, int retval)
1669 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1670 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1674 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1675 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1677 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1678 retval = ZFCP_ERP_EXIT;
1682 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1683 case ZFCP_ERP_ACTION_REOPEN_PORT:
1684 if (zfcp_erp_strategy_statechange_detected(&port->status,
1686 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1687 retval = ZFCP_ERP_EXIT;
1691 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1692 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1694 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1695 retval = ZFCP_ERP_EXIT;
1711 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1714 /* take it online */
1715 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1716 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1717 /* take it offline */
1718 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1719 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1723 * zfcp_erp_scsi_add_device
1724 * @data: pointer to a struct zfcp_unit
1726 * Registers a logical unit with the SCSI stack.
1729 zfcp_erp_scsi_add_device(void *data)
1732 struct zfcp_unit *unit;
1733 struct work_struct work;
1737 scsi_add_device(p->unit->port->adapter->scsi_host,
1738 0, p->unit->port->scsi_id, p->unit->scsi_lun);
1739 atomic_set(&p->unit->scsi_add_work, 0);
1740 wake_up(&p->unit->scsi_add_wq);
1741 zfcp_unit_put(p->unit);
1746 * zfcp_erp_schedule_work
1747 * @unit: pointer to unit which should be registered with SCSI stack
1749 * Schedules work which registers a unit with the SCSI stack
1752 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1755 struct zfcp_unit * unit;
1756 struct work_struct work;
1759 if (atomic_compare_and_swap(0, 1, &unit->scsi_add_work))
1762 if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
1763 ZFCP_LOG_NORMAL("error: registration at SCSI stack failed for "
1764 "unit 0x%016Lx on port 0x%016Lx on "
1765 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
1766 zfcp_get_busid_by_unit(unit));
1767 atomic_set(&unit->scsi_add_work, 0);
1771 zfcp_unit_get(unit);
1772 memset(p, 0, sizeof(*p));
1773 INIT_WORK(&p->work, zfcp_erp_scsi_add_device, p);
1775 schedule_work(&p->work);
1787 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1789 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1790 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1791 sizeof (fcp_lun_t));
1794 case ZFCP_ERP_SUCCEEDED :
1795 atomic_set(&unit->erp_counter, 0);
1796 zfcp_erp_unit_unblock(unit);
1798 case ZFCP_ERP_FAILED :
1799 atomic_inc(&unit->erp_counter);
1800 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1801 zfcp_erp_unit_failed(unit);
1803 case ZFCP_ERP_EXIT :
1808 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1809 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1810 result = ZFCP_ERP_EXIT;
1824 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1826 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1827 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1830 case ZFCP_ERP_SUCCEEDED :
1831 atomic_set(&port->erp_counter, 0);
1832 zfcp_erp_port_unblock(port);
1834 case ZFCP_ERP_FAILED :
1835 atomic_inc(&port->erp_counter);
1836 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1837 zfcp_erp_port_failed(port);
1839 case ZFCP_ERP_EXIT :
1844 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1845 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1846 result = ZFCP_ERP_EXIT;
1860 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1862 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1865 case ZFCP_ERP_SUCCEEDED :
1866 atomic_set(&adapter->erp_counter, 0);
1867 zfcp_erp_adapter_unblock(adapter);
1869 case ZFCP_ERP_FAILED :
1870 atomic_inc(&adapter->erp_counter);
1871 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1872 zfcp_erp_adapter_failed(adapter);
1874 case ZFCP_ERP_EXIT :
1879 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1880 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1881 result = ZFCP_ERP_EXIT;
1890 * purpose: remaining things in good cases,
1891 * escalation in bad cases
1896 zfcp_erp_strategy_followup_actions(int action,
1897 struct zfcp_adapter *adapter,
1898 struct zfcp_port *port,
1899 struct zfcp_unit *unit, int status)
1901 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1902 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1904 /* initiate follow-up actions depending on success of finished action */
1907 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1908 if (status == ZFCP_ERP_SUCCEEDED)
1909 zfcp_erp_port_reopen_all_internal(adapter, 0);
1911 zfcp_erp_adapter_reopen_internal(adapter, 0);
1914 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1915 if (status == ZFCP_ERP_SUCCEEDED)
1916 zfcp_erp_port_reopen_internal(port, 0);
1918 zfcp_erp_adapter_reopen_internal(adapter, 0);
1921 case ZFCP_ERP_ACTION_REOPEN_PORT:
1922 if (status == ZFCP_ERP_SUCCEEDED)
1923 zfcp_erp_unit_reopen_all_internal(port, 0);
1925 zfcp_erp_port_forced_reopen_internal(port, 0);
1928 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1929 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1931 zfcp_erp_port_reopen_internal(unit->port, 0);
1946 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1949 unsigned long flags;
1950 struct zfcp_port *nport = adapter->nameserver_port;
1952 read_lock_irqsave(&zfcp_data.config_lock, flags);
1953 read_lock(&adapter->erp_lock);
1954 if (list_empty(&adapter->erp_ready_head) &&
1955 list_empty(&adapter->erp_running_head)) {
1957 && atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
1959 debug_text_event(adapter->erp_dbf, 4, "a_cq_nspsd");
1960 /* taking down nameserver port */
1961 zfcp_erp_port_reopen_internal(nport,
1962 ZFCP_STATUS_COMMON_RUNNING |
1963 ZFCP_STATUS_COMMON_ERP_FAILED);
1965 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1966 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1968 wake_up(&adapter->erp_done_wqh);
1971 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1972 read_unlock(&adapter->erp_lock);
1973 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1986 zfcp_erp_wait(struct zfcp_adapter *adapter)
1990 wait_event(adapter->erp_done_wqh,
1991 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1998 * function: zfcp_erp_modify_adapter_status
2004 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
2005 u32 mask, int set_or_clear)
2007 struct zfcp_port *port;
2008 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2010 if (set_or_clear == ZFCP_SET) {
2011 atomic_set_mask(mask, &adapter->status);
2012 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
2014 atomic_clear_mask(mask, &adapter->status);
2015 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2016 atomic_set(&adapter->erp_counter, 0);
2017 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
2019 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
2021 /* Deal with all underlying devices, only pass common_mask */
2023 list_for_each_entry(port, &adapter->port_list_head, list)
2024 zfcp_erp_modify_port_status(port, common_mask,
2029 * function: zfcp_erp_modify_port_status
2031 * purpose: sets the port and all underlying devices to ERP_FAILED
2035 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
2037 struct zfcp_unit *unit;
2038 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
2040 if (set_or_clear == ZFCP_SET) {
2041 atomic_set_mask(mask, &port->status);
2042 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
2044 atomic_clear_mask(mask, &port->status);
2045 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
2046 atomic_set(&port->erp_counter, 0);
2047 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
2049 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2050 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2052 /* Modify status of all underlying devices, only pass common mask */
2054 list_for_each_entry(unit, &port->unit_list_head, list)
2055 zfcp_erp_modify_unit_status(unit, common_mask,
2060 * function: zfcp_erp_modify_unit_status
2062 * purpose: sets the unit to ERP_FAILED
2066 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
2068 if (set_or_clear == ZFCP_SET) {
2069 atomic_set_mask(mask, &unit->status);
2070 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
2072 atomic_clear_mask(mask, &unit->status);
2073 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
2074 atomic_set(&unit->erp_counter, 0);
2076 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
2078 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
2079 sizeof (fcp_lun_t));
2080 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2086 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
2087 * used to ensure the correct locking
2089 * returns: 0 - initiated action succesfully
2090 * <0 - failed to initiate action
2093 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
2096 unsigned long flags;
2098 read_lock_irqsave(&zfcp_data.config_lock, flags);
2099 write_lock(&adapter->erp_lock);
2100 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
2101 write_unlock(&adapter->erp_lock);
2102 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2115 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
2118 struct zfcp_port *port;
2120 list_for_each_entry(port, &adapter->port_list_head, list)
2121 if (!atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER, &port->status))
2122 zfcp_erp_port_reopen_internal(port, clear_mask);
2135 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
2138 struct zfcp_unit *unit;
2140 list_for_each_entry(unit, &port->unit_list_head, list)
2141 zfcp_erp_unit_reopen_internal(unit, clear_mask);
2149 * purpose: this routine executes the 'Reopen Adapter' action
2150 * (the entire action is processed synchronously, since
2151 * there are no actions which might be run concurrently
2154 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2155 * ZFCP_ERP_FAILED - action finished unsuccessfully
2158 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
2161 unsigned long timeout;
2162 struct zfcp_adapter *adapter = erp_action->adapter;
2164 retval = zfcp_erp_adapter_strategy_close(erp_action);
2165 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2166 retval = ZFCP_ERP_EXIT;
2168 retval = zfcp_erp_adapter_strategy_open(erp_action);
2170 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
2171 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2172 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2174 if (retval == ZFCP_ERP_FAILED) {
2175 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2176 "to recover itself\n",
2177 zfcp_get_busid_by_adapter(adapter));
2179 * SUGGESTION: substitute by
2180 * timeout = ZFCP_TYPE2_RECOVERY_TIME;
2181 * __ZFCP_WAIT_EVENT_TIMEOUT(timeout, 0);
2183 timeout = ZFCP_TYPE2_RECOVERY_TIME;
2184 set_current_state(TASK_UNINTERRUPTIBLE);
2185 schedule_timeout(timeout);
2196 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2197 * ZFCP_ERP_FAILED - action finished unsuccessfully
2200 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2204 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2205 &erp_action->adapter->status);
2206 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2207 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2208 &erp_action->adapter->status);
2218 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2219 * ZFCP_ERP_FAILED - action finished unsuccessfully
2222 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2226 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2227 &erp_action->adapter->status);
2228 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2229 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2230 &erp_action->adapter->status);
2236 * function: zfcp_register_adapter
2238 * purpose: allocate the irq associated with this devno and register
2239 * the FSF adapter with the SCSI stack
2244 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2246 int retval = ZFCP_ERP_SUCCEEDED;
2251 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2252 if (retval != ZFCP_ERP_SUCCEEDED)
2255 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2256 if (retval != ZFCP_ERP_SUCCEEDED)
2257 goto failed_openfcp;
2259 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2263 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2264 &erp_action->adapter->status);
2267 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2268 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2275 * function: zfcp_qdio_init
2277 * purpose: setup QDIO operation for specified adapter
2279 * returns: 0 - successful setup
2283 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2287 volatile struct qdio_buffer_element *sbale;
2288 struct zfcp_adapter *adapter = erp_action->adapter;
2289 int retval_cleanup = 0;
2291 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2292 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2294 zfcp_get_busid_by_adapter(adapter));
2298 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2299 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2301 zfcp_get_busid_by_adapter(adapter));
2302 goto failed_qdio_establish;
2304 ZFCP_LOG_DEBUG("queues established\n");
2306 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2307 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2309 zfcp_get_busid_by_adapter(adapter));
2310 goto failed_qdio_activate;
2312 ZFCP_LOG_DEBUG("queues activated\n");
2315 * put buffers into response queue,
2317 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2318 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2320 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2324 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2325 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2326 zfcp_get_busid_by_adapter(adapter),
2327 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2329 retval = do_QDIO(adapter->ccw_device,
2330 QDIO_FLAG_SYNC_INPUT,
2331 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2334 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2336 goto failed_do_qdio;
2338 adapter->response_queue.free_index = 0;
2339 atomic_set(&adapter->response_queue.free_count, 0);
2340 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2341 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2343 /* set index of first avalable SBALS / number of available SBALS */
2344 adapter->request_queue.free_index = 0;
2345 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2346 adapter->request_queue.distance_from_int = 0;
2348 /* initialize waitqueue used to wait for free SBALs in requests queue */
2349 init_waitqueue_head(&adapter->request_wq);
2351 /* ok, we did it - skip all cleanups for different failures */
2352 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2353 retval = ZFCP_ERP_SUCCEEDED;
2359 failed_qdio_activate:
2361 //__ZFCP_WAIT_EVENT_TIMEOUT(timeout, 0);
2362 /* cleanup queues previously established */
2363 retval_cleanup = qdio_shutdown(adapter->ccw_device,
2364 QDIO_FLAG_CLEANUP_USING_CLEAR);
2365 if (retval_cleanup) {
2366 ZFCP_LOG_NORMAL("bug: shutdown of QDIO queues failed "
2367 "(retval=%d)\n", retval_cleanup);
2370 failed_qdio_establish:
2371 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2374 retval = ZFCP_ERP_FAILED;
2381 * function: zfcp_qdio_cleanup
2383 * purpose: cleans up QDIO operation for the specified adapter
2385 * returns: 0 - successful cleanup
2386 * !0 - failed cleanup
2389 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2391 int retval = ZFCP_ERP_SUCCEEDED;
2394 struct zfcp_adapter *adapter = erp_action->adapter;
2396 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2397 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2398 "queues on adapter %s\n",
2399 zfcp_get_busid_by_adapter(adapter));
2400 retval = ZFCP_ERP_FAILED;
2404 /* cleanup queues previously established */
2407 * MUST NOT LOCK - qdio_cleanup might call schedule
2408 * FIXME: need another way to make cleanup safe
2411 * We need the request_queue lock here, otherwise there exists the
2414 * queuecommand calls create_fcp_commmand_task...calls req_create,
2415 * gets sbal x to x+y - meanwhile adapter reopen is called, completes
2416 * - req_send calls do_QDIO for sbal x to x+y, i.e. wrong indices.
2419 * queuecommand calls create_fcp_commmand_task...calls req_create,
2420 * gets sbal x to x+y - meanwhile adapter reopen is called, waits
2421 * - req_send calls do_QDIO for sbal x to x+y, i.e. wrong indices
2422 * but do_QDIO fails as adapter_reopen is still waiting for the lock
2424 * queuecommand calls create_fcp_commmand_task...calls req_create
2425 * - meanwhile adapter reopen is called...completes,
2426 * - gets sbal 0 to 0+y, - req_send calls do_QDIO for sbal 0 to 0+y,
2427 * i.e. correct indices...though an fcp command is called before
2428 * exchange config data...that should be fine, however
2430 if (qdio_shutdown(adapter->ccw_device, QDIO_FLAG_CLEANUP_USING_CLEAR)) {
2433 * What went wrong? What to do best? Proper retval?
2435 ZFCP_LOG_NORMAL("bug: shutdown of QDIO queues failed on "
2437 zfcp_get_busid_by_adapter(adapter));
2439 ZFCP_LOG_DEBUG("queues cleaned up\n");
2442 * First we had to stop QDIO operation.
2443 * Now it is safe to take the following actions.
2446 /* Cleanup only necessary when there are unacknowledged buffers */
2447 if (atomic_read(&adapter->request_queue.free_count)
2448 < QDIO_MAX_BUFFERS_PER_Q) {
2449 first_used = (adapter->request_queue.free_index +
2450 atomic_read(&adapter->request_queue.free_count))
2451 % QDIO_MAX_BUFFERS_PER_Q;
2452 used_count = QDIO_MAX_BUFFERS_PER_Q -
2453 atomic_read(&adapter->request_queue.free_count);
2454 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2455 first_used, used_count);
2457 adapter->response_queue.free_index = 0;
2458 atomic_set(&adapter->response_queue.free_count, 0);
2459 adapter->request_queue.free_index = 0;
2460 atomic_set(&adapter->request_queue.free_count, 0);
2461 adapter->request_queue.distance_from_int = 0;
2463 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2469 * function: zfcp_fsf_init
2471 * purpose: initializes FSF operation for the specified adapter
2473 * returns: 0 - succesful initialization of FSF operation
2474 * !0 - failed to initialize FSF operation
2477 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2481 /* do 'exchange configuration data' */
2482 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2483 if (retval == ZFCP_ERP_FAILED)
2486 /* start the desired number of Status Reads */
2487 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2499 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2501 int retval = ZFCP_ERP_SUCCEEDED;
2503 struct zfcp_adapter *adapter = erp_action->adapter;
2505 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2506 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2509 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2511 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2512 zfcp_erp_action_to_running(erp_action);
2513 zfcp_erp_timeout_init(erp_action);
2514 if (zfcp_fsf_exchange_config_data(erp_action)) {
2515 retval = ZFCP_ERP_FAILED;
2516 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2517 ZFCP_LOG_INFO("error: initiation of exchange of "
2518 "configuration data failed for "
2520 zfcp_get_busid_by_adapter(adapter));
2523 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2524 ZFCP_LOG_DEBUG("Xchange underway\n");
2528 * Both the normal completion handler as well as the timeout
2529 * handler will do an 'up' when the 'exchange config data'
2530 * request completes or times out. Thus, the signal to go on
2531 * won't be lost utilizing this semaphore.
2532 * Furthermore, this 'adapter_reopen' action is
2533 * guaranteed to be the only action being there (highest action
2534 * which prevents other actions from being created).
2535 * Resulting from that, the wake signal recognized here
2536 * _must_ be the one belonging to the 'exchange config
2539 down(&adapter->erp_ready_sem);
2540 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2541 ZFCP_LOG_INFO("error: exchange of configuration data "
2542 "for adapter %s timed out\n",
2543 zfcp_get_busid_by_adapter(adapter));
2546 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2547 &adapter->status)) {
2548 ZFCP_LOG_DEBUG("host connection still initialising... "
2549 "waiting and retrying...\n");
2550 /* sleep a little bit before retry */
2551 set_current_state(TASK_INTERRUPTIBLE);
2552 schedule_timeout(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP);
2554 } while ((retries--) &&
2555 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2558 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2559 &adapter->status)) {
2560 ZFCP_LOG_INFO("error: exchange of configuration data for "
2561 "adapter %s failed\n",
2562 zfcp_get_busid_by_adapter(adapter));
2563 retval = ZFCP_ERP_FAILED;
2577 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2580 int retval = ZFCP_ERP_SUCCEEDED;
2582 struct zfcp_adapter *adapter = erp_action->adapter;
2585 adapter->status_read_failed = 0;
2586 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2587 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2589 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2590 "notification failed on adapter %s\n",
2591 zfcp_get_busid_by_adapter(adapter));
2592 retval = ZFCP_ERP_FAILED;
2602 * function: zfcp_fsf_cleanup
2604 * purpose: cleanup FSF operation for specified adapter
2606 * returns: 0 - FSF operation successfully cleaned up
2607 * !0 - failed to cleanup FSF operation for this adapter
2610 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2612 int retval = ZFCP_ERP_SUCCEEDED;
2613 struct zfcp_adapter *adapter = erp_action->adapter;
2616 * wake waiting initiators of requests,
2617 * return SCSI commands (with error status),
2618 * clean up all requests (synchronously)
2620 zfcp_fsf_req_dismiss_all(adapter);
2621 /* reset FSF request sequence number */
2622 adapter->fsf_req_seq_no = 0;
2623 /* all ports and units are closed */
2624 zfcp_erp_modify_adapter_status(adapter,
2625 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2633 * purpose: this routine executes the 'Reopen Physical Port' action
2635 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2636 * ZFCP_ERP_SUCCEEDED - action finished successfully
2637 * ZFCP_ERP_FAILED - action finished unsuccessfully
2640 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2642 int retval = ZFCP_ERP_FAILED;
2643 struct zfcp_port *port = erp_action->port;
2644 struct zfcp_adapter *adapter = erp_action->adapter;
2646 switch (erp_action->step) {
2650 * the ULP spec. begs for waiting for oustanding commands
2652 case ZFCP_ERP_STEP_UNINITIALIZED:
2653 zfcp_erp_port_strategy_clearstati(port);
2655 * it would be sufficient to test only the normal open flag
2656 * since the phys. open flag cannot be set if the normal
2657 * open flag is unset - however, this is for readabilty ...
2659 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2660 ZFCP_STATUS_COMMON_OPEN),
2662 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2663 "close physical\n", port->wwpn);
2665 zfcp_erp_port_forced_strategy_close(erp_action);
2667 retval = ZFCP_ERP_FAILED;
2670 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2671 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2673 ZFCP_LOG_DEBUG("close physical failed for port "
2674 "0x%016Lx\n", port->wwpn);
2675 retval = ZFCP_ERP_FAILED;
2677 retval = ZFCP_ERP_SUCCEEDED;
2681 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2682 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2683 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2684 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2692 * purpose: this routine executes the 'Reopen Port' action
2694 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2695 * ZFCP_ERP_SUCCEEDED - action finished successfully
2696 * ZFCP_ERP_FAILED - action finished unsuccessfully
2699 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2701 int retval = ZFCP_ERP_FAILED;
2702 struct zfcp_port *port = erp_action->port;
2703 struct zfcp_adapter *adapter = erp_action->adapter;
2705 switch (erp_action->step) {
2709 * the ULP spec. begs for waiting for oustanding commands
2711 case ZFCP_ERP_STEP_UNINITIALIZED:
2712 zfcp_erp_port_strategy_clearstati(port);
2713 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2714 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2715 "close\n", port->wwpn);
2716 retval = zfcp_erp_port_strategy_close(erp_action);
2718 } /* else it's already closed, open it */
2721 case ZFCP_ERP_STEP_PORT_CLOSING:
2722 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2723 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2725 retval = ZFCP_ERP_FAILED;
2727 } /* else it's closed now, open it */
2730 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2731 retval = ZFCP_ERP_EXIT;
2733 retval = zfcp_erp_port_strategy_open(erp_action);
2736 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2737 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2738 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2739 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2752 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2756 if (atomic_test_mask(ZFCP_STATUS_PORT_NAMESERVER,
2757 &erp_action->port->status))
2758 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2760 retval = zfcp_erp_port_strategy_open_common(erp_action);
2772 * FIXME(design): currently only prepared for fabric (nameserver!)
2775 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2778 struct zfcp_adapter *adapter = erp_action->adapter;
2779 struct zfcp_port *port = erp_action->port;
2781 switch (erp_action->step) {
2783 case ZFCP_ERP_STEP_UNINITIALIZED:
2784 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2785 case ZFCP_ERP_STEP_PORT_CLOSING:
2786 if (!(adapter->nameserver_port)) {
2787 retval = zfcp_nameserver_enqueue(adapter);
2789 ZFCP_LOG_NORMAL("error: nameserver port "
2790 "unavailable for adapter %s\n",
2791 zfcp_get_busid_by_adapter(adapter));
2792 retval = ZFCP_ERP_FAILED;
2796 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2797 &adapter->nameserver_port->status)) {
2798 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2799 "nameserver port\n");
2800 /* nameserver port may live again */
2801 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2802 &adapter->nameserver_port->status);
2803 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0) >= 0) {
2804 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_OPEN;
2805 retval = ZFCP_ERP_CONTINUES;
2806 } else retval = ZFCP_ERP_FAILED;
2809 /* else nameserver port is already open, fall through */
2810 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2811 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2812 &adapter->nameserver_port->status)) {
2813 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2814 retval = ZFCP_ERP_FAILED;
2816 ZFCP_LOG_DEBUG("nameserver port is open -> "
2817 "nameserver look-up for port 0x%016Lx\n",
2819 retval = zfcp_erp_port_strategy_open_common_lookup
2824 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2825 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2826 if (atomic_test_mask
2827 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2828 ZFCP_LOG_DEBUG("nameserver look-up failed "
2829 "for port 0x%016Lx "
2830 "(misconfigured WWPN?)\n",
2832 zfcp_erp_port_failed(port);
2833 retval = ZFCP_ERP_EXIT;
2835 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2836 "port 0x%016Lx\n", port->wwpn);
2837 retval = ZFCP_ERP_FAILED;
2840 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2841 "trying open\n", port->wwpn, port->d_id);
2842 retval = zfcp_erp_port_strategy_open_port(erp_action);
2846 case ZFCP_ERP_STEP_PORT_OPENING:
2847 /* D_ID might have changed during open */
2848 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2849 ZFCP_STATUS_PORT_DID_DID),
2851 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2852 retval = ZFCP_ERP_SUCCEEDED;
2854 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2856 retval = ZFCP_ERP_FAILED;
2861 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2863 retval = ZFCP_ERP_FAILED;
2877 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2880 struct zfcp_port *port = erp_action->port;
2882 switch (erp_action->step) {
2884 case ZFCP_ERP_STEP_UNINITIALIZED:
2885 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2886 case ZFCP_ERP_STEP_PORT_CLOSING:
2887 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2888 port->wwpn, port->d_id);
2889 retval = zfcp_erp_port_strategy_open_port(erp_action);
2892 case ZFCP_ERP_STEP_PORT_OPENING:
2893 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2894 ZFCP_LOG_DEBUG("nameserver port is open\n");
2895 retval = ZFCP_ERP_SUCCEEDED;
2897 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2898 retval = ZFCP_ERP_FAILED;
2900 /* this is needed anyway (dont care for retval of wakeup) */
2901 ZFCP_LOG_DEBUG("continue other open port operations\n");
2902 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2906 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2908 retval = ZFCP_ERP_FAILED;
2917 * purpose: makes the erp thread continue with reopen (physical) port
2918 * actions which have been paused until the name server port
2919 * is opened (or failed)
2921 * returns: 0 (a kind of void retval, its not used)
2924 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2928 unsigned long flags;
2929 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2930 struct zfcp_erp_action *erp_action, *tmp;
2932 read_lock_irqsave(&adapter->erp_lock, flags);
2933 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2935 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2936 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2938 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2939 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2940 debug_event(adapter->erp_dbf, 3,
2941 &erp_action->port->wwpn, sizeof (wwn_t));
2942 if (atomic_test_mask(
2943 ZFCP_STATUS_COMMON_ERP_FAILED,
2944 &adapter->nameserver_port->status))
2945 zfcp_erp_port_failed(erp_action->port);
2946 zfcp_erp_action_ready(erp_action);
2949 read_unlock_irqrestore(&adapter->erp_lock, flags);
2959 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2960 * ZFCP_ERP_FAILED - action finished unsuccessfully
2963 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2966 struct zfcp_adapter *adapter = erp_action->adapter;
2967 struct zfcp_port *port = erp_action->port;
2969 zfcp_erp_timeout_init(erp_action);
2970 retval = zfcp_fsf_close_physical_port(erp_action);
2971 if (retval == -ENOMEM) {
2972 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2973 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2974 retval = ZFCP_ERP_NOMEM;
2977 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2979 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2980 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2981 /* could not send 'open', fail */
2982 retval = ZFCP_ERP_FAILED;
2985 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2986 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2987 retval = ZFCP_ERP_CONTINUES;
3000 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
3003 struct zfcp_adapter *adapter = port->adapter;
3005 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
3006 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3008 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3009 ZFCP_STATUS_COMMON_CLOSING |
3010 ZFCP_STATUS_PORT_DID_DID |
3011 ZFCP_STATUS_PORT_PHYS_CLOSING |
3012 ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
3021 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3022 * ZFCP_ERP_FAILED - action finished unsuccessfully
3025 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
3028 struct zfcp_adapter *adapter = erp_action->adapter;
3029 struct zfcp_port *port = erp_action->port;
3031 zfcp_erp_timeout_init(erp_action);
3032 retval = zfcp_fsf_close_port(erp_action);
3033 if (retval == -ENOMEM) {
3034 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
3035 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3036 retval = ZFCP_ERP_NOMEM;
3039 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
3041 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
3042 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3043 /* could not send 'close', fail */
3044 retval = ZFCP_ERP_FAILED;
3047 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
3048 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3049 retval = ZFCP_ERP_CONTINUES;
3059 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3060 * ZFCP_ERP_FAILED - action finished unsuccessfully
3063 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
3066 struct zfcp_adapter *adapter = erp_action->adapter;
3067 struct zfcp_port *port = erp_action->port;
3069 zfcp_erp_timeout_init(erp_action);
3070 retval = zfcp_fsf_open_port(erp_action);
3071 if (retval == -ENOMEM) {
3072 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
3073 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3074 retval = ZFCP_ERP_NOMEM;
3077 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
3079 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
3080 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3081 /* could not send 'open', fail */
3082 retval = ZFCP_ERP_FAILED;
3085 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
3086 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3087 retval = ZFCP_ERP_CONTINUES;
3097 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3098 * ZFCP_ERP_FAILED - action finished unsuccessfully
3101 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
3104 struct zfcp_adapter *adapter = erp_action->adapter;
3105 struct zfcp_port *port = erp_action->port;
3107 zfcp_erp_timeout_init(erp_action);
3108 retval = zfcp_ns_gid_pn_request(erp_action);
3109 if (retval == -ENOMEM) {
3110 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
3111 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3112 retval = ZFCP_ERP_NOMEM;
3115 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
3117 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
3118 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3119 /* could not send nameserver request, fail */
3120 retval = ZFCP_ERP_FAILED;
3123 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3124 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3125 retval = ZFCP_ERP_CONTINUES;
3133 * purpose: this routine executes the 'Reopen Unit' action
3134 * currently no retries
3136 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3137 * ZFCP_ERP_SUCCEEDED - action finished successfully
3138 * ZFCP_ERP_FAILED - action finished unsuccessfully
3141 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3143 int retval = ZFCP_ERP_FAILED;
3144 struct zfcp_unit *unit = erp_action->unit;
3145 struct zfcp_adapter *adapter = erp_action->adapter;
3147 switch (erp_action->step) {
3151 * the ULP spec. begs for waiting for oustanding commands
3153 case ZFCP_ERP_STEP_UNINITIALIZED:
3154 zfcp_erp_unit_strategy_clearstati(unit);
3155 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3156 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3157 "trying close\n", unit->fcp_lun);
3158 retval = zfcp_erp_unit_strategy_close(erp_action);
3161 /* else it's already closed, fall through */
3162 case ZFCP_ERP_STEP_UNIT_CLOSING:
3163 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3164 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3166 retval = ZFCP_ERP_FAILED;
3168 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3169 retval = ZFCP_ERP_EXIT;
3171 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3172 "trying open\n", unit->fcp_lun);
3174 zfcp_erp_unit_strategy_open(erp_action);
3179 case ZFCP_ERP_STEP_UNIT_OPENING:
3180 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3181 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3183 retval = ZFCP_ERP_SUCCEEDED;
3185 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3187 retval = ZFCP_ERP_FAILED;
3192 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3193 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3194 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3195 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3207 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3210 struct zfcp_adapter *adapter = unit->port->adapter;
3212 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3213 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3215 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3216 ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3226 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3227 * ZFCP_ERP_FAILED - action finished unsuccessfully
3230 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3233 struct zfcp_adapter *adapter = erp_action->adapter;
3234 struct zfcp_unit *unit = erp_action->unit;
3236 zfcp_erp_timeout_init(erp_action);
3237 retval = zfcp_fsf_close_unit(erp_action);
3238 if (retval == -ENOMEM) {
3239 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3240 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3241 sizeof (fcp_lun_t));
3242 retval = ZFCP_ERP_NOMEM;
3245 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3247 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3248 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3249 sizeof (fcp_lun_t));
3250 /* could not send 'close', fail */
3251 retval = ZFCP_ERP_FAILED;
3254 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3255 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3256 retval = ZFCP_ERP_CONTINUES;
3267 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3268 * ZFCP_ERP_FAILED - action finished unsuccessfully
3271 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3274 struct zfcp_adapter *adapter = erp_action->adapter;
3275 struct zfcp_unit *unit = erp_action->unit;
3277 zfcp_erp_timeout_init(erp_action);
3278 retval = zfcp_fsf_open_unit(erp_action);
3279 if (retval == -ENOMEM) {
3280 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3281 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3282 sizeof (fcp_lun_t));
3283 retval = ZFCP_ERP_NOMEM;
3286 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3288 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3289 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3290 sizeof (fcp_lun_t));
3291 /* could not send 'open', fail */
3292 retval = ZFCP_ERP_FAILED;
3295 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3296 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3297 retval = ZFCP_ERP_CONTINUES;
3310 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3312 init_timer(&erp_action->timer);
3313 erp_action->timer.function = zfcp_erp_timeout_handler;
3314 erp_action->timer.data = (unsigned long) erp_action;
3315 /* jiffies will be added in zfcp_fsf_req_send */
3316 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3322 * purpose: enqueue the specified error recovery action, if needed
3327 zfcp_erp_action_enqueue(int action,
3328 struct zfcp_adapter *adapter,
3329 struct zfcp_port *port, struct zfcp_unit *unit)
3332 struct zfcp_erp_action *erp_action = NULL;
3333 int stronger_action = 0;
3337 * We need some rules here which check whether we really need
3338 * this action or whether we should just drop it.
3339 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3340 * 'Reopen Unit' request for an associated unit since we can't
3341 * satisfy this request now. A 'Reopen Port' action will trigger
3342 * 'Reopen Unit' actions when it completes.
3343 * Thus, there are only actions in the queue which can immediately be
3344 * executed. This makes the processing of the action queue more
3348 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3352 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3353 /* check whether we really need this */
3355 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3356 if (atomic_test_mask
3357 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3358 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3359 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3361 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3362 sizeof (fcp_lun_t));
3365 if (!atomic_test_mask
3366 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3368 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3371 if (!atomic_test_mask
3372 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3373 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3376 /* fall through !!! */
3378 case ZFCP_ERP_ACTION_REOPEN_PORT:
3379 if (atomic_test_mask
3380 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3381 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3382 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3386 /* fall through !!! */
3388 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3389 if (atomic_test_mask
3390 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3391 && port->erp_action.action ==
3392 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3393 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3394 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3398 if (!atomic_test_mask
3399 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3401 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3404 if (!atomic_test_mask
3405 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3406 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3409 /* fall through !!! */
3411 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3412 if (atomic_test_mask
3413 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3414 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3420 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3421 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3422 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3423 "on adapter %s (action=%d)\n",
3424 zfcp_get_busid_by_adapter(adapter), action);
3428 /* check whether we need something stronger first */
3429 if (stronger_action) {
3430 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3431 debug_event(adapter->erp_dbf, 4, &stronger_action,
3433 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3434 "erp action %d on adapter %s\n",
3435 stronger_action, action,
3436 zfcp_get_busid_by_adapter(adapter));
3437 action = stronger_action;
3440 /* mark adapter to have some error recovery pending */
3441 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3443 /* setup error recovery action */
3446 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3447 zfcp_unit_get(unit);
3448 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3449 erp_action = &unit->erp_action;
3450 if (!atomic_test_mask
3451 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3452 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3455 case ZFCP_ERP_ACTION_REOPEN_PORT:
3456 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3457 zfcp_port_get(port);
3458 zfcp_erp_action_dismiss_port(port);
3459 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3460 erp_action = &port->erp_action;
3461 if (!atomic_test_mask
3462 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3463 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3466 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3467 zfcp_adapter_get(adapter);
3468 zfcp_erp_action_dismiss_adapter(adapter);
3469 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3470 erp_action = &adapter->erp_action;
3471 if (!atomic_test_mask
3472 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3473 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3477 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3479 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3480 erp_action->adapter = adapter;
3481 erp_action->port = port;
3482 erp_action->unit = unit;
3483 erp_action->action = action;
3484 erp_action->status = status;
3486 ++adapter->erp_total_count;
3488 /* finally put it into 'ready' queue and kick erp thread */
3489 list_add(&erp_action->list, &adapter->erp_ready_head);
3490 up(&adapter->erp_ready_sem);
3504 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3507 struct zfcp_adapter *adapter = erp_action->adapter;
3509 --adapter->erp_total_count;
3510 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3511 --adapter->erp_low_mem_count;
3512 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3515 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3516 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3517 list_del(&erp_action->list);
3518 switch (erp_action->action) {
3519 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3520 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3521 &erp_action->unit->status);
3523 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3524 case ZFCP_ERP_ACTION_REOPEN_PORT:
3525 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3526 &erp_action->port->status);
3528 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3529 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3530 &erp_action->adapter->status);
3540 * zfcp_erp_action_cleanup
3542 * registers unit with scsi stack if appropiate and fixes reference counts
3546 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3547 struct zfcp_port *port, struct zfcp_unit *unit,
3550 if ((action == ZFCP_ERP_ACTION_REOPEN_UNIT)
3551 && (result == ZFCP_ERP_SUCCEEDED)
3552 && (!unit->device)) {
3553 zfcp_erp_schedule_work(unit);
3556 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3557 zfcp_unit_put(unit);
3559 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3560 case ZFCP_ERP_ACTION_REOPEN_PORT:
3561 zfcp_port_put(port);
3563 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3564 zfcp_adapter_put(adapter);
3580 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3583 struct zfcp_port *port;
3585 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3586 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3587 zfcp_erp_action_dismiss(&adapter->erp_action);
3589 list_for_each_entry(port, &adapter->port_list_head, list)
3590 zfcp_erp_action_dismiss_port(port);
3603 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3606 struct zfcp_unit *unit;
3607 struct zfcp_adapter *adapter = port->adapter;
3609 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3610 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3611 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3612 zfcp_erp_action_dismiss(&port->erp_action);
3614 list_for_each_entry(unit, &port->unit_list_head, list)
3615 zfcp_erp_action_dismiss_unit(unit);
3628 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3631 struct zfcp_adapter *adapter = unit->port->adapter;
3633 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3634 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3635 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3636 zfcp_erp_action_dismiss(&unit->erp_action);
3644 * purpose: moves erp_action to 'erp running list'
3649 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3651 struct zfcp_adapter *adapter = erp_action->adapter;
3653 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3654 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3655 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3661 * purpose: moves erp_action to 'erp ready list'
3666 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3668 struct zfcp_adapter *adapter = erp_action->adapter;
3670 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3671 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3672 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3675 #undef ZFCP_LOG_AREA