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 = 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 = 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)
843 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
845 struct zfcp_adapter *adapter = erp_action->adapter;
847 if (erp_action->fsf_req) {
848 /* take lock to ensure that request is not deleted meanwhile */
849 spin_lock(&adapter->req_list_lock);
850 if (zfcp_reqlist_ismember(adapter,
851 erp_action->fsf_req->req_id)) {
852 /* fsf_req still exists */
853 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
854 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
855 sizeof (unsigned long));
856 /* dismiss fsf_req of timed out/dismissed erp_action */
857 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
858 ZFCP_STATUS_ERP_TIMEDOUT)) {
859 debug_text_event(adapter->erp_dbf, 3,
861 erp_action->fsf_req->status |=
862 ZFCP_STATUS_FSFREQ_DISMISSED;
864 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
865 ZFCP_LOG_NORMAL("error: erp step timed out "
866 "(action=%d, fsf_req=%p)\n ",
868 erp_action->fsf_req);
871 * If fsf_req is neither dismissed nor completed
872 * then keep it running asynchronously and don't mess
873 * with the association of erp_action and fsf_req.
875 if (erp_action->fsf_req->status &
876 (ZFCP_STATUS_FSFREQ_COMPLETED |
877 ZFCP_STATUS_FSFREQ_DISMISSED)) {
878 /* forget about association between fsf_req
880 erp_action->fsf_req = NULL;
883 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
885 * even if this fsf_req has gone, forget about
886 * association between erp_action and fsf_req
888 erp_action->fsf_req = NULL;
890 spin_unlock(&adapter->req_list_lock);
892 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
896 * zfcp_erp_async_handler_nolock - complete erp_action
898 * Used for normal completion, time-out, dismissal and failure after
899 * low memory condition.
901 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
902 unsigned long set_mask)
904 struct zfcp_adapter *adapter = erp_action->adapter;
906 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
907 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
908 debug_event(adapter->erp_dbf, 2, &erp_action->action,
910 erp_action->status |= set_mask;
911 zfcp_erp_action_ready(erp_action);
913 /* action is ready or gone - nothing to do */
914 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
915 debug_event(adapter->erp_dbf, 3, &erp_action->action,
921 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
923 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
924 unsigned long set_mask)
926 struct zfcp_adapter *adapter = erp_action->adapter;
929 write_lock_irqsave(&adapter->erp_lock, flags);
930 zfcp_erp_async_handler_nolock(erp_action, set_mask);
931 write_unlock_irqrestore(&adapter->erp_lock, flags);
935 * purpose: is called for erp_action which was slept waiting for
936 * memory becoming avaliable,
937 * will trigger that this action will be continued
940 zfcp_erp_memwait_handler(unsigned long data)
942 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
943 struct zfcp_adapter *adapter = erp_action->adapter;
945 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
946 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
948 zfcp_erp_async_handler(erp_action, 0);
952 * purpose: is called if an asynchronous erp step timed out,
953 * action gets an appropriate flag and will be processed
956 void zfcp_erp_timeout_handler(unsigned long data)
958 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
959 struct zfcp_adapter *adapter = erp_action->adapter;
961 debug_text_event(adapter->erp_dbf, 2, "a_th");
962 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
964 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
968 * zfcp_erp_action_dismiss - dismiss an erp_action
970 * adapter->erp_lock must be held
972 * Dismissal of an erp_action is usually required if an erp_action of
973 * higher priority is generated.
975 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
977 struct zfcp_adapter *adapter = erp_action->adapter;
979 debug_text_event(adapter->erp_dbf, 2, "a_adis");
980 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
982 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
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.prev;
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
1160 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1163 case ZFCP_ERP_DISMISSED:
1164 /* leave since this action has ridden to its ancestors */
1165 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1167 case ZFCP_ERP_NOMEM:
1168 /* no memory to continue immediately, let it sleep */
1169 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1170 ++adapter->erp_low_mem_count;
1171 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1173 /* This condition is true if there is no memory available
1174 for any erp_action on this adapter. This implies that there
1175 are no elements in the memory pool(s) left for erp_actions.
1176 This might happen if an erp_action that used a memory pool
1177 element was timed out.
1179 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1180 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1181 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1182 "restarting I/O on adapter %s "
1183 "to free mempool\n",
1184 zfcp_get_busid_by_adapter(adapter));
1185 zfcp_erp_adapter_reopen_internal(adapter, 0);
1187 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1188 retval = zfcp_erp_strategy_memwait(erp_action);
1191 case ZFCP_ERP_CONTINUES:
1192 /* leave since this action runs asynchronously */
1193 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1194 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1195 --adapter->erp_low_mem_count;
1196 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1200 /* ok, finished action (whatever its result is) */
1202 /* check for unrecoverable targets */
1203 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1205 /* action must be dequeued (here to allow for further ones) */
1206 zfcp_erp_action_dequeue(erp_action);
1209 * put this target through the erp mill again if someone has
1210 * requested to change the status of a target being online
1211 * to offline or the other way around
1212 * (old retval is preserved if nothing has to be done here)
1214 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1215 port, unit, retval);
1218 * leave if target is in permanent error state or if
1219 * action is repeated in order to process state change
1221 if (retval == ZFCP_ERP_EXIT) {
1222 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1226 /* trigger follow up actions */
1227 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1230 write_unlock(&adapter->erp_lock);
1231 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1233 if (retval != ZFCP_ERP_CONTINUES)
1234 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1237 * a few tasks remain when the erp queues are empty
1238 * (don't do that if the last action evaluated was dismissed
1239 * since this clearly indicates that there is more to come) :
1240 * - close the name server port if it is open yet
1241 * (enqueues another [probably] final action)
1242 * - otherwise, wake up whoever wants to be woken when we are
1245 if (retval != ZFCP_ERP_DISMISSED)
1246 zfcp_erp_strategy_check_queues(adapter);
1248 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1258 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1259 * retval - otherwise
1262 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1264 struct zfcp_adapter *adapter = erp_action->adapter;
1266 zfcp_erp_strategy_check_fsfreq(erp_action);
1268 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1269 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1270 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1271 zfcp_erp_action_dequeue(erp_action);
1272 retval = ZFCP_ERP_DISMISSED;
1274 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1280 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1282 int retval = ZFCP_ERP_FAILED;
1283 struct zfcp_adapter *adapter = erp_action->adapter;
1286 * try to execute/continue action as far as possible,
1287 * note: no lock in subsequent strategy routines
1288 * (this allows these routine to call schedule, e.g.
1289 * kmalloc with such flags or qdio_initialize & friends)
1290 * Note: in case of timeout, the seperate strategies will fail
1291 * anyhow. No need for a special action. Even worse, a nameserver
1292 * failure would not wake up waiting ports without the call.
1294 switch (erp_action->action) {
1296 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1297 retval = zfcp_erp_adapter_strategy(erp_action);
1300 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1301 retval = zfcp_erp_port_forced_strategy(erp_action);
1304 case ZFCP_ERP_ACTION_REOPEN_PORT:
1305 retval = zfcp_erp_port_strategy(erp_action);
1308 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1309 retval = zfcp_erp_unit_strategy(erp_action);
1313 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1314 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1316 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1317 "adapter %s (action=%d)\n",
1318 zfcp_get_busid_by_adapter(erp_action->adapter),
1319 erp_action->action);
1328 * purpose: triggers retry of this action after a certain amount of time
1329 * by means of timer provided by erp_action
1331 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1334 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1336 int retval = ZFCP_ERP_CONTINUES;
1337 struct zfcp_adapter *adapter = erp_action->adapter;
1339 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1340 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1341 init_timer(&erp_action->timer);
1342 erp_action->timer.function = zfcp_erp_memwait_handler;
1343 erp_action->timer.data = (unsigned long) erp_action;
1344 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1345 add_timer(&erp_action->timer);
1351 * function: zfcp_erp_adapter_failed
1353 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1357 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1359 zfcp_erp_modify_adapter_status(adapter,
1360 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1361 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1362 zfcp_get_busid_by_adapter(adapter));
1363 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1367 * function: zfcp_erp_port_failed
1369 * purpose: sets the port and all underlying devices to ERP_FAILED
1373 zfcp_erp_port_failed(struct zfcp_port *port)
1375 zfcp_erp_modify_port_status(port,
1376 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1378 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1379 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1380 "port d_id=0x%08x)\n",
1381 zfcp_get_busid_by_port(port), port->d_id);
1383 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1384 zfcp_get_busid_by_port(port), port->wwpn);
1386 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1387 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1391 * function: zfcp_erp_unit_failed
1393 * purpose: sets the unit to ERP_FAILED
1397 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1399 zfcp_erp_modify_unit_status(unit,
1400 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1402 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1403 " on adapter %s\n", unit->fcp_lun,
1404 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1405 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1406 debug_event(unit->port->adapter->erp_dbf, 2,
1407 &unit->fcp_lun, sizeof (fcp_lun_t));
1411 * function: zfcp_erp_strategy_check_target
1413 * purpose: increments the erp action count on the device currently in
1414 * recovery if the action failed or resets the count in case of
1415 * success. If a maximum count is exceeded the device is marked
1417 * The 'blocked' state of a target which has been recovered
1418 * successfully is reset.
1420 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1421 * ZFCP_ERP_SUCCEEDED - action finished successfully
1422 * ZFCP_ERP_EXIT - action failed and will not continue
1425 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1427 struct zfcp_adapter *adapter = erp_action->adapter;
1428 struct zfcp_port *port = erp_action->port;
1429 struct zfcp_unit *unit = erp_action->unit;
1431 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1432 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1433 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1435 switch (erp_action->action) {
1437 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1438 result = zfcp_erp_strategy_check_unit(unit, result);
1441 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1442 case ZFCP_ERP_ACTION_REOPEN_PORT:
1443 result = zfcp_erp_strategy_check_port(port, result);
1446 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1447 result = zfcp_erp_strategy_check_adapter(adapter, result);
1455 zfcp_erp_strategy_statechange(int action,
1457 struct zfcp_adapter *adapter,
1458 struct zfcp_port *port,
1459 struct zfcp_unit *unit, int retval)
1461 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1462 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1466 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1467 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1469 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1470 retval = ZFCP_ERP_EXIT;
1474 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1475 case ZFCP_ERP_ACTION_REOPEN_PORT:
1476 if (zfcp_erp_strategy_statechange_detected(&port->status,
1478 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1479 retval = ZFCP_ERP_EXIT;
1483 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1484 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1486 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1487 retval = ZFCP_ERP_EXIT;
1496 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1499 /* take it online */
1500 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1501 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1502 /* take it offline */
1503 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1504 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1508 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1510 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1511 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1512 sizeof (fcp_lun_t));
1515 case ZFCP_ERP_SUCCEEDED :
1516 atomic_set(&unit->erp_counter, 0);
1517 zfcp_erp_unit_unblock(unit);
1519 case ZFCP_ERP_FAILED :
1520 atomic_inc(&unit->erp_counter);
1521 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1522 zfcp_erp_unit_failed(unit);
1524 case ZFCP_ERP_EXIT :
1529 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1530 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1531 result = ZFCP_ERP_EXIT;
1538 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1540 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1541 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1544 case ZFCP_ERP_SUCCEEDED :
1545 atomic_set(&port->erp_counter, 0);
1546 zfcp_erp_port_unblock(port);
1548 case ZFCP_ERP_FAILED :
1549 atomic_inc(&port->erp_counter);
1550 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1551 zfcp_erp_port_failed(port);
1553 case ZFCP_ERP_EXIT :
1558 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1559 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1560 result = ZFCP_ERP_EXIT;
1567 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1569 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1572 case ZFCP_ERP_SUCCEEDED :
1573 atomic_set(&adapter->erp_counter, 0);
1574 zfcp_erp_adapter_unblock(adapter);
1576 case ZFCP_ERP_FAILED :
1577 atomic_inc(&adapter->erp_counter);
1578 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1579 zfcp_erp_adapter_failed(adapter);
1581 case ZFCP_ERP_EXIT :
1586 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1587 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1588 result = ZFCP_ERP_EXIT;
1597 * purpose: remaining things in good cases,
1598 * escalation in bad cases
1603 zfcp_erp_strategy_followup_actions(int action,
1604 struct zfcp_adapter *adapter,
1605 struct zfcp_port *port,
1606 struct zfcp_unit *unit, int status)
1608 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1609 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1611 /* initiate follow-up actions depending on success of finished action */
1614 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1615 if (status == ZFCP_ERP_SUCCEEDED)
1616 zfcp_erp_port_reopen_all_internal(adapter, 0);
1618 zfcp_erp_adapter_reopen_internal(adapter, 0);
1621 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1622 if (status == ZFCP_ERP_SUCCEEDED)
1623 zfcp_erp_port_reopen_internal(port, 0);
1625 zfcp_erp_adapter_reopen_internal(adapter, 0);
1628 case ZFCP_ERP_ACTION_REOPEN_PORT:
1629 if (status == ZFCP_ERP_SUCCEEDED)
1630 zfcp_erp_unit_reopen_all_internal(port, 0);
1632 zfcp_erp_port_forced_reopen_internal(port, 0);
1635 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1636 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1638 zfcp_erp_port_reopen_internal(unit->port, 0);
1646 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1648 unsigned long flags;
1650 read_lock_irqsave(&zfcp_data.config_lock, flags);
1651 read_lock(&adapter->erp_lock);
1652 if (list_empty(&adapter->erp_ready_head) &&
1653 list_empty(&adapter->erp_running_head)) {
1654 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1655 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1657 wake_up(&adapter->erp_done_wqh);
1659 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1660 read_unlock(&adapter->erp_lock);
1661 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1667 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1668 * @adapter: adapter for which to wait for completion of its error recovery
1672 zfcp_erp_wait(struct zfcp_adapter *adapter)
1676 wait_event(adapter->erp_done_wqh,
1677 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1684 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1685 u32 mask, int set_or_clear)
1687 struct zfcp_port *port;
1688 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1690 if (set_or_clear == ZFCP_SET) {
1691 atomic_set_mask(mask, &adapter->status);
1692 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1694 atomic_clear_mask(mask, &adapter->status);
1695 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1696 atomic_set(&adapter->erp_counter, 0);
1697 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1699 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1701 /* Deal with all underlying devices, only pass common_mask */
1703 list_for_each_entry(port, &adapter->port_list_head, list)
1704 zfcp_erp_modify_port_status(port, common_mask,
1709 * function: zfcp_erp_modify_port_status
1711 * purpose: sets the port and all underlying devices to ERP_FAILED
1715 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1717 struct zfcp_unit *unit;
1718 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1720 if (set_or_clear == ZFCP_SET) {
1721 atomic_set_mask(mask, &port->status);
1722 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1724 atomic_clear_mask(mask, &port->status);
1725 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1726 atomic_set(&port->erp_counter, 0);
1727 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1729 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1730 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1732 /* Modify status of all underlying devices, only pass common mask */
1734 list_for_each_entry(unit, &port->unit_list_head, list)
1735 zfcp_erp_modify_unit_status(unit, common_mask,
1740 * function: zfcp_erp_modify_unit_status
1742 * purpose: sets the unit to ERP_FAILED
1746 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1748 if (set_or_clear == ZFCP_SET) {
1749 atomic_set_mask(mask, &unit->status);
1750 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1752 atomic_clear_mask(mask, &unit->status);
1753 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1754 atomic_set(&unit->erp_counter, 0);
1756 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1758 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1759 sizeof (fcp_lun_t));
1760 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1766 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1767 * used to ensure the correct locking
1769 * returns: 0 - initiated action successfully
1770 * <0 - failed to initiate action
1773 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1776 unsigned long flags;
1778 read_lock_irqsave(&zfcp_data.config_lock, flags);
1779 write_lock(&adapter->erp_lock);
1780 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1781 write_unlock(&adapter->erp_lock);
1782 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1788 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1791 struct zfcp_port *port;
1793 list_for_each_entry(port, &adapter->port_list_head, list)
1794 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1795 zfcp_erp_port_reopen_internal(port, clear_mask);
1808 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1811 struct zfcp_unit *unit;
1813 list_for_each_entry(unit, &port->unit_list_head, list)
1814 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1822 * purpose: this routine executes the 'Reopen Adapter' action
1823 * (the entire action is processed synchronously, since
1824 * there are no actions which might be run concurrently
1827 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1828 * ZFCP_ERP_FAILED - action finished unsuccessfully
1831 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1834 struct zfcp_adapter *adapter = erp_action->adapter;
1836 retval = zfcp_erp_adapter_strategy_close(erp_action);
1837 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1838 retval = ZFCP_ERP_EXIT;
1840 retval = zfcp_erp_adapter_strategy_open(erp_action);
1842 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1843 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1844 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1846 if (retval == ZFCP_ERP_FAILED) {
1847 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1848 "to recover itself\n",
1849 zfcp_get_busid_by_adapter(adapter));
1850 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1861 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1862 * ZFCP_ERP_FAILED - action finished unsuccessfully
1865 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1869 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1870 &erp_action->adapter->status);
1871 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1872 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1873 &erp_action->adapter->status);
1883 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1884 * ZFCP_ERP_FAILED - action finished unsuccessfully
1887 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1891 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1892 &erp_action->adapter->status);
1893 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1894 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1895 &erp_action->adapter->status);
1901 * function: zfcp_register_adapter
1903 * purpose: allocate the irq associated with this devno and register
1904 * the FSF adapter with the SCSI stack
1909 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1911 int retval = ZFCP_ERP_SUCCEEDED;
1916 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1917 if (retval != ZFCP_ERP_SUCCEEDED)
1920 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1921 if (retval != ZFCP_ERP_SUCCEEDED)
1922 goto failed_openfcp;
1924 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1928 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1929 &erp_action->adapter->status);
1932 zfcp_close_fsf(erp_action->adapter);
1939 * function: zfcp_qdio_init
1941 * purpose: setup QDIO operation for specified adapter
1943 * returns: 0 - successful setup
1947 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1951 volatile struct qdio_buffer_element *sbale;
1952 struct zfcp_adapter *adapter = erp_action->adapter;
1954 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
1955 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1957 zfcp_get_busid_by_adapter(adapter));
1961 if (qdio_establish(&adapter->qdio_init_data) != 0) {
1962 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1964 zfcp_get_busid_by_adapter(adapter));
1965 goto failed_qdio_establish;
1967 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
1969 if (qdio_activate(adapter->ccw_device, 0) != 0) {
1970 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1972 zfcp_get_busid_by_adapter(adapter));
1973 goto failed_qdio_activate;
1975 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
1978 * put buffers into response queue,
1980 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
1981 sbale = &(adapter->response_queue.buffer[i]->element[0]);
1983 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
1987 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1988 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1989 zfcp_get_busid_by_adapter(adapter),
1990 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
1992 retval = do_QDIO(adapter->ccw_device,
1993 QDIO_FLAG_SYNC_INPUT,
1994 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
1997 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
1999 goto failed_do_qdio;
2001 adapter->response_queue.free_index = 0;
2002 atomic_set(&adapter->response_queue.free_count, 0);
2003 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2004 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2006 /* set index of first avalable SBALS / number of available SBALS */
2007 adapter->request_queue.free_index = 0;
2008 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2009 adapter->request_queue.distance_from_int = 0;
2011 /* initialize waitqueue used to wait for free SBALs in requests queue */
2012 init_waitqueue_head(&adapter->request_wq);
2014 /* ok, we did it - skip all cleanups for different failures */
2015 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2016 retval = ZFCP_ERP_SUCCEEDED;
2022 failed_qdio_activate:
2023 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2024 while (qdio_shutdown(adapter->ccw_device,
2025 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2027 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2029 failed_qdio_establish:
2031 retval = ZFCP_ERP_FAILED;
2039 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2043 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2044 if (retval == ZFCP_ERP_FAILED)
2045 return ZFCP_ERP_FAILED;
2047 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2048 if (retval == ZFCP_ERP_FAILED)
2049 return ZFCP_ERP_FAILED;
2051 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2055 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2057 int retval = ZFCP_ERP_SUCCEEDED;
2059 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2060 struct zfcp_adapter *adapter = erp_action->adapter;
2062 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2064 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2065 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2067 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2068 write_lock_irq(&adapter->erp_lock);
2069 zfcp_erp_action_to_running(erp_action);
2070 write_unlock_irq(&adapter->erp_lock);
2071 if (zfcp_fsf_exchange_config_data(erp_action)) {
2072 retval = ZFCP_ERP_FAILED;
2073 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2074 ZFCP_LOG_INFO("error: initiation of exchange of "
2075 "configuration data failed for "
2077 zfcp_get_busid_by_adapter(adapter));
2080 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2081 ZFCP_LOG_DEBUG("Xchange underway\n");
2085 * Both the normal completion handler as well as the timeout
2086 * handler will do an 'up' when the 'exchange config data'
2087 * request completes or times out. Thus, the signal to go on
2088 * won't be lost utilizing this semaphore.
2089 * Furthermore, this 'adapter_reopen' action is
2090 * guaranteed to be the only action being there (highest action
2091 * which prevents other actions from being created).
2092 * Resulting from that, the wake signal recognized here
2093 * _must_ be the one belonging to the 'exchange config
2096 down(&adapter->erp_ready_sem);
2097 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2098 ZFCP_LOG_INFO("error: exchange of configuration data "
2099 "for adapter %s timed out\n",
2100 zfcp_get_busid_by_adapter(adapter));
2104 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2108 ZFCP_LOG_DEBUG("host connection still initialising... "
2109 "waiting and retrying...\n");
2110 /* sleep a little bit before retry */
2111 msleep(jiffies_to_msecs(sleep));
2115 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2116 &adapter->status)) {
2117 ZFCP_LOG_INFO("error: exchange of configuration data for "
2118 "adapter %s failed\n",
2119 zfcp_get_busid_by_adapter(adapter));
2120 retval = ZFCP_ERP_FAILED;
2127 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2130 struct zfcp_adapter *adapter;
2132 adapter = erp_action->adapter;
2133 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2135 write_lock_irq(&adapter->erp_lock);
2136 zfcp_erp_action_to_running(erp_action);
2137 write_unlock_irq(&adapter->erp_lock);
2139 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
2140 if (ret == -EOPNOTSUPP) {
2141 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2142 return ZFCP_ERP_SUCCEEDED;
2144 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2145 return ZFCP_ERP_FAILED;
2147 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2149 ret = ZFCP_ERP_SUCCEEDED;
2150 down(&adapter->erp_ready_sem);
2151 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2152 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2153 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2154 ret = ZFCP_ERP_FAILED;
2157 /* don't treat as error for the sake of compatibility */
2158 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2159 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2160 "%s\n", zfcp_get_busid_by_adapter(adapter));
2166 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2169 int retval = ZFCP_ERP_SUCCEEDED;
2171 struct zfcp_adapter *adapter = erp_action->adapter;
2174 adapter->status_read_failed = 0;
2175 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2176 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2178 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2179 "notification failed on adapter %s\n",
2180 zfcp_get_busid_by_adapter(adapter));
2181 retval = ZFCP_ERP_FAILED;
2193 * purpose: this routine executes the 'Reopen Physical Port' action
2195 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2196 * ZFCP_ERP_SUCCEEDED - action finished successfully
2197 * ZFCP_ERP_FAILED - action finished unsuccessfully
2200 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2202 int retval = ZFCP_ERP_FAILED;
2203 struct zfcp_port *port = erp_action->port;
2204 struct zfcp_adapter *adapter = erp_action->adapter;
2206 switch (erp_action->step) {
2210 * the ULP spec. begs for waiting for oustanding commands
2212 case ZFCP_ERP_STEP_UNINITIALIZED:
2213 zfcp_erp_port_strategy_clearstati(port);
2215 * it would be sufficient to test only the normal open flag
2216 * since the phys. open flag cannot be set if the normal
2217 * open flag is unset - however, this is for readabilty ...
2219 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2220 ZFCP_STATUS_COMMON_OPEN),
2222 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2223 "close physical\n", port->wwpn);
2225 zfcp_erp_port_forced_strategy_close(erp_action);
2227 retval = ZFCP_ERP_FAILED;
2230 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2231 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2233 ZFCP_LOG_DEBUG("close physical failed for port "
2234 "0x%016Lx\n", port->wwpn);
2235 retval = ZFCP_ERP_FAILED;
2237 retval = ZFCP_ERP_SUCCEEDED;
2241 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2242 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2243 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2244 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2252 * purpose: this routine executes the 'Reopen 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_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);
2273 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2274 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2275 "close\n", port->wwpn);
2276 retval = zfcp_erp_port_strategy_close(erp_action);
2278 } /* else it's already closed, open it */
2281 case ZFCP_ERP_STEP_PORT_CLOSING:
2282 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2283 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2285 retval = ZFCP_ERP_FAILED;
2287 } /* else it's closed now, open it */
2290 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2291 retval = ZFCP_ERP_EXIT;
2293 retval = zfcp_erp_port_strategy_open(erp_action);
2296 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2297 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2298 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2299 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2305 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2309 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2310 &erp_action->port->status))
2311 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2313 retval = zfcp_erp_port_strategy_open_common(erp_action);
2319 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2322 struct zfcp_adapter *adapter = erp_action->adapter;
2323 struct zfcp_port *port = erp_action->port;
2325 switch (erp_action->step) {
2327 case ZFCP_ERP_STEP_UNINITIALIZED:
2328 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2329 case ZFCP_ERP_STEP_PORT_CLOSING:
2330 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2331 if (port->wwpn != adapter->peer_wwpn) {
2332 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2333 "on adapter %s.\nPeer WWPN "
2334 "0x%016Lx does not match\n",
2336 zfcp_get_busid_by_adapter(adapter),
2337 adapter->peer_wwpn);
2338 zfcp_erp_port_failed(port);
2339 retval = ZFCP_ERP_FAILED;
2342 port->d_id = adapter->peer_d_id;
2343 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2344 retval = zfcp_erp_port_strategy_open_port(erp_action);
2347 if (!(adapter->nameserver_port)) {
2348 retval = zfcp_nameserver_enqueue(adapter);
2350 ZFCP_LOG_NORMAL("error: nameserver port "
2351 "unavailable for adapter %s\n",
2352 zfcp_get_busid_by_adapter(adapter));
2353 retval = ZFCP_ERP_FAILED;
2357 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2358 &adapter->nameserver_port->status)) {
2359 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2360 "nameserver port\n");
2361 /* nameserver port may live again */
2362 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2363 &adapter->nameserver_port->status);
2364 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2367 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2368 retval = ZFCP_ERP_CONTINUES;
2370 retval = ZFCP_ERP_FAILED;
2373 /* else nameserver port is already open, fall through */
2374 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2375 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2376 &adapter->nameserver_port->status)) {
2377 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2378 retval = ZFCP_ERP_FAILED;
2380 ZFCP_LOG_DEBUG("nameserver port is open -> "
2381 "nameserver look-up for port 0x%016Lx\n",
2383 retval = zfcp_erp_port_strategy_open_common_lookup
2388 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2389 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2390 if (atomic_test_mask
2391 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2392 ZFCP_LOG_DEBUG("nameserver look-up failed "
2393 "for port 0x%016Lx "
2394 "(misconfigured WWPN?)\n",
2396 zfcp_erp_port_failed(port);
2397 retval = ZFCP_ERP_EXIT;
2399 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2400 "port 0x%016Lx\n", port->wwpn);
2401 retval = ZFCP_ERP_FAILED;
2404 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2405 "trying open\n", port->wwpn, port->d_id);
2406 retval = zfcp_erp_port_strategy_open_port(erp_action);
2410 case ZFCP_ERP_STEP_PORT_OPENING:
2411 /* D_ID might have changed during open */
2412 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2413 ZFCP_STATUS_PORT_DID_DID),
2415 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2416 retval = ZFCP_ERP_SUCCEEDED;
2418 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2420 retval = ZFCP_ERP_FAILED;
2425 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2427 retval = ZFCP_ERP_FAILED;
2434 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2437 struct zfcp_port *port = erp_action->port;
2439 switch (erp_action->step) {
2441 case ZFCP_ERP_STEP_UNINITIALIZED:
2442 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2443 case ZFCP_ERP_STEP_PORT_CLOSING:
2444 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2445 port->wwpn, port->d_id);
2446 retval = zfcp_erp_port_strategy_open_port(erp_action);
2449 case ZFCP_ERP_STEP_PORT_OPENING:
2450 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2451 ZFCP_LOG_DEBUG("WKA port is open\n");
2452 retval = ZFCP_ERP_SUCCEEDED;
2454 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2455 retval = ZFCP_ERP_FAILED;
2457 /* this is needed anyway (dont care for retval of wakeup) */
2458 ZFCP_LOG_DEBUG("continue other open port operations\n");
2459 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2463 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2465 retval = ZFCP_ERP_FAILED;
2474 * purpose: makes the erp thread continue with reopen (physical) port
2475 * actions which have been paused until the name server port
2476 * is opened (or failed)
2478 * returns: 0 (a kind of void retval, its not used)
2481 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2485 unsigned long flags;
2486 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2487 struct zfcp_erp_action *erp_action, *tmp;
2489 read_lock_irqsave(&adapter->erp_lock, flags);
2490 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2492 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2493 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2495 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2496 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2497 debug_event(adapter->erp_dbf, 3,
2498 &erp_action->port->wwpn, sizeof (wwn_t));
2499 if (atomic_test_mask(
2500 ZFCP_STATUS_COMMON_ERP_FAILED,
2501 &adapter->nameserver_port->status))
2502 zfcp_erp_port_failed(erp_action->port);
2503 zfcp_erp_action_ready(erp_action);
2506 read_unlock_irqrestore(&adapter->erp_lock, flags);
2516 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2517 * ZFCP_ERP_FAILED - action finished unsuccessfully
2520 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2523 struct zfcp_adapter *adapter = erp_action->adapter;
2524 struct zfcp_port *port = erp_action->port;
2526 retval = zfcp_fsf_close_physical_port(erp_action);
2527 if (retval == -ENOMEM) {
2528 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2529 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2530 retval = ZFCP_ERP_NOMEM;
2533 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2535 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2536 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2537 /* could not send 'open', fail */
2538 retval = ZFCP_ERP_FAILED;
2541 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2542 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2543 retval = ZFCP_ERP_CONTINUES;
2549 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2552 struct zfcp_adapter *adapter = port->adapter;
2554 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2555 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2557 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2558 ZFCP_STATUS_COMMON_CLOSING |
2559 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2560 ZFCP_STATUS_PORT_DID_DID |
2561 ZFCP_STATUS_PORT_PHYS_CLOSING |
2562 ZFCP_STATUS_PORT_INVALID_WWPN,
2572 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2573 * ZFCP_ERP_FAILED - action finished unsuccessfully
2576 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2579 struct zfcp_adapter *adapter = erp_action->adapter;
2580 struct zfcp_port *port = erp_action->port;
2582 retval = zfcp_fsf_close_port(erp_action);
2583 if (retval == -ENOMEM) {
2584 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2585 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2586 retval = ZFCP_ERP_NOMEM;
2589 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2591 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2592 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2593 /* could not send 'close', fail */
2594 retval = ZFCP_ERP_FAILED;
2597 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2598 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2599 retval = ZFCP_ERP_CONTINUES;
2609 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2610 * ZFCP_ERP_FAILED - action finished unsuccessfully
2613 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2616 struct zfcp_adapter *adapter = erp_action->adapter;
2617 struct zfcp_port *port = erp_action->port;
2619 retval = zfcp_fsf_open_port(erp_action);
2620 if (retval == -ENOMEM) {
2621 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2622 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2623 retval = ZFCP_ERP_NOMEM;
2626 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2628 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2629 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2630 /* could not send 'open', fail */
2631 retval = ZFCP_ERP_FAILED;
2634 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2635 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2636 retval = ZFCP_ERP_CONTINUES;
2646 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2647 * ZFCP_ERP_FAILED - action finished unsuccessfully
2650 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2653 struct zfcp_adapter *adapter = erp_action->adapter;
2654 struct zfcp_port *port = erp_action->port;
2656 retval = zfcp_ns_gid_pn_request(erp_action);
2657 if (retval == -ENOMEM) {
2658 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2659 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2660 retval = ZFCP_ERP_NOMEM;
2663 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2665 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2666 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2667 /* could not send nameserver request, fail */
2668 retval = ZFCP_ERP_FAILED;
2671 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2672 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2673 retval = ZFCP_ERP_CONTINUES;
2681 * purpose: this routine executes the 'Reopen Unit' action
2682 * currently no retries
2684 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2685 * ZFCP_ERP_SUCCEEDED - action finished successfully
2686 * ZFCP_ERP_FAILED - action finished unsuccessfully
2689 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2691 int retval = ZFCP_ERP_FAILED;
2692 struct zfcp_unit *unit = erp_action->unit;
2693 struct zfcp_adapter *adapter = erp_action->adapter;
2695 switch (erp_action->step) {
2699 * the ULP spec. begs for waiting for oustanding commands
2701 case ZFCP_ERP_STEP_UNINITIALIZED:
2702 zfcp_erp_unit_strategy_clearstati(unit);
2703 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2704 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2705 "trying close\n", unit->fcp_lun);
2706 retval = zfcp_erp_unit_strategy_close(erp_action);
2709 /* else it's already closed, fall through */
2710 case ZFCP_ERP_STEP_UNIT_CLOSING:
2711 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2712 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2714 retval = ZFCP_ERP_FAILED;
2716 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2717 retval = ZFCP_ERP_EXIT;
2719 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2720 "trying open\n", unit->fcp_lun);
2722 zfcp_erp_unit_strategy_open(erp_action);
2727 case ZFCP_ERP_STEP_UNIT_OPENING:
2728 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2729 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2731 retval = ZFCP_ERP_SUCCEEDED;
2733 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2735 retval = ZFCP_ERP_FAILED;
2740 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2741 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2742 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2743 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2748 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2751 struct zfcp_adapter *adapter = unit->port->adapter;
2753 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2754 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2756 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2757 ZFCP_STATUS_COMMON_CLOSING |
2758 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2759 ZFCP_STATUS_UNIT_SHARED |
2760 ZFCP_STATUS_UNIT_READONLY,
2771 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2772 * ZFCP_ERP_FAILED - action finished unsuccessfully
2775 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2778 struct zfcp_adapter *adapter = erp_action->adapter;
2779 struct zfcp_unit *unit = erp_action->unit;
2781 retval = zfcp_fsf_close_unit(erp_action);
2782 if (retval == -ENOMEM) {
2783 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2784 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2785 sizeof (fcp_lun_t));
2786 retval = ZFCP_ERP_NOMEM;
2789 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2791 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2792 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2793 sizeof (fcp_lun_t));
2794 /* could not send 'close', fail */
2795 retval = ZFCP_ERP_FAILED;
2798 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2799 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2800 retval = ZFCP_ERP_CONTINUES;
2811 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2812 * ZFCP_ERP_FAILED - action finished unsuccessfully
2815 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2818 struct zfcp_adapter *adapter = erp_action->adapter;
2819 struct zfcp_unit *unit = erp_action->unit;
2821 retval = zfcp_fsf_open_unit(erp_action);
2822 if (retval == -ENOMEM) {
2823 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2824 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2825 sizeof (fcp_lun_t));
2826 retval = ZFCP_ERP_NOMEM;
2829 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2831 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2832 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2833 sizeof (fcp_lun_t));
2834 /* could not send 'open', fail */
2835 retval = ZFCP_ERP_FAILED;
2838 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2839 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2840 retval = ZFCP_ERP_CONTINUES;
2845 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2847 BUG_ON(!fsf_req->erp_action);
2848 fsf_req->timer.function = zfcp_erp_timeout_handler;
2849 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2850 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2851 add_timer(&fsf_req->timer);
2857 * purpose: enqueue the specified error recovery action, if needed
2862 zfcp_erp_action_enqueue(int action,
2863 struct zfcp_adapter *adapter,
2864 struct zfcp_port *port, struct zfcp_unit *unit)
2867 struct zfcp_erp_action *erp_action = NULL;
2868 int stronger_action = 0;
2872 * We need some rules here which check whether we really need
2873 * this action or whether we should just drop it.
2874 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2875 * 'Reopen Unit' request for an associated unit since we can't
2876 * satisfy this request now. A 'Reopen Port' action will trigger
2877 * 'Reopen Unit' actions when it completes.
2878 * Thus, there are only actions in the queue which can immediately be
2879 * executed. This makes the processing of the action queue more
2883 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2887 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2888 /* check whether we really need this */
2890 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2891 if (atomic_test_mask
2892 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2893 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2894 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2896 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2897 sizeof (fcp_lun_t));
2900 if (!atomic_test_mask
2901 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2903 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2906 if (!atomic_test_mask
2907 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2908 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2911 /* fall through !!! */
2913 case ZFCP_ERP_ACTION_REOPEN_PORT:
2914 if (atomic_test_mask
2915 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2916 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2917 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2921 /* fall through !!! */
2923 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2924 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2926 if (port->erp_action.action !=
2927 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2928 ZFCP_LOG_INFO("dropped erp action %i (port "
2929 "0x%016Lx, action in use: %i)\n",
2931 port->erp_action.action);
2932 debug_text_event(adapter->erp_dbf, 4,
2935 debug_text_event(adapter->erp_dbf, 4,
2937 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2941 if (!atomic_test_mask
2942 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2944 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2947 if (!atomic_test_mask
2948 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
2949 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
2952 /* fall through !!! */
2954 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2955 if (atomic_test_mask
2956 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
2957 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
2963 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
2964 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
2965 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2966 "on adapter %s (action=%d)\n",
2967 zfcp_get_busid_by_adapter(adapter), action);
2971 /* check whether we need something stronger first */
2972 if (stronger_action) {
2973 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
2974 debug_event(adapter->erp_dbf, 4, &stronger_action,
2976 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2977 "erp action %d on adapter %s\n",
2978 stronger_action, action,
2979 zfcp_get_busid_by_adapter(adapter));
2980 action = stronger_action;
2983 /* mark adapter to have some error recovery pending */
2984 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2986 /* setup error recovery action */
2989 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2990 zfcp_unit_get(unit);
2991 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2992 erp_action = &unit->erp_action;
2993 if (!atomic_test_mask
2994 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
2995 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2998 case ZFCP_ERP_ACTION_REOPEN_PORT:
2999 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3000 zfcp_port_get(port);
3001 zfcp_erp_action_dismiss_port(port);
3002 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3003 erp_action = &port->erp_action;
3004 if (!atomic_test_mask
3005 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3006 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3009 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3010 zfcp_adapter_get(adapter);
3011 zfcp_erp_action_dismiss_adapter(adapter);
3012 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3013 erp_action = &adapter->erp_action;
3014 if (!atomic_test_mask
3015 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3016 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3020 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3022 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3023 erp_action->adapter = adapter;
3024 erp_action->port = port;
3025 erp_action->unit = unit;
3026 erp_action->action = action;
3027 erp_action->status = status;
3029 ++adapter->erp_total_count;
3031 /* finally put it into 'ready' queue and kick erp thread */
3032 list_add(&erp_action->list, &adapter->erp_ready_head);
3033 up(&adapter->erp_ready_sem);
3040 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3043 struct zfcp_adapter *adapter = erp_action->adapter;
3045 --adapter->erp_total_count;
3046 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3047 --adapter->erp_low_mem_count;
3048 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3051 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3052 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3053 list_del(&erp_action->list);
3054 switch (erp_action->action) {
3055 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3056 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3057 &erp_action->unit->status);
3059 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3060 case ZFCP_ERP_ACTION_REOPEN_PORT:
3061 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3062 &erp_action->port->status);
3064 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3065 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3066 &erp_action->adapter->status);
3076 * zfcp_erp_action_cleanup
3078 * Register unit with scsi stack if appropriate and fix reference counts.
3079 * Note: Temporary units are not registered with scsi stack.
3082 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3083 struct zfcp_port *port, struct zfcp_unit *unit,
3087 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3088 if ((result == ZFCP_ERP_SUCCEEDED)
3089 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3093 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3095 scsi_scan_target(&port->rport->dev, 0,
3096 port->rport->scsi_target_id,
3099 zfcp_unit_put(unit);
3101 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3102 case ZFCP_ERP_ACTION_REOPEN_PORT:
3103 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3105 zfcp_port_put(port);
3109 if ((result == ZFCP_ERP_SUCCEEDED)
3111 struct fc_rport_identifiers ids;
3112 ids.node_name = port->wwnn;
3113 ids.port_name = port->wwpn;
3114 ids.port_id = port->d_id;
3115 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3117 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3119 ZFCP_LOG_NORMAL("failed registration of rport"
3120 "(adapter %s, wwpn=0x%016Lx)\n",
3121 zfcp_get_busid_by_port(port),
3124 scsi_flush_work(adapter->scsi_host);
3125 port->rport->maxframe_size = port->maxframe_size;
3126 port->rport->supported_classes =
3127 port->supported_classes;
3130 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3131 fc_remote_port_delete(port->rport);
3134 zfcp_port_put(port);
3136 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3137 if (result != ZFCP_ERP_SUCCEEDED) {
3138 list_for_each_entry(port, &adapter->port_list_head, list)
3140 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3142 fc_remote_port_delete(port->rport);
3146 zfcp_adapter_put(adapter);
3154 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3156 struct zfcp_port *port;
3158 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3159 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3160 zfcp_erp_action_dismiss(&adapter->erp_action);
3162 list_for_each_entry(port, &adapter->port_list_head, list)
3163 zfcp_erp_action_dismiss_port(port);
3166 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3168 struct zfcp_unit *unit;
3169 struct zfcp_adapter *adapter = port->adapter;
3171 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3172 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3173 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3174 zfcp_erp_action_dismiss(&port->erp_action);
3176 list_for_each_entry(unit, &port->unit_list_head, list)
3177 zfcp_erp_action_dismiss_unit(unit);
3180 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3182 struct zfcp_adapter *adapter = unit->port->adapter;
3184 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3185 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3186 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3187 zfcp_erp_action_dismiss(&unit->erp_action);
3191 zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3193 struct zfcp_adapter *adapter = erp_action->adapter;
3195 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3196 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3197 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3201 zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3203 struct zfcp_adapter *adapter = erp_action->adapter;
3205 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3206 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3207 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3211 zfcp_erp_port_boxed(struct zfcp_port *port)
3213 struct zfcp_adapter *adapter = port->adapter;
3214 unsigned long flags;
3216 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3217 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3218 read_lock_irqsave(&zfcp_data.config_lock, flags);
3219 zfcp_erp_modify_port_status(port,
3220 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3222 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3223 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3227 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3229 struct zfcp_adapter *adapter = unit->port->adapter;
3231 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3232 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3233 zfcp_erp_modify_unit_status(unit,
3234 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3236 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3240 zfcp_erp_port_access_denied(struct zfcp_port *port)
3242 struct zfcp_adapter *adapter = port->adapter;
3243 unsigned long flags;
3245 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3246 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3247 read_lock_irqsave(&zfcp_data.config_lock, flags);
3248 zfcp_erp_modify_port_status(port,
3249 ZFCP_STATUS_COMMON_ERP_FAILED |
3250 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3252 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3256 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3258 struct zfcp_adapter *adapter = unit->port->adapter;
3260 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3261 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3262 zfcp_erp_modify_unit_status(unit,
3263 ZFCP_STATUS_COMMON_ERP_FAILED |
3264 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3269 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3271 struct zfcp_port *port;
3272 unsigned long flags;
3274 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3277 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3278 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3280 read_lock_irqsave(&zfcp_data.config_lock, flags);
3281 if (adapter->nameserver_port)
3282 zfcp_erp_port_access_changed(adapter->nameserver_port);
3283 list_for_each_entry(port, &adapter->port_list_head, list)
3284 if (port != adapter->nameserver_port)
3285 zfcp_erp_port_access_changed(port);
3286 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3290 zfcp_erp_port_access_changed(struct zfcp_port *port)
3292 struct zfcp_adapter *adapter = port->adapter;
3293 struct zfcp_unit *unit;
3295 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3296 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3298 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3300 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3302 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3303 list_for_each_entry(unit, &port->unit_list_head, list)
3304 zfcp_erp_unit_access_changed(unit);
3308 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3309 "(due to ACT update)\n",
3310 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3311 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3312 ZFCP_LOG_NORMAL("failed reopen of port"
3313 "(adapter %s, wwpn=0x%016Lx)\n",
3314 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3318 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3320 struct zfcp_adapter *adapter = unit->port->adapter;
3322 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3323 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3325 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3327 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3331 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3332 " on adapter %s (due to ACT update)\n",
3333 unit->fcp_lun, unit->port->wwpn,
3334 zfcp_get_busid_by_adapter(adapter));
3335 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3336 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3337 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3338 zfcp_get_busid_by_adapter(adapter),
3339 unit->port->wwpn, unit->fcp_lun);
3342 #undef ZFCP_LOG_AREA