2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
26 static int zfcp_erp_adisc(struct zfcp_port *);
27 static void zfcp_erp_adisc_handler(unsigned long);
29 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
30 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
31 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
32 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
34 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
35 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
37 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
38 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
39 static void zfcp_erp_port_block(struct zfcp_port *, int);
40 static void zfcp_erp_port_unblock(struct zfcp_port *);
41 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
42 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
44 static int zfcp_erp_thread(void *);
46 static int zfcp_erp_strategy(struct zfcp_erp_action *);
48 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
49 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
50 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
51 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
52 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
53 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
54 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
56 struct zfcp_unit *, int);
57 static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
58 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
60 struct zfcp_unit *, int);
61 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
62 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
67 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
68 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
69 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
73 struct zfcp_erp_action *);
75 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
76 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
78 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
79 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
80 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
83 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
84 struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
86 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
87 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
89 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
90 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
91 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
94 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
95 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
96 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
97 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
99 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
100 struct zfcp_port *, struct zfcp_unit *);
101 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
102 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
103 struct zfcp_port *, struct zfcp_unit *,
106 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
107 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
109 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
110 static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
112 static void zfcp_erp_memwait_handler(unsigned long);
115 * zfcp_close_qdio - close qdio queues for an adapter
117 static void zfcp_close_qdio(struct zfcp_adapter *adapter)
119 struct zfcp_qdio_queue *req_queue;
122 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
125 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
126 req_queue = &adapter->request_queue;
127 write_lock_irq(&req_queue->queue_lock);
128 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
129 write_unlock_irq(&req_queue->queue_lock);
131 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
132 while (qdio_shutdown(adapter->ccw_device,
133 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
135 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
137 /* cleanup used outbound sbals */
138 count = atomic_read(&req_queue->free_count);
139 if (count < QDIO_MAX_BUFFERS_PER_Q) {
140 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
141 count = QDIO_MAX_BUFFERS_PER_Q - count;
142 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
144 req_queue->free_index = 0;
145 atomic_set(&req_queue->free_count, 0);
146 req_queue->distance_from_int = 0;
147 adapter->response_queue.free_index = 0;
148 atomic_set(&adapter->response_queue.free_count, 0);
152 * zfcp_close_fsf - stop FSF operations for an adapter
154 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
155 * requests waiting for completion; especially this returns SCSI commands
158 static void zfcp_close_fsf(struct zfcp_adapter *adapter)
160 /* close queues to ensure that buffers are not accessed by adapter */
161 zfcp_close_qdio(adapter);
162 zfcp_fsf_req_dismiss_all(adapter);
163 /* reset FSF request sequence number */
164 adapter->fsf_req_seq_no = 0;
165 /* all ports and units are closed */
166 zfcp_erp_modify_adapter_status(adapter,
167 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
171 * zfcp_fsf_request_timeout_handler - called if a request timed out
172 * @data: pointer to adapter for handler function
174 * This function needs to be called if requests (ELS, Generic Service,
175 * or SCSI commands) exceed a certain time limit. The assumption is
176 * that after the time limit the adapter get stuck. So we trigger a reopen of
179 static void zfcp_fsf_request_timeout_handler(unsigned long data)
181 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
182 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
185 void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
187 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
188 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
189 fsf_req->timer.expires = jiffies + timeout;
190 add_timer(&fsf_req->timer);
196 * purpose: called if an adapter failed,
197 * initiates adapter recovery which is done
200 * returns: 0 - initiated action successfully
201 * <0 - failed to initiate action
204 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
208 debug_text_event(adapter->erp_dbf, 5, "a_ro");
209 ZFCP_LOG_DEBUG("reopen adapter %s\n",
210 zfcp_get_busid_by_adapter(adapter));
212 zfcp_erp_adapter_block(adapter, clear_mask);
214 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
215 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
216 zfcp_get_busid_by_adapter(adapter));
217 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
218 /* ensure propagation of failed status to new devices */
219 zfcp_erp_adapter_failed(adapter);
223 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
224 adapter, NULL, NULL);
233 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
234 * used to ensure the correct locking
236 * returns: 0 - initiated action successfully
237 * <0 - failed to initiate action
240 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
245 read_lock_irqsave(&zfcp_data.config_lock, flags);
246 write_lock(&adapter->erp_lock);
247 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
248 write_unlock(&adapter->erp_lock);
249 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
255 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
259 retval = zfcp_erp_adapter_reopen(adapter,
260 ZFCP_STATUS_COMMON_RUNNING |
261 ZFCP_STATUS_COMMON_ERP_FAILED |
268 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
272 retval = zfcp_erp_port_reopen(port,
273 ZFCP_STATUS_COMMON_RUNNING |
274 ZFCP_STATUS_COMMON_ERP_FAILED |
281 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
285 retval = zfcp_erp_unit_reopen(unit,
286 ZFCP_STATUS_COMMON_RUNNING |
287 ZFCP_STATUS_COMMON_ERP_FAILED |
295 * zfcp_erp_adisc - send ADISC ELS command
296 * @port: port structure
299 zfcp_erp_adisc(struct zfcp_port *port)
301 struct zfcp_adapter *adapter = port->adapter;
302 struct zfcp_send_els *send_els;
303 struct zfcp_ls_adisc *adisc;
304 void *address = NULL;
307 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
308 if (send_els == NULL)
311 send_els->req = 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%06x to d_id 0x%06x "
346 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
347 "hard_nport_id=0x%06x, nport_id=0x%06x)\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%06x 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%06x)\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%06x to s_id "
415 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
416 "hard_nport_id=0x%06x, nport_id=0x%06x)\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_find(adapter, erp_action->fsf_req->req_id)) {
851 /* fsf_req still exists */
852 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
853 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
854 sizeof (unsigned long));
855 /* dismiss fsf_req of timed out/dismissed erp_action */
856 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
857 ZFCP_STATUS_ERP_TIMEDOUT)) {
858 debug_text_event(adapter->erp_dbf, 3,
860 erp_action->fsf_req->status |=
861 ZFCP_STATUS_FSFREQ_DISMISSED;
863 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
864 ZFCP_LOG_NORMAL("error: erp step timed out "
865 "(action=%d, fsf_req=%p)\n ",
867 erp_action->fsf_req);
870 * If fsf_req is neither dismissed nor completed
871 * then keep it running asynchronously and don't mess
872 * with the association of erp_action and fsf_req.
874 if (erp_action->fsf_req->status &
875 (ZFCP_STATUS_FSFREQ_COMPLETED |
876 ZFCP_STATUS_FSFREQ_DISMISSED)) {
877 /* forget about association between fsf_req
879 erp_action->fsf_req = NULL;
882 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
884 * even if this fsf_req has gone, forget about
885 * association between erp_action and fsf_req
887 erp_action->fsf_req = NULL;
889 spin_unlock(&adapter->req_list_lock);
891 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
895 * zfcp_erp_async_handler_nolock - complete erp_action
897 * Used for normal completion, time-out, dismissal and failure after
898 * low memory condition.
900 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
901 unsigned long set_mask)
903 struct zfcp_adapter *adapter = erp_action->adapter;
905 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
906 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
907 debug_event(adapter->erp_dbf, 2, &erp_action->action,
909 erp_action->status |= set_mask;
910 zfcp_erp_action_ready(erp_action);
912 /* action is ready or gone - nothing to do */
913 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
914 debug_event(adapter->erp_dbf, 3, &erp_action->action,
920 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
922 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
923 unsigned long set_mask)
925 struct zfcp_adapter *adapter = erp_action->adapter;
928 write_lock_irqsave(&adapter->erp_lock, flags);
929 zfcp_erp_async_handler_nolock(erp_action, set_mask);
930 write_unlock_irqrestore(&adapter->erp_lock, flags);
934 * purpose: is called for erp_action which was slept waiting for
935 * memory becoming avaliable,
936 * will trigger that this action will be continued
939 zfcp_erp_memwait_handler(unsigned long data)
941 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
942 struct zfcp_adapter *adapter = erp_action->adapter;
944 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
945 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
947 zfcp_erp_async_handler(erp_action, 0);
951 * purpose: is called if an asynchronous erp step timed out,
952 * action gets an appropriate flag and will be processed
955 static void zfcp_erp_timeout_handler(unsigned long data)
957 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
958 struct zfcp_adapter *adapter = erp_action->adapter;
960 debug_text_event(adapter->erp_dbf, 2, "a_th");
961 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
963 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
967 * zfcp_erp_action_dismiss - dismiss an erp_action
969 * adapter->erp_lock must be held
971 * Dismissal of an erp_action is usually required if an erp_action of
972 * higher priority is generated.
974 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
976 struct zfcp_adapter *adapter = erp_action->adapter;
978 debug_text_event(adapter->erp_dbf, 2, "a_adis");
979 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
981 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
985 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
989 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
991 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
993 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
995 zfcp_get_busid_by_adapter(adapter));
996 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
998 wait_event(adapter->erp_thread_wqh,
999 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1001 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1004 return (retval < 0);
1014 * context: process (i.e. proc-fs or rmmod/insmod)
1016 * note: The caller of this routine ensures that the specified
1017 * adapter has been shut down and that this operation
1018 * has been completed. Thus, there are no pending erp_actions
1019 * which would need to be handled here.
1022 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1026 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1027 up(&adapter->erp_ready_sem);
1029 wait_event(adapter->erp_thread_wqh,
1030 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1033 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1036 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1042 * purpose: is run as a kernel thread,
1043 * goes through list of error recovery actions of associated adapter
1044 * and delegates single action to execution
1049 zfcp_erp_thread(void *data)
1051 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1052 struct list_head *next;
1053 struct zfcp_erp_action *erp_action;
1054 unsigned long flags;
1056 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1057 /* Block all signals */
1058 siginitsetinv(¤t->blocked, 0);
1059 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1060 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1061 wake_up(&adapter->erp_thread_wqh);
1063 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1064 &adapter->status)) {
1066 write_lock_irqsave(&adapter->erp_lock, flags);
1067 next = adapter->erp_ready_head.prev;
1068 write_unlock_irqrestore(&adapter->erp_lock, flags);
1070 if (next != &adapter->erp_ready_head) {
1072 list_entry(next, struct zfcp_erp_action, list);
1074 * process action (incl. [re]moving it
1075 * from 'ready' queue)
1077 zfcp_erp_strategy(erp_action);
1081 * sleep as long as there is nothing to do, i.e.
1082 * no action in 'ready' queue to be processed and
1083 * thread is not to be killed
1085 down_interruptible(&adapter->erp_ready_sem);
1086 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1089 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1090 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1091 wake_up(&adapter->erp_thread_wqh);
1099 * purpose: drives single error recovery action and schedules higher and
1100 * subordinate actions, if necessary
1102 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1103 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1104 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1105 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1106 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1109 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1112 struct zfcp_adapter *adapter = erp_action->adapter;
1113 struct zfcp_port *port = erp_action->port;
1114 struct zfcp_unit *unit = erp_action->unit;
1115 int action = erp_action->action;
1116 u32 status = erp_action->status;
1117 unsigned long flags;
1119 /* serialise dismissing, timing out, moving, enqueueing */
1120 read_lock_irqsave(&zfcp_data.config_lock, flags);
1121 write_lock(&adapter->erp_lock);
1123 /* dequeue dismissed action and leave, if required */
1124 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1125 if (retval == ZFCP_ERP_DISMISSED) {
1126 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1131 * move action to 'running' queue before processing it
1132 * (to avoid a race condition regarding moving the
1133 * action to the 'running' queue and back)
1135 zfcp_erp_action_to_running(erp_action);
1138 * try to process action as far as possible,
1139 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1140 * afterwards the lock is required again for the following reasons:
1141 * - dequeueing of finished action and enqueueing of
1142 * follow-up actions must be atomic so that any other
1143 * reopen-routine does not believe there is nothing to do
1144 * and that it is safe to enqueue something else,
1145 * - we want to force any control thread which is dismissing
1146 * actions to finish this before we decide about
1147 * necessary steps to be taken here further
1149 write_unlock(&adapter->erp_lock);
1150 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1151 retval = zfcp_erp_strategy_do_action(erp_action);
1152 read_lock_irqsave(&zfcp_data.config_lock, flags);
1153 write_lock(&adapter->erp_lock);
1156 * check for dismissed status again to avoid follow-up actions,
1157 * failing of targets and so on for dismissed actions
1159 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1162 case ZFCP_ERP_DISMISSED:
1163 /* leave since this action has ridden to its ancestors */
1164 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1166 case ZFCP_ERP_NOMEM:
1167 /* no memory to continue immediately, let it sleep */
1168 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1169 ++adapter->erp_low_mem_count;
1170 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1172 /* This condition is true if there is no memory available
1173 for any erp_action on this adapter. This implies that there
1174 are no elements in the memory pool(s) left for erp_actions.
1175 This might happen if an erp_action that used a memory pool
1176 element was timed out.
1178 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1179 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1180 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1181 "restarting I/O on adapter %s "
1182 "to free mempool\n",
1183 zfcp_get_busid_by_adapter(adapter));
1184 zfcp_erp_adapter_reopen_internal(adapter, 0);
1186 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1187 retval = zfcp_erp_strategy_memwait(erp_action);
1190 case ZFCP_ERP_CONTINUES:
1191 /* leave since this action runs asynchronously */
1192 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1193 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1194 --adapter->erp_low_mem_count;
1195 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1199 /* ok, finished action (whatever its result is) */
1201 /* check for unrecoverable targets */
1202 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1204 /* action must be dequeued (here to allow for further ones) */
1205 zfcp_erp_action_dequeue(erp_action);
1208 * put this target through the erp mill again if someone has
1209 * requested to change the status of a target being online
1210 * to offline or the other way around
1211 * (old retval is preserved if nothing has to be done here)
1213 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1214 port, unit, retval);
1217 * leave if target is in permanent error state or if
1218 * action is repeated in order to process state change
1220 if (retval == ZFCP_ERP_EXIT) {
1221 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1225 /* trigger follow up actions */
1226 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1229 write_unlock(&adapter->erp_lock);
1230 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1232 if (retval != ZFCP_ERP_CONTINUES)
1233 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1236 * a few tasks remain when the erp queues are empty
1237 * (don't do that if the last action evaluated was dismissed
1238 * since this clearly indicates that there is more to come) :
1239 * - close the name server port if it is open yet
1240 * (enqueues another [probably] final action)
1241 * - otherwise, wake up whoever wants to be woken when we are
1244 if (retval != ZFCP_ERP_DISMISSED)
1245 zfcp_erp_strategy_check_queues(adapter);
1247 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1257 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1258 * retval - otherwise
1261 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1263 struct zfcp_adapter *adapter = erp_action->adapter;
1265 zfcp_erp_strategy_check_fsfreq(erp_action);
1267 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1268 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1269 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1270 zfcp_erp_action_dequeue(erp_action);
1271 retval = ZFCP_ERP_DISMISSED;
1273 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1279 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1281 int retval = ZFCP_ERP_FAILED;
1282 struct zfcp_adapter *adapter = erp_action->adapter;
1285 * try to execute/continue action as far as possible,
1286 * note: no lock in subsequent strategy routines
1287 * (this allows these routine to call schedule, e.g.
1288 * kmalloc with such flags or qdio_initialize & friends)
1289 * Note: in case of timeout, the seperate strategies will fail
1290 * anyhow. No need for a special action. Even worse, a nameserver
1291 * failure would not wake up waiting ports without the call.
1293 switch (erp_action->action) {
1295 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1296 retval = zfcp_erp_adapter_strategy(erp_action);
1299 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1300 retval = zfcp_erp_port_forced_strategy(erp_action);
1303 case ZFCP_ERP_ACTION_REOPEN_PORT:
1304 retval = zfcp_erp_port_strategy(erp_action);
1307 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1308 retval = zfcp_erp_unit_strategy(erp_action);
1312 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1313 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1315 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1316 "adapter %s (action=%d)\n",
1317 zfcp_get_busid_by_adapter(erp_action->adapter),
1318 erp_action->action);
1327 * purpose: triggers retry of this action after a certain amount of time
1328 * by means of timer provided by erp_action
1330 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1333 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1335 int retval = ZFCP_ERP_CONTINUES;
1336 struct zfcp_adapter *adapter = erp_action->adapter;
1338 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1339 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1340 init_timer(&erp_action->timer);
1341 erp_action->timer.function = zfcp_erp_memwait_handler;
1342 erp_action->timer.data = (unsigned long) erp_action;
1343 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1344 add_timer(&erp_action->timer);
1350 * function: zfcp_erp_adapter_failed
1352 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1356 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1358 zfcp_erp_modify_adapter_status(adapter,
1359 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1360 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1361 zfcp_get_busid_by_adapter(adapter));
1362 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1366 * function: zfcp_erp_port_failed
1368 * purpose: sets the port and all underlying devices to ERP_FAILED
1372 zfcp_erp_port_failed(struct zfcp_port *port)
1374 zfcp_erp_modify_port_status(port,
1375 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1377 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1378 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1379 "port d_id=0x%06x)\n",
1380 zfcp_get_busid_by_port(port), port->d_id);
1382 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1383 zfcp_get_busid_by_port(port), port->wwpn);
1385 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1386 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1390 * function: zfcp_erp_unit_failed
1392 * purpose: sets the unit to ERP_FAILED
1396 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1398 zfcp_erp_modify_unit_status(unit,
1399 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1401 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1402 " on adapter %s\n", unit->fcp_lun,
1403 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1404 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1405 debug_event(unit->port->adapter->erp_dbf, 2,
1406 &unit->fcp_lun, sizeof (fcp_lun_t));
1410 * function: zfcp_erp_strategy_check_target
1412 * purpose: increments the erp action count on the device currently in
1413 * recovery if the action failed or resets the count in case of
1414 * success. If a maximum count is exceeded the device is marked
1416 * The 'blocked' state of a target which has been recovered
1417 * successfully is reset.
1419 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1420 * ZFCP_ERP_SUCCEEDED - action finished successfully
1421 * ZFCP_ERP_EXIT - action failed and will not continue
1424 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1426 struct zfcp_adapter *adapter = erp_action->adapter;
1427 struct zfcp_port *port = erp_action->port;
1428 struct zfcp_unit *unit = erp_action->unit;
1430 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1431 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1432 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1434 switch (erp_action->action) {
1436 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1437 result = zfcp_erp_strategy_check_unit(unit, result);
1440 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1441 case ZFCP_ERP_ACTION_REOPEN_PORT:
1442 result = zfcp_erp_strategy_check_port(port, result);
1445 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1446 result = zfcp_erp_strategy_check_adapter(adapter, result);
1454 zfcp_erp_strategy_statechange(int action,
1456 struct zfcp_adapter *adapter,
1457 struct zfcp_port *port,
1458 struct zfcp_unit *unit, int retval)
1460 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1461 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1465 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1466 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1468 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1469 retval = ZFCP_ERP_EXIT;
1473 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1474 case ZFCP_ERP_ACTION_REOPEN_PORT:
1475 if (zfcp_erp_strategy_statechange_detected(&port->status,
1477 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1478 retval = ZFCP_ERP_EXIT;
1482 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1483 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1485 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1486 retval = ZFCP_ERP_EXIT;
1495 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1498 /* take it online */
1499 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1500 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1501 /* take it offline */
1502 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1503 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1507 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1509 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1510 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1511 sizeof (fcp_lun_t));
1514 case ZFCP_ERP_SUCCEEDED :
1515 atomic_set(&unit->erp_counter, 0);
1516 zfcp_erp_unit_unblock(unit);
1518 case ZFCP_ERP_FAILED :
1519 atomic_inc(&unit->erp_counter);
1520 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1521 zfcp_erp_unit_failed(unit);
1523 case ZFCP_ERP_EXIT :
1528 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1529 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1530 result = ZFCP_ERP_EXIT;
1537 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1539 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1540 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1543 case ZFCP_ERP_SUCCEEDED :
1544 atomic_set(&port->erp_counter, 0);
1545 zfcp_erp_port_unblock(port);
1547 case ZFCP_ERP_FAILED :
1548 atomic_inc(&port->erp_counter);
1549 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1550 zfcp_erp_port_failed(port);
1552 case ZFCP_ERP_EXIT :
1557 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1558 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1559 result = ZFCP_ERP_EXIT;
1566 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1568 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1571 case ZFCP_ERP_SUCCEEDED :
1572 atomic_set(&adapter->erp_counter, 0);
1573 zfcp_erp_adapter_unblock(adapter);
1575 case ZFCP_ERP_FAILED :
1576 atomic_inc(&adapter->erp_counter);
1577 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1578 zfcp_erp_adapter_failed(adapter);
1580 case ZFCP_ERP_EXIT :
1585 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1586 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1587 result = ZFCP_ERP_EXIT;
1593 struct zfcp_erp_add_work {
1594 struct zfcp_unit *unit;
1595 struct work_struct work;
1599 * zfcp_erp_scsi_scan
1600 * @data: pointer to a struct zfcp_erp_add_work
1602 * Registers a logical unit with the SCSI stack.
1604 static void zfcp_erp_scsi_scan(struct work_struct *work)
1606 struct zfcp_erp_add_work *p =
1607 container_of(work, struct zfcp_erp_add_work, work);
1608 struct zfcp_unit *unit = p->unit;
1609 struct fc_rport *rport = unit->port->rport;
1610 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1612 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1613 wake_up(&unit->scsi_scan_wq);
1614 zfcp_unit_put(unit);
1619 * zfcp_erp_schedule_work
1620 * @unit: pointer to unit which should be registered with SCSI stack
1622 * Schedules work which registers a unit with the SCSI stack
1625 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1627 struct zfcp_erp_add_work *p;
1629 p = kzalloc(sizeof(*p), GFP_KERNEL);
1631 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1632 "the FCP-LUN 0x%Lx connected to "
1633 "the port with WWPN 0x%Lx connected to "
1634 "the adapter %s with the SCSI stack.\n",
1637 zfcp_get_busid_by_unit(unit));
1641 zfcp_unit_get(unit);
1642 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1643 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1645 schedule_work(&p->work);
1651 * purpose: remaining things in good cases,
1652 * escalation in bad cases
1657 zfcp_erp_strategy_followup_actions(int action,
1658 struct zfcp_adapter *adapter,
1659 struct zfcp_port *port,
1660 struct zfcp_unit *unit, int status)
1662 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1663 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1665 /* initiate follow-up actions depending on success of finished action */
1668 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1669 if (status == ZFCP_ERP_SUCCEEDED)
1670 zfcp_erp_port_reopen_all_internal(adapter, 0);
1672 zfcp_erp_adapter_reopen_internal(adapter, 0);
1675 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1676 if (status == ZFCP_ERP_SUCCEEDED)
1677 zfcp_erp_port_reopen_internal(port, 0);
1679 zfcp_erp_adapter_reopen_internal(adapter, 0);
1682 case ZFCP_ERP_ACTION_REOPEN_PORT:
1683 if (status == ZFCP_ERP_SUCCEEDED)
1684 zfcp_erp_unit_reopen_all_internal(port, 0);
1686 zfcp_erp_port_forced_reopen_internal(port, 0);
1689 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1690 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1691 if (status != ZFCP_ERP_SUCCEEDED)
1692 zfcp_erp_port_reopen_internal(unit->port, 0);
1700 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1702 unsigned long flags;
1704 read_lock_irqsave(&zfcp_data.config_lock, flags);
1705 read_lock(&adapter->erp_lock);
1706 if (list_empty(&adapter->erp_ready_head) &&
1707 list_empty(&adapter->erp_running_head)) {
1708 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1709 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1711 wake_up(&adapter->erp_done_wqh);
1713 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1714 read_unlock(&adapter->erp_lock);
1715 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1721 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1722 * @adapter: adapter for which to wait for completion of its error recovery
1726 zfcp_erp_wait(struct zfcp_adapter *adapter)
1730 wait_event(adapter->erp_done_wqh,
1731 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1738 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1739 u32 mask, int set_or_clear)
1741 struct zfcp_port *port;
1742 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1744 if (set_or_clear == ZFCP_SET) {
1745 atomic_set_mask(mask, &adapter->status);
1746 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1748 atomic_clear_mask(mask, &adapter->status);
1749 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1750 atomic_set(&adapter->erp_counter, 0);
1751 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1753 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1755 /* Deal with all underlying devices, only pass common_mask */
1757 list_for_each_entry(port, &adapter->port_list_head, list)
1758 zfcp_erp_modify_port_status(port, common_mask,
1763 * function: zfcp_erp_modify_port_status
1765 * purpose: sets the port and all underlying devices to ERP_FAILED
1769 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1771 struct zfcp_unit *unit;
1772 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1774 if (set_or_clear == ZFCP_SET) {
1775 atomic_set_mask(mask, &port->status);
1776 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1778 atomic_clear_mask(mask, &port->status);
1779 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1780 atomic_set(&port->erp_counter, 0);
1781 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1783 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1784 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1786 /* Modify status of all underlying devices, only pass common mask */
1788 list_for_each_entry(unit, &port->unit_list_head, list)
1789 zfcp_erp_modify_unit_status(unit, common_mask,
1794 * function: zfcp_erp_modify_unit_status
1796 * purpose: sets the unit to ERP_FAILED
1800 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1802 if (set_or_clear == ZFCP_SET) {
1803 atomic_set_mask(mask, &unit->status);
1804 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1806 atomic_clear_mask(mask, &unit->status);
1807 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1808 atomic_set(&unit->erp_counter, 0);
1810 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1812 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1813 sizeof (fcp_lun_t));
1814 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1820 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1821 * used to ensure the correct locking
1823 * returns: 0 - initiated action successfully
1824 * <0 - failed to initiate action
1827 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1830 unsigned long flags;
1832 read_lock_irqsave(&zfcp_data.config_lock, flags);
1833 write_lock(&adapter->erp_lock);
1834 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1835 write_unlock(&adapter->erp_lock);
1836 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1842 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1845 struct zfcp_port *port;
1847 list_for_each_entry(port, &adapter->port_list_head, list)
1848 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1849 zfcp_erp_port_reopen_internal(port, clear_mask);
1862 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1865 struct zfcp_unit *unit;
1867 list_for_each_entry(unit, &port->unit_list_head, list)
1868 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1876 * purpose: this routine executes the 'Reopen Adapter' action
1877 * (the entire action is processed synchronously, since
1878 * there are no actions which might be run concurrently
1881 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1882 * ZFCP_ERP_FAILED - action finished unsuccessfully
1885 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1888 struct zfcp_adapter *adapter = erp_action->adapter;
1890 retval = zfcp_erp_adapter_strategy_close(erp_action);
1891 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1892 retval = ZFCP_ERP_EXIT;
1894 retval = zfcp_erp_adapter_strategy_open(erp_action);
1896 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1897 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1898 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1900 if (retval == ZFCP_ERP_FAILED) {
1901 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1902 "to recover itself\n",
1903 zfcp_get_busid_by_adapter(adapter));
1904 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1915 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1916 * ZFCP_ERP_FAILED - action finished unsuccessfully
1919 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1923 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1924 &erp_action->adapter->status);
1925 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1926 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1927 &erp_action->adapter->status);
1937 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1938 * ZFCP_ERP_FAILED - action finished unsuccessfully
1941 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1945 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1946 &erp_action->adapter->status);
1947 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1948 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1949 &erp_action->adapter->status);
1955 * function: zfcp_register_adapter
1957 * purpose: allocate the irq associated with this devno and register
1958 * the FSF adapter with the SCSI stack
1963 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1965 int retval = ZFCP_ERP_SUCCEEDED;
1970 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1971 if (retval != ZFCP_ERP_SUCCEEDED)
1974 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1975 if (retval != ZFCP_ERP_SUCCEEDED)
1976 goto failed_openfcp;
1978 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1982 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1983 &erp_action->adapter->status);
1986 zfcp_close_fsf(erp_action->adapter);
1988 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1989 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1990 ZFCP_STATUS_ADAPTER_XPORT_OK,
1991 &erp_action->adapter->status);
1997 * function: zfcp_qdio_init
1999 * purpose: setup QDIO operation for specified adapter
2001 * returns: 0 - successful setup
2005 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2009 volatile struct qdio_buffer_element *sbale;
2010 struct zfcp_adapter *adapter = erp_action->adapter;
2012 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2013 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2015 zfcp_get_busid_by_adapter(adapter));
2019 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2020 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2022 zfcp_get_busid_by_adapter(adapter));
2023 goto failed_qdio_establish;
2025 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2027 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2028 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2030 zfcp_get_busid_by_adapter(adapter));
2031 goto failed_qdio_activate;
2033 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2036 * put buffers into response queue,
2038 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2039 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2041 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2045 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2046 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2047 zfcp_get_busid_by_adapter(adapter),
2048 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2050 retval = do_QDIO(adapter->ccw_device,
2051 QDIO_FLAG_SYNC_INPUT,
2052 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2055 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2057 goto failed_do_qdio;
2059 adapter->response_queue.free_index = 0;
2060 atomic_set(&adapter->response_queue.free_count, 0);
2061 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2062 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2064 /* set index of first avalable SBALS / number of available SBALS */
2065 adapter->request_queue.free_index = 0;
2066 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2067 adapter->request_queue.distance_from_int = 0;
2069 /* initialize waitqueue used to wait for free SBALs in requests queue */
2070 init_waitqueue_head(&adapter->request_wq);
2072 /* ok, we did it - skip all cleanups for different failures */
2073 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2074 retval = ZFCP_ERP_SUCCEEDED;
2080 failed_qdio_activate:
2081 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2082 while (qdio_shutdown(adapter->ccw_device,
2083 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2085 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2087 failed_qdio_establish:
2089 retval = ZFCP_ERP_FAILED;
2097 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2101 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2102 if (retval == ZFCP_ERP_FAILED)
2103 return ZFCP_ERP_FAILED;
2105 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2106 if (retval == ZFCP_ERP_FAILED)
2107 return ZFCP_ERP_FAILED;
2109 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2113 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2115 int retval = ZFCP_ERP_SUCCEEDED;
2117 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2118 struct zfcp_adapter *adapter = erp_action->adapter;
2120 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2122 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2123 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2125 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2126 write_lock_irq(&adapter->erp_lock);
2127 zfcp_erp_action_to_running(erp_action);
2128 write_unlock_irq(&adapter->erp_lock);
2129 if (zfcp_fsf_exchange_config_data(erp_action)) {
2130 retval = ZFCP_ERP_FAILED;
2131 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2132 ZFCP_LOG_INFO("error: initiation of exchange of "
2133 "configuration data failed for "
2135 zfcp_get_busid_by_adapter(adapter));
2138 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2139 ZFCP_LOG_DEBUG("Xchange underway\n");
2143 * Both the normal completion handler as well as the timeout
2144 * handler will do an 'up' when the 'exchange config data'
2145 * request completes or times out. Thus, the signal to go on
2146 * won't be lost utilizing this semaphore.
2147 * Furthermore, this 'adapter_reopen' action is
2148 * guaranteed to be the only action being there (highest action
2149 * which prevents other actions from being created).
2150 * Resulting from that, the wake signal recognized here
2151 * _must_ be the one belonging to the 'exchange config
2154 down(&adapter->erp_ready_sem);
2155 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2156 ZFCP_LOG_INFO("error: exchange of configuration data "
2157 "for adapter %s timed out\n",
2158 zfcp_get_busid_by_adapter(adapter));
2162 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2166 ZFCP_LOG_DEBUG("host connection still initialising... "
2167 "waiting and retrying...\n");
2168 /* sleep a little bit before retry */
2169 msleep(jiffies_to_msecs(sleep));
2173 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2176 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2177 &adapter->status)) {
2178 ZFCP_LOG_INFO("error: exchange of configuration data for "
2179 "adapter %s failed\n",
2180 zfcp_get_busid_by_adapter(adapter));
2181 retval = ZFCP_ERP_FAILED;
2188 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2191 struct zfcp_adapter *adapter;
2193 adapter = erp_action->adapter;
2194 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2196 write_lock_irq(&adapter->erp_lock);
2197 zfcp_erp_action_to_running(erp_action);
2198 write_unlock_irq(&adapter->erp_lock);
2200 ret = zfcp_fsf_exchange_port_data(erp_action);
2201 if (ret == -EOPNOTSUPP) {
2202 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2203 return ZFCP_ERP_SUCCEEDED;
2205 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2206 return ZFCP_ERP_FAILED;
2208 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2210 ret = ZFCP_ERP_SUCCEEDED;
2211 down(&adapter->erp_ready_sem);
2212 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2213 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2214 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2215 ret = ZFCP_ERP_FAILED;
2218 /* don't treat as error for the sake of compatibility */
2219 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2220 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2221 "%s\n", zfcp_get_busid_by_adapter(adapter));
2227 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2230 int retval = ZFCP_ERP_SUCCEEDED;
2232 struct zfcp_adapter *adapter = erp_action->adapter;
2235 adapter->status_read_failed = 0;
2236 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2237 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2239 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2240 "notification failed on adapter %s\n",
2241 zfcp_get_busid_by_adapter(adapter));
2242 retval = ZFCP_ERP_FAILED;
2254 * purpose: this routine executes the 'Reopen Physical 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_forced_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);
2276 * it would be sufficient to test only the normal open flag
2277 * since the phys. open flag cannot be set if the normal
2278 * open flag is unset - however, this is for readabilty ...
2280 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2281 ZFCP_STATUS_COMMON_OPEN),
2283 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2284 "close physical\n", port->wwpn);
2286 zfcp_erp_port_forced_strategy_close(erp_action);
2288 retval = ZFCP_ERP_FAILED;
2291 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2292 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2294 ZFCP_LOG_DEBUG("close physical failed for port "
2295 "0x%016Lx\n", port->wwpn);
2296 retval = ZFCP_ERP_FAILED;
2298 retval = ZFCP_ERP_SUCCEEDED;
2302 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2303 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2304 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2305 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2313 * purpose: this routine executes the 'Reopen Port' action
2315 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2316 * ZFCP_ERP_SUCCEEDED - action finished successfully
2317 * ZFCP_ERP_FAILED - action finished unsuccessfully
2320 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2322 int retval = ZFCP_ERP_FAILED;
2323 struct zfcp_port *port = erp_action->port;
2324 struct zfcp_adapter *adapter = erp_action->adapter;
2326 switch (erp_action->step) {
2330 * the ULP spec. begs for waiting for oustanding commands
2332 case ZFCP_ERP_STEP_UNINITIALIZED:
2333 zfcp_erp_port_strategy_clearstati(port);
2334 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2335 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2336 "close\n", port->wwpn);
2337 retval = zfcp_erp_port_strategy_close(erp_action);
2339 } /* else it's already closed, open it */
2342 case ZFCP_ERP_STEP_PORT_CLOSING:
2343 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2344 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2346 retval = ZFCP_ERP_FAILED;
2348 } /* else it's closed now, open it */
2351 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2352 retval = ZFCP_ERP_EXIT;
2354 retval = zfcp_erp_port_strategy_open(erp_action);
2357 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2358 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2359 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2360 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2366 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2370 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2371 &erp_action->port->status))
2372 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2374 retval = zfcp_erp_port_strategy_open_common(erp_action);
2380 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2383 struct zfcp_adapter *adapter = erp_action->adapter;
2384 struct zfcp_port *port = erp_action->port;
2386 switch (erp_action->step) {
2388 case ZFCP_ERP_STEP_UNINITIALIZED:
2389 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2390 case ZFCP_ERP_STEP_PORT_CLOSING:
2391 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2392 if (port->wwpn != adapter->peer_wwpn) {
2393 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2394 "on adapter %s.\nPeer WWPN "
2395 "0x%016Lx does not match\n",
2397 zfcp_get_busid_by_adapter(adapter),
2398 adapter->peer_wwpn);
2399 zfcp_erp_port_failed(port);
2400 retval = ZFCP_ERP_FAILED;
2403 port->d_id = adapter->peer_d_id;
2404 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2405 retval = zfcp_erp_port_strategy_open_port(erp_action);
2408 if (!(adapter->nameserver_port)) {
2409 retval = zfcp_nameserver_enqueue(adapter);
2411 ZFCP_LOG_NORMAL("error: nameserver port "
2412 "unavailable for adapter %s\n",
2413 zfcp_get_busid_by_adapter(adapter));
2414 retval = ZFCP_ERP_FAILED;
2418 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2419 &adapter->nameserver_port->status)) {
2420 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2421 "nameserver port\n");
2422 /* nameserver port may live again */
2423 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2424 &adapter->nameserver_port->status);
2425 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2428 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2429 retval = ZFCP_ERP_CONTINUES;
2431 retval = ZFCP_ERP_FAILED;
2434 /* else nameserver port is already open, fall through */
2435 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2436 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2437 &adapter->nameserver_port->status)) {
2438 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2439 retval = ZFCP_ERP_FAILED;
2441 ZFCP_LOG_DEBUG("nameserver port is open -> "
2442 "nameserver look-up for port 0x%016Lx\n",
2444 retval = zfcp_erp_port_strategy_open_common_lookup
2449 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2450 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2451 if (atomic_test_mask
2452 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2453 ZFCP_LOG_DEBUG("nameserver look-up failed "
2454 "for port 0x%016Lx "
2455 "(misconfigured WWPN?)\n",
2457 zfcp_erp_port_failed(port);
2458 retval = ZFCP_ERP_EXIT;
2460 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2461 "port 0x%016Lx\n", port->wwpn);
2462 retval = ZFCP_ERP_FAILED;
2465 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2466 "trying open\n", port->wwpn, port->d_id);
2467 retval = zfcp_erp_port_strategy_open_port(erp_action);
2471 case ZFCP_ERP_STEP_PORT_OPENING:
2472 /* D_ID might have changed during open */
2473 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2474 ZFCP_STATUS_PORT_DID_DID),
2476 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2477 retval = ZFCP_ERP_SUCCEEDED;
2479 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2481 retval = ZFCP_ERP_FAILED;
2486 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2488 retval = ZFCP_ERP_FAILED;
2495 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2498 struct zfcp_port *port = erp_action->port;
2500 switch (erp_action->step) {
2502 case ZFCP_ERP_STEP_UNINITIALIZED:
2503 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2504 case ZFCP_ERP_STEP_PORT_CLOSING:
2505 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2506 port->wwpn, port->d_id);
2507 retval = zfcp_erp_port_strategy_open_port(erp_action);
2510 case ZFCP_ERP_STEP_PORT_OPENING:
2511 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2512 ZFCP_LOG_DEBUG("WKA port is open\n");
2513 retval = ZFCP_ERP_SUCCEEDED;
2515 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2516 retval = ZFCP_ERP_FAILED;
2518 /* this is needed anyway (dont care for retval of wakeup) */
2519 ZFCP_LOG_DEBUG("continue other open port operations\n");
2520 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2524 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2526 retval = ZFCP_ERP_FAILED;
2535 * purpose: makes the erp thread continue with reopen (physical) port
2536 * actions which have been paused until the name server port
2537 * is opened (or failed)
2539 * returns: 0 (a kind of void retval, its not used)
2542 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2546 unsigned long flags;
2547 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2548 struct zfcp_erp_action *erp_action, *tmp;
2550 read_lock_irqsave(&adapter->erp_lock, flags);
2551 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2553 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2554 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2556 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2557 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2558 debug_event(adapter->erp_dbf, 3,
2559 &erp_action->port->wwpn, sizeof (wwn_t));
2560 if (atomic_test_mask(
2561 ZFCP_STATUS_COMMON_ERP_FAILED,
2562 &adapter->nameserver_port->status))
2563 zfcp_erp_port_failed(erp_action->port);
2564 zfcp_erp_action_ready(erp_action);
2567 read_unlock_irqrestore(&adapter->erp_lock, flags);
2577 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2578 * ZFCP_ERP_FAILED - action finished unsuccessfully
2581 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2584 struct zfcp_adapter *adapter = erp_action->adapter;
2585 struct zfcp_port *port = erp_action->port;
2587 retval = zfcp_fsf_close_physical_port(erp_action);
2588 if (retval == -ENOMEM) {
2589 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2590 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2591 retval = ZFCP_ERP_NOMEM;
2594 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2596 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2597 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2598 /* could not send 'open', fail */
2599 retval = ZFCP_ERP_FAILED;
2602 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2603 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2604 retval = ZFCP_ERP_CONTINUES;
2610 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2613 struct zfcp_adapter *adapter = port->adapter;
2615 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2616 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2618 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2619 ZFCP_STATUS_COMMON_CLOSING |
2620 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2621 ZFCP_STATUS_PORT_DID_DID |
2622 ZFCP_STATUS_PORT_PHYS_CLOSING |
2623 ZFCP_STATUS_PORT_INVALID_WWPN,
2633 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2634 * ZFCP_ERP_FAILED - action finished unsuccessfully
2637 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2640 struct zfcp_adapter *adapter = erp_action->adapter;
2641 struct zfcp_port *port = erp_action->port;
2643 retval = zfcp_fsf_close_port(erp_action);
2644 if (retval == -ENOMEM) {
2645 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2646 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2647 retval = ZFCP_ERP_NOMEM;
2650 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2652 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2653 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2654 /* could not send 'close', fail */
2655 retval = ZFCP_ERP_FAILED;
2658 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2659 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2660 retval = ZFCP_ERP_CONTINUES;
2670 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2671 * ZFCP_ERP_FAILED - action finished unsuccessfully
2674 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2677 struct zfcp_adapter *adapter = erp_action->adapter;
2678 struct zfcp_port *port = erp_action->port;
2680 retval = zfcp_fsf_open_port(erp_action);
2681 if (retval == -ENOMEM) {
2682 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2683 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2684 retval = ZFCP_ERP_NOMEM;
2687 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2689 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2690 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2691 /* could not send 'open', fail */
2692 retval = ZFCP_ERP_FAILED;
2695 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2696 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2697 retval = ZFCP_ERP_CONTINUES;
2707 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2708 * ZFCP_ERP_FAILED - action finished unsuccessfully
2711 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2714 struct zfcp_adapter *adapter = erp_action->adapter;
2715 struct zfcp_port *port = erp_action->port;
2717 retval = zfcp_ns_gid_pn_request(erp_action);
2718 if (retval == -ENOMEM) {
2719 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2720 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2721 retval = ZFCP_ERP_NOMEM;
2724 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2726 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2727 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2728 /* could not send nameserver request, fail */
2729 retval = ZFCP_ERP_FAILED;
2732 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2733 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2734 retval = ZFCP_ERP_CONTINUES;
2742 * purpose: this routine executes the 'Reopen Unit' action
2743 * currently no retries
2745 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2746 * ZFCP_ERP_SUCCEEDED - action finished successfully
2747 * ZFCP_ERP_FAILED - action finished unsuccessfully
2750 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2752 int retval = ZFCP_ERP_FAILED;
2753 struct zfcp_unit *unit = erp_action->unit;
2754 struct zfcp_adapter *adapter = erp_action->adapter;
2756 switch (erp_action->step) {
2760 * the ULP spec. begs for waiting for oustanding commands
2762 case ZFCP_ERP_STEP_UNINITIALIZED:
2763 zfcp_erp_unit_strategy_clearstati(unit);
2764 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2765 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2766 "trying close\n", unit->fcp_lun);
2767 retval = zfcp_erp_unit_strategy_close(erp_action);
2770 /* else it's already closed, fall through */
2771 case ZFCP_ERP_STEP_UNIT_CLOSING:
2772 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2773 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2775 retval = ZFCP_ERP_FAILED;
2777 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2778 retval = ZFCP_ERP_EXIT;
2780 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2781 "trying open\n", unit->fcp_lun);
2783 zfcp_erp_unit_strategy_open(erp_action);
2788 case ZFCP_ERP_STEP_UNIT_OPENING:
2789 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2790 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2792 retval = ZFCP_ERP_SUCCEEDED;
2794 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2796 retval = ZFCP_ERP_FAILED;
2801 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2802 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2803 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2804 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2809 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2812 struct zfcp_adapter *adapter = unit->port->adapter;
2814 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2815 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2817 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2818 ZFCP_STATUS_COMMON_CLOSING |
2819 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2820 ZFCP_STATUS_UNIT_SHARED |
2821 ZFCP_STATUS_UNIT_READONLY,
2832 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2833 * ZFCP_ERP_FAILED - action finished unsuccessfully
2836 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2839 struct zfcp_adapter *adapter = erp_action->adapter;
2840 struct zfcp_unit *unit = erp_action->unit;
2842 retval = zfcp_fsf_close_unit(erp_action);
2843 if (retval == -ENOMEM) {
2844 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2845 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2846 sizeof (fcp_lun_t));
2847 retval = ZFCP_ERP_NOMEM;
2850 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2852 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2853 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2854 sizeof (fcp_lun_t));
2855 /* could not send 'close', fail */
2856 retval = ZFCP_ERP_FAILED;
2859 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2860 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2861 retval = ZFCP_ERP_CONTINUES;
2872 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2873 * ZFCP_ERP_FAILED - action finished unsuccessfully
2876 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2879 struct zfcp_adapter *adapter = erp_action->adapter;
2880 struct zfcp_unit *unit = erp_action->unit;
2882 retval = zfcp_fsf_open_unit(erp_action);
2883 if (retval == -ENOMEM) {
2884 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2885 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2886 sizeof (fcp_lun_t));
2887 retval = ZFCP_ERP_NOMEM;
2890 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2892 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2893 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2894 sizeof (fcp_lun_t));
2895 /* could not send 'open', fail */
2896 retval = ZFCP_ERP_FAILED;
2899 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2900 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2901 retval = ZFCP_ERP_CONTINUES;
2906 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2908 BUG_ON(!fsf_req->erp_action);
2909 fsf_req->timer.function = zfcp_erp_timeout_handler;
2910 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2911 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2912 add_timer(&fsf_req->timer);
2918 * purpose: enqueue the specified error recovery action, if needed
2923 zfcp_erp_action_enqueue(int action,
2924 struct zfcp_adapter *adapter,
2925 struct zfcp_port *port, struct zfcp_unit *unit)
2928 struct zfcp_erp_action *erp_action = NULL;
2929 int stronger_action = 0;
2933 * We need some rules here which check whether we really need
2934 * this action or whether we should just drop it.
2935 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2936 * 'Reopen Unit' request for an associated unit since we can't
2937 * satisfy this request now. A 'Reopen Port' action will trigger
2938 * 'Reopen Unit' actions when it completes.
2939 * Thus, there are only actions in the queue which can immediately be
2940 * executed. This makes the processing of the action queue more
2944 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2948 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2949 /* check whether we really need this */
2951 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2952 if (atomic_test_mask
2953 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2954 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2955 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2957 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2958 sizeof (fcp_lun_t));
2961 if (!atomic_test_mask
2962 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2964 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2967 if (!atomic_test_mask
2968 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2969 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2972 /* fall through !!! */
2974 case ZFCP_ERP_ACTION_REOPEN_PORT:
2975 if (atomic_test_mask
2976 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2977 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2978 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2982 /* fall through !!! */
2984 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2985 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2987 if (port->erp_action.action !=
2988 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2989 ZFCP_LOG_INFO("dropped erp action %i (port "
2990 "0x%016Lx, action in use: %i)\n",
2992 port->erp_action.action);
2993 debug_text_event(adapter->erp_dbf, 4,
2996 debug_text_event(adapter->erp_dbf, 4,
2998 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3002 if (!atomic_test_mask
3003 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3005 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3008 if (!atomic_test_mask
3009 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3010 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3013 /* fall through !!! */
3015 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3016 if (atomic_test_mask
3017 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3018 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3024 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3025 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3026 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3027 "on adapter %s (action=%d)\n",
3028 zfcp_get_busid_by_adapter(adapter), action);
3032 /* check whether we need something stronger first */
3033 if (stronger_action) {
3034 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3035 debug_event(adapter->erp_dbf, 4, &stronger_action,
3037 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3038 "erp action %d on adapter %s\n",
3039 stronger_action, action,
3040 zfcp_get_busid_by_adapter(adapter));
3041 action = stronger_action;
3044 /* mark adapter to have some error recovery pending */
3045 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3047 /* setup error recovery action */
3050 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3051 zfcp_unit_get(unit);
3052 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3053 erp_action = &unit->erp_action;
3054 if (!atomic_test_mask
3055 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3056 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3059 case ZFCP_ERP_ACTION_REOPEN_PORT:
3060 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3061 zfcp_port_get(port);
3062 zfcp_erp_action_dismiss_port(port);
3063 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3064 erp_action = &port->erp_action;
3065 if (!atomic_test_mask
3066 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3067 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3070 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3071 zfcp_adapter_get(adapter);
3072 zfcp_erp_action_dismiss_adapter(adapter);
3073 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3074 erp_action = &adapter->erp_action;
3075 if (!atomic_test_mask
3076 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3077 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3081 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3083 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3084 erp_action->adapter = adapter;
3085 erp_action->port = port;
3086 erp_action->unit = unit;
3087 erp_action->action = action;
3088 erp_action->status = status;
3090 ++adapter->erp_total_count;
3092 /* finally put it into 'ready' queue and kick erp thread */
3093 list_add(&erp_action->list, &adapter->erp_ready_head);
3094 up(&adapter->erp_ready_sem);
3101 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3104 struct zfcp_adapter *adapter = erp_action->adapter;
3106 --adapter->erp_total_count;
3107 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3108 --adapter->erp_low_mem_count;
3109 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3112 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3113 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3114 list_del(&erp_action->list);
3115 switch (erp_action->action) {
3116 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3117 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3118 &erp_action->unit->status);
3120 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3121 case ZFCP_ERP_ACTION_REOPEN_PORT:
3122 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3123 &erp_action->port->status);
3125 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3126 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3127 &erp_action->adapter->status);
3137 * zfcp_erp_action_cleanup
3139 * Register unit with scsi stack if appropriate and fix reference counts.
3140 * Note: Temporary units are not registered with scsi stack.
3143 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3144 struct zfcp_port *port, struct zfcp_unit *unit,
3148 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3149 if ((result == ZFCP_ERP_SUCCEEDED)
3150 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3154 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3156 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3157 &unit->status) == 0)
3158 zfcp_erp_schedule_work(unit);
3160 zfcp_unit_put(unit);
3162 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3163 case ZFCP_ERP_ACTION_REOPEN_PORT:
3164 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3166 zfcp_port_put(port);
3170 if ((result == ZFCP_ERP_SUCCEEDED)
3172 struct fc_rport_identifiers ids;
3173 ids.node_name = port->wwnn;
3174 ids.port_name = port->wwpn;
3175 ids.port_id = port->d_id;
3176 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3178 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3180 ZFCP_LOG_NORMAL("failed registration of rport"
3181 "(adapter %s, wwpn=0x%016Lx)\n",
3182 zfcp_get_busid_by_port(port),
3185 scsi_target_unblock(&port->rport->dev);
3186 port->rport->maxframe_size = port->maxframe_size;
3187 port->rport->supported_classes =
3188 port->supported_classes;
3191 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3192 fc_remote_port_delete(port->rport);
3195 zfcp_port_put(port);
3197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3198 if (result != ZFCP_ERP_SUCCEEDED) {
3199 list_for_each_entry(port, &adapter->port_list_head, list)
3201 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3203 fc_remote_port_delete(port->rport);
3207 zfcp_adapter_put(adapter);
3215 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3217 struct zfcp_port *port;
3219 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3220 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3221 zfcp_erp_action_dismiss(&adapter->erp_action);
3223 list_for_each_entry(port, &adapter->port_list_head, list)
3224 zfcp_erp_action_dismiss_port(port);
3227 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3229 struct zfcp_unit *unit;
3230 struct zfcp_adapter *adapter = port->adapter;
3232 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3233 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3234 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3235 zfcp_erp_action_dismiss(&port->erp_action);
3237 list_for_each_entry(unit, &port->unit_list_head, list)
3238 zfcp_erp_action_dismiss_unit(unit);
3241 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3243 struct zfcp_adapter *adapter = unit->port->adapter;
3245 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3246 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3247 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3248 zfcp_erp_action_dismiss(&unit->erp_action);
3251 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3253 struct zfcp_adapter *adapter = erp_action->adapter;
3255 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3256 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3257 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3260 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3262 struct zfcp_adapter *adapter = erp_action->adapter;
3264 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3265 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3266 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3270 zfcp_erp_port_boxed(struct zfcp_port *port)
3272 struct zfcp_adapter *adapter = port->adapter;
3273 unsigned long flags;
3275 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3276 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3277 read_lock_irqsave(&zfcp_data.config_lock, flags);
3278 zfcp_erp_modify_port_status(port,
3279 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3281 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3282 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3286 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3288 struct zfcp_adapter *adapter = unit->port->adapter;
3290 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3291 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3292 zfcp_erp_modify_unit_status(unit,
3293 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3295 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3299 zfcp_erp_port_access_denied(struct zfcp_port *port)
3301 struct zfcp_adapter *adapter = port->adapter;
3302 unsigned long flags;
3304 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3305 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3306 read_lock_irqsave(&zfcp_data.config_lock, flags);
3307 zfcp_erp_modify_port_status(port,
3308 ZFCP_STATUS_COMMON_ERP_FAILED |
3309 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3311 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3315 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3317 struct zfcp_adapter *adapter = unit->port->adapter;
3319 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3320 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3321 zfcp_erp_modify_unit_status(unit,
3322 ZFCP_STATUS_COMMON_ERP_FAILED |
3323 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3328 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3330 struct zfcp_port *port;
3331 unsigned long flags;
3333 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3336 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3337 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3339 read_lock_irqsave(&zfcp_data.config_lock, flags);
3340 if (adapter->nameserver_port)
3341 zfcp_erp_port_access_changed(adapter->nameserver_port);
3342 list_for_each_entry(port, &adapter->port_list_head, list)
3343 if (port != adapter->nameserver_port)
3344 zfcp_erp_port_access_changed(port);
3345 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3349 zfcp_erp_port_access_changed(struct zfcp_port *port)
3351 struct zfcp_adapter *adapter = port->adapter;
3352 struct zfcp_unit *unit;
3354 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3355 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3357 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3359 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3361 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3362 list_for_each_entry(unit, &port->unit_list_head, list)
3363 zfcp_erp_unit_access_changed(unit);
3367 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3368 "(due to ACT update)\n",
3369 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3370 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3371 ZFCP_LOG_NORMAL("failed reopen of port"
3372 "(adapter %s, wwpn=0x%016Lx)\n",
3373 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3377 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3379 struct zfcp_adapter *adapter = unit->port->adapter;
3381 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3382 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3384 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3386 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3390 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3391 " on adapter %s (due to ACT update)\n",
3392 unit->fcp_lun, unit->port->wwpn,
3393 zfcp_get_busid_by_adapter(adapter));
3394 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3395 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3396 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3397 zfcp_get_busid_by_adapter(adapter),
3398 unit->port->wwpn, unit->fcp_lun);
3401 #undef ZFCP_LOG_AREA