2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
26 static int zfcp_erp_adisc(struct zfcp_port *);
27 static void zfcp_erp_adisc_handler(unsigned long);
29 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
30 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
31 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
32 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
34 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
35 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
37 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
38 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
39 static void zfcp_erp_port_block(struct zfcp_port *, int);
40 static void zfcp_erp_port_unblock(struct zfcp_port *);
41 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
42 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
44 static int zfcp_erp_thread(void *);
46 static int zfcp_erp_strategy(struct zfcp_erp_action *);
48 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
49 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
50 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
51 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
52 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
53 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
54 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
56 struct zfcp_unit *, int);
57 static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
58 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
60 struct zfcp_unit *, int);
61 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
62 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
67 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
68 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
69 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
73 struct zfcp_erp_action *);
75 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
76 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
78 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
79 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
80 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
83 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
84 struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
86 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
87 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
89 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
90 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
91 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
94 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
95 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
96 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
97 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
99 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
100 struct zfcp_port *, struct zfcp_unit *);
101 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
102 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
103 struct zfcp_port *, struct zfcp_unit *,
106 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
107 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
109 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
110 static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
112 static void zfcp_erp_memwait_handler(unsigned long);
115 * zfcp_close_qdio - close qdio queues for an adapter
117 static void zfcp_close_qdio(struct zfcp_adapter *adapter)
119 struct zfcp_qdio_queue *req_queue;
122 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
125 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
126 req_queue = &adapter->request_queue;
127 write_lock_irq(&req_queue->queue_lock);
128 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
129 write_unlock_irq(&req_queue->queue_lock);
131 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
132 while (qdio_shutdown(adapter->ccw_device,
133 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
135 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
137 /* cleanup used outbound sbals */
138 count = atomic_read(&req_queue->free_count);
139 if (count < QDIO_MAX_BUFFERS_PER_Q) {
140 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
141 count = QDIO_MAX_BUFFERS_PER_Q - count;
142 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
144 req_queue->free_index = 0;
145 atomic_set(&req_queue->free_count, 0);
146 req_queue->distance_from_int = 0;
147 adapter->response_queue.free_index = 0;
148 atomic_set(&adapter->response_queue.free_count, 0);
152 * zfcp_close_fsf - stop FSF operations for an adapter
154 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
155 * requests waiting for completion; especially this returns SCSI commands
158 static void zfcp_close_fsf(struct zfcp_adapter *adapter)
160 /* close queues to ensure that buffers are not accessed by adapter */
161 zfcp_close_qdio(adapter);
162 zfcp_fsf_req_dismiss_all(adapter);
163 /* reset FSF request sequence number */
164 adapter->fsf_req_seq_no = 0;
165 /* all ports and units are closed */
166 zfcp_erp_modify_adapter_status(adapter,
167 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
171 * zfcp_fsf_request_timeout_handler - called if a request timed out
172 * @data: pointer to adapter for handler function
174 * This function needs to be called if requests (ELS, Generic Service,
175 * or SCSI commands) exceed a certain time limit. The assumption is
176 * that after the time limit the adapter get stuck. So we trigger a reopen of
179 static void zfcp_fsf_request_timeout_handler(unsigned long data)
181 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
182 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
185 void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
187 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
188 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
189 fsf_req->timer.expires = jiffies + timeout;
190 add_timer(&fsf_req->timer);
196 * purpose: called if an adapter failed,
197 * initiates adapter recovery which is done
200 * returns: 0 - initiated action successfully
201 * <0 - failed to initiate action
204 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
208 debug_text_event(adapter->erp_dbf, 5, "a_ro");
209 ZFCP_LOG_DEBUG("reopen adapter %s\n",
210 zfcp_get_busid_by_adapter(adapter));
212 zfcp_erp_adapter_block(adapter, clear_mask);
214 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
215 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
216 zfcp_get_busid_by_adapter(adapter));
217 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
218 /* ensure propagation of failed status to new devices */
219 zfcp_erp_adapter_failed(adapter);
223 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
224 adapter, NULL, NULL);
233 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
234 * used to ensure the correct locking
236 * returns: 0 - initiated action successfully
237 * <0 - failed to initiate action
240 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
245 read_lock_irqsave(&zfcp_data.config_lock, flags);
246 write_lock(&adapter->erp_lock);
247 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
248 write_unlock(&adapter->erp_lock);
249 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
255 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
259 retval = zfcp_erp_adapter_reopen(adapter,
260 ZFCP_STATUS_COMMON_RUNNING |
261 ZFCP_STATUS_COMMON_ERP_FAILED |
268 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
272 retval = zfcp_erp_port_reopen(port,
273 ZFCP_STATUS_COMMON_RUNNING |
274 ZFCP_STATUS_COMMON_ERP_FAILED |
281 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
285 retval = zfcp_erp_unit_reopen(unit,
286 ZFCP_STATUS_COMMON_RUNNING |
287 ZFCP_STATUS_COMMON_ERP_FAILED |
295 * zfcp_erp_adisc - send ADISC ELS command
296 * @port: port structure
299 zfcp_erp_adisc(struct zfcp_port *port)
301 struct zfcp_adapter *adapter = port->adapter;
302 struct zfcp_send_els *send_els;
303 struct zfcp_ls_adisc *adisc;
304 void *address = NULL;
307 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
308 if (send_els == NULL)
311 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
312 if (send_els->req == NULL)
314 sg_init_table(send_els->req, 1);
316 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
317 if (send_els->resp == NULL)
319 sg_init_table(send_els->resp, 1);
321 address = (void *) get_zeroed_page(GFP_ATOMIC);
325 zfcp_address_to_sg(address, send_els->req, sizeof(struct zfcp_ls_adisc));
326 address += PAGE_SIZE >> 1;
327 zfcp_address_to_sg(address, send_els->resp, sizeof(struct zfcp_ls_adisc_acc));
328 send_els->req_count = send_els->resp_count = 1;
330 send_els->adapter = adapter;
331 send_els->port = port;
332 send_els->d_id = port->d_id;
333 send_els->handler = zfcp_erp_adisc_handler;
334 send_els->handler_data = (unsigned long) send_els;
336 adisc = zfcp_sg_to_address(send_els->req);
337 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
339 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
340 without FC-AL-2 capability, so we don't set it */
341 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
342 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
343 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
344 ZFCP_LOG_INFO("ADISC request from s_id 0x%06x to d_id 0x%06x "
345 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
346 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
347 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
348 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
351 retval = zfcp_fsf_send_els(send_els);
353 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
354 "0x%06x on adapter %s\n", send_els->d_id,
355 zfcp_get_busid_by_adapter(adapter));
365 __free_pages(sg_page(send_els->req), 0);
366 if (send_els != NULL) {
367 kfree(send_els->req);
368 kfree(send_els->resp);
377 * zfcp_erp_adisc_handler - handler for ADISC ELS command
378 * @data: pointer to struct zfcp_send_els
380 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
383 zfcp_erp_adisc_handler(unsigned long data)
385 struct zfcp_send_els *send_els;
386 struct zfcp_port *port;
387 struct zfcp_adapter *adapter;
389 struct zfcp_ls_adisc_acc *adisc;
391 send_els = (struct zfcp_send_els *) data;
392 adapter = send_els->adapter;
393 port = send_els->port;
394 d_id = send_els->d_id;
396 /* request rejected or timed out */
397 if (send_els->status != 0) {
398 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
399 "force physical port reopen "
400 "(adapter %s, port d_id=0x%06x)\n",
401 zfcp_get_busid_by_adapter(adapter), d_id);
402 debug_text_event(adapter->erp_dbf, 3, "forcreop");
403 if (zfcp_erp_port_forced_reopen(port, 0))
404 ZFCP_LOG_NORMAL("failed reopen of port "
405 "(adapter %s, wwpn=0x%016Lx)\n",
406 zfcp_get_busid_by_port(port),
411 adisc = zfcp_sg_to_address(send_els->resp);
413 ZFCP_LOG_INFO("ADISC response from d_id 0x%06x to s_id "
414 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
415 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
416 d_id, fc_host_port_id(adapter->scsi_host),
417 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
418 adisc->hard_nport_id, adisc->nport_id);
420 /* set wwnn for port */
422 port->wwnn = adisc->wwnn;
424 if (port->wwpn != adisc->wwpn) {
425 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
426 "port (adapter %s, wwpn=0x%016Lx, "
427 "adisc_resp_wwpn=0x%016Lx)\n",
428 zfcp_get_busid_by_port(port),
429 port->wwpn, (wwn_t) adisc->wwpn);
430 if (zfcp_erp_port_reopen(port, 0))
431 ZFCP_LOG_NORMAL("failed reopen of port "
432 "(adapter %s, wwpn=0x%016Lx)\n",
433 zfcp_get_busid_by_port(port),
439 __free_pages(sg_page(send_els->req), 0);
440 kfree(send_els->req);
441 kfree(send_els->resp);
447 * zfcp_test_link - lightweight link test procedure
448 * @port: port to be tested
450 * Test status of a link to a remote port using the ELS command ADISC.
453 zfcp_test_link(struct zfcp_port *port)
458 retval = zfcp_erp_adisc(port);
461 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
462 "on adapter %s\n ", port->wwpn,
463 zfcp_get_busid_by_port(port));
464 retval = zfcp_erp_port_forced_reopen(port, 0);
466 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
467 "on adapter %s failed\n", port->wwpn,
468 zfcp_get_busid_by_port(port));
480 * purpose: called if a port failed to be opened normally
481 * initiates Forced Reopen recovery which is done
484 * returns: 0 - initiated action successfully
485 * <0 - failed to initiate action
488 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
491 struct zfcp_adapter *adapter = port->adapter;
493 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
494 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
496 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
497 port->wwpn, zfcp_get_busid_by_port(port));
499 zfcp_erp_port_block(port, clear_mask);
501 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
502 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
503 "on adapter %s\n", port->wwpn,
504 zfcp_get_busid_by_port(port));
505 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
506 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
511 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
512 port->adapter, port, NULL);
521 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
522 * used to ensure the correct locking
524 * returns: 0 - initiated action successfully
525 * <0 - failed to initiate action
528 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
532 struct zfcp_adapter *adapter;
534 adapter = port->adapter;
535 read_lock_irqsave(&zfcp_data.config_lock, flags);
536 write_lock(&adapter->erp_lock);
537 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
538 write_unlock(&adapter->erp_lock);
539 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
547 * purpose: called if a port is to be opened
548 * initiates Reopen recovery which is done
551 * returns: 0 - initiated action successfully
552 * <0 - failed to initiate action
555 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
558 struct zfcp_adapter *adapter = port->adapter;
560 debug_text_event(adapter->erp_dbf, 5, "p_ro");
561 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
563 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
564 port->wwpn, zfcp_get_busid_by_port(port));
566 zfcp_erp_port_block(port, clear_mask);
568 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
569 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
570 "on adapter %s\n", port->wwpn,
571 zfcp_get_busid_by_port(port));
572 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
573 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
574 /* ensure propagation of failed status to new devices */
575 zfcp_erp_port_failed(port);
580 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
581 port->adapter, port, NULL);
588 * zfcp_erp_port_reopen - initiate reopen of a remote port
589 * @port: port to be reopened
590 * @clear_mask: specifies flags in port status to be cleared
591 * Return: 0 on success, < 0 on error
593 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
594 * correct locking. An error recovery task is initiated to do the reopen.
595 * To wait for the completion of the reopen zfcp_erp_wait should be used.
598 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
602 struct zfcp_adapter *adapter = port->adapter;
604 read_lock_irqsave(&zfcp_data.config_lock, flags);
605 write_lock(&adapter->erp_lock);
606 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
607 write_unlock(&adapter->erp_lock);
608 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
616 * purpose: called if a unit is to be opened
617 * initiates Reopen recovery which is done
620 * returns: 0 - initiated action successfully
621 * <0 - failed to initiate action
624 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
627 struct zfcp_adapter *adapter = unit->port->adapter;
629 debug_text_event(adapter->erp_dbf, 5, "u_ro");
630 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
631 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
632 "on adapter %s\n", unit->fcp_lun,
633 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
635 zfcp_erp_unit_block(unit, clear_mask);
637 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
638 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
639 "on port 0x%016Lx on adapter %s\n",
640 unit->fcp_lun, unit->port->wwpn,
641 zfcp_get_busid_by_unit(unit));
642 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
643 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
649 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
650 unit->port->adapter, unit->port, unit);
656 * zfcp_erp_unit_reopen - initiate reopen of a unit
657 * @unit: unit to be reopened
658 * @clear_mask: specifies flags in unit status to be cleared
659 * Return: 0 on success, < 0 on error
661 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
662 * locking. An error recovery task is initiated to do the reopen.
663 * To wait for the completion of the reopen zfcp_erp_wait should be used.
666 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
670 struct zfcp_adapter *adapter;
671 struct zfcp_port *port;
674 adapter = port->adapter;
676 read_lock_irqsave(&zfcp_data.config_lock, flags);
677 write_lock(&adapter->erp_lock);
678 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
679 write_unlock(&adapter->erp_lock);
680 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
686 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
688 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
690 debug_text_event(adapter->erp_dbf, 6, "a_bl");
691 zfcp_erp_modify_adapter_status(adapter,
692 ZFCP_STATUS_COMMON_UNBLOCKED |
693 clear_mask, ZFCP_CLEAR);
697 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
699 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
701 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
702 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
708 * purpose: disable I/O,
709 * return any open requests and clean them up,
710 * aim: no pending and incoming I/O
715 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
717 struct zfcp_adapter *adapter = port->adapter;
719 debug_text_event(adapter->erp_dbf, 6, "p_bl");
720 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
721 zfcp_erp_modify_port_status(port,
722 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
729 * purpose: enable I/O
734 zfcp_erp_port_unblock(struct zfcp_port *port)
736 struct zfcp_adapter *adapter = port->adapter;
738 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
739 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
740 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
746 * purpose: disable I/O,
747 * return any open requests and clean them up,
748 * aim: no pending and incoming I/O
753 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
755 struct zfcp_adapter *adapter = unit->port->adapter;
757 debug_text_event(adapter->erp_dbf, 6, "u_bl");
758 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
759 zfcp_erp_modify_unit_status(unit,
760 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
767 * purpose: enable I/O
772 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
774 struct zfcp_adapter *adapter = unit->port->adapter;
776 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
777 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
778 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
782 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
784 struct zfcp_adapter *adapter = erp_action->adapter;
786 debug_text_event(adapter->erp_dbf, 4, "a_ar");
787 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
789 zfcp_erp_action_to_ready(erp_action);
790 up(&adapter->erp_ready_sem);
798 * returns: <0 erp_action not found in any list
799 * ZFCP_ERP_ACTION_READY erp_action is in ready list
800 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
802 * locks: erp_lock must be held
805 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
807 int retval = -EINVAL;
808 struct list_head *entry;
809 struct zfcp_erp_action *entry_erp_action;
810 struct zfcp_adapter *adapter = erp_action->adapter;
812 /* search in running list */
813 list_for_each(entry, &adapter->erp_running_head) {
815 list_entry(entry, struct zfcp_erp_action, list);
816 if (entry_erp_action == erp_action) {
817 retval = ZFCP_ERP_ACTION_RUNNING;
821 /* search in ready list */
822 list_for_each(entry, &adapter->erp_ready_head) {
824 list_entry(entry, struct zfcp_erp_action, list);
825 if (entry_erp_action == erp_action) {
826 retval = ZFCP_ERP_ACTION_READY;
836 * purpose: checks current status of action (timed out, dismissed, ...)
837 * and does appropriate preparations (dismiss fsf request, ...)
839 * locks: called under erp_lock (disabled interrupts)
842 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
844 struct zfcp_adapter *adapter = erp_action->adapter;
846 if (erp_action->fsf_req) {
847 /* take lock to ensure that request is not deleted meanwhile */
848 spin_lock(&adapter->req_list_lock);
849 if (zfcp_reqlist_find(adapter, erp_action->fsf_req->req_id)) {
850 /* fsf_req still exists */
851 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
852 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
853 sizeof (unsigned long));
854 /* dismiss fsf_req of timed out/dismissed erp_action */
855 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
856 ZFCP_STATUS_ERP_TIMEDOUT)) {
857 debug_text_event(adapter->erp_dbf, 3,
859 erp_action->fsf_req->status |=
860 ZFCP_STATUS_FSFREQ_DISMISSED;
862 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
863 ZFCP_LOG_NORMAL("error: erp step timed out "
864 "(action=%d, fsf_req=%p)\n ",
866 erp_action->fsf_req);
869 * If fsf_req is neither dismissed nor completed
870 * then keep it running asynchronously and don't mess
871 * with the association of erp_action and fsf_req.
873 if (erp_action->fsf_req->status &
874 (ZFCP_STATUS_FSFREQ_COMPLETED |
875 ZFCP_STATUS_FSFREQ_DISMISSED)) {
876 /* forget about association between fsf_req
878 erp_action->fsf_req = NULL;
881 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
883 * even if this fsf_req has gone, forget about
884 * association between erp_action and fsf_req
886 erp_action->fsf_req = NULL;
888 spin_unlock(&adapter->req_list_lock);
890 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
894 * zfcp_erp_async_handler_nolock - complete erp_action
896 * Used for normal completion, time-out, dismissal and failure after
897 * low memory condition.
899 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
900 unsigned long set_mask)
902 struct zfcp_adapter *adapter = erp_action->adapter;
904 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
905 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
906 debug_event(adapter->erp_dbf, 2, &erp_action->action,
908 erp_action->status |= set_mask;
909 zfcp_erp_action_ready(erp_action);
911 /* action is ready or gone - nothing to do */
912 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
913 debug_event(adapter->erp_dbf, 3, &erp_action->action,
919 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
921 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
922 unsigned long set_mask)
924 struct zfcp_adapter *adapter = erp_action->adapter;
927 write_lock_irqsave(&adapter->erp_lock, flags);
928 zfcp_erp_async_handler_nolock(erp_action, set_mask);
929 write_unlock_irqrestore(&adapter->erp_lock, flags);
933 * purpose: is called for erp_action which was slept waiting for
934 * memory becoming avaliable,
935 * will trigger that this action will be continued
938 zfcp_erp_memwait_handler(unsigned long data)
940 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
941 struct zfcp_adapter *adapter = erp_action->adapter;
943 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
944 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
946 zfcp_erp_async_handler(erp_action, 0);
950 * purpose: is called if an asynchronous erp step timed out,
951 * action gets an appropriate flag and will be processed
954 static void zfcp_erp_timeout_handler(unsigned long data)
956 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
957 struct zfcp_adapter *adapter = erp_action->adapter;
959 debug_text_event(adapter->erp_dbf, 2, "a_th");
960 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
962 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
966 * zfcp_erp_action_dismiss - dismiss an erp_action
968 * adapter->erp_lock must be held
970 * Dismissal of an erp_action is usually required if an erp_action of
971 * higher priority is generated.
973 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
975 struct zfcp_adapter *adapter = erp_action->adapter;
977 debug_text_event(adapter->erp_dbf, 2, "a_adis");
978 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
980 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
981 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
982 zfcp_erp_action_ready(erp_action);
986 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
990 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
992 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
994 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
996 zfcp_get_busid_by_adapter(adapter));
997 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
999 wait_event(adapter->erp_thread_wqh,
1000 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1002 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1005 return (retval < 0);
1015 * context: process (i.e. proc-fs or rmmod/insmod)
1017 * note: The caller of this routine ensures that the specified
1018 * adapter has been shut down and that this operation
1019 * has been completed. Thus, there are no pending erp_actions
1020 * which would need to be handled here.
1023 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1027 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1028 up(&adapter->erp_ready_sem);
1030 wait_event(adapter->erp_thread_wqh,
1031 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1034 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1037 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1043 * purpose: is run as a kernel thread,
1044 * goes through list of error recovery actions of associated adapter
1045 * and delegates single action to execution
1050 zfcp_erp_thread(void *data)
1052 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1053 struct list_head *next;
1054 struct zfcp_erp_action *erp_action;
1055 unsigned long flags;
1057 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1058 /* Block all signals */
1059 siginitsetinv(¤t->blocked, 0);
1060 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1061 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1062 wake_up(&adapter->erp_thread_wqh);
1064 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1065 &adapter->status)) {
1067 write_lock_irqsave(&adapter->erp_lock, flags);
1068 next = adapter->erp_ready_head.next;
1069 write_unlock_irqrestore(&adapter->erp_lock, flags);
1071 if (next != &adapter->erp_ready_head) {
1073 list_entry(next, struct zfcp_erp_action, list);
1075 * process action (incl. [re]moving it
1076 * from 'ready' queue)
1078 zfcp_erp_strategy(erp_action);
1082 * sleep as long as there is nothing to do, i.e.
1083 * no action in 'ready' queue to be processed and
1084 * thread is not to be killed
1086 down_interruptible(&adapter->erp_ready_sem);
1087 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1090 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1091 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1092 wake_up(&adapter->erp_thread_wqh);
1100 * purpose: drives single error recovery action and schedules higher and
1101 * subordinate actions, if necessary
1103 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1104 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1105 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1106 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1107 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1110 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1113 struct zfcp_adapter *adapter = erp_action->adapter;
1114 struct zfcp_port *port = erp_action->port;
1115 struct zfcp_unit *unit = erp_action->unit;
1116 int action = erp_action->action;
1117 u32 status = erp_action->status;
1118 unsigned long flags;
1120 /* serialise dismissing, timing out, moving, enqueueing */
1121 read_lock_irqsave(&zfcp_data.config_lock, flags);
1122 write_lock(&adapter->erp_lock);
1124 /* dequeue dismissed action and leave, if required */
1125 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1126 if (retval == ZFCP_ERP_DISMISSED) {
1127 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1132 * move action to 'running' queue before processing it
1133 * (to avoid a race condition regarding moving the
1134 * action to the 'running' queue and back)
1136 zfcp_erp_action_to_running(erp_action);
1139 * try to process action as far as possible,
1140 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1141 * afterwards the lock is required again for the following reasons:
1142 * - dequeueing of finished action and enqueueing of
1143 * follow-up actions must be atomic so that any other
1144 * reopen-routine does not believe there is nothing to do
1145 * and that it is safe to enqueue something else,
1146 * - we want to force any control thread which is dismissing
1147 * actions to finish this before we decide about
1148 * necessary steps to be taken here further
1150 write_unlock(&adapter->erp_lock);
1151 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1152 retval = zfcp_erp_strategy_do_action(erp_action);
1153 read_lock_irqsave(&zfcp_data.config_lock, flags);
1154 write_lock(&adapter->erp_lock);
1157 * check for dismissed status again to avoid follow-up actions,
1158 * failing of targets and so on for dismissed actions,
1159 * we go through down() here because there has been an up()
1161 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1162 retval = ZFCP_ERP_CONTINUES;
1165 case ZFCP_ERP_NOMEM:
1166 /* no memory to continue immediately, let it sleep */
1167 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1168 ++adapter->erp_low_mem_count;
1169 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1171 /* This condition is true if there is no memory available
1172 for any erp_action on this adapter. This implies that there
1173 are no elements in the memory pool(s) left for erp_actions.
1174 This might happen if an erp_action that used a memory pool
1175 element was timed out.
1177 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1178 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1179 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1180 "restarting I/O on adapter %s "
1181 "to free mempool\n",
1182 zfcp_get_busid_by_adapter(adapter));
1183 zfcp_erp_adapter_reopen_internal(adapter, 0);
1185 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1186 retval = zfcp_erp_strategy_memwait(erp_action);
1189 case ZFCP_ERP_CONTINUES:
1190 /* leave since this action runs asynchronously */
1191 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1192 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1193 --adapter->erp_low_mem_count;
1194 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1198 /* ok, finished action (whatever its result is) */
1200 /* check for unrecoverable targets */
1201 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1203 /* action must be dequeued (here to allow for further ones) */
1204 zfcp_erp_action_dequeue(erp_action);
1207 * put this target through the erp mill again if someone has
1208 * requested to change the status of a target being online
1209 * to offline or the other way around
1210 * (old retval is preserved if nothing has to be done here)
1212 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1213 port, unit, retval);
1216 * leave if target is in permanent error state or if
1217 * action is repeated in order to process state change
1219 if (retval == ZFCP_ERP_EXIT) {
1220 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1224 /* trigger follow up actions */
1225 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1228 write_unlock(&adapter->erp_lock);
1229 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1231 if (retval != ZFCP_ERP_CONTINUES)
1232 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1235 * a few tasks remain when the erp queues are empty
1236 * (don't do that if the last action evaluated was dismissed
1237 * since this clearly indicates that there is more to come) :
1238 * - close the name server port if it is open yet
1239 * (enqueues another [probably] final action)
1240 * - otherwise, wake up whoever wants to be woken when we are
1243 if (retval != ZFCP_ERP_DISMISSED)
1244 zfcp_erp_strategy_check_queues(adapter);
1246 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1256 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1257 * retval - otherwise
1260 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1262 struct zfcp_adapter *adapter = erp_action->adapter;
1264 zfcp_erp_strategy_check_fsfreq(erp_action);
1266 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1267 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1268 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1269 zfcp_erp_action_dequeue(erp_action);
1270 retval = ZFCP_ERP_DISMISSED;
1272 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1278 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1280 int retval = ZFCP_ERP_FAILED;
1281 struct zfcp_adapter *adapter = erp_action->adapter;
1284 * try to execute/continue action as far as possible,
1285 * note: no lock in subsequent strategy routines
1286 * (this allows these routine to call schedule, e.g.
1287 * kmalloc with such flags or qdio_initialize & friends)
1288 * Note: in case of timeout, the seperate strategies will fail
1289 * anyhow. No need for a special action. Even worse, a nameserver
1290 * failure would not wake up waiting ports without the call.
1292 switch (erp_action->action) {
1294 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1295 retval = zfcp_erp_adapter_strategy(erp_action);
1298 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1299 retval = zfcp_erp_port_forced_strategy(erp_action);
1302 case ZFCP_ERP_ACTION_REOPEN_PORT:
1303 retval = zfcp_erp_port_strategy(erp_action);
1306 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1307 retval = zfcp_erp_unit_strategy(erp_action);
1311 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1312 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1314 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1315 "adapter %s (action=%d)\n",
1316 zfcp_get_busid_by_adapter(erp_action->adapter),
1317 erp_action->action);
1326 * purpose: triggers retry of this action after a certain amount of time
1327 * by means of timer provided by erp_action
1329 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1332 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1334 int retval = ZFCP_ERP_CONTINUES;
1335 struct zfcp_adapter *adapter = erp_action->adapter;
1337 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1338 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1339 init_timer(&erp_action->timer);
1340 erp_action->timer.function = zfcp_erp_memwait_handler;
1341 erp_action->timer.data = (unsigned long) erp_action;
1342 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1343 add_timer(&erp_action->timer);
1349 * function: zfcp_erp_adapter_failed
1351 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1355 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1357 zfcp_erp_modify_adapter_status(adapter,
1358 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1359 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1360 zfcp_get_busid_by_adapter(adapter));
1361 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1365 * function: zfcp_erp_port_failed
1367 * purpose: sets the port and all underlying devices to ERP_FAILED
1371 zfcp_erp_port_failed(struct zfcp_port *port)
1373 zfcp_erp_modify_port_status(port,
1374 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1376 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1377 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1378 "port d_id=0x%06x)\n",
1379 zfcp_get_busid_by_port(port), port->d_id);
1381 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1382 zfcp_get_busid_by_port(port), port->wwpn);
1384 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1385 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1389 * function: zfcp_erp_unit_failed
1391 * purpose: sets the unit to ERP_FAILED
1395 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1397 zfcp_erp_modify_unit_status(unit,
1398 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1400 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1401 " on adapter %s\n", unit->fcp_lun,
1402 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1403 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1404 debug_event(unit->port->adapter->erp_dbf, 2,
1405 &unit->fcp_lun, sizeof (fcp_lun_t));
1409 * function: zfcp_erp_strategy_check_target
1411 * purpose: increments the erp action count on the device currently in
1412 * recovery if the action failed or resets the count in case of
1413 * success. If a maximum count is exceeded the device is marked
1415 * The 'blocked' state of a target which has been recovered
1416 * successfully is reset.
1418 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1419 * ZFCP_ERP_SUCCEEDED - action finished successfully
1420 * ZFCP_ERP_EXIT - action failed and will not continue
1423 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1425 struct zfcp_adapter *adapter = erp_action->adapter;
1426 struct zfcp_port *port = erp_action->port;
1427 struct zfcp_unit *unit = erp_action->unit;
1429 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1430 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1431 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1433 switch (erp_action->action) {
1435 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1436 result = zfcp_erp_strategy_check_unit(unit, result);
1439 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1440 case ZFCP_ERP_ACTION_REOPEN_PORT:
1441 result = zfcp_erp_strategy_check_port(port, result);
1444 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1445 result = zfcp_erp_strategy_check_adapter(adapter, result);
1453 zfcp_erp_strategy_statechange(int action,
1455 struct zfcp_adapter *adapter,
1456 struct zfcp_port *port,
1457 struct zfcp_unit *unit, int retval)
1459 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1460 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1464 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1465 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1467 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1468 retval = ZFCP_ERP_EXIT;
1472 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1473 case ZFCP_ERP_ACTION_REOPEN_PORT:
1474 if (zfcp_erp_strategy_statechange_detected(&port->status,
1476 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1477 retval = ZFCP_ERP_EXIT;
1481 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1482 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1484 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1485 retval = ZFCP_ERP_EXIT;
1494 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1497 /* take it online */
1498 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1499 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1500 /* take it offline */
1501 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1502 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1506 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1508 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1509 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1510 sizeof (fcp_lun_t));
1513 case ZFCP_ERP_SUCCEEDED :
1514 atomic_set(&unit->erp_counter, 0);
1515 zfcp_erp_unit_unblock(unit);
1517 case ZFCP_ERP_FAILED :
1518 atomic_inc(&unit->erp_counter);
1519 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1520 zfcp_erp_unit_failed(unit);
1522 case ZFCP_ERP_EXIT :
1527 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1528 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1529 result = ZFCP_ERP_EXIT;
1536 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1538 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1539 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1542 case ZFCP_ERP_SUCCEEDED :
1543 atomic_set(&port->erp_counter, 0);
1544 zfcp_erp_port_unblock(port);
1546 case ZFCP_ERP_FAILED :
1547 atomic_inc(&port->erp_counter);
1548 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1549 zfcp_erp_port_failed(port);
1551 case ZFCP_ERP_EXIT :
1556 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1557 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1558 result = ZFCP_ERP_EXIT;
1565 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1567 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1570 case ZFCP_ERP_SUCCEEDED :
1571 atomic_set(&adapter->erp_counter, 0);
1572 zfcp_erp_adapter_unblock(adapter);
1574 case ZFCP_ERP_FAILED :
1575 atomic_inc(&adapter->erp_counter);
1576 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1577 zfcp_erp_adapter_failed(adapter);
1579 case ZFCP_ERP_EXIT :
1584 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1585 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1586 result = ZFCP_ERP_EXIT;
1592 struct zfcp_erp_add_work {
1593 struct zfcp_unit *unit;
1594 struct work_struct work;
1598 * zfcp_erp_scsi_scan
1599 * @data: pointer to a struct zfcp_erp_add_work
1601 * Registers a logical unit with the SCSI stack.
1603 static void zfcp_erp_scsi_scan(struct work_struct *work)
1605 struct zfcp_erp_add_work *p =
1606 container_of(work, struct zfcp_erp_add_work, work);
1607 struct zfcp_unit *unit = p->unit;
1608 struct fc_rport *rport = unit->port->rport;
1609 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1611 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1612 zfcp_unit_put(unit);
1617 * zfcp_erp_schedule_work
1618 * @unit: pointer to unit which should be registered with SCSI stack
1620 * Schedules work which registers a unit with the SCSI stack
1623 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1625 struct zfcp_erp_add_work *p;
1627 p = kzalloc(sizeof(*p), GFP_KERNEL);
1629 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1630 "the FCP-LUN 0x%Lx connected to "
1631 "the port with WWPN 0x%Lx connected to "
1632 "the adapter %s with the SCSI stack.\n",
1635 zfcp_get_busid_by_unit(unit));
1639 zfcp_unit_get(unit);
1640 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1641 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1643 schedule_work(&p->work);
1649 * purpose: remaining things in good cases,
1650 * escalation in bad cases
1655 zfcp_erp_strategy_followup_actions(int action,
1656 struct zfcp_adapter *adapter,
1657 struct zfcp_port *port,
1658 struct zfcp_unit *unit, int status)
1660 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1661 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1663 /* initiate follow-up actions depending on success of finished action */
1666 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1667 if (status == ZFCP_ERP_SUCCEEDED)
1668 zfcp_erp_port_reopen_all_internal(adapter, 0);
1670 zfcp_erp_adapter_reopen_internal(adapter, 0);
1673 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1674 if (status == ZFCP_ERP_SUCCEEDED)
1675 zfcp_erp_port_reopen_internal(port, 0);
1677 zfcp_erp_adapter_reopen_internal(adapter, 0);
1680 case ZFCP_ERP_ACTION_REOPEN_PORT:
1681 if (status == ZFCP_ERP_SUCCEEDED)
1682 zfcp_erp_unit_reopen_all_internal(port, 0);
1684 zfcp_erp_port_forced_reopen_internal(port, 0);
1687 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1688 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1689 if (status != ZFCP_ERP_SUCCEEDED)
1690 zfcp_erp_port_reopen_internal(unit->port, 0);
1698 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1700 unsigned long flags;
1702 read_lock_irqsave(&zfcp_data.config_lock, flags);
1703 read_lock(&adapter->erp_lock);
1704 if (list_empty(&adapter->erp_ready_head) &&
1705 list_empty(&adapter->erp_running_head)) {
1706 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1707 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1709 wake_up(&adapter->erp_done_wqh);
1711 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1712 read_unlock(&adapter->erp_lock);
1713 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1719 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1720 * @adapter: adapter for which to wait for completion of its error recovery
1724 zfcp_erp_wait(struct zfcp_adapter *adapter)
1728 wait_event(adapter->erp_done_wqh,
1729 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1736 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1737 u32 mask, int set_or_clear)
1739 struct zfcp_port *port;
1740 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1742 if (set_or_clear == ZFCP_SET) {
1743 atomic_set_mask(mask, &adapter->status);
1744 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1746 atomic_clear_mask(mask, &adapter->status);
1747 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1748 atomic_set(&adapter->erp_counter, 0);
1749 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1751 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1753 /* Deal with all underlying devices, only pass common_mask */
1755 list_for_each_entry(port, &adapter->port_list_head, list)
1756 zfcp_erp_modify_port_status(port, common_mask,
1761 * function: zfcp_erp_modify_port_status
1763 * purpose: sets the port and all underlying devices to ERP_FAILED
1767 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1769 struct zfcp_unit *unit;
1770 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1772 if (set_or_clear == ZFCP_SET) {
1773 atomic_set_mask(mask, &port->status);
1774 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1776 atomic_clear_mask(mask, &port->status);
1777 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1778 atomic_set(&port->erp_counter, 0);
1779 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1781 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1782 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1784 /* Modify status of all underlying devices, only pass common mask */
1786 list_for_each_entry(unit, &port->unit_list_head, list)
1787 zfcp_erp_modify_unit_status(unit, common_mask,
1792 * function: zfcp_erp_modify_unit_status
1794 * purpose: sets the unit to ERP_FAILED
1798 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1800 if (set_or_clear == ZFCP_SET) {
1801 atomic_set_mask(mask, &unit->status);
1802 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1804 atomic_clear_mask(mask, &unit->status);
1805 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1806 atomic_set(&unit->erp_counter, 0);
1808 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1810 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1811 sizeof (fcp_lun_t));
1812 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1818 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1819 * used to ensure the correct locking
1821 * returns: 0 - initiated action successfully
1822 * <0 - failed to initiate action
1825 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1828 unsigned long flags;
1830 read_lock_irqsave(&zfcp_data.config_lock, flags);
1831 write_lock(&adapter->erp_lock);
1832 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1833 write_unlock(&adapter->erp_lock);
1834 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1840 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1843 struct zfcp_port *port;
1845 list_for_each_entry(port, &adapter->port_list_head, list)
1846 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1847 zfcp_erp_port_reopen_internal(port, clear_mask);
1860 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1863 struct zfcp_unit *unit;
1865 list_for_each_entry(unit, &port->unit_list_head, list)
1866 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1874 * purpose: this routine executes the 'Reopen Adapter' action
1875 * (the entire action is processed synchronously, since
1876 * there are no actions which might be run concurrently
1879 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1880 * ZFCP_ERP_FAILED - action finished unsuccessfully
1883 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1886 struct zfcp_adapter *adapter = erp_action->adapter;
1888 retval = zfcp_erp_adapter_strategy_close(erp_action);
1889 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1890 retval = ZFCP_ERP_EXIT;
1892 retval = zfcp_erp_adapter_strategy_open(erp_action);
1894 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1895 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1896 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1898 if (retval == ZFCP_ERP_FAILED) {
1899 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1900 "to recover itself\n",
1901 zfcp_get_busid_by_adapter(adapter));
1902 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
1913 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1914 * ZFCP_ERP_FAILED - action finished unsuccessfully
1917 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1921 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1922 &erp_action->adapter->status);
1923 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1924 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1925 &erp_action->adapter->status);
1935 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1936 * ZFCP_ERP_FAILED - action finished unsuccessfully
1939 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1943 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1944 &erp_action->adapter->status);
1945 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1946 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1947 &erp_action->adapter->status);
1953 * function: zfcp_register_adapter
1955 * purpose: allocate the irq associated with this devno and register
1956 * the FSF adapter with the SCSI stack
1961 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1963 int retval = ZFCP_ERP_SUCCEEDED;
1968 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1969 if (retval != ZFCP_ERP_SUCCEEDED)
1972 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1973 if (retval != ZFCP_ERP_SUCCEEDED)
1974 goto failed_openfcp;
1976 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1980 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1981 &erp_action->adapter->status);
1984 zfcp_close_fsf(erp_action->adapter);
1986 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1987 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1988 ZFCP_STATUS_ADAPTER_XPORT_OK,
1989 &erp_action->adapter->status);
1995 * function: zfcp_qdio_init
1997 * purpose: setup QDIO operation for specified adapter
1999 * returns: 0 - successful setup
2003 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2007 volatile struct qdio_buffer_element *sbale;
2008 struct zfcp_adapter *adapter = erp_action->adapter;
2010 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2011 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2013 zfcp_get_busid_by_adapter(adapter));
2017 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2018 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2020 zfcp_get_busid_by_adapter(adapter));
2021 goto failed_qdio_establish;
2023 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2025 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2026 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2028 zfcp_get_busid_by_adapter(adapter));
2029 goto failed_qdio_activate;
2031 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2034 * put buffers into response queue,
2036 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2037 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2039 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2043 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2044 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2045 zfcp_get_busid_by_adapter(adapter),
2046 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2048 retval = do_QDIO(adapter->ccw_device,
2049 QDIO_FLAG_SYNC_INPUT,
2050 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2053 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2055 goto failed_do_qdio;
2057 adapter->response_queue.free_index = 0;
2058 atomic_set(&adapter->response_queue.free_count, 0);
2059 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2060 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2062 /* set index of first avalable SBALS / number of available SBALS */
2063 adapter->request_queue.free_index = 0;
2064 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2065 adapter->request_queue.distance_from_int = 0;
2067 /* initialize waitqueue used to wait for free SBALs in requests queue */
2068 init_waitqueue_head(&adapter->request_wq);
2070 /* ok, we did it - skip all cleanups for different failures */
2071 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2072 retval = ZFCP_ERP_SUCCEEDED;
2078 failed_qdio_activate:
2079 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2080 while (qdio_shutdown(adapter->ccw_device,
2081 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2083 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2085 failed_qdio_establish:
2087 retval = ZFCP_ERP_FAILED;
2095 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2099 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2100 if (retval == ZFCP_ERP_FAILED)
2101 return ZFCP_ERP_FAILED;
2103 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2104 if (retval == ZFCP_ERP_FAILED)
2105 return ZFCP_ERP_FAILED;
2107 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2111 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2113 int retval = ZFCP_ERP_SUCCEEDED;
2115 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2116 struct zfcp_adapter *adapter = erp_action->adapter;
2118 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2120 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2121 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2123 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2124 write_lock_irq(&adapter->erp_lock);
2125 zfcp_erp_action_to_running(erp_action);
2126 write_unlock_irq(&adapter->erp_lock);
2127 if (zfcp_fsf_exchange_config_data(erp_action)) {
2128 retval = ZFCP_ERP_FAILED;
2129 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2130 ZFCP_LOG_INFO("error: initiation of exchange of "
2131 "configuration data failed for "
2133 zfcp_get_busid_by_adapter(adapter));
2136 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2137 ZFCP_LOG_DEBUG("Xchange underway\n");
2141 * Both the normal completion handler as well as the timeout
2142 * handler will do an 'up' when the 'exchange config data'
2143 * request completes or times out. Thus, the signal to go on
2144 * won't be lost utilizing this semaphore.
2145 * Furthermore, this 'adapter_reopen' action is
2146 * guaranteed to be the only action being there (highest action
2147 * which prevents other actions from being created).
2148 * Resulting from that, the wake signal recognized here
2149 * _must_ be the one belonging to the 'exchange config
2152 down(&adapter->erp_ready_sem);
2153 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2154 ZFCP_LOG_INFO("error: exchange of configuration data "
2155 "for adapter %s timed out\n",
2156 zfcp_get_busid_by_adapter(adapter));
2160 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2164 ZFCP_LOG_DEBUG("host connection still initialising... "
2165 "waiting and retrying...\n");
2166 /* sleep a little bit before retry */
2171 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2174 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2175 &adapter->status)) {
2176 ZFCP_LOG_INFO("error: exchange of configuration data for "
2177 "adapter %s failed\n",
2178 zfcp_get_busid_by_adapter(adapter));
2179 retval = ZFCP_ERP_FAILED;
2186 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2189 struct zfcp_adapter *adapter;
2191 adapter = erp_action->adapter;
2192 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2194 write_lock_irq(&adapter->erp_lock);
2195 zfcp_erp_action_to_running(erp_action);
2196 write_unlock_irq(&adapter->erp_lock);
2198 ret = zfcp_fsf_exchange_port_data(erp_action);
2199 if (ret == -EOPNOTSUPP) {
2200 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2201 return ZFCP_ERP_SUCCEEDED;
2203 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2204 return ZFCP_ERP_FAILED;
2206 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2208 ret = ZFCP_ERP_SUCCEEDED;
2209 down(&adapter->erp_ready_sem);
2210 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2211 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2212 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2213 ret = ZFCP_ERP_FAILED;
2216 /* don't treat as error for the sake of compatibility */
2217 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2218 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2219 "%s\n", zfcp_get_busid_by_adapter(adapter));
2225 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2228 int retval = ZFCP_ERP_SUCCEEDED;
2230 struct zfcp_adapter *adapter = erp_action->adapter;
2233 adapter->status_read_failed = 0;
2234 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2235 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2237 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2238 "notification failed on adapter %s\n",
2239 zfcp_get_busid_by_adapter(adapter));
2240 retval = ZFCP_ERP_FAILED;
2252 * purpose: this routine executes the 'Reopen Physical Port' action
2254 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2255 * ZFCP_ERP_SUCCEEDED - action finished successfully
2256 * ZFCP_ERP_FAILED - action finished unsuccessfully
2259 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2261 int retval = ZFCP_ERP_FAILED;
2262 struct zfcp_port *port = erp_action->port;
2263 struct zfcp_adapter *adapter = erp_action->adapter;
2265 switch (erp_action->step) {
2269 * the ULP spec. begs for waiting for oustanding commands
2271 case ZFCP_ERP_STEP_UNINITIALIZED:
2272 zfcp_erp_port_strategy_clearstati(port);
2274 * it would be sufficient to test only the normal open flag
2275 * since the phys. open flag cannot be set if the normal
2276 * open flag is unset - however, this is for readabilty ...
2278 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2279 ZFCP_STATUS_COMMON_OPEN),
2281 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2282 "close physical\n", port->wwpn);
2284 zfcp_erp_port_forced_strategy_close(erp_action);
2286 retval = ZFCP_ERP_FAILED;
2289 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2290 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2292 ZFCP_LOG_DEBUG("close physical failed for port "
2293 "0x%016Lx\n", port->wwpn);
2294 retval = ZFCP_ERP_FAILED;
2296 retval = ZFCP_ERP_SUCCEEDED;
2300 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2301 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2302 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2303 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2311 * purpose: this routine executes the 'Reopen Port' action
2313 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2314 * ZFCP_ERP_SUCCEEDED - action finished successfully
2315 * ZFCP_ERP_FAILED - action finished unsuccessfully
2318 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2320 int retval = ZFCP_ERP_FAILED;
2321 struct zfcp_port *port = erp_action->port;
2322 struct zfcp_adapter *adapter = erp_action->adapter;
2324 switch (erp_action->step) {
2328 * the ULP spec. begs for waiting for oustanding commands
2330 case ZFCP_ERP_STEP_UNINITIALIZED:
2331 zfcp_erp_port_strategy_clearstati(port);
2332 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2333 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2334 "close\n", port->wwpn);
2335 retval = zfcp_erp_port_strategy_close(erp_action);
2337 } /* else it's already closed, open it */
2340 case ZFCP_ERP_STEP_PORT_CLOSING:
2341 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2342 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2344 retval = ZFCP_ERP_FAILED;
2346 } /* else it's closed now, open it */
2349 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2350 retval = ZFCP_ERP_EXIT;
2352 retval = zfcp_erp_port_strategy_open(erp_action);
2355 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2356 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2357 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2358 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2364 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2368 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2369 &erp_action->port->status))
2370 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2372 retval = zfcp_erp_port_strategy_open_common(erp_action);
2378 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2381 struct zfcp_adapter *adapter = erp_action->adapter;
2382 struct zfcp_port *port = erp_action->port;
2384 switch (erp_action->step) {
2386 case ZFCP_ERP_STEP_UNINITIALIZED:
2387 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2388 case ZFCP_ERP_STEP_PORT_CLOSING:
2389 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2390 if (port->wwpn != adapter->peer_wwpn) {
2391 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2392 "on adapter %s.\nPeer WWPN "
2393 "0x%016Lx does not match\n",
2395 zfcp_get_busid_by_adapter(adapter),
2396 adapter->peer_wwpn);
2397 zfcp_erp_port_failed(port);
2398 retval = ZFCP_ERP_FAILED;
2401 port->d_id = adapter->peer_d_id;
2402 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2403 retval = zfcp_erp_port_strategy_open_port(erp_action);
2406 if (!(adapter->nameserver_port)) {
2407 retval = zfcp_nameserver_enqueue(adapter);
2409 ZFCP_LOG_NORMAL("error: nameserver port "
2410 "unavailable for adapter %s\n",
2411 zfcp_get_busid_by_adapter(adapter));
2412 retval = ZFCP_ERP_FAILED;
2416 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2417 &adapter->nameserver_port->status)) {
2418 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2419 "nameserver port\n");
2420 /* nameserver port may live again */
2421 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2422 &adapter->nameserver_port->status);
2423 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2426 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2427 retval = ZFCP_ERP_CONTINUES;
2429 retval = ZFCP_ERP_FAILED;
2432 /* else nameserver port is already open, fall through */
2433 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2434 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2435 &adapter->nameserver_port->status)) {
2436 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2437 retval = ZFCP_ERP_FAILED;
2439 ZFCP_LOG_DEBUG("nameserver port is open -> "
2440 "nameserver look-up for port 0x%016Lx\n",
2442 retval = zfcp_erp_port_strategy_open_common_lookup
2447 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2448 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2449 if (atomic_test_mask
2450 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2451 ZFCP_LOG_DEBUG("nameserver look-up failed "
2452 "for port 0x%016Lx "
2453 "(misconfigured WWPN?)\n",
2455 zfcp_erp_port_failed(port);
2456 retval = ZFCP_ERP_EXIT;
2458 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2459 "port 0x%016Lx\n", port->wwpn);
2460 retval = ZFCP_ERP_FAILED;
2463 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2464 "trying open\n", port->wwpn, port->d_id);
2465 retval = zfcp_erp_port_strategy_open_port(erp_action);
2469 case ZFCP_ERP_STEP_PORT_OPENING:
2470 /* D_ID might have changed during open */
2471 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2472 ZFCP_STATUS_PORT_DID_DID),
2474 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2475 retval = ZFCP_ERP_SUCCEEDED;
2477 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2479 retval = ZFCP_ERP_FAILED;
2484 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2486 retval = ZFCP_ERP_FAILED;
2493 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2496 struct zfcp_port *port = erp_action->port;
2498 switch (erp_action->step) {
2500 case ZFCP_ERP_STEP_UNINITIALIZED:
2501 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2502 case ZFCP_ERP_STEP_PORT_CLOSING:
2503 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2504 port->wwpn, port->d_id);
2505 retval = zfcp_erp_port_strategy_open_port(erp_action);
2508 case ZFCP_ERP_STEP_PORT_OPENING:
2509 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2510 ZFCP_LOG_DEBUG("WKA port is open\n");
2511 retval = ZFCP_ERP_SUCCEEDED;
2513 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2514 retval = ZFCP_ERP_FAILED;
2516 /* this is needed anyway (dont care for retval of wakeup) */
2517 ZFCP_LOG_DEBUG("continue other open port operations\n");
2518 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2522 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2524 retval = ZFCP_ERP_FAILED;
2533 * purpose: makes the erp thread continue with reopen (physical) port
2534 * actions which have been paused until the name server port
2535 * is opened (or failed)
2537 * returns: 0 (a kind of void retval, its not used)
2540 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2544 unsigned long flags;
2545 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2546 struct zfcp_erp_action *erp_action, *tmp;
2548 read_lock_irqsave(&adapter->erp_lock, flags);
2549 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2551 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2552 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2554 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2555 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2556 debug_event(adapter->erp_dbf, 3,
2557 &erp_action->port->wwpn, sizeof (wwn_t));
2558 if (atomic_test_mask(
2559 ZFCP_STATUS_COMMON_ERP_FAILED,
2560 &adapter->nameserver_port->status))
2561 zfcp_erp_port_failed(erp_action->port);
2562 zfcp_erp_action_ready(erp_action);
2565 read_unlock_irqrestore(&adapter->erp_lock, flags);
2575 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2576 * ZFCP_ERP_FAILED - action finished unsuccessfully
2579 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2582 struct zfcp_adapter *adapter = erp_action->adapter;
2583 struct zfcp_port *port = erp_action->port;
2585 retval = zfcp_fsf_close_physical_port(erp_action);
2586 if (retval == -ENOMEM) {
2587 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2588 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2589 retval = ZFCP_ERP_NOMEM;
2592 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2594 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2595 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2596 /* could not send 'open', fail */
2597 retval = ZFCP_ERP_FAILED;
2600 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2601 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2602 retval = ZFCP_ERP_CONTINUES;
2608 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2611 struct zfcp_adapter *adapter = port->adapter;
2613 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2614 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2616 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2617 ZFCP_STATUS_COMMON_CLOSING |
2618 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2619 ZFCP_STATUS_PORT_DID_DID |
2620 ZFCP_STATUS_PORT_PHYS_CLOSING |
2621 ZFCP_STATUS_PORT_INVALID_WWPN,
2631 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2632 * ZFCP_ERP_FAILED - action finished unsuccessfully
2635 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2638 struct zfcp_adapter *adapter = erp_action->adapter;
2639 struct zfcp_port *port = erp_action->port;
2641 retval = zfcp_fsf_close_port(erp_action);
2642 if (retval == -ENOMEM) {
2643 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2644 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2645 retval = ZFCP_ERP_NOMEM;
2648 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2650 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2651 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2652 /* could not send 'close', fail */
2653 retval = ZFCP_ERP_FAILED;
2656 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2657 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2658 retval = ZFCP_ERP_CONTINUES;
2668 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2669 * ZFCP_ERP_FAILED - action finished unsuccessfully
2672 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2675 struct zfcp_adapter *adapter = erp_action->adapter;
2676 struct zfcp_port *port = erp_action->port;
2678 retval = zfcp_fsf_open_port(erp_action);
2679 if (retval == -ENOMEM) {
2680 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2681 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2682 retval = ZFCP_ERP_NOMEM;
2685 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2687 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2688 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2689 /* could not send 'open', fail */
2690 retval = ZFCP_ERP_FAILED;
2693 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2694 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2695 retval = ZFCP_ERP_CONTINUES;
2705 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2706 * ZFCP_ERP_FAILED - action finished unsuccessfully
2709 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2712 struct zfcp_adapter *adapter = erp_action->adapter;
2713 struct zfcp_port *port = erp_action->port;
2715 retval = zfcp_ns_gid_pn_request(erp_action);
2716 if (retval == -ENOMEM) {
2717 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2718 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2719 retval = ZFCP_ERP_NOMEM;
2722 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2724 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2725 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2726 /* could not send nameserver request, fail */
2727 retval = ZFCP_ERP_FAILED;
2730 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2731 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2732 retval = ZFCP_ERP_CONTINUES;
2740 * purpose: this routine executes the 'Reopen Unit' action
2741 * currently no retries
2743 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2744 * ZFCP_ERP_SUCCEEDED - action finished successfully
2745 * ZFCP_ERP_FAILED - action finished unsuccessfully
2748 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2750 int retval = ZFCP_ERP_FAILED;
2751 struct zfcp_unit *unit = erp_action->unit;
2752 struct zfcp_adapter *adapter = erp_action->adapter;
2754 switch (erp_action->step) {
2758 * the ULP spec. begs for waiting for oustanding commands
2760 case ZFCP_ERP_STEP_UNINITIALIZED:
2761 zfcp_erp_unit_strategy_clearstati(unit);
2762 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2763 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2764 "trying close\n", unit->fcp_lun);
2765 retval = zfcp_erp_unit_strategy_close(erp_action);
2768 /* else it's already closed, fall through */
2769 case ZFCP_ERP_STEP_UNIT_CLOSING:
2770 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2771 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2773 retval = ZFCP_ERP_FAILED;
2775 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2776 retval = ZFCP_ERP_EXIT;
2778 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2779 "trying open\n", unit->fcp_lun);
2781 zfcp_erp_unit_strategy_open(erp_action);
2786 case ZFCP_ERP_STEP_UNIT_OPENING:
2787 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2788 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2790 retval = ZFCP_ERP_SUCCEEDED;
2792 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2794 retval = ZFCP_ERP_FAILED;
2799 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2800 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2801 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2802 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2807 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2810 struct zfcp_adapter *adapter = unit->port->adapter;
2812 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2813 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2815 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2816 ZFCP_STATUS_COMMON_CLOSING |
2817 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2818 ZFCP_STATUS_UNIT_SHARED |
2819 ZFCP_STATUS_UNIT_READONLY,
2830 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2831 * ZFCP_ERP_FAILED - action finished unsuccessfully
2834 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2837 struct zfcp_adapter *adapter = erp_action->adapter;
2838 struct zfcp_unit *unit = erp_action->unit;
2840 retval = zfcp_fsf_close_unit(erp_action);
2841 if (retval == -ENOMEM) {
2842 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2843 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2844 sizeof (fcp_lun_t));
2845 retval = ZFCP_ERP_NOMEM;
2848 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2850 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2851 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2852 sizeof (fcp_lun_t));
2853 /* could not send 'close', fail */
2854 retval = ZFCP_ERP_FAILED;
2857 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2858 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2859 retval = ZFCP_ERP_CONTINUES;
2870 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2871 * ZFCP_ERP_FAILED - action finished unsuccessfully
2874 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2877 struct zfcp_adapter *adapter = erp_action->adapter;
2878 struct zfcp_unit *unit = erp_action->unit;
2880 retval = zfcp_fsf_open_unit(erp_action);
2881 if (retval == -ENOMEM) {
2882 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2883 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2884 sizeof (fcp_lun_t));
2885 retval = ZFCP_ERP_NOMEM;
2888 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2890 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2891 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2892 sizeof (fcp_lun_t));
2893 /* could not send 'open', fail */
2894 retval = ZFCP_ERP_FAILED;
2897 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2898 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2899 retval = ZFCP_ERP_CONTINUES;
2904 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2906 BUG_ON(!fsf_req->erp_action);
2907 fsf_req->timer.function = zfcp_erp_timeout_handler;
2908 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2909 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2910 add_timer(&fsf_req->timer);
2916 * purpose: enqueue the specified error recovery action, if needed
2921 zfcp_erp_action_enqueue(int action,
2922 struct zfcp_adapter *adapter,
2923 struct zfcp_port *port, struct zfcp_unit *unit)
2926 struct zfcp_erp_action *erp_action = NULL;
2927 int stronger_action = 0;
2931 * We need some rules here which check whether we really need
2932 * this action or whether we should just drop it.
2933 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2934 * 'Reopen Unit' request for an associated unit since we can't
2935 * satisfy this request now. A 'Reopen Port' action will trigger
2936 * 'Reopen Unit' actions when it completes.
2937 * Thus, there are only actions in the queue which can immediately be
2938 * executed. This makes the processing of the action queue more
2942 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2946 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2947 /* check whether we really need this */
2949 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2950 if (atomic_test_mask
2951 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2952 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2953 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2955 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2956 sizeof (fcp_lun_t));
2959 if (!atomic_test_mask
2960 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2962 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2965 if (!atomic_test_mask
2966 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2967 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2970 /* fall through !!! */
2972 case ZFCP_ERP_ACTION_REOPEN_PORT:
2973 if (atomic_test_mask
2974 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2975 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2976 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2980 /* fall through !!! */
2982 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2983 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2985 if (port->erp_action.action !=
2986 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2987 ZFCP_LOG_INFO("dropped erp action %i (port "
2988 "0x%016Lx, action in use: %i)\n",
2990 port->erp_action.action);
2991 debug_text_event(adapter->erp_dbf, 4,
2994 debug_text_event(adapter->erp_dbf, 4,
2996 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3000 if (!atomic_test_mask
3001 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3003 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3006 if (!atomic_test_mask
3007 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3008 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3011 /* fall through !!! */
3013 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3014 if (atomic_test_mask
3015 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3016 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3022 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3023 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3024 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3025 "on adapter %s (action=%d)\n",
3026 zfcp_get_busid_by_adapter(adapter), action);
3030 /* check whether we need something stronger first */
3031 if (stronger_action) {
3032 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3033 debug_event(adapter->erp_dbf, 4, &stronger_action,
3035 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3036 "erp action %d on adapter %s\n",
3037 stronger_action, action,
3038 zfcp_get_busid_by_adapter(adapter));
3039 action = stronger_action;
3042 /* mark adapter to have some error recovery pending */
3043 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3045 /* setup error recovery action */
3048 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3049 zfcp_unit_get(unit);
3050 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3051 erp_action = &unit->erp_action;
3052 if (!atomic_test_mask
3053 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3054 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3057 case ZFCP_ERP_ACTION_REOPEN_PORT:
3058 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3059 zfcp_port_get(port);
3060 zfcp_erp_action_dismiss_port(port);
3061 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3062 erp_action = &port->erp_action;
3063 if (!atomic_test_mask
3064 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3065 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3068 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3069 zfcp_adapter_get(adapter);
3070 zfcp_erp_action_dismiss_adapter(adapter);
3071 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3072 erp_action = &adapter->erp_action;
3073 if (!atomic_test_mask
3074 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3075 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3079 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3081 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3082 erp_action->adapter = adapter;
3083 erp_action->port = port;
3084 erp_action->unit = unit;
3085 erp_action->action = action;
3086 erp_action->status = status;
3088 ++adapter->erp_total_count;
3090 /* finally put it into 'ready' queue and kick erp thread */
3091 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
3092 up(&adapter->erp_ready_sem);
3099 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3102 struct zfcp_adapter *adapter = erp_action->adapter;
3104 --adapter->erp_total_count;
3105 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3106 --adapter->erp_low_mem_count;
3107 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3110 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3111 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3112 list_del(&erp_action->list);
3113 switch (erp_action->action) {
3114 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3115 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3116 &erp_action->unit->status);
3118 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3119 case ZFCP_ERP_ACTION_REOPEN_PORT:
3120 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3121 &erp_action->port->status);
3123 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3124 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3125 &erp_action->adapter->status);
3135 * zfcp_erp_action_cleanup
3137 * Register unit with scsi stack if appropriate and fix reference counts.
3138 * Note: Temporary units are not registered with scsi stack.
3141 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3142 struct zfcp_port *port, struct zfcp_unit *unit,
3146 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3147 if ((result == ZFCP_ERP_SUCCEEDED)
3148 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3152 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3154 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3155 &unit->status) == 0)
3156 zfcp_erp_schedule_work(unit);
3158 zfcp_unit_put(unit);
3160 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3161 case ZFCP_ERP_ACTION_REOPEN_PORT:
3162 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3164 zfcp_port_put(port);
3168 if ((result == ZFCP_ERP_SUCCEEDED)
3170 struct fc_rport_identifiers ids;
3171 ids.node_name = port->wwnn;
3172 ids.port_name = port->wwpn;
3173 ids.port_id = port->d_id;
3174 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3176 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3178 ZFCP_LOG_NORMAL("failed registration of rport"
3179 "(adapter %s, wwpn=0x%016Lx)\n",
3180 zfcp_get_busid_by_port(port),
3183 scsi_target_unblock(&port->rport->dev);
3184 port->rport->maxframe_size = port->maxframe_size;
3185 port->rport->supported_classes =
3186 port->supported_classes;
3189 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3190 fc_remote_port_delete(port->rport);
3193 zfcp_port_put(port);
3195 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3196 if (result != ZFCP_ERP_SUCCEEDED) {
3197 list_for_each_entry(port, &adapter->port_list_head, list)
3199 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3201 fc_remote_port_delete(port->rport);
3205 zfcp_adapter_put(adapter);
3213 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3215 struct zfcp_port *port;
3217 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3218 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3219 zfcp_erp_action_dismiss(&adapter->erp_action);
3221 list_for_each_entry(port, &adapter->port_list_head, list)
3222 zfcp_erp_action_dismiss_port(port);
3225 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3227 struct zfcp_unit *unit;
3228 struct zfcp_adapter *adapter = port->adapter;
3230 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3231 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3232 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3233 zfcp_erp_action_dismiss(&port->erp_action);
3235 list_for_each_entry(unit, &port->unit_list_head, list)
3236 zfcp_erp_action_dismiss_unit(unit);
3239 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3241 struct zfcp_adapter *adapter = unit->port->adapter;
3243 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3244 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3245 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3246 zfcp_erp_action_dismiss(&unit->erp_action);
3249 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3251 struct zfcp_adapter *adapter = erp_action->adapter;
3253 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3254 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3255 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3258 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3260 struct zfcp_adapter *adapter = erp_action->adapter;
3262 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3263 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3264 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3268 zfcp_erp_port_boxed(struct zfcp_port *port)
3270 struct zfcp_adapter *adapter = port->adapter;
3271 unsigned long flags;
3273 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3274 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3275 read_lock_irqsave(&zfcp_data.config_lock, flags);
3276 zfcp_erp_modify_port_status(port,
3277 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3279 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3280 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3284 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3286 struct zfcp_adapter *adapter = unit->port->adapter;
3288 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3289 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3290 zfcp_erp_modify_unit_status(unit,
3291 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3293 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3297 zfcp_erp_port_access_denied(struct zfcp_port *port)
3299 struct zfcp_adapter *adapter = port->adapter;
3300 unsigned long flags;
3302 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3303 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3304 read_lock_irqsave(&zfcp_data.config_lock, flags);
3305 zfcp_erp_modify_port_status(port,
3306 ZFCP_STATUS_COMMON_ERP_FAILED |
3307 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3309 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3313 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3315 struct zfcp_adapter *adapter = unit->port->adapter;
3317 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3318 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3319 zfcp_erp_modify_unit_status(unit,
3320 ZFCP_STATUS_COMMON_ERP_FAILED |
3321 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3326 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3328 struct zfcp_port *port;
3329 unsigned long flags;
3331 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3334 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3335 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3337 read_lock_irqsave(&zfcp_data.config_lock, flags);
3338 if (adapter->nameserver_port)
3339 zfcp_erp_port_access_changed(adapter->nameserver_port);
3340 list_for_each_entry(port, &adapter->port_list_head, list)
3341 if (port != adapter->nameserver_port)
3342 zfcp_erp_port_access_changed(port);
3343 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3347 zfcp_erp_port_access_changed(struct zfcp_port *port)
3349 struct zfcp_adapter *adapter = port->adapter;
3350 struct zfcp_unit *unit;
3352 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3353 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3355 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3357 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3359 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3360 list_for_each_entry(unit, &port->unit_list_head, list)
3361 zfcp_erp_unit_access_changed(unit);
3365 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3366 "(due to ACT update)\n",
3367 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3368 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3369 ZFCP_LOG_NORMAL("failed reopen of port"
3370 "(adapter %s, wwpn=0x%016Lx)\n",
3371 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3375 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3377 struct zfcp_adapter *adapter = unit->port->adapter;
3379 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3380 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3382 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3384 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3388 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3389 " on adapter %s (due to ACT update)\n",
3390 unit->fcp_lun, unit->port->wwpn,
3391 zfcp_get_busid_by_adapter(adapter));
3392 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3393 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3394 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3395 zfcp_get_busid_by_adapter(adapter),
3396 unit->port->wwpn, unit->fcp_lun);
3399 #undef ZFCP_LOG_AREA