4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2010
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kthread.h>
14 #include "zfcp_reqlist.h"
16 #define ZFCP_MAX_ERPS 3
18 enum zfcp_erp_act_flags
{
19 ZFCP_STATUS_ERP_TIMEDOUT
= 0x10000000,
20 ZFCP_STATUS_ERP_CLOSE_ONLY
= 0x01000000,
21 ZFCP_STATUS_ERP_DISMISSING
= 0x00100000,
22 ZFCP_STATUS_ERP_DISMISSED
= 0x00200000,
23 ZFCP_STATUS_ERP_LOWMEM
= 0x00400000,
27 ZFCP_ERP_STEP_UNINITIALIZED
= 0x0000,
28 ZFCP_ERP_STEP_FSF_XCONFIG
= 0x0001,
29 ZFCP_ERP_STEP_PHYS_PORT_CLOSING
= 0x0010,
30 ZFCP_ERP_STEP_PORT_CLOSING
= 0x0100,
31 ZFCP_ERP_STEP_PORT_OPENING
= 0x0800,
32 ZFCP_ERP_STEP_UNIT_CLOSING
= 0x1000,
33 ZFCP_ERP_STEP_UNIT_OPENING
= 0x2000,
36 enum zfcp_erp_act_type
{
37 ZFCP_ERP_ACTION_REOPEN_UNIT
= 1,
38 ZFCP_ERP_ACTION_REOPEN_PORT
= 2,
39 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
= 3,
40 ZFCP_ERP_ACTION_REOPEN_ADAPTER
= 4,
43 enum zfcp_erp_act_state
{
44 ZFCP_ERP_ACTION_RUNNING
= 1,
45 ZFCP_ERP_ACTION_READY
= 2,
48 enum zfcp_erp_act_result
{
49 ZFCP_ERP_SUCCEEDED
= 0,
51 ZFCP_ERP_CONTINUES
= 2,
53 ZFCP_ERP_DISMISSED
= 4,
57 static void zfcp_erp_adapter_block(struct zfcp_adapter
*adapter
, int mask
)
59 zfcp_erp_modify_adapter_status(adapter
, "erablk1", NULL
,
60 ZFCP_STATUS_COMMON_UNBLOCKED
| mask
,
64 static int zfcp_erp_action_exists(struct zfcp_erp_action
*act
)
66 struct zfcp_erp_action
*curr_act
;
68 list_for_each_entry(curr_act
, &act
->adapter
->erp_running_head
, list
)
70 return ZFCP_ERP_ACTION_RUNNING
;
74 static void zfcp_erp_action_ready(struct zfcp_erp_action
*act
)
76 struct zfcp_adapter
*adapter
= act
->adapter
;
78 list_move(&act
->list
, &act
->adapter
->erp_ready_head
);
79 zfcp_dbf_rec_action("erardy1", act
);
80 wake_up(&adapter
->erp_ready_wq
);
81 zfcp_dbf_rec_thread("erardy2", adapter
->dbf
);
84 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*act
)
86 act
->status
|= ZFCP_STATUS_ERP_DISMISSED
;
87 if (zfcp_erp_action_exists(act
) == ZFCP_ERP_ACTION_RUNNING
)
88 zfcp_erp_action_ready(act
);
91 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit
*unit
)
93 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
94 zfcp_erp_action_dismiss(&unit
->erp_action
);
97 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*port
)
99 struct zfcp_unit
*unit
;
101 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
102 zfcp_erp_action_dismiss(&port
->erp_action
);
104 read_lock(&port
->unit_list_lock
);
105 list_for_each_entry(unit
, &port
->unit_list
, list
)
106 zfcp_erp_action_dismiss_unit(unit
);
107 read_unlock(&port
->unit_list_lock
);
111 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
113 struct zfcp_port
*port
;
115 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
116 zfcp_erp_action_dismiss(&adapter
->erp_action
);
118 read_lock(&adapter
->port_list_lock
);
119 list_for_each_entry(port
, &adapter
->port_list
, list
)
120 zfcp_erp_action_dismiss_port(port
);
121 read_unlock(&adapter
->port_list_lock
);
125 static int zfcp_erp_required_act(int want
, struct zfcp_adapter
*adapter
,
126 struct zfcp_port
*port
,
127 struct zfcp_unit
*unit
)
130 int u_status
, p_status
, a_status
;
133 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
134 u_status
= atomic_read(&unit
->status
);
135 if (u_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
137 p_status
= atomic_read(&port
->status
);
138 if (!(p_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
139 p_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
141 if (!(p_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
142 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
144 case ZFCP_ERP_ACTION_REOPEN_PORT
:
145 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
146 p_status
= atomic_read(&port
->status
);
147 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
149 a_status
= atomic_read(&adapter
->status
);
150 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
151 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
153 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
154 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
156 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
157 a_status
= atomic_read(&adapter
->status
);
158 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
160 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) &&
161 !(a_status
& ZFCP_STATUS_COMMON_OPEN
))
162 return 0; /* shutdown requested for closed adapter */
168 static struct zfcp_erp_action
*zfcp_erp_setup_act(int need
,
169 struct zfcp_adapter
*adapter
,
170 struct zfcp_port
*port
,
171 struct zfcp_unit
*unit
)
173 struct zfcp_erp_action
*erp_action
;
177 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
178 if (!get_device(&unit
->dev
))
180 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
);
181 erp_action
= &unit
->erp_action
;
182 if (!(atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
183 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
186 case ZFCP_ERP_ACTION_REOPEN_PORT
:
187 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
188 if (!get_device(&port
->dev
))
190 zfcp_erp_action_dismiss_port(port
);
191 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
192 erp_action
= &port
->erp_action
;
193 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
194 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
198 kref_get(&adapter
->ref
);
199 zfcp_erp_action_dismiss_adapter(adapter
);
200 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
201 erp_action
= &adapter
->erp_action
;
202 if (!(atomic_read(&adapter
->status
) &
203 ZFCP_STATUS_COMMON_RUNNING
))
204 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
211 memset(erp_action
, 0, sizeof(struct zfcp_erp_action
));
212 erp_action
->adapter
= adapter
;
213 erp_action
->port
= port
;
214 erp_action
->unit
= unit
;
215 erp_action
->action
= need
;
216 erp_action
->status
= status
;
221 static int zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
222 struct zfcp_port
*port
,
223 struct zfcp_unit
*unit
, char *id
, void *ref
)
225 int retval
= 1, need
;
226 struct zfcp_erp_action
*act
= NULL
;
228 if (!adapter
->erp_thread
)
231 need
= zfcp_erp_required_act(want
, adapter
, port
, unit
);
235 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
236 act
= zfcp_erp_setup_act(need
, adapter
, port
, unit
);
239 ++adapter
->erp_total_count
;
240 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
241 wake_up(&adapter
->erp_ready_wq
);
242 zfcp_dbf_rec_thread("eracte1", adapter
->dbf
);
245 zfcp_dbf_rec_trigger(id
, ref
, want
, need
, act
, adapter
, port
, unit
);
249 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
250 int clear_mask
, char *id
, void *ref
)
252 zfcp_erp_adapter_block(adapter
, clear_mask
);
253 zfcp_scsi_schedule_rports_block(adapter
);
255 /* ensure propagation of failed status to new devices */
256 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
257 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
260 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
261 adapter
, NULL
, NULL
, id
, ref
);
265 * zfcp_erp_adapter_reopen - Reopen adapter.
266 * @adapter: Adapter to reopen.
267 * @clear: Status flags to clear.
268 * @id: Id for debug trace event.
269 * @ref: Reference for debug trace event.
271 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
276 zfcp_erp_adapter_block(adapter
, clear
);
277 zfcp_scsi_schedule_rports_block(adapter
);
279 write_lock_irqsave(&adapter
->erp_lock
, flags
);
280 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
281 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
283 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
, adapter
,
284 NULL
, NULL
, id
, ref
);
285 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
289 * zfcp_erp_adapter_shutdown - Shutdown adapter.
290 * @adapter: Adapter to shut down.
291 * @clear: Status flags to clear.
292 * @id: Id for debug trace event.
293 * @ref: Reference for debug trace event.
295 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
298 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
299 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
, ref
);
303 * zfcp_erp_port_shutdown - Shutdown port
304 * @port: Port to shut down.
305 * @clear: Status flags to clear.
306 * @id: Id for debug trace event.
307 * @ref: Reference for debug trace event.
309 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
,
312 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
313 zfcp_erp_port_reopen(port
, clear
| flags
, id
, ref
);
317 * zfcp_erp_unit_shutdown - Shutdown unit
318 * @unit: Unit to shut down.
319 * @clear: Status flags to clear.
320 * @id: Id for debug trace event.
321 * @ref: Reference for debug trace event.
323 void zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear
, char *id
,
326 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
327 zfcp_erp_unit_reopen(unit
, clear
| flags
, id
, ref
);
330 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
332 zfcp_erp_modify_port_status(port
, "erpblk1", NULL
,
333 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
,
337 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
,
338 int clear
, char *id
, void *ref
)
340 zfcp_erp_port_block(port
, clear
);
341 zfcp_scsi_schedule_rport_block(port
);
343 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
346 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
347 port
->adapter
, port
, NULL
, id
, ref
);
351 * zfcp_erp_port_forced_reopen - Forced close of port and open again
352 * @port: Port to force close and to reopen.
353 * @id: Id for debug trace event.
354 * @ref: Reference for debug trace event.
356 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
,
360 struct zfcp_adapter
*adapter
= port
->adapter
;
362 write_lock_irqsave(&adapter
->erp_lock
, flags
);
363 _zfcp_erp_port_forced_reopen(port
, clear
, id
, ref
);
364 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
367 static int _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
,
370 zfcp_erp_port_block(port
, clear
);
371 zfcp_scsi_schedule_rport_block(port
);
373 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
374 /* ensure propagation of failed status to new devices */
375 zfcp_erp_port_failed(port
, "erpreo1", NULL
);
379 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
380 port
->adapter
, port
, NULL
, id
, ref
);
384 * zfcp_erp_port_reopen - trigger remote port recovery
385 * @port: port to recover
386 * @clear_mask: flags in port status to be cleared
388 * Returns 0 if recovery has been triggered, < 0 if not.
390 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
, void *ref
)
394 struct zfcp_adapter
*adapter
= port
->adapter
;
396 write_lock_irqsave(&adapter
->erp_lock
, flags
);
397 retval
= _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
398 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
403 static void zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
405 zfcp_erp_modify_unit_status(unit
, "erublk1", NULL
,
406 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
410 static void _zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
413 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
415 zfcp_erp_unit_block(unit
, clear
);
417 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
420 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
421 adapter
, unit
->port
, unit
, id
, ref
);
425 * zfcp_erp_unit_reopen - initiate reopen of a unit
426 * @unit: unit to be reopened
427 * @clear_mask: specifies flags in unit status to be cleared
428 * Return: 0 on success, < 0 on error
430 void zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
434 struct zfcp_port
*port
= unit
->port
;
435 struct zfcp_adapter
*adapter
= port
->adapter
;
437 write_lock_irqsave(&adapter
->erp_lock
, flags
);
438 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
439 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
442 static int status_change_set(unsigned long mask
, atomic_t
*status
)
444 return (atomic_read(status
) ^ mask
) & mask
;
447 static int status_change_clear(unsigned long mask
, atomic_t
*status
)
449 return atomic_read(status
) & mask
;
452 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
454 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
455 zfcp_dbf_rec_adapter("eraubl1", NULL
, adapter
->dbf
);
456 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
459 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
461 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
462 zfcp_dbf_rec_port("erpubl1", NULL
, port
);
463 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
466 static void zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
468 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
))
469 zfcp_dbf_rec_unit("eruubl1", NULL
, unit
);
470 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
);
473 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
475 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
476 zfcp_dbf_rec_action("erator1", erp_action
);
479 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
481 struct zfcp_adapter
*adapter
= act
->adapter
;
482 struct zfcp_fsf_req
*req
;
484 if (!act
->fsf_req_id
)
487 spin_lock(&adapter
->req_list
->lock
);
488 req
= _zfcp_reqlist_find(adapter
->req_list
, act
->fsf_req_id
);
489 if (req
&& req
->erp_action
== act
) {
490 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
491 ZFCP_STATUS_ERP_TIMEDOUT
)) {
492 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
493 zfcp_dbf_rec_action("erscf_1", act
);
494 req
->erp_action
= NULL
;
496 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
497 zfcp_dbf_rec_action("erscf_2", act
);
498 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
502 spin_unlock(&adapter
->req_list
->lock
);
506 * zfcp_erp_notify - Trigger ERP action.
507 * @erp_action: ERP action to continue.
508 * @set_mask: ERP action status flags to set.
510 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
512 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
515 write_lock_irqsave(&adapter
->erp_lock
, flags
);
516 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
517 erp_action
->status
|= set_mask
;
518 zfcp_erp_action_ready(erp_action
);
520 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
524 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
525 * @data: ERP action (from timer data)
527 void zfcp_erp_timeout_handler(unsigned long data
)
529 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
530 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
533 static void zfcp_erp_memwait_handler(unsigned long data
)
535 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
538 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
540 init_timer(&erp_action
->timer
);
541 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
542 erp_action
->timer
.data
= (unsigned long) erp_action
;
543 erp_action
->timer
.expires
= jiffies
+ HZ
;
544 add_timer(&erp_action
->timer
);
547 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
548 int clear
, char *id
, void *ref
)
550 struct zfcp_port
*port
;
552 read_lock(&adapter
->port_list_lock
);
553 list_for_each_entry(port
, &adapter
->port_list
, list
)
554 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
555 read_unlock(&adapter
->port_list_lock
);
558 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
561 struct zfcp_unit
*unit
;
563 read_lock(&port
->unit_list_lock
);
564 list_for_each_entry(unit
, &port
->unit_list
, list
)
565 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
566 read_unlock(&port
->unit_list_lock
);
569 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
571 switch (act
->action
) {
572 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
573 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
575 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
576 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
578 case ZFCP_ERP_ACTION_REOPEN_PORT
:
579 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
581 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
582 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
587 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
589 switch (act
->action
) {
590 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
591 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
593 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
594 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
596 case ZFCP_ERP_ACTION_REOPEN_PORT
:
597 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
602 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
606 read_lock_irqsave(&adapter
->erp_lock
, flags
);
607 if (list_empty(&adapter
->erp_ready_head
) &&
608 list_empty(&adapter
->erp_running_head
)) {
609 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
611 wake_up(&adapter
->erp_done_wqh
);
613 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
616 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
618 struct zfcp_qdio
*qdio
= act
->adapter
->qdio
;
620 if (zfcp_qdio_open(qdio
))
621 return ZFCP_ERP_FAILED
;
622 init_waitqueue_head(&qdio
->req_q_wq
);
623 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &act
->adapter
->status
);
624 return ZFCP_ERP_SUCCEEDED
;
627 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
629 struct zfcp_port
*port
;
630 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
632 if (IS_ERR(port
)) /* error or port already attached */
634 _zfcp_erp_port_reopen(port
, 0, "ereptp1", NULL
);
637 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
641 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
643 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
645 for (retries
= 7; retries
; retries
--) {
646 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
648 write_lock_irq(&adapter
->erp_lock
);
649 zfcp_erp_action_to_running(erp_action
);
650 write_unlock_irq(&adapter
->erp_lock
);
651 if (zfcp_fsf_exchange_config_data(erp_action
)) {
652 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
654 return ZFCP_ERP_FAILED
;
657 zfcp_dbf_rec_thread_lock("erasfx1", adapter
->dbf
);
658 wait_event(adapter
->erp_ready_wq
,
659 !list_empty(&adapter
->erp_ready_head
));
660 zfcp_dbf_rec_thread_lock("erasfx2", adapter
->dbf
);
661 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
664 if (!(atomic_read(&adapter
->status
) &
665 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
672 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
675 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
676 return ZFCP_ERP_FAILED
;
678 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
679 zfcp_erp_enqueue_ptp_port(adapter
);
681 return ZFCP_ERP_SUCCEEDED
;
684 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
687 struct zfcp_adapter
*adapter
= act
->adapter
;
689 write_lock_irq(&adapter
->erp_lock
);
690 zfcp_erp_action_to_running(act
);
691 write_unlock_irq(&adapter
->erp_lock
);
693 ret
= zfcp_fsf_exchange_port_data(act
);
694 if (ret
== -EOPNOTSUPP
)
695 return ZFCP_ERP_SUCCEEDED
;
697 return ZFCP_ERP_FAILED
;
699 zfcp_dbf_rec_thread_lock("erasox1", adapter
->dbf
);
700 wait_event(adapter
->erp_ready_wq
,
701 !list_empty(&adapter
->erp_ready_head
));
702 zfcp_dbf_rec_thread_lock("erasox2", adapter
->dbf
);
703 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
704 return ZFCP_ERP_FAILED
;
706 return ZFCP_ERP_SUCCEEDED
;
709 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
711 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
712 return ZFCP_ERP_FAILED
;
714 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
715 return ZFCP_ERP_FAILED
;
717 atomic_set(&act
->adapter
->stat_miss
, act
->adapter
->stat_read_buf_num
);
718 if (zfcp_status_read_refill(act
->adapter
))
719 return ZFCP_ERP_FAILED
;
721 return ZFCP_ERP_SUCCEEDED
;
724 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
726 struct zfcp_adapter
*adapter
= act
->adapter
;
728 /* close queues to ensure that buffers are not accessed by adapter */
729 zfcp_qdio_close(adapter
->qdio
);
730 zfcp_fsf_req_dismiss_all(adapter
);
731 adapter
->fsf_req_seq_no
= 0;
732 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
733 /* all ports and units are closed */
734 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
735 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
737 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
738 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
741 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
743 struct zfcp_adapter
*adapter
= act
->adapter
;
745 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
746 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
747 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
749 return ZFCP_ERP_FAILED
;
752 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
753 zfcp_erp_adapter_strategy_close(act
);
754 return ZFCP_ERP_FAILED
;
757 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
759 return ZFCP_ERP_SUCCEEDED
;
762 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
764 struct zfcp_adapter
*adapter
= act
->adapter
;
766 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
767 zfcp_erp_adapter_strategy_close(act
);
768 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
769 return ZFCP_ERP_EXIT
;
772 if (zfcp_erp_adapter_strategy_open(act
)) {
774 return ZFCP_ERP_FAILED
;
777 return ZFCP_ERP_SUCCEEDED
;
780 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
784 retval
= zfcp_fsf_close_physical_port(act
);
785 if (retval
== -ENOMEM
)
786 return ZFCP_ERP_NOMEM
;
787 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
789 return ZFCP_ERP_FAILED
;
791 return ZFCP_ERP_CONTINUES
;
794 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
796 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
799 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
801 struct zfcp_port
*port
= erp_action
->port
;
802 int status
= atomic_read(&port
->status
);
804 switch (erp_action
->step
) {
805 case ZFCP_ERP_STEP_UNINITIALIZED
:
806 zfcp_erp_port_strategy_clearstati(port
);
807 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
808 (status
& ZFCP_STATUS_COMMON_OPEN
))
809 return zfcp_erp_port_forced_strategy_close(erp_action
);
811 return ZFCP_ERP_FAILED
;
813 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
814 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
815 return ZFCP_ERP_SUCCEEDED
;
817 return ZFCP_ERP_FAILED
;
820 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
824 retval
= zfcp_fsf_close_port(erp_action
);
825 if (retval
== -ENOMEM
)
826 return ZFCP_ERP_NOMEM
;
827 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
829 return ZFCP_ERP_FAILED
;
830 return ZFCP_ERP_CONTINUES
;
833 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
837 retval
= zfcp_fsf_open_port(erp_action
);
838 if (retval
== -ENOMEM
)
839 return ZFCP_ERP_NOMEM
;
840 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
842 return ZFCP_ERP_FAILED
;
843 return ZFCP_ERP_CONTINUES
;
846 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
848 struct zfcp_adapter
*adapter
= act
->adapter
;
849 struct zfcp_port
*port
= act
->port
;
851 if (port
->wwpn
!= adapter
->peer_wwpn
) {
852 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
853 return ZFCP_ERP_FAILED
;
855 port
->d_id
= adapter
->peer_d_id
;
856 return zfcp_erp_port_strategy_open_port(act
);
859 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
861 struct zfcp_adapter
*adapter
= act
->adapter
;
862 struct zfcp_port
*port
= act
->port
;
863 int p_status
= atomic_read(&port
->status
);
866 case ZFCP_ERP_STEP_UNINITIALIZED
:
867 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
868 case ZFCP_ERP_STEP_PORT_CLOSING
:
869 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
870 return zfcp_erp_open_ptp_port(act
);
872 zfcp_fc_trigger_did_lookup(port
);
873 return ZFCP_ERP_EXIT
;
875 return zfcp_erp_port_strategy_open_port(act
);
877 case ZFCP_ERP_STEP_PORT_OPENING
:
878 /* D_ID might have changed during open */
879 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
881 zfcp_fc_trigger_did_lookup(port
);
882 return ZFCP_ERP_EXIT
;
884 return ZFCP_ERP_SUCCEEDED
;
886 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
888 _zfcp_erp_port_reopen(port
, 0, "erpsoc1", NULL
);
889 return ZFCP_ERP_EXIT
;
891 /* fall through otherwise */
893 return ZFCP_ERP_FAILED
;
896 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
898 struct zfcp_port
*port
= erp_action
->port
;
899 int p_status
= atomic_read(&port
->status
);
901 if ((p_status
& ZFCP_STATUS_COMMON_NOESC
) &&
902 !(p_status
& ZFCP_STATUS_COMMON_OPEN
))
903 goto close_init_done
;
905 switch (erp_action
->step
) {
906 case ZFCP_ERP_STEP_UNINITIALIZED
:
907 zfcp_erp_port_strategy_clearstati(port
);
908 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
909 return zfcp_erp_port_strategy_close(erp_action
);
912 case ZFCP_ERP_STEP_PORT_CLOSING
:
913 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
914 return ZFCP_ERP_FAILED
;
919 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
920 return ZFCP_ERP_EXIT
;
922 return zfcp_erp_port_strategy_open_common(erp_action
);
925 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
927 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
928 ZFCP_STATUS_UNIT_SHARED
|
929 ZFCP_STATUS_UNIT_READONLY
,
933 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
935 int retval
= zfcp_fsf_close_unit(erp_action
);
936 if (retval
== -ENOMEM
)
937 return ZFCP_ERP_NOMEM
;
938 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
940 return ZFCP_ERP_FAILED
;
941 return ZFCP_ERP_CONTINUES
;
944 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
946 int retval
= zfcp_fsf_open_unit(erp_action
);
947 if (retval
== -ENOMEM
)
948 return ZFCP_ERP_NOMEM
;
949 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
951 return ZFCP_ERP_FAILED
;
952 return ZFCP_ERP_CONTINUES
;
955 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
957 struct zfcp_unit
*unit
= erp_action
->unit
;
959 switch (erp_action
->step
) {
960 case ZFCP_ERP_STEP_UNINITIALIZED
:
961 zfcp_erp_unit_strategy_clearstati(unit
);
962 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
963 return zfcp_erp_unit_strategy_close(erp_action
);
964 /* already closed, fall through */
965 case ZFCP_ERP_STEP_UNIT_CLOSING
:
966 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
967 return ZFCP_ERP_FAILED
;
968 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
969 return ZFCP_ERP_EXIT
;
970 return zfcp_erp_unit_strategy_open(erp_action
);
972 case ZFCP_ERP_STEP_UNIT_OPENING
:
973 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
974 return ZFCP_ERP_SUCCEEDED
;
976 return ZFCP_ERP_FAILED
;
979 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
982 case ZFCP_ERP_SUCCEEDED
:
983 atomic_set(&unit
->erp_counter
, 0);
984 zfcp_erp_unit_unblock(unit
);
986 case ZFCP_ERP_FAILED
:
987 atomic_inc(&unit
->erp_counter
);
988 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
) {
989 dev_err(&unit
->port
->adapter
->ccw_device
->dev
,
990 "ERP failed for unit 0x%016Lx on "
992 (unsigned long long)unit
->fcp_lun
,
993 (unsigned long long)unit
->port
->wwpn
);
994 zfcp_erp_unit_failed(unit
, "erusck1", NULL
);
999 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1000 zfcp_erp_unit_block(unit
, 0);
1001 result
= ZFCP_ERP_EXIT
;
1006 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1009 case ZFCP_ERP_SUCCEEDED
:
1010 atomic_set(&port
->erp_counter
, 0);
1011 zfcp_erp_port_unblock(port
);
1014 case ZFCP_ERP_FAILED
:
1015 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1016 zfcp_erp_port_block(port
, 0);
1017 result
= ZFCP_ERP_EXIT
;
1019 atomic_inc(&port
->erp_counter
);
1020 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1021 dev_err(&port
->adapter
->ccw_device
->dev
,
1022 "ERP failed for remote port 0x%016Lx\n",
1023 (unsigned long long)port
->wwpn
);
1024 zfcp_erp_port_failed(port
, "erpsck1", NULL
);
1029 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1030 zfcp_erp_port_block(port
, 0);
1031 result
= ZFCP_ERP_EXIT
;
1036 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1040 case ZFCP_ERP_SUCCEEDED
:
1041 atomic_set(&adapter
->erp_counter
, 0);
1042 zfcp_erp_adapter_unblock(adapter
);
1045 case ZFCP_ERP_FAILED
:
1046 atomic_inc(&adapter
->erp_counter
);
1047 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1048 dev_err(&adapter
->ccw_device
->dev
,
1049 "ERP cannot recover an error "
1050 "on the FCP device\n");
1051 zfcp_erp_adapter_failed(adapter
, "erasck1", NULL
);
1056 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1057 zfcp_erp_adapter_block(adapter
, 0);
1058 result
= ZFCP_ERP_EXIT
;
1063 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1066 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1067 struct zfcp_port
*port
= erp_action
->port
;
1068 struct zfcp_unit
*unit
= erp_action
->unit
;
1070 switch (erp_action
->action
) {
1072 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1073 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1076 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1077 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1078 result
= zfcp_erp_strategy_check_port(port
, result
);
1081 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1082 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1088 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1090 int status
= atomic_read(target_status
);
1092 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1093 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1094 return 1; /* take it online */
1096 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1097 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1098 return 1; /* take it offline */
1103 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1105 int action
= act
->action
;
1106 struct zfcp_adapter
*adapter
= act
->adapter
;
1107 struct zfcp_port
*port
= act
->port
;
1108 struct zfcp_unit
*unit
= act
->unit
;
1109 u32 erp_status
= act
->status
;
1112 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1113 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1114 _zfcp_erp_adapter_reopen(adapter
,
1115 ZFCP_STATUS_COMMON_ERP_FAILED
,
1117 return ZFCP_ERP_EXIT
;
1121 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1122 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1123 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1124 _zfcp_erp_port_reopen(port
,
1125 ZFCP_STATUS_COMMON_ERP_FAILED
,
1127 return ZFCP_ERP_EXIT
;
1131 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1132 if (zfcp_erp_strat_change_det(&unit
->status
, erp_status
)) {
1133 _zfcp_erp_unit_reopen(unit
,
1134 ZFCP_STATUS_COMMON_ERP_FAILED
,
1136 return ZFCP_ERP_EXIT
;
1143 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1145 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1147 adapter
->erp_total_count
--;
1148 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1149 adapter
->erp_low_mem_count
--;
1150 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1153 list_del(&erp_action
->list
);
1154 zfcp_dbf_rec_action("eractd1", erp_action
);
1156 switch (erp_action
->action
) {
1157 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1158 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1159 &erp_action
->unit
->status
);
1162 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1163 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1164 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1165 &erp_action
->port
->status
);
1168 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1169 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1170 &erp_action
->adapter
->status
);
1175 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1177 struct zfcp_adapter
*adapter
= act
->adapter
;
1178 struct zfcp_port
*port
= act
->port
;
1179 struct zfcp_unit
*unit
= act
->unit
;
1181 switch (act
->action
) {
1182 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1183 if ((result
== ZFCP_ERP_SUCCEEDED
) && !unit
->device
) {
1184 get_device(&unit
->dev
);
1185 if (scsi_queue_work(unit
->port
->adapter
->scsi_host
,
1186 &unit
->scsi_work
) <= 0)
1187 put_device(&unit
->dev
);
1189 put_device(&unit
->dev
);
1192 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1193 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1194 if (result
== ZFCP_ERP_SUCCEEDED
)
1195 zfcp_scsi_schedule_rport_register(port
);
1196 put_device(&port
->dev
);
1199 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1200 if (result
== ZFCP_ERP_SUCCEEDED
) {
1201 register_service_level(&adapter
->service_level
);
1202 queue_work(adapter
->work_queue
, &adapter
->scan_work
);
1204 unregister_service_level(&adapter
->service_level
);
1205 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1210 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1212 switch (erp_action
->action
) {
1213 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1214 return zfcp_erp_adapter_strategy(erp_action
);
1215 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1216 return zfcp_erp_port_forced_strategy(erp_action
);
1217 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1218 return zfcp_erp_port_strategy(erp_action
);
1219 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1220 return zfcp_erp_unit_strategy(erp_action
);
1222 return ZFCP_ERP_FAILED
;
1225 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1228 unsigned long flags
;
1229 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1231 kref_get(&adapter
->ref
);
1233 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1234 zfcp_erp_strategy_check_fsfreq(erp_action
);
1236 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1237 zfcp_erp_action_dequeue(erp_action
);
1238 retval
= ZFCP_ERP_DISMISSED
;
1242 zfcp_erp_action_to_running(erp_action
);
1244 /* no lock to allow for blocking operations */
1245 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1246 retval
= zfcp_erp_strategy_do_action(erp_action
);
1247 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1249 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1250 retval
= ZFCP_ERP_CONTINUES
;
1253 case ZFCP_ERP_NOMEM
:
1254 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1255 ++adapter
->erp_low_mem_count
;
1256 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1258 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1259 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1261 zfcp_erp_strategy_memwait(erp_action
);
1262 retval
= ZFCP_ERP_CONTINUES
;
1266 case ZFCP_ERP_CONTINUES
:
1267 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1268 --adapter
->erp_low_mem_count
;
1269 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1274 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1275 zfcp_erp_action_dequeue(erp_action
);
1276 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1277 if (retval
== ZFCP_ERP_EXIT
)
1279 if (retval
== ZFCP_ERP_SUCCEEDED
)
1280 zfcp_erp_strategy_followup_success(erp_action
);
1281 if (retval
== ZFCP_ERP_FAILED
)
1282 zfcp_erp_strategy_followup_failed(erp_action
);
1285 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1287 if (retval
!= ZFCP_ERP_CONTINUES
)
1288 zfcp_erp_action_cleanup(erp_action
, retval
);
1290 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1294 static int zfcp_erp_thread(void *data
)
1296 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1297 struct list_head
*next
;
1298 struct zfcp_erp_action
*act
;
1299 unsigned long flags
;
1302 zfcp_dbf_rec_thread_lock("erthrd1", adapter
->dbf
);
1303 wait_event_interruptible(adapter
->erp_ready_wq
,
1304 !list_empty(&adapter
->erp_ready_head
) ||
1305 kthread_should_stop());
1306 zfcp_dbf_rec_thread_lock("erthrd2", adapter
->dbf
);
1308 if (kthread_should_stop())
1311 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1312 next
= adapter
->erp_ready_head
.next
;
1313 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1315 if (next
!= &adapter
->erp_ready_head
) {
1316 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1318 /* there is more to come after dismission, no notify */
1319 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1320 zfcp_erp_wakeup(adapter
);
1328 * zfcp_erp_thread_setup - Start ERP thread for adapter
1329 * @adapter: Adapter to start the ERP thread for
1331 * Returns 0 on success or error code from kernel_thread()
1333 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1335 struct task_struct
*thread
;
1337 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1338 dev_name(&adapter
->ccw_device
->dev
));
1339 if (IS_ERR(thread
)) {
1340 dev_err(&adapter
->ccw_device
->dev
,
1341 "Creating an ERP thread for the FCP device failed.\n");
1342 return PTR_ERR(thread
);
1345 adapter
->erp_thread
= thread
;
1350 * zfcp_erp_thread_kill - Stop ERP thread.
1351 * @adapter: Adapter where the ERP thread should be stopped.
1353 * The caller of this routine ensures that the specified adapter has
1354 * been shut down and that this operation has been completed. Thus,
1355 * there are no pending erp_actions which would need to be handled
1358 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1360 kthread_stop(adapter
->erp_thread
);
1361 adapter
->erp_thread
= NULL
;
1362 WARN_ON(!list_empty(&adapter
->erp_ready_head
));
1363 WARN_ON(!list_empty(&adapter
->erp_running_head
));
1367 * zfcp_erp_adapter_failed - Set adapter status to failed.
1368 * @adapter: Failed adapter.
1369 * @id: Event id for debug trace.
1370 * @ref: Reference for debug trace.
1372 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1374 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1375 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1379 * zfcp_erp_port_failed - Set port status to failed.
1380 * @port: Failed port.
1381 * @id: Event id for debug trace.
1382 * @ref: Reference for debug trace.
1384 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1386 zfcp_erp_modify_port_status(port
, id
, ref
,
1387 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1391 * zfcp_erp_unit_failed - Set unit status to failed.
1392 * @unit: Failed unit.
1393 * @id: Event id for debug trace.
1394 * @ref: Reference for debug trace.
1396 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1398 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1399 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1403 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1404 * @adapter: adapter for which to wait for completion of its error recovery
1406 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1408 wait_event(adapter
->erp_done_wqh
,
1409 !(atomic_read(&adapter
->status
) &
1410 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1414 * zfcp_erp_modify_adapter_status - change adapter status bits
1415 * @adapter: adapter to change the status
1416 * @id: id for the debug trace
1417 * @ref: reference for the debug trace
1418 * @mask: status bits to change
1419 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1421 * Changes in common status bits are propagated to attached ports and units.
1423 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1424 void *ref
, u32 mask
, int set_or_clear
)
1426 struct zfcp_port
*port
;
1427 unsigned long flags
;
1428 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1430 if (set_or_clear
== ZFCP_SET
) {
1431 if (status_change_set(mask
, &adapter
->status
))
1432 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1433 atomic_set_mask(mask
, &adapter
->status
);
1435 if (status_change_clear(mask
, &adapter
->status
))
1436 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1437 atomic_clear_mask(mask
, &adapter
->status
);
1438 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1439 atomic_set(&adapter
->erp_counter
, 0);
1443 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1444 list_for_each_entry(port
, &adapter
->port_list
, list
)
1445 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1447 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1452 * zfcp_erp_modify_port_status - change port status bits
1453 * @port: port to change the status bits
1454 * @id: id for the debug trace
1455 * @ref: reference for the debug trace
1456 * @mask: status bits to change
1457 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1459 * Changes in common status bits are propagated to attached units.
1461 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1462 u32 mask
, int set_or_clear
)
1464 struct zfcp_unit
*unit
;
1465 unsigned long flags
;
1466 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1468 if (set_or_clear
== ZFCP_SET
) {
1469 if (status_change_set(mask
, &port
->status
))
1470 zfcp_dbf_rec_port(id
, ref
, port
);
1471 atomic_set_mask(mask
, &port
->status
);
1473 if (status_change_clear(mask
, &port
->status
))
1474 zfcp_dbf_rec_port(id
, ref
, port
);
1475 atomic_clear_mask(mask
, &port
->status
);
1476 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1477 atomic_set(&port
->erp_counter
, 0);
1481 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1482 list_for_each_entry(unit
, &port
->unit_list
, list
)
1483 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1485 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1490 * zfcp_erp_modify_unit_status - change unit status bits
1491 * @unit: unit to change the status bits
1492 * @id: id for the debug trace
1493 * @ref: reference for the debug trace
1494 * @mask: status bits to change
1495 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1497 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1498 u32 mask
, int set_or_clear
)
1500 if (set_or_clear
== ZFCP_SET
) {
1501 if (status_change_set(mask
, &unit
->status
))
1502 zfcp_dbf_rec_unit(id
, ref
, unit
);
1503 atomic_set_mask(mask
, &unit
->status
);
1505 if (status_change_clear(mask
, &unit
->status
))
1506 zfcp_dbf_rec_unit(id
, ref
, unit
);
1507 atomic_clear_mask(mask
, &unit
->status
);
1508 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1509 atomic_set(&unit
->erp_counter
, 0);
1515 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1516 * @port: The "boxed" port.
1517 * @id: The debug trace id.
1518 * @id: Reference for the debug trace.
1520 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1522 zfcp_erp_modify_port_status(port
, id
, ref
,
1523 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1524 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1528 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1529 * @port: The "boxed" unit.
1530 * @id: The debug trace id.
1531 * @id: Reference for the debug trace.
1533 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1535 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1536 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1537 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1541 * zfcp_erp_port_access_denied - Adapter denied access to port.
1542 * @port: port where access has been denied
1543 * @id: id for debug trace
1544 * @ref: reference for debug trace
1546 * Since the adapter has denied access, stop using the port and the
1549 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1551 zfcp_erp_modify_port_status(port
, id
, ref
,
1552 ZFCP_STATUS_COMMON_ERP_FAILED
|
1553 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1557 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1558 * @unit: unit where access has been denied
1559 * @id: id for debug trace
1560 * @ref: reference for debug trace
1562 * Since the adapter has denied access, stop using the unit.
1564 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1566 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1567 ZFCP_STATUS_COMMON_ERP_FAILED
|
1568 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1571 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1574 int status
= atomic_read(&unit
->status
);
1575 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1576 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1579 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1582 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1585 struct zfcp_unit
*unit
;
1586 unsigned long flags
;
1587 int status
= atomic_read(&port
->status
);
1589 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1590 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1591 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1592 list_for_each_entry(unit
, &port
->unit_list
, list
)
1593 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1594 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1598 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1602 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1603 * @adapter: Adapter where the Access Control Table (ACT) changed
1604 * @id: Id for debug trace
1605 * @ref: Reference for debug trace
1607 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1610 unsigned long flags
;
1611 struct zfcp_port
*port
;
1613 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1616 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1617 list_for_each_entry(port
, &adapter
->port_list
, list
)
1618 zfcp_erp_port_access_changed(port
, id
, ref
);
1619 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);