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 inline 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 inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
110 static inline 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, 0);
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 = 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 = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
312 if (send_els->req == NULL)
315 send_els->resp = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->resp == NULL)
319 address = (void *) get_zeroed_page(GFP_ATOMIC);
323 zfcp_address_to_sg(address, send_els->req);
324 address += PAGE_SIZE >> 1;
325 zfcp_address_to_sg(address, send_els->resp);
326 send_els->req_count = send_els->resp_count = 1;
328 send_els->adapter = adapter;
329 send_els->port = port;
330 send_els->d_id = port->d_id;
331 send_els->handler = zfcp_erp_adisc_handler;
332 send_els->handler_data = (unsigned long) send_els;
334 adisc = zfcp_sg_to_address(send_els->req);
335 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
337 send_els->req->length = sizeof(struct zfcp_ls_adisc);
338 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
340 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
341 without FC-AL-2 capability, so we don't set it */
342 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
343 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
344 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
345 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
346 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
347 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
348 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
349 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
352 retval = zfcp_fsf_send_els(send_els);
354 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
355 "0x%08x on adapter %s\n", send_els->d_id,
356 zfcp_get_busid_by_adapter(adapter));
366 __free_pages(send_els->req->page, 0);
367 if (send_els != NULL) {
368 kfree(send_els->req);
369 kfree(send_els->resp);
378 * zfcp_erp_adisc_handler - handler for ADISC ELS command
379 * @data: pointer to struct zfcp_send_els
381 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
384 zfcp_erp_adisc_handler(unsigned long data)
386 struct zfcp_send_els *send_els;
387 struct zfcp_port *port;
388 struct zfcp_adapter *adapter;
390 struct zfcp_ls_adisc_acc *adisc;
392 send_els = (struct zfcp_send_els *) data;
393 adapter = send_els->adapter;
394 port = send_els->port;
395 d_id = send_els->d_id;
397 /* request rejected or timed out */
398 if (send_els->status != 0) {
399 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
400 "force physical port reopen "
401 "(adapter %s, port d_id=0x%08x)\n",
402 zfcp_get_busid_by_adapter(adapter), d_id);
403 debug_text_event(adapter->erp_dbf, 3, "forcreop");
404 if (zfcp_erp_port_forced_reopen(port, 0))
405 ZFCP_LOG_NORMAL("failed reopen of port "
406 "(adapter %s, wwpn=0x%016Lx)\n",
407 zfcp_get_busid_by_port(port),
412 adisc = zfcp_sg_to_address(send_els->resp);
414 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
415 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
416 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
417 d_id, fc_host_port_id(adapter->scsi_host),
418 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
419 adisc->hard_nport_id, adisc->nport_id);
421 /* set wwnn for port */
423 port->wwnn = adisc->wwnn;
425 if (port->wwpn != adisc->wwpn) {
426 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
427 "port (adapter %s, wwpn=0x%016Lx, "
428 "adisc_resp_wwpn=0x%016Lx)\n",
429 zfcp_get_busid_by_port(port),
430 port->wwpn, (wwn_t) adisc->wwpn);
431 if (zfcp_erp_port_reopen(port, 0))
432 ZFCP_LOG_NORMAL("failed reopen of port "
433 "(adapter %s, wwpn=0x%016Lx)\n",
434 zfcp_get_busid_by_port(port),
440 __free_pages(send_els->req->page, 0);
441 kfree(send_els->req);
442 kfree(send_els->resp);
448 * zfcp_test_link - lightweight link test procedure
449 * @port: port to be tested
451 * Test status of a link to a remote port using the ELS command ADISC.
454 zfcp_test_link(struct zfcp_port *port)
459 retval = zfcp_erp_adisc(port);
462 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
463 "on adapter %s\n ", port->wwpn,
464 zfcp_get_busid_by_port(port));
465 retval = zfcp_erp_port_forced_reopen(port, 0);
467 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
468 "on adapter %s failed\n", port->wwpn,
469 zfcp_get_busid_by_port(port));
481 * purpose: called if a port failed to be opened normally
482 * initiates Forced Reopen recovery which is done
485 * returns: 0 - initiated action successfully
486 * <0 - failed to initiate action
489 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
492 struct zfcp_adapter *adapter = port->adapter;
494 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
495 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
497 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
498 port->wwpn, zfcp_get_busid_by_port(port));
500 zfcp_erp_port_block(port, clear_mask);
502 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
503 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
504 "on adapter %s\n", port->wwpn,
505 zfcp_get_busid_by_port(port));
506 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
507 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
512 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
513 port->adapter, port, NULL);
522 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
523 * used to ensure the correct locking
525 * returns: 0 - initiated action successfully
526 * <0 - failed to initiate action
529 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
533 struct zfcp_adapter *adapter;
535 adapter = port->adapter;
536 read_lock_irqsave(&zfcp_data.config_lock, flags);
537 write_lock(&adapter->erp_lock);
538 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
539 write_unlock(&adapter->erp_lock);
540 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
548 * purpose: called if a port is to be opened
549 * initiates Reopen recovery which is done
552 * returns: 0 - initiated action successfully
553 * <0 - failed to initiate action
556 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
559 struct zfcp_adapter *adapter = port->adapter;
561 debug_text_event(adapter->erp_dbf, 5, "p_ro");
562 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
564 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
565 port->wwpn, zfcp_get_busid_by_port(port));
567 zfcp_erp_port_block(port, clear_mask);
569 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
570 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
571 "on adapter %s\n", port->wwpn,
572 zfcp_get_busid_by_port(port));
573 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
574 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
575 /* ensure propagation of failed status to new devices */
576 zfcp_erp_port_failed(port);
581 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
582 port->adapter, port, NULL);
589 * zfcp_erp_port_reopen - initiate reopen of a remote port
590 * @port: port to be reopened
591 * @clear_mask: specifies flags in port status to be cleared
592 * Return: 0 on success, < 0 on error
594 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
595 * correct locking. An error recovery task is initiated to do the reopen.
596 * To wait for the completion of the reopen zfcp_erp_wait should be used.
599 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
603 struct zfcp_adapter *adapter = port->adapter;
605 read_lock_irqsave(&zfcp_data.config_lock, flags);
606 write_lock(&adapter->erp_lock);
607 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
608 write_unlock(&adapter->erp_lock);
609 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
617 * purpose: called if a unit is to be opened
618 * initiates Reopen recovery which is done
621 * returns: 0 - initiated action successfully
622 * <0 - failed to initiate action
625 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
628 struct zfcp_adapter *adapter = unit->port->adapter;
630 debug_text_event(adapter->erp_dbf, 5, "u_ro");
631 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
632 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
633 "on adapter %s\n", unit->fcp_lun,
634 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
636 zfcp_erp_unit_block(unit, clear_mask);
638 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
639 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
640 "on port 0x%016Lx on adapter %s\n",
641 unit->fcp_lun, unit->port->wwpn,
642 zfcp_get_busid_by_unit(unit));
643 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
644 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
650 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
651 unit->port->adapter, unit->port, unit);
657 * zfcp_erp_unit_reopen - initiate reopen of a unit
658 * @unit: unit to be reopened
659 * @clear_mask: specifies flags in unit status to be cleared
660 * Return: 0 on success, < 0 on error
662 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
663 * locking. An error recovery task is initiated to do the reopen.
664 * To wait for the completion of the reopen zfcp_erp_wait should be used.
667 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
671 struct zfcp_adapter *adapter;
672 struct zfcp_port *port;
675 adapter = port->adapter;
677 read_lock_irqsave(&zfcp_data.config_lock, flags);
678 write_lock(&adapter->erp_lock);
679 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
680 write_unlock(&adapter->erp_lock);
681 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
687 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
689 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
691 debug_text_event(adapter->erp_dbf, 6, "a_bl");
692 zfcp_erp_modify_adapter_status(adapter,
693 ZFCP_STATUS_COMMON_UNBLOCKED |
694 clear_mask, ZFCP_CLEAR);
698 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
700 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
702 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
703 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
709 * purpose: disable I/O,
710 * return any open requests and clean them up,
711 * aim: no pending and incoming I/O
716 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
718 struct zfcp_adapter *adapter = port->adapter;
720 debug_text_event(adapter->erp_dbf, 6, "p_bl");
721 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
722 zfcp_erp_modify_port_status(port,
723 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
730 * purpose: enable I/O
735 zfcp_erp_port_unblock(struct zfcp_port *port)
737 struct zfcp_adapter *adapter = port->adapter;
739 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
740 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
741 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
747 * purpose: disable I/O,
748 * return any open requests and clean them up,
749 * aim: no pending and incoming I/O
754 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
756 struct zfcp_adapter *adapter = unit->port->adapter;
758 debug_text_event(adapter->erp_dbf, 6, "u_bl");
759 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
760 zfcp_erp_modify_unit_status(unit,
761 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
768 * purpose: enable I/O
773 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
775 struct zfcp_adapter *adapter = unit->port->adapter;
777 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
778 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
779 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
783 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
785 struct zfcp_adapter *adapter = erp_action->adapter;
787 debug_text_event(adapter->erp_dbf, 4, "a_ar");
788 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
790 zfcp_erp_action_to_ready(erp_action);
791 up(&adapter->erp_ready_sem);
799 * returns: <0 erp_action not found in any list
800 * ZFCP_ERP_ACTION_READY erp_action is in ready list
801 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
803 * locks: erp_lock must be held
806 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
808 int retval = -EINVAL;
809 struct list_head *entry;
810 struct zfcp_erp_action *entry_erp_action;
811 struct zfcp_adapter *adapter = erp_action->adapter;
813 /* search in running list */
814 list_for_each(entry, &adapter->erp_running_head) {
816 list_entry(entry, struct zfcp_erp_action, list);
817 if (entry_erp_action == erp_action) {
818 retval = ZFCP_ERP_ACTION_RUNNING;
822 /* search in ready list */
823 list_for_each(entry, &adapter->erp_ready_head) {
825 list_entry(entry, struct zfcp_erp_action, list);
826 if (entry_erp_action == erp_action) {
827 retval = ZFCP_ERP_ACTION_READY;
837 * purpose: checks current status of action (timed out, dismissed, ...)
838 * and does appropriate preparations (dismiss fsf request, ...)
840 * locks: called under erp_lock (disabled interrupts)
845 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
847 struct zfcp_adapter *adapter = erp_action->adapter;
849 if (erp_action->fsf_req) {
850 /* take lock to ensure that request is not deleted meanwhile */
851 spin_lock(&adapter->req_list_lock);
852 if (zfcp_reqlist_ismember(adapter,
853 erp_action->fsf_req->req_id)) {
854 /* fsf_req still exists */
855 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
856 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
857 sizeof (unsigned long));
858 /* dismiss fsf_req of timed out/dismissed erp_action */
859 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
860 ZFCP_STATUS_ERP_TIMEDOUT)) {
861 debug_text_event(adapter->erp_dbf, 3,
863 erp_action->fsf_req->status |=
864 ZFCP_STATUS_FSFREQ_DISMISSED;
866 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
867 ZFCP_LOG_NORMAL("error: erp step timed out "
868 "(action=%d, fsf_req=%p)\n ",
870 erp_action->fsf_req);
873 * If fsf_req is neither dismissed nor completed
874 * then keep it running asynchronously and don't mess
875 * with the association of erp_action and fsf_req.
877 if (erp_action->fsf_req->status &
878 (ZFCP_STATUS_FSFREQ_COMPLETED |
879 ZFCP_STATUS_FSFREQ_DISMISSED)) {
880 /* forget about association between fsf_req
882 erp_action->fsf_req = NULL;
885 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
887 * even if this fsf_req has gone, forget about
888 * association between erp_action and fsf_req
890 erp_action->fsf_req = NULL;
892 spin_unlock(&adapter->req_list_lock);
894 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
898 * zfcp_erp_async_handler_nolock - complete erp_action
900 * Used for normal completion, time-out, dismissal and failure after
901 * low memory condition.
903 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
904 unsigned long set_mask)
906 struct zfcp_adapter *adapter = erp_action->adapter;
908 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
909 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
910 debug_event(adapter->erp_dbf, 2, &erp_action->action,
912 erp_action->status |= set_mask;
913 zfcp_erp_action_ready(erp_action);
915 /* action is ready or gone - nothing to do */
916 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
917 debug_event(adapter->erp_dbf, 3, &erp_action->action,
923 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
925 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
926 unsigned long set_mask)
928 struct zfcp_adapter *adapter = erp_action->adapter;
931 write_lock_irqsave(&adapter->erp_lock, flags);
932 zfcp_erp_async_handler_nolock(erp_action, set_mask);
933 write_unlock_irqrestore(&adapter->erp_lock, flags);
937 * purpose: is called for erp_action which was slept waiting for
938 * memory becoming avaliable,
939 * will trigger that this action will be continued
942 zfcp_erp_memwait_handler(unsigned long data)
944 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
945 struct zfcp_adapter *adapter = erp_action->adapter;
947 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
948 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
950 zfcp_erp_async_handler(erp_action, 0);
954 * purpose: is called if an asynchronous erp step timed out,
955 * action gets an appropriate flag and will be processed
958 void zfcp_erp_timeout_handler(unsigned long data)
960 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
961 struct zfcp_adapter *adapter = erp_action->adapter;
963 debug_text_event(adapter->erp_dbf, 2, "a_th");
964 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
966 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
970 * zfcp_erp_action_dismiss - dismiss an erp_action
972 * adapter->erp_lock must be held
974 * Dismissal of an erp_action is usually required if an erp_action of
975 * higher priority is generated.
977 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
979 struct zfcp_adapter *adapter = erp_action->adapter;
981 debug_text_event(adapter->erp_dbf, 2, "a_adis");
982 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
984 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
988 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
992 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
994 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
996 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
998 zfcp_get_busid_by_adapter(adapter));
999 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1001 wait_event(adapter->erp_thread_wqh,
1002 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1004 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1007 return (retval < 0);
1017 * context: process (i.e. proc-fs or rmmod/insmod)
1019 * note: The caller of this routine ensures that the specified
1020 * adapter has been shut down and that this operation
1021 * has been completed. Thus, there are no pending erp_actions
1022 * which would need to be handled here.
1025 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1029 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1030 up(&adapter->erp_ready_sem);
1032 wait_event(adapter->erp_thread_wqh,
1033 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1036 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1039 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1045 * purpose: is run as a kernel thread,
1046 * goes through list of error recovery actions of associated adapter
1047 * and delegates single action to execution
1052 zfcp_erp_thread(void *data)
1054 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1055 struct list_head *next;
1056 struct zfcp_erp_action *erp_action;
1057 unsigned long flags;
1059 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1060 /* Block all signals */
1061 siginitsetinv(¤t->blocked, 0);
1062 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1063 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1064 wake_up(&adapter->erp_thread_wqh);
1066 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1067 &adapter->status)) {
1069 write_lock_irqsave(&adapter->erp_lock, flags);
1070 next = adapter->erp_ready_head.prev;
1071 write_unlock_irqrestore(&adapter->erp_lock, flags);
1073 if (next != &adapter->erp_ready_head) {
1075 list_entry(next, struct zfcp_erp_action, list);
1077 * process action (incl. [re]moving it
1078 * from 'ready' queue)
1080 zfcp_erp_strategy(erp_action);
1084 * sleep as long as there is nothing to do, i.e.
1085 * no action in 'ready' queue to be processed and
1086 * thread is not to be killed
1088 down_interruptible(&adapter->erp_ready_sem);
1089 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1092 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1093 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1094 wake_up(&adapter->erp_thread_wqh);
1102 * purpose: drives single error recovery action and schedules higher and
1103 * subordinate actions, if necessary
1105 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1106 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1107 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1108 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1109 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1112 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1115 struct zfcp_adapter *adapter = erp_action->adapter;
1116 struct zfcp_port *port = erp_action->port;
1117 struct zfcp_unit *unit = erp_action->unit;
1118 int action = erp_action->action;
1119 u32 status = erp_action->status;
1120 unsigned long flags;
1122 /* serialise dismissing, timing out, moving, enqueueing */
1123 read_lock_irqsave(&zfcp_data.config_lock, flags);
1124 write_lock(&adapter->erp_lock);
1126 /* dequeue dismissed action and leave, if required */
1127 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1128 if (retval == ZFCP_ERP_DISMISSED) {
1129 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1134 * move action to 'running' queue before processing it
1135 * (to avoid a race condition regarding moving the
1136 * action to the 'running' queue and back)
1138 zfcp_erp_action_to_running(erp_action);
1141 * try to process action as far as possible,
1142 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1143 * afterwards the lock is required again for the following reasons:
1144 * - dequeueing of finished action and enqueueing of
1145 * follow-up actions must be atomic so that any other
1146 * reopen-routine does not believe there is nothing to do
1147 * and that it is safe to enqueue something else,
1148 * - we want to force any control thread which is dismissing
1149 * actions to finish this before we decide about
1150 * necessary steps to be taken here further
1152 write_unlock(&adapter->erp_lock);
1153 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1154 retval = zfcp_erp_strategy_do_action(erp_action);
1155 read_lock_irqsave(&zfcp_data.config_lock, flags);
1156 write_lock(&adapter->erp_lock);
1159 * check for dismissed status again to avoid follow-up actions,
1160 * failing of targets and so on for dismissed actions
1162 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1165 case ZFCP_ERP_DISMISSED:
1166 /* leave since this action has ridden to its ancestors */
1167 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1169 case ZFCP_ERP_NOMEM:
1170 /* no memory to continue immediately, let it sleep */
1171 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1172 ++adapter->erp_low_mem_count;
1173 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1175 /* This condition is true if there is no memory available
1176 for any erp_action on this adapter. This implies that there
1177 are no elements in the memory pool(s) left for erp_actions.
1178 This might happen if an erp_action that used a memory pool
1179 element was timed out.
1181 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1182 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1183 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1184 "restarting I/O on adapter %s "
1185 "to free mempool\n",
1186 zfcp_get_busid_by_adapter(adapter));
1187 zfcp_erp_adapter_reopen_internal(adapter, 0);
1189 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1190 retval = zfcp_erp_strategy_memwait(erp_action);
1193 case ZFCP_ERP_CONTINUES:
1194 /* leave since this action runs asynchronously */
1195 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1196 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1197 --adapter->erp_low_mem_count;
1198 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1202 /* ok, finished action (whatever its result is) */
1204 /* check for unrecoverable targets */
1205 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1207 /* action must be dequeued (here to allow for further ones) */
1208 zfcp_erp_action_dequeue(erp_action);
1211 * put this target through the erp mill again if someone has
1212 * requested to change the status of a target being online
1213 * to offline or the other way around
1214 * (old retval is preserved if nothing has to be done here)
1216 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1217 port, unit, retval);
1220 * leave if target is in permanent error state or if
1221 * action is repeated in order to process state change
1223 if (retval == ZFCP_ERP_EXIT) {
1224 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1228 /* trigger follow up actions */
1229 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1232 write_unlock(&adapter->erp_lock);
1233 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1235 if (retval != ZFCP_ERP_CONTINUES)
1236 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1239 * a few tasks remain when the erp queues are empty
1240 * (don't do that if the last action evaluated was dismissed
1241 * since this clearly indicates that there is more to come) :
1242 * - close the name server port if it is open yet
1243 * (enqueues another [probably] final action)
1244 * - otherwise, wake up whoever wants to be woken when we are
1247 if (retval != ZFCP_ERP_DISMISSED)
1248 zfcp_erp_strategy_check_queues(adapter);
1250 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1260 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1261 * retval - otherwise
1264 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1266 struct zfcp_adapter *adapter = erp_action->adapter;
1268 zfcp_erp_strategy_check_fsfreq(erp_action);
1270 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1271 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1272 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1273 zfcp_erp_action_dequeue(erp_action);
1274 retval = ZFCP_ERP_DISMISSED;
1276 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1282 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1284 int retval = ZFCP_ERP_FAILED;
1285 struct zfcp_adapter *adapter = erp_action->adapter;
1288 * try to execute/continue action as far as possible,
1289 * note: no lock in subsequent strategy routines
1290 * (this allows these routine to call schedule, e.g.
1291 * kmalloc with such flags or qdio_initialize & friends)
1292 * Note: in case of timeout, the seperate strategies will fail
1293 * anyhow. No need for a special action. Even worse, a nameserver
1294 * failure would not wake up waiting ports without the call.
1296 switch (erp_action->action) {
1298 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1299 retval = zfcp_erp_adapter_strategy(erp_action);
1302 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1303 retval = zfcp_erp_port_forced_strategy(erp_action);
1306 case ZFCP_ERP_ACTION_REOPEN_PORT:
1307 retval = zfcp_erp_port_strategy(erp_action);
1310 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1311 retval = zfcp_erp_unit_strategy(erp_action);
1315 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1316 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1318 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1319 "adapter %s (action=%d)\n",
1320 zfcp_get_busid_by_adapter(erp_action->adapter),
1321 erp_action->action);
1330 * purpose: triggers retry of this action after a certain amount of time
1331 * by means of timer provided by erp_action
1333 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1336 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1338 int retval = ZFCP_ERP_CONTINUES;
1339 struct zfcp_adapter *adapter = erp_action->adapter;
1341 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1342 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1343 init_timer(&erp_action->timer);
1344 erp_action->timer.function = zfcp_erp_memwait_handler;
1345 erp_action->timer.data = (unsigned long) erp_action;
1346 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1347 add_timer(&erp_action->timer);
1353 * function: zfcp_erp_adapter_failed
1355 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1359 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1361 zfcp_erp_modify_adapter_status(adapter,
1362 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1363 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1364 zfcp_get_busid_by_adapter(adapter));
1365 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1369 * function: zfcp_erp_port_failed
1371 * purpose: sets the port and all underlying devices to ERP_FAILED
1375 zfcp_erp_port_failed(struct zfcp_port *port)
1377 zfcp_erp_modify_port_status(port,
1378 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1380 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1381 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1382 "port d_id=0x%08x)\n",
1383 zfcp_get_busid_by_port(port), port->d_id);
1385 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1386 zfcp_get_busid_by_port(port), port->wwpn);
1388 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1389 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1393 * function: zfcp_erp_unit_failed
1395 * purpose: sets the unit to ERP_FAILED
1399 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1401 zfcp_erp_modify_unit_status(unit,
1402 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1404 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1405 " on adapter %s\n", unit->fcp_lun,
1406 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1407 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1408 debug_event(unit->port->adapter->erp_dbf, 2,
1409 &unit->fcp_lun, sizeof (fcp_lun_t));
1413 * function: zfcp_erp_strategy_check_target
1415 * purpose: increments the erp action count on the device currently in
1416 * recovery if the action failed or resets the count in case of
1417 * success. If a maximum count is exceeded the device is marked
1419 * The 'blocked' state of a target which has been recovered
1420 * successfully is reset.
1422 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1423 * ZFCP_ERP_SUCCEEDED - action finished successfully
1424 * ZFCP_ERP_EXIT - action failed and will not continue
1427 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1429 struct zfcp_adapter *adapter = erp_action->adapter;
1430 struct zfcp_port *port = erp_action->port;
1431 struct zfcp_unit *unit = erp_action->unit;
1433 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1434 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1435 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1437 switch (erp_action->action) {
1439 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1440 result = zfcp_erp_strategy_check_unit(unit, result);
1443 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1444 case ZFCP_ERP_ACTION_REOPEN_PORT:
1445 result = zfcp_erp_strategy_check_port(port, result);
1448 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1449 result = zfcp_erp_strategy_check_adapter(adapter, result);
1457 zfcp_erp_strategy_statechange(int action,
1459 struct zfcp_adapter *adapter,
1460 struct zfcp_port *port,
1461 struct zfcp_unit *unit, int retval)
1463 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1464 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1468 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1469 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1471 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1472 retval = ZFCP_ERP_EXIT;
1476 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1477 case ZFCP_ERP_ACTION_REOPEN_PORT:
1478 if (zfcp_erp_strategy_statechange_detected(&port->status,
1480 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1481 retval = ZFCP_ERP_EXIT;
1485 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1486 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1488 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1489 retval = ZFCP_ERP_EXIT;
1498 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1501 /* take it online */
1502 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1503 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1504 /* take it offline */
1505 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1506 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1510 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1512 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1513 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1514 sizeof (fcp_lun_t));
1517 case ZFCP_ERP_SUCCEEDED :
1518 atomic_set(&unit->erp_counter, 0);
1519 zfcp_erp_unit_unblock(unit);
1521 case ZFCP_ERP_FAILED :
1522 atomic_inc(&unit->erp_counter);
1523 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1524 zfcp_erp_unit_failed(unit);
1526 case ZFCP_ERP_EXIT :
1531 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1532 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1533 result = ZFCP_ERP_EXIT;
1540 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1542 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1543 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1546 case ZFCP_ERP_SUCCEEDED :
1547 atomic_set(&port->erp_counter, 0);
1548 zfcp_erp_port_unblock(port);
1550 case ZFCP_ERP_FAILED :
1551 atomic_inc(&port->erp_counter);
1552 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1553 zfcp_erp_port_failed(port);
1555 case ZFCP_ERP_EXIT :
1560 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1561 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1562 result = ZFCP_ERP_EXIT;
1569 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1571 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1574 case ZFCP_ERP_SUCCEEDED :
1575 atomic_set(&adapter->erp_counter, 0);
1576 zfcp_erp_adapter_unblock(adapter);
1578 case ZFCP_ERP_FAILED :
1579 atomic_inc(&adapter->erp_counter);
1580 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1581 zfcp_erp_adapter_failed(adapter);
1583 case ZFCP_ERP_EXIT :
1588 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1589 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1590 result = ZFCP_ERP_EXIT;
1599 * purpose: remaining things in good cases,
1600 * escalation in bad cases
1605 zfcp_erp_strategy_followup_actions(int action,
1606 struct zfcp_adapter *adapter,
1607 struct zfcp_port *port,
1608 struct zfcp_unit *unit, int status)
1610 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1611 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1613 /* initiate follow-up actions depending on success of finished action */
1616 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1617 if (status == ZFCP_ERP_SUCCEEDED)
1618 zfcp_erp_port_reopen_all_internal(adapter, 0);
1620 zfcp_erp_adapter_reopen_internal(adapter, 0);
1623 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1624 if (status == ZFCP_ERP_SUCCEEDED)
1625 zfcp_erp_port_reopen_internal(port, 0);
1627 zfcp_erp_adapter_reopen_internal(adapter, 0);
1630 case ZFCP_ERP_ACTION_REOPEN_PORT:
1631 if (status == ZFCP_ERP_SUCCEEDED)
1632 zfcp_erp_unit_reopen_all_internal(port, 0);
1634 zfcp_erp_port_forced_reopen_internal(port, 0);
1637 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1638 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1640 zfcp_erp_port_reopen_internal(unit->port, 0);
1648 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1650 unsigned long flags;
1652 read_lock_irqsave(&zfcp_data.config_lock, flags);
1653 read_lock(&adapter->erp_lock);
1654 if (list_empty(&adapter->erp_ready_head) &&
1655 list_empty(&adapter->erp_running_head)) {
1656 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1657 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1659 wake_up(&adapter->erp_done_wqh);
1661 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1662 read_unlock(&adapter->erp_lock);
1663 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1669 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1670 * @adapter: adapter for which to wait for completion of its error recovery
1674 zfcp_erp_wait(struct zfcp_adapter *adapter)
1678 wait_event(adapter->erp_done_wqh,
1679 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1686 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1687 u32 mask, int set_or_clear)
1689 struct zfcp_port *port;
1690 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1692 if (set_or_clear == ZFCP_SET) {
1693 atomic_set_mask(mask, &adapter->status);
1694 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1696 atomic_clear_mask(mask, &adapter->status);
1697 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1698 atomic_set(&adapter->erp_counter, 0);
1699 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1701 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1703 /* Deal with all underlying devices, only pass common_mask */
1705 list_for_each_entry(port, &adapter->port_list_head, list)
1706 zfcp_erp_modify_port_status(port, common_mask,
1711 * function: zfcp_erp_modify_port_status
1713 * purpose: sets the port and all underlying devices to ERP_FAILED
1717 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1719 struct zfcp_unit *unit;
1720 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1722 if (set_or_clear == ZFCP_SET) {
1723 atomic_set_mask(mask, &port->status);
1724 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1726 atomic_clear_mask(mask, &port->status);
1727 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1728 atomic_set(&port->erp_counter, 0);
1729 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1731 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1732 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1734 /* Modify status of all underlying devices, only pass common mask */
1736 list_for_each_entry(unit, &port->unit_list_head, list)
1737 zfcp_erp_modify_unit_status(unit, common_mask,
1742 * function: zfcp_erp_modify_unit_status
1744 * purpose: sets the unit to ERP_FAILED
1748 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1750 if (set_or_clear == ZFCP_SET) {
1751 atomic_set_mask(mask, &unit->status);
1752 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1754 atomic_clear_mask(mask, &unit->status);
1755 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1756 atomic_set(&unit->erp_counter, 0);
1758 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1760 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1761 sizeof (fcp_lun_t));
1762 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1768 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1769 * used to ensure the correct locking
1771 * returns: 0 - initiated action successfully
1772 * <0 - failed to initiate action
1775 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1778 unsigned long flags;
1780 read_lock_irqsave(&zfcp_data.config_lock, flags);
1781 write_lock(&adapter->erp_lock);
1782 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1783 write_unlock(&adapter->erp_lock);
1784 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1790 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1793 struct zfcp_port *port;
1795 list_for_each_entry(port, &adapter->port_list_head, list)
1796 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1797 zfcp_erp_port_reopen_internal(port, clear_mask);
1810 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1813 struct zfcp_unit *unit;
1815 list_for_each_entry(unit, &port->unit_list_head, list)
1816 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1824 * purpose: this routine executes the 'Reopen Adapter' action
1825 * (the entire action is processed synchronously, since
1826 * there are no actions which might be run concurrently
1829 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1830 * ZFCP_ERP_FAILED - action finished unsuccessfully
1833 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1836 struct zfcp_adapter *adapter = erp_action->adapter;
1838 retval = zfcp_erp_adapter_strategy_close(erp_action);
1839 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1840 retval = ZFCP_ERP_EXIT;
1842 retval = zfcp_erp_adapter_strategy_open(erp_action);
1844 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1845 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1846 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1848 if (retval == ZFCP_ERP_FAILED) {
1849 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1850 "to recover itself\n",
1851 zfcp_get_busid_by_adapter(adapter));
1852 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1863 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1864 * ZFCP_ERP_FAILED - action finished unsuccessfully
1867 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1871 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1872 &erp_action->adapter->status);
1873 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1874 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1875 &erp_action->adapter->status);
1885 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1886 * ZFCP_ERP_FAILED - action finished unsuccessfully
1889 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1893 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1894 &erp_action->adapter->status);
1895 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1896 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1897 &erp_action->adapter->status);
1903 * function: zfcp_register_adapter
1905 * purpose: allocate the irq associated with this devno and register
1906 * the FSF adapter with the SCSI stack
1911 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1913 int retval = ZFCP_ERP_SUCCEEDED;
1918 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1919 if (retval != ZFCP_ERP_SUCCEEDED)
1922 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1923 if (retval != ZFCP_ERP_SUCCEEDED)
1924 goto failed_openfcp;
1926 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1930 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1931 &erp_action->adapter->status);
1934 zfcp_close_fsf(erp_action->adapter);
1941 * function: zfcp_qdio_init
1943 * purpose: setup QDIO operation for specified adapter
1945 * returns: 0 - successful setup
1949 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1953 volatile struct qdio_buffer_element *sbale;
1954 struct zfcp_adapter *adapter = erp_action->adapter;
1956 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
1957 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1959 zfcp_get_busid_by_adapter(adapter));
1963 if (qdio_establish(&adapter->qdio_init_data) != 0) {
1964 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1966 zfcp_get_busid_by_adapter(adapter));
1967 goto failed_qdio_establish;
1969 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
1971 if (qdio_activate(adapter->ccw_device, 0) != 0) {
1972 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1974 zfcp_get_busid_by_adapter(adapter));
1975 goto failed_qdio_activate;
1977 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
1980 * put buffers into response queue,
1982 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
1983 sbale = &(adapter->response_queue.buffer[i]->element[0]);
1985 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
1989 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1990 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1991 zfcp_get_busid_by_adapter(adapter),
1992 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
1994 retval = do_QDIO(adapter->ccw_device,
1995 QDIO_FLAG_SYNC_INPUT,
1996 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
1999 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2001 goto failed_do_qdio;
2003 adapter->response_queue.free_index = 0;
2004 atomic_set(&adapter->response_queue.free_count, 0);
2005 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2006 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2008 /* set index of first avalable SBALS / number of available SBALS */
2009 adapter->request_queue.free_index = 0;
2010 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2011 adapter->request_queue.distance_from_int = 0;
2013 /* initialize waitqueue used to wait for free SBALs in requests queue */
2014 init_waitqueue_head(&adapter->request_wq);
2016 /* ok, we did it - skip all cleanups for different failures */
2017 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2018 retval = ZFCP_ERP_SUCCEEDED;
2024 failed_qdio_activate:
2025 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2026 while (qdio_shutdown(adapter->ccw_device,
2027 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2029 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2031 failed_qdio_establish:
2033 retval = ZFCP_ERP_FAILED;
2041 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2045 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2046 if (retval == ZFCP_ERP_FAILED)
2047 return ZFCP_ERP_FAILED;
2049 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2050 if (retval == ZFCP_ERP_FAILED)
2051 return ZFCP_ERP_FAILED;
2053 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2057 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2059 int retval = ZFCP_ERP_SUCCEEDED;
2061 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2062 struct zfcp_adapter *adapter = erp_action->adapter;
2064 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2066 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2067 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2069 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2070 write_lock_irq(&adapter->erp_lock);
2071 zfcp_erp_action_to_running(erp_action);
2072 write_unlock_irq(&adapter->erp_lock);
2073 if (zfcp_fsf_exchange_config_data(erp_action)) {
2074 retval = ZFCP_ERP_FAILED;
2075 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2076 ZFCP_LOG_INFO("error: initiation of exchange of "
2077 "configuration data failed for "
2079 zfcp_get_busid_by_adapter(adapter));
2082 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2083 ZFCP_LOG_DEBUG("Xchange underway\n");
2087 * Both the normal completion handler as well as the timeout
2088 * handler will do an 'up' when the 'exchange config data'
2089 * request completes or times out. Thus, the signal to go on
2090 * won't be lost utilizing this semaphore.
2091 * Furthermore, this 'adapter_reopen' action is
2092 * guaranteed to be the only action being there (highest action
2093 * which prevents other actions from being created).
2094 * Resulting from that, the wake signal recognized here
2095 * _must_ be the one belonging to the 'exchange config
2098 down(&adapter->erp_ready_sem);
2099 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2100 ZFCP_LOG_INFO("error: exchange of configuration data "
2101 "for adapter %s timed out\n",
2102 zfcp_get_busid_by_adapter(adapter));
2106 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2110 ZFCP_LOG_DEBUG("host connection still initialising... "
2111 "waiting and retrying...\n");
2112 /* sleep a little bit before retry */
2113 msleep(jiffies_to_msecs(sleep));
2117 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2118 &adapter->status)) {
2119 ZFCP_LOG_INFO("error: exchange of configuration data for "
2120 "adapter %s failed\n",
2121 zfcp_get_busid_by_adapter(adapter));
2122 retval = ZFCP_ERP_FAILED;
2129 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2132 struct zfcp_adapter *adapter;
2134 adapter = erp_action->adapter;
2135 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2137 write_lock_irq(&adapter->erp_lock);
2138 zfcp_erp_action_to_running(erp_action);
2139 write_unlock_irq(&adapter->erp_lock);
2141 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
2142 if (ret == -EOPNOTSUPP) {
2143 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2144 return ZFCP_ERP_SUCCEEDED;
2146 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2147 return ZFCP_ERP_FAILED;
2149 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2151 ret = ZFCP_ERP_SUCCEEDED;
2152 down(&adapter->erp_ready_sem);
2153 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2154 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2155 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2156 ret = ZFCP_ERP_FAILED;
2159 /* don't treat as error for the sake of compatibility */
2160 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2161 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2162 "%s\n", zfcp_get_busid_by_adapter(adapter));
2168 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2171 int retval = ZFCP_ERP_SUCCEEDED;
2173 struct zfcp_adapter *adapter = erp_action->adapter;
2176 adapter->status_read_failed = 0;
2177 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2178 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2180 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2181 "notification failed on adapter %s\n",
2182 zfcp_get_busid_by_adapter(adapter));
2183 retval = ZFCP_ERP_FAILED;
2195 * purpose: this routine executes the 'Reopen Physical Port' action
2197 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2198 * ZFCP_ERP_SUCCEEDED - action finished successfully
2199 * ZFCP_ERP_FAILED - action finished unsuccessfully
2202 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2204 int retval = ZFCP_ERP_FAILED;
2205 struct zfcp_port *port = erp_action->port;
2206 struct zfcp_adapter *adapter = erp_action->adapter;
2208 switch (erp_action->step) {
2212 * the ULP spec. begs for waiting for oustanding commands
2214 case ZFCP_ERP_STEP_UNINITIALIZED:
2215 zfcp_erp_port_strategy_clearstati(port);
2217 * it would be sufficient to test only the normal open flag
2218 * since the phys. open flag cannot be set if the normal
2219 * open flag is unset - however, this is for readabilty ...
2221 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2222 ZFCP_STATUS_COMMON_OPEN),
2224 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2225 "close physical\n", port->wwpn);
2227 zfcp_erp_port_forced_strategy_close(erp_action);
2229 retval = ZFCP_ERP_FAILED;
2232 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2233 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2235 ZFCP_LOG_DEBUG("close physical failed for port "
2236 "0x%016Lx\n", port->wwpn);
2237 retval = ZFCP_ERP_FAILED;
2239 retval = ZFCP_ERP_SUCCEEDED;
2243 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2244 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2245 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2246 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2254 * purpose: this routine executes the 'Reopen Port' action
2256 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2257 * ZFCP_ERP_SUCCEEDED - action finished successfully
2258 * ZFCP_ERP_FAILED - action finished unsuccessfully
2261 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2263 int retval = ZFCP_ERP_FAILED;
2264 struct zfcp_port *port = erp_action->port;
2265 struct zfcp_adapter *adapter = erp_action->adapter;
2267 switch (erp_action->step) {
2271 * the ULP spec. begs for waiting for oustanding commands
2273 case ZFCP_ERP_STEP_UNINITIALIZED:
2274 zfcp_erp_port_strategy_clearstati(port);
2275 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2276 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2277 "close\n", port->wwpn);
2278 retval = zfcp_erp_port_strategy_close(erp_action);
2280 } /* else it's already closed, open it */
2283 case ZFCP_ERP_STEP_PORT_CLOSING:
2284 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2285 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2287 retval = ZFCP_ERP_FAILED;
2289 } /* else it's closed now, open it */
2292 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2293 retval = ZFCP_ERP_EXIT;
2295 retval = zfcp_erp_port_strategy_open(erp_action);
2298 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2299 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2300 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2301 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2307 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2311 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2312 &erp_action->port->status))
2313 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2315 retval = zfcp_erp_port_strategy_open_common(erp_action);
2321 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2324 struct zfcp_adapter *adapter = erp_action->adapter;
2325 struct zfcp_port *port = erp_action->port;
2327 switch (erp_action->step) {
2329 case ZFCP_ERP_STEP_UNINITIALIZED:
2330 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2331 case ZFCP_ERP_STEP_PORT_CLOSING:
2332 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2333 if (port->wwpn != adapter->peer_wwpn) {
2334 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2335 "on adapter %s.\nPeer WWPN "
2336 "0x%016Lx does not match\n",
2338 zfcp_get_busid_by_adapter(adapter),
2339 adapter->peer_wwpn);
2340 zfcp_erp_port_failed(port);
2341 retval = ZFCP_ERP_FAILED;
2344 port->d_id = adapter->peer_d_id;
2345 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2346 retval = zfcp_erp_port_strategy_open_port(erp_action);
2349 if (!(adapter->nameserver_port)) {
2350 retval = zfcp_nameserver_enqueue(adapter);
2352 ZFCP_LOG_NORMAL("error: nameserver port "
2353 "unavailable for adapter %s\n",
2354 zfcp_get_busid_by_adapter(adapter));
2355 retval = ZFCP_ERP_FAILED;
2359 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2360 &adapter->nameserver_port->status)) {
2361 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2362 "nameserver port\n");
2363 /* nameserver port may live again */
2364 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2365 &adapter->nameserver_port->status);
2366 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2369 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2370 retval = ZFCP_ERP_CONTINUES;
2372 retval = ZFCP_ERP_FAILED;
2375 /* else nameserver port is already open, fall through */
2376 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2377 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2378 &adapter->nameserver_port->status)) {
2379 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2380 retval = ZFCP_ERP_FAILED;
2382 ZFCP_LOG_DEBUG("nameserver port is open -> "
2383 "nameserver look-up for port 0x%016Lx\n",
2385 retval = zfcp_erp_port_strategy_open_common_lookup
2390 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2391 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2392 if (atomic_test_mask
2393 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2394 ZFCP_LOG_DEBUG("nameserver look-up failed "
2395 "for port 0x%016Lx "
2396 "(misconfigured WWPN?)\n",
2398 zfcp_erp_port_failed(port);
2399 retval = ZFCP_ERP_EXIT;
2401 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2402 "port 0x%016Lx\n", port->wwpn);
2403 retval = ZFCP_ERP_FAILED;
2406 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2407 "trying open\n", port->wwpn, port->d_id);
2408 retval = zfcp_erp_port_strategy_open_port(erp_action);
2412 case ZFCP_ERP_STEP_PORT_OPENING:
2413 /* D_ID might have changed during open */
2414 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2415 ZFCP_STATUS_PORT_DID_DID),
2417 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2418 retval = ZFCP_ERP_SUCCEEDED;
2420 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2422 retval = ZFCP_ERP_FAILED;
2427 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2429 retval = ZFCP_ERP_FAILED;
2436 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2439 struct zfcp_port *port = erp_action->port;
2441 switch (erp_action->step) {
2443 case ZFCP_ERP_STEP_UNINITIALIZED:
2444 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2445 case ZFCP_ERP_STEP_PORT_CLOSING:
2446 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2447 port->wwpn, port->d_id);
2448 retval = zfcp_erp_port_strategy_open_port(erp_action);
2451 case ZFCP_ERP_STEP_PORT_OPENING:
2452 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2453 ZFCP_LOG_DEBUG("WKA port is open\n");
2454 retval = ZFCP_ERP_SUCCEEDED;
2456 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2457 retval = ZFCP_ERP_FAILED;
2459 /* this is needed anyway (dont care for retval of wakeup) */
2460 ZFCP_LOG_DEBUG("continue other open port operations\n");
2461 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2465 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2467 retval = ZFCP_ERP_FAILED;
2476 * purpose: makes the erp thread continue with reopen (physical) port
2477 * actions which have been paused until the name server port
2478 * is opened (or failed)
2480 * returns: 0 (a kind of void retval, its not used)
2483 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2487 unsigned long flags;
2488 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2489 struct zfcp_erp_action *erp_action, *tmp;
2491 read_lock_irqsave(&adapter->erp_lock, flags);
2492 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2494 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2495 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2497 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2498 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2499 debug_event(adapter->erp_dbf, 3,
2500 &erp_action->port->wwpn, sizeof (wwn_t));
2501 if (atomic_test_mask(
2502 ZFCP_STATUS_COMMON_ERP_FAILED,
2503 &adapter->nameserver_port->status))
2504 zfcp_erp_port_failed(erp_action->port);
2505 zfcp_erp_action_ready(erp_action);
2508 read_unlock_irqrestore(&adapter->erp_lock, flags);
2518 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2519 * ZFCP_ERP_FAILED - action finished unsuccessfully
2522 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2525 struct zfcp_adapter *adapter = erp_action->adapter;
2526 struct zfcp_port *port = erp_action->port;
2528 retval = zfcp_fsf_close_physical_port(erp_action);
2529 if (retval == -ENOMEM) {
2530 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2531 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2532 retval = ZFCP_ERP_NOMEM;
2535 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2537 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2538 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2539 /* could not send 'open', fail */
2540 retval = ZFCP_ERP_FAILED;
2543 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2544 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2545 retval = ZFCP_ERP_CONTINUES;
2551 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2554 struct zfcp_adapter *adapter = port->adapter;
2556 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2557 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2559 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2560 ZFCP_STATUS_COMMON_CLOSING |
2561 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2562 ZFCP_STATUS_PORT_DID_DID |
2563 ZFCP_STATUS_PORT_PHYS_CLOSING |
2564 ZFCP_STATUS_PORT_INVALID_WWPN,
2574 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2575 * ZFCP_ERP_FAILED - action finished unsuccessfully
2578 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2581 struct zfcp_adapter *adapter = erp_action->adapter;
2582 struct zfcp_port *port = erp_action->port;
2584 retval = zfcp_fsf_close_port(erp_action);
2585 if (retval == -ENOMEM) {
2586 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2587 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2588 retval = ZFCP_ERP_NOMEM;
2591 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2593 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2594 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2595 /* could not send 'close', fail */
2596 retval = ZFCP_ERP_FAILED;
2599 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2600 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2601 retval = ZFCP_ERP_CONTINUES;
2611 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2612 * ZFCP_ERP_FAILED - action finished unsuccessfully
2615 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2618 struct zfcp_adapter *adapter = erp_action->adapter;
2619 struct zfcp_port *port = erp_action->port;
2621 retval = zfcp_fsf_open_port(erp_action);
2622 if (retval == -ENOMEM) {
2623 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2624 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2625 retval = ZFCP_ERP_NOMEM;
2628 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2630 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2631 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2632 /* could not send 'open', fail */
2633 retval = ZFCP_ERP_FAILED;
2636 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2637 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2638 retval = ZFCP_ERP_CONTINUES;
2648 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2649 * ZFCP_ERP_FAILED - action finished unsuccessfully
2652 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2655 struct zfcp_adapter *adapter = erp_action->adapter;
2656 struct zfcp_port *port = erp_action->port;
2658 retval = zfcp_ns_gid_pn_request(erp_action);
2659 if (retval == -ENOMEM) {
2660 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2661 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2662 retval = ZFCP_ERP_NOMEM;
2665 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2667 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2668 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2669 /* could not send nameserver request, fail */
2670 retval = ZFCP_ERP_FAILED;
2673 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2674 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2675 retval = ZFCP_ERP_CONTINUES;
2683 * purpose: this routine executes the 'Reopen Unit' action
2684 * currently no retries
2686 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2687 * ZFCP_ERP_SUCCEEDED - action finished successfully
2688 * ZFCP_ERP_FAILED - action finished unsuccessfully
2691 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2693 int retval = ZFCP_ERP_FAILED;
2694 struct zfcp_unit *unit = erp_action->unit;
2695 struct zfcp_adapter *adapter = erp_action->adapter;
2697 switch (erp_action->step) {
2701 * the ULP spec. begs for waiting for oustanding commands
2703 case ZFCP_ERP_STEP_UNINITIALIZED:
2704 zfcp_erp_unit_strategy_clearstati(unit);
2705 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2706 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2707 "trying close\n", unit->fcp_lun);
2708 retval = zfcp_erp_unit_strategy_close(erp_action);
2711 /* else it's already closed, fall through */
2712 case ZFCP_ERP_STEP_UNIT_CLOSING:
2713 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2714 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2716 retval = ZFCP_ERP_FAILED;
2718 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2719 retval = ZFCP_ERP_EXIT;
2721 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2722 "trying open\n", unit->fcp_lun);
2724 zfcp_erp_unit_strategy_open(erp_action);
2729 case ZFCP_ERP_STEP_UNIT_OPENING:
2730 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2731 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2733 retval = ZFCP_ERP_SUCCEEDED;
2735 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2737 retval = ZFCP_ERP_FAILED;
2742 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2743 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2744 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2745 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2750 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2753 struct zfcp_adapter *adapter = unit->port->adapter;
2755 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2756 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2758 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2759 ZFCP_STATUS_COMMON_CLOSING |
2760 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2761 ZFCP_STATUS_UNIT_SHARED |
2762 ZFCP_STATUS_UNIT_READONLY,
2773 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2774 * ZFCP_ERP_FAILED - action finished unsuccessfully
2777 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2780 struct zfcp_adapter *adapter = erp_action->adapter;
2781 struct zfcp_unit *unit = erp_action->unit;
2783 retval = zfcp_fsf_close_unit(erp_action);
2784 if (retval == -ENOMEM) {
2785 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2786 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2787 sizeof (fcp_lun_t));
2788 retval = ZFCP_ERP_NOMEM;
2791 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2793 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2794 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2795 sizeof (fcp_lun_t));
2796 /* could not send 'close', fail */
2797 retval = ZFCP_ERP_FAILED;
2800 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2801 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2802 retval = ZFCP_ERP_CONTINUES;
2813 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2814 * ZFCP_ERP_FAILED - action finished unsuccessfully
2817 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2820 struct zfcp_adapter *adapter = erp_action->adapter;
2821 struct zfcp_unit *unit = erp_action->unit;
2823 retval = zfcp_fsf_open_unit(erp_action);
2824 if (retval == -ENOMEM) {
2825 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2826 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2827 sizeof (fcp_lun_t));
2828 retval = ZFCP_ERP_NOMEM;
2831 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2833 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2834 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2835 sizeof (fcp_lun_t));
2836 /* could not send 'open', fail */
2837 retval = ZFCP_ERP_FAILED;
2840 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2841 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2842 retval = ZFCP_ERP_CONTINUES;
2847 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2849 BUG_ON(!fsf_req->erp_action);
2850 fsf_req->timer.function = zfcp_erp_timeout_handler;
2851 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2852 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2853 add_timer(&fsf_req->timer);
2859 * purpose: enqueue the specified error recovery action, if needed
2864 zfcp_erp_action_enqueue(int action,
2865 struct zfcp_adapter *adapter,
2866 struct zfcp_port *port, struct zfcp_unit *unit)
2869 struct zfcp_erp_action *erp_action = NULL;
2870 int stronger_action = 0;
2874 * We need some rules here which check whether we really need
2875 * this action or whether we should just drop it.
2876 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2877 * 'Reopen Unit' request for an associated unit since we can't
2878 * satisfy this request now. A 'Reopen Port' action will trigger
2879 * 'Reopen Unit' actions when it completes.
2880 * Thus, there are only actions in the queue which can immediately be
2881 * executed. This makes the processing of the action queue more
2885 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2889 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2890 /* check whether we really need this */
2892 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2893 if (atomic_test_mask
2894 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2895 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2896 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2898 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2899 sizeof (fcp_lun_t));
2902 if (!atomic_test_mask
2903 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2905 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2908 if (!atomic_test_mask
2909 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2910 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2913 /* fall through !!! */
2915 case ZFCP_ERP_ACTION_REOPEN_PORT:
2916 if (atomic_test_mask
2917 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2918 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2919 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2923 /* fall through !!! */
2925 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2926 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2928 if (port->erp_action.action !=
2929 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2930 ZFCP_LOG_INFO("dropped erp action %i (port "
2931 "0x%016Lx, action in use: %i)\n",
2933 port->erp_action.action);
2934 debug_text_event(adapter->erp_dbf, 4,
2937 debug_text_event(adapter->erp_dbf, 4,
2939 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2943 if (!atomic_test_mask
2944 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2946 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2949 if (!atomic_test_mask
2950 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
2951 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
2954 /* fall through !!! */
2956 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2957 if (atomic_test_mask
2958 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
2959 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
2965 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
2966 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
2967 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2968 "on adapter %s (action=%d)\n",
2969 zfcp_get_busid_by_adapter(adapter), action);
2973 /* check whether we need something stronger first */
2974 if (stronger_action) {
2975 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
2976 debug_event(adapter->erp_dbf, 4, &stronger_action,
2978 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2979 "erp action %d on adapter %s\n",
2980 stronger_action, action,
2981 zfcp_get_busid_by_adapter(adapter));
2982 action = stronger_action;
2985 /* mark adapter to have some error recovery pending */
2986 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2988 /* setup error recovery action */
2991 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2992 zfcp_unit_get(unit);
2993 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2994 erp_action = &unit->erp_action;
2995 if (!atomic_test_mask
2996 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
2997 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3000 case ZFCP_ERP_ACTION_REOPEN_PORT:
3001 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3002 zfcp_port_get(port);
3003 zfcp_erp_action_dismiss_port(port);
3004 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3005 erp_action = &port->erp_action;
3006 if (!atomic_test_mask
3007 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3008 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3011 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3012 zfcp_adapter_get(adapter);
3013 zfcp_erp_action_dismiss_adapter(adapter);
3014 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3015 erp_action = &adapter->erp_action;
3016 if (!atomic_test_mask
3017 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3018 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3022 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3024 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3025 erp_action->adapter = adapter;
3026 erp_action->port = port;
3027 erp_action->unit = unit;
3028 erp_action->action = action;
3029 erp_action->status = status;
3031 ++adapter->erp_total_count;
3033 /* finally put it into 'ready' queue and kick erp thread */
3034 list_add(&erp_action->list, &adapter->erp_ready_head);
3035 up(&adapter->erp_ready_sem);
3042 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3045 struct zfcp_adapter *adapter = erp_action->adapter;
3047 --adapter->erp_total_count;
3048 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3049 --adapter->erp_low_mem_count;
3050 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3053 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3054 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3055 list_del(&erp_action->list);
3056 switch (erp_action->action) {
3057 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3058 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3059 &erp_action->unit->status);
3061 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3062 case ZFCP_ERP_ACTION_REOPEN_PORT:
3063 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3064 &erp_action->port->status);
3066 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3067 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3068 &erp_action->adapter->status);
3078 * zfcp_erp_action_cleanup
3080 * Register unit with scsi stack if appropriate and fix reference counts.
3081 * Note: Temporary units are not registered with scsi stack.
3084 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3085 struct zfcp_port *port, struct zfcp_unit *unit,
3089 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3090 if ((result == ZFCP_ERP_SUCCEEDED)
3091 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3095 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3097 scsi_scan_target(&port->rport->dev, 0,
3098 port->rport->scsi_target_id,
3101 zfcp_unit_put(unit);
3103 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3104 case ZFCP_ERP_ACTION_REOPEN_PORT:
3105 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3107 zfcp_port_put(port);
3111 if ((result == ZFCP_ERP_SUCCEEDED)
3113 struct fc_rport_identifiers ids;
3114 ids.node_name = port->wwnn;
3115 ids.port_name = port->wwpn;
3116 ids.port_id = port->d_id;
3117 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3119 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3121 ZFCP_LOG_NORMAL("failed registration of rport"
3122 "(adapter %s, wwpn=0x%016Lx)\n",
3123 zfcp_get_busid_by_port(port),
3126 scsi_flush_work(adapter->scsi_host);
3127 port->rport->maxframe_size = port->maxframe_size;
3128 port->rport->supported_classes =
3129 port->supported_classes;
3132 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3133 fc_remote_port_delete(port->rport);
3136 zfcp_port_put(port);
3138 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3139 if (result != ZFCP_ERP_SUCCEEDED) {
3140 struct zfcp_port *port;
3141 list_for_each_entry(port, &adapter->port_list_head, list)
3143 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3145 fc_remote_port_delete(port->rport);
3149 zfcp_adapter_put(adapter);
3157 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3159 struct zfcp_port *port;
3161 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3162 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3163 zfcp_erp_action_dismiss(&adapter->erp_action);
3165 list_for_each_entry(port, &adapter->port_list_head, list)
3166 zfcp_erp_action_dismiss_port(port);
3169 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3171 struct zfcp_unit *unit;
3172 struct zfcp_adapter *adapter = port->adapter;
3174 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3175 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3176 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3177 zfcp_erp_action_dismiss(&port->erp_action);
3179 list_for_each_entry(unit, &port->unit_list_head, list)
3180 zfcp_erp_action_dismiss_unit(unit);
3183 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3185 struct zfcp_adapter *adapter = unit->port->adapter;
3187 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3188 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3189 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3190 zfcp_erp_action_dismiss(&unit->erp_action);
3194 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3196 struct zfcp_adapter *adapter = erp_action->adapter;
3198 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3199 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3200 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3204 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3206 struct zfcp_adapter *adapter = erp_action->adapter;
3208 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3209 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3210 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3214 zfcp_erp_port_boxed(struct zfcp_port *port)
3216 struct zfcp_adapter *adapter = port->adapter;
3217 unsigned long flags;
3219 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3220 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3221 read_lock_irqsave(&zfcp_data.config_lock, flags);
3222 zfcp_erp_modify_port_status(port,
3223 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3225 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3226 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3230 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3232 struct zfcp_adapter *adapter = unit->port->adapter;
3234 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3235 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3236 zfcp_erp_modify_unit_status(unit,
3237 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3239 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3243 zfcp_erp_port_access_denied(struct zfcp_port *port)
3245 struct zfcp_adapter *adapter = port->adapter;
3246 unsigned long flags;
3248 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3249 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3250 read_lock_irqsave(&zfcp_data.config_lock, flags);
3251 zfcp_erp_modify_port_status(port,
3252 ZFCP_STATUS_COMMON_ERP_FAILED |
3253 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3255 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3259 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3261 struct zfcp_adapter *adapter = unit->port->adapter;
3263 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3264 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3265 zfcp_erp_modify_unit_status(unit,
3266 ZFCP_STATUS_COMMON_ERP_FAILED |
3267 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3272 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3274 struct zfcp_port *port;
3275 unsigned long flags;
3277 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3280 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3281 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3283 read_lock_irqsave(&zfcp_data.config_lock, flags);
3284 if (adapter->nameserver_port)
3285 zfcp_erp_port_access_changed(adapter->nameserver_port);
3286 list_for_each_entry(port, &adapter->port_list_head, list)
3287 if (port != adapter->nameserver_port)
3288 zfcp_erp_port_access_changed(port);
3289 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3293 zfcp_erp_port_access_changed(struct zfcp_port *port)
3295 struct zfcp_adapter *adapter = port->adapter;
3296 struct zfcp_unit *unit;
3298 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3299 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3301 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3303 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3305 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3306 list_for_each_entry(unit, &port->unit_list_head, list)
3307 zfcp_erp_unit_access_changed(unit);
3311 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3312 "(due to ACT update)\n",
3313 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3314 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3315 ZFCP_LOG_NORMAL("failed reopen of port"
3316 "(adapter %s, wwpn=0x%016Lx)\n",
3317 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3321 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3323 struct zfcp_adapter *adapter = unit->port->adapter;
3325 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3326 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3328 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3330 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3334 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3335 " on adapter %s (due to ACT update)\n",
3336 unit->fcp_lun, unit->port->wwpn,
3337 zfcp_get_busid_by_adapter(adapter));
3338 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3339 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3340 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3341 zfcp_get_busid_by_adapter(adapter),
3342 unit->port->wwpn, unit->fcp_lun);
3345 #undef ZFCP_LOG_AREA