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.65 $"
38 static int zfcp_els(struct zfcp_port *, u8);
39 static void zfcp_els_handler(unsigned long);
41 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
42 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
43 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
44 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
46 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
47 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
49 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
50 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
51 static void zfcp_erp_port_block(struct zfcp_port *, int);
52 static void zfcp_erp_port_unblock(struct zfcp_port *);
53 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
54 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
56 static int zfcp_erp_thread(void *);
58 static int zfcp_erp_strategy(struct zfcp_erp_action *);
60 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
61 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
62 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
63 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
65 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
66 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
68 struct zfcp_unit *, int);
69 static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
70 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
72 struct zfcp_unit *, int);
73 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
74 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
76 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
77 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
78 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
79 static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
80 static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
81 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
83 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
84 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
85 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
86 struct zfcp_erp_action *);
88 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
89 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
91 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
92 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
93 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
94 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
95 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
96 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
97 struct zfcp_erp_action *);
98 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
99 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
100 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
102 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
103 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
104 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
105 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
107 static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
108 static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
109 static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
110 static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
112 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
113 struct zfcp_port *, struct zfcp_unit *);
114 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
115 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
116 struct zfcp_port *, struct zfcp_unit *,
119 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
120 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
122 static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
123 static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
125 static void zfcp_erp_memwait_handler(unsigned long);
126 static void zfcp_erp_timeout_handler(unsigned long);
127 static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
130 * zfcp_fsf_request_timeout_handler - called if a request timed out
131 * @data: pointer to adapter for handler function
133 * This function needs to be called if requests (ELS, Generic Service,
134 * or SCSI commands) exceed a certain time limit. The assumption is
135 * that after the time limit the adapter get stuck. So we trigger a reopen of
136 * the adapter. This should not be used for error recovery, SCSI abort
137 * commands and SCSI requests from SCSI mid-layer.
140 zfcp_fsf_request_timeout_handler(unsigned long data)
142 struct zfcp_adapter *adapter;
144 adapter = (struct zfcp_adapter *) data;
146 zfcp_erp_adapter_reopen(adapter, 0);
150 * function: zfcp_fsf_scsi_er_timeout_handler
152 * purpose: This function needs to be called whenever a SCSI error recovery
153 * action (abort/reset) does not return.
154 * Re-opening the adapter means that the command can be returned
155 * by zfcp (it is guarranteed that it does not return via the
156 * adapter anymore). The buffer can then be used again.
161 zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
163 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
165 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
166 "Restarting all operations on the adapter %s\n",
167 zfcp_get_busid_by_adapter(adapter));
168 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
169 zfcp_erp_adapter_reopen(adapter, 0);
177 * purpose: called if an adapter failed,
178 * initiates adapter recovery which is done
181 * returns: 0 - initiated action succesfully
182 * <0 - failed to initiate action
185 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
189 debug_text_event(adapter->erp_dbf, 5, "a_ro");
190 ZFCP_LOG_DEBUG("reopen adapter %s\n",
191 zfcp_get_busid_by_adapter(adapter));
193 zfcp_erp_adapter_block(adapter, clear_mask);
195 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
196 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
197 zfcp_get_busid_by_adapter(adapter));
198 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
199 /* ensure propagation of failed status to new devices */
200 zfcp_erp_adapter_failed(adapter);
204 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
205 adapter, NULL, NULL);
214 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
215 * used to ensure the correct locking
217 * returns: 0 - initiated action succesfully
218 * <0 - failed to initiate action
221 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
226 read_lock_irqsave(&zfcp_data.config_lock, flags);
227 write_lock(&adapter->erp_lock);
228 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
229 write_unlock(&adapter->erp_lock);
230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
243 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
247 retval = zfcp_erp_adapter_reopen(adapter,
248 ZFCP_STATUS_COMMON_RUNNING |
249 ZFCP_STATUS_COMMON_ERP_FAILED |
263 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
267 retval = zfcp_erp_port_reopen(port,
268 ZFCP_STATUS_COMMON_RUNNING |
269 ZFCP_STATUS_COMMON_ERP_FAILED |
283 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
287 retval = zfcp_erp_unit_reopen(unit,
288 ZFCP_STATUS_COMMON_RUNNING |
289 ZFCP_STATUS_COMMON_ERP_FAILED |
299 * purpose: Originator of the ELS commands
301 * returns: 0 - Operation completed successfuly
302 * -EINVAL - Unknown IOCTL command or invalid sense data record
303 * -ENOMEM - Insufficient memory
304 * -EPERM - Cannot create or queue FSF request
307 zfcp_els(struct zfcp_port *port, u8 ls_code)
309 struct zfcp_send_els *send_els;
310 struct zfcp_ls_rls *rls;
311 struct zfcp_ls_pdisc *pdisc;
312 struct zfcp_ls_adisc *adisc;
313 struct page *page = NULL;
317 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
318 if (send_els == NULL)
321 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
322 if (send_els->req == NULL)
324 send_els->req_count = 1;
326 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
327 if (send_els->resp == NULL)
329 send_els->resp_count = 1;
331 page = alloc_pages(GFP_ATOMIC, 0);
334 send_els->req->page = page;
335 send_els->resp->page = page;
336 send_els->req->offset = 0;
337 send_els->resp->offset = PAGE_SIZE >> 1;
339 send_els->port = port;
340 send_els->ls_code = ls_code;
341 send_els->handler = zfcp_els_handler;
342 send_els->handler_data = (unsigned long)send_els;
343 send_els->completion = NULL;
345 req = zfcp_sg_to_address(send_els->req);
346 memset(req, 0, PAGE_SIZE);
354 send_els->req->length = sizeof(struct zfcp_ls_rtv);
355 send_els->resp->length = sizeof(struct zfcp_ls_rtv_acc);
356 ZFCP_LOG_INFO("RTV request from s_id 0x%08x to d_id 0x%08x\n",
357 port->adapter->s_id, port->d_id);
361 send_els->req->length = sizeof(struct zfcp_ls_rls);
362 send_els->resp->length = sizeof(struct zfcp_ls_rls_acc);
363 rls = (struct zfcp_ls_rls*)req;
364 rls->port_id = port->adapter->s_id;
365 ZFCP_LOG_INFO("RLS request from s_id 0x%08x to d_id 0x%08x "
366 "(port_id=0x%08x)\n",
367 port->adapter->s_id, port->d_id, rls->port_id);
371 send_els->req->length = sizeof(struct zfcp_ls_pdisc);
372 send_els->resp->length = sizeof(struct zfcp_ls_pdisc_acc);
373 pdisc = (struct zfcp_ls_pdisc*)req;
374 pdisc->wwpn = port->adapter->wwpn;
375 pdisc->wwnn = port->adapter->wwnn;
376 ZFCP_LOG_INFO("PDISC request from s_id 0x%08x to d_id 0x%08x "
377 "(wwpn=0x%016Lx, wwnn=0x%016Lx)\n",
378 port->adapter->s_id, port->d_id,
379 pdisc->wwpn, pdisc->wwnn);
383 send_els->req->length = sizeof(struct zfcp_ls_adisc);
384 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
385 adisc = (struct zfcp_ls_adisc*)req;
386 adisc->hard_nport_id = port->adapter->s_id;
387 adisc->wwpn = port->adapter->wwpn;
388 adisc->wwnn = port->adapter->wwnn;
389 adisc->nport_id = port->adapter->s_id;
390 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
391 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
392 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
393 port->adapter->s_id, port->d_id,
394 adisc->wwpn, adisc->wwnn,
395 adisc->hard_nport_id, adisc->nport_id);
399 ZFCP_LOG_NORMAL("ELS command code 0x%02x is not supported\n",
402 goto invalid_ls_code;
405 retval = zfcp_fsf_send_els(send_els);
407 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
408 "0x%016Lx on adapter %s\n",
409 port->wwpn, zfcp_get_busid_by_port(port));
416 ZFCP_LOG_DEBUG("out of memory\n");
421 __free_pages(page, 0);
422 if (send_els != NULL) {
423 if (send_els->req != NULL)
424 kfree(send_els->req);
425 if (send_els->resp != NULL)
426 kfree(send_els->resp);
436 * zfcp_els_handler - handler for ELS commands
437 * @data: pointer to struct zfcp_send_els
438 * If ELS failed (LS_RJT or timed out) forced reopen of the port is triggered.
441 zfcp_els_handler(unsigned long data)
443 struct zfcp_send_els *send_els = (struct zfcp_send_els*)data;
444 struct zfcp_port *port = send_els->port;
445 struct zfcp_ls_rtv_acc *rtv;
446 struct zfcp_ls_rls_acc *rls;
447 struct zfcp_ls_pdisc_acc *pdisc;
448 struct zfcp_ls_adisc_acc *adisc;
452 /* request rejected or timed out */
453 if (send_els->status != 0) {
454 ZFCP_LOG_NORMAL("ELS request timed out, force physical port "
455 "reopen of port 0x%016Lx on adapter %s\n",
456 port->wwpn, zfcp_get_busid_by_port(port));
457 debug_text_event(port->adapter->erp_dbf, 3, "forcreop");
458 if (zfcp_erp_port_forced_reopen(port, 0))
459 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
460 "on adapter %s failed\n", port->wwpn,
461 zfcp_get_busid_by_port(port));
465 req = zfcp_sg_to_address(send_els->req);
466 resp = zfcp_sg_to_address(send_els->resp);
467 req_code = *(u8*)req;
472 rtv = (struct zfcp_ls_rtv_acc*)resp;
473 ZFCP_LOG_INFO("RTV response from d_id 0x%08x to s_id "
474 "0x%08x (R_A_TOV=%ds E_D_TOV=%d%cs)\n",
475 port->d_id, port->adapter->s_id,
476 rtv->r_a_tov, rtv->e_d_tov,
478 ZFCP_LS_RTV_E_D_TOV_FLAG ? 'n' : 'm');
482 rls = (struct zfcp_ls_rls_acc*)resp;
483 ZFCP_LOG_INFO("RLS response from d_id 0x%08x to s_id "
484 "0x%08x (link_failure_count=%u, "
485 "loss_of_sync_count=%u, "
486 "loss_of_signal_count=%u, "
487 "primitive_sequence_protocol_error=%u, "
488 "invalid_transmition_word=%u, "
489 "invalid_crc_count=%u)\n",
490 port->d_id, port->adapter->s_id,
491 rls->link_failure_count,
492 rls->loss_of_sync_count,
493 rls->loss_of_signal_count,
494 rls->prim_seq_prot_error,
495 rls->invalid_transmition_word,
496 rls->invalid_crc_count);
500 pdisc = (struct zfcp_ls_pdisc_acc*)resp;
501 ZFCP_LOG_INFO("PDISC response from d_id 0x%08x to s_id "
502 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
503 "vendor='%-16s')\n", port->d_id,
504 port->adapter->s_id, pdisc->wwpn,
505 pdisc->wwnn, pdisc->vendor_version);
509 adisc = (struct zfcp_ls_adisc_acc*)resp;
510 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
511 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
512 "hard_nport_id=0x%08x, "
513 "nport_id=0x%08x)\n", port->d_id,
514 port->adapter->s_id, adisc->wwpn,
515 adisc->wwnn, adisc->hard_nport_id,
517 /* FIXME: set wwnn in during open port */
519 port->wwnn = adisc->wwnn;
524 __free_pages(send_els->req->page, 0);
525 kfree(send_els->req);
526 kfree(send_els->resp);
532 * function: zfcp_test_link
534 * purpose: Test a status of a link to a remote port using the ELS command ADISC
536 * returns: 0 - Link is OK
537 * -EPERM - Port forced reopen failed
540 zfcp_test_link(struct zfcp_port *port)
544 retval = zfcp_els(port, ZFCP_LS_ADISC);
546 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
547 "on adapter %s\n ", port->wwpn,
548 zfcp_get_busid_by_port(port));
549 retval = zfcp_erp_port_forced_reopen(port, 0);
551 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
552 "on adapter %s failed\n", port->wwpn,
553 zfcp_get_busid_by_port(port));
565 * purpose: called if a port failed to be opened normally
566 * initiates Forced Reopen recovery which is done
569 * returns: 0 - initiated action succesfully
570 * <0 - failed to initiate action
573 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
576 struct zfcp_adapter *adapter = port->adapter;
578 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
579 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
581 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
582 port->wwpn, zfcp_get_busid_by_port(port));
584 zfcp_erp_port_block(port, clear_mask);
586 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
587 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
588 "on adapter %s\n", port->wwpn,
589 zfcp_get_busid_by_port(port));
590 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
591 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
596 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
597 port->adapter, port, NULL);
606 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
607 * used to ensure the correct locking
609 * returns: 0 - initiated action succesfully
610 * <0 - failed to initiate action
613 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
617 struct zfcp_adapter *adapter;
619 adapter = port->adapter;
620 read_lock_irqsave(&zfcp_data.config_lock, flags);
621 write_lock(&adapter->erp_lock);
622 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
623 write_unlock(&adapter->erp_lock);
624 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
632 * purpose: called if a port is to be opened
633 * initiates Reopen recovery which is done
636 * returns: 0 - initiated action succesfully
637 * <0 - failed to initiate action
640 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
643 struct zfcp_adapter *adapter = port->adapter;
645 debug_text_event(adapter->erp_dbf, 5, "p_ro");
646 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
648 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
649 port->wwpn, zfcp_get_busid_by_port(port));
651 zfcp_erp_port_block(port, clear_mask);
653 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
654 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
655 "on adapter %s\n", port->wwpn,
656 zfcp_get_busid_by_port(port));
657 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
658 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
659 /* ensure propagation of failed status to new devices */
660 zfcp_erp_port_failed(port);
665 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
666 port->adapter, port, NULL);
673 * zfcp_erp_port_reopen - initiate reopen of a remote port
674 * @port: port to be reopened
675 * @clear_mask: specifies flags in port status to be cleared
676 * Return: 0 on success, < 0 on error
678 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
679 * correct locking. An error recovery task is initiated to do the reopen.
680 * To wait for the completion of the reopen zfcp_erp_wait should be used.
683 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
687 struct zfcp_adapter *adapter = port->adapter;
689 read_lock_irqsave(&zfcp_data.config_lock, flags);
690 write_lock(&adapter->erp_lock);
691 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
692 write_unlock(&adapter->erp_lock);
693 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
701 * purpose: called if a unit is to be opened
702 * initiates Reopen recovery which is done
705 * returns: 0 - initiated action succesfully
706 * <0 - failed to initiate action
709 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
712 struct zfcp_adapter *adapter = unit->port->adapter;
714 debug_text_event(adapter->erp_dbf, 5, "u_ro");
715 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
716 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
717 "on adapter %s\n", unit->fcp_lun,
718 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
720 zfcp_erp_unit_block(unit, clear_mask);
722 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
723 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
724 "on port 0x%016Lx on adapter %s\n",
725 unit->fcp_lun, unit->port->wwpn,
726 zfcp_get_busid_by_unit(unit));
727 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
728 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
734 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
735 unit->port->adapter, unit->port, unit);
741 * zfcp_erp_unit_reopen - initiate reopen of a unit
742 * @unit: unit to be reopened
743 * @clear_mask: specifies flags in unit status to be cleared
744 * Return: 0 on success, < 0 on error
746 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
747 * locking. An error recovery task is initiated to do the reopen.
748 * To wait for the completion of the reopen zfcp_erp_wait should be used.
751 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
755 struct zfcp_adapter *adapter;
756 struct zfcp_port *port;
759 adapter = port->adapter;
761 read_lock_irqsave(&zfcp_data.config_lock, flags);
762 write_lock(&adapter->erp_lock);
763 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
764 write_unlock(&adapter->erp_lock);
765 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
773 * purpose: disable I/O,
774 * return any open requests and clean them up,
775 * aim: no pending and incoming I/O
780 zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
782 debug_text_event(adapter->erp_dbf, 6, "a_bl");
783 zfcp_erp_modify_adapter_status(adapter,
784 ZFCP_STATUS_COMMON_UNBLOCKED |
785 clear_mask, ZFCP_CLEAR);
791 * purpose: enable I/O
796 zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
798 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
799 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
805 * purpose: disable I/O,
806 * return any open requests and clean them up,
807 * aim: no pending and incoming I/O
812 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
814 struct zfcp_adapter *adapter = port->adapter;
816 debug_text_event(adapter->erp_dbf, 6, "p_bl");
817 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
818 zfcp_erp_modify_port_status(port,
819 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
826 * purpose: enable I/O
831 zfcp_erp_port_unblock(struct zfcp_port *port)
833 struct zfcp_adapter *adapter = port->adapter;
835 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
836 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
837 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
843 * purpose: disable I/O,
844 * return any open requests and clean them up,
845 * aim: no pending and incoming I/O
850 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
852 struct zfcp_adapter *adapter = unit->port->adapter;
854 debug_text_event(adapter->erp_dbf, 6, "u_bl");
855 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
856 zfcp_erp_modify_unit_status(unit,
857 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
864 * purpose: enable I/O
869 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
871 struct zfcp_adapter *adapter = unit->port->adapter;
873 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
874 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
875 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
886 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
888 struct zfcp_adapter *adapter = erp_action->adapter;
890 debug_text_event(adapter->erp_dbf, 4, "a_ar");
891 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
893 zfcp_erp_action_to_ready(erp_action);
894 up(&adapter->erp_ready_sem);
902 * returns: <0 erp_action not found in any list
903 * ZFCP_ERP_ACTION_READY erp_action is in ready list
904 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
906 * locks: erp_lock must be held
909 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
911 int retval = -EINVAL;
912 struct list_head *entry;
913 struct zfcp_erp_action *entry_erp_action;
914 struct zfcp_adapter *adapter = erp_action->adapter;
916 /* search in running list */
917 list_for_each(entry, &adapter->erp_running_head) {
919 list_entry(entry, struct zfcp_erp_action, list);
920 if (entry_erp_action == erp_action) {
921 retval = ZFCP_ERP_ACTION_RUNNING;
925 /* search in ready list */
926 list_for_each(entry, &adapter->erp_ready_head) {
928 list_entry(entry, struct zfcp_erp_action, list);
929 if (entry_erp_action == erp_action) {
930 retval = ZFCP_ERP_ACTION_READY;
940 * purpose: checks current status of action (timed out, dismissed, ...)
941 * and does appropriate preparations (dismiss fsf request, ...)
943 * locks: called under erp_lock (disabled interrupts)
948 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
951 struct zfcp_fsf_req *fsf_req;
952 struct zfcp_adapter *adapter = erp_action->adapter;
954 if (erp_action->fsf_req) {
955 /* take lock to ensure that request is not being deleted meanwhile */
956 write_lock(&adapter->fsf_req_list_lock);
957 /* check whether fsf req does still exist */
958 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
959 if (fsf_req == erp_action->fsf_req)
961 if (fsf_req == erp_action->fsf_req) {
962 /* fsf_req still exists */
963 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
964 debug_event(adapter->erp_dbf, 3, &fsf_req,
965 sizeof (unsigned long));
966 /* dismiss fsf_req of timed out or dismissed erp_action */
967 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
968 ZFCP_STATUS_ERP_TIMEDOUT)) {
969 debug_text_event(adapter->erp_dbf, 3,
971 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
973 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
974 ZFCP_LOG_NORMAL("error: erp step timed out "
975 "(action=%d, fsf_req=%p)\n ",
977 erp_action->fsf_req);
980 * If fsf_req is neither dismissed nor completed
981 * then keep it running asynchronously and don't mess
982 * with the association of erp_action and fsf_req.
984 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
985 ZFCP_STATUS_FSFREQ_DISMISSED)) {
986 /* forget about association between fsf_req
988 fsf_req->erp_action = NULL;
989 erp_action->fsf_req = NULL;
992 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
994 * even if this fsf_req has gone, forget about
995 * association between erp_action and fsf_req
997 erp_action->fsf_req = NULL;
999 write_unlock(&adapter->fsf_req_list_lock);
1001 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
1007 * purpose: generic handler for asynchronous events related to erp_action events
1008 * (normal completion, time-out, dismissing, retry after
1009 * low memory condition)
1011 * note: deletion of timer is not required (e.g. in case of a time-out),
1012 * but a second try does no harm,
1013 * we leave it in here to allow for greater simplification
1015 * returns: 0 - there was an action to handle
1019 zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
1020 unsigned long set_mask)
1023 struct zfcp_adapter *adapter = erp_action->adapter;
1025 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
1026 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
1027 debug_event(adapter->erp_dbf, 2, &erp_action->action,
1029 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
1030 del_timer_sync(&erp_action->timer);
1031 erp_action->status |= set_mask;
1032 zfcp_erp_action_ready(erp_action);
1035 /* action is ready or gone - nothing to do */
1036 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
1037 debug_event(adapter->erp_dbf, 3, &erp_action->action,
1046 * purpose: generic handler for asynchronous events related to erp_action
1047 * events (normal completion, time-out, dismissing, retry after
1048 * low memory condition)
1050 * note: deletion of timer is not required (e.g. in case of a time-out),
1051 * but a second try does no harm,
1052 * we leave it in here to allow for greater simplification
1054 * returns: 0 - there was an action to handle
1058 zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
1059 unsigned long set_mask)
1061 struct zfcp_adapter *adapter = erp_action->adapter;
1062 unsigned long flags;
1065 write_lock_irqsave(&adapter->erp_lock, flags);
1066 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
1067 write_unlock_irqrestore(&adapter->erp_lock, flags);
1073 * purpose: is called for erp_action which was slept waiting for
1074 * memory becoming avaliable,
1075 * will trigger that this action will be continued
1078 zfcp_erp_memwait_handler(unsigned long data)
1080 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1081 struct zfcp_adapter *adapter = erp_action->adapter;
1083 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1084 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1086 zfcp_erp_async_handler(erp_action, 0);
1090 * purpose: is called if an asynchronous erp step timed out,
1091 * action gets an appropriate flag and will be processed
1095 zfcp_erp_timeout_handler(unsigned long data)
1097 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1098 struct zfcp_adapter *adapter = erp_action->adapter;
1100 debug_text_event(adapter->erp_dbf, 2, "a_th");
1101 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1103 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1107 * purpose: is called for an erp_action which needs to be ended
1108 * though not being done,
1109 * this is usually required if an higher is generated,
1110 * action gets an appropriate flag and will be processed
1113 * locks: erp_lock held (thus we need to call another handler variant)
1116 zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1118 struct zfcp_adapter *adapter = erp_action->adapter;
1120 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1121 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1123 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1129 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1133 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1135 rwlock_init(&adapter->erp_lock);
1136 INIT_LIST_HEAD(&adapter->erp_ready_head);
1137 INIT_LIST_HEAD(&adapter->erp_running_head);
1138 sema_init(&adapter->erp_ready_sem, 0);
1140 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1142 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1144 zfcp_get_busid_by_adapter(adapter));
1145 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1147 wait_event(adapter->erp_thread_wqh,
1148 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1150 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1153 return (retval < 0);
1163 * context: process (i.e. proc-fs or rmmod/insmod)
1165 * note: The caller of this routine ensures that the specified
1166 * adapter has been shut down and that this operation
1167 * has been completed. Thus, there are no pending erp_actions
1168 * which would need to be handled here.
1171 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1175 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1176 up(&adapter->erp_ready_sem);
1178 wait_event(adapter->erp_thread_wqh,
1179 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1182 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1185 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1191 * purpose: is run as a kernel thread,
1192 * goes through list of error recovery actions of associated adapter
1193 * and delegates single action to execution
1198 zfcp_erp_thread(void *data)
1200 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1201 struct list_head *next;
1202 struct zfcp_erp_action *erp_action;
1203 unsigned long flags;
1205 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1206 /* Block all signals */
1207 siginitsetinv(¤t->blocked, 0);
1208 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1209 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1210 wake_up(&adapter->erp_thread_wqh);
1212 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1213 &adapter->status)) {
1215 write_lock_irqsave(&adapter->erp_lock, flags);
1216 next = adapter->erp_ready_head.prev;
1217 write_unlock_irqrestore(&adapter->erp_lock, flags);
1219 if (next != &adapter->erp_ready_head) {
1221 list_entry(next, struct zfcp_erp_action, list);
1223 * process action (incl. [re]moving it
1224 * from 'ready' queue)
1226 zfcp_erp_strategy(erp_action);
1230 * sleep as long as there is nothing to do, i.e.
1231 * no action in 'ready' queue to be processed and
1232 * thread is not to be killed
1234 down_interruptible(&adapter->erp_ready_sem);
1235 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1238 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1239 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1240 wake_up(&adapter->erp_thread_wqh);
1248 * purpose: drives single error recovery action and schedules higher and
1249 * subordinate actions, if necessary
1251 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1252 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1253 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1254 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1255 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1258 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1261 struct zfcp_adapter *adapter = erp_action->adapter;
1262 struct zfcp_port *port = erp_action->port;
1263 struct zfcp_unit *unit = erp_action->unit;
1264 int action = erp_action->action;
1265 u32 status = erp_action->status;
1266 unsigned long flags;
1268 /* serialise dismissing, timing out, moving, enqueueing */
1269 read_lock_irqsave(&zfcp_data.config_lock, flags);
1270 write_lock(&adapter->erp_lock);
1272 /* dequeue dismissed action and leave, if required */
1273 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1274 if (retval == ZFCP_ERP_DISMISSED) {
1275 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1280 * move action to 'running' queue before processing it
1281 * (to avoid a race condition regarding moving the
1282 * action to the 'running' queue and back)
1284 zfcp_erp_action_to_running(erp_action);
1287 * try to process action as far as possible,
1288 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1289 * afterwards the lock is required again for the following reasons:
1290 * - dequeueing of finished action and enqueueing of
1291 * follow-up actions must be atomic so that any other
1292 * reopen-routine does not believe there is nothing to do
1293 * and that it is safe to enqueue something else,
1294 * - we want to force any control thread which is dismissing
1295 * actions to finish this before we decide about
1296 * necessary steps to be taken here further
1298 write_unlock(&adapter->erp_lock);
1299 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1300 retval = zfcp_erp_strategy_do_action(erp_action);
1301 read_lock_irqsave(&zfcp_data.config_lock, flags);
1302 write_lock(&adapter->erp_lock);
1305 * check for dismissed status again to avoid follow-up actions,
1306 * failing of targets and so on for dismissed actions
1308 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1311 case ZFCP_ERP_DISMISSED:
1312 /* leave since this action has ridden to its ancestors */
1313 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1315 case ZFCP_ERP_NOMEM:
1316 /* no memory to continue immediately, let it sleep */
1317 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1318 ++adapter->erp_low_mem_count;
1319 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1321 /* This condition is true if there is no memory available
1322 for any erp_action on this adapter. This implies that there
1323 are no elements in the memory pool(s) left for erp_actions.
1324 This might happen if an erp_action that used a memory pool
1325 element was timed out.
1327 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1328 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1329 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1330 "restarting I/O on adapter %s "
1331 "to free mempool\n",
1332 zfcp_get_busid_by_adapter(adapter));
1333 zfcp_erp_adapter_reopen_internal(adapter, 0);
1335 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1336 retval = zfcp_erp_strategy_memwait(erp_action);
1339 case ZFCP_ERP_CONTINUES:
1340 /* leave since this action runs asynchronously */
1341 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1342 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1343 --adapter->erp_low_mem_count;
1344 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1348 /* ok, finished action (whatever its result is) */
1350 /* check for unrecoverable targets */
1351 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1353 /* action must be dequeued (here to allow for further ones) */
1354 zfcp_erp_action_dequeue(erp_action);
1357 * put this target through the erp mill again if someone has
1358 * requested to change the status of a target being online
1359 * to offline or the other way around
1360 * (old retval is preserved if nothing has to be done here)
1362 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1363 port, unit, retval);
1366 * leave if target is in permanent error state or if
1367 * action is repeated in order to process state change
1369 if (retval == ZFCP_ERP_EXIT) {
1370 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1374 /* trigger follow up actions */
1375 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1378 write_unlock(&adapter->erp_lock);
1379 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1381 if (retval != ZFCP_ERP_CONTINUES)
1382 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1385 * a few tasks remain when the erp queues are empty
1386 * (don't do that if the last action evaluated was dismissed
1387 * since this clearly indicates that there is more to come) :
1388 * - close the name server port if it is open yet
1389 * (enqueues another [probably] final action)
1390 * - otherwise, wake up whoever wants to be woken when we are
1393 if (retval != ZFCP_ERP_DISMISSED)
1394 zfcp_erp_strategy_check_queues(adapter);
1396 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1406 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1407 * retval - otherwise
1410 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1412 struct zfcp_adapter *adapter = erp_action->adapter;
1414 zfcp_erp_strategy_check_fsfreq(erp_action);
1416 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1417 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1418 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1419 zfcp_erp_action_dequeue(erp_action);
1420 retval = ZFCP_ERP_DISMISSED;
1422 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1435 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1437 int retval = ZFCP_ERP_FAILED;
1438 struct zfcp_adapter *adapter = erp_action->adapter;
1441 * try to execute/continue action as far as possible,
1442 * note: no lock in subsequent strategy routines
1443 * (this allows these routine to call schedule, e.g.
1444 * kmalloc with such flags or qdio_initialize & friends)
1445 * Note: in case of timeout, the seperate strategies will fail
1446 * anyhow. No need for a special action. Even worse, a nameserver
1447 * failure would not wake up waiting ports without the call.
1449 switch (erp_action->action) {
1451 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1452 retval = zfcp_erp_adapter_strategy(erp_action);
1455 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1456 retval = zfcp_erp_port_forced_strategy(erp_action);
1459 case ZFCP_ERP_ACTION_REOPEN_PORT:
1460 retval = zfcp_erp_port_strategy(erp_action);
1463 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1464 retval = zfcp_erp_unit_strategy(erp_action);
1468 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1469 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1471 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1472 "adapter %s (action=%d)\n",
1473 zfcp_get_busid_by_adapter(erp_action->adapter),
1474 erp_action->action);
1483 * purpose: triggers retry of this action after a certain amount of time
1484 * by means of timer provided by erp_action
1486 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1489 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1491 int retval = ZFCP_ERP_CONTINUES;
1492 struct zfcp_adapter *adapter = erp_action->adapter;
1494 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1495 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1496 init_timer(&erp_action->timer);
1497 erp_action->timer.function = zfcp_erp_memwait_handler;
1498 erp_action->timer.data = (unsigned long) erp_action;
1499 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1500 add_timer(&erp_action->timer);
1506 * function: zfcp_erp_adapter_failed
1508 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1512 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1514 zfcp_erp_modify_adapter_status(adapter,
1515 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1516 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1517 zfcp_get_busid_by_adapter(adapter));
1518 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1522 * function: zfcp_erp_port_failed
1524 * purpose: sets the port and all underlying devices to ERP_FAILED
1528 zfcp_erp_port_failed(struct zfcp_port *port)
1530 zfcp_erp_modify_port_status(port,
1531 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1533 ZFCP_LOG_NORMAL("port erp failed on port 0x%016Lx on adapter %s\n",
1534 port->wwpn, zfcp_get_busid_by_port(port));
1535 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1536 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1540 * function: zfcp_erp_unit_failed
1542 * purpose: sets the unit to ERP_FAILED
1546 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1548 zfcp_erp_modify_unit_status(unit,
1549 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1551 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1552 " on adapter %s\n", unit->fcp_lun,
1553 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1554 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1555 debug_event(unit->port->adapter->erp_dbf, 2,
1556 &unit->fcp_lun, sizeof (fcp_lun_t));
1560 * function: zfcp_erp_strategy_check_target
1562 * purpose: increments the erp action count on the device currently in
1563 * recovery if the action failed or resets the count in case of
1564 * success. If a maximum count is exceeded the device is marked
1566 * The 'blocked' state of a target which has been recovered
1567 * successfully is reset.
1569 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1570 * ZFCP_ERP_SUCCEEDED - action finished successfully
1571 * ZFCP_ERP_EXIT - action failed and will not continue
1574 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1576 struct zfcp_adapter *adapter = erp_action->adapter;
1577 struct zfcp_port *port = erp_action->port;
1578 struct zfcp_unit *unit = erp_action->unit;
1580 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1581 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1582 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1584 switch (erp_action->action) {
1586 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1587 result = zfcp_erp_strategy_check_unit(unit, result);
1590 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1591 case ZFCP_ERP_ACTION_REOPEN_PORT:
1592 result = zfcp_erp_strategy_check_port(port, result);
1595 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1596 result = zfcp_erp_strategy_check_adapter(adapter, result);
1611 zfcp_erp_strategy_statechange(int action,
1613 struct zfcp_adapter *adapter,
1614 struct zfcp_port *port,
1615 struct zfcp_unit *unit, int retval)
1617 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1618 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1622 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1623 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1625 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1626 retval = ZFCP_ERP_EXIT;
1630 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1631 case ZFCP_ERP_ACTION_REOPEN_PORT:
1632 if (zfcp_erp_strategy_statechange_detected(&port->status,
1634 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1635 retval = ZFCP_ERP_EXIT;
1639 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1640 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1642 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1643 retval = ZFCP_ERP_EXIT;
1659 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1662 /* take it online */
1663 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1664 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1665 /* take it offline */
1666 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1667 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1671 * zfcp_erp_scsi_add_device
1672 * @data: pointer to a struct zfcp_unit
1674 * Registers a logical unit with the SCSI stack.
1677 zfcp_erp_scsi_add_device(void *data)
1680 struct zfcp_unit *unit;
1681 struct work_struct work;
1685 scsi_add_device(p->unit->port->adapter->scsi_host,
1686 0, p->unit->port->scsi_id, p->unit->scsi_lun);
1687 atomic_set(&p->unit->scsi_add_work, 0);
1688 wake_up(&p->unit->scsi_add_wq);
1689 zfcp_unit_put(p->unit);
1694 * zfcp_erp_schedule_work
1695 * @unit: pointer to unit which should be registered with SCSI stack
1697 * Schedules work which registers a unit with the SCSI stack
1700 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1703 struct zfcp_unit * unit;
1704 struct work_struct work;
1707 if (atomic_compare_and_swap(0, 1, &unit->scsi_add_work))
1710 if ((p = kmalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
1711 ZFCP_LOG_NORMAL("error: registration at SCSI stack failed for "
1712 "unit 0x%016Lx on port 0x%016Lx on "
1713 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
1714 zfcp_get_busid_by_unit(unit));
1715 atomic_set(&unit->scsi_add_work, 0);
1719 zfcp_unit_get(unit);
1720 memset(p, 0, sizeof(*p));
1721 INIT_WORK(&p->work, zfcp_erp_scsi_add_device, p);
1723 schedule_work(&p->work);
1735 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1737 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1738 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1739 sizeof (fcp_lun_t));
1742 case ZFCP_ERP_SUCCEEDED :
1743 atomic_set(&unit->erp_counter, 0);
1744 zfcp_erp_unit_unblock(unit);
1746 case ZFCP_ERP_FAILED :
1747 atomic_inc(&unit->erp_counter);
1748 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1749 zfcp_erp_unit_failed(unit);
1751 case ZFCP_ERP_EXIT :
1756 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1757 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1758 result = ZFCP_ERP_EXIT;
1772 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1774 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1775 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1778 case ZFCP_ERP_SUCCEEDED :
1779 atomic_set(&port->erp_counter, 0);
1780 zfcp_erp_port_unblock(port);
1782 case ZFCP_ERP_FAILED :
1783 atomic_inc(&port->erp_counter);
1784 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1785 zfcp_erp_port_failed(port);
1787 case ZFCP_ERP_EXIT :
1792 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1793 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1794 result = ZFCP_ERP_EXIT;
1808 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1810 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1813 case ZFCP_ERP_SUCCEEDED :
1814 atomic_set(&adapter->erp_counter, 0);
1815 zfcp_erp_adapter_unblock(adapter);
1817 case ZFCP_ERP_FAILED :
1818 atomic_inc(&adapter->erp_counter);
1819 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1820 zfcp_erp_adapter_failed(adapter);
1822 case ZFCP_ERP_EXIT :
1827 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1828 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1829 result = ZFCP_ERP_EXIT;
1838 * purpose: remaining things in good cases,
1839 * escalation in bad cases
1844 zfcp_erp_strategy_followup_actions(int action,
1845 struct zfcp_adapter *adapter,
1846 struct zfcp_port *port,
1847 struct zfcp_unit *unit, int status)
1849 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1850 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1852 /* initiate follow-up actions depending on success of finished action */
1855 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1856 if (status == ZFCP_ERP_SUCCEEDED)
1857 zfcp_erp_port_reopen_all_internal(adapter, 0);
1859 zfcp_erp_adapter_reopen_internal(adapter, 0);
1862 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1863 if (status == ZFCP_ERP_SUCCEEDED)
1864 zfcp_erp_port_reopen_internal(port, 0);
1866 zfcp_erp_adapter_reopen_internal(adapter, 0);
1869 case ZFCP_ERP_ACTION_REOPEN_PORT:
1870 if (status == ZFCP_ERP_SUCCEEDED)
1871 zfcp_erp_unit_reopen_all_internal(port, 0);
1873 zfcp_erp_port_forced_reopen_internal(port, 0);
1876 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1877 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1879 zfcp_erp_port_reopen_internal(unit->port, 0);
1894 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1897 unsigned long flags;
1898 struct zfcp_port *nport = adapter->nameserver_port;
1900 read_lock_irqsave(&zfcp_data.config_lock, flags);
1901 read_lock(&adapter->erp_lock);
1902 if (list_empty(&adapter->erp_ready_head) &&
1903 list_empty(&adapter->erp_running_head)) {
1905 && atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
1907 debug_text_event(adapter->erp_dbf, 4, "a_cq_nspsd");
1908 /* taking down nameserver port */
1909 zfcp_erp_port_reopen_internal(nport,
1910 ZFCP_STATUS_COMMON_RUNNING |
1911 ZFCP_STATUS_COMMON_ERP_FAILED);
1913 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1914 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1916 wake_up(&adapter->erp_done_wqh);
1919 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1920 read_unlock(&adapter->erp_lock);
1921 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1927 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1928 * @adapter: adapter for which to wait for completion of its error recovery
1932 zfcp_erp_wait(struct zfcp_adapter *adapter)
1936 wait_event(adapter->erp_done_wqh,
1937 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1944 * function: zfcp_erp_modify_adapter_status
1950 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1951 u32 mask, int set_or_clear)
1953 struct zfcp_port *port;
1954 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1956 if (set_or_clear == ZFCP_SET) {
1957 atomic_set_mask(mask, &adapter->status);
1958 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1960 atomic_clear_mask(mask, &adapter->status);
1961 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1962 atomic_set(&adapter->erp_counter, 0);
1963 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1965 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1967 /* Deal with all underlying devices, only pass common_mask */
1969 list_for_each_entry(port, &adapter->port_list_head, list)
1970 zfcp_erp_modify_port_status(port, common_mask,
1975 * function: zfcp_erp_modify_port_status
1977 * purpose: sets the port and all underlying devices to ERP_FAILED
1981 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1983 struct zfcp_unit *unit;
1984 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1986 if (set_or_clear == ZFCP_SET) {
1987 atomic_set_mask(mask, &port->status);
1988 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1990 atomic_clear_mask(mask, &port->status);
1991 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1992 atomic_set(&port->erp_counter, 0);
1993 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1995 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1996 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1998 /* Modify status of all underlying devices, only pass common mask */
2000 list_for_each_entry(unit, &port->unit_list_head, list)
2001 zfcp_erp_modify_unit_status(unit, common_mask,
2006 * function: zfcp_erp_modify_unit_status
2008 * purpose: sets the unit to ERP_FAILED
2012 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
2014 if (set_or_clear == ZFCP_SET) {
2015 atomic_set_mask(mask, &unit->status);
2016 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
2018 atomic_clear_mask(mask, &unit->status);
2019 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
2020 atomic_set(&unit->erp_counter, 0);
2022 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
2024 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
2025 sizeof (fcp_lun_t));
2026 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
2032 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
2033 * used to ensure the correct locking
2035 * returns: 0 - initiated action succesfully
2036 * <0 - failed to initiate action
2039 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
2042 unsigned long flags;
2044 read_lock_irqsave(&zfcp_data.config_lock, flags);
2045 write_lock(&adapter->erp_lock);
2046 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
2047 write_unlock(&adapter->erp_lock);
2048 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2061 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
2064 struct zfcp_port *port;
2066 list_for_each_entry(port, &adapter->port_list_head, list)
2067 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
2068 zfcp_erp_port_reopen_internal(port, clear_mask);
2081 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
2084 struct zfcp_unit *unit;
2086 list_for_each_entry(unit, &port->unit_list_head, list)
2087 zfcp_erp_unit_reopen_internal(unit, clear_mask);
2095 * purpose: this routine executes the 'Reopen Adapter' action
2096 * (the entire action is processed synchronously, since
2097 * there are no actions which might be run concurrently
2100 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2101 * ZFCP_ERP_FAILED - action finished unsuccessfully
2104 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
2107 struct zfcp_adapter *adapter = erp_action->adapter;
2109 retval = zfcp_erp_adapter_strategy_close(erp_action);
2110 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2111 retval = ZFCP_ERP_EXIT;
2113 retval = zfcp_erp_adapter_strategy_open(erp_action);
2115 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
2116 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2117 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2119 if (retval == ZFCP_ERP_FAILED) {
2120 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
2121 "to recover itself\n",
2122 zfcp_get_busid_by_adapter(adapter));
2123 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
2134 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2135 * ZFCP_ERP_FAILED - action finished unsuccessfully
2138 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
2142 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2143 &erp_action->adapter->status);
2144 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2145 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2146 &erp_action->adapter->status);
2156 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2157 * ZFCP_ERP_FAILED - action finished unsuccessfully
2160 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2164 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2165 &erp_action->adapter->status);
2166 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2167 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2168 &erp_action->adapter->status);
2174 * function: zfcp_register_adapter
2176 * purpose: allocate the irq associated with this devno and register
2177 * the FSF adapter with the SCSI stack
2182 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2184 int retval = ZFCP_ERP_SUCCEEDED;
2189 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2190 if (retval != ZFCP_ERP_SUCCEEDED)
2193 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2194 if (retval != ZFCP_ERP_SUCCEEDED)
2195 goto failed_openfcp;
2197 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2201 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2202 &erp_action->adapter->status);
2205 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2206 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2213 * function: zfcp_qdio_init
2215 * purpose: setup QDIO operation for specified adapter
2217 * returns: 0 - successful setup
2221 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2225 volatile struct qdio_buffer_element *sbale;
2226 struct zfcp_adapter *adapter = erp_action->adapter;
2228 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2229 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2231 zfcp_get_busid_by_adapter(adapter));
2235 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2236 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2238 zfcp_get_busid_by_adapter(adapter));
2239 goto failed_qdio_establish;
2241 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2243 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2244 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2246 zfcp_get_busid_by_adapter(adapter));
2247 goto failed_qdio_activate;
2249 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2252 * put buffers into response queue,
2254 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2255 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2257 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2261 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2262 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2263 zfcp_get_busid_by_adapter(adapter),
2264 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2266 retval = do_QDIO(adapter->ccw_device,
2267 QDIO_FLAG_SYNC_INPUT,
2268 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2271 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2273 goto failed_do_qdio;
2275 adapter->response_queue.free_index = 0;
2276 atomic_set(&adapter->response_queue.free_count, 0);
2277 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2278 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2280 /* set index of first avalable SBALS / number of available SBALS */
2281 adapter->request_queue.free_index = 0;
2282 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2283 adapter->request_queue.distance_from_int = 0;
2285 /* initialize waitqueue used to wait for free SBALs in requests queue */
2286 init_waitqueue_head(&adapter->request_wq);
2288 /* ok, we did it - skip all cleanups for different failures */
2289 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2290 retval = ZFCP_ERP_SUCCEEDED;
2296 failed_qdio_activate:
2297 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2298 while (qdio_shutdown(adapter->ccw_device,
2299 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2301 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2303 failed_qdio_establish:
2305 retval = ZFCP_ERP_FAILED;
2312 * function: zfcp_qdio_cleanup
2314 * purpose: cleans up QDIO operation for the specified adapter
2316 * returns: 0 - successful cleanup
2317 * !0 - failed cleanup
2320 zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2322 int retval = ZFCP_ERP_SUCCEEDED;
2325 struct zfcp_adapter *adapter = erp_action->adapter;
2327 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2328 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2329 "queues on adapter %s\n",
2330 zfcp_get_busid_by_adapter(adapter));
2331 retval = ZFCP_ERP_FAILED;
2336 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2337 * do_QDIO won't be called while qdio_shutdown is in progress.
2340 write_lock_irq(&adapter->request_queue.queue_lock);
2341 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2342 write_unlock_irq(&adapter->request_queue.queue_lock);
2344 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2345 while (qdio_shutdown(adapter->ccw_device,
2346 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2348 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2351 * First we had to stop QDIO operation.
2352 * Now it is safe to take the following actions.
2355 /* Cleanup only necessary when there are unacknowledged buffers */
2356 if (atomic_read(&adapter->request_queue.free_count)
2357 < QDIO_MAX_BUFFERS_PER_Q) {
2358 first_used = (adapter->request_queue.free_index +
2359 atomic_read(&adapter->request_queue.free_count))
2360 % QDIO_MAX_BUFFERS_PER_Q;
2361 used_count = QDIO_MAX_BUFFERS_PER_Q -
2362 atomic_read(&adapter->request_queue.free_count);
2363 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2364 first_used, used_count);
2366 adapter->response_queue.free_index = 0;
2367 atomic_set(&adapter->response_queue.free_count, 0);
2368 adapter->request_queue.free_index = 0;
2369 atomic_set(&adapter->request_queue.free_count, 0);
2370 adapter->request_queue.distance_from_int = 0;
2376 * function: zfcp_fsf_init
2378 * purpose: initializes FSF operation for the specified adapter
2380 * returns: 0 - succesful initialization of FSF operation
2381 * !0 - failed to initialize FSF operation
2384 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2388 /* do 'exchange configuration data' */
2389 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2390 if (retval == ZFCP_ERP_FAILED)
2393 /* start the desired number of Status Reads */
2394 retval = zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2406 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2408 int retval = ZFCP_ERP_SUCCEEDED;
2410 struct zfcp_adapter *adapter = erp_action->adapter;
2412 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2413 retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES;
2416 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2418 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2419 zfcp_erp_action_to_running(erp_action);
2420 zfcp_erp_timeout_init(erp_action);
2421 if (zfcp_fsf_exchange_config_data(erp_action)) {
2422 retval = ZFCP_ERP_FAILED;
2423 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2424 ZFCP_LOG_INFO("error: initiation of exchange of "
2425 "configuration data failed for "
2427 zfcp_get_busid_by_adapter(adapter));
2430 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2431 ZFCP_LOG_DEBUG("Xchange underway\n");
2435 * Both the normal completion handler as well as the timeout
2436 * handler will do an 'up' when the 'exchange config data'
2437 * request completes or times out. Thus, the signal to go on
2438 * won't be lost utilizing this semaphore.
2439 * Furthermore, this 'adapter_reopen' action is
2440 * guaranteed to be the only action being there (highest action
2441 * which prevents other actions from being created).
2442 * Resulting from that, the wake signal recognized here
2443 * _must_ be the one belonging to the 'exchange config
2446 down(&adapter->erp_ready_sem);
2447 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2448 ZFCP_LOG_INFO("error: exchange of configuration data "
2449 "for adapter %s timed out\n",
2450 zfcp_get_busid_by_adapter(adapter));
2453 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2454 &adapter->status)) {
2455 ZFCP_LOG_DEBUG("host connection still initialising... "
2456 "waiting and retrying...\n");
2457 /* sleep a little bit before retry */
2458 msleep(jiffies_to_msecs(ZFCP_EXCHANGE_CONFIG_DATA_SLEEP));
2460 } while ((retries--) &&
2461 atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2464 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2465 &adapter->status)) {
2466 ZFCP_LOG_INFO("error: exchange of configuration data for "
2467 "adapter %s failed\n",
2468 zfcp_get_busid_by_adapter(adapter));
2469 retval = ZFCP_ERP_FAILED;
2483 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2486 int retval = ZFCP_ERP_SUCCEEDED;
2488 struct zfcp_adapter *adapter = erp_action->adapter;
2491 adapter->status_read_failed = 0;
2492 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2493 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2495 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2496 "notification failed on adapter %s\n",
2497 zfcp_get_busid_by_adapter(adapter));
2498 retval = ZFCP_ERP_FAILED;
2508 * function: zfcp_fsf_cleanup
2510 * purpose: cleanup FSF operation for specified adapter
2512 * returns: 0 - FSF operation successfully cleaned up
2513 * !0 - failed to cleanup FSF operation for this adapter
2516 zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2518 int retval = ZFCP_ERP_SUCCEEDED;
2519 struct zfcp_adapter *adapter = erp_action->adapter;
2522 * wake waiting initiators of requests,
2523 * return SCSI commands (with error status),
2524 * clean up all requests (synchronously)
2526 zfcp_fsf_req_dismiss_all(adapter);
2527 /* reset FSF request sequence number */
2528 adapter->fsf_req_seq_no = 0;
2529 /* all ports and units are closed */
2530 zfcp_erp_modify_adapter_status(adapter,
2531 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2539 * purpose: this routine executes the 'Reopen Physical Port' action
2541 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2542 * ZFCP_ERP_SUCCEEDED - action finished successfully
2543 * ZFCP_ERP_FAILED - action finished unsuccessfully
2546 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2548 int retval = ZFCP_ERP_FAILED;
2549 struct zfcp_port *port = erp_action->port;
2550 struct zfcp_adapter *adapter = erp_action->adapter;
2552 switch (erp_action->step) {
2556 * the ULP spec. begs for waiting for oustanding commands
2558 case ZFCP_ERP_STEP_UNINITIALIZED:
2559 zfcp_erp_port_strategy_clearstati(port);
2561 * it would be sufficient to test only the normal open flag
2562 * since the phys. open flag cannot be set if the normal
2563 * open flag is unset - however, this is for readabilty ...
2565 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2566 ZFCP_STATUS_COMMON_OPEN),
2568 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2569 "close physical\n", port->wwpn);
2571 zfcp_erp_port_forced_strategy_close(erp_action);
2573 retval = ZFCP_ERP_FAILED;
2576 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2577 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2579 ZFCP_LOG_DEBUG("close physical failed for port "
2580 "0x%016Lx\n", port->wwpn);
2581 retval = ZFCP_ERP_FAILED;
2583 retval = ZFCP_ERP_SUCCEEDED;
2587 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2588 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2589 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2590 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2598 * purpose: this routine executes the 'Reopen Port' action
2600 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2601 * ZFCP_ERP_SUCCEEDED - action finished successfully
2602 * ZFCP_ERP_FAILED - action finished unsuccessfully
2605 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2607 int retval = ZFCP_ERP_FAILED;
2608 struct zfcp_port *port = erp_action->port;
2609 struct zfcp_adapter *adapter = erp_action->adapter;
2611 switch (erp_action->step) {
2615 * the ULP spec. begs for waiting for oustanding commands
2617 case ZFCP_ERP_STEP_UNINITIALIZED:
2618 zfcp_erp_port_strategy_clearstati(port);
2619 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2620 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2621 "close\n", port->wwpn);
2622 retval = zfcp_erp_port_strategy_close(erp_action);
2624 } /* else it's already closed, open it */
2627 case ZFCP_ERP_STEP_PORT_CLOSING:
2628 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2629 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2631 retval = ZFCP_ERP_FAILED;
2633 } /* else it's closed now, open it */
2636 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2637 retval = ZFCP_ERP_EXIT;
2639 retval = zfcp_erp_port_strategy_open(erp_action);
2642 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2643 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2644 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2645 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2658 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2662 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2663 &erp_action->port->status))
2664 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2666 retval = zfcp_erp_port_strategy_open_common(erp_action);
2678 * FIXME(design): currently only prepared for fabric (nameserver!)
2681 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2684 struct zfcp_adapter *adapter = erp_action->adapter;
2685 struct zfcp_port *port = erp_action->port;
2687 switch (erp_action->step) {
2689 case ZFCP_ERP_STEP_UNINITIALIZED:
2690 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2691 case ZFCP_ERP_STEP_PORT_CLOSING:
2692 if (!(adapter->nameserver_port)) {
2693 retval = zfcp_nameserver_enqueue(adapter);
2695 ZFCP_LOG_NORMAL("error: nameserver port "
2696 "unavailable for adapter %s\n",
2697 zfcp_get_busid_by_adapter(adapter));
2698 retval = ZFCP_ERP_FAILED;
2702 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2703 &adapter->nameserver_port->status)) {
2704 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2705 "nameserver port\n");
2706 /* nameserver port may live again */
2707 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2708 &adapter->nameserver_port->status);
2709 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0) >= 0) {
2710 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_OPEN;
2711 retval = ZFCP_ERP_CONTINUES;
2712 } else retval = ZFCP_ERP_FAILED;
2715 /* else nameserver port is already open, fall through */
2716 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2717 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2718 &adapter->nameserver_port->status)) {
2719 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2720 retval = ZFCP_ERP_FAILED;
2722 ZFCP_LOG_DEBUG("nameserver port is open -> "
2723 "nameserver look-up for port 0x%016Lx\n",
2725 retval = zfcp_erp_port_strategy_open_common_lookup
2730 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2731 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2732 if (atomic_test_mask
2733 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2734 ZFCP_LOG_DEBUG("nameserver look-up failed "
2735 "for port 0x%016Lx "
2736 "(misconfigured WWPN?)\n",
2738 zfcp_erp_port_failed(port);
2739 retval = ZFCP_ERP_EXIT;
2741 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2742 "port 0x%016Lx\n", port->wwpn);
2743 retval = ZFCP_ERP_FAILED;
2746 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2747 "trying open\n", port->wwpn, port->d_id);
2748 retval = zfcp_erp_port_strategy_open_port(erp_action);
2752 case ZFCP_ERP_STEP_PORT_OPENING:
2753 /* D_ID might have changed during open */
2754 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2755 ZFCP_STATUS_PORT_DID_DID),
2757 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2758 retval = ZFCP_ERP_SUCCEEDED;
2760 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2762 retval = ZFCP_ERP_FAILED;
2767 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2769 retval = ZFCP_ERP_FAILED;
2783 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2786 struct zfcp_port *port = erp_action->port;
2788 switch (erp_action->step) {
2790 case ZFCP_ERP_STEP_UNINITIALIZED:
2791 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2792 case ZFCP_ERP_STEP_PORT_CLOSING:
2793 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2794 port->wwpn, port->d_id);
2795 retval = zfcp_erp_port_strategy_open_port(erp_action);
2798 case ZFCP_ERP_STEP_PORT_OPENING:
2799 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2800 ZFCP_LOG_DEBUG("WKA port is open\n");
2801 retval = ZFCP_ERP_SUCCEEDED;
2803 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2804 retval = ZFCP_ERP_FAILED;
2806 /* this is needed anyway (dont care for retval of wakeup) */
2807 ZFCP_LOG_DEBUG("continue other open port operations\n");
2808 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2812 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2814 retval = ZFCP_ERP_FAILED;
2823 * purpose: makes the erp thread continue with reopen (physical) port
2824 * actions which have been paused until the name server port
2825 * is opened (or failed)
2827 * returns: 0 (a kind of void retval, its not used)
2830 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2834 unsigned long flags;
2835 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2836 struct zfcp_erp_action *erp_action, *tmp;
2838 read_lock_irqsave(&adapter->erp_lock, flags);
2839 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2841 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2842 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2844 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2845 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2846 debug_event(adapter->erp_dbf, 3,
2847 &erp_action->port->wwpn, sizeof (wwn_t));
2848 if (atomic_test_mask(
2849 ZFCP_STATUS_COMMON_ERP_FAILED,
2850 &adapter->nameserver_port->status))
2851 zfcp_erp_port_failed(erp_action->port);
2852 zfcp_erp_action_ready(erp_action);
2855 read_unlock_irqrestore(&adapter->erp_lock, flags);
2865 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2866 * ZFCP_ERP_FAILED - action finished unsuccessfully
2869 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2872 struct zfcp_adapter *adapter = erp_action->adapter;
2873 struct zfcp_port *port = erp_action->port;
2875 zfcp_erp_timeout_init(erp_action);
2876 retval = zfcp_fsf_close_physical_port(erp_action);
2877 if (retval == -ENOMEM) {
2878 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2879 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2880 retval = ZFCP_ERP_NOMEM;
2883 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2885 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2886 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2887 /* could not send 'open', fail */
2888 retval = ZFCP_ERP_FAILED;
2891 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2892 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2893 retval = ZFCP_ERP_CONTINUES;
2906 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2909 struct zfcp_adapter *adapter = port->adapter;
2911 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2912 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2914 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2915 ZFCP_STATUS_COMMON_CLOSING |
2916 ZFCP_STATUS_PORT_DID_DID |
2917 ZFCP_STATUS_PORT_PHYS_CLOSING |
2918 ZFCP_STATUS_PORT_INVALID_WWPN, &port->status);
2927 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2928 * ZFCP_ERP_FAILED - action finished unsuccessfully
2931 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2934 struct zfcp_adapter *adapter = erp_action->adapter;
2935 struct zfcp_port *port = erp_action->port;
2937 zfcp_erp_timeout_init(erp_action);
2938 retval = zfcp_fsf_close_port(erp_action);
2939 if (retval == -ENOMEM) {
2940 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2941 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2942 retval = ZFCP_ERP_NOMEM;
2945 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2947 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2948 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2949 /* could not send 'close', fail */
2950 retval = ZFCP_ERP_FAILED;
2953 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2954 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2955 retval = ZFCP_ERP_CONTINUES;
2965 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2966 * ZFCP_ERP_FAILED - action finished unsuccessfully
2969 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2972 struct zfcp_adapter *adapter = erp_action->adapter;
2973 struct zfcp_port *port = erp_action->port;
2975 zfcp_erp_timeout_init(erp_action);
2976 retval = zfcp_fsf_open_port(erp_action);
2977 if (retval == -ENOMEM) {
2978 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2979 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2980 retval = ZFCP_ERP_NOMEM;
2983 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2985 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2986 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2987 /* could not send 'open', fail */
2988 retval = ZFCP_ERP_FAILED;
2991 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2992 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2993 retval = ZFCP_ERP_CONTINUES;
3003 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3004 * ZFCP_ERP_FAILED - action finished unsuccessfully
3007 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
3010 struct zfcp_adapter *adapter = erp_action->adapter;
3011 struct zfcp_port *port = erp_action->port;
3013 zfcp_erp_timeout_init(erp_action);
3014 retval = zfcp_ns_gid_pn_request(erp_action);
3015 if (retval == -ENOMEM) {
3016 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
3017 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3018 retval = ZFCP_ERP_NOMEM;
3021 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
3023 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
3024 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3025 /* could not send nameserver request, fail */
3026 retval = ZFCP_ERP_FAILED;
3029 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
3030 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
3031 retval = ZFCP_ERP_CONTINUES;
3039 * purpose: this routine executes the 'Reopen Unit' action
3040 * currently no retries
3042 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3043 * ZFCP_ERP_SUCCEEDED - action finished successfully
3044 * ZFCP_ERP_FAILED - action finished unsuccessfully
3047 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
3049 int retval = ZFCP_ERP_FAILED;
3050 struct zfcp_unit *unit = erp_action->unit;
3051 struct zfcp_adapter *adapter = erp_action->adapter;
3053 switch (erp_action->step) {
3057 * the ULP spec. begs for waiting for oustanding commands
3059 case ZFCP_ERP_STEP_UNINITIALIZED:
3060 zfcp_erp_unit_strategy_clearstati(unit);
3061 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3062 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
3063 "trying close\n", unit->fcp_lun);
3064 retval = zfcp_erp_unit_strategy_close(erp_action);
3067 /* else it's already closed, fall through */
3068 case ZFCP_ERP_STEP_UNIT_CLOSING:
3069 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3070 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
3072 retval = ZFCP_ERP_FAILED;
3074 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
3075 retval = ZFCP_ERP_EXIT;
3077 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
3078 "trying open\n", unit->fcp_lun);
3080 zfcp_erp_unit_strategy_open(erp_action);
3085 case ZFCP_ERP_STEP_UNIT_OPENING:
3086 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
3087 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
3089 retval = ZFCP_ERP_SUCCEEDED;
3091 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3093 retval = ZFCP_ERP_FAILED;
3098 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3099 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3100 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3101 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3113 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3116 struct zfcp_adapter *adapter = unit->port->adapter;
3118 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3119 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3121 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3122 ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3132 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3133 * ZFCP_ERP_FAILED - action finished unsuccessfully
3136 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3139 struct zfcp_adapter *adapter = erp_action->adapter;
3140 struct zfcp_unit *unit = erp_action->unit;
3142 zfcp_erp_timeout_init(erp_action);
3143 retval = zfcp_fsf_close_unit(erp_action);
3144 if (retval == -ENOMEM) {
3145 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3146 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3147 sizeof (fcp_lun_t));
3148 retval = ZFCP_ERP_NOMEM;
3151 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3153 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3154 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3155 sizeof (fcp_lun_t));
3156 /* could not send 'close', fail */
3157 retval = ZFCP_ERP_FAILED;
3160 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3161 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3162 retval = ZFCP_ERP_CONTINUES;
3173 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3174 * ZFCP_ERP_FAILED - action finished unsuccessfully
3177 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3180 struct zfcp_adapter *adapter = erp_action->adapter;
3181 struct zfcp_unit *unit = erp_action->unit;
3183 zfcp_erp_timeout_init(erp_action);
3184 retval = zfcp_fsf_open_unit(erp_action);
3185 if (retval == -ENOMEM) {
3186 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3187 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3188 sizeof (fcp_lun_t));
3189 retval = ZFCP_ERP_NOMEM;
3192 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3194 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3195 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3196 sizeof (fcp_lun_t));
3197 /* could not send 'open', fail */
3198 retval = ZFCP_ERP_FAILED;
3201 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3202 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3203 retval = ZFCP_ERP_CONTINUES;
3216 zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3218 init_timer(&erp_action->timer);
3219 erp_action->timer.function = zfcp_erp_timeout_handler;
3220 erp_action->timer.data = (unsigned long) erp_action;
3221 /* jiffies will be added in zfcp_fsf_req_send */
3222 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3228 * purpose: enqueue the specified error recovery action, if needed
3233 zfcp_erp_action_enqueue(int action,
3234 struct zfcp_adapter *adapter,
3235 struct zfcp_port *port, struct zfcp_unit *unit)
3238 struct zfcp_erp_action *erp_action = NULL;
3239 int stronger_action = 0;
3243 * We need some rules here which check whether we really need
3244 * this action or whether we should just drop it.
3245 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3246 * 'Reopen Unit' request for an associated unit since we can't
3247 * satisfy this request now. A 'Reopen Port' action will trigger
3248 * 'Reopen Unit' actions when it completes.
3249 * Thus, there are only actions in the queue which can immediately be
3250 * executed. This makes the processing of the action queue more
3254 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3258 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3259 /* check whether we really need this */
3261 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3262 if (atomic_test_mask
3263 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3264 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3265 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3267 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3268 sizeof (fcp_lun_t));
3271 if (!atomic_test_mask
3272 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3274 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3277 if (!atomic_test_mask
3278 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3279 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3282 /* fall through !!! */
3284 case ZFCP_ERP_ACTION_REOPEN_PORT:
3285 if (atomic_test_mask
3286 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3287 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3288 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3292 /* fall through !!! */
3294 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3295 if (atomic_test_mask
3296 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)
3297 && port->erp_action.action ==
3298 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3299 debug_text_event(adapter->erp_dbf, 4, "pf_actenq_drp");
3300 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3304 if (!atomic_test_mask
3305 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3307 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3310 if (!atomic_test_mask
3311 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3312 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3315 /* fall through !!! */
3317 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3318 if (atomic_test_mask
3319 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3320 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3326 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3327 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3328 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3329 "on adapter %s (action=%d)\n",
3330 zfcp_get_busid_by_adapter(adapter), action);
3334 /* check whether we need something stronger first */
3335 if (stronger_action) {
3336 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3337 debug_event(adapter->erp_dbf, 4, &stronger_action,
3339 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3340 "erp action %d on adapter %s\n",
3341 stronger_action, action,
3342 zfcp_get_busid_by_adapter(adapter));
3343 action = stronger_action;
3346 /* mark adapter to have some error recovery pending */
3347 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3349 /* setup error recovery action */
3352 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3353 zfcp_unit_get(unit);
3354 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3355 erp_action = &unit->erp_action;
3356 if (!atomic_test_mask
3357 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3358 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3361 case ZFCP_ERP_ACTION_REOPEN_PORT:
3362 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3363 zfcp_port_get(port);
3364 zfcp_erp_action_dismiss_port(port);
3365 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3366 erp_action = &port->erp_action;
3367 if (!atomic_test_mask
3368 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3369 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3372 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3373 zfcp_adapter_get(adapter);
3374 zfcp_erp_action_dismiss_adapter(adapter);
3375 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3376 erp_action = &adapter->erp_action;
3377 if (!atomic_test_mask
3378 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3379 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3383 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3385 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3386 erp_action->adapter = adapter;
3387 erp_action->port = port;
3388 erp_action->unit = unit;
3389 erp_action->action = action;
3390 erp_action->status = status;
3392 ++adapter->erp_total_count;
3394 /* finally put it into 'ready' queue and kick erp thread */
3395 list_add(&erp_action->list, &adapter->erp_ready_head);
3396 up(&adapter->erp_ready_sem);
3410 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3413 struct zfcp_adapter *adapter = erp_action->adapter;
3415 --adapter->erp_total_count;
3416 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3417 --adapter->erp_low_mem_count;
3418 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3421 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3422 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3423 list_del(&erp_action->list);
3424 switch (erp_action->action) {
3425 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3426 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3427 &erp_action->unit->status);
3429 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3430 case ZFCP_ERP_ACTION_REOPEN_PORT:
3431 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3432 &erp_action->port->status);
3434 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3435 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3436 &erp_action->adapter->status);
3446 * zfcp_erp_action_cleanup
3448 * registers unit with scsi stack if appropiate and fixes reference counts
3452 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3453 struct zfcp_port *port, struct zfcp_unit *unit,
3456 if ((action == ZFCP_ERP_ACTION_REOPEN_UNIT)
3457 && (result == ZFCP_ERP_SUCCEEDED)
3458 && (!unit->device)) {
3459 zfcp_erp_schedule_work(unit);
3462 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3463 zfcp_unit_put(unit);
3465 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3466 case ZFCP_ERP_ACTION_REOPEN_PORT:
3467 zfcp_port_put(port);
3469 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3470 zfcp_adapter_put(adapter);
3486 zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3489 struct zfcp_port *port;
3491 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3492 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3493 zfcp_erp_action_dismiss(&adapter->erp_action);
3495 list_for_each_entry(port, &adapter->port_list_head, list)
3496 zfcp_erp_action_dismiss_port(port);
3509 zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3512 struct zfcp_unit *unit;
3513 struct zfcp_adapter *adapter = port->adapter;
3515 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3516 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3517 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3518 zfcp_erp_action_dismiss(&port->erp_action);
3520 list_for_each_entry(unit, &port->unit_list_head, list)
3521 zfcp_erp_action_dismiss_unit(unit);
3534 zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3537 struct zfcp_adapter *adapter = unit->port->adapter;
3539 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3540 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3541 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3542 zfcp_erp_action_dismiss(&unit->erp_action);
3550 * purpose: moves erp_action to 'erp running list'
3555 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3557 struct zfcp_adapter *adapter = erp_action->adapter;
3559 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3560 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3561 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3567 * purpose: moves erp_action to 'erp ready list'
3572 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3574 struct zfcp_adapter *adapter = erp_action->adapter;
3576 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3577 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3578 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3581 #undef ZFCP_LOG_AREA