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_FORCED
:
145 p_status
= atomic_read(&port
->status
);
146 if (!(p_status
& ZFCP_STATUS_COMMON_OPEN
))
147 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
149 case ZFCP_ERP_ACTION_REOPEN_PORT
:
150 p_status
= atomic_read(&port
->status
);
151 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
153 a_status
= atomic_read(&adapter
->status
);
154 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
155 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
157 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
158 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
160 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
161 a_status
= atomic_read(&adapter
->status
);
162 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
164 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) &&
165 !(a_status
& ZFCP_STATUS_COMMON_OPEN
))
166 return 0; /* shutdown requested for closed adapter */
172 static struct zfcp_erp_action
*zfcp_erp_setup_act(int need
,
173 struct zfcp_adapter
*adapter
,
174 struct zfcp_port
*port
,
175 struct zfcp_unit
*unit
)
177 struct zfcp_erp_action
*erp_action
;
181 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
182 if (!get_device(&unit
->dev
))
184 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
);
185 erp_action
= &unit
->erp_action
;
186 if (!(atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
187 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
190 case ZFCP_ERP_ACTION_REOPEN_PORT
:
191 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
192 if (!get_device(&port
->dev
))
194 zfcp_erp_action_dismiss_port(port
);
195 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
196 erp_action
= &port
->erp_action
;
197 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
198 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
201 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
202 kref_get(&adapter
->ref
);
203 zfcp_erp_action_dismiss_adapter(adapter
);
204 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
205 erp_action
= &adapter
->erp_action
;
206 if (!(atomic_read(&adapter
->status
) &
207 ZFCP_STATUS_COMMON_RUNNING
))
208 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
215 memset(erp_action
, 0, sizeof(struct zfcp_erp_action
));
216 erp_action
->adapter
= adapter
;
217 erp_action
->port
= port
;
218 erp_action
->unit
= unit
;
219 erp_action
->action
= need
;
220 erp_action
->status
= status
;
225 static int zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
226 struct zfcp_port
*port
,
227 struct zfcp_unit
*unit
, char *id
, void *ref
)
229 int retval
= 1, need
;
230 struct zfcp_erp_action
*act
= NULL
;
232 if (!adapter
->erp_thread
)
235 need
= zfcp_erp_required_act(want
, adapter
, port
, unit
);
239 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
240 act
= zfcp_erp_setup_act(need
, adapter
, port
, unit
);
243 ++adapter
->erp_total_count
;
244 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
245 wake_up(&adapter
->erp_ready_wq
);
246 zfcp_dbf_rec_thread("eracte1", adapter
->dbf
);
249 zfcp_dbf_rec_trigger(id
, ref
, want
, need
, act
, adapter
, port
, unit
);
253 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
254 int clear_mask
, char *id
, void *ref
)
256 zfcp_erp_adapter_block(adapter
, clear_mask
);
257 zfcp_scsi_schedule_rports_block(adapter
);
259 /* ensure propagation of failed status to new devices */
260 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
261 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
264 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
265 adapter
, NULL
, NULL
, id
, ref
);
269 * zfcp_erp_adapter_reopen - Reopen adapter.
270 * @adapter: Adapter to reopen.
271 * @clear: Status flags to clear.
272 * @id: Id for debug trace event.
273 * @ref: Reference for debug trace event.
275 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
280 zfcp_erp_adapter_block(adapter
, clear
);
281 zfcp_scsi_schedule_rports_block(adapter
);
283 write_lock_irqsave(&adapter
->erp_lock
, flags
);
284 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
285 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
287 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
, adapter
,
288 NULL
, NULL
, id
, ref
);
289 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
293 * zfcp_erp_adapter_shutdown - Shutdown adapter.
294 * @adapter: Adapter to shut down.
295 * @clear: Status flags to clear.
296 * @id: Id for debug trace event.
297 * @ref: Reference for debug trace event.
299 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
302 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
303 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
, ref
);
307 * zfcp_erp_port_shutdown - Shutdown port
308 * @port: Port to shut down.
309 * @clear: Status flags to clear.
310 * @id: Id for debug trace event.
311 * @ref: Reference for debug trace event.
313 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
,
316 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
317 zfcp_erp_port_reopen(port
, clear
| flags
, id
, ref
);
321 * zfcp_erp_unit_shutdown - Shutdown unit
322 * @unit: Unit to shut down.
323 * @clear: Status flags to clear.
324 * @id: Id for debug trace event.
325 * @ref: Reference for debug trace event.
327 void zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear
, char *id
,
330 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
331 zfcp_erp_unit_reopen(unit
, clear
| flags
, id
, ref
);
334 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
336 zfcp_erp_modify_port_status(port
, "erpblk1", NULL
,
337 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
,
341 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
,
342 int clear
, char *id
, void *ref
)
344 zfcp_erp_port_block(port
, clear
);
345 zfcp_scsi_schedule_rport_block(port
);
347 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
350 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
351 port
->adapter
, port
, NULL
, id
, ref
);
355 * zfcp_erp_port_forced_reopen - Forced close of port and open again
356 * @port: Port to force close and to reopen.
357 * @id: Id for debug trace event.
358 * @ref: Reference for debug trace event.
360 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
,
364 struct zfcp_adapter
*adapter
= port
->adapter
;
366 write_lock_irqsave(&adapter
->erp_lock
, flags
);
367 _zfcp_erp_port_forced_reopen(port
, clear
, id
, ref
);
368 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
371 static int _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
,
374 zfcp_erp_port_block(port
, clear
);
375 zfcp_scsi_schedule_rport_block(port
);
377 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
378 /* ensure propagation of failed status to new devices */
379 zfcp_erp_port_failed(port
, "erpreo1", NULL
);
383 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
384 port
->adapter
, port
, NULL
, id
, ref
);
388 * zfcp_erp_port_reopen - trigger remote port recovery
389 * @port: port to recover
390 * @clear_mask: flags in port status to be cleared
392 * Returns 0 if recovery has been triggered, < 0 if not.
394 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
, void *ref
)
398 struct zfcp_adapter
*adapter
= port
->adapter
;
400 write_lock_irqsave(&adapter
->erp_lock
, flags
);
401 retval
= _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
402 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
407 static void zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
409 zfcp_erp_modify_unit_status(unit
, "erublk1", NULL
,
410 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
414 static void _zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
417 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
419 zfcp_erp_unit_block(unit
, clear
);
421 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
424 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
425 adapter
, unit
->port
, unit
, id
, ref
);
429 * zfcp_erp_unit_reopen - initiate reopen of a unit
430 * @unit: unit to be reopened
431 * @clear_mask: specifies flags in unit status to be cleared
432 * Return: 0 on success, < 0 on error
434 void zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
438 struct zfcp_port
*port
= unit
->port
;
439 struct zfcp_adapter
*adapter
= port
->adapter
;
441 write_lock_irqsave(&adapter
->erp_lock
, flags
);
442 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
443 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
446 static int status_change_set(unsigned long mask
, atomic_t
*status
)
448 return (atomic_read(status
) ^ mask
) & mask
;
451 static int status_change_clear(unsigned long mask
, atomic_t
*status
)
453 return atomic_read(status
) & mask
;
456 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
458 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
459 zfcp_dbf_rec_adapter("eraubl1", NULL
, adapter
->dbf
);
460 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
463 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
465 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
466 zfcp_dbf_rec_port("erpubl1", NULL
, port
);
467 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
470 static void zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
472 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
))
473 zfcp_dbf_rec_unit("eruubl1", NULL
, unit
);
474 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
);
477 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
479 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
480 zfcp_dbf_rec_action("erator1", erp_action
);
483 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
485 struct zfcp_adapter
*adapter
= act
->adapter
;
486 struct zfcp_fsf_req
*req
;
488 if (!act
->fsf_req_id
)
491 spin_lock(&adapter
->req_list
->lock
);
492 req
= _zfcp_reqlist_find(adapter
->req_list
, act
->fsf_req_id
);
493 if (req
&& req
->erp_action
== act
) {
494 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
495 ZFCP_STATUS_ERP_TIMEDOUT
)) {
496 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
497 zfcp_dbf_rec_action("erscf_1", act
);
498 req
->erp_action
= NULL
;
500 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
501 zfcp_dbf_rec_action("erscf_2", act
);
502 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
506 spin_unlock(&adapter
->req_list
->lock
);
510 * zfcp_erp_notify - Trigger ERP action.
511 * @erp_action: ERP action to continue.
512 * @set_mask: ERP action status flags to set.
514 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
516 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
519 write_lock_irqsave(&adapter
->erp_lock
, flags
);
520 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
521 erp_action
->status
|= set_mask
;
522 zfcp_erp_action_ready(erp_action
);
524 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
528 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
529 * @data: ERP action (from timer data)
531 void zfcp_erp_timeout_handler(unsigned long data
)
533 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
534 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
537 static void zfcp_erp_memwait_handler(unsigned long data
)
539 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
542 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
544 init_timer(&erp_action
->timer
);
545 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
546 erp_action
->timer
.data
= (unsigned long) erp_action
;
547 erp_action
->timer
.expires
= jiffies
+ HZ
;
548 add_timer(&erp_action
->timer
);
551 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
552 int clear
, char *id
, void *ref
)
554 struct zfcp_port
*port
;
556 read_lock(&adapter
->port_list_lock
);
557 list_for_each_entry(port
, &adapter
->port_list
, list
)
558 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
559 read_unlock(&adapter
->port_list_lock
);
562 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
565 struct zfcp_unit
*unit
;
567 read_lock(&port
->unit_list_lock
);
568 list_for_each_entry(unit
, &port
->unit_list
, list
)
569 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
570 read_unlock(&port
->unit_list_lock
);
573 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
575 switch (act
->action
) {
576 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
577 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
579 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
580 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
582 case ZFCP_ERP_ACTION_REOPEN_PORT
:
583 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
585 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
586 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
591 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
593 switch (act
->action
) {
594 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
595 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
597 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
598 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
600 case ZFCP_ERP_ACTION_REOPEN_PORT
:
601 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
606 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
610 read_lock_irqsave(&adapter
->erp_lock
, flags
);
611 if (list_empty(&adapter
->erp_ready_head
) &&
612 list_empty(&adapter
->erp_running_head
)) {
613 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
615 wake_up(&adapter
->erp_done_wqh
);
617 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
620 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
622 struct zfcp_qdio
*qdio
= act
->adapter
->qdio
;
624 if (zfcp_qdio_open(qdio
))
625 return ZFCP_ERP_FAILED
;
626 init_waitqueue_head(&qdio
->req_q_wq
);
627 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &act
->adapter
->status
);
628 return ZFCP_ERP_SUCCEEDED
;
631 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
633 struct zfcp_port
*port
;
634 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
636 if (IS_ERR(port
)) /* error or port already attached */
638 _zfcp_erp_port_reopen(port
, 0, "ereptp1", NULL
);
641 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
645 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
647 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
649 for (retries
= 7; retries
; retries
--) {
650 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
652 write_lock_irq(&adapter
->erp_lock
);
653 zfcp_erp_action_to_running(erp_action
);
654 write_unlock_irq(&adapter
->erp_lock
);
655 if (zfcp_fsf_exchange_config_data(erp_action
)) {
656 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
658 return ZFCP_ERP_FAILED
;
661 zfcp_dbf_rec_thread_lock("erasfx1", adapter
->dbf
);
662 wait_event(adapter
->erp_ready_wq
,
663 !list_empty(&adapter
->erp_ready_head
));
664 zfcp_dbf_rec_thread_lock("erasfx2", adapter
->dbf
);
665 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
668 if (!(atomic_read(&adapter
->status
) &
669 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
676 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
679 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
680 return ZFCP_ERP_FAILED
;
682 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
683 zfcp_erp_enqueue_ptp_port(adapter
);
685 return ZFCP_ERP_SUCCEEDED
;
688 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
691 struct zfcp_adapter
*adapter
= act
->adapter
;
693 write_lock_irq(&adapter
->erp_lock
);
694 zfcp_erp_action_to_running(act
);
695 write_unlock_irq(&adapter
->erp_lock
);
697 ret
= zfcp_fsf_exchange_port_data(act
);
698 if (ret
== -EOPNOTSUPP
)
699 return ZFCP_ERP_SUCCEEDED
;
701 return ZFCP_ERP_FAILED
;
703 zfcp_dbf_rec_thread_lock("erasox1", adapter
->dbf
);
704 wait_event(adapter
->erp_ready_wq
,
705 !list_empty(&adapter
->erp_ready_head
));
706 zfcp_dbf_rec_thread_lock("erasox2", adapter
->dbf
);
707 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
708 return ZFCP_ERP_FAILED
;
710 return ZFCP_ERP_SUCCEEDED
;
713 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
715 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
716 return ZFCP_ERP_FAILED
;
718 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
719 return ZFCP_ERP_FAILED
;
721 if (mempool_resize(act
->adapter
->pool
.status_read_data
,
722 act
->adapter
->stat_read_buf_num
, GFP_KERNEL
))
723 return ZFCP_ERP_FAILED
;
725 if (mempool_resize(act
->adapter
->pool
.status_read_req
,
726 act
->adapter
->stat_read_buf_num
, GFP_KERNEL
))
727 return ZFCP_ERP_FAILED
;
729 atomic_set(&act
->adapter
->stat_miss
, act
->adapter
->stat_read_buf_num
);
730 if (zfcp_status_read_refill(act
->adapter
))
731 return ZFCP_ERP_FAILED
;
733 return ZFCP_ERP_SUCCEEDED
;
736 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
738 struct zfcp_adapter
*adapter
= act
->adapter
;
740 /* close queues to ensure that buffers are not accessed by adapter */
741 zfcp_qdio_close(adapter
->qdio
);
742 zfcp_fsf_req_dismiss_all(adapter
);
743 adapter
->fsf_req_seq_no
= 0;
744 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
745 /* all ports and units are closed */
746 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
747 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
749 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
750 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
753 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
755 struct zfcp_adapter
*adapter
= act
->adapter
;
757 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
758 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
759 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
761 return ZFCP_ERP_FAILED
;
764 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
765 zfcp_erp_adapter_strategy_close(act
);
766 return ZFCP_ERP_FAILED
;
769 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
771 return ZFCP_ERP_SUCCEEDED
;
774 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
776 struct zfcp_adapter
*adapter
= act
->adapter
;
778 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
779 zfcp_erp_adapter_strategy_close(act
);
780 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
781 return ZFCP_ERP_EXIT
;
784 if (zfcp_erp_adapter_strategy_open(act
)) {
786 return ZFCP_ERP_FAILED
;
789 return ZFCP_ERP_SUCCEEDED
;
792 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
796 retval
= zfcp_fsf_close_physical_port(act
);
797 if (retval
== -ENOMEM
)
798 return ZFCP_ERP_NOMEM
;
799 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
801 return ZFCP_ERP_FAILED
;
803 return ZFCP_ERP_CONTINUES
;
806 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
808 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
811 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
813 struct zfcp_port
*port
= erp_action
->port
;
814 int status
= atomic_read(&port
->status
);
816 switch (erp_action
->step
) {
817 case ZFCP_ERP_STEP_UNINITIALIZED
:
818 zfcp_erp_port_strategy_clearstati(port
);
819 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
820 (status
& ZFCP_STATUS_COMMON_OPEN
))
821 return zfcp_erp_port_forced_strategy_close(erp_action
);
823 return ZFCP_ERP_FAILED
;
825 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
826 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
827 return ZFCP_ERP_SUCCEEDED
;
829 return ZFCP_ERP_FAILED
;
832 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
836 retval
= zfcp_fsf_close_port(erp_action
);
837 if (retval
== -ENOMEM
)
838 return ZFCP_ERP_NOMEM
;
839 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
841 return ZFCP_ERP_FAILED
;
842 return ZFCP_ERP_CONTINUES
;
845 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
849 retval
= zfcp_fsf_open_port(erp_action
);
850 if (retval
== -ENOMEM
)
851 return ZFCP_ERP_NOMEM
;
852 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
854 return ZFCP_ERP_FAILED
;
855 return ZFCP_ERP_CONTINUES
;
858 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
860 struct zfcp_adapter
*adapter
= act
->adapter
;
861 struct zfcp_port
*port
= act
->port
;
863 if (port
->wwpn
!= adapter
->peer_wwpn
) {
864 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
865 return ZFCP_ERP_FAILED
;
867 port
->d_id
= adapter
->peer_d_id
;
868 return zfcp_erp_port_strategy_open_port(act
);
871 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
873 struct zfcp_adapter
*adapter
= act
->adapter
;
874 struct zfcp_port
*port
= act
->port
;
875 int p_status
= atomic_read(&port
->status
);
878 case ZFCP_ERP_STEP_UNINITIALIZED
:
879 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
880 case ZFCP_ERP_STEP_PORT_CLOSING
:
881 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
882 return zfcp_erp_open_ptp_port(act
);
884 zfcp_fc_trigger_did_lookup(port
);
885 return ZFCP_ERP_EXIT
;
887 return zfcp_erp_port_strategy_open_port(act
);
889 case ZFCP_ERP_STEP_PORT_OPENING
:
890 /* D_ID might have changed during open */
891 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
893 zfcp_fc_trigger_did_lookup(port
);
894 return ZFCP_ERP_EXIT
;
896 return ZFCP_ERP_SUCCEEDED
;
898 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
900 return ZFCP_ERP_FAILED
;
902 /* fall through otherwise */
904 return ZFCP_ERP_FAILED
;
907 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
909 struct zfcp_port
*port
= erp_action
->port
;
910 int p_status
= atomic_read(&port
->status
);
912 if ((p_status
& ZFCP_STATUS_COMMON_NOESC
) &&
913 !(p_status
& ZFCP_STATUS_COMMON_OPEN
))
914 goto close_init_done
;
916 switch (erp_action
->step
) {
917 case ZFCP_ERP_STEP_UNINITIALIZED
:
918 zfcp_erp_port_strategy_clearstati(port
);
919 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
920 return zfcp_erp_port_strategy_close(erp_action
);
923 case ZFCP_ERP_STEP_PORT_CLOSING
:
924 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
925 return ZFCP_ERP_FAILED
;
930 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
931 return ZFCP_ERP_EXIT
;
933 return zfcp_erp_port_strategy_open_common(erp_action
);
936 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
938 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
939 ZFCP_STATUS_UNIT_SHARED
|
940 ZFCP_STATUS_UNIT_READONLY
,
944 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
946 int retval
= zfcp_fsf_close_unit(erp_action
);
947 if (retval
== -ENOMEM
)
948 return ZFCP_ERP_NOMEM
;
949 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
951 return ZFCP_ERP_FAILED
;
952 return ZFCP_ERP_CONTINUES
;
955 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
957 int retval
= zfcp_fsf_open_unit(erp_action
);
958 if (retval
== -ENOMEM
)
959 return ZFCP_ERP_NOMEM
;
960 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
962 return ZFCP_ERP_FAILED
;
963 return ZFCP_ERP_CONTINUES
;
966 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
968 struct zfcp_unit
*unit
= erp_action
->unit
;
970 switch (erp_action
->step
) {
971 case ZFCP_ERP_STEP_UNINITIALIZED
:
972 zfcp_erp_unit_strategy_clearstati(unit
);
973 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
974 return zfcp_erp_unit_strategy_close(erp_action
);
975 /* already closed, fall through */
976 case ZFCP_ERP_STEP_UNIT_CLOSING
:
977 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
978 return ZFCP_ERP_FAILED
;
979 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
980 return ZFCP_ERP_EXIT
;
981 return zfcp_erp_unit_strategy_open(erp_action
);
983 case ZFCP_ERP_STEP_UNIT_OPENING
:
984 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
985 return ZFCP_ERP_SUCCEEDED
;
987 return ZFCP_ERP_FAILED
;
990 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
993 case ZFCP_ERP_SUCCEEDED
:
994 atomic_set(&unit
->erp_counter
, 0);
995 zfcp_erp_unit_unblock(unit
);
997 case ZFCP_ERP_FAILED
:
998 atomic_inc(&unit
->erp_counter
);
999 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
) {
1000 dev_err(&unit
->port
->adapter
->ccw_device
->dev
,
1001 "ERP failed for unit 0x%016Lx on "
1003 (unsigned long long)unit
->fcp_lun
,
1004 (unsigned long long)unit
->port
->wwpn
);
1005 zfcp_erp_unit_failed(unit
, "erusck1", NULL
);
1010 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1011 zfcp_erp_unit_block(unit
, 0);
1012 result
= ZFCP_ERP_EXIT
;
1017 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1020 case ZFCP_ERP_SUCCEEDED
:
1021 atomic_set(&port
->erp_counter
, 0);
1022 zfcp_erp_port_unblock(port
);
1025 case ZFCP_ERP_FAILED
:
1026 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1027 zfcp_erp_port_block(port
, 0);
1028 result
= ZFCP_ERP_EXIT
;
1030 atomic_inc(&port
->erp_counter
);
1031 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1032 dev_err(&port
->adapter
->ccw_device
->dev
,
1033 "ERP failed for remote port 0x%016Lx\n",
1034 (unsigned long long)port
->wwpn
);
1035 zfcp_erp_port_failed(port
, "erpsck1", NULL
);
1040 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1041 zfcp_erp_port_block(port
, 0);
1042 result
= ZFCP_ERP_EXIT
;
1047 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1051 case ZFCP_ERP_SUCCEEDED
:
1052 atomic_set(&adapter
->erp_counter
, 0);
1053 zfcp_erp_adapter_unblock(adapter
);
1056 case ZFCP_ERP_FAILED
:
1057 atomic_inc(&adapter
->erp_counter
);
1058 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1059 dev_err(&adapter
->ccw_device
->dev
,
1060 "ERP cannot recover an error "
1061 "on the FCP device\n");
1062 zfcp_erp_adapter_failed(adapter
, "erasck1", NULL
);
1067 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1068 zfcp_erp_adapter_block(adapter
, 0);
1069 result
= ZFCP_ERP_EXIT
;
1074 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1077 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1078 struct zfcp_port
*port
= erp_action
->port
;
1079 struct zfcp_unit
*unit
= erp_action
->unit
;
1081 switch (erp_action
->action
) {
1083 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1084 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1087 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1088 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1089 result
= zfcp_erp_strategy_check_port(port
, result
);
1092 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1093 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1099 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1101 int status
= atomic_read(target_status
);
1103 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1104 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1105 return 1; /* take it online */
1107 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1108 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1109 return 1; /* take it offline */
1114 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1116 int action
= act
->action
;
1117 struct zfcp_adapter
*adapter
= act
->adapter
;
1118 struct zfcp_port
*port
= act
->port
;
1119 struct zfcp_unit
*unit
= act
->unit
;
1120 u32 erp_status
= act
->status
;
1123 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1124 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1125 _zfcp_erp_adapter_reopen(adapter
,
1126 ZFCP_STATUS_COMMON_ERP_FAILED
,
1128 return ZFCP_ERP_EXIT
;
1132 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1133 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1134 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1135 _zfcp_erp_port_reopen(port
,
1136 ZFCP_STATUS_COMMON_ERP_FAILED
,
1138 return ZFCP_ERP_EXIT
;
1142 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1143 if (zfcp_erp_strat_change_det(&unit
->status
, erp_status
)) {
1144 _zfcp_erp_unit_reopen(unit
,
1145 ZFCP_STATUS_COMMON_ERP_FAILED
,
1147 return ZFCP_ERP_EXIT
;
1154 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1156 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1158 adapter
->erp_total_count
--;
1159 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1160 adapter
->erp_low_mem_count
--;
1161 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1164 list_del(&erp_action
->list
);
1165 zfcp_dbf_rec_action("eractd1", erp_action
);
1167 switch (erp_action
->action
) {
1168 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1169 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1170 &erp_action
->unit
->status
);
1173 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1174 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1175 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1176 &erp_action
->port
->status
);
1179 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1180 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1181 &erp_action
->adapter
->status
);
1186 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1188 struct zfcp_adapter
*adapter
= act
->adapter
;
1189 struct zfcp_port
*port
= act
->port
;
1190 struct zfcp_unit
*unit
= act
->unit
;
1192 switch (act
->action
) {
1193 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1194 put_device(&unit
->dev
);
1197 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1198 if (result
== ZFCP_ERP_SUCCEEDED
)
1199 zfcp_scsi_schedule_rport_register(port
);
1201 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1202 put_device(&port
->dev
);
1205 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1206 if (result
== ZFCP_ERP_SUCCEEDED
) {
1207 register_service_level(&adapter
->service_level
);
1208 queue_work(adapter
->work_queue
, &adapter
->scan_work
);
1210 unregister_service_level(&adapter
->service_level
);
1211 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1216 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1218 switch (erp_action
->action
) {
1219 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1220 return zfcp_erp_adapter_strategy(erp_action
);
1221 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1222 return zfcp_erp_port_forced_strategy(erp_action
);
1223 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1224 return zfcp_erp_port_strategy(erp_action
);
1225 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1226 return zfcp_erp_unit_strategy(erp_action
);
1228 return ZFCP_ERP_FAILED
;
1231 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1234 unsigned long flags
;
1235 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1237 kref_get(&adapter
->ref
);
1239 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1240 zfcp_erp_strategy_check_fsfreq(erp_action
);
1242 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1243 zfcp_erp_action_dequeue(erp_action
);
1244 retval
= ZFCP_ERP_DISMISSED
;
1248 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
1249 retval
= ZFCP_ERP_FAILED
;
1253 zfcp_erp_action_to_running(erp_action
);
1255 /* no lock to allow for blocking operations */
1256 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1257 retval
= zfcp_erp_strategy_do_action(erp_action
);
1258 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1260 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1261 retval
= ZFCP_ERP_CONTINUES
;
1264 case ZFCP_ERP_NOMEM
:
1265 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1266 ++adapter
->erp_low_mem_count
;
1267 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1269 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1270 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1272 zfcp_erp_strategy_memwait(erp_action
);
1273 retval
= ZFCP_ERP_CONTINUES
;
1277 case ZFCP_ERP_CONTINUES
:
1278 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1279 --adapter
->erp_low_mem_count
;
1280 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1286 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1287 zfcp_erp_action_dequeue(erp_action
);
1288 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1289 if (retval
== ZFCP_ERP_EXIT
)
1291 if (retval
== ZFCP_ERP_SUCCEEDED
)
1292 zfcp_erp_strategy_followup_success(erp_action
);
1293 if (retval
== ZFCP_ERP_FAILED
)
1294 zfcp_erp_strategy_followup_failed(erp_action
);
1297 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1299 if (retval
!= ZFCP_ERP_CONTINUES
)
1300 zfcp_erp_action_cleanup(erp_action
, retval
);
1302 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1306 static int zfcp_erp_thread(void *data
)
1308 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1309 struct list_head
*next
;
1310 struct zfcp_erp_action
*act
;
1311 unsigned long flags
;
1314 zfcp_dbf_rec_thread_lock("erthrd1", adapter
->dbf
);
1315 wait_event_interruptible(adapter
->erp_ready_wq
,
1316 !list_empty(&adapter
->erp_ready_head
) ||
1317 kthread_should_stop());
1318 zfcp_dbf_rec_thread_lock("erthrd2", adapter
->dbf
);
1320 if (kthread_should_stop())
1323 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1324 next
= adapter
->erp_ready_head
.next
;
1325 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1327 if (next
!= &adapter
->erp_ready_head
) {
1328 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1330 /* there is more to come after dismission, no notify */
1331 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1332 zfcp_erp_wakeup(adapter
);
1340 * zfcp_erp_thread_setup - Start ERP thread for adapter
1341 * @adapter: Adapter to start the ERP thread for
1343 * Returns 0 on success or error code from kernel_thread()
1345 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1347 struct task_struct
*thread
;
1349 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1350 dev_name(&adapter
->ccw_device
->dev
));
1351 if (IS_ERR(thread
)) {
1352 dev_err(&adapter
->ccw_device
->dev
,
1353 "Creating an ERP thread for the FCP device failed.\n");
1354 return PTR_ERR(thread
);
1357 adapter
->erp_thread
= thread
;
1362 * zfcp_erp_thread_kill - Stop ERP thread.
1363 * @adapter: Adapter where the ERP thread should be stopped.
1365 * The caller of this routine ensures that the specified adapter has
1366 * been shut down and that this operation has been completed. Thus,
1367 * there are no pending erp_actions which would need to be handled
1370 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1372 kthread_stop(adapter
->erp_thread
);
1373 adapter
->erp_thread
= NULL
;
1374 WARN_ON(!list_empty(&adapter
->erp_ready_head
));
1375 WARN_ON(!list_empty(&adapter
->erp_running_head
));
1379 * zfcp_erp_adapter_failed - Set adapter status to failed.
1380 * @adapter: Failed adapter.
1381 * @id: Event id for debug trace.
1382 * @ref: Reference for debug trace.
1384 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1386 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1387 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1391 * zfcp_erp_port_failed - Set port status to failed.
1392 * @port: Failed port.
1393 * @id: Event id for debug trace.
1394 * @ref: Reference for debug trace.
1396 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1398 zfcp_erp_modify_port_status(port
, id
, ref
,
1399 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1403 * zfcp_erp_unit_failed - Set unit status to failed.
1404 * @unit: Failed unit.
1405 * @id: Event id for debug trace.
1406 * @ref: Reference for debug trace.
1408 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1410 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1411 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1415 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1416 * @adapter: adapter for which to wait for completion of its error recovery
1418 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1420 wait_event(adapter
->erp_done_wqh
,
1421 !(atomic_read(&adapter
->status
) &
1422 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1426 * zfcp_erp_modify_adapter_status - change adapter status bits
1427 * @adapter: adapter to change the status
1428 * @id: id for the debug trace
1429 * @ref: reference for the debug trace
1430 * @mask: status bits to change
1431 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1433 * Changes in common status bits are propagated to attached ports and units.
1435 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1436 void *ref
, u32 mask
, int set_or_clear
)
1438 struct zfcp_port
*port
;
1439 unsigned long flags
;
1440 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1442 if (set_or_clear
== ZFCP_SET
) {
1443 if (status_change_set(mask
, &adapter
->status
))
1444 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1445 atomic_set_mask(mask
, &adapter
->status
);
1447 if (status_change_clear(mask
, &adapter
->status
))
1448 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1449 atomic_clear_mask(mask
, &adapter
->status
);
1450 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1451 atomic_set(&adapter
->erp_counter
, 0);
1455 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1456 list_for_each_entry(port
, &adapter
->port_list
, list
)
1457 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1459 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1464 * zfcp_erp_modify_port_status - change port status bits
1465 * @port: port to change the status bits
1466 * @id: id for the debug trace
1467 * @ref: reference for the debug trace
1468 * @mask: status bits to change
1469 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1471 * Changes in common status bits are propagated to attached units.
1473 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1474 u32 mask
, int set_or_clear
)
1476 struct zfcp_unit
*unit
;
1477 unsigned long flags
;
1478 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1480 if (set_or_clear
== ZFCP_SET
) {
1481 if (status_change_set(mask
, &port
->status
))
1482 zfcp_dbf_rec_port(id
, ref
, port
);
1483 atomic_set_mask(mask
, &port
->status
);
1485 if (status_change_clear(mask
, &port
->status
))
1486 zfcp_dbf_rec_port(id
, ref
, port
);
1487 atomic_clear_mask(mask
, &port
->status
);
1488 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1489 atomic_set(&port
->erp_counter
, 0);
1493 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1494 list_for_each_entry(unit
, &port
->unit_list
, list
)
1495 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1497 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1502 * zfcp_erp_modify_unit_status - change unit status bits
1503 * @unit: unit to change the status bits
1504 * @id: id for the debug trace
1505 * @ref: reference for the debug trace
1506 * @mask: status bits to change
1507 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1509 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1510 u32 mask
, int set_or_clear
)
1512 if (set_or_clear
== ZFCP_SET
) {
1513 if (status_change_set(mask
, &unit
->status
))
1514 zfcp_dbf_rec_unit(id
, ref
, unit
);
1515 atomic_set_mask(mask
, &unit
->status
);
1517 if (status_change_clear(mask
, &unit
->status
))
1518 zfcp_dbf_rec_unit(id
, ref
, unit
);
1519 atomic_clear_mask(mask
, &unit
->status
);
1520 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1521 atomic_set(&unit
->erp_counter
, 0);
1527 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1528 * @port: The "boxed" port.
1529 * @id: The debug trace id.
1530 * @id: Reference for the debug trace.
1532 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1534 zfcp_erp_modify_port_status(port
, id
, ref
,
1535 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1536 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1540 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1541 * @port: The "boxed" unit.
1542 * @id: The debug trace id.
1543 * @id: Reference for the debug trace.
1545 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1547 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1548 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1549 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1553 * zfcp_erp_port_access_denied - Adapter denied access to port.
1554 * @port: port where access has been denied
1555 * @id: id for debug trace
1556 * @ref: reference for debug trace
1558 * Since the adapter has denied access, stop using the port and the
1561 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1563 zfcp_erp_modify_port_status(port
, id
, ref
,
1564 ZFCP_STATUS_COMMON_ERP_FAILED
|
1565 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1569 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1570 * @unit: unit where access has been denied
1571 * @id: id for debug trace
1572 * @ref: reference for debug trace
1574 * Since the adapter has denied access, stop using the unit.
1576 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1578 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1579 ZFCP_STATUS_COMMON_ERP_FAILED
|
1580 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1583 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1586 int status
= atomic_read(&unit
->status
);
1587 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1588 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1591 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1594 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1597 struct zfcp_unit
*unit
;
1598 unsigned long flags
;
1599 int status
= atomic_read(&port
->status
);
1601 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1602 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1603 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1604 list_for_each_entry(unit
, &port
->unit_list
, list
)
1605 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1606 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1610 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1614 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1615 * @adapter: Adapter where the Access Control Table (ACT) changed
1616 * @id: Id for debug trace
1617 * @ref: Reference for debug trace
1619 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1622 unsigned long flags
;
1623 struct zfcp_port
*port
;
1625 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1628 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1629 list_for_each_entry(port
, &adapter
->port_list
, list
)
1630 zfcp_erp_port_access_changed(port
, id
, ref
);
1631 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);