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, u8,
31 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int, u8,
33 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int, u8, u64);
34 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int, u8, u64);
36 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int, u8,
38 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int, u8, u64);
40 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
41 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
42 static void zfcp_erp_port_block(struct zfcp_port *, int);
43 static void zfcp_erp_port_unblock(struct zfcp_port *);
44 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
45 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
47 static int zfcp_erp_thread(void *);
49 static int zfcp_erp_strategy(struct zfcp_erp_action *);
51 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
52 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
53 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
54 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
55 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
56 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
57 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
59 struct zfcp_unit *, int);
60 static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
61 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
63 struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
65 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
67 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
68 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
69 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
73 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
74 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
75 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
76 struct zfcp_erp_action *);
78 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
79 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
82 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
83 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
84 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
86 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
87 struct zfcp_erp_action *);
88 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
89 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
90 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
93 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
94 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
95 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
97 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
98 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
99 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
100 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
102 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
103 struct zfcp_port *, struct zfcp_unit *,
105 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
106 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
107 struct zfcp_port *, struct zfcp_unit *,
110 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
111 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
113 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
114 static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
116 static void zfcp_erp_memwait_handler(unsigned long);
119 * zfcp_close_qdio - close qdio queues for an adapter
121 static void zfcp_close_qdio(struct zfcp_adapter *adapter)
123 struct zfcp_qdio_queue *req_queue;
126 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
129 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
130 req_queue = &adapter->request_queue;
131 write_lock_irq(&req_queue->queue_lock);
132 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
133 write_unlock_irq(&req_queue->queue_lock);
135 while (qdio_shutdown(adapter->ccw_device,
136 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
139 /* cleanup used outbound sbals */
140 count = atomic_read(&req_queue->free_count);
141 if (count < QDIO_MAX_BUFFERS_PER_Q) {
142 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
143 count = QDIO_MAX_BUFFERS_PER_Q - count;
144 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
146 req_queue->free_index = 0;
147 atomic_set(&req_queue->free_count, 0);
148 req_queue->distance_from_int = 0;
149 adapter->response_queue.free_index = 0;
150 atomic_set(&adapter->response_queue.free_count, 0);
154 * zfcp_close_fsf - stop FSF operations for an adapter
156 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
157 * requests waiting for completion; especially this returns SCSI commands
160 static void zfcp_close_fsf(struct zfcp_adapter *adapter)
162 /* close queues to ensure that buffers are not accessed by adapter */
163 zfcp_close_qdio(adapter);
164 zfcp_fsf_req_dismiss_all(adapter);
165 /* reset FSF request sequence number */
166 adapter->fsf_req_seq_no = 0;
167 /* all ports and units are closed */
168 zfcp_erp_modify_adapter_status(adapter, 24, 0,
169 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
173 * zfcp_fsf_request_timeout_handler - called if a request timed out
174 * @data: pointer to adapter for handler function
176 * This function needs to be called if requests (ELS, Generic Service,
177 * or SCSI commands) exceed a certain time limit. The assumption is
178 * that after the time limit the adapter get stuck. So we trigger a reopen of
181 static void zfcp_fsf_request_timeout_handler(unsigned long data)
183 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
184 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62, 0);
187 void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
189 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
190 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
191 fsf_req->timer.expires = jiffies + timeout;
192 add_timer(&fsf_req->timer);
198 * purpose: called if an adapter failed,
199 * initiates adapter recovery which is done
202 * returns: 0 - initiated action successfully
203 * <0 - failed to initiate action
205 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter,
206 int clear_mask, u8 id, u64 ref)
210 ZFCP_LOG_DEBUG("reopen adapter %s\n",
211 zfcp_get_busid_by_adapter(adapter));
213 zfcp_erp_adapter_block(adapter, clear_mask);
215 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
216 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
217 zfcp_get_busid_by_adapter(adapter));
218 /* ensure propagation of failed status to new devices */
219 zfcp_erp_adapter_failed(adapter, 13, 0);
223 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
224 adapter, NULL, NULL, id, ref);
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
239 int 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, id, ref);
248 write_unlock(&adapter->erp_lock);
249 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
254 int 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 |
262 clear_mask, id, ref);
267 int zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask, u8 id,
272 retval = zfcp_erp_port_reopen(port,
273 ZFCP_STATUS_COMMON_RUNNING |
274 ZFCP_STATUS_COMMON_ERP_FAILED |
275 clear_mask, id, ref);
280 int zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask, u8 id,
285 retval = zfcp_erp_unit_reopen(unit,
286 ZFCP_STATUS_COMMON_RUNNING |
287 ZFCP_STATUS_COMMON_ERP_FAILED |
288 clear_mask, id, ref);
295 * zfcp_erp_adisc - send ADISC ELS command
296 * @port: port structure
299 zfcp_erp_adisc(struct zfcp_port *port)
301 struct zfcp_adapter *adapter = port->adapter;
302 struct zfcp_send_els *send_els;
303 struct zfcp_ls_adisc *adisc;
304 void *address = NULL;
307 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
308 if (send_els == NULL)
311 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
312 if (send_els->req == NULL)
314 sg_init_table(send_els->req, 1);
316 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
317 if (send_els->resp == NULL)
319 sg_init_table(send_els->resp, 1);
321 address = (void *) get_zeroed_page(GFP_ATOMIC);
325 zfcp_address_to_sg(address, send_els->req, sizeof(struct zfcp_ls_adisc));
326 address += PAGE_SIZE >> 1;
327 zfcp_address_to_sg(address, send_els->resp, sizeof(struct zfcp_ls_adisc_acc));
328 send_els->req_count = send_els->resp_count = 1;
330 send_els->adapter = adapter;
331 send_els->port = port;
332 send_els->d_id = port->d_id;
333 send_els->handler = zfcp_erp_adisc_handler;
334 send_els->handler_data = (unsigned long) send_els;
336 adisc = zfcp_sg_to_address(send_els->req);
337 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
339 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
340 without FC-AL-2 capability, so we don't set it */
341 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
342 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
343 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
344 ZFCP_LOG_INFO("ADISC request from s_id 0x%06x to d_id 0x%06x "
345 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
346 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
347 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
348 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
351 retval = zfcp_fsf_send_els(send_els);
353 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
354 "0x%06x on adapter %s\n", send_els->d_id,
355 zfcp_get_busid_by_adapter(adapter));
365 __free_pages(sg_page(send_els->req), 0);
366 if (send_els != NULL) {
367 kfree(send_els->req);
368 kfree(send_els->resp);
377 * zfcp_erp_adisc_handler - handler for ADISC ELS command
378 * @data: pointer to struct zfcp_send_els
380 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
383 zfcp_erp_adisc_handler(unsigned long data)
385 struct zfcp_send_els *send_els;
386 struct zfcp_port *port;
387 struct zfcp_adapter *adapter;
389 struct zfcp_ls_adisc_acc *adisc;
391 send_els = (struct zfcp_send_els *) data;
392 adapter = send_els->adapter;
393 port = send_els->port;
394 d_id = send_els->d_id;
396 /* request rejected or timed out */
397 if (send_els->status != 0) {
398 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
399 "force physical port reopen "
400 "(adapter %s, port d_id=0x%06x)\n",
401 zfcp_get_busid_by_adapter(adapter), d_id);
402 if (zfcp_erp_port_forced_reopen(port, 0, 63, 0))
403 ZFCP_LOG_NORMAL("failed reopen of port "
404 "(adapter %s, wwpn=0x%016Lx)\n",
405 zfcp_get_busid_by_port(port),
410 adisc = zfcp_sg_to_address(send_els->resp);
412 ZFCP_LOG_INFO("ADISC response from d_id 0x%06x to s_id "
413 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
414 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
415 d_id, fc_host_port_id(adapter->scsi_host),
416 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
417 adisc->hard_nport_id, adisc->nport_id);
419 /* set wwnn for port */
421 port->wwnn = adisc->wwnn;
423 if (port->wwpn != adisc->wwpn) {
424 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
425 "port (adapter %s, wwpn=0x%016Lx, "
426 "adisc_resp_wwpn=0x%016Lx)\n",
427 zfcp_get_busid_by_port(port),
428 port->wwpn, (wwn_t) adisc->wwpn);
429 if (zfcp_erp_port_reopen(port, 0, 64, 0))
430 ZFCP_LOG_NORMAL("failed reopen of port "
431 "(adapter %s, wwpn=0x%016Lx)\n",
432 zfcp_get_busid_by_port(port),
438 __free_pages(sg_page(send_els->req), 0);
439 kfree(send_els->req);
440 kfree(send_els->resp);
446 * zfcp_test_link - lightweight link test procedure
447 * @port: port to be tested
449 * Test status of a link to a remote port using the ELS command ADISC.
452 zfcp_test_link(struct zfcp_port *port)
457 retval = zfcp_erp_adisc(port);
458 if (retval != 0 && retval != -EBUSY) {
460 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
461 "on adapter %s\n ", port->wwpn,
462 zfcp_get_busid_by_port(port));
463 retval = zfcp_erp_port_forced_reopen(port, 0, 65, 0);
465 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
466 "on adapter %s failed\n", port->wwpn,
467 zfcp_get_busid_by_port(port));
479 * purpose: called if a port failed to be opened normally
480 * initiates Forced Reopen recovery which is done
483 * returns: 0 - initiated action successfully
484 * <0 - failed to initiate action
486 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port,
487 int clear_mask, u8 id, u64 ref)
491 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
492 port->wwpn, zfcp_get_busid_by_port(port));
494 zfcp_erp_port_block(port, clear_mask);
496 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
497 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
498 "on adapter %s\n", port->wwpn,
499 zfcp_get_busid_by_port(port));
504 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
505 port->adapter, port, NULL, id, ref);
514 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
515 * used to ensure the correct locking
517 * returns: 0 - initiated action successfully
518 * <0 - failed to initiate action
520 int zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask, u8 id,
525 struct zfcp_adapter *adapter;
527 adapter = port->adapter;
528 read_lock_irqsave(&zfcp_data.config_lock, flags);
529 write_lock(&adapter->erp_lock);
530 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask, id,
532 write_unlock(&adapter->erp_lock);
533 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
541 * purpose: called if a port is to be opened
542 * initiates Reopen recovery which is done
545 * returns: 0 - initiated action successfully
546 * <0 - failed to initiate action
548 static int zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask,
553 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
554 port->wwpn, zfcp_get_busid_by_port(port));
556 zfcp_erp_port_block(port, clear_mask);
558 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
559 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
560 "on adapter %s\n", port->wwpn,
561 zfcp_get_busid_by_port(port));
562 /* ensure propagation of failed status to new devices */
563 zfcp_erp_port_failed(port, 14, 0);
568 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
569 port->adapter, port, NULL, id, ref);
576 * zfcp_erp_port_reopen - initiate reopen of a remote port
577 * @port: port to be reopened
578 * @clear_mask: specifies flags in port status to be cleared
579 * Return: 0 on success, < 0 on error
581 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
582 * correct locking. An error recovery task is initiated to do the reopen.
583 * To wait for the completion of the reopen zfcp_erp_wait should be used.
585 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask, u8 id, u64 ref)
589 struct zfcp_adapter *adapter = port->adapter;
591 read_lock_irqsave(&zfcp_data.config_lock, flags);
592 write_lock(&adapter->erp_lock);
593 retval = zfcp_erp_port_reopen_internal(port, clear_mask, id, ref);
594 write_unlock(&adapter->erp_lock);
595 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
603 * purpose: called if a unit is to be opened
604 * initiates Reopen recovery which is done
607 * returns: 0 - initiated action successfully
608 * <0 - failed to initiate action
610 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask,
614 struct zfcp_adapter *adapter = unit->port->adapter;
616 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
617 "on adapter %s\n", unit->fcp_lun,
618 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
620 zfcp_erp_unit_block(unit, clear_mask);
622 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
623 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
624 "on port 0x%016Lx on adapter %s\n",
625 unit->fcp_lun, unit->port->wwpn,
626 zfcp_get_busid_by_unit(unit));
631 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
632 adapter, unit->port, unit, id, ref);
638 * zfcp_erp_unit_reopen - initiate reopen of a unit
639 * @unit: unit to be reopened
640 * @clear_mask: specifies flags in unit status to be cleared
641 * Return: 0 on success, < 0 on error
643 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
644 * locking. An error recovery task is initiated to do the reopen.
645 * To wait for the completion of the reopen zfcp_erp_wait should be used.
647 int zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask, u8 id, u64 ref)
651 struct zfcp_adapter *adapter;
652 struct zfcp_port *port;
655 adapter = port->adapter;
657 read_lock_irqsave(&zfcp_data.config_lock, flags);
658 write_lock(&adapter->erp_lock);
659 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
660 write_unlock(&adapter->erp_lock);
661 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
667 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
669 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
671 zfcp_erp_modify_adapter_status(adapter, 15, 0,
672 ZFCP_STATUS_COMMON_UNBLOCKED |
673 clear_mask, ZFCP_CLEAR);
676 /* FIXME: isn't really atomic */
678 * returns the mask which has not been set so far, i.e.
679 * 0 if no bit has been changed, !0 if some bit has been changed
681 static int atomic_test_and_set_mask(unsigned long mask, atomic_t *v)
683 int changed_bits = (atomic_read(v) /*XOR*/^ mask) & mask;
684 atomic_set_mask(mask, v);
688 /* FIXME: isn't really atomic */
690 * returns the mask which has not been cleared so far, i.e.
691 * 0 if no bit has been changed, !0 if some bit has been changed
693 static int atomic_test_and_clear_mask(unsigned long mask, atomic_t *v)
695 int changed_bits = atomic_read(v) & mask;
696 atomic_clear_mask(mask, v);
701 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
703 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
705 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
707 zfcp_rec_dbf_event_adapter(16, 0, adapter);
713 * purpose: disable I/O,
714 * return any open requests and clean them up,
715 * aim: no pending and incoming I/O
720 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
722 zfcp_erp_modify_port_status(port, 17, 0,
723 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
730 * purpose: enable I/O
735 zfcp_erp_port_unblock(struct zfcp_port *port)
737 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
739 zfcp_rec_dbf_event_port(18, 0, port);
745 * purpose: disable I/O,
746 * return any open requests and clean them up,
747 * aim: no pending and incoming I/O
752 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
754 zfcp_erp_modify_unit_status(unit, 19, 0,
755 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
762 * purpose: enable I/O
767 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
769 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
771 zfcp_rec_dbf_event_unit(20, 0, unit);
775 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
777 struct zfcp_adapter *adapter = erp_action->adapter;
779 zfcp_erp_action_to_ready(erp_action);
780 up(&adapter->erp_ready_sem);
781 zfcp_rec_dbf_event_thread(2, adapter, 0);
789 * returns: <0 erp_action not found in any list
790 * ZFCP_ERP_ACTION_READY erp_action is in ready list
791 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
793 * locks: erp_lock must be held
796 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
798 int retval = -EINVAL;
799 struct list_head *entry;
800 struct zfcp_erp_action *entry_erp_action;
801 struct zfcp_adapter *adapter = erp_action->adapter;
803 /* search in running list */
804 list_for_each(entry, &adapter->erp_running_head) {
806 list_entry(entry, struct zfcp_erp_action, list);
807 if (entry_erp_action == erp_action) {
808 retval = ZFCP_ERP_ACTION_RUNNING;
812 /* search in ready list */
813 list_for_each(entry, &adapter->erp_ready_head) {
815 list_entry(entry, struct zfcp_erp_action, list);
816 if (entry_erp_action == erp_action) {
817 retval = ZFCP_ERP_ACTION_READY;
827 * purpose: checks current status of action (timed out, dismissed, ...)
828 * and does appropriate preparations (dismiss fsf request, ...)
830 * locks: called under erp_lock (disabled interrupts)
833 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
835 struct zfcp_adapter *adapter = erp_action->adapter;
837 if (erp_action->fsf_req) {
838 /* take lock to ensure that request is not deleted meanwhile */
839 spin_lock(&adapter->req_list_lock);
840 if (zfcp_reqlist_find_safe(adapter, erp_action->fsf_req) &&
841 erp_action->fsf_req->erp_action == erp_action) {
842 /* fsf_req still exists */
843 /* dismiss fsf_req of timed out/dismissed erp_action */
844 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
845 ZFCP_STATUS_ERP_TIMEDOUT)) {
846 erp_action->fsf_req->status |=
847 ZFCP_STATUS_FSFREQ_DISMISSED;
848 zfcp_rec_dbf_event_action(142, erp_action);
850 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
851 zfcp_rec_dbf_event_action(143, erp_action);
852 ZFCP_LOG_NORMAL("error: erp step timed out "
853 "(action=%d, fsf_req=%p)\n ",
855 erp_action->fsf_req);
858 * If fsf_req is neither dismissed nor completed
859 * then keep it running asynchronously and don't mess
860 * with the association of erp_action and fsf_req.
862 if (erp_action->fsf_req->status &
863 (ZFCP_STATUS_FSFREQ_COMPLETED |
864 ZFCP_STATUS_FSFREQ_DISMISSED)) {
865 /* forget about association between fsf_req
867 erp_action->fsf_req = NULL;
871 * even if this fsf_req has gone, forget about
872 * association between erp_action and fsf_req
874 erp_action->fsf_req = NULL;
876 spin_unlock(&adapter->req_list_lock);
881 * zfcp_erp_async_handler_nolock - complete erp_action
883 * Used for normal completion, time-out, dismissal and failure after
884 * low memory condition.
886 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
887 unsigned long set_mask)
889 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
890 erp_action->status |= set_mask;
891 zfcp_erp_action_ready(erp_action);
893 /* action is ready or gone - nothing to do */
898 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
900 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
901 unsigned long set_mask)
903 struct zfcp_adapter *adapter = erp_action->adapter;
906 write_lock_irqsave(&adapter->erp_lock, flags);
907 zfcp_erp_async_handler_nolock(erp_action, set_mask);
908 write_unlock_irqrestore(&adapter->erp_lock, flags);
912 * purpose: is called for erp_action which was slept waiting for
913 * memory becoming avaliable,
914 * will trigger that this action will be continued
917 zfcp_erp_memwait_handler(unsigned long data)
919 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
921 zfcp_erp_async_handler(erp_action, 0);
925 * purpose: is called if an asynchronous erp step timed out,
926 * action gets an appropriate flag and will be processed
929 static void zfcp_erp_timeout_handler(unsigned long data)
931 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
933 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
937 * zfcp_erp_action_dismiss - dismiss an erp_action
939 * adapter->erp_lock must be held
941 * Dismissal of an erp_action is usually required if an erp_action of
942 * higher priority is generated.
944 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
946 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
947 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
948 zfcp_erp_action_ready(erp_action);
952 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
956 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
958 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
960 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
962 zfcp_get_busid_by_adapter(adapter));
964 wait_event(adapter->erp_thread_wqh,
965 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
979 * context: process (i.e. proc-fs or rmmod/insmod)
981 * note: The caller of this routine ensures that the specified
982 * adapter has been shut down and that this operation
983 * has been completed. Thus, there are no pending erp_actions
984 * which would need to be handled here.
987 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
991 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
992 up(&adapter->erp_ready_sem);
993 zfcp_rec_dbf_event_thread(2, adapter, 1);
995 wait_event(adapter->erp_thread_wqh,
996 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
999 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1006 * purpose: is run as a kernel thread,
1007 * goes through list of error recovery actions of associated adapter
1008 * and delegates single action to execution
1013 zfcp_erp_thread(void *data)
1015 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1016 struct list_head *next;
1017 struct zfcp_erp_action *erp_action;
1018 unsigned long flags;
1020 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1021 /* Block all signals */
1022 siginitsetinv(¤t->blocked, 0);
1023 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1024 wake_up(&adapter->erp_thread_wqh);
1026 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1027 &adapter->status)) {
1029 write_lock_irqsave(&adapter->erp_lock, flags);
1030 next = adapter->erp_ready_head.next;
1031 write_unlock_irqrestore(&adapter->erp_lock, flags);
1033 if (next != &adapter->erp_ready_head) {
1035 list_entry(next, struct zfcp_erp_action, list);
1037 * process action (incl. [re]moving it
1038 * from 'ready' queue)
1040 zfcp_erp_strategy(erp_action);
1044 * sleep as long as there is nothing to do, i.e.
1045 * no action in 'ready' queue to be processed and
1046 * thread is not to be killed
1048 zfcp_rec_dbf_event_thread(4, adapter, 1);
1049 down_interruptible(&adapter->erp_ready_sem);
1050 zfcp_rec_dbf_event_thread(5, adapter, 1);
1053 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1054 wake_up(&adapter->erp_thread_wqh);
1062 * purpose: drives single error recovery action and schedules higher and
1063 * subordinate actions, if necessary
1065 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1066 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1067 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1068 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1069 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1072 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1075 struct zfcp_adapter *adapter = erp_action->adapter;
1076 struct zfcp_port *port = erp_action->port;
1077 struct zfcp_unit *unit = erp_action->unit;
1078 int action = erp_action->action;
1079 u32 status = erp_action->status;
1080 unsigned long flags;
1082 /* serialise dismissing, timing out, moving, enqueueing */
1083 read_lock_irqsave(&zfcp_data.config_lock, flags);
1084 write_lock(&adapter->erp_lock);
1086 /* dequeue dismissed action and leave, if required */
1087 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1088 if (retval == ZFCP_ERP_DISMISSED) {
1093 * move action to 'running' queue before processing it
1094 * (to avoid a race condition regarding moving the
1095 * action to the 'running' queue and back)
1097 zfcp_erp_action_to_running(erp_action);
1100 * try to process action as far as possible,
1101 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1102 * afterwards the lock is required again for the following reasons:
1103 * - dequeueing of finished action and enqueueing of
1104 * follow-up actions must be atomic so that any other
1105 * reopen-routine does not believe there is nothing to do
1106 * and that it is safe to enqueue something else,
1107 * - we want to force any control thread which is dismissing
1108 * actions to finish this before we decide about
1109 * necessary steps to be taken here further
1111 write_unlock(&adapter->erp_lock);
1112 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1113 retval = zfcp_erp_strategy_do_action(erp_action);
1114 read_lock_irqsave(&zfcp_data.config_lock, flags);
1115 write_lock(&adapter->erp_lock);
1118 * check for dismissed status again to avoid follow-up actions,
1119 * failing of targets and so on for dismissed actions,
1120 * we go through down() here because there has been an up()
1122 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1123 retval = ZFCP_ERP_CONTINUES;
1126 case ZFCP_ERP_NOMEM:
1127 /* no memory to continue immediately, let it sleep */
1128 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1129 ++adapter->erp_low_mem_count;
1130 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1132 /* This condition is true if there is no memory available
1133 for any erp_action on this adapter. This implies that there
1134 are no elements in the memory pool(s) left for erp_actions.
1135 This might happen if an erp_action that used a memory pool
1136 element was timed out.
1138 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1139 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1140 "restarting I/O on adapter %s "
1141 "to free mempool\n",
1142 zfcp_get_busid_by_adapter(adapter));
1143 zfcp_erp_adapter_reopen_internal(adapter, 0, 66, 0);
1145 retval = zfcp_erp_strategy_memwait(erp_action);
1148 case ZFCP_ERP_CONTINUES:
1149 /* leave since this action runs asynchronously */
1150 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1151 --adapter->erp_low_mem_count;
1152 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1156 /* ok, finished action (whatever its result is) */
1158 /* check for unrecoverable targets */
1159 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1161 /* action must be dequeued (here to allow for further ones) */
1162 zfcp_erp_action_dequeue(erp_action);
1165 * put this target through the erp mill again if someone has
1166 * requested to change the status of a target being online
1167 * to offline or the other way around
1168 * (old retval is preserved if nothing has to be done here)
1170 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1171 port, unit, retval);
1174 * leave if target is in permanent error state or if
1175 * action is repeated in order to process state change
1177 if (retval == ZFCP_ERP_EXIT) {
1181 /* trigger follow up actions */
1182 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1185 write_unlock(&adapter->erp_lock);
1186 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1188 if (retval != ZFCP_ERP_CONTINUES)
1189 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1192 * a few tasks remain when the erp queues are empty
1193 * (don't do that if the last action evaluated was dismissed
1194 * since this clearly indicates that there is more to come) :
1195 * - close the name server port if it is open yet
1196 * (enqueues another [probably] final action)
1197 * - otherwise, wake up whoever wants to be woken when we are
1200 if (retval != ZFCP_ERP_DISMISSED)
1201 zfcp_erp_strategy_check_queues(adapter);
1211 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1212 * retval - otherwise
1215 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1217 zfcp_erp_strategy_check_fsfreq(erp_action);
1219 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1220 zfcp_erp_action_dequeue(erp_action);
1221 retval = ZFCP_ERP_DISMISSED;
1228 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1230 int retval = ZFCP_ERP_FAILED;
1233 * try to execute/continue action as far as possible,
1234 * note: no lock in subsequent strategy routines
1235 * (this allows these routine to call schedule, e.g.
1236 * kmalloc with such flags or qdio_initialize & friends)
1237 * Note: in case of timeout, the separate strategies will fail
1238 * anyhow. No need for a special action. Even worse, a nameserver
1239 * failure would not wake up waiting ports without the call.
1241 switch (erp_action->action) {
1243 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1244 retval = zfcp_erp_adapter_strategy(erp_action);
1247 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1248 retval = zfcp_erp_port_forced_strategy(erp_action);
1251 case ZFCP_ERP_ACTION_REOPEN_PORT:
1252 retval = zfcp_erp_port_strategy(erp_action);
1255 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1256 retval = zfcp_erp_unit_strategy(erp_action);
1260 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1261 "adapter %s (action=%d)\n",
1262 zfcp_get_busid_by_adapter(erp_action->adapter),
1263 erp_action->action);
1272 * purpose: triggers retry of this action after a certain amount of time
1273 * by means of timer provided by erp_action
1275 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1278 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1280 int retval = ZFCP_ERP_CONTINUES;
1282 init_timer(&erp_action->timer);
1283 erp_action->timer.function = zfcp_erp_memwait_handler;
1284 erp_action->timer.data = (unsigned long) erp_action;
1285 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1286 add_timer(&erp_action->timer);
1292 * function: zfcp_erp_adapter_failed
1294 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1298 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, u64 ref)
1300 zfcp_erp_modify_adapter_status(adapter, id, ref,
1301 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1302 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1303 zfcp_get_busid_by_adapter(adapter));
1307 * function: zfcp_erp_port_failed
1309 * purpose: sets the port and all underlying devices to ERP_FAILED
1313 zfcp_erp_port_failed(struct zfcp_port *port, u8 id, u64 ref)
1315 zfcp_erp_modify_port_status(port, id, ref,
1316 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1318 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1319 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1320 "port d_id=0x%06x)\n",
1321 zfcp_get_busid_by_port(port), port->d_id);
1323 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1324 zfcp_get_busid_by_port(port), port->wwpn);
1328 * function: zfcp_erp_unit_failed
1330 * purpose: sets the unit to ERP_FAILED
1334 zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, u64 ref)
1336 zfcp_erp_modify_unit_status(unit, id, ref,
1337 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1339 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1340 " on adapter %s\n", unit->fcp_lun,
1341 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1345 * function: zfcp_erp_strategy_check_target
1347 * purpose: increments the erp action count on the device currently in
1348 * recovery if the action failed or resets the count in case of
1349 * success. If a maximum count is exceeded the device is marked
1351 * The 'blocked' state of a target which has been recovered
1352 * successfully is reset.
1354 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1355 * ZFCP_ERP_SUCCEEDED - action finished successfully
1356 * ZFCP_ERP_EXIT - action failed and will not continue
1359 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1361 struct zfcp_adapter *adapter = erp_action->adapter;
1362 struct zfcp_port *port = erp_action->port;
1363 struct zfcp_unit *unit = erp_action->unit;
1365 switch (erp_action->action) {
1367 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1368 result = zfcp_erp_strategy_check_unit(unit, result);
1371 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1372 case ZFCP_ERP_ACTION_REOPEN_PORT:
1373 result = zfcp_erp_strategy_check_port(port, result);
1376 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1377 result = zfcp_erp_strategy_check_adapter(adapter, result);
1385 zfcp_erp_strategy_statechange(int action,
1387 struct zfcp_adapter *adapter,
1388 struct zfcp_port *port,
1389 struct zfcp_unit *unit, int retval)
1393 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1394 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1396 zfcp_erp_adapter_reopen_internal(adapter,
1397 ZFCP_STATUS_COMMON_ERP_FAILED,
1399 retval = ZFCP_ERP_EXIT;
1403 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1404 case ZFCP_ERP_ACTION_REOPEN_PORT:
1405 if (zfcp_erp_strategy_statechange_detected(&port->status,
1407 zfcp_erp_port_reopen_internal(port,
1408 ZFCP_STATUS_COMMON_ERP_FAILED,
1410 retval = ZFCP_ERP_EXIT;
1414 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1415 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1417 zfcp_erp_unit_reopen_internal(unit,
1418 ZFCP_STATUS_COMMON_ERP_FAILED,
1420 retval = ZFCP_ERP_EXIT;
1429 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1432 /* take it online */
1433 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1434 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1435 /* take it offline */
1436 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1437 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1441 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1444 case ZFCP_ERP_SUCCEEDED :
1445 atomic_set(&unit->erp_counter, 0);
1446 zfcp_erp_unit_unblock(unit);
1448 case ZFCP_ERP_FAILED :
1449 atomic_inc(&unit->erp_counter);
1450 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1451 zfcp_erp_unit_failed(unit, 21, 0);
1453 case ZFCP_ERP_EXIT :
1458 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1459 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1460 result = ZFCP_ERP_EXIT;
1467 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1470 case ZFCP_ERP_SUCCEEDED :
1471 atomic_set(&port->erp_counter, 0);
1472 zfcp_erp_port_unblock(port);
1474 case ZFCP_ERP_FAILED :
1475 atomic_inc(&port->erp_counter);
1476 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1477 zfcp_erp_port_failed(port, 22, 0);
1479 case ZFCP_ERP_EXIT :
1484 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1485 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1486 result = ZFCP_ERP_EXIT;
1493 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1496 case ZFCP_ERP_SUCCEEDED :
1497 atomic_set(&adapter->erp_counter, 0);
1498 zfcp_erp_adapter_unblock(adapter);
1500 case ZFCP_ERP_FAILED :
1501 atomic_inc(&adapter->erp_counter);
1502 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1503 zfcp_erp_adapter_failed(adapter, 23, 0);
1505 case ZFCP_ERP_EXIT :
1510 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1511 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1512 result = ZFCP_ERP_EXIT;
1518 struct zfcp_erp_add_work {
1519 struct zfcp_unit *unit;
1520 struct work_struct work;
1524 * zfcp_erp_scsi_scan
1525 * @data: pointer to a struct zfcp_erp_add_work
1527 * Registers a logical unit with the SCSI stack.
1529 static void zfcp_erp_scsi_scan(struct work_struct *work)
1531 struct zfcp_erp_add_work *p =
1532 container_of(work, struct zfcp_erp_add_work, work);
1533 struct zfcp_unit *unit = p->unit;
1534 struct fc_rport *rport = unit->port->rport;
1535 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1537 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1538 zfcp_unit_put(unit);
1543 * zfcp_erp_schedule_work
1544 * @unit: pointer to unit which should be registered with SCSI stack
1546 * Schedules work which registers a unit with the SCSI stack
1549 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1551 struct zfcp_erp_add_work *p;
1553 p = kzalloc(sizeof(*p), GFP_KERNEL);
1555 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1556 "the FCP-LUN 0x%Lx connected to "
1557 "the port with WWPN 0x%Lx connected to "
1558 "the adapter %s with the SCSI stack.\n",
1561 zfcp_get_busid_by_unit(unit));
1565 zfcp_unit_get(unit);
1566 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1567 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1569 schedule_work(&p->work);
1575 * purpose: remaining things in good cases,
1576 * escalation in bad cases
1581 zfcp_erp_strategy_followup_actions(int action,
1582 struct zfcp_adapter *adapter,
1583 struct zfcp_port *port,
1584 struct zfcp_unit *unit, int status)
1586 /* initiate follow-up actions depending on success of finished action */
1589 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1590 if (status == ZFCP_ERP_SUCCEEDED)
1591 zfcp_erp_port_reopen_all_internal(adapter, 0, 70, 0);
1593 zfcp_erp_adapter_reopen_internal(adapter, 0, 71, 0);
1596 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1597 if (status == ZFCP_ERP_SUCCEEDED)
1598 zfcp_erp_port_reopen_internal(port, 0, 72, 0);
1600 zfcp_erp_adapter_reopen_internal(adapter, 0, 73, 0);
1603 case ZFCP_ERP_ACTION_REOPEN_PORT:
1604 if (status == ZFCP_ERP_SUCCEEDED)
1605 zfcp_erp_unit_reopen_all_internal(port, 0, 74, 0);
1607 zfcp_erp_port_forced_reopen_internal(port, 0, 75, 0);
1610 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1611 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1612 if (status != ZFCP_ERP_SUCCEEDED)
1613 zfcp_erp_port_reopen_internal(unit->port, 0, 76, 0);
1621 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1623 unsigned long flags;
1625 read_lock_irqsave(&zfcp_data.config_lock, flags);
1626 read_lock(&adapter->erp_lock);
1627 if (list_empty(&adapter->erp_ready_head) &&
1628 list_empty(&adapter->erp_running_head)) {
1629 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1631 wake_up(&adapter->erp_done_wqh);
1633 read_unlock(&adapter->erp_lock);
1634 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1640 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1641 * @adapter: adapter for which to wait for completion of its error recovery
1645 zfcp_erp_wait(struct zfcp_adapter *adapter)
1649 wait_event(adapter->erp_done_wqh,
1650 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1656 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1657 u64 ref, u32 mask, int set_or_clear)
1659 struct zfcp_port *port;
1660 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1662 if (set_or_clear == ZFCP_SET) {
1663 changed = atomic_test_and_set_mask(mask, &adapter->status);
1665 changed = atomic_test_and_clear_mask(mask, &adapter->status);
1666 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1667 atomic_set(&adapter->erp_counter, 0);
1670 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1672 /* Deal with all underlying devices, only pass common_mask */
1674 list_for_each_entry(port, &adapter->port_list_head, list)
1675 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1680 * function: zfcp_erp_modify_port_status
1682 * purpose: sets the port and all underlying devices to ERP_FAILED
1685 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, u64 ref,
1686 u32 mask, int set_or_clear)
1688 struct zfcp_unit *unit;
1689 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1691 if (set_or_clear == ZFCP_SET) {
1692 changed = atomic_test_and_set_mask(mask, &port->status);
1694 changed = atomic_test_and_clear_mask(mask, &port->status);
1695 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1696 atomic_set(&port->erp_counter, 0);
1699 zfcp_rec_dbf_event_port(id, ref, port);
1701 /* Modify status of all underlying devices, only pass common mask */
1703 list_for_each_entry(unit, &port->unit_list_head, list)
1704 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1709 * function: zfcp_erp_modify_unit_status
1711 * purpose: sets the unit to ERP_FAILED
1714 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, u64 ref,
1715 u32 mask, int set_or_clear)
1719 if (set_or_clear == ZFCP_SET) {
1720 changed = atomic_test_and_set_mask(mask, &unit->status);
1722 changed = atomic_test_and_clear_mask(mask, &unit->status);
1723 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1724 atomic_set(&unit->erp_counter, 0);
1728 zfcp_rec_dbf_event_unit(id, ref, unit);
1734 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1735 * used to ensure the correct locking
1737 * returns: 0 - initiated action successfully
1738 * <0 - failed to initiate action
1740 int zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask,
1744 unsigned long flags;
1746 read_lock_irqsave(&zfcp_data.config_lock, flags);
1747 write_lock(&adapter->erp_lock);
1748 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask, id,
1750 write_unlock(&adapter->erp_lock);
1751 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1756 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter,
1757 int clear_mask, u8 id, u64 ref)
1760 struct zfcp_port *port;
1762 list_for_each_entry(port, &adapter->port_list_head, list)
1763 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1764 zfcp_erp_port_reopen_internal(port, clear_mask, id,
1777 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port,
1778 int clear_mask, u8 id, u64 ref)
1781 struct zfcp_unit *unit;
1783 list_for_each_entry(unit, &port->unit_list_head, list)
1784 zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
1792 * purpose: this routine executes the 'Reopen Adapter' action
1793 * (the entire action is processed synchronously, since
1794 * there are no actions which might be run concurrently
1797 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1798 * ZFCP_ERP_FAILED - action finished unsuccessfully
1801 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1804 struct zfcp_adapter *adapter = erp_action->adapter;
1806 retval = zfcp_erp_adapter_strategy_close(erp_action);
1807 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1808 retval = ZFCP_ERP_EXIT;
1810 retval = zfcp_erp_adapter_strategy_open(erp_action);
1812 if (retval == ZFCP_ERP_FAILED) {
1813 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1814 "to recover itself\n",
1815 zfcp_get_busid_by_adapter(adapter));
1816 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
1827 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1828 * ZFCP_ERP_FAILED - action finished unsuccessfully
1831 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1835 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1836 &erp_action->adapter->status);
1837 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1838 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1839 &erp_action->adapter->status);
1849 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1850 * ZFCP_ERP_FAILED - action finished unsuccessfully
1853 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1857 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1858 &erp_action->adapter->status);
1859 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1860 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1861 &erp_action->adapter->status);
1867 * function: zfcp_register_adapter
1869 * purpose: allocate the irq associated with this devno and register
1870 * the FSF adapter with the SCSI stack
1875 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1877 int retval = ZFCP_ERP_SUCCEEDED;
1882 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1883 if (retval != ZFCP_ERP_SUCCEEDED)
1886 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1887 if (retval != ZFCP_ERP_SUCCEEDED)
1888 goto failed_openfcp;
1890 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1894 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1895 &erp_action->adapter->status);
1898 zfcp_close_fsf(erp_action->adapter);
1900 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1901 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1902 ZFCP_STATUS_ADAPTER_XPORT_OK,
1903 &erp_action->adapter->status);
1909 * function: zfcp_qdio_init
1911 * purpose: setup QDIO operation for specified adapter
1913 * returns: 0 - successful setup
1917 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1921 volatile struct qdio_buffer_element *sbale;
1922 struct zfcp_adapter *adapter = erp_action->adapter;
1924 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
1925 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1927 zfcp_get_busid_by_adapter(adapter));
1931 if (qdio_establish(&adapter->qdio_init_data) != 0) {
1932 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1934 zfcp_get_busid_by_adapter(adapter));
1935 goto failed_qdio_establish;
1938 if (qdio_activate(adapter->ccw_device, 0) != 0) {
1939 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1941 zfcp_get_busid_by_adapter(adapter));
1942 goto failed_qdio_activate;
1946 * put buffers into response queue,
1948 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
1949 sbale = &(adapter->response_queue.buffer[i]->element[0]);
1951 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
1955 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1956 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1957 zfcp_get_busid_by_adapter(adapter),
1958 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
1960 retval = do_QDIO(adapter->ccw_device,
1961 QDIO_FLAG_SYNC_INPUT,
1962 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
1965 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
1967 goto failed_do_qdio;
1969 adapter->response_queue.free_index = 0;
1970 atomic_set(&adapter->response_queue.free_count, 0);
1971 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
1972 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
1974 /* set index of first avalable SBALS / number of available SBALS */
1975 adapter->request_queue.free_index = 0;
1976 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
1977 adapter->request_queue.distance_from_int = 0;
1979 /* initialize waitqueue used to wait for free SBALs in requests queue */
1980 init_waitqueue_head(&adapter->request_wq);
1982 /* ok, we did it - skip all cleanups for different failures */
1983 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
1984 retval = ZFCP_ERP_SUCCEEDED;
1990 failed_qdio_activate:
1991 while (qdio_shutdown(adapter->ccw_device,
1992 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
1995 failed_qdio_establish:
1997 retval = ZFCP_ERP_FAILED;
2005 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2009 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2010 if (retval == ZFCP_ERP_FAILED)
2011 return ZFCP_ERP_FAILED;
2013 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2014 if (retval == ZFCP_ERP_FAILED)
2015 return ZFCP_ERP_FAILED;
2017 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2021 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2023 int retval = ZFCP_ERP_SUCCEEDED;
2025 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2026 struct zfcp_adapter *adapter = erp_action->adapter;
2028 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2030 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2031 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2033 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2034 write_lock_irq(&adapter->erp_lock);
2035 zfcp_erp_action_to_running(erp_action);
2036 write_unlock_irq(&adapter->erp_lock);
2037 if (zfcp_fsf_exchange_config_data(erp_action)) {
2038 retval = ZFCP_ERP_FAILED;
2039 ZFCP_LOG_INFO("error: initiation of exchange of "
2040 "configuration data failed for "
2042 zfcp_get_busid_by_adapter(adapter));
2045 ZFCP_LOG_DEBUG("Xchange underway\n");
2049 * Both the normal completion handler as well as the timeout
2050 * handler will do an 'up' when the 'exchange config data'
2051 * request completes or times out. Thus, the signal to go on
2052 * won't be lost utilizing this semaphore.
2053 * Furthermore, this 'adapter_reopen' action is
2054 * guaranteed to be the only action being there (highest action
2055 * which prevents other actions from being created).
2056 * Resulting from that, the wake signal recognized here
2057 * _must_ be the one belonging to the 'exchange config
2060 zfcp_rec_dbf_event_thread(6, adapter, 1);
2061 down(&adapter->erp_ready_sem);
2062 zfcp_rec_dbf_event_thread(7, adapter, 1);
2063 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2064 ZFCP_LOG_INFO("error: exchange of configuration data "
2065 "for adapter %s timed out\n",
2066 zfcp_get_busid_by_adapter(adapter));
2070 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2074 ZFCP_LOG_DEBUG("host connection still initialising... "
2075 "waiting and retrying...\n");
2076 /* sleep a little bit before retry */
2081 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2084 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2085 &adapter->status)) {
2086 ZFCP_LOG_INFO("error: exchange of configuration data for "
2087 "adapter %s failed\n",
2088 zfcp_get_busid_by_adapter(adapter));
2089 retval = ZFCP_ERP_FAILED;
2096 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2099 struct zfcp_adapter *adapter;
2101 adapter = erp_action->adapter;
2102 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2104 write_lock_irq(&adapter->erp_lock);
2105 zfcp_erp_action_to_running(erp_action);
2106 write_unlock_irq(&adapter->erp_lock);
2108 ret = zfcp_fsf_exchange_port_data(erp_action);
2109 if (ret == -EOPNOTSUPP) {
2110 return ZFCP_ERP_SUCCEEDED;
2112 return ZFCP_ERP_FAILED;
2115 ret = ZFCP_ERP_SUCCEEDED;
2116 zfcp_rec_dbf_event_thread(8, adapter, 1);
2117 down(&adapter->erp_ready_sem);
2118 zfcp_rec_dbf_event_thread(9, adapter, 1);
2119 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2120 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2121 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2122 ret = ZFCP_ERP_FAILED;
2125 /* don't treat as error for the sake of compatibility */
2126 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2127 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2128 "%s\n", zfcp_get_busid_by_adapter(adapter));
2134 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2137 int retval = ZFCP_ERP_SUCCEEDED;
2139 struct zfcp_adapter *adapter = erp_action->adapter;
2142 adapter->status_read_failed = 0;
2143 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2144 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2146 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2147 "notification failed on adapter %s\n",
2148 zfcp_get_busid_by_adapter(adapter));
2149 retval = ZFCP_ERP_FAILED;
2161 * purpose: this routine executes the 'Reopen Physical Port' action
2163 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2164 * ZFCP_ERP_SUCCEEDED - action finished successfully
2165 * ZFCP_ERP_FAILED - action finished unsuccessfully
2168 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2170 int retval = ZFCP_ERP_FAILED;
2171 struct zfcp_port *port = erp_action->port;
2173 switch (erp_action->step) {
2177 * the ULP spec. begs for waiting for oustanding commands
2179 case ZFCP_ERP_STEP_UNINITIALIZED:
2180 zfcp_erp_port_strategy_clearstati(port);
2182 * it would be sufficient to test only the normal open flag
2183 * since the phys. open flag cannot be set if the normal
2184 * open flag is unset - however, this is for readabilty ...
2186 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2187 ZFCP_STATUS_COMMON_OPEN),
2189 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2190 "close physical\n", port->wwpn);
2192 zfcp_erp_port_forced_strategy_close(erp_action);
2194 retval = ZFCP_ERP_FAILED;
2197 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2198 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2200 ZFCP_LOG_DEBUG("close physical failed for port "
2201 "0x%016Lx\n", port->wwpn);
2202 retval = ZFCP_ERP_FAILED;
2204 retval = ZFCP_ERP_SUCCEEDED;
2214 * purpose: this routine executes the 'Reopen Port' action
2216 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2217 * ZFCP_ERP_SUCCEEDED - action finished successfully
2218 * ZFCP_ERP_FAILED - action finished unsuccessfully
2221 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2223 int retval = ZFCP_ERP_FAILED;
2224 struct zfcp_port *port = erp_action->port;
2226 switch (erp_action->step) {
2230 * the ULP spec. begs for waiting for oustanding commands
2232 case ZFCP_ERP_STEP_UNINITIALIZED:
2233 zfcp_erp_port_strategy_clearstati(port);
2234 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2235 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2236 "close\n", port->wwpn);
2237 retval = zfcp_erp_port_strategy_close(erp_action);
2239 } /* else it's already closed, open it */
2242 case ZFCP_ERP_STEP_PORT_CLOSING:
2243 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2244 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2246 retval = ZFCP_ERP_FAILED;
2248 } /* else it's closed now, open it */
2251 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2252 retval = ZFCP_ERP_EXIT;
2254 retval = zfcp_erp_port_strategy_open(erp_action);
2261 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2265 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2266 &erp_action->port->status))
2267 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2269 retval = zfcp_erp_port_strategy_open_common(erp_action);
2275 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2278 struct zfcp_adapter *adapter = erp_action->adapter;
2279 struct zfcp_port *port = erp_action->port;
2281 switch (erp_action->step) {
2283 case ZFCP_ERP_STEP_UNINITIALIZED:
2284 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2285 case ZFCP_ERP_STEP_PORT_CLOSING:
2286 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2287 if (port->wwpn != adapter->peer_wwpn) {
2288 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2289 "on adapter %s.\nPeer WWPN "
2290 "0x%016Lx does not match\n",
2292 zfcp_get_busid_by_adapter(adapter),
2293 adapter->peer_wwpn);
2294 zfcp_erp_port_failed(port, 25, 0);
2295 retval = ZFCP_ERP_FAILED;
2298 port->d_id = adapter->peer_d_id;
2299 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2300 retval = zfcp_erp_port_strategy_open_port(erp_action);
2303 if (!(adapter->nameserver_port)) {
2304 retval = zfcp_nameserver_enqueue(adapter);
2306 ZFCP_LOG_NORMAL("error: nameserver port "
2307 "unavailable for adapter %s\n",
2308 zfcp_get_busid_by_adapter(adapter));
2309 retval = ZFCP_ERP_FAILED;
2313 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2314 &adapter->nameserver_port->status)) {
2315 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2316 "nameserver port\n");
2317 /* nameserver port may live again */
2318 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2319 &adapter->nameserver_port->status);
2320 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0,
2321 77, (u64)erp_action) >= 0) {
2323 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2324 retval = ZFCP_ERP_CONTINUES;
2326 retval = ZFCP_ERP_FAILED;
2329 /* else nameserver port is already open, fall through */
2330 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2331 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2332 &adapter->nameserver_port->status)) {
2333 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2334 retval = ZFCP_ERP_FAILED;
2336 ZFCP_LOG_DEBUG("nameserver port is open -> "
2337 "nameserver look-up for port 0x%016Lx\n",
2339 retval = zfcp_erp_port_strategy_open_common_lookup
2344 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2345 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2346 if (atomic_test_mask
2347 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2348 ZFCP_LOG_DEBUG("nameserver look-up failed "
2349 "for port 0x%016Lx "
2350 "(misconfigured WWPN?)\n",
2352 zfcp_erp_port_failed(port, 26, 0);
2353 retval = ZFCP_ERP_EXIT;
2355 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2356 "port 0x%016Lx\n", port->wwpn);
2357 retval = ZFCP_ERP_FAILED;
2360 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2361 "trying open\n", port->wwpn, port->d_id);
2362 retval = zfcp_erp_port_strategy_open_port(erp_action);
2366 case ZFCP_ERP_STEP_PORT_OPENING:
2367 /* D_ID might have changed during open */
2368 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2369 ZFCP_STATUS_PORT_DID_DID),
2371 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2372 retval = ZFCP_ERP_SUCCEEDED;
2374 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2376 retval = ZFCP_ERP_FAILED;
2381 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2383 retval = ZFCP_ERP_FAILED;
2390 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2393 struct zfcp_port *port = erp_action->port;
2395 switch (erp_action->step) {
2397 case ZFCP_ERP_STEP_UNINITIALIZED:
2398 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2399 case ZFCP_ERP_STEP_PORT_CLOSING:
2400 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2401 port->wwpn, port->d_id);
2402 retval = zfcp_erp_port_strategy_open_port(erp_action);
2405 case ZFCP_ERP_STEP_PORT_OPENING:
2406 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2407 ZFCP_LOG_DEBUG("WKA port is open\n");
2408 retval = ZFCP_ERP_SUCCEEDED;
2410 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2411 retval = ZFCP_ERP_FAILED;
2413 /* this is needed anyway (dont care for retval of wakeup) */
2414 ZFCP_LOG_DEBUG("continue other open port operations\n");
2415 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2419 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2421 retval = ZFCP_ERP_FAILED;
2430 * purpose: makes the erp thread continue with reopen (physical) port
2431 * actions which have been paused until the name server port
2432 * is opened (or failed)
2434 * returns: 0 (a kind of void retval, its not used)
2437 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2441 unsigned long flags;
2442 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2443 struct zfcp_erp_action *erp_action, *tmp;
2445 read_lock_irqsave(&adapter->erp_lock, flags);
2446 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2448 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2449 if (atomic_test_mask(
2450 ZFCP_STATUS_COMMON_ERP_FAILED,
2451 &adapter->nameserver_port->status))
2452 zfcp_erp_port_failed(erp_action->port, 27, 0);
2453 zfcp_erp_action_ready(erp_action);
2456 read_unlock_irqrestore(&adapter->erp_lock, flags);
2466 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2467 * ZFCP_ERP_FAILED - action finished unsuccessfully
2470 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2474 retval = zfcp_fsf_close_physical_port(erp_action);
2475 if (retval == -ENOMEM) {
2476 retval = ZFCP_ERP_NOMEM;
2479 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2481 /* could not send 'open', fail */
2482 retval = ZFCP_ERP_FAILED;
2485 retval = ZFCP_ERP_CONTINUES;
2491 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2495 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2496 ZFCP_STATUS_COMMON_CLOSING |
2497 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2498 ZFCP_STATUS_PORT_DID_DID |
2499 ZFCP_STATUS_PORT_PHYS_CLOSING |
2500 ZFCP_STATUS_PORT_INVALID_WWPN,
2510 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2511 * ZFCP_ERP_FAILED - action finished unsuccessfully
2514 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2518 retval = zfcp_fsf_close_port(erp_action);
2519 if (retval == -ENOMEM) {
2520 retval = ZFCP_ERP_NOMEM;
2523 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2525 /* could not send 'close', fail */
2526 retval = ZFCP_ERP_FAILED;
2529 retval = ZFCP_ERP_CONTINUES;
2539 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2540 * ZFCP_ERP_FAILED - action finished unsuccessfully
2543 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2547 retval = zfcp_fsf_open_port(erp_action);
2548 if (retval == -ENOMEM) {
2549 retval = ZFCP_ERP_NOMEM;
2552 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2554 /* could not send 'open', fail */
2555 retval = ZFCP_ERP_FAILED;
2558 retval = ZFCP_ERP_CONTINUES;
2568 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2569 * ZFCP_ERP_FAILED - action finished unsuccessfully
2572 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2576 retval = zfcp_ns_gid_pn_request(erp_action);
2577 if (retval == -ENOMEM) {
2578 retval = ZFCP_ERP_NOMEM;
2581 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2583 /* could not send nameserver request, fail */
2584 retval = ZFCP_ERP_FAILED;
2587 retval = ZFCP_ERP_CONTINUES;
2595 * purpose: this routine executes the 'Reopen Unit' action
2596 * currently no retries
2598 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2599 * ZFCP_ERP_SUCCEEDED - action finished successfully
2600 * ZFCP_ERP_FAILED - action finished unsuccessfully
2603 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2605 int retval = ZFCP_ERP_FAILED;
2606 struct zfcp_unit *unit = erp_action->unit;
2608 switch (erp_action->step) {
2612 * the ULP spec. begs for waiting for oustanding commands
2614 case ZFCP_ERP_STEP_UNINITIALIZED:
2615 zfcp_erp_unit_strategy_clearstati(unit);
2616 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2617 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2618 "trying close\n", unit->fcp_lun);
2619 retval = zfcp_erp_unit_strategy_close(erp_action);
2622 /* else it's already closed, fall through */
2623 case ZFCP_ERP_STEP_UNIT_CLOSING:
2624 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2625 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2627 retval = ZFCP_ERP_FAILED;
2629 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2630 retval = ZFCP_ERP_EXIT;
2632 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2633 "trying open\n", unit->fcp_lun);
2635 zfcp_erp_unit_strategy_open(erp_action);
2640 case ZFCP_ERP_STEP_UNIT_OPENING:
2641 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2642 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2644 retval = ZFCP_ERP_SUCCEEDED;
2646 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2648 retval = ZFCP_ERP_FAILED;
2657 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2661 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2662 ZFCP_STATUS_COMMON_CLOSING |
2663 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2664 ZFCP_STATUS_UNIT_SHARED |
2665 ZFCP_STATUS_UNIT_READONLY,
2676 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2677 * ZFCP_ERP_FAILED - action finished unsuccessfully
2680 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2684 retval = zfcp_fsf_close_unit(erp_action);
2685 if (retval == -ENOMEM) {
2686 retval = ZFCP_ERP_NOMEM;
2689 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2691 /* could not send 'close', fail */
2692 retval = ZFCP_ERP_FAILED;
2695 retval = ZFCP_ERP_CONTINUES;
2706 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2707 * ZFCP_ERP_FAILED - action finished unsuccessfully
2710 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2714 retval = zfcp_fsf_open_unit(erp_action);
2715 if (retval == -ENOMEM) {
2716 retval = ZFCP_ERP_NOMEM;
2719 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2721 /* could not send 'open', fail */
2722 retval = ZFCP_ERP_FAILED;
2725 retval = ZFCP_ERP_CONTINUES;
2730 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2732 BUG_ON(!fsf_req->erp_action);
2733 fsf_req->timer.function = zfcp_erp_timeout_handler;
2734 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2735 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2736 add_timer(&fsf_req->timer);
2742 * purpose: enqueue the specified error recovery action, if needed
2746 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
2747 struct zfcp_port *port,
2748 struct zfcp_unit *unit, u8 id, u64 ref)
2750 int retval = 1, need = want;
2751 struct zfcp_erp_action *erp_action = NULL;
2755 * We need some rules here which check whether we really need
2756 * this action or whether we should just drop it.
2757 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2758 * 'Reopen Unit' request for an associated unit since we can't
2759 * satisfy this request now. A 'Reopen Port' action will trigger
2760 * 'Reopen Unit' actions when it completes.
2761 * Thus, there are only actions in the queue which can immediately be
2762 * executed. This makes the processing of the action queue more
2766 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2770 /* check whether we really need this */
2772 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2773 if (atomic_test_mask
2774 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2777 if (!atomic_test_mask
2778 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2780 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2783 if (!atomic_test_mask
2784 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
2785 need = ZFCP_ERP_ACTION_REOPEN_PORT;
2786 /* fall through !!! */
2788 case ZFCP_ERP_ACTION_REOPEN_PORT:
2789 if (atomic_test_mask
2790 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2793 /* fall through !!! */
2795 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2796 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2798 if (port->erp_action.action !=
2799 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2800 ZFCP_LOG_INFO("dropped erp action %i (port "
2801 "0x%016Lx, action in use: %i)\n",
2803 port->erp_action.action);
2807 if (!atomic_test_mask
2808 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2810 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2813 if (!atomic_test_mask
2814 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
2815 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
2816 /* fall through !!! */
2818 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2819 if (atomic_test_mask
2820 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
2826 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2827 "on adapter %s (action=%d)\n",
2828 zfcp_get_busid_by_adapter(adapter), want);
2832 /* check whether we need something stronger first */
2834 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2835 "erp action %d on adapter %s\n",
2836 need, want, zfcp_get_busid_by_adapter(adapter));
2839 /* mark adapter to have some error recovery pending */
2840 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2842 /* setup error recovery action */
2845 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2846 zfcp_unit_get(unit);
2847 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2848 erp_action = &unit->erp_action;
2849 if (!atomic_test_mask
2850 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
2851 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2854 case ZFCP_ERP_ACTION_REOPEN_PORT:
2855 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2856 zfcp_port_get(port);
2857 zfcp_erp_action_dismiss_port(port);
2858 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
2859 erp_action = &port->erp_action;
2860 if (!atomic_test_mask
2861 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
2862 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2865 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2866 zfcp_adapter_get(adapter);
2867 zfcp_erp_action_dismiss_adapter(adapter);
2868 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
2869 erp_action = &adapter->erp_action;
2870 if (!atomic_test_mask
2871 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
2872 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2876 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
2877 erp_action->adapter = adapter;
2878 erp_action->port = port;
2879 erp_action->unit = unit;
2880 erp_action->action = need;
2881 erp_action->status = status;
2883 ++adapter->erp_total_count;
2885 /* finally put it into 'ready' queue and kick erp thread */
2886 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
2887 up(&adapter->erp_ready_sem);
2888 zfcp_rec_dbf_event_thread(1, adapter, 0);
2891 zfcp_rec_dbf_event_trigger(id, ref, want, need, (u64)erp_action,
2892 adapter, port, unit);
2897 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
2900 struct zfcp_adapter *adapter = erp_action->adapter;
2902 --adapter->erp_total_count;
2903 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
2904 --adapter->erp_low_mem_count;
2905 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
2908 list_del(&erp_action->list);
2909 zfcp_rec_dbf_event_action(144, erp_action);
2911 switch (erp_action->action) {
2912 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2913 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2914 &erp_action->unit->status);
2916 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2917 case ZFCP_ERP_ACTION_REOPEN_PORT:
2918 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2919 &erp_action->port->status);
2921 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2922 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2923 &erp_action->adapter->status);
2933 * zfcp_erp_action_cleanup
2935 * Register unit with scsi stack if appropriate and fix reference counts.
2936 * Note: Temporary units are not registered with scsi stack.
2939 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
2940 struct zfcp_port *port, struct zfcp_unit *unit,
2944 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2945 if ((result == ZFCP_ERP_SUCCEEDED)
2946 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
2950 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
2952 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
2953 &unit->status) == 0)
2954 zfcp_erp_schedule_work(unit);
2956 zfcp_unit_put(unit);
2958 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2959 case ZFCP_ERP_ACTION_REOPEN_PORT:
2960 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
2962 zfcp_port_put(port);
2966 if ((result == ZFCP_ERP_SUCCEEDED)
2968 struct fc_rport_identifiers ids;
2969 ids.node_name = port->wwnn;
2970 ids.port_name = port->wwpn;
2971 ids.port_id = port->d_id;
2972 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
2974 fc_remote_port_add(adapter->scsi_host, 0, &ids);
2976 ZFCP_LOG_NORMAL("failed registration of rport"
2977 "(adapter %s, wwpn=0x%016Lx)\n",
2978 zfcp_get_busid_by_port(port),
2981 scsi_target_unblock(&port->rport->dev);
2982 port->rport->maxframe_size = port->maxframe_size;
2983 port->rport->supported_classes =
2984 port->supported_classes;
2987 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
2988 fc_remote_port_delete(port->rport);
2991 zfcp_port_put(port);
2993 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2994 if (result != ZFCP_ERP_SUCCEEDED) {
2995 list_for_each_entry(port, &adapter->port_list_head, list)
2997 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2999 fc_remote_port_delete(port->rport);
3003 zfcp_adapter_put(adapter);
3011 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3013 struct zfcp_port *port;
3015 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3016 zfcp_erp_action_dismiss(&adapter->erp_action);
3018 list_for_each_entry(port, &adapter->port_list_head, list)
3019 zfcp_erp_action_dismiss_port(port);
3022 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3024 struct zfcp_unit *unit;
3026 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3027 zfcp_erp_action_dismiss(&port->erp_action);
3029 list_for_each_entry(unit, &port->unit_list_head, list)
3030 zfcp_erp_action_dismiss_unit(unit);
3033 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3035 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3036 zfcp_erp_action_dismiss(&unit->erp_action);
3039 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3041 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3042 zfcp_rec_dbf_event_action(145, erp_action);
3045 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3047 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3048 zfcp_rec_dbf_event_action(146, erp_action);
3051 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, u64 ref)
3053 unsigned long flags;
3055 read_lock_irqsave(&zfcp_data.config_lock, flags);
3056 zfcp_erp_modify_port_status(port, id, ref,
3057 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3058 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3059 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3062 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, u64 ref)
3064 zfcp_erp_modify_unit_status(unit, id, ref,
3065 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3066 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3069 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, u64 ref)
3071 unsigned long flags;
3073 read_lock_irqsave(&zfcp_data.config_lock, flags);
3074 zfcp_erp_modify_port_status(port, id, ref,
3075 ZFCP_STATUS_COMMON_ERP_FAILED |
3076 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3077 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3080 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, u64 ref)
3082 zfcp_erp_modify_unit_status(unit, id, ref,
3083 ZFCP_STATUS_COMMON_ERP_FAILED |
3084 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3087 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
3090 struct zfcp_port *port;
3091 unsigned long flags;
3093 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3096 read_lock_irqsave(&zfcp_data.config_lock, flags);
3097 if (adapter->nameserver_port)
3098 zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
3099 list_for_each_entry(port, &adapter->port_list_head, list)
3100 if (port != adapter->nameserver_port)
3101 zfcp_erp_port_access_changed(port, id, ref);
3102 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3105 void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, u64 ref)
3107 struct zfcp_adapter *adapter = port->adapter;
3108 struct zfcp_unit *unit;
3110 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3112 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3114 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3115 list_for_each_entry(unit, &port->unit_list_head, list)
3116 zfcp_erp_unit_access_changed(unit, id, ref);
3120 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3121 "(due to ACT update)\n",
3122 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3123 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3124 ZFCP_LOG_NORMAL("failed reopen of port"
3125 "(adapter %s, wwpn=0x%016Lx)\n",
3126 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3129 void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, u64 ref)
3131 struct zfcp_adapter *adapter = unit->port->adapter;
3133 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3135 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3139 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3140 " on adapter %s (due to ACT update)\n",
3141 unit->fcp_lun, unit->port->wwpn,
3142 zfcp_get_busid_by_adapter(adapter));
3143 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3144 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3145 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3146 zfcp_get_busid_by_adapter(adapter),
3147 unit->port->wwpn, unit->fcp_lun);
3150 #undef ZFCP_LOG_AREA