2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
26 static int zfcp_erp_adisc(struct zfcp_port *);
27 static void zfcp_erp_adisc_handler(unsigned long);
29 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
30 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
31 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
32 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
34 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
35 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
37 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
38 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
39 static void zfcp_erp_port_block(struct zfcp_port *, int);
40 static void zfcp_erp_port_unblock(struct zfcp_port *);
41 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
42 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
44 static int zfcp_erp_thread(void *);
46 static int zfcp_erp_strategy(struct zfcp_erp_action *);
48 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
49 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
50 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
51 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
52 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
53 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
54 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
56 struct zfcp_unit *, int);
57 static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
58 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
60 struct zfcp_unit *, int);
61 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
62 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
67 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
68 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
69 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
73 struct zfcp_erp_action *);
75 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
76 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
78 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
79 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
80 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
82 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
83 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
84 struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
86 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
87 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
89 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
90 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
91 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
94 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
95 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
96 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
97 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
99 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
100 struct zfcp_port *, struct zfcp_unit *);
101 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
102 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
103 struct zfcp_port *, struct zfcp_unit *,
106 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
107 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
109 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
110 static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
112 static void zfcp_erp_memwait_handler(unsigned long);
115 * zfcp_close_qdio - close qdio queues for an adapter
117 static void zfcp_close_qdio(struct zfcp_adapter *adapter)
119 struct zfcp_qdio_queue *req_queue;
122 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
125 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
126 req_queue = &adapter->request_queue;
127 write_lock_irq(&req_queue->queue_lock);
128 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
129 write_unlock_irq(&req_queue->queue_lock);
131 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
132 while (qdio_shutdown(adapter->ccw_device,
133 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
135 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
137 /* cleanup used outbound sbals */
138 count = atomic_read(&req_queue->free_count);
139 if (count < QDIO_MAX_BUFFERS_PER_Q) {
140 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
141 count = QDIO_MAX_BUFFERS_PER_Q - count;
142 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
144 req_queue->free_index = 0;
145 atomic_set(&req_queue->free_count, 0);
146 req_queue->distance_from_int = 0;
147 adapter->response_queue.free_index = 0;
148 atomic_set(&adapter->response_queue.free_count, 0);
152 * zfcp_close_fsf - stop FSF operations for an adapter
154 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
155 * requests waiting for completion; especially this returns SCSI commands
158 static void zfcp_close_fsf(struct zfcp_adapter *adapter)
160 /* close queues to ensure that buffers are not accessed by adapter */
161 zfcp_close_qdio(adapter);
162 zfcp_fsf_req_dismiss_all(adapter);
163 /* reset FSF request sequence number */
164 adapter->fsf_req_seq_no = 0;
165 /* all ports and units are closed */
166 zfcp_erp_modify_adapter_status(adapter,
167 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
171 * zfcp_fsf_request_timeout_handler - called if a request timed out
172 * @data: pointer to adapter for handler function
174 * This function needs to be called if requests (ELS, Generic Service,
175 * or SCSI commands) exceed a certain time limit. The assumption is
176 * that after the time limit the adapter get stuck. So we trigger a reopen of
179 static void zfcp_fsf_request_timeout_handler(unsigned long data)
181 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
182 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
185 void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
187 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
188 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
189 fsf_req->timer.expires = jiffies + timeout;
190 add_timer(&fsf_req->timer);
196 * purpose: called if an adapter failed,
197 * initiates adapter recovery which is done
200 * returns: 0 - initiated action successfully
201 * <0 - failed to initiate action
204 zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
208 debug_text_event(adapter->erp_dbf, 5, "a_ro");
209 ZFCP_LOG_DEBUG("reopen adapter %s\n",
210 zfcp_get_busid_by_adapter(adapter));
212 zfcp_erp_adapter_block(adapter, clear_mask);
214 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
215 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
216 zfcp_get_busid_by_adapter(adapter));
217 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
218 /* ensure propagation of failed status to new devices */
219 zfcp_erp_adapter_failed(adapter);
223 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
224 adapter, NULL, NULL);
233 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
234 * used to ensure the correct locking
236 * returns: 0 - initiated action successfully
237 * <0 - failed to initiate action
240 zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
245 read_lock_irqsave(&zfcp_data.config_lock, flags);
246 write_lock(&adapter->erp_lock);
247 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
248 write_unlock(&adapter->erp_lock);
249 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
255 zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
259 retval = zfcp_erp_adapter_reopen(adapter,
260 ZFCP_STATUS_COMMON_RUNNING |
261 ZFCP_STATUS_COMMON_ERP_FAILED |
268 zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
272 retval = zfcp_erp_port_reopen(port,
273 ZFCP_STATUS_COMMON_RUNNING |
274 ZFCP_STATUS_COMMON_ERP_FAILED |
281 zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
285 retval = zfcp_erp_unit_reopen(unit,
286 ZFCP_STATUS_COMMON_RUNNING |
287 ZFCP_STATUS_COMMON_ERP_FAILED |
295 * zfcp_erp_adisc - send ADISC ELS command
296 * @port: port structure
299 zfcp_erp_adisc(struct zfcp_port *port)
301 struct zfcp_adapter *adapter = port->adapter;
302 struct zfcp_send_els *send_els;
303 struct zfcp_ls_adisc *adisc;
304 void *address = NULL;
307 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
308 if (send_els == NULL)
311 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
312 if (send_els->req == NULL)
314 sg_init_table(send_els->req, 1);
316 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
317 if (send_els->resp == NULL)
319 sg_init_table(send_els->resp, 1);
321 address = (void *) get_zeroed_page(GFP_ATOMIC);
325 zfcp_address_to_sg(address, send_els->req);
326 address += PAGE_SIZE >> 1;
327 zfcp_address_to_sg(address, send_els->resp);
328 send_els->req_count = send_els->resp_count = 1;
330 send_els->adapter = adapter;
331 send_els->port = port;
332 send_els->d_id = port->d_id;
333 send_els->handler = zfcp_erp_adisc_handler;
334 send_els->handler_data = (unsigned long) send_els;
336 adisc = zfcp_sg_to_address(send_els->req);
337 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
339 send_els->req->length = sizeof(struct zfcp_ls_adisc);
340 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
342 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
343 without FC-AL-2 capability, so we don't set it */
344 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
345 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
346 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
347 ZFCP_LOG_INFO("ADISC request from s_id 0x%06x to d_id 0x%06x "
348 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
349 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
350 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
351 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
354 retval = zfcp_fsf_send_els(send_els);
356 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
357 "0x%06x on adapter %s\n", send_els->d_id,
358 zfcp_get_busid_by_adapter(adapter));
368 __free_pages(sg_page(send_els->req), 0);
369 if (send_els != NULL) {
370 kfree(send_els->req);
371 kfree(send_els->resp);
380 * zfcp_erp_adisc_handler - handler for ADISC ELS command
381 * @data: pointer to struct zfcp_send_els
383 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
386 zfcp_erp_adisc_handler(unsigned long data)
388 struct zfcp_send_els *send_els;
389 struct zfcp_port *port;
390 struct zfcp_adapter *adapter;
392 struct zfcp_ls_adisc_acc *adisc;
394 send_els = (struct zfcp_send_els *) data;
395 adapter = send_els->adapter;
396 port = send_els->port;
397 d_id = send_els->d_id;
399 /* request rejected or timed out */
400 if (send_els->status != 0) {
401 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
402 "force physical port reopen "
403 "(adapter %s, port d_id=0x%06x)\n",
404 zfcp_get_busid_by_adapter(adapter), d_id);
405 debug_text_event(adapter->erp_dbf, 3, "forcreop");
406 if (zfcp_erp_port_forced_reopen(port, 0))
407 ZFCP_LOG_NORMAL("failed reopen of port "
408 "(adapter %s, wwpn=0x%016Lx)\n",
409 zfcp_get_busid_by_port(port),
414 adisc = zfcp_sg_to_address(send_els->resp);
416 ZFCP_LOG_INFO("ADISC response from d_id 0x%06x to s_id "
417 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
418 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
419 d_id, fc_host_port_id(adapter->scsi_host),
420 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
421 adisc->hard_nport_id, adisc->nport_id);
423 /* set wwnn for port */
425 port->wwnn = adisc->wwnn;
427 if (port->wwpn != adisc->wwpn) {
428 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
429 "port (adapter %s, wwpn=0x%016Lx, "
430 "adisc_resp_wwpn=0x%016Lx)\n",
431 zfcp_get_busid_by_port(port),
432 port->wwpn, (wwn_t) adisc->wwpn);
433 if (zfcp_erp_port_reopen(port, 0))
434 ZFCP_LOG_NORMAL("failed reopen of port "
435 "(adapter %s, wwpn=0x%016Lx)\n",
436 zfcp_get_busid_by_port(port),
442 __free_pages(sg_page(send_els->req), 0);
443 kfree(send_els->req);
444 kfree(send_els->resp);
450 * zfcp_test_link - lightweight link test procedure
451 * @port: port to be tested
453 * Test status of a link to a remote port using the ELS command ADISC.
456 zfcp_test_link(struct zfcp_port *port)
461 retval = zfcp_erp_adisc(port);
464 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
465 "on adapter %s\n ", port->wwpn,
466 zfcp_get_busid_by_port(port));
467 retval = zfcp_erp_port_forced_reopen(port, 0);
469 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
470 "on adapter %s failed\n", port->wwpn,
471 zfcp_get_busid_by_port(port));
483 * purpose: called if a port failed to be opened normally
484 * initiates Forced Reopen recovery which is done
487 * returns: 0 - initiated action successfully
488 * <0 - failed to initiate action
491 zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
494 struct zfcp_adapter *adapter = port->adapter;
496 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
497 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
499 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
500 port->wwpn, zfcp_get_busid_by_port(port));
502 zfcp_erp_port_block(port, clear_mask);
504 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
505 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
506 "on adapter %s\n", port->wwpn,
507 zfcp_get_busid_by_port(port));
508 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
509 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
514 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
515 port->adapter, port, NULL);
524 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
525 * used to ensure the correct locking
527 * returns: 0 - initiated action successfully
528 * <0 - failed to initiate action
531 zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
535 struct zfcp_adapter *adapter;
537 adapter = port->adapter;
538 read_lock_irqsave(&zfcp_data.config_lock, flags);
539 write_lock(&adapter->erp_lock);
540 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
541 write_unlock(&adapter->erp_lock);
542 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
550 * purpose: called if a port is to be opened
551 * initiates Reopen recovery which is done
554 * returns: 0 - initiated action successfully
555 * <0 - failed to initiate action
558 zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
561 struct zfcp_adapter *adapter = port->adapter;
563 debug_text_event(adapter->erp_dbf, 5, "p_ro");
564 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
566 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
567 port->wwpn, zfcp_get_busid_by_port(port));
569 zfcp_erp_port_block(port, clear_mask);
571 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
572 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
573 "on adapter %s\n", port->wwpn,
574 zfcp_get_busid_by_port(port));
575 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
576 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
577 /* ensure propagation of failed status to new devices */
578 zfcp_erp_port_failed(port);
583 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
584 port->adapter, port, NULL);
591 * zfcp_erp_port_reopen - initiate reopen of a remote port
592 * @port: port to be reopened
593 * @clear_mask: specifies flags in port status to be cleared
594 * Return: 0 on success, < 0 on error
596 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
597 * correct locking. An error recovery task is initiated to do the reopen.
598 * To wait for the completion of the reopen zfcp_erp_wait should be used.
601 zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
605 struct zfcp_adapter *adapter = port->adapter;
607 read_lock_irqsave(&zfcp_data.config_lock, flags);
608 write_lock(&adapter->erp_lock);
609 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
610 write_unlock(&adapter->erp_lock);
611 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
619 * purpose: called if a unit is to be opened
620 * initiates Reopen recovery which is done
623 * returns: 0 - initiated action successfully
624 * <0 - failed to initiate action
627 zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
630 struct zfcp_adapter *adapter = unit->port->adapter;
632 debug_text_event(adapter->erp_dbf, 5, "u_ro");
633 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
634 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
635 "on adapter %s\n", unit->fcp_lun,
636 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
638 zfcp_erp_unit_block(unit, clear_mask);
640 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
641 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
642 "on port 0x%016Lx on adapter %s\n",
643 unit->fcp_lun, unit->port->wwpn,
644 zfcp_get_busid_by_unit(unit));
645 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
646 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
652 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
653 unit->port->adapter, unit->port, unit);
659 * zfcp_erp_unit_reopen - initiate reopen of a unit
660 * @unit: unit to be reopened
661 * @clear_mask: specifies flags in unit status to be cleared
662 * Return: 0 on success, < 0 on error
664 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
665 * locking. An error recovery task is initiated to do the reopen.
666 * To wait for the completion of the reopen zfcp_erp_wait should be used.
669 zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
673 struct zfcp_adapter *adapter;
674 struct zfcp_port *port;
677 adapter = port->adapter;
679 read_lock_irqsave(&zfcp_data.config_lock, flags);
680 write_lock(&adapter->erp_lock);
681 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
682 write_unlock(&adapter->erp_lock);
683 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
689 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
691 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
693 debug_text_event(adapter->erp_dbf, 6, "a_bl");
694 zfcp_erp_modify_adapter_status(adapter,
695 ZFCP_STATUS_COMMON_UNBLOCKED |
696 clear_mask, ZFCP_CLEAR);
700 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
702 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
704 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
705 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
711 * purpose: disable I/O,
712 * return any open requests and clean them up,
713 * aim: no pending and incoming I/O
718 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
720 struct zfcp_adapter *adapter = port->adapter;
722 debug_text_event(adapter->erp_dbf, 6, "p_bl");
723 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
724 zfcp_erp_modify_port_status(port,
725 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
732 * purpose: enable I/O
737 zfcp_erp_port_unblock(struct zfcp_port *port)
739 struct zfcp_adapter *adapter = port->adapter;
741 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
742 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
743 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
749 * purpose: disable I/O,
750 * return any open requests and clean them up,
751 * aim: no pending and incoming I/O
756 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
758 struct zfcp_adapter *adapter = unit->port->adapter;
760 debug_text_event(adapter->erp_dbf, 6, "u_bl");
761 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
762 zfcp_erp_modify_unit_status(unit,
763 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
770 * purpose: enable I/O
775 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
777 struct zfcp_adapter *adapter = unit->port->adapter;
779 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
780 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
781 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
785 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
787 struct zfcp_adapter *adapter = erp_action->adapter;
789 debug_text_event(adapter->erp_dbf, 4, "a_ar");
790 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
792 zfcp_erp_action_to_ready(erp_action);
793 up(&adapter->erp_ready_sem);
801 * returns: <0 erp_action not found in any list
802 * ZFCP_ERP_ACTION_READY erp_action is in ready list
803 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
805 * locks: erp_lock must be held
808 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
810 int retval = -EINVAL;
811 struct list_head *entry;
812 struct zfcp_erp_action *entry_erp_action;
813 struct zfcp_adapter *adapter = erp_action->adapter;
815 /* search in running list */
816 list_for_each(entry, &adapter->erp_running_head) {
818 list_entry(entry, struct zfcp_erp_action, list);
819 if (entry_erp_action == erp_action) {
820 retval = ZFCP_ERP_ACTION_RUNNING;
824 /* search in ready list */
825 list_for_each(entry, &adapter->erp_ready_head) {
827 list_entry(entry, struct zfcp_erp_action, list);
828 if (entry_erp_action == erp_action) {
829 retval = ZFCP_ERP_ACTION_READY;
839 * purpose: checks current status of action (timed out, dismissed, ...)
840 * and does appropriate preparations (dismiss fsf request, ...)
842 * locks: called under erp_lock (disabled interrupts)
845 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
847 struct zfcp_adapter *adapter = erp_action->adapter;
849 if (erp_action->fsf_req) {
850 /* take lock to ensure that request is not deleted meanwhile */
851 spin_lock(&adapter->req_list_lock);
852 if (zfcp_reqlist_find(adapter, erp_action->fsf_req->req_id)) {
853 /* fsf_req still exists */
854 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
855 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
856 sizeof (unsigned long));
857 /* dismiss fsf_req of timed out/dismissed erp_action */
858 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
859 ZFCP_STATUS_ERP_TIMEDOUT)) {
860 debug_text_event(adapter->erp_dbf, 3,
862 erp_action->fsf_req->status |=
863 ZFCP_STATUS_FSFREQ_DISMISSED;
865 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
866 ZFCP_LOG_NORMAL("error: erp step timed out "
867 "(action=%d, fsf_req=%p)\n ",
869 erp_action->fsf_req);
872 * If fsf_req is neither dismissed nor completed
873 * then keep it running asynchronously and don't mess
874 * with the association of erp_action and fsf_req.
876 if (erp_action->fsf_req->status &
877 (ZFCP_STATUS_FSFREQ_COMPLETED |
878 ZFCP_STATUS_FSFREQ_DISMISSED)) {
879 /* forget about association between fsf_req
881 erp_action->fsf_req = NULL;
884 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
886 * even if this fsf_req has gone, forget about
887 * association between erp_action and fsf_req
889 erp_action->fsf_req = NULL;
891 spin_unlock(&adapter->req_list_lock);
893 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
897 * zfcp_erp_async_handler_nolock - complete erp_action
899 * Used for normal completion, time-out, dismissal and failure after
900 * low memory condition.
902 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
903 unsigned long set_mask)
905 struct zfcp_adapter *adapter = erp_action->adapter;
907 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
908 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
909 debug_event(adapter->erp_dbf, 2, &erp_action->action,
911 erp_action->status |= set_mask;
912 zfcp_erp_action_ready(erp_action);
914 /* action is ready or gone - nothing to do */
915 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
916 debug_event(adapter->erp_dbf, 3, &erp_action->action,
922 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
924 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
925 unsigned long set_mask)
927 struct zfcp_adapter *adapter = erp_action->adapter;
930 write_lock_irqsave(&adapter->erp_lock, flags);
931 zfcp_erp_async_handler_nolock(erp_action, set_mask);
932 write_unlock_irqrestore(&adapter->erp_lock, flags);
936 * purpose: is called for erp_action which was slept waiting for
937 * memory becoming avaliable,
938 * will trigger that this action will be continued
941 zfcp_erp_memwait_handler(unsigned long data)
943 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
944 struct zfcp_adapter *adapter = erp_action->adapter;
946 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
947 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
949 zfcp_erp_async_handler(erp_action, 0);
953 * purpose: is called if an asynchronous erp step timed out,
954 * action gets an appropriate flag and will be processed
957 static void zfcp_erp_timeout_handler(unsigned long data)
959 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
960 struct zfcp_adapter *adapter = erp_action->adapter;
962 debug_text_event(adapter->erp_dbf, 2, "a_th");
963 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
965 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
969 * zfcp_erp_action_dismiss - dismiss an erp_action
971 * adapter->erp_lock must be held
973 * Dismissal of an erp_action is usually required if an erp_action of
974 * higher priority is generated.
976 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
978 struct zfcp_adapter *adapter = erp_action->adapter;
980 debug_text_event(adapter->erp_dbf, 2, "a_adis");
981 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
983 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
987 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
991 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
993 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
995 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
997 zfcp_get_busid_by_adapter(adapter));
998 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1000 wait_event(adapter->erp_thread_wqh,
1001 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1003 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1006 return (retval < 0);
1016 * context: process (i.e. proc-fs or rmmod/insmod)
1018 * note: The caller of this routine ensures that the specified
1019 * adapter has been shut down and that this operation
1020 * has been completed. Thus, there are no pending erp_actions
1021 * which would need to be handled here.
1024 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1028 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1029 up(&adapter->erp_ready_sem);
1031 wait_event(adapter->erp_thread_wqh,
1032 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1035 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1038 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1044 * purpose: is run as a kernel thread,
1045 * goes through list of error recovery actions of associated adapter
1046 * and delegates single action to execution
1051 zfcp_erp_thread(void *data)
1053 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1054 struct list_head *next;
1055 struct zfcp_erp_action *erp_action;
1056 unsigned long flags;
1058 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1059 /* Block all signals */
1060 siginitsetinv(¤t->blocked, 0);
1061 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1062 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1063 wake_up(&adapter->erp_thread_wqh);
1065 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1066 &adapter->status)) {
1068 write_lock_irqsave(&adapter->erp_lock, flags);
1069 next = adapter->erp_ready_head.prev;
1070 write_unlock_irqrestore(&adapter->erp_lock, flags);
1072 if (next != &adapter->erp_ready_head) {
1074 list_entry(next, struct zfcp_erp_action, list);
1076 * process action (incl. [re]moving it
1077 * from 'ready' queue)
1079 zfcp_erp_strategy(erp_action);
1083 * sleep as long as there is nothing to do, i.e.
1084 * no action in 'ready' queue to be processed and
1085 * thread is not to be killed
1087 down_interruptible(&adapter->erp_ready_sem);
1088 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1091 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1092 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1093 wake_up(&adapter->erp_thread_wqh);
1101 * purpose: drives single error recovery action and schedules higher and
1102 * subordinate actions, if necessary
1104 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1105 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1106 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1107 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1108 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1111 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1114 struct zfcp_adapter *adapter = erp_action->adapter;
1115 struct zfcp_port *port = erp_action->port;
1116 struct zfcp_unit *unit = erp_action->unit;
1117 int action = erp_action->action;
1118 u32 status = erp_action->status;
1119 unsigned long flags;
1121 /* serialise dismissing, timing out, moving, enqueueing */
1122 read_lock_irqsave(&zfcp_data.config_lock, flags);
1123 write_lock(&adapter->erp_lock);
1125 /* dequeue dismissed action and leave, if required */
1126 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1127 if (retval == ZFCP_ERP_DISMISSED) {
1128 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1133 * move action to 'running' queue before processing it
1134 * (to avoid a race condition regarding moving the
1135 * action to the 'running' queue and back)
1137 zfcp_erp_action_to_running(erp_action);
1140 * try to process action as far as possible,
1141 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1142 * afterwards the lock is required again for the following reasons:
1143 * - dequeueing of finished action and enqueueing of
1144 * follow-up actions must be atomic so that any other
1145 * reopen-routine does not believe there is nothing to do
1146 * and that it is safe to enqueue something else,
1147 * - we want to force any control thread which is dismissing
1148 * actions to finish this before we decide about
1149 * necessary steps to be taken here further
1151 write_unlock(&adapter->erp_lock);
1152 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1153 retval = zfcp_erp_strategy_do_action(erp_action);
1154 read_lock_irqsave(&zfcp_data.config_lock, flags);
1155 write_lock(&adapter->erp_lock);
1158 * check for dismissed status again to avoid follow-up actions,
1159 * failing of targets and so on for dismissed actions
1161 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1164 case ZFCP_ERP_DISMISSED:
1165 /* leave since this action has ridden to its ancestors */
1166 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1168 case ZFCP_ERP_NOMEM:
1169 /* no memory to continue immediately, let it sleep */
1170 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1171 ++adapter->erp_low_mem_count;
1172 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1174 /* This condition is true if there is no memory available
1175 for any erp_action on this adapter. This implies that there
1176 are no elements in the memory pool(s) left for erp_actions.
1177 This might happen if an erp_action that used a memory pool
1178 element was timed out.
1180 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1181 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1182 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1183 "restarting I/O on adapter %s "
1184 "to free mempool\n",
1185 zfcp_get_busid_by_adapter(adapter));
1186 zfcp_erp_adapter_reopen_internal(adapter, 0);
1188 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1189 retval = zfcp_erp_strategy_memwait(erp_action);
1192 case ZFCP_ERP_CONTINUES:
1193 /* leave since this action runs asynchronously */
1194 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1195 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1196 --adapter->erp_low_mem_count;
1197 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1201 /* ok, finished action (whatever its result is) */
1203 /* check for unrecoverable targets */
1204 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1206 /* action must be dequeued (here to allow for further ones) */
1207 zfcp_erp_action_dequeue(erp_action);
1210 * put this target through the erp mill again if someone has
1211 * requested to change the status of a target being online
1212 * to offline or the other way around
1213 * (old retval is preserved if nothing has to be done here)
1215 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1216 port, unit, retval);
1219 * leave if target is in permanent error state or if
1220 * action is repeated in order to process state change
1222 if (retval == ZFCP_ERP_EXIT) {
1223 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1227 /* trigger follow up actions */
1228 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1231 write_unlock(&adapter->erp_lock);
1232 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1234 if (retval != ZFCP_ERP_CONTINUES)
1235 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1238 * a few tasks remain when the erp queues are empty
1239 * (don't do that if the last action evaluated was dismissed
1240 * since this clearly indicates that there is more to come) :
1241 * - close the name server port if it is open yet
1242 * (enqueues another [probably] final action)
1243 * - otherwise, wake up whoever wants to be woken when we are
1246 if (retval != ZFCP_ERP_DISMISSED)
1247 zfcp_erp_strategy_check_queues(adapter);
1249 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1259 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1260 * retval - otherwise
1263 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1265 struct zfcp_adapter *adapter = erp_action->adapter;
1267 zfcp_erp_strategy_check_fsfreq(erp_action);
1269 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1270 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1271 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1272 zfcp_erp_action_dequeue(erp_action);
1273 retval = ZFCP_ERP_DISMISSED;
1275 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1281 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1283 int retval = ZFCP_ERP_FAILED;
1284 struct zfcp_adapter *adapter = erp_action->adapter;
1287 * try to execute/continue action as far as possible,
1288 * note: no lock in subsequent strategy routines
1289 * (this allows these routine to call schedule, e.g.
1290 * kmalloc with such flags or qdio_initialize & friends)
1291 * Note: in case of timeout, the seperate strategies will fail
1292 * anyhow. No need for a special action. Even worse, a nameserver
1293 * failure would not wake up waiting ports without the call.
1295 switch (erp_action->action) {
1297 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1298 retval = zfcp_erp_adapter_strategy(erp_action);
1301 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1302 retval = zfcp_erp_port_forced_strategy(erp_action);
1305 case ZFCP_ERP_ACTION_REOPEN_PORT:
1306 retval = zfcp_erp_port_strategy(erp_action);
1309 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1310 retval = zfcp_erp_unit_strategy(erp_action);
1314 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1315 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1317 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1318 "adapter %s (action=%d)\n",
1319 zfcp_get_busid_by_adapter(erp_action->adapter),
1320 erp_action->action);
1329 * purpose: triggers retry of this action after a certain amount of time
1330 * by means of timer provided by erp_action
1332 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1335 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1337 int retval = ZFCP_ERP_CONTINUES;
1338 struct zfcp_adapter *adapter = erp_action->adapter;
1340 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1341 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1342 init_timer(&erp_action->timer);
1343 erp_action->timer.function = zfcp_erp_memwait_handler;
1344 erp_action->timer.data = (unsigned long) erp_action;
1345 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1346 add_timer(&erp_action->timer);
1352 * function: zfcp_erp_adapter_failed
1354 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1358 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1360 zfcp_erp_modify_adapter_status(adapter,
1361 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1362 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1363 zfcp_get_busid_by_adapter(adapter));
1364 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1368 * function: zfcp_erp_port_failed
1370 * purpose: sets the port and all underlying devices to ERP_FAILED
1374 zfcp_erp_port_failed(struct zfcp_port *port)
1376 zfcp_erp_modify_port_status(port,
1377 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1379 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1380 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1381 "port d_id=0x%06x)\n",
1382 zfcp_get_busid_by_port(port), port->d_id);
1384 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1385 zfcp_get_busid_by_port(port), port->wwpn);
1387 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1388 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1392 * function: zfcp_erp_unit_failed
1394 * purpose: sets the unit to ERP_FAILED
1398 zfcp_erp_unit_failed(struct zfcp_unit *unit)
1400 zfcp_erp_modify_unit_status(unit,
1401 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1403 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1404 " on adapter %s\n", unit->fcp_lun,
1405 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1406 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1407 debug_event(unit->port->adapter->erp_dbf, 2,
1408 &unit->fcp_lun, sizeof (fcp_lun_t));
1412 * function: zfcp_erp_strategy_check_target
1414 * purpose: increments the erp action count on the device currently in
1415 * recovery if the action failed or resets the count in case of
1416 * success. If a maximum count is exceeded the device is marked
1418 * The 'blocked' state of a target which has been recovered
1419 * successfully is reset.
1421 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1422 * ZFCP_ERP_SUCCEEDED - action finished successfully
1423 * ZFCP_ERP_EXIT - action failed and will not continue
1426 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1428 struct zfcp_adapter *adapter = erp_action->adapter;
1429 struct zfcp_port *port = erp_action->port;
1430 struct zfcp_unit *unit = erp_action->unit;
1432 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1433 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1434 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1436 switch (erp_action->action) {
1438 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1439 result = zfcp_erp_strategy_check_unit(unit, result);
1442 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1443 case ZFCP_ERP_ACTION_REOPEN_PORT:
1444 result = zfcp_erp_strategy_check_port(port, result);
1447 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1448 result = zfcp_erp_strategy_check_adapter(adapter, result);
1456 zfcp_erp_strategy_statechange(int action,
1458 struct zfcp_adapter *adapter,
1459 struct zfcp_port *port,
1460 struct zfcp_unit *unit, int retval)
1462 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1463 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1467 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1468 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1470 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1471 retval = ZFCP_ERP_EXIT;
1475 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1476 case ZFCP_ERP_ACTION_REOPEN_PORT:
1477 if (zfcp_erp_strategy_statechange_detected(&port->status,
1479 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1480 retval = ZFCP_ERP_EXIT;
1484 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1485 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1487 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1488 retval = ZFCP_ERP_EXIT;
1497 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1500 /* take it online */
1501 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1502 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1503 /* take it offline */
1504 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1505 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1509 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1511 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1512 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1513 sizeof (fcp_lun_t));
1516 case ZFCP_ERP_SUCCEEDED :
1517 atomic_set(&unit->erp_counter, 0);
1518 zfcp_erp_unit_unblock(unit);
1520 case ZFCP_ERP_FAILED :
1521 atomic_inc(&unit->erp_counter);
1522 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1523 zfcp_erp_unit_failed(unit);
1525 case ZFCP_ERP_EXIT :
1530 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1531 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1532 result = ZFCP_ERP_EXIT;
1539 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1541 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1542 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1545 case ZFCP_ERP_SUCCEEDED :
1546 atomic_set(&port->erp_counter, 0);
1547 zfcp_erp_port_unblock(port);
1549 case ZFCP_ERP_FAILED :
1550 atomic_inc(&port->erp_counter);
1551 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1552 zfcp_erp_port_failed(port);
1554 case ZFCP_ERP_EXIT :
1559 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1560 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1561 result = ZFCP_ERP_EXIT;
1568 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1570 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1573 case ZFCP_ERP_SUCCEEDED :
1574 atomic_set(&adapter->erp_counter, 0);
1575 zfcp_erp_adapter_unblock(adapter);
1577 case ZFCP_ERP_FAILED :
1578 atomic_inc(&adapter->erp_counter);
1579 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1580 zfcp_erp_adapter_failed(adapter);
1582 case ZFCP_ERP_EXIT :
1587 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1588 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1589 result = ZFCP_ERP_EXIT;
1595 struct zfcp_erp_add_work {
1596 struct zfcp_unit *unit;
1597 struct work_struct work;
1601 * zfcp_erp_scsi_scan
1602 * @data: pointer to a struct zfcp_erp_add_work
1604 * Registers a logical unit with the SCSI stack.
1606 static void zfcp_erp_scsi_scan(struct work_struct *work)
1608 struct zfcp_erp_add_work *p =
1609 container_of(work, struct zfcp_erp_add_work, work);
1610 struct zfcp_unit *unit = p->unit;
1611 struct fc_rport *rport = unit->port->rport;
1612 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1614 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1615 wake_up(&unit->scsi_scan_wq);
1616 zfcp_unit_put(unit);
1621 * zfcp_erp_schedule_work
1622 * @unit: pointer to unit which should be registered with SCSI stack
1624 * Schedules work which registers a unit with the SCSI stack
1627 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1629 struct zfcp_erp_add_work *p;
1631 p = kzalloc(sizeof(*p), GFP_KERNEL);
1633 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1634 "the FCP-LUN 0x%Lx connected to "
1635 "the port with WWPN 0x%Lx connected to "
1636 "the adapter %s with the SCSI stack.\n",
1639 zfcp_get_busid_by_unit(unit));
1643 zfcp_unit_get(unit);
1644 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1645 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1647 schedule_work(&p->work);
1653 * purpose: remaining things in good cases,
1654 * escalation in bad cases
1659 zfcp_erp_strategy_followup_actions(int action,
1660 struct zfcp_adapter *adapter,
1661 struct zfcp_port *port,
1662 struct zfcp_unit *unit, int status)
1664 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1665 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1667 /* initiate follow-up actions depending on success of finished action */
1670 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1671 if (status == ZFCP_ERP_SUCCEEDED)
1672 zfcp_erp_port_reopen_all_internal(adapter, 0);
1674 zfcp_erp_adapter_reopen_internal(adapter, 0);
1677 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1678 if (status == ZFCP_ERP_SUCCEEDED)
1679 zfcp_erp_port_reopen_internal(port, 0);
1681 zfcp_erp_adapter_reopen_internal(adapter, 0);
1684 case ZFCP_ERP_ACTION_REOPEN_PORT:
1685 if (status == ZFCP_ERP_SUCCEEDED)
1686 zfcp_erp_unit_reopen_all_internal(port, 0);
1688 zfcp_erp_port_forced_reopen_internal(port, 0);
1691 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1692 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1693 if (status != ZFCP_ERP_SUCCEEDED)
1694 zfcp_erp_port_reopen_internal(unit->port, 0);
1702 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1704 unsigned long flags;
1706 read_lock_irqsave(&zfcp_data.config_lock, flags);
1707 read_lock(&adapter->erp_lock);
1708 if (list_empty(&adapter->erp_ready_head) &&
1709 list_empty(&adapter->erp_running_head)) {
1710 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1711 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1713 wake_up(&adapter->erp_done_wqh);
1715 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1716 read_unlock(&adapter->erp_lock);
1717 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1723 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1724 * @adapter: adapter for which to wait for completion of its error recovery
1728 zfcp_erp_wait(struct zfcp_adapter *adapter)
1732 wait_event(adapter->erp_done_wqh,
1733 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1740 zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1741 u32 mask, int set_or_clear)
1743 struct zfcp_port *port;
1744 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1746 if (set_or_clear == ZFCP_SET) {
1747 atomic_set_mask(mask, &adapter->status);
1748 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1750 atomic_clear_mask(mask, &adapter->status);
1751 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1752 atomic_set(&adapter->erp_counter, 0);
1753 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1755 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1757 /* Deal with all underlying devices, only pass common_mask */
1759 list_for_each_entry(port, &adapter->port_list_head, list)
1760 zfcp_erp_modify_port_status(port, common_mask,
1765 * function: zfcp_erp_modify_port_status
1767 * purpose: sets the port and all underlying devices to ERP_FAILED
1771 zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1773 struct zfcp_unit *unit;
1774 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1776 if (set_or_clear == ZFCP_SET) {
1777 atomic_set_mask(mask, &port->status);
1778 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1780 atomic_clear_mask(mask, &port->status);
1781 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1782 atomic_set(&port->erp_counter, 0);
1783 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1785 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1786 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1788 /* Modify status of all underlying devices, only pass common mask */
1790 list_for_each_entry(unit, &port->unit_list_head, list)
1791 zfcp_erp_modify_unit_status(unit, common_mask,
1796 * function: zfcp_erp_modify_unit_status
1798 * purpose: sets the unit to ERP_FAILED
1802 zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1804 if (set_or_clear == ZFCP_SET) {
1805 atomic_set_mask(mask, &unit->status);
1806 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1808 atomic_clear_mask(mask, &unit->status);
1809 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1810 atomic_set(&unit->erp_counter, 0);
1812 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1814 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1815 sizeof (fcp_lun_t));
1816 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1822 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1823 * used to ensure the correct locking
1825 * returns: 0 - initiated action successfully
1826 * <0 - failed to initiate action
1829 zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1832 unsigned long flags;
1834 read_lock_irqsave(&zfcp_data.config_lock, flags);
1835 write_lock(&adapter->erp_lock);
1836 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1837 write_unlock(&adapter->erp_lock);
1838 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1844 zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1847 struct zfcp_port *port;
1849 list_for_each_entry(port, &adapter->port_list_head, list)
1850 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1851 zfcp_erp_port_reopen_internal(port, clear_mask);
1864 zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1867 struct zfcp_unit *unit;
1869 list_for_each_entry(unit, &port->unit_list_head, list)
1870 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1878 * purpose: this routine executes the 'Reopen Adapter' action
1879 * (the entire action is processed synchronously, since
1880 * there are no actions which might be run concurrently
1883 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1884 * ZFCP_ERP_FAILED - action finished unsuccessfully
1887 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1890 struct zfcp_adapter *adapter = erp_action->adapter;
1892 retval = zfcp_erp_adapter_strategy_close(erp_action);
1893 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1894 retval = ZFCP_ERP_EXIT;
1896 retval = zfcp_erp_adapter_strategy_open(erp_action);
1898 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1899 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1900 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1902 if (retval == ZFCP_ERP_FAILED) {
1903 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1904 "to recover itself\n",
1905 zfcp_get_busid_by_adapter(adapter));
1906 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1917 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1918 * ZFCP_ERP_FAILED - action finished unsuccessfully
1921 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1925 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1926 &erp_action->adapter->status);
1927 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1928 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1929 &erp_action->adapter->status);
1939 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1940 * ZFCP_ERP_FAILED - action finished unsuccessfully
1943 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1947 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1948 &erp_action->adapter->status);
1949 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1950 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1951 &erp_action->adapter->status);
1957 * function: zfcp_register_adapter
1959 * purpose: allocate the irq associated with this devno and register
1960 * the FSF adapter with the SCSI stack
1965 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1967 int retval = ZFCP_ERP_SUCCEEDED;
1972 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1973 if (retval != ZFCP_ERP_SUCCEEDED)
1976 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1977 if (retval != ZFCP_ERP_SUCCEEDED)
1978 goto failed_openfcp;
1980 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1984 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1985 &erp_action->adapter->status);
1988 zfcp_close_fsf(erp_action->adapter);
1990 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1991 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1992 ZFCP_STATUS_ADAPTER_XPORT_OK,
1993 &erp_action->adapter->status);
1999 * function: zfcp_qdio_init
2001 * purpose: setup QDIO operation for specified adapter
2003 * returns: 0 - successful setup
2007 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2011 volatile struct qdio_buffer_element *sbale;
2012 struct zfcp_adapter *adapter = erp_action->adapter;
2014 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2015 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2017 zfcp_get_busid_by_adapter(adapter));
2021 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2022 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2024 zfcp_get_busid_by_adapter(adapter));
2025 goto failed_qdio_establish;
2027 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2029 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2030 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2032 zfcp_get_busid_by_adapter(adapter));
2033 goto failed_qdio_activate;
2035 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2038 * put buffers into response queue,
2040 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2041 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2043 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2047 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2048 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2049 zfcp_get_busid_by_adapter(adapter),
2050 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2052 retval = do_QDIO(adapter->ccw_device,
2053 QDIO_FLAG_SYNC_INPUT,
2054 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2057 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2059 goto failed_do_qdio;
2061 adapter->response_queue.free_index = 0;
2062 atomic_set(&adapter->response_queue.free_count, 0);
2063 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2064 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2066 /* set index of first avalable SBALS / number of available SBALS */
2067 adapter->request_queue.free_index = 0;
2068 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2069 adapter->request_queue.distance_from_int = 0;
2071 /* initialize waitqueue used to wait for free SBALs in requests queue */
2072 init_waitqueue_head(&adapter->request_wq);
2074 /* ok, we did it - skip all cleanups for different failures */
2075 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2076 retval = ZFCP_ERP_SUCCEEDED;
2082 failed_qdio_activate:
2083 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2084 while (qdio_shutdown(adapter->ccw_device,
2085 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2087 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2089 failed_qdio_establish:
2091 retval = ZFCP_ERP_FAILED;
2099 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2103 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2104 if (retval == ZFCP_ERP_FAILED)
2105 return ZFCP_ERP_FAILED;
2107 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2108 if (retval == ZFCP_ERP_FAILED)
2109 return ZFCP_ERP_FAILED;
2111 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2115 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2117 int retval = ZFCP_ERP_SUCCEEDED;
2119 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2120 struct zfcp_adapter *adapter = erp_action->adapter;
2122 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2124 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2125 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2127 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2128 write_lock_irq(&adapter->erp_lock);
2129 zfcp_erp_action_to_running(erp_action);
2130 write_unlock_irq(&adapter->erp_lock);
2131 if (zfcp_fsf_exchange_config_data(erp_action)) {
2132 retval = ZFCP_ERP_FAILED;
2133 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2134 ZFCP_LOG_INFO("error: initiation of exchange of "
2135 "configuration data failed for "
2137 zfcp_get_busid_by_adapter(adapter));
2140 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2141 ZFCP_LOG_DEBUG("Xchange underway\n");
2145 * Both the normal completion handler as well as the timeout
2146 * handler will do an 'up' when the 'exchange config data'
2147 * request completes or times out. Thus, the signal to go on
2148 * won't be lost utilizing this semaphore.
2149 * Furthermore, this 'adapter_reopen' action is
2150 * guaranteed to be the only action being there (highest action
2151 * which prevents other actions from being created).
2152 * Resulting from that, the wake signal recognized here
2153 * _must_ be the one belonging to the 'exchange config
2156 down(&adapter->erp_ready_sem);
2157 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2158 ZFCP_LOG_INFO("error: exchange of configuration data "
2159 "for adapter %s timed out\n",
2160 zfcp_get_busid_by_adapter(adapter));
2164 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2168 ZFCP_LOG_DEBUG("host connection still initialising... "
2169 "waiting and retrying...\n");
2170 /* sleep a little bit before retry */
2171 msleep(jiffies_to_msecs(sleep));
2175 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2178 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2179 &adapter->status)) {
2180 ZFCP_LOG_INFO("error: exchange of configuration data for "
2181 "adapter %s failed\n",
2182 zfcp_get_busid_by_adapter(adapter));
2183 retval = ZFCP_ERP_FAILED;
2190 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2193 struct zfcp_adapter *adapter;
2195 adapter = erp_action->adapter;
2196 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2198 write_lock_irq(&adapter->erp_lock);
2199 zfcp_erp_action_to_running(erp_action);
2200 write_unlock_irq(&adapter->erp_lock);
2202 ret = zfcp_fsf_exchange_port_data(erp_action);
2203 if (ret == -EOPNOTSUPP) {
2204 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2205 return ZFCP_ERP_SUCCEEDED;
2207 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2208 return ZFCP_ERP_FAILED;
2210 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2212 ret = ZFCP_ERP_SUCCEEDED;
2213 down(&adapter->erp_ready_sem);
2214 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2215 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2216 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2217 ret = ZFCP_ERP_FAILED;
2220 /* don't treat as error for the sake of compatibility */
2221 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2222 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2223 "%s\n", zfcp_get_busid_by_adapter(adapter));
2229 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2232 int retval = ZFCP_ERP_SUCCEEDED;
2234 struct zfcp_adapter *adapter = erp_action->adapter;
2237 adapter->status_read_failed = 0;
2238 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2239 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2241 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2242 "notification failed on adapter %s\n",
2243 zfcp_get_busid_by_adapter(adapter));
2244 retval = ZFCP_ERP_FAILED;
2256 * purpose: this routine executes the 'Reopen Physical Port' action
2258 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2259 * ZFCP_ERP_SUCCEEDED - action finished successfully
2260 * ZFCP_ERP_FAILED - action finished unsuccessfully
2263 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2265 int retval = ZFCP_ERP_FAILED;
2266 struct zfcp_port *port = erp_action->port;
2267 struct zfcp_adapter *adapter = erp_action->adapter;
2269 switch (erp_action->step) {
2273 * the ULP spec. begs for waiting for oustanding commands
2275 case ZFCP_ERP_STEP_UNINITIALIZED:
2276 zfcp_erp_port_strategy_clearstati(port);
2278 * it would be sufficient to test only the normal open flag
2279 * since the phys. open flag cannot be set if the normal
2280 * open flag is unset - however, this is for readabilty ...
2282 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2283 ZFCP_STATUS_COMMON_OPEN),
2285 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2286 "close physical\n", port->wwpn);
2288 zfcp_erp_port_forced_strategy_close(erp_action);
2290 retval = ZFCP_ERP_FAILED;
2293 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2294 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2296 ZFCP_LOG_DEBUG("close physical failed for port "
2297 "0x%016Lx\n", port->wwpn);
2298 retval = ZFCP_ERP_FAILED;
2300 retval = ZFCP_ERP_SUCCEEDED;
2304 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2305 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2306 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2307 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2315 * purpose: this routine executes the 'Reopen Port' action
2317 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2318 * ZFCP_ERP_SUCCEEDED - action finished successfully
2319 * ZFCP_ERP_FAILED - action finished unsuccessfully
2322 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2324 int retval = ZFCP_ERP_FAILED;
2325 struct zfcp_port *port = erp_action->port;
2326 struct zfcp_adapter *adapter = erp_action->adapter;
2328 switch (erp_action->step) {
2332 * the ULP spec. begs for waiting for oustanding commands
2334 case ZFCP_ERP_STEP_UNINITIALIZED:
2335 zfcp_erp_port_strategy_clearstati(port);
2336 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2337 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2338 "close\n", port->wwpn);
2339 retval = zfcp_erp_port_strategy_close(erp_action);
2341 } /* else it's already closed, open it */
2344 case ZFCP_ERP_STEP_PORT_CLOSING:
2345 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2346 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2348 retval = ZFCP_ERP_FAILED;
2350 } /* else it's closed now, open it */
2353 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2354 retval = ZFCP_ERP_EXIT;
2356 retval = zfcp_erp_port_strategy_open(erp_action);
2359 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2360 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2361 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2362 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2368 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2372 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2373 &erp_action->port->status))
2374 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2376 retval = zfcp_erp_port_strategy_open_common(erp_action);
2382 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2385 struct zfcp_adapter *adapter = erp_action->adapter;
2386 struct zfcp_port *port = erp_action->port;
2388 switch (erp_action->step) {
2390 case ZFCP_ERP_STEP_UNINITIALIZED:
2391 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2392 case ZFCP_ERP_STEP_PORT_CLOSING:
2393 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2394 if (port->wwpn != adapter->peer_wwpn) {
2395 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2396 "on adapter %s.\nPeer WWPN "
2397 "0x%016Lx does not match\n",
2399 zfcp_get_busid_by_adapter(adapter),
2400 adapter->peer_wwpn);
2401 zfcp_erp_port_failed(port);
2402 retval = ZFCP_ERP_FAILED;
2405 port->d_id = adapter->peer_d_id;
2406 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2407 retval = zfcp_erp_port_strategy_open_port(erp_action);
2410 if (!(adapter->nameserver_port)) {
2411 retval = zfcp_nameserver_enqueue(adapter);
2413 ZFCP_LOG_NORMAL("error: nameserver port "
2414 "unavailable for adapter %s\n",
2415 zfcp_get_busid_by_adapter(adapter));
2416 retval = ZFCP_ERP_FAILED;
2420 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2421 &adapter->nameserver_port->status)) {
2422 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2423 "nameserver port\n");
2424 /* nameserver port may live again */
2425 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2426 &adapter->nameserver_port->status);
2427 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2430 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2431 retval = ZFCP_ERP_CONTINUES;
2433 retval = ZFCP_ERP_FAILED;
2436 /* else nameserver port is already open, fall through */
2437 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2438 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2439 &adapter->nameserver_port->status)) {
2440 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2441 retval = ZFCP_ERP_FAILED;
2443 ZFCP_LOG_DEBUG("nameserver port is open -> "
2444 "nameserver look-up for port 0x%016Lx\n",
2446 retval = zfcp_erp_port_strategy_open_common_lookup
2451 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2452 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2453 if (atomic_test_mask
2454 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2455 ZFCP_LOG_DEBUG("nameserver look-up failed "
2456 "for port 0x%016Lx "
2457 "(misconfigured WWPN?)\n",
2459 zfcp_erp_port_failed(port);
2460 retval = ZFCP_ERP_EXIT;
2462 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2463 "port 0x%016Lx\n", port->wwpn);
2464 retval = ZFCP_ERP_FAILED;
2467 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2468 "trying open\n", port->wwpn, port->d_id);
2469 retval = zfcp_erp_port_strategy_open_port(erp_action);
2473 case ZFCP_ERP_STEP_PORT_OPENING:
2474 /* D_ID might have changed during open */
2475 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2476 ZFCP_STATUS_PORT_DID_DID),
2478 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2479 retval = ZFCP_ERP_SUCCEEDED;
2481 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2483 retval = ZFCP_ERP_FAILED;
2488 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2490 retval = ZFCP_ERP_FAILED;
2497 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2500 struct zfcp_port *port = erp_action->port;
2502 switch (erp_action->step) {
2504 case ZFCP_ERP_STEP_UNINITIALIZED:
2505 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2506 case ZFCP_ERP_STEP_PORT_CLOSING:
2507 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2508 port->wwpn, port->d_id);
2509 retval = zfcp_erp_port_strategy_open_port(erp_action);
2512 case ZFCP_ERP_STEP_PORT_OPENING:
2513 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2514 ZFCP_LOG_DEBUG("WKA port is open\n");
2515 retval = ZFCP_ERP_SUCCEEDED;
2517 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2518 retval = ZFCP_ERP_FAILED;
2520 /* this is needed anyway (dont care for retval of wakeup) */
2521 ZFCP_LOG_DEBUG("continue other open port operations\n");
2522 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2526 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2528 retval = ZFCP_ERP_FAILED;
2537 * purpose: makes the erp thread continue with reopen (physical) port
2538 * actions which have been paused until the name server port
2539 * is opened (or failed)
2541 * returns: 0 (a kind of void retval, its not used)
2544 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2548 unsigned long flags;
2549 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2550 struct zfcp_erp_action *erp_action, *tmp;
2552 read_lock_irqsave(&adapter->erp_lock, flags);
2553 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2555 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2556 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2558 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2559 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2560 debug_event(adapter->erp_dbf, 3,
2561 &erp_action->port->wwpn, sizeof (wwn_t));
2562 if (atomic_test_mask(
2563 ZFCP_STATUS_COMMON_ERP_FAILED,
2564 &adapter->nameserver_port->status))
2565 zfcp_erp_port_failed(erp_action->port);
2566 zfcp_erp_action_ready(erp_action);
2569 read_unlock_irqrestore(&adapter->erp_lock, flags);
2579 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2580 * ZFCP_ERP_FAILED - action finished unsuccessfully
2583 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2586 struct zfcp_adapter *adapter = erp_action->adapter;
2587 struct zfcp_port *port = erp_action->port;
2589 retval = zfcp_fsf_close_physical_port(erp_action);
2590 if (retval == -ENOMEM) {
2591 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2592 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2593 retval = ZFCP_ERP_NOMEM;
2596 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2598 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2599 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2600 /* could not send 'open', fail */
2601 retval = ZFCP_ERP_FAILED;
2604 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2605 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2606 retval = ZFCP_ERP_CONTINUES;
2612 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2615 struct zfcp_adapter *adapter = port->adapter;
2617 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2618 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2620 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2621 ZFCP_STATUS_COMMON_CLOSING |
2622 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2623 ZFCP_STATUS_PORT_DID_DID |
2624 ZFCP_STATUS_PORT_PHYS_CLOSING |
2625 ZFCP_STATUS_PORT_INVALID_WWPN,
2635 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2636 * ZFCP_ERP_FAILED - action finished unsuccessfully
2639 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2642 struct zfcp_adapter *adapter = erp_action->adapter;
2643 struct zfcp_port *port = erp_action->port;
2645 retval = zfcp_fsf_close_port(erp_action);
2646 if (retval == -ENOMEM) {
2647 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2648 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2649 retval = ZFCP_ERP_NOMEM;
2652 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2654 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2655 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2656 /* could not send 'close', fail */
2657 retval = ZFCP_ERP_FAILED;
2660 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2661 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2662 retval = ZFCP_ERP_CONTINUES;
2672 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2673 * ZFCP_ERP_FAILED - action finished unsuccessfully
2676 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2679 struct zfcp_adapter *adapter = erp_action->adapter;
2680 struct zfcp_port *port = erp_action->port;
2682 retval = zfcp_fsf_open_port(erp_action);
2683 if (retval == -ENOMEM) {
2684 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2685 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2686 retval = ZFCP_ERP_NOMEM;
2689 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2691 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2692 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2693 /* could not send 'open', fail */
2694 retval = ZFCP_ERP_FAILED;
2697 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2698 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2699 retval = ZFCP_ERP_CONTINUES;
2709 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2710 * ZFCP_ERP_FAILED - action finished unsuccessfully
2713 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2716 struct zfcp_adapter *adapter = erp_action->adapter;
2717 struct zfcp_port *port = erp_action->port;
2719 retval = zfcp_ns_gid_pn_request(erp_action);
2720 if (retval == -ENOMEM) {
2721 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2722 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2723 retval = ZFCP_ERP_NOMEM;
2726 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2728 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2729 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2730 /* could not send nameserver request, fail */
2731 retval = ZFCP_ERP_FAILED;
2734 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2735 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2736 retval = ZFCP_ERP_CONTINUES;
2744 * purpose: this routine executes the 'Reopen Unit' action
2745 * currently no retries
2747 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2748 * ZFCP_ERP_SUCCEEDED - action finished successfully
2749 * ZFCP_ERP_FAILED - action finished unsuccessfully
2752 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2754 int retval = ZFCP_ERP_FAILED;
2755 struct zfcp_unit *unit = erp_action->unit;
2756 struct zfcp_adapter *adapter = erp_action->adapter;
2758 switch (erp_action->step) {
2762 * the ULP spec. begs for waiting for oustanding commands
2764 case ZFCP_ERP_STEP_UNINITIALIZED:
2765 zfcp_erp_unit_strategy_clearstati(unit);
2766 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2767 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2768 "trying close\n", unit->fcp_lun);
2769 retval = zfcp_erp_unit_strategy_close(erp_action);
2772 /* else it's already closed, fall through */
2773 case ZFCP_ERP_STEP_UNIT_CLOSING:
2774 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2775 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2777 retval = ZFCP_ERP_FAILED;
2779 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2780 retval = ZFCP_ERP_EXIT;
2782 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2783 "trying open\n", unit->fcp_lun);
2785 zfcp_erp_unit_strategy_open(erp_action);
2790 case ZFCP_ERP_STEP_UNIT_OPENING:
2791 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2792 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2794 retval = ZFCP_ERP_SUCCEEDED;
2796 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2798 retval = ZFCP_ERP_FAILED;
2803 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2804 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2805 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2806 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2811 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2814 struct zfcp_adapter *adapter = unit->port->adapter;
2816 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2817 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2819 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2820 ZFCP_STATUS_COMMON_CLOSING |
2821 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2822 ZFCP_STATUS_UNIT_SHARED |
2823 ZFCP_STATUS_UNIT_READONLY,
2834 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2835 * ZFCP_ERP_FAILED - action finished unsuccessfully
2838 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2841 struct zfcp_adapter *adapter = erp_action->adapter;
2842 struct zfcp_unit *unit = erp_action->unit;
2844 retval = zfcp_fsf_close_unit(erp_action);
2845 if (retval == -ENOMEM) {
2846 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2847 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2848 sizeof (fcp_lun_t));
2849 retval = ZFCP_ERP_NOMEM;
2852 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2854 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2855 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2856 sizeof (fcp_lun_t));
2857 /* could not send 'close', fail */
2858 retval = ZFCP_ERP_FAILED;
2861 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2862 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2863 retval = ZFCP_ERP_CONTINUES;
2874 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2875 * ZFCP_ERP_FAILED - action finished unsuccessfully
2878 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2881 struct zfcp_adapter *adapter = erp_action->adapter;
2882 struct zfcp_unit *unit = erp_action->unit;
2884 retval = zfcp_fsf_open_unit(erp_action);
2885 if (retval == -ENOMEM) {
2886 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2887 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2888 sizeof (fcp_lun_t));
2889 retval = ZFCP_ERP_NOMEM;
2892 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2894 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2895 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2896 sizeof (fcp_lun_t));
2897 /* could not send 'open', fail */
2898 retval = ZFCP_ERP_FAILED;
2901 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2902 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2903 retval = ZFCP_ERP_CONTINUES;
2908 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2910 BUG_ON(!fsf_req->erp_action);
2911 fsf_req->timer.function = zfcp_erp_timeout_handler;
2912 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2913 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2914 add_timer(&fsf_req->timer);
2920 * purpose: enqueue the specified error recovery action, if needed
2925 zfcp_erp_action_enqueue(int action,
2926 struct zfcp_adapter *adapter,
2927 struct zfcp_port *port, struct zfcp_unit *unit)
2930 struct zfcp_erp_action *erp_action = NULL;
2931 int stronger_action = 0;
2935 * We need some rules here which check whether we really need
2936 * this action or whether we should just drop it.
2937 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2938 * 'Reopen Unit' request for an associated unit since we can't
2939 * satisfy this request now. A 'Reopen Port' action will trigger
2940 * 'Reopen Unit' actions when it completes.
2941 * Thus, there are only actions in the queue which can immediately be
2942 * executed. This makes the processing of the action queue more
2946 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2950 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2951 /* check whether we really need this */
2953 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2954 if (atomic_test_mask
2955 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2956 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2957 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2959 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2960 sizeof (fcp_lun_t));
2963 if (!atomic_test_mask
2964 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2966 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2969 if (!atomic_test_mask
2970 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2971 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2974 /* fall through !!! */
2976 case ZFCP_ERP_ACTION_REOPEN_PORT:
2977 if (atomic_test_mask
2978 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2979 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2980 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2984 /* fall through !!! */
2986 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2987 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2989 if (port->erp_action.action !=
2990 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2991 ZFCP_LOG_INFO("dropped erp action %i (port "
2992 "0x%016Lx, action in use: %i)\n",
2994 port->erp_action.action);
2995 debug_text_event(adapter->erp_dbf, 4,
2998 debug_text_event(adapter->erp_dbf, 4,
3000 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3004 if (!atomic_test_mask
3005 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3007 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3010 if (!atomic_test_mask
3011 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3012 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3015 /* fall through !!! */
3017 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3018 if (atomic_test_mask
3019 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3020 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3026 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3027 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3028 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3029 "on adapter %s (action=%d)\n",
3030 zfcp_get_busid_by_adapter(adapter), action);
3034 /* check whether we need something stronger first */
3035 if (stronger_action) {
3036 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3037 debug_event(adapter->erp_dbf, 4, &stronger_action,
3039 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3040 "erp action %d on adapter %s\n",
3041 stronger_action, action,
3042 zfcp_get_busid_by_adapter(adapter));
3043 action = stronger_action;
3046 /* mark adapter to have some error recovery pending */
3047 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3049 /* setup error recovery action */
3052 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3053 zfcp_unit_get(unit);
3054 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3055 erp_action = &unit->erp_action;
3056 if (!atomic_test_mask
3057 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3058 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3061 case ZFCP_ERP_ACTION_REOPEN_PORT:
3062 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3063 zfcp_port_get(port);
3064 zfcp_erp_action_dismiss_port(port);
3065 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3066 erp_action = &port->erp_action;
3067 if (!atomic_test_mask
3068 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3069 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3072 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3073 zfcp_adapter_get(adapter);
3074 zfcp_erp_action_dismiss_adapter(adapter);
3075 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3076 erp_action = &adapter->erp_action;
3077 if (!atomic_test_mask
3078 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3079 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3083 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3085 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3086 erp_action->adapter = adapter;
3087 erp_action->port = port;
3088 erp_action->unit = unit;
3089 erp_action->action = action;
3090 erp_action->status = status;
3092 ++adapter->erp_total_count;
3094 /* finally put it into 'ready' queue and kick erp thread */
3095 list_add(&erp_action->list, &adapter->erp_ready_head);
3096 up(&adapter->erp_ready_sem);
3103 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3106 struct zfcp_adapter *adapter = erp_action->adapter;
3108 --adapter->erp_total_count;
3109 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3110 --adapter->erp_low_mem_count;
3111 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3114 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3115 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3116 list_del(&erp_action->list);
3117 switch (erp_action->action) {
3118 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3119 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3120 &erp_action->unit->status);
3122 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3123 case ZFCP_ERP_ACTION_REOPEN_PORT:
3124 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3125 &erp_action->port->status);
3127 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3128 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3129 &erp_action->adapter->status);
3139 * zfcp_erp_action_cleanup
3141 * Register unit with scsi stack if appropriate and fix reference counts.
3142 * Note: Temporary units are not registered with scsi stack.
3145 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3146 struct zfcp_port *port, struct zfcp_unit *unit,
3150 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3151 if ((result == ZFCP_ERP_SUCCEEDED)
3152 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3156 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3158 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3159 &unit->status) == 0)
3160 zfcp_erp_schedule_work(unit);
3162 zfcp_unit_put(unit);
3164 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3165 case ZFCP_ERP_ACTION_REOPEN_PORT:
3166 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3168 zfcp_port_put(port);
3172 if ((result == ZFCP_ERP_SUCCEEDED)
3174 struct fc_rport_identifiers ids;
3175 ids.node_name = port->wwnn;
3176 ids.port_name = port->wwpn;
3177 ids.port_id = port->d_id;
3178 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3180 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3182 ZFCP_LOG_NORMAL("failed registration of rport"
3183 "(adapter %s, wwpn=0x%016Lx)\n",
3184 zfcp_get_busid_by_port(port),
3187 scsi_target_unblock(&port->rport->dev);
3188 port->rport->maxframe_size = port->maxframe_size;
3189 port->rport->supported_classes =
3190 port->supported_classes;
3193 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3194 fc_remote_port_delete(port->rport);
3197 zfcp_port_put(port);
3199 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3200 if (result != ZFCP_ERP_SUCCEEDED) {
3201 list_for_each_entry(port, &adapter->port_list_head, list)
3203 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3205 fc_remote_port_delete(port->rport);
3209 zfcp_adapter_put(adapter);
3217 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3219 struct zfcp_port *port;
3221 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3222 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3223 zfcp_erp_action_dismiss(&adapter->erp_action);
3225 list_for_each_entry(port, &adapter->port_list_head, list)
3226 zfcp_erp_action_dismiss_port(port);
3229 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3231 struct zfcp_unit *unit;
3232 struct zfcp_adapter *adapter = port->adapter;
3234 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3235 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3236 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3237 zfcp_erp_action_dismiss(&port->erp_action);
3239 list_for_each_entry(unit, &port->unit_list_head, list)
3240 zfcp_erp_action_dismiss_unit(unit);
3243 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3245 struct zfcp_adapter *adapter = unit->port->adapter;
3247 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3248 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3249 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3250 zfcp_erp_action_dismiss(&unit->erp_action);
3253 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3255 struct zfcp_adapter *adapter = erp_action->adapter;
3257 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3258 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3259 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3262 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3264 struct zfcp_adapter *adapter = erp_action->adapter;
3266 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3267 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3268 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3272 zfcp_erp_port_boxed(struct zfcp_port *port)
3274 struct zfcp_adapter *adapter = port->adapter;
3275 unsigned long flags;
3277 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3278 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3279 read_lock_irqsave(&zfcp_data.config_lock, flags);
3280 zfcp_erp_modify_port_status(port,
3281 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3283 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3284 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3288 zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3290 struct zfcp_adapter *adapter = unit->port->adapter;
3292 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3293 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3294 zfcp_erp_modify_unit_status(unit,
3295 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3297 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3301 zfcp_erp_port_access_denied(struct zfcp_port *port)
3303 struct zfcp_adapter *adapter = port->adapter;
3304 unsigned long flags;
3306 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3307 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3308 read_lock_irqsave(&zfcp_data.config_lock, flags);
3309 zfcp_erp_modify_port_status(port,
3310 ZFCP_STATUS_COMMON_ERP_FAILED |
3311 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3313 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3317 zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3319 struct zfcp_adapter *adapter = unit->port->adapter;
3321 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3322 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3323 zfcp_erp_modify_unit_status(unit,
3324 ZFCP_STATUS_COMMON_ERP_FAILED |
3325 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3330 zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3332 struct zfcp_port *port;
3333 unsigned long flags;
3335 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3338 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3339 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3341 read_lock_irqsave(&zfcp_data.config_lock, flags);
3342 if (adapter->nameserver_port)
3343 zfcp_erp_port_access_changed(adapter->nameserver_port);
3344 list_for_each_entry(port, &adapter->port_list_head, list)
3345 if (port != adapter->nameserver_port)
3346 zfcp_erp_port_access_changed(port);
3347 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3351 zfcp_erp_port_access_changed(struct zfcp_port *port)
3353 struct zfcp_adapter *adapter = port->adapter;
3354 struct zfcp_unit *unit;
3356 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3357 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3359 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3361 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3363 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3364 list_for_each_entry(unit, &port->unit_list_head, list)
3365 zfcp_erp_unit_access_changed(unit);
3369 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3370 "(due to ACT update)\n",
3371 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3372 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3373 ZFCP_LOG_NORMAL("failed reopen of port"
3374 "(adapter %s, wwpn=0x%016Lx)\n",
3375 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3379 zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3381 struct zfcp_adapter *adapter = unit->port->adapter;
3383 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3384 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3386 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3388 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3392 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3393 " on adapter %s (due to ACT update)\n",
3394 unit->fcp_lun, unit->port->wwpn,
3395 zfcp_get_busid_by_adapter(adapter));
3396 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3397 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3398 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3399 zfcp_get_busid_by_adapter(adapter),
3400 unit->port->wwpn, unit->fcp_lun);
3403 #undef ZFCP_LOG_AREA