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_adapter_reopen_internal(struct zfcp_adapter
*, int, u8
,
28 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port
*, int, u8
,
30 static int zfcp_erp_port_reopen_internal(struct zfcp_port
*, int, u8
, void *);
31 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit
*, int, u8
, void *);
33 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter
*, int, u8
,
35 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port
*, int, u8
,
38 static void zfcp_erp_adapter_block(struct zfcp_adapter
*, int);
39 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*);
40 static void zfcp_erp_port_block(struct zfcp_port
*, int);
41 static void zfcp_erp_port_unblock(struct zfcp_port
*);
42 static void zfcp_erp_unit_block(struct zfcp_unit
*, int);
43 static void zfcp_erp_unit_unblock(struct zfcp_unit
*);
45 static int zfcp_erp_thread(void *);
47 static int zfcp_erp_strategy(struct zfcp_erp_action
*);
49 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*);
50 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action
*);
51 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*, int);
52 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*, int);
53 static int zfcp_erp_strategy_check_port(struct zfcp_port
*, int);
54 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*, int);
55 static int zfcp_erp_strategy_statechange(int, u32
, struct zfcp_adapter
*,
57 struct zfcp_unit
*, int);
58 static int zfcp_erp_strategy_statechange_detected(atomic_t
*, u32
);
59 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter
*,
61 struct zfcp_unit
*, int);
62 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter
*);
63 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action
*, int);
65 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*);
66 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action
*, int);
67 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*);
68 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*);
69 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*);
70 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*);
71 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action
*);
72 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*);
73 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
74 struct zfcp_erp_action
*);
76 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*);
77 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*);
79 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*);
80 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port
*);
81 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*);
82 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action
*);
83 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action
*);
84 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
85 struct zfcp_erp_action
*);
86 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*);
87 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action
*);
88 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*);
90 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*);
91 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*);
92 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*);
93 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*);
95 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*);
96 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*);
97 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit
*);
98 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*);
100 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter
*,
101 struct zfcp_port
*, struct zfcp_unit
*,
103 static int zfcp_erp_action_dequeue(struct zfcp_erp_action
*);
104 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter
*,
105 struct zfcp_port
*, struct zfcp_unit
*,
108 static void zfcp_erp_action_ready(struct zfcp_erp_action
*);
109 static int zfcp_erp_action_exists(struct zfcp_erp_action
*);
111 static void zfcp_erp_action_to_ready(struct zfcp_erp_action
*);
112 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*);
114 static void zfcp_erp_memwait_handler(unsigned long);
117 * zfcp_close_qdio - close qdio queues for an adapter
119 static void zfcp_close_qdio(struct zfcp_adapter
*adapter
)
121 struct zfcp_qdio_queue
*req_queue
;
124 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &adapter
->status
))
127 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
128 req_queue
= &adapter
->request_queue
;
129 write_lock_irq(&req_queue
->queue_lock
);
130 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &adapter
->status
);
131 write_unlock_irq(&req_queue
->queue_lock
);
133 while (qdio_shutdown(adapter
->ccw_device
,
134 QDIO_FLAG_CLEANUP_USING_CLEAR
) == -EINPROGRESS
)
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
, 24, NULL
,
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
, 62,
186 void zfcp_fsf_start_timer(struct zfcp_fsf_req
*fsf_req
, unsigned long timeout
)
188 fsf_req
->timer
.function
= zfcp_fsf_request_timeout_handler
;
189 fsf_req
->timer
.data
= (unsigned long) fsf_req
->adapter
;
190 fsf_req
->timer
.expires
= jiffies
+ timeout
;
191 add_timer(&fsf_req
->timer
);
197 * purpose: called if an adapter failed,
198 * initiates adapter recovery which is done
201 * returns: 0 - initiated action successfully
202 * <0 - failed to initiate action
204 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter
*adapter
,
205 int clear_mask
, u8 id
, void *ref
)
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 /* ensure propagation of failed status to new devices */
218 zfcp_erp_adapter_failed(adapter
, 13, NULL
);
222 retval
= zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
223 adapter
, NULL
, NULL
, id
, ref
);
232 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
233 * used to ensure the correct locking
235 * returns: 0 - initiated action successfully
236 * <0 - failed to initiate action
238 int zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear_mask
,
244 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
245 write_lock(&adapter
->erp_lock
);
246 retval
= zfcp_erp_adapter_reopen_internal(adapter
, clear_mask
, id
, ref
);
247 write_unlock(&adapter
->erp_lock
);
248 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
253 int zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear_mask
,
258 retval
= zfcp_erp_adapter_reopen(adapter
,
259 ZFCP_STATUS_COMMON_RUNNING
|
260 ZFCP_STATUS_COMMON_ERP_FAILED
|
261 clear_mask
, id
, ref
);
266 int zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear_mask
, u8 id
,
271 retval
= zfcp_erp_port_reopen(port
,
272 ZFCP_STATUS_COMMON_RUNNING
|
273 ZFCP_STATUS_COMMON_ERP_FAILED
|
274 clear_mask
, id
, ref
);
279 int zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear_mask
, u8 id
,
284 retval
= zfcp_erp_unit_reopen(unit
,
285 ZFCP_STATUS_COMMON_RUNNING
|
286 ZFCP_STATUS_COMMON_ERP_FAILED
|
287 clear_mask
, id
, ref
);
295 * purpose: called if a port failed to be opened normally
296 * initiates Forced Reopen recovery which is done
299 * returns: 0 - initiated action successfully
300 * <0 - failed to initiate action
302 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port
*port
,
303 int clear_mask
, u8 id
,
308 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
309 port
->wwpn
, zfcp_get_busid_by_port(port
));
311 zfcp_erp_port_block(port
, clear_mask
);
313 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &port
->status
)) {
314 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
315 "on adapter %s\n", port
->wwpn
,
316 zfcp_get_busid_by_port(port
));
321 retval
= zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
322 port
->adapter
, port
, NULL
, id
, ref
);
331 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
332 * used to ensure the correct locking
334 * returns: 0 - initiated action successfully
335 * <0 - failed to initiate action
337 int zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear_mask
, u8 id
,
342 struct zfcp_adapter
*adapter
;
344 adapter
= port
->adapter
;
345 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
346 write_lock(&adapter
->erp_lock
);
347 retval
= zfcp_erp_port_forced_reopen_internal(port
, clear_mask
, id
,
349 write_unlock(&adapter
->erp_lock
);
350 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
358 * purpose: called if a port is to be opened
359 * initiates Reopen recovery which is done
362 * returns: 0 - initiated action successfully
363 * <0 - failed to initiate action
365 static int zfcp_erp_port_reopen_internal(struct zfcp_port
*port
, int clear_mask
,
370 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
371 port
->wwpn
, zfcp_get_busid_by_port(port
));
373 zfcp_erp_port_block(port
, clear_mask
);
375 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &port
->status
)) {
376 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
377 "on adapter %s\n", port
->wwpn
,
378 zfcp_get_busid_by_port(port
));
379 /* ensure propagation of failed status to new devices */
380 zfcp_erp_port_failed(port
, 14, NULL
);
385 retval
= zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
386 port
->adapter
, port
, NULL
, id
, ref
);
393 * zfcp_erp_port_reopen - initiate reopen of a remote port
394 * @port: port to be reopened
395 * @clear_mask: specifies flags in port status to be cleared
396 * Return: 0 on success, < 0 on error
398 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
399 * correct locking. An error recovery task is initiated to do the reopen.
400 * To wait for the completion of the reopen zfcp_erp_wait should be used.
402 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear_mask
, u8 id
,
407 struct zfcp_adapter
*adapter
= port
->adapter
;
409 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
410 write_lock(&adapter
->erp_lock
);
411 retval
= zfcp_erp_port_reopen_internal(port
, clear_mask
, id
, ref
);
412 write_unlock(&adapter
->erp_lock
);
413 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
421 * purpose: called if a unit is to be opened
422 * initiates Reopen recovery which is done
425 * returns: 0 - initiated action successfully
426 * <0 - failed to initiate action
428 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit
*unit
, int clear_mask
,
432 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
434 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
435 "on adapter %s\n", unit
->fcp_lun
,
436 unit
->port
->wwpn
, zfcp_get_busid_by_unit(unit
));
438 zfcp_erp_unit_block(unit
, clear_mask
);
440 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &unit
->status
)) {
441 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
442 "on port 0x%016Lx on adapter %s\n",
443 unit
->fcp_lun
, unit
->port
->wwpn
,
444 zfcp_get_busid_by_unit(unit
));
449 retval
= zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
450 adapter
, unit
->port
, unit
, id
, ref
);
456 * zfcp_erp_unit_reopen - initiate reopen of a unit
457 * @unit: unit to be reopened
458 * @clear_mask: specifies flags in unit status to be cleared
459 * Return: 0 on success, < 0 on error
461 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
462 * locking. An error recovery task is initiated to do the reopen.
463 * To wait for the completion of the reopen zfcp_erp_wait should be used.
465 int zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear_mask
, u8 id
,
470 struct zfcp_adapter
*adapter
;
471 struct zfcp_port
*port
;
474 adapter
= port
->adapter
;
476 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
477 write_lock(&adapter
->erp_lock
);
478 retval
= zfcp_erp_unit_reopen_internal(unit
, clear_mask
, id
, ref
);
479 write_unlock(&adapter
->erp_lock
);
480 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
486 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
488 static void zfcp_erp_adapter_block(struct zfcp_adapter
*adapter
, int clear_mask
)
490 zfcp_erp_modify_adapter_status(adapter
, 15, NULL
,
491 ZFCP_STATUS_COMMON_UNBLOCKED
|
492 clear_mask
, ZFCP_CLEAR
);
495 /* FIXME: isn't really atomic */
497 * returns the mask which has not been set so far, i.e.
498 * 0 if no bit has been changed, !0 if some bit has been changed
500 static int atomic_test_and_set_mask(unsigned long mask
, atomic_t
*v
)
502 int changed_bits
= (atomic_read(v
) /*XOR*/^ mask
) & mask
;
503 atomic_set_mask(mask
, v
);
507 /* FIXME: isn't really atomic */
509 * returns the mask which has not been cleared so far, i.e.
510 * 0 if no bit has been changed, !0 if some bit has been changed
512 static int atomic_test_and_clear_mask(unsigned long mask
, atomic_t
*v
)
514 int changed_bits
= atomic_read(v
) & mask
;
515 atomic_clear_mask(mask
, v
);
520 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
522 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
524 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
,
526 zfcp_rec_dbf_event_adapter(16, NULL
, adapter
);
532 * purpose: disable I/O,
533 * return any open requests and clean them up,
534 * aim: no pending and incoming I/O
539 zfcp_erp_port_block(struct zfcp_port
*port
, int clear_mask
)
541 zfcp_erp_modify_port_status(port
, 17, NULL
,
542 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
549 * purpose: enable I/O
554 zfcp_erp_port_unblock(struct zfcp_port
*port
)
556 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
,
558 zfcp_rec_dbf_event_port(18, NULL
, port
);
564 * purpose: disable I/O,
565 * return any open requests and clean them up,
566 * aim: no pending and incoming I/O
571 zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
573 zfcp_erp_modify_unit_status(unit
, 19, NULL
,
574 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
581 * purpose: enable I/O
586 zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
588 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
,
590 zfcp_rec_dbf_event_unit(20, NULL
, unit
);
594 zfcp_erp_action_ready(struct zfcp_erp_action
*erp_action
)
596 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
598 zfcp_erp_action_to_ready(erp_action
);
599 up(&adapter
->erp_ready_sem
);
600 zfcp_rec_dbf_event_thread(2, adapter
);
608 * returns: <0 erp_action not found in any list
609 * ZFCP_ERP_ACTION_READY erp_action is in ready list
610 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
612 * locks: erp_lock must be held
615 zfcp_erp_action_exists(struct zfcp_erp_action
*erp_action
)
617 int retval
= -EINVAL
;
618 struct list_head
*entry
;
619 struct zfcp_erp_action
*entry_erp_action
;
620 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
622 /* search in running list */
623 list_for_each(entry
, &adapter
->erp_running_head
) {
625 list_entry(entry
, struct zfcp_erp_action
, list
);
626 if (entry_erp_action
== erp_action
) {
627 retval
= ZFCP_ERP_ACTION_RUNNING
;
631 /* search in ready list */
632 list_for_each(entry
, &adapter
->erp_ready_head
) {
634 list_entry(entry
, struct zfcp_erp_action
, list
);
635 if (entry_erp_action
== erp_action
) {
636 retval
= ZFCP_ERP_ACTION_READY
;
646 * purpose: checks current status of action (timed out, dismissed, ...)
647 * and does appropriate preparations (dismiss fsf request, ...)
649 * locks: called under erp_lock (disabled interrupts)
652 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*erp_action
)
654 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
656 if (erp_action
->fsf_req
) {
657 /* take lock to ensure that request is not deleted meanwhile */
658 spin_lock(&adapter
->req_list_lock
);
659 if (zfcp_reqlist_find_safe(adapter
, erp_action
->fsf_req
) &&
660 erp_action
->fsf_req
->erp_action
== erp_action
) {
661 /* fsf_req still exists */
662 /* dismiss fsf_req of timed out/dismissed erp_action */
663 if (erp_action
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
664 ZFCP_STATUS_ERP_TIMEDOUT
)) {
665 erp_action
->fsf_req
->status
|=
666 ZFCP_STATUS_FSFREQ_DISMISSED
;
667 zfcp_rec_dbf_event_action(142, erp_action
);
669 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
670 zfcp_rec_dbf_event_action(143, erp_action
);
671 ZFCP_LOG_NORMAL("error: erp step timed out "
672 "(action=%d, fsf_req=%p)\n ",
674 erp_action
->fsf_req
);
677 * If fsf_req is neither dismissed nor completed
678 * then keep it running asynchronously and don't mess
679 * with the association of erp_action and fsf_req.
681 if (erp_action
->fsf_req
->status
&
682 (ZFCP_STATUS_FSFREQ_COMPLETED
|
683 ZFCP_STATUS_FSFREQ_DISMISSED
)) {
684 /* forget about association between fsf_req
686 erp_action
->fsf_req
= NULL
;
690 * even if this fsf_req has gone, forget about
691 * association between erp_action and fsf_req
693 erp_action
->fsf_req
= NULL
;
695 spin_unlock(&adapter
->req_list_lock
);
700 * zfcp_erp_async_handler_nolock - complete erp_action
702 * Used for normal completion, time-out, dismissal and failure after
703 * low memory condition.
705 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action
*erp_action
,
706 unsigned long set_mask
)
708 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
709 erp_action
->status
|= set_mask
;
710 zfcp_erp_action_ready(erp_action
);
712 /* action is ready or gone - nothing to do */
717 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
719 void zfcp_erp_async_handler(struct zfcp_erp_action
*erp_action
,
720 unsigned long set_mask
)
722 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
725 write_lock_irqsave(&adapter
->erp_lock
, flags
);
726 zfcp_erp_async_handler_nolock(erp_action
, set_mask
);
727 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
731 * purpose: is called for erp_action which was slept waiting for
732 * memory becoming avaliable,
733 * will trigger that this action will be continued
736 zfcp_erp_memwait_handler(unsigned long data
)
738 struct zfcp_erp_action
*erp_action
= (struct zfcp_erp_action
*) data
;
740 zfcp_erp_async_handler(erp_action
, 0);
744 * purpose: is called if an asynchronous erp step timed out,
745 * action gets an appropriate flag and will be processed
748 static void zfcp_erp_timeout_handler(unsigned long data
)
750 struct zfcp_erp_action
*erp_action
= (struct zfcp_erp_action
*) data
;
752 zfcp_erp_async_handler(erp_action
, ZFCP_STATUS_ERP_TIMEDOUT
);
756 * zfcp_erp_action_dismiss - dismiss an erp_action
758 * adapter->erp_lock must be held
760 * Dismissal of an erp_action is usually required if an erp_action of
761 * higher priority is generated.
763 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*erp_action
)
765 erp_action
->status
|= ZFCP_STATUS_ERP_DISMISSED
;
766 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
)
767 zfcp_erp_action_ready(erp_action
);
771 zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
775 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
777 retval
= kernel_thread(zfcp_erp_thread
, adapter
, SIGCHLD
);
779 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
781 zfcp_get_busid_by_adapter(adapter
));
783 wait_event(adapter
->erp_thread_wqh
,
784 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
,
798 * context: process (i.e. proc-fs or rmmod/insmod)
800 * note: The caller of this routine ensures that the specified
801 * adapter has been shut down and that this operation
802 * has been completed. Thus, there are no pending erp_actions
803 * which would need to be handled here.
806 zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
810 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
, &adapter
->status
);
811 up(&adapter
->erp_ready_sem
);
812 zfcp_rec_dbf_event_thread_lock(2, adapter
);
814 wait_event(adapter
->erp_thread_wqh
,
815 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
,
818 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
,
825 * purpose: is run as a kernel thread,
826 * goes through list of error recovery actions of associated adapter
827 * and delegates single action to execution
832 zfcp_erp_thread(void *data
)
834 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
835 struct list_head
*next
;
836 struct zfcp_erp_action
*erp_action
;
839 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter
));
840 /* Block all signals */
841 siginitsetinv(¤t
->blocked
, 0);
842 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
843 wake_up(&adapter
->erp_thread_wqh
);
845 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
,
848 write_lock_irqsave(&adapter
->erp_lock
, flags
);
849 next
= adapter
->erp_ready_head
.next
;
850 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
852 if (next
!= &adapter
->erp_ready_head
) {
854 list_entry(next
, struct zfcp_erp_action
, list
);
856 * process action (incl. [re]moving it
857 * from 'ready' queue)
859 zfcp_erp_strategy(erp_action
);
863 * sleep as long as there is nothing to do, i.e.
864 * no action in 'ready' queue to be processed and
865 * thread is not to be killed
867 zfcp_rec_dbf_event_thread_lock(4, adapter
);
868 down_interruptible(&adapter
->erp_ready_sem
);
869 zfcp_rec_dbf_event_thread_lock(5, adapter
);
872 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
873 wake_up(&adapter
->erp_thread_wqh
);
881 * purpose: drives single error recovery action and schedules higher and
882 * subordinate actions, if necessary
884 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
885 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
886 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
887 * ZFCP_ERP_EXIT - action finished (dequeued), offline
888 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
891 zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
894 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
895 struct zfcp_port
*port
= erp_action
->port
;
896 struct zfcp_unit
*unit
= erp_action
->unit
;
897 int action
= erp_action
->action
;
898 u32 status
= erp_action
->status
;
901 /* serialise dismissing, timing out, moving, enqueueing */
902 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
903 write_lock(&adapter
->erp_lock
);
905 /* dequeue dismissed action and leave, if required */
906 retval
= zfcp_erp_strategy_check_action(erp_action
, retval
);
907 if (retval
== ZFCP_ERP_DISMISSED
) {
912 * move action to 'running' queue before processing it
913 * (to avoid a race condition regarding moving the
914 * action to the 'running' queue and back)
916 zfcp_erp_action_to_running(erp_action
);
919 * try to process action as far as possible,
920 * no lock to allow for blocking operations (kmalloc, qdio, ...),
921 * afterwards the lock is required again for the following reasons:
922 * - dequeueing of finished action and enqueueing of
923 * follow-up actions must be atomic so that any other
924 * reopen-routine does not believe there is nothing to do
925 * and that it is safe to enqueue something else,
926 * - we want to force any control thread which is dismissing
927 * actions to finish this before we decide about
928 * necessary steps to be taken here further
930 write_unlock(&adapter
->erp_lock
);
931 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
932 retval
= zfcp_erp_strategy_do_action(erp_action
);
933 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
934 write_lock(&adapter
->erp_lock
);
937 * check for dismissed status again to avoid follow-up actions,
938 * failing of targets and so on for dismissed actions,
939 * we go through down() here because there has been an up()
941 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
942 retval
= ZFCP_ERP_CONTINUES
;
946 /* no memory to continue immediately, let it sleep */
947 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
948 ++adapter
->erp_low_mem_count
;
949 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
951 /* This condition is true if there is no memory available
952 for any erp_action on this adapter. This implies that there
953 are no elements in the memory pool(s) left for erp_actions.
954 This might happen if an erp_action that used a memory pool
955 element was timed out.
957 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
) {
958 ZFCP_LOG_NORMAL("error: no mempool elements available, "
959 "restarting I/O on adapter %s "
961 zfcp_get_busid_by_adapter(adapter
));
962 zfcp_erp_adapter_reopen_internal(adapter
, 0, 66, NULL
);
964 retval
= zfcp_erp_strategy_memwait(erp_action
);
967 case ZFCP_ERP_CONTINUES
:
968 /* leave since this action runs asynchronously */
969 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
970 --adapter
->erp_low_mem_count
;
971 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
975 /* ok, finished action (whatever its result is) */
977 /* check for unrecoverable targets */
978 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
980 /* action must be dequeued (here to allow for further ones) */
981 zfcp_erp_action_dequeue(erp_action
);
984 * put this target through the erp mill again if someone has
985 * requested to change the status of a target being online
986 * to offline or the other way around
987 * (old retval is preserved if nothing has to be done here)
989 retval
= zfcp_erp_strategy_statechange(action
, status
, adapter
,
993 * leave if target is in permanent error state or if
994 * action is repeated in order to process state change
996 if (retval
== ZFCP_ERP_EXIT
) {
1000 /* trigger follow up actions */
1001 zfcp_erp_strategy_followup_actions(action
, adapter
, port
, unit
, retval
);
1004 write_unlock(&adapter
->erp_lock
);
1005 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1007 if (retval
!= ZFCP_ERP_CONTINUES
)
1008 zfcp_erp_action_cleanup(action
, adapter
, port
, unit
, retval
);
1011 * a few tasks remain when the erp queues are empty
1012 * (don't do that if the last action evaluated was dismissed
1013 * since this clearly indicates that there is more to come) :
1014 * - close the name server port if it is open yet
1015 * (enqueues another [probably] final action)
1016 * - otherwise, wake up whoever wants to be woken when we are
1019 if (retval
!= ZFCP_ERP_DISMISSED
)
1020 zfcp_erp_strategy_check_queues(adapter
);
1030 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1031 * retval - otherwise
1034 zfcp_erp_strategy_check_action(struct zfcp_erp_action
*erp_action
, int retval
)
1036 zfcp_erp_strategy_check_fsfreq(erp_action
);
1038 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1039 zfcp_erp_action_dequeue(erp_action
);
1040 retval
= ZFCP_ERP_DISMISSED
;
1047 zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1049 int retval
= ZFCP_ERP_FAILED
;
1052 * try to execute/continue action as far as possible,
1053 * note: no lock in subsequent strategy routines
1054 * (this allows these routine to call schedule, e.g.
1055 * kmalloc with such flags or qdio_initialize & friends)
1056 * Note: in case of timeout, the separate strategies will fail
1057 * anyhow. No need for a special action. Even worse, a nameserver
1058 * failure would not wake up waiting ports without the call.
1060 switch (erp_action
->action
) {
1062 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1063 retval
= zfcp_erp_adapter_strategy(erp_action
);
1066 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1067 retval
= zfcp_erp_port_forced_strategy(erp_action
);
1070 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1071 retval
= zfcp_erp_port_strategy(erp_action
);
1074 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1075 retval
= zfcp_erp_unit_strategy(erp_action
);
1079 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1080 "adapter %s (action=%d)\n",
1081 zfcp_get_busid_by_adapter(erp_action
->adapter
),
1082 erp_action
->action
);
1091 * purpose: triggers retry of this action after a certain amount of time
1092 * by means of timer provided by erp_action
1094 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1097 zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
1099 int retval
= ZFCP_ERP_CONTINUES
;
1101 init_timer(&erp_action
->timer
);
1102 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
1103 erp_action
->timer
.data
= (unsigned long) erp_action
;
1104 erp_action
->timer
.expires
= jiffies
+ ZFCP_ERP_MEMWAIT_TIMEOUT
;
1105 add_timer(&erp_action
->timer
);
1111 * function: zfcp_erp_adapter_failed
1113 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1117 zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, u8 id
, void *ref
)
1119 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1120 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1121 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1122 zfcp_get_busid_by_adapter(adapter
));
1126 * function: zfcp_erp_port_failed
1128 * purpose: sets the port and all underlying devices to ERP_FAILED
1132 zfcp_erp_port_failed(struct zfcp_port
*port
, u8 id
, void *ref
)
1134 zfcp_erp_modify_port_status(port
, id
, ref
,
1135 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1137 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA
, &port
->status
))
1138 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1139 "port d_id=0x%06x)\n",
1140 zfcp_get_busid_by_port(port
), port
->d_id
);
1142 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1143 zfcp_get_busid_by_port(port
), port
->wwpn
);
1147 * function: zfcp_erp_unit_failed
1149 * purpose: sets the unit to ERP_FAILED
1153 zfcp_erp_unit_failed(struct zfcp_unit
*unit
, u8 id
, void *ref
)
1155 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1156 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1158 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1159 " on adapter %s\n", unit
->fcp_lun
,
1160 unit
->port
->wwpn
, zfcp_get_busid_by_unit(unit
));
1164 * function: zfcp_erp_strategy_check_target
1166 * purpose: increments the erp action count on the device currently in
1167 * recovery if the action failed or resets the count in case of
1168 * success. If a maximum count is exceeded the device is marked
1170 * The 'blocked' state of a target which has been recovered
1171 * successfully is reset.
1173 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1174 * ZFCP_ERP_SUCCEEDED - action finished successfully
1175 * ZFCP_ERP_EXIT - action failed and will not continue
1178 zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
, int result
)
1180 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1181 struct zfcp_port
*port
= erp_action
->port
;
1182 struct zfcp_unit
*unit
= erp_action
->unit
;
1184 switch (erp_action
->action
) {
1186 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1187 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1191 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1192 result
= zfcp_erp_strategy_check_port(port
, result
);
1195 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1196 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1204 zfcp_erp_strategy_statechange(int action
,
1206 struct zfcp_adapter
*adapter
,
1207 struct zfcp_port
*port
,
1208 struct zfcp_unit
*unit
, int retval
)
1212 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1213 if (zfcp_erp_strategy_statechange_detected(&adapter
->status
,
1215 zfcp_erp_adapter_reopen_internal(adapter
,
1216 ZFCP_STATUS_COMMON_ERP_FAILED
,
1218 retval
= ZFCP_ERP_EXIT
;
1222 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1223 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1224 if (zfcp_erp_strategy_statechange_detected(&port
->status
,
1226 zfcp_erp_port_reopen_internal(port
,
1227 ZFCP_STATUS_COMMON_ERP_FAILED
,
1229 retval
= ZFCP_ERP_EXIT
;
1233 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1234 if (zfcp_erp_strategy_statechange_detected(&unit
->status
,
1236 zfcp_erp_unit_reopen_internal(unit
,
1237 ZFCP_STATUS_COMMON_ERP_FAILED
,
1239 retval
= ZFCP_ERP_EXIT
;
1248 zfcp_erp_strategy_statechange_detected(atomic_t
* target_status
, u32 erp_status
)
1251 /* take it online */
1252 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING
, target_status
) &&
1253 (ZFCP_STATUS_ERP_CLOSE_ONLY
& erp_status
)) ||
1254 /* take it offline */
1255 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING
, target_status
) &&
1256 !(ZFCP_STATUS_ERP_CLOSE_ONLY
& erp_status
));
1260 zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
1263 case ZFCP_ERP_SUCCEEDED
:
1264 atomic_set(&unit
->erp_counter
, 0);
1265 zfcp_erp_unit_unblock(unit
);
1267 case ZFCP_ERP_FAILED
:
1268 atomic_inc(&unit
->erp_counter
);
1269 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
)
1270 zfcp_erp_unit_failed(unit
, 21, NULL
);
1272 case ZFCP_ERP_EXIT
:
1277 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &unit
->status
)) {
1278 zfcp_erp_unit_block(unit
, 0); /* for ZFCP_ERP_SUCCEEDED */
1279 result
= ZFCP_ERP_EXIT
;
1286 zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1289 case ZFCP_ERP_SUCCEEDED
:
1290 atomic_set(&port
->erp_counter
, 0);
1291 zfcp_erp_port_unblock(port
);
1293 case ZFCP_ERP_FAILED
:
1294 atomic_inc(&port
->erp_counter
);
1295 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
)
1296 zfcp_erp_port_failed(port
, 22, NULL
);
1298 case ZFCP_ERP_EXIT
:
1303 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &port
->status
)) {
1304 zfcp_erp_port_block(port
, 0); /* for ZFCP_ERP_SUCCEEDED */
1305 result
= ZFCP_ERP_EXIT
;
1312 zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
, int result
)
1315 case ZFCP_ERP_SUCCEEDED
:
1316 atomic_set(&adapter
->erp_counter
, 0);
1317 zfcp_erp_adapter_unblock(adapter
);
1319 case ZFCP_ERP_FAILED
:
1320 atomic_inc(&adapter
->erp_counter
);
1321 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
)
1322 zfcp_erp_adapter_failed(adapter
, 23, NULL
);
1324 case ZFCP_ERP_EXIT
:
1329 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED
, &adapter
->status
)) {
1330 zfcp_erp_adapter_block(adapter
, 0); /* for ZFCP_ERP_SUCCEEDED */
1331 result
= ZFCP_ERP_EXIT
;
1337 struct zfcp_erp_add_work
{
1338 struct zfcp_unit
*unit
;
1339 struct work_struct work
;
1343 * zfcp_erp_scsi_scan
1344 * @data: pointer to a struct zfcp_erp_add_work
1346 * Registers a logical unit with the SCSI stack.
1348 static void zfcp_erp_scsi_scan(struct work_struct
*work
)
1350 struct zfcp_erp_add_work
*p
=
1351 container_of(work
, struct zfcp_erp_add_work
, work
);
1352 struct zfcp_unit
*unit
= p
->unit
;
1353 struct fc_rport
*rport
= unit
->port
->rport
;
1354 scsi_scan_target(&rport
->dev
, 0, rport
->scsi_target_id
,
1356 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING
, &unit
->status
);
1357 zfcp_unit_put(unit
);
1362 * zfcp_erp_schedule_work
1363 * @unit: pointer to unit which should be registered with SCSI stack
1365 * Schedules work which registers a unit with the SCSI stack
1368 zfcp_erp_schedule_work(struct zfcp_unit
*unit
)
1370 struct zfcp_erp_add_work
*p
;
1372 p
= kzalloc(sizeof(*p
), GFP_KERNEL
);
1374 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1375 "the FCP-LUN 0x%Lx connected to "
1376 "the port with WWPN 0x%Lx connected to "
1377 "the adapter %s with the SCSI stack.\n",
1380 zfcp_get_busid_by_unit(unit
));
1384 zfcp_unit_get(unit
);
1385 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING
, &unit
->status
);
1386 INIT_WORK(&p
->work
, zfcp_erp_scsi_scan
);
1388 schedule_work(&p
->work
);
1394 * purpose: remaining things in good cases,
1395 * escalation in bad cases
1400 zfcp_erp_strategy_followup_actions(int action
,
1401 struct zfcp_adapter
*adapter
,
1402 struct zfcp_port
*port
,
1403 struct zfcp_unit
*unit
, int status
)
1405 /* initiate follow-up actions depending on success of finished action */
1408 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1409 if (status
== ZFCP_ERP_SUCCEEDED
)
1410 zfcp_erp_port_reopen_all_internal(adapter
, 0, 70, NULL
);
1412 zfcp_erp_adapter_reopen_internal(adapter
, 0, 71, NULL
);
1415 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1416 if (status
== ZFCP_ERP_SUCCEEDED
)
1417 zfcp_erp_port_reopen_internal(port
, 0, 72, NULL
);
1419 zfcp_erp_adapter_reopen_internal(adapter
, 0, 73, NULL
);
1422 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1423 if (status
== ZFCP_ERP_SUCCEEDED
)
1424 zfcp_erp_unit_reopen_all_internal(port
, 0, 74, NULL
);
1426 zfcp_erp_port_forced_reopen_internal(port
, 0, 75, NULL
);
1429 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1430 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1431 if (status
!= ZFCP_ERP_SUCCEEDED
)
1432 zfcp_erp_port_reopen_internal(unit
->port
, 0, 76, NULL
);
1440 zfcp_erp_strategy_check_queues(struct zfcp_adapter
*adapter
)
1442 unsigned long flags
;
1444 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1445 read_lock(&adapter
->erp_lock
);
1446 if (list_empty(&adapter
->erp_ready_head
) &&
1447 list_empty(&adapter
->erp_running_head
)) {
1448 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
1450 wake_up(&adapter
->erp_done_wqh
);
1452 read_unlock(&adapter
->erp_lock
);
1453 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1459 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1460 * @adapter: adapter for which to wait for completion of its error recovery
1464 zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1468 wait_event(adapter
->erp_done_wqh
,
1469 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
1475 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, u8 id
,
1476 void *ref
, u32 mask
, int set_or_clear
)
1478 struct zfcp_port
*port
;
1479 u32 changed
, common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1481 if (set_or_clear
== ZFCP_SET
) {
1482 changed
= atomic_test_and_set_mask(mask
, &adapter
->status
);
1484 changed
= atomic_test_and_clear_mask(mask
, &adapter
->status
);
1485 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1486 atomic_set(&adapter
->erp_counter
, 0);
1489 zfcp_rec_dbf_event_adapter(id
, ref
, adapter
);
1491 /* Deal with all underlying devices, only pass common_mask */
1493 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1494 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1499 * function: zfcp_erp_modify_port_status
1501 * purpose: sets the port and all underlying devices to ERP_FAILED
1504 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, u8 id
, void *ref
,
1505 u32 mask
, int set_or_clear
)
1507 struct zfcp_unit
*unit
;
1508 u32 changed
, common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1510 if (set_or_clear
== ZFCP_SET
) {
1511 changed
= atomic_test_and_set_mask(mask
, &port
->status
);
1513 changed
= atomic_test_and_clear_mask(mask
, &port
->status
);
1514 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1515 atomic_set(&port
->erp_counter
, 0);
1518 zfcp_rec_dbf_event_port(id
, ref
, port
);
1520 /* Modify status of all underlying devices, only pass common mask */
1522 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1523 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1528 * function: zfcp_erp_modify_unit_status
1530 * purpose: sets the unit to ERP_FAILED
1533 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, u8 id
, void *ref
,
1534 u32 mask
, int set_or_clear
)
1538 if (set_or_clear
== ZFCP_SET
) {
1539 changed
= atomic_test_and_set_mask(mask
, &unit
->status
);
1541 changed
= atomic_test_and_clear_mask(mask
, &unit
->status
);
1542 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1543 atomic_set(&unit
->erp_counter
, 0);
1547 zfcp_rec_dbf_event_unit(id
, ref
, unit
);
1553 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1554 * used to ensure the correct locking
1556 * returns: 0 - initiated action successfully
1557 * <0 - failed to initiate action
1559 int zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
, int clear_mask
,
1563 unsigned long flags
;
1565 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1566 write_lock(&adapter
->erp_lock
);
1567 retval
= zfcp_erp_port_reopen_all_internal(adapter
, clear_mask
, id
,
1569 write_unlock(&adapter
->erp_lock
);
1570 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1575 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter
*adapter
,
1576 int clear_mask
, u8 id
, void *ref
)
1579 struct zfcp_port
*port
;
1581 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1582 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA
, &port
->status
))
1583 zfcp_erp_port_reopen_internal(port
, clear_mask
, id
,
1596 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port
*port
,
1597 int clear_mask
, u8 id
, void *ref
)
1600 struct zfcp_unit
*unit
;
1602 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1603 zfcp_erp_unit_reopen_internal(unit
, clear_mask
, id
, ref
);
1611 * purpose: this routine executes the 'Reopen Adapter' action
1612 * (the entire action is processed synchronously, since
1613 * there are no actions which might be run concurrently
1616 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1617 * ZFCP_ERP_FAILED - action finished unsuccessfully
1620 zfcp_erp_adapter_strategy(struct zfcp_erp_action
*erp_action
)
1623 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1625 retval
= zfcp_erp_adapter_strategy_close(erp_action
);
1626 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
1627 retval
= ZFCP_ERP_EXIT
;
1629 retval
= zfcp_erp_adapter_strategy_open(erp_action
);
1631 if (retval
== ZFCP_ERP_FAILED
) {
1632 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1633 "to recover itself\n",
1634 zfcp_get_busid_by_adapter(adapter
));
1635 ssleep(ZFCP_TYPE2_RECOVERY_TIME
);
1646 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1647 * ZFCP_ERP_FAILED - action finished unsuccessfully
1650 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*erp_action
)
1654 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING
,
1655 &erp_action
->adapter
->status
);
1656 retval
= zfcp_erp_adapter_strategy_generic(erp_action
, 1);
1657 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING
,
1658 &erp_action
->adapter
->status
);
1668 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1669 * ZFCP_ERP_FAILED - action finished unsuccessfully
1672 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*erp_action
)
1676 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING
,
1677 &erp_action
->adapter
->status
);
1678 retval
= zfcp_erp_adapter_strategy_generic(erp_action
, 0);
1679 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING
,
1680 &erp_action
->adapter
->status
);
1686 * function: zfcp_register_adapter
1688 * purpose: allocate the irq associated with this devno and register
1689 * the FSF adapter with the SCSI stack
1694 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action
*erp_action
, int close
)
1696 int retval
= ZFCP_ERP_SUCCEEDED
;
1701 retval
= zfcp_erp_adapter_strategy_open_qdio(erp_action
);
1702 if (retval
!= ZFCP_ERP_SUCCEEDED
)
1705 retval
= zfcp_erp_adapter_strategy_open_fsf(erp_action
);
1706 if (retval
!= ZFCP_ERP_SUCCEEDED
)
1707 goto failed_openfcp
;
1709 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &erp_action
->adapter
->status
);
1713 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN
,
1714 &erp_action
->adapter
->status
);
1717 zfcp_close_fsf(erp_action
->adapter
);
1719 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
1720 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
|
1721 ZFCP_STATUS_ADAPTER_XPORT_OK
,
1722 &erp_action
->adapter
->status
);
1728 * function: zfcp_qdio_init
1730 * purpose: setup QDIO operation for specified adapter
1732 * returns: 0 - successful setup
1736 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*erp_action
)
1740 volatile struct qdio_buffer_element
*sbale
;
1741 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1743 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &adapter
->status
)) {
1744 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1746 zfcp_get_busid_by_adapter(adapter
));
1750 if (qdio_establish(&adapter
->qdio_init_data
) != 0) {
1751 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1753 zfcp_get_busid_by_adapter(adapter
));
1754 goto failed_qdio_establish
;
1757 if (qdio_activate(adapter
->ccw_device
, 0) != 0) {
1758 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1760 zfcp_get_busid_by_adapter(adapter
));
1761 goto failed_qdio_activate
;
1765 * put buffers into response queue,
1767 for (i
= 0; i
< QDIO_MAX_BUFFERS_PER_Q
; i
++) {
1768 sbale
= &(adapter
->response_queue
.buffer
[i
]->element
[0]);
1770 sbale
->flags
= SBAL_FLAGS_LAST_ENTRY
;
1774 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1775 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1776 zfcp_get_busid_by_adapter(adapter
),
1777 QDIO_FLAG_SYNC_INPUT
, 0, 0, QDIO_MAX_BUFFERS_PER_Q
);
1779 retval
= do_QDIO(adapter
->ccw_device
,
1780 QDIO_FLAG_SYNC_INPUT
,
1781 0, 0, QDIO_MAX_BUFFERS_PER_Q
, NULL
);
1784 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
1786 goto failed_do_qdio
;
1788 adapter
->response_queue
.free_index
= 0;
1789 atomic_set(&adapter
->response_queue
.free_count
, 0);
1790 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
1791 "response queue\n", QDIO_MAX_BUFFERS_PER_Q
);
1793 /* set index of first avalable SBALS / number of available SBALS */
1794 adapter
->request_queue
.free_index
= 0;
1795 atomic_set(&adapter
->request_queue
.free_count
, QDIO_MAX_BUFFERS_PER_Q
);
1796 adapter
->request_queue
.distance_from_int
= 0;
1798 /* initialize waitqueue used to wait for free SBALs in requests queue */
1799 init_waitqueue_head(&adapter
->request_wq
);
1801 /* ok, we did it - skip all cleanups for different failures */
1802 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &adapter
->status
);
1803 retval
= ZFCP_ERP_SUCCEEDED
;
1809 failed_qdio_activate
:
1810 while (qdio_shutdown(adapter
->ccw_device
,
1811 QDIO_FLAG_CLEANUP_USING_CLEAR
) == -EINPROGRESS
)
1814 failed_qdio_establish
:
1816 retval
= ZFCP_ERP_FAILED
;
1824 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*erp_action
)
1828 retval
= zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action
);
1829 if (retval
== ZFCP_ERP_FAILED
)
1830 return ZFCP_ERP_FAILED
;
1832 retval
= zfcp_erp_adapter_strategy_open_fsf_xport(erp_action
);
1833 if (retval
== ZFCP_ERP_FAILED
)
1834 return ZFCP_ERP_FAILED
;
1836 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action
);
1840 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action
*erp_action
)
1842 int retval
= ZFCP_ERP_SUCCEEDED
;
1844 int sleep
= ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP
;
1845 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1847 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
1849 for (retries
= ZFCP_EXCHANGE_CONFIG_DATA_RETRIES
; retries
; retries
--) {
1850 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
1852 ZFCP_LOG_DEBUG("Doing exchange config data\n");
1853 write_lock_irq(&adapter
->erp_lock
);
1854 zfcp_erp_action_to_running(erp_action
);
1855 write_unlock_irq(&adapter
->erp_lock
);
1856 if (zfcp_fsf_exchange_config_data(erp_action
)) {
1857 retval
= ZFCP_ERP_FAILED
;
1858 ZFCP_LOG_INFO("error: initiation of exchange of "
1859 "configuration data failed for "
1861 zfcp_get_busid_by_adapter(adapter
));
1864 ZFCP_LOG_DEBUG("Xchange underway\n");
1868 * Both the normal completion handler as well as the timeout
1869 * handler will do an 'up' when the 'exchange config data'
1870 * request completes or times out. Thus, the signal to go on
1871 * won't be lost utilizing this semaphore.
1872 * Furthermore, this 'adapter_reopen' action is
1873 * guaranteed to be the only action being there (highest action
1874 * which prevents other actions from being created).
1875 * Resulting from that, the wake signal recognized here
1876 * _must_ be the one belonging to the 'exchange config
1879 zfcp_rec_dbf_event_thread_lock(6, adapter
);
1880 down(&adapter
->erp_ready_sem
);
1881 zfcp_rec_dbf_event_thread_lock(7, adapter
);
1882 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
1883 ZFCP_LOG_INFO("error: exchange of configuration data "
1884 "for adapter %s timed out\n",
1885 zfcp_get_busid_by_adapter(adapter
));
1889 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
1893 ZFCP_LOG_DEBUG("host connection still initialising... "
1894 "waiting and retrying...\n");
1895 /* sleep a little bit before retry */
1900 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
1903 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
,
1904 &adapter
->status
)) {
1905 ZFCP_LOG_INFO("error: exchange of configuration data for "
1906 "adapter %s failed\n",
1907 zfcp_get_busid_by_adapter(adapter
));
1908 retval
= ZFCP_ERP_FAILED
;
1915 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*erp_action
)
1918 struct zfcp_adapter
*adapter
;
1920 adapter
= erp_action
->adapter
;
1921 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK
, &adapter
->status
);
1923 write_lock_irq(&adapter
->erp_lock
);
1924 zfcp_erp_action_to_running(erp_action
);
1925 write_unlock_irq(&adapter
->erp_lock
);
1927 ret
= zfcp_fsf_exchange_port_data(erp_action
);
1928 if (ret
== -EOPNOTSUPP
) {
1929 return ZFCP_ERP_SUCCEEDED
;
1931 return ZFCP_ERP_FAILED
;
1934 ret
= ZFCP_ERP_SUCCEEDED
;
1935 zfcp_rec_dbf_event_thread_lock(8, adapter
);
1936 down(&adapter
->erp_ready_sem
);
1937 zfcp_rec_dbf_event_thread_lock(9, adapter
);
1938 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
1939 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
1940 "%s)\n", zfcp_get_busid_by_adapter(adapter
));
1941 ret
= ZFCP_ERP_FAILED
;
1944 /* don't treat as error for the sake of compatibility */
1945 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK
, &adapter
->status
))
1946 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
1947 "%s\n", zfcp_get_busid_by_adapter(adapter
));
1953 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
1956 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1958 atomic_set(&adapter
->stat_miss
, 16);
1959 return zfcp_status_read_refill(adapter
);
1965 * purpose: this routine executes the 'Reopen Physical Port' action
1967 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1968 * ZFCP_ERP_SUCCEEDED - action finished successfully
1969 * ZFCP_ERP_FAILED - action finished unsuccessfully
1972 zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
1974 int retval
= ZFCP_ERP_FAILED
;
1975 struct zfcp_port
*port
= erp_action
->port
;
1977 switch (erp_action
->step
) {
1981 * the ULP spec. begs for waiting for oustanding commands
1983 case ZFCP_ERP_STEP_UNINITIALIZED
:
1984 zfcp_erp_port_strategy_clearstati(port
);
1986 * it would be sufficient to test only the normal open flag
1987 * since the phys. open flag cannot be set if the normal
1988 * open flag is unset - however, this is for readabilty ...
1990 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN
|
1991 ZFCP_STATUS_COMMON_OPEN
),
1993 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
1994 "close physical\n", port
->wwpn
);
1996 zfcp_erp_port_forced_strategy_close(erp_action
);
1998 retval
= ZFCP_ERP_FAILED
;
2001 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
2002 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN
,
2004 ZFCP_LOG_DEBUG("close physical failed for port "
2005 "0x%016Lx\n", port
->wwpn
);
2006 retval
= ZFCP_ERP_FAILED
;
2008 retval
= ZFCP_ERP_SUCCEEDED
;
2018 * purpose: this routine executes the 'Reopen Port' action
2020 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2021 * ZFCP_ERP_SUCCEEDED - action finished successfully
2022 * ZFCP_ERP_FAILED - action finished unsuccessfully
2025 zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
2027 int retval
= ZFCP_ERP_FAILED
;
2028 struct zfcp_port
*port
= erp_action
->port
;
2030 switch (erp_action
->step
) {
2034 * the ULP spec. begs for waiting for oustanding commands
2036 case ZFCP_ERP_STEP_UNINITIALIZED
:
2037 zfcp_erp_port_strategy_clearstati(port
);
2038 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &port
->status
)) {
2039 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2040 "close\n", port
->wwpn
);
2041 retval
= zfcp_erp_port_strategy_close(erp_action
);
2043 } /* else it's already closed, open it */
2046 case ZFCP_ERP_STEP_PORT_CLOSING
:
2047 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &port
->status
)) {
2048 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2050 retval
= ZFCP_ERP_FAILED
;
2052 } /* else it's closed now, open it */
2055 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
2056 retval
= ZFCP_ERP_EXIT
;
2058 retval
= zfcp_erp_port_strategy_open(erp_action
);
2065 zfcp_erp_port_strategy_open(struct zfcp_erp_action
*erp_action
)
2069 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA
,
2070 &erp_action
->port
->status
))
2071 retval
= zfcp_erp_port_strategy_open_nameserver(erp_action
);
2073 retval
= zfcp_erp_port_strategy_open_common(erp_action
);
2079 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*erp_action
)
2082 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
2083 struct zfcp_port
*port
= erp_action
->port
;
2085 switch (erp_action
->step
) {
2087 case ZFCP_ERP_STEP_UNINITIALIZED
:
2088 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
2089 case ZFCP_ERP_STEP_PORT_CLOSING
:
2090 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
) {
2091 if (port
->wwpn
!= adapter
->peer_wwpn
) {
2092 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2093 "on adapter %s.\nPeer WWPN "
2094 "0x%016Lx does not match\n",
2096 zfcp_get_busid_by_adapter(adapter
),
2097 adapter
->peer_wwpn
);
2098 zfcp_erp_port_failed(port
, 25, NULL
);
2099 retval
= ZFCP_ERP_FAILED
;
2102 port
->d_id
= adapter
->peer_d_id
;
2103 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
);
2104 retval
= zfcp_erp_port_strategy_open_port(erp_action
);
2107 if (!(adapter
->nameserver_port
)) {
2108 retval
= zfcp_nameserver_enqueue(adapter
);
2110 ZFCP_LOG_NORMAL("error: nameserver port "
2111 "unavailable for adapter %s\n",
2112 zfcp_get_busid_by_adapter(adapter
));
2113 retval
= ZFCP_ERP_FAILED
;
2117 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED
,
2118 &adapter
->nameserver_port
->status
)) {
2119 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2120 "nameserver port\n");
2121 /* nameserver port may live again */
2122 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING
,
2123 &adapter
->nameserver_port
->status
);
2124 if (zfcp_erp_port_reopen(adapter
->nameserver_port
, 0,
2125 77, erp_action
) >= 0) {
2127 ZFCP_ERP_STEP_NAMESERVER_OPEN
;
2128 retval
= ZFCP_ERP_CONTINUES
;
2130 retval
= ZFCP_ERP_FAILED
;
2133 /* else nameserver port is already open, fall through */
2134 case ZFCP_ERP_STEP_NAMESERVER_OPEN
:
2135 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
,
2136 &adapter
->nameserver_port
->status
)) {
2137 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2138 retval
= ZFCP_ERP_FAILED
;
2140 ZFCP_LOG_DEBUG("nameserver port is open -> "
2141 "nameserver look-up for port 0x%016Lx\n",
2143 retval
= zfcp_erp_port_strategy_open_common_lookup
2148 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP
:
2149 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID
, &port
->status
)) {
2150 if (atomic_test_mask
2151 (ZFCP_STATUS_PORT_INVALID_WWPN
, &port
->status
)) {
2152 ZFCP_LOG_DEBUG("nameserver look-up failed "
2153 "for port 0x%016Lx "
2154 "(misconfigured WWPN?)\n",
2156 zfcp_erp_port_failed(port
, 26, NULL
);
2157 retval
= ZFCP_ERP_EXIT
;
2159 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2160 "port 0x%016Lx\n", port
->wwpn
);
2161 retval
= ZFCP_ERP_FAILED
;
2164 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2165 "trying open\n", port
->wwpn
, port
->d_id
);
2166 retval
= zfcp_erp_port_strategy_open_port(erp_action
);
2170 case ZFCP_ERP_STEP_PORT_OPENING
:
2171 /* D_ID might have changed during open */
2172 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN
|
2173 ZFCP_STATUS_PORT_DID_DID
),
2175 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port
->wwpn
);
2176 retval
= ZFCP_ERP_SUCCEEDED
;
2178 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2180 retval
= ZFCP_ERP_FAILED
;
2185 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2187 retval
= ZFCP_ERP_FAILED
;
2194 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action
*erp_action
)
2197 struct zfcp_port
*port
= erp_action
->port
;
2199 switch (erp_action
->step
) {
2201 case ZFCP_ERP_STEP_UNINITIALIZED
:
2202 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
2203 case ZFCP_ERP_STEP_PORT_CLOSING
:
2204 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2205 port
->wwpn
, port
->d_id
);
2206 retval
= zfcp_erp_port_strategy_open_port(erp_action
);
2209 case ZFCP_ERP_STEP_PORT_OPENING
:
2210 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &port
->status
)) {
2211 ZFCP_LOG_DEBUG("WKA port is open\n");
2212 retval
= ZFCP_ERP_SUCCEEDED
;
2214 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2215 retval
= ZFCP_ERP_FAILED
;
2217 /* this is needed anyway (dont care for retval of wakeup) */
2218 ZFCP_LOG_DEBUG("continue other open port operations\n");
2219 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action
);
2223 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2225 retval
= ZFCP_ERP_FAILED
;
2234 * purpose: makes the erp thread continue with reopen (physical) port
2235 * actions which have been paused until the name server port
2236 * is opened (or failed)
2238 * returns: 0 (a kind of void retval, its not used)
2241 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2245 unsigned long flags
;
2246 struct zfcp_adapter
*adapter
= ns_erp_action
->adapter
;
2247 struct zfcp_erp_action
*erp_action
, *tmp
;
2249 read_lock_irqsave(&adapter
->erp_lock
, flags
);
2250 list_for_each_entry_safe(erp_action
, tmp
, &adapter
->erp_running_head
,
2252 if (erp_action
->step
== ZFCP_ERP_STEP_NAMESERVER_OPEN
) {
2253 if (atomic_test_mask(
2254 ZFCP_STATUS_COMMON_ERP_FAILED
,
2255 &adapter
->nameserver_port
->status
))
2256 zfcp_erp_port_failed(erp_action
->port
, 27,
2258 zfcp_erp_action_ready(erp_action
);
2261 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
2271 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2272 * ZFCP_ERP_FAILED - action finished unsuccessfully
2275 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*erp_action
)
2279 retval
= zfcp_fsf_close_physical_port(erp_action
);
2280 if (retval
== -ENOMEM
) {
2281 retval
= ZFCP_ERP_NOMEM
;
2284 erp_action
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
2286 /* could not send 'open', fail */
2287 retval
= ZFCP_ERP_FAILED
;
2290 retval
= ZFCP_ERP_CONTINUES
;
2296 zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
2300 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING
|
2301 ZFCP_STATUS_COMMON_CLOSING
|
2302 ZFCP_STATUS_COMMON_ACCESS_DENIED
|
2303 ZFCP_STATUS_PORT_DID_DID
|
2304 ZFCP_STATUS_PORT_PHYS_CLOSING
|
2305 ZFCP_STATUS_PORT_INVALID_WWPN
,
2315 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2316 * ZFCP_ERP_FAILED - action finished unsuccessfully
2319 zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
2323 retval
= zfcp_fsf_close_port(erp_action
);
2324 if (retval
== -ENOMEM
) {
2325 retval
= ZFCP_ERP_NOMEM
;
2328 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
2330 /* could not send 'close', fail */
2331 retval
= ZFCP_ERP_FAILED
;
2334 retval
= ZFCP_ERP_CONTINUES
;
2344 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2345 * ZFCP_ERP_FAILED - action finished unsuccessfully
2348 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
2352 retval
= zfcp_fsf_open_port(erp_action
);
2353 if (retval
== -ENOMEM
) {
2354 retval
= ZFCP_ERP_NOMEM
;
2357 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
2359 /* could not send 'open', fail */
2360 retval
= ZFCP_ERP_FAILED
;
2363 retval
= ZFCP_ERP_CONTINUES
;
2373 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2374 * ZFCP_ERP_FAILED - action finished unsuccessfully
2377 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action
*erp_action
)
2381 retval
= zfcp_fc_ns_gid_pn_request(erp_action
);
2382 if (retval
== -ENOMEM
) {
2383 retval
= ZFCP_ERP_NOMEM
;
2386 erp_action
->step
= ZFCP_ERP_STEP_NAMESERVER_LOOKUP
;
2388 /* could not send nameserver request, fail */
2389 retval
= ZFCP_ERP_FAILED
;
2392 retval
= ZFCP_ERP_CONTINUES
;
2400 * purpose: this routine executes the 'Reopen Unit' action
2401 * currently no retries
2403 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2404 * ZFCP_ERP_SUCCEEDED - action finished successfully
2405 * ZFCP_ERP_FAILED - action finished unsuccessfully
2408 zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
2410 int retval
= ZFCP_ERP_FAILED
;
2411 struct zfcp_unit
*unit
= erp_action
->unit
;
2413 switch (erp_action
->step
) {
2417 * the ULP spec. begs for waiting for oustanding commands
2419 case ZFCP_ERP_STEP_UNINITIALIZED
:
2420 zfcp_erp_unit_strategy_clearstati(unit
);
2421 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
)) {
2422 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2423 "trying close\n", unit
->fcp_lun
);
2424 retval
= zfcp_erp_unit_strategy_close(erp_action
);
2427 /* else it's already closed, fall through */
2428 case ZFCP_ERP_STEP_UNIT_CLOSING
:
2429 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
)) {
2430 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2432 retval
= ZFCP_ERP_FAILED
;
2434 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
2435 retval
= ZFCP_ERP_EXIT
;
2437 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2438 "trying open\n", unit
->fcp_lun
);
2440 zfcp_erp_unit_strategy_open(erp_action
);
2445 case ZFCP_ERP_STEP_UNIT_OPENING
:
2446 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN
, &unit
->status
)) {
2447 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2449 retval
= ZFCP_ERP_SUCCEEDED
;
2451 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2453 retval
= ZFCP_ERP_FAILED
;
2462 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
2466 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING
|
2467 ZFCP_STATUS_COMMON_CLOSING
|
2468 ZFCP_STATUS_COMMON_ACCESS_DENIED
|
2469 ZFCP_STATUS_UNIT_SHARED
|
2470 ZFCP_STATUS_UNIT_READONLY
,
2481 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2482 * ZFCP_ERP_FAILED - action finished unsuccessfully
2485 zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
2489 retval
= zfcp_fsf_close_unit(erp_action
);
2490 if (retval
== -ENOMEM
) {
2491 retval
= ZFCP_ERP_NOMEM
;
2494 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
2496 /* could not send 'close', fail */
2497 retval
= ZFCP_ERP_FAILED
;
2500 retval
= ZFCP_ERP_CONTINUES
;
2511 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2512 * ZFCP_ERP_FAILED - action finished unsuccessfully
2515 zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
2519 retval
= zfcp_fsf_open_unit(erp_action
);
2520 if (retval
== -ENOMEM
) {
2521 retval
= ZFCP_ERP_NOMEM
;
2524 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
2526 /* could not send 'open', fail */
2527 retval
= ZFCP_ERP_FAILED
;
2530 retval
= ZFCP_ERP_CONTINUES
;
2535 void zfcp_erp_start_timer(struct zfcp_fsf_req
*fsf_req
)
2537 BUG_ON(!fsf_req
->erp_action
);
2538 fsf_req
->timer
.function
= zfcp_erp_timeout_handler
;
2539 fsf_req
->timer
.data
= (unsigned long) fsf_req
->erp_action
;
2540 fsf_req
->timer
.expires
= jiffies
+ ZFCP_ERP_FSFREQ_TIMEOUT
;
2541 add_timer(&fsf_req
->timer
);
2547 * purpose: enqueue the specified error recovery action, if needed
2551 static int zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
2552 struct zfcp_port
*port
,
2553 struct zfcp_unit
*unit
, u8 id
, void *ref
)
2555 int retval
= 1, need
= want
;
2556 struct zfcp_erp_action
*erp_action
= NULL
;
2560 * We need some rules here which check whether we really need
2561 * this action or whether we should just drop it.
2562 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2563 * 'Reopen Unit' request for an associated unit since we can't
2564 * satisfy this request now. A 'Reopen Port' action will trigger
2565 * 'Reopen Unit' actions when it completes.
2566 * Thus, there are only actions in the queue which can immediately be
2567 * executed. This makes the processing of the action queue more
2571 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
,
2575 /* check whether we really need this */
2577 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
2578 if (atomic_test_mask
2579 (ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
)) {
2582 if (!atomic_test_mask
2583 (ZFCP_STATUS_COMMON_RUNNING
, &port
->status
) ||
2585 (ZFCP_STATUS_COMMON_ERP_FAILED
, &port
->status
)) {
2588 if (!atomic_test_mask
2589 (ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
2590 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
2591 /* fall through !!! */
2593 case ZFCP_ERP_ACTION_REOPEN_PORT
:
2594 if (atomic_test_mask
2595 (ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
)) {
2598 /* fall through !!! */
2600 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
2601 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
2603 if (port
->erp_action
.action
!=
2604 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
) {
2605 ZFCP_LOG_INFO("dropped erp action %i (port "
2606 "0x%016Lx, action in use: %i)\n",
2608 port
->erp_action
.action
);
2612 if (!atomic_test_mask
2613 (ZFCP_STATUS_COMMON_RUNNING
, &adapter
->status
) ||
2615 (ZFCP_STATUS_COMMON_ERP_FAILED
, &adapter
->status
)) {
2618 if (!atomic_test_mask
2619 (ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
2620 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
2621 /* fall through !!! */
2623 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
2624 if (atomic_test_mask
2625 (ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
)) {
2631 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2632 "on adapter %s (action=%d)\n",
2633 zfcp_get_busid_by_adapter(adapter
), want
);
2637 /* check whether we need something stronger first */
2639 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2640 "erp action %d on adapter %s\n",
2641 need
, want
, zfcp_get_busid_by_adapter(adapter
));
2644 /* mark adapter to have some error recovery pending */
2645 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
2647 /* setup error recovery action */
2650 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
2651 zfcp_unit_get(unit
);
2652 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
);
2653 erp_action
= &unit
->erp_action
;
2654 if (!atomic_test_mask
2655 (ZFCP_STATUS_COMMON_RUNNING
, &unit
->status
))
2656 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
2659 case ZFCP_ERP_ACTION_REOPEN_PORT
:
2660 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
2661 zfcp_port_get(port
);
2662 zfcp_erp_action_dismiss_port(port
);
2663 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
2664 erp_action
= &port
->erp_action
;
2665 if (!atomic_test_mask
2666 (ZFCP_STATUS_COMMON_RUNNING
, &port
->status
))
2667 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
2670 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
2671 zfcp_adapter_get(adapter
);
2672 zfcp_erp_action_dismiss_adapter(adapter
);
2673 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
2674 erp_action
= &adapter
->erp_action
;
2675 if (!atomic_test_mask
2676 (ZFCP_STATUS_COMMON_RUNNING
, &adapter
->status
))
2677 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
2681 memset(erp_action
, 0, sizeof (struct zfcp_erp_action
));
2682 erp_action
->adapter
= adapter
;
2683 erp_action
->port
= port
;
2684 erp_action
->unit
= unit
;
2685 erp_action
->action
= need
;
2686 erp_action
->status
= status
;
2688 ++adapter
->erp_total_count
;
2690 /* finally put it into 'ready' queue and kick erp thread */
2691 list_add_tail(&erp_action
->list
, &adapter
->erp_ready_head
);
2692 up(&adapter
->erp_ready_sem
);
2693 zfcp_rec_dbf_event_thread(1, adapter
);
2696 zfcp_rec_dbf_event_trigger(id
, ref
, want
, need
, erp_action
,
2697 adapter
, port
, unit
);
2702 zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
2705 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
2707 --adapter
->erp_total_count
;
2708 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
2709 --adapter
->erp_low_mem_count
;
2710 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
2713 list_del(&erp_action
->list
);
2714 zfcp_rec_dbf_event_action(144, erp_action
);
2716 switch (erp_action
->action
) {
2717 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
2718 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
2719 &erp_action
->unit
->status
);
2721 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
2722 case ZFCP_ERP_ACTION_REOPEN_PORT
:
2723 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
2724 &erp_action
->port
->status
);
2726 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
2727 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
2728 &erp_action
->adapter
->status
);
2738 * zfcp_erp_action_cleanup
2740 * Register unit with scsi stack if appropriate and fix reference counts.
2741 * Note: Temporary units are not registered with scsi stack.
2744 zfcp_erp_action_cleanup(int action
, struct zfcp_adapter
*adapter
,
2745 struct zfcp_port
*port
, struct zfcp_unit
*unit
,
2749 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
2750 if ((result
== ZFCP_ERP_SUCCEEDED
)
2751 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY
,
2755 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED
,
2757 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING
,
2758 &unit
->status
) == 0)
2759 zfcp_erp_schedule_work(unit
);
2761 zfcp_unit_put(unit
);
2763 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
2764 case ZFCP_ERP_ACTION_REOPEN_PORT
:
2765 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN
,
2767 zfcp_port_put(port
);
2771 if ((result
== ZFCP_ERP_SUCCEEDED
)
2773 struct fc_rport_identifiers ids
;
2774 ids
.node_name
= port
->wwnn
;
2775 ids
.port_name
= port
->wwpn
;
2776 ids
.port_id
= port
->d_id
;
2777 ids
.roles
= FC_RPORT_ROLE_FCP_TARGET
;
2779 fc_remote_port_add(adapter
->scsi_host
, 0, &ids
);
2781 ZFCP_LOG_NORMAL("failed registration of rport"
2782 "(adapter %s, wwpn=0x%016Lx)\n",
2783 zfcp_get_busid_by_port(port
),
2786 scsi_target_unblock(&port
->rport
->dev
);
2787 port
->rport
->maxframe_size
= port
->maxframe_size
;
2788 port
->rport
->supported_classes
=
2789 port
->supported_classes
;
2792 if ((result
!= ZFCP_ERP_SUCCEEDED
) && port
->rport
) {
2793 fc_remote_port_delete(port
->rport
);
2796 zfcp_port_put(port
);
2798 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
2799 if (result
!= ZFCP_ERP_SUCCEEDED
) {
2800 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
2802 !atomic_test_mask(ZFCP_STATUS_PORT_WKA
,
2804 fc_remote_port_delete(port
->rport
);
2808 zfcp_adapter_put(adapter
);
2816 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
2818 struct zfcp_port
*port
;
2820 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
))
2821 zfcp_erp_action_dismiss(&adapter
->erp_action
);
2823 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
2824 zfcp_erp_action_dismiss_port(port
);
2827 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*port
)
2829 struct zfcp_unit
*unit
;
2831 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
))
2832 zfcp_erp_action_dismiss(&port
->erp_action
);
2834 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
2835 zfcp_erp_action_dismiss_unit(unit
);
2838 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit
*unit
)
2840 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
))
2841 zfcp_erp_action_dismiss(&unit
->erp_action
);
2844 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
2846 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
2847 zfcp_rec_dbf_event_action(145, erp_action
);
2850 static void zfcp_erp_action_to_ready(struct zfcp_erp_action
*erp_action
)
2852 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_ready_head
);
2853 zfcp_rec_dbf_event_action(146, erp_action
);
2856 void zfcp_erp_port_boxed(struct zfcp_port
*port
, u8 id
, void *ref
)
2858 unsigned long flags
;
2860 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
2861 zfcp_erp_modify_port_status(port
, id
, ref
,
2862 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
2863 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
2864 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
2867 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, u8 id
, void *ref
)
2869 zfcp_erp_modify_unit_status(unit
, id
, ref
,
2870 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
2871 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
2874 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, u8 id
, void *ref
)
2876 unsigned long flags
;
2878 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
2879 zfcp_erp_modify_port_status(port
, id
, ref
,
2880 ZFCP_STATUS_COMMON_ERP_FAILED
|
2881 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
2882 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
2885 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, u8 id
, void *ref
)
2887 zfcp_erp_modify_unit_status(unit
, id
, ref
,
2888 ZFCP_STATUS_COMMON_ERP_FAILED
|
2889 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
2892 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, u8 id
,
2895 struct zfcp_port
*port
;
2896 unsigned long flags
;
2898 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
2901 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
2902 if (adapter
->nameserver_port
)
2903 zfcp_erp_port_access_changed(adapter
->nameserver_port
, id
, ref
);
2904 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
2905 if (port
!= adapter
->nameserver_port
)
2906 zfcp_erp_port_access_changed(port
, id
, ref
);
2907 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
2910 void zfcp_erp_port_access_changed(struct zfcp_port
*port
, u8 id
, void *ref
)
2912 struct zfcp_adapter
*adapter
= port
->adapter
;
2913 struct zfcp_unit
*unit
;
2915 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
,
2917 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED
,
2919 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA
, &port
->status
))
2920 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
2921 zfcp_erp_unit_access_changed(unit
, id
, ref
);
2925 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
2926 "(due to ACT update)\n",
2927 port
->wwpn
, zfcp_get_busid_by_adapter(adapter
));
2928 if (zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
))
2929 ZFCP_LOG_NORMAL("failed reopen of port"
2930 "(adapter %s, wwpn=0x%016Lx)\n",
2931 zfcp_get_busid_by_adapter(adapter
), port
->wwpn
);
2934 void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, u8 id
, void *ref
)
2936 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
2938 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
,
2940 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED
,
2944 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
2945 " on adapter %s (due to ACT update)\n",
2946 unit
->fcp_lun
, unit
->port
->wwpn
,
2947 zfcp_get_busid_by_adapter(adapter
));
2948 if (zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
))
2949 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
2950 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
2951 zfcp_get_busid_by_adapter(adapter
),
2952 unit
->port
->wwpn
, unit
->fcp_lun
);
2955 #undef ZFCP_LOG_AREA