4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #define ZFCP_MAX_ERPS 3
16 enum zfcp_erp_act_flags
{
17 ZFCP_STATUS_ERP_TIMEDOUT
= 0x10000000,
18 ZFCP_STATUS_ERP_CLOSE_ONLY
= 0x01000000,
19 ZFCP_STATUS_ERP_DISMISSING
= 0x00100000,
20 ZFCP_STATUS_ERP_DISMISSED
= 0x00200000,
21 ZFCP_STATUS_ERP_LOWMEM
= 0x00400000,
25 ZFCP_ERP_STEP_UNINITIALIZED
= 0x0000,
26 ZFCP_ERP_STEP_FSF_XCONFIG
= 0x0001,
27 ZFCP_ERP_STEP_PHYS_PORT_CLOSING
= 0x0010,
28 ZFCP_ERP_STEP_PORT_CLOSING
= 0x0100,
29 ZFCP_ERP_STEP_NAMESERVER_LOOKUP
= 0x0400,
30 ZFCP_ERP_STEP_PORT_OPENING
= 0x0800,
31 ZFCP_ERP_STEP_UNIT_CLOSING
= 0x1000,
32 ZFCP_ERP_STEP_UNIT_OPENING
= 0x2000,
35 enum zfcp_erp_act_type
{
36 ZFCP_ERP_ACTION_REOPEN_UNIT
= 1,
37 ZFCP_ERP_ACTION_REOPEN_PORT
= 2,
38 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
= 3,
39 ZFCP_ERP_ACTION_REOPEN_ADAPTER
= 4,
42 enum zfcp_erp_act_state
{
43 ZFCP_ERP_ACTION_RUNNING
= 1,
44 ZFCP_ERP_ACTION_READY
= 2,
47 enum zfcp_erp_act_result
{
48 ZFCP_ERP_SUCCEEDED
= 0,
50 ZFCP_ERP_CONTINUES
= 2,
52 ZFCP_ERP_DISMISSED
= 4,
56 static void zfcp_erp_adapter_block(struct zfcp_adapter
*adapter
, int mask
)
58 zfcp_erp_modify_adapter_status(adapter
, "erablk1", NULL
,
59 ZFCP_STATUS_COMMON_UNBLOCKED
| mask
,
63 static int zfcp_erp_action_exists(struct zfcp_erp_action
*act
)
65 struct zfcp_erp_action
*curr_act
;
67 list_for_each_entry(curr_act
, &act
->adapter
->erp_running_head
, list
)
69 return ZFCP_ERP_ACTION_RUNNING
;
73 static void zfcp_erp_action_ready(struct zfcp_erp_action
*act
)
75 struct zfcp_adapter
*adapter
= act
->adapter
;
77 list_move(&act
->list
, &act
->adapter
->erp_ready_head
);
78 zfcp_rec_dbf_event_action("erardy1", act
);
79 up(&adapter
->erp_ready_sem
);
80 zfcp_rec_dbf_event_thread("erardy2", adapter
);
83 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*act
)
85 act
->status
|= ZFCP_STATUS_ERP_DISMISSED
;
86 if (zfcp_erp_action_exists(act
) == ZFCP_ERP_ACTION_RUNNING
)
87 zfcp_erp_action_ready(act
);
90 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit
*unit
)
92 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
93 zfcp_erp_action_dismiss(&unit
->erp_action
);
96 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*port
)
98 struct zfcp_unit
*unit
;
100 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
101 zfcp_erp_action_dismiss(&port
->erp_action
);
103 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
104 zfcp_erp_action_dismiss_unit(unit
);
107 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
109 struct zfcp_port
*port
;
111 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
112 zfcp_erp_action_dismiss(&adapter
->erp_action
);
114 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
115 zfcp_erp_action_dismiss_port(port
);
118 static int zfcp_erp_required_act(int want
, struct zfcp_adapter
*adapter
,
119 struct zfcp_port
*port
,
120 struct zfcp_unit
*unit
)
123 int u_status
, p_status
, a_status
;
126 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
127 u_status
= atomic_read(&unit
->status
);
128 if (u_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
130 p_status
= atomic_read(&port
->status
);
131 if (!(p_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
132 p_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
134 if (!(p_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
135 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
137 case ZFCP_ERP_ACTION_REOPEN_PORT
:
138 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
139 p_status
= atomic_read(&port
->status
);
140 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
142 a_status
= atomic_read(&adapter
->status
);
143 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
144 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
146 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
147 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
149 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
150 a_status
= atomic_read(&adapter
->status
);
151 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
158 static struct zfcp_erp_action
*zfcp_erp_setup_act(int need
,
159 struct zfcp_adapter
*adapter
,
160 struct zfcp_port
*port
,
161 struct zfcp_unit
*unit
)
163 struct zfcp_erp_action
*erp_action
;
167 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
169 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
);
170 erp_action
= &unit
->erp_action
;
171 if (!(atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
172 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
175 case ZFCP_ERP_ACTION_REOPEN_PORT
:
176 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
178 zfcp_erp_action_dismiss_port(port
);
179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
180 erp_action
= &port
->erp_action
;
181 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
182 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
185 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
186 zfcp_adapter_get(adapter
);
187 zfcp_erp_action_dismiss_adapter(adapter
);
188 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
189 erp_action
= &adapter
->erp_action
;
190 if (!(atomic_read(&adapter
->status
) &
191 ZFCP_STATUS_COMMON_RUNNING
))
192 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
199 memset(erp_action
, 0, sizeof(struct zfcp_erp_action
));
200 erp_action
->adapter
= adapter
;
201 erp_action
->port
= port
;
202 erp_action
->unit
= unit
;
203 erp_action
->action
= need
;
204 erp_action
->status
= status
;
209 static int zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
210 struct zfcp_port
*port
,
211 struct zfcp_unit
*unit
, char *id
, void *ref
)
213 int retval
= 1, need
;
214 struct zfcp_erp_action
*act
= NULL
;
216 if (!(atomic_read(&adapter
->status
) &
217 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
))
220 need
= zfcp_erp_required_act(want
, adapter
, port
, unit
);
224 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
225 act
= zfcp_erp_setup_act(need
, adapter
, port
, unit
);
228 ++adapter
->erp_total_count
;
229 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
230 up(&adapter
->erp_ready_sem
);
231 zfcp_rec_dbf_event_thread("eracte1", adapter
);
234 zfcp_rec_dbf_event_trigger(id
, ref
, want
, need
, act
,
235 adapter
, port
, unit
);
239 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
240 int clear_mask
, char *id
, void *ref
)
242 zfcp_erp_adapter_block(adapter
, clear_mask
);
243 zfcp_scsi_schedule_rports_block(adapter
);
245 /* ensure propagation of failed status to new devices */
246 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
247 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
250 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
251 adapter
, NULL
, NULL
, id
, ref
);
255 * zfcp_erp_adapter_reopen - Reopen adapter.
256 * @adapter: Adapter to reopen.
257 * @clear: Status flags to clear.
258 * @id: Id for debug trace event.
259 * @ref: Reference for debug trace event.
261 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
266 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
267 write_lock(&adapter
->erp_lock
);
268 _zfcp_erp_adapter_reopen(adapter
, clear
, id
, ref
);
269 write_unlock(&adapter
->erp_lock
);
270 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
274 * zfcp_erp_adapter_shutdown - Shutdown adapter.
275 * @adapter: Adapter to shut down.
276 * @clear: Status flags to clear.
277 * @id: Id for debug trace event.
278 * @ref: Reference for debug trace event.
280 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
283 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
284 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
, ref
);
288 * zfcp_erp_port_shutdown - Shutdown port
289 * @port: Port to shut down.
290 * @clear: Status flags to clear.
291 * @id: Id for debug trace event.
292 * @ref: Reference for debug trace event.
294 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
,
297 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
298 zfcp_erp_port_reopen(port
, clear
| flags
, id
, ref
);
302 * zfcp_erp_unit_shutdown - Shutdown unit
303 * @unit: Unit to shut down.
304 * @clear: Status flags to clear.
305 * @id: Id for debug trace event.
306 * @ref: Reference for debug trace event.
308 void zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear
, char *id
,
311 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
312 zfcp_erp_unit_reopen(unit
, clear
| flags
, id
, ref
);
315 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
317 zfcp_erp_modify_port_status(port
, "erpblk1", NULL
,
318 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
,
322 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
,
323 int clear
, char *id
, void *ref
)
325 zfcp_erp_port_block(port
, clear
);
326 zfcp_scsi_schedule_rport_block(port
);
328 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
331 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
332 port
->adapter
, port
, NULL
, id
, ref
);
336 * zfcp_erp_port_forced_reopen - Forced close of port and open again
337 * @port: Port to force close and to reopen.
338 * @id: Id for debug trace event.
339 * @ref: Reference for debug trace event.
341 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
,
345 struct zfcp_adapter
*adapter
= port
->adapter
;
347 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
348 write_lock(&adapter
->erp_lock
);
349 _zfcp_erp_port_forced_reopen(port
, clear
, id
, ref
);
350 write_unlock(&adapter
->erp_lock
);
351 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
354 static int _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
,
357 zfcp_erp_port_block(port
, clear
);
358 zfcp_scsi_schedule_rport_block(port
);
360 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
361 /* ensure propagation of failed status to new devices */
362 zfcp_erp_port_failed(port
, "erpreo1", NULL
);
366 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
367 port
->adapter
, port
, NULL
, id
, ref
);
371 * zfcp_erp_port_reopen - trigger remote port recovery
372 * @port: port to recover
373 * @clear_mask: flags in port status to be cleared
375 * Returns 0 if recovery has been triggered, < 0 if not.
377 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
, void *ref
)
381 struct zfcp_adapter
*adapter
= port
->adapter
;
383 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
384 write_lock(&adapter
->erp_lock
);
385 retval
= _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
386 write_unlock(&adapter
->erp_lock
);
387 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
392 static void zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
394 zfcp_erp_modify_unit_status(unit
, "erublk1", NULL
,
395 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
399 static void _zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
402 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
404 zfcp_erp_unit_block(unit
, clear
);
406 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
409 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
410 adapter
, unit
->port
, unit
, id
, ref
);
414 * zfcp_erp_unit_reopen - initiate reopen of a unit
415 * @unit: unit to be reopened
416 * @clear_mask: specifies flags in unit status to be cleared
417 * Return: 0 on success, < 0 on error
419 void zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
423 struct zfcp_port
*port
= unit
->port
;
424 struct zfcp_adapter
*adapter
= port
->adapter
;
426 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
427 write_lock(&adapter
->erp_lock
);
428 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
429 write_unlock(&adapter
->erp_lock
);
430 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
433 static int status_change_set(unsigned long mask
, atomic_t
*status
)
435 return (atomic_read(status
) ^ mask
) & mask
;
438 static int status_change_clear(unsigned long mask
, atomic_t
*status
)
440 return atomic_read(status
) & mask
;
443 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
445 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
446 zfcp_rec_dbf_event_adapter("eraubl1", NULL
, adapter
);
447 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
450 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
452 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
453 zfcp_rec_dbf_event_port("erpubl1", NULL
, port
);
454 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
457 static void zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
459 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
))
460 zfcp_rec_dbf_event_unit("eruubl1", NULL
, unit
);
461 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
);
464 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
466 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
467 zfcp_rec_dbf_event_action("erator1", erp_action
);
470 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
472 struct zfcp_adapter
*adapter
= act
->adapter
;
477 spin_lock(&adapter
->req_list_lock
);
478 if (zfcp_reqlist_find_safe(adapter
, act
->fsf_req
) &&
479 act
->fsf_req
->erp_action
== act
) {
480 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
481 ZFCP_STATUS_ERP_TIMEDOUT
)) {
482 act
->fsf_req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
483 zfcp_rec_dbf_event_action("erscf_1", act
);
484 act
->fsf_req
->erp_action
= NULL
;
486 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
487 zfcp_rec_dbf_event_action("erscf_2", act
);
488 if (act
->fsf_req
->status
& (ZFCP_STATUS_FSFREQ_COMPLETED
|
489 ZFCP_STATUS_FSFREQ_DISMISSED
))
493 spin_unlock(&adapter
->req_list_lock
);
497 * zfcp_erp_notify - Trigger ERP action.
498 * @erp_action: ERP action to continue.
499 * @set_mask: ERP action status flags to set.
501 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
503 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
506 write_lock_irqsave(&adapter
->erp_lock
, flags
);
507 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
508 erp_action
->status
|= set_mask
;
509 zfcp_erp_action_ready(erp_action
);
511 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
515 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
516 * @data: ERP action (from timer data)
518 void zfcp_erp_timeout_handler(unsigned long data
)
520 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
521 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
524 static void zfcp_erp_memwait_handler(unsigned long data
)
526 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
529 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
531 init_timer(&erp_action
->timer
);
532 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
533 erp_action
->timer
.data
= (unsigned long) erp_action
;
534 erp_action
->timer
.expires
= jiffies
+ HZ
;
535 add_timer(&erp_action
->timer
);
538 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
539 int clear
, char *id
, void *ref
)
541 struct zfcp_port
*port
;
543 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
544 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
547 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
550 struct zfcp_unit
*unit
;
552 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
553 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
556 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
558 switch (act
->action
) {
559 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
560 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
562 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
563 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
565 case ZFCP_ERP_ACTION_REOPEN_PORT
:
566 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
568 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
569 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
574 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
576 switch (act
->action
) {
577 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
578 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
580 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
581 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
583 case ZFCP_ERP_ACTION_REOPEN_PORT
:
584 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
589 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
593 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
594 read_lock(&adapter
->erp_lock
);
595 if (list_empty(&adapter
->erp_ready_head
) &&
596 list_empty(&adapter
->erp_running_head
)) {
597 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
599 wake_up(&adapter
->erp_done_wqh
);
601 read_unlock(&adapter
->erp_lock
);
602 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
605 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
607 if (zfcp_qdio_open(act
->adapter
))
608 return ZFCP_ERP_FAILED
;
609 init_waitqueue_head(&act
->adapter
->request_wq
);
610 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &act
->adapter
->status
);
611 return ZFCP_ERP_SUCCEEDED
;
614 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
616 struct zfcp_port
*port
;
617 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
619 if (IS_ERR(port
)) /* error or port already attached */
621 _zfcp_erp_port_reopen(port
, 0, "ereptp1", NULL
);
624 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
628 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
630 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
632 for (retries
= 7; retries
; retries
--) {
633 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
635 write_lock_irq(&adapter
->erp_lock
);
636 zfcp_erp_action_to_running(erp_action
);
637 write_unlock_irq(&adapter
->erp_lock
);
638 if (zfcp_fsf_exchange_config_data(erp_action
)) {
639 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
641 return ZFCP_ERP_FAILED
;
644 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter
);
645 down(&adapter
->erp_ready_sem
);
646 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter
);
647 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
650 if (!(atomic_read(&adapter
->status
) &
651 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
658 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
661 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
662 return ZFCP_ERP_FAILED
;
664 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
665 zfcp_erp_enqueue_ptp_port(adapter
);
667 return ZFCP_ERP_SUCCEEDED
;
670 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
673 struct zfcp_adapter
*adapter
= act
->adapter
;
675 write_lock_irq(&adapter
->erp_lock
);
676 zfcp_erp_action_to_running(act
);
677 write_unlock_irq(&adapter
->erp_lock
);
679 ret
= zfcp_fsf_exchange_port_data(act
);
680 if (ret
== -EOPNOTSUPP
)
681 return ZFCP_ERP_SUCCEEDED
;
683 return ZFCP_ERP_FAILED
;
685 zfcp_rec_dbf_event_thread_lock("erasox1", adapter
);
686 down(&adapter
->erp_ready_sem
);
687 zfcp_rec_dbf_event_thread_lock("erasox2", adapter
);
688 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
689 return ZFCP_ERP_FAILED
;
691 return ZFCP_ERP_SUCCEEDED
;
694 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
696 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
697 return ZFCP_ERP_FAILED
;
699 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
700 return ZFCP_ERP_FAILED
;
702 atomic_set(&act
->adapter
->stat_miss
, 16);
703 if (zfcp_status_read_refill(act
->adapter
))
704 return ZFCP_ERP_FAILED
;
706 return ZFCP_ERP_SUCCEEDED
;
709 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
711 struct zfcp_adapter
*adapter
= act
->adapter
;
713 /* close queues to ensure that buffers are not accessed by adapter */
714 zfcp_qdio_close(adapter
);
715 zfcp_fsf_req_dismiss_all(adapter
);
716 adapter
->fsf_req_seq_no
= 0;
717 zfcp_fc_wka_port_force_offline(&adapter
->gs
->ds
);
718 /* all ports and units are closed */
719 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
720 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
722 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
723 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
726 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
728 struct zfcp_adapter
*adapter
= act
->adapter
;
730 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
731 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
732 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
734 return ZFCP_ERP_FAILED
;
737 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
738 zfcp_erp_adapter_strategy_close(act
);
739 return ZFCP_ERP_FAILED
;
742 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
744 return ZFCP_ERP_SUCCEEDED
;
747 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
749 struct zfcp_adapter
*adapter
= act
->adapter
;
751 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
752 zfcp_erp_adapter_strategy_close(act
);
753 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
754 return ZFCP_ERP_EXIT
;
757 if (zfcp_erp_adapter_strategy_open(act
)) {
759 return ZFCP_ERP_FAILED
;
762 return ZFCP_ERP_SUCCEEDED
;
765 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
769 retval
= zfcp_fsf_close_physical_port(act
);
770 if (retval
== -ENOMEM
)
771 return ZFCP_ERP_NOMEM
;
772 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
774 return ZFCP_ERP_FAILED
;
776 return ZFCP_ERP_CONTINUES
;
779 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
781 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
784 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
786 struct zfcp_port
*port
= erp_action
->port
;
787 int status
= atomic_read(&port
->status
);
789 switch (erp_action
->step
) {
790 case ZFCP_ERP_STEP_UNINITIALIZED
:
791 zfcp_erp_port_strategy_clearstati(port
);
792 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
793 (status
& ZFCP_STATUS_COMMON_OPEN
))
794 return zfcp_erp_port_forced_strategy_close(erp_action
);
796 return ZFCP_ERP_FAILED
;
798 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
799 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
800 return ZFCP_ERP_SUCCEEDED
;
802 return ZFCP_ERP_FAILED
;
805 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
809 retval
= zfcp_fsf_close_port(erp_action
);
810 if (retval
== -ENOMEM
)
811 return ZFCP_ERP_NOMEM
;
812 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
814 return ZFCP_ERP_FAILED
;
815 return ZFCP_ERP_CONTINUES
;
818 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
822 retval
= zfcp_fsf_open_port(erp_action
);
823 if (retval
== -ENOMEM
)
824 return ZFCP_ERP_NOMEM
;
825 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
827 return ZFCP_ERP_FAILED
;
828 return ZFCP_ERP_CONTINUES
;
831 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
833 struct zfcp_adapter
*adapter
= act
->adapter
;
834 struct zfcp_port
*port
= act
->port
;
836 if (port
->wwpn
!= adapter
->peer_wwpn
) {
837 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
838 return ZFCP_ERP_FAILED
;
840 port
->d_id
= adapter
->peer_d_id
;
841 return zfcp_erp_port_strategy_open_port(act
);
844 void zfcp_erp_port_strategy_open_lookup(struct work_struct
*work
)
847 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
850 retval
= zfcp_fc_ns_gid_pn(&port
->erp_action
);
852 port
->erp_action
.step
= ZFCP_ERP_STEP_NAMESERVER_LOOKUP
;
855 if (retval
== -ENOMEM
) {
856 zfcp_erp_notify(&port
->erp_action
, ZFCP_STATUS_ERP_LOWMEM
);
859 /* all other error condtions */
860 zfcp_erp_notify(&port
->erp_action
, 0);
865 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
867 struct zfcp_adapter
*adapter
= act
->adapter
;
868 struct zfcp_port
*port
= act
->port
;
869 int p_status
= atomic_read(&port
->status
);
872 case ZFCP_ERP_STEP_UNINITIALIZED
:
873 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
874 case ZFCP_ERP_STEP_PORT_CLOSING
:
875 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
876 return zfcp_erp_open_ptp_port(act
);
879 if (!queue_work(zfcp_data
.work_queue
,
882 return ZFCP_ERP_CONTINUES
;
885 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP
:
887 return ZFCP_ERP_FAILED
;
888 return zfcp_erp_port_strategy_open_port(act
);
890 case ZFCP_ERP_STEP_PORT_OPENING
:
891 /* D_ID might have changed during open */
892 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
894 return ZFCP_ERP_SUCCEEDED
;
896 act
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
897 return ZFCP_ERP_CONTINUES
;
900 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
902 _zfcp_erp_port_reopen(port
, 0, "erpsoc1", NULL
);
903 return ZFCP_ERP_EXIT
;
905 /* fall through otherwise */
907 return ZFCP_ERP_FAILED
;
910 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
912 struct zfcp_port
*port
= erp_action
->port
;
914 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
)
915 goto close_init_done
;
917 switch (erp_action
->step
) {
918 case ZFCP_ERP_STEP_UNINITIALIZED
:
919 zfcp_erp_port_strategy_clearstati(port
);
920 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_OPEN
)
921 return zfcp_erp_port_strategy_close(erp_action
);
924 case ZFCP_ERP_STEP_PORT_CLOSING
:
925 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_OPEN
)
926 return ZFCP_ERP_FAILED
;
931 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
932 return ZFCP_ERP_EXIT
;
934 return zfcp_erp_port_strategy_open_common(erp_action
);
937 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
939 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
940 ZFCP_STATUS_UNIT_SHARED
|
941 ZFCP_STATUS_UNIT_READONLY
,
945 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
947 int retval
= zfcp_fsf_close_unit(erp_action
);
948 if (retval
== -ENOMEM
)
949 return ZFCP_ERP_NOMEM
;
950 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
952 return ZFCP_ERP_FAILED
;
953 return ZFCP_ERP_CONTINUES
;
956 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
958 int retval
= zfcp_fsf_open_unit(erp_action
);
959 if (retval
== -ENOMEM
)
960 return ZFCP_ERP_NOMEM
;
961 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
963 return ZFCP_ERP_FAILED
;
964 return ZFCP_ERP_CONTINUES
;
967 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
969 struct zfcp_unit
*unit
= erp_action
->unit
;
971 switch (erp_action
->step
) {
972 case ZFCP_ERP_STEP_UNINITIALIZED
:
973 zfcp_erp_unit_strategy_clearstati(unit
);
974 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
975 return zfcp_erp_unit_strategy_close(erp_action
);
976 /* already closed, fall through */
977 case ZFCP_ERP_STEP_UNIT_CLOSING
:
978 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
979 return ZFCP_ERP_FAILED
;
980 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
981 return ZFCP_ERP_EXIT
;
982 return zfcp_erp_unit_strategy_open(erp_action
);
984 case ZFCP_ERP_STEP_UNIT_OPENING
:
985 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
986 return ZFCP_ERP_SUCCEEDED
;
988 return ZFCP_ERP_FAILED
;
991 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
994 case ZFCP_ERP_SUCCEEDED
:
995 atomic_set(&unit
->erp_counter
, 0);
996 zfcp_erp_unit_unblock(unit
);
998 case ZFCP_ERP_FAILED
:
999 atomic_inc(&unit
->erp_counter
);
1000 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
) {
1001 dev_err(&unit
->port
->adapter
->ccw_device
->dev
,
1002 "ERP failed for unit 0x%016Lx on "
1004 (unsigned long long)unit
->fcp_lun
,
1005 (unsigned long long)unit
->port
->wwpn
);
1006 zfcp_erp_unit_failed(unit
, "erusck1", NULL
);
1011 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1012 zfcp_erp_unit_block(unit
, 0);
1013 result
= ZFCP_ERP_EXIT
;
1018 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1021 case ZFCP_ERP_SUCCEEDED
:
1022 atomic_set(&port
->erp_counter
, 0);
1023 zfcp_erp_port_unblock(port
);
1026 case ZFCP_ERP_FAILED
:
1027 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1028 zfcp_erp_port_block(port
, 0);
1029 result
= ZFCP_ERP_EXIT
;
1031 atomic_inc(&port
->erp_counter
);
1032 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1033 dev_err(&port
->adapter
->ccw_device
->dev
,
1034 "ERP failed for remote port 0x%016Lx\n",
1035 (unsigned long long)port
->wwpn
);
1036 zfcp_erp_port_failed(port
, "erpsck1", NULL
);
1041 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1042 zfcp_erp_port_block(port
, 0);
1043 result
= ZFCP_ERP_EXIT
;
1048 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1052 case ZFCP_ERP_SUCCEEDED
:
1053 atomic_set(&adapter
->erp_counter
, 0);
1054 zfcp_erp_adapter_unblock(adapter
);
1057 case ZFCP_ERP_FAILED
:
1058 atomic_inc(&adapter
->erp_counter
);
1059 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1060 dev_err(&adapter
->ccw_device
->dev
,
1061 "ERP cannot recover an error "
1062 "on the FCP device\n");
1063 zfcp_erp_adapter_failed(adapter
, "erasck1", NULL
);
1068 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1069 zfcp_erp_adapter_block(adapter
, 0);
1070 result
= ZFCP_ERP_EXIT
;
1075 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1078 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1079 struct zfcp_port
*port
= erp_action
->port
;
1080 struct zfcp_unit
*unit
= erp_action
->unit
;
1082 switch (erp_action
->action
) {
1084 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1085 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1088 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1089 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1090 result
= zfcp_erp_strategy_check_port(port
, result
);
1093 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1094 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1100 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1102 int status
= atomic_read(target_status
);
1104 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1105 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1106 return 1; /* take it online */
1108 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1109 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1110 return 1; /* take it offline */
1115 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1117 int action
= act
->action
;
1118 struct zfcp_adapter
*adapter
= act
->adapter
;
1119 struct zfcp_port
*port
= act
->port
;
1120 struct zfcp_unit
*unit
= act
->unit
;
1121 u32 erp_status
= act
->status
;
1124 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1125 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1126 _zfcp_erp_adapter_reopen(adapter
,
1127 ZFCP_STATUS_COMMON_ERP_FAILED
,
1129 return ZFCP_ERP_EXIT
;
1133 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1134 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1135 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1136 _zfcp_erp_port_reopen(port
,
1137 ZFCP_STATUS_COMMON_ERP_FAILED
,
1139 return ZFCP_ERP_EXIT
;
1143 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1144 if (zfcp_erp_strat_change_det(&unit
->status
, erp_status
)) {
1145 _zfcp_erp_unit_reopen(unit
,
1146 ZFCP_STATUS_COMMON_ERP_FAILED
,
1148 return ZFCP_ERP_EXIT
;
1155 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1157 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1159 adapter
->erp_total_count
--;
1160 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1161 adapter
->erp_low_mem_count
--;
1162 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1165 list_del(&erp_action
->list
);
1166 zfcp_rec_dbf_event_action("eractd1", erp_action
);
1168 switch (erp_action
->action
) {
1169 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1170 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1171 &erp_action
->unit
->status
);
1174 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1175 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1176 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1177 &erp_action
->port
->status
);
1180 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1181 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1182 &erp_action
->adapter
->status
);
1187 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1189 struct zfcp_adapter
*adapter
= act
->adapter
;
1190 struct zfcp_port
*port
= act
->port
;
1191 struct zfcp_unit
*unit
= act
->unit
;
1193 switch (act
->action
) {
1194 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1195 if ((result
== ZFCP_ERP_SUCCEEDED
) && !unit
->device
) {
1196 zfcp_unit_get(unit
);
1197 if (scsi_queue_work(unit
->port
->adapter
->scsi_host
,
1198 &unit
->scsi_work
) <= 0)
1199 zfcp_unit_put(unit
);
1201 zfcp_unit_put(unit
);
1204 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1205 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1206 if (result
== ZFCP_ERP_SUCCEEDED
)
1207 zfcp_scsi_schedule_rport_register(port
);
1208 zfcp_port_put(port
);
1211 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1212 if (result
== ZFCP_ERP_SUCCEEDED
) {
1213 register_service_level(&adapter
->service_level
);
1214 schedule_work(&adapter
->scan_work
);
1216 unregister_service_level(&adapter
->service_level
);
1217 zfcp_adapter_put(adapter
);
1222 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1224 switch (erp_action
->action
) {
1225 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1226 return zfcp_erp_adapter_strategy(erp_action
);
1227 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1228 return zfcp_erp_port_forced_strategy(erp_action
);
1229 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1230 return zfcp_erp_port_strategy(erp_action
);
1231 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1232 return zfcp_erp_unit_strategy(erp_action
);
1234 return ZFCP_ERP_FAILED
;
1237 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1240 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1241 unsigned long flags
;
1243 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1244 write_lock(&adapter
->erp_lock
);
1246 zfcp_erp_strategy_check_fsfreq(erp_action
);
1248 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1249 zfcp_erp_action_dequeue(erp_action
);
1250 retval
= ZFCP_ERP_DISMISSED
;
1254 zfcp_erp_action_to_running(erp_action
);
1256 /* no lock to allow for blocking operations */
1257 write_unlock(&adapter
->erp_lock
);
1258 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1259 retval
= zfcp_erp_strategy_do_action(erp_action
);
1260 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1261 write_lock(&adapter
->erp_lock
);
1263 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1264 retval
= ZFCP_ERP_CONTINUES
;
1267 case ZFCP_ERP_NOMEM
:
1268 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1269 ++adapter
->erp_low_mem_count
;
1270 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1272 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1273 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1275 zfcp_erp_strategy_memwait(erp_action
);
1276 retval
= ZFCP_ERP_CONTINUES
;
1280 case ZFCP_ERP_CONTINUES
:
1281 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1282 --adapter
->erp_low_mem_count
;
1283 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1288 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1289 zfcp_erp_action_dequeue(erp_action
);
1290 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1291 if (retval
== ZFCP_ERP_EXIT
)
1293 if (retval
== ZFCP_ERP_SUCCEEDED
)
1294 zfcp_erp_strategy_followup_success(erp_action
);
1295 if (retval
== ZFCP_ERP_FAILED
)
1296 zfcp_erp_strategy_followup_failed(erp_action
);
1299 write_unlock(&adapter
->erp_lock
);
1300 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1302 if (retval
!= ZFCP_ERP_CONTINUES
)
1303 zfcp_erp_action_cleanup(erp_action
, retval
);
1308 static int zfcp_erp_thread(void *data
)
1310 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1311 struct list_head
*next
;
1312 struct zfcp_erp_action
*act
;
1313 unsigned long flags
;
1316 daemonize("zfcperp%s", dev_name(&adapter
->ccw_device
->dev
));
1317 /* Block all signals */
1318 siginitsetinv(¤t
->blocked
, 0);
1319 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1320 wake_up(&adapter
->erp_thread_wqh
);
1322 while (!(atomic_read(&adapter
->status
) &
1323 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
)) {
1325 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter
);
1326 ignore
= down_interruptible(&adapter
->erp_ready_sem
);
1327 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter
);
1329 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1330 next
= adapter
->erp_ready_head
.next
;
1331 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1333 if (next
!= &adapter
->erp_ready_head
) {
1334 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1336 /* there is more to come after dismission, no notify */
1337 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1338 zfcp_erp_wakeup(adapter
);
1342 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1343 wake_up(&adapter
->erp_thread_wqh
);
1349 * zfcp_erp_thread_setup - Start ERP thread for adapter
1350 * @adapter: Adapter to start the ERP thread for
1352 * Returns 0 on success or error code from kernel_thread()
1354 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1358 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1359 retval
= kernel_thread(zfcp_erp_thread
, adapter
, SIGCHLD
);
1361 dev_err(&adapter
->ccw_device
->dev
,
1362 "Creating an ERP thread for the FCP device failed.\n");
1365 wait_event(adapter
->erp_thread_wqh
,
1366 atomic_read(&adapter
->status
) &
1367 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
);
1372 * zfcp_erp_thread_kill - Stop ERP thread.
1373 * @adapter: Adapter where the ERP thread should be stopped.
1375 * The caller of this routine ensures that the specified adapter has
1376 * been shut down and that this operation has been completed. Thus,
1377 * there are no pending erp_actions which would need to be handled
1380 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1382 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
, &adapter
->status
);
1383 up(&adapter
->erp_ready_sem
);
1384 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter
);
1386 wait_event(adapter
->erp_thread_wqh
,
1387 !(atomic_read(&adapter
->status
) &
1388 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
));
1390 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
,
1395 * zfcp_erp_adapter_failed - Set adapter status to failed.
1396 * @adapter: Failed adapter.
1397 * @id: Event id for debug trace.
1398 * @ref: Reference for debug trace.
1400 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1402 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1403 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1407 * zfcp_erp_port_failed - Set port status to failed.
1408 * @port: Failed port.
1409 * @id: Event id for debug trace.
1410 * @ref: Reference for debug trace.
1412 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1414 zfcp_erp_modify_port_status(port
, id
, ref
,
1415 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1419 * zfcp_erp_unit_failed - Set unit status to failed.
1420 * @unit: Failed unit.
1421 * @id: Event id for debug trace.
1422 * @ref: Reference for debug trace.
1424 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1426 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1427 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1431 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1432 * @adapter: adapter for which to wait for completion of its error recovery
1434 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1436 wait_event(adapter
->erp_done_wqh
,
1437 !(atomic_read(&adapter
->status
) &
1438 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1442 * zfcp_erp_modify_adapter_status - change adapter status bits
1443 * @adapter: adapter to change the status
1444 * @id: id for the debug trace
1445 * @ref: reference for the debug trace
1446 * @mask: status bits to change
1447 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1449 * Changes in common status bits are propagated to attached ports and units.
1451 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1452 void *ref
, u32 mask
, int set_or_clear
)
1454 struct zfcp_port
*port
;
1455 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1457 if (set_or_clear
== ZFCP_SET
) {
1458 if (status_change_set(mask
, &adapter
->status
))
1459 zfcp_rec_dbf_event_adapter(id
, ref
, adapter
);
1460 atomic_set_mask(mask
, &adapter
->status
);
1462 if (status_change_clear(mask
, &adapter
->status
))
1463 zfcp_rec_dbf_event_adapter(id
, ref
, adapter
);
1464 atomic_clear_mask(mask
, &adapter
->status
);
1465 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1466 atomic_set(&adapter
->erp_counter
, 0);
1470 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1471 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1476 * zfcp_erp_modify_port_status - change port status bits
1477 * @port: port to change the status bits
1478 * @id: id for the debug trace
1479 * @ref: reference for the debug trace
1480 * @mask: status bits to change
1481 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1483 * Changes in common status bits are propagated to attached units.
1485 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1486 u32 mask
, int set_or_clear
)
1488 struct zfcp_unit
*unit
;
1489 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1491 if (set_or_clear
== ZFCP_SET
) {
1492 if (status_change_set(mask
, &port
->status
))
1493 zfcp_rec_dbf_event_port(id
, ref
, port
);
1494 atomic_set_mask(mask
, &port
->status
);
1496 if (status_change_clear(mask
, &port
->status
))
1497 zfcp_rec_dbf_event_port(id
, ref
, port
);
1498 atomic_clear_mask(mask
, &port
->status
);
1499 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1500 atomic_set(&port
->erp_counter
, 0);
1504 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1505 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1510 * zfcp_erp_modify_unit_status - change unit status bits
1511 * @unit: unit to change the status bits
1512 * @id: id for the debug trace
1513 * @ref: reference for the debug trace
1514 * @mask: status bits to change
1515 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1517 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1518 u32 mask
, int set_or_clear
)
1520 if (set_or_clear
== ZFCP_SET
) {
1521 if (status_change_set(mask
, &unit
->status
))
1522 zfcp_rec_dbf_event_unit(id
, ref
, unit
);
1523 atomic_set_mask(mask
, &unit
->status
);
1525 if (status_change_clear(mask
, &unit
->status
))
1526 zfcp_rec_dbf_event_unit(id
, ref
, unit
);
1527 atomic_clear_mask(mask
, &unit
->status
);
1528 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1529 atomic_set(&unit
->erp_counter
, 0);
1535 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1536 * @port: The "boxed" port.
1537 * @id: The debug trace id.
1538 * @id: Reference for the debug trace.
1540 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1542 unsigned long flags
;
1544 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1545 zfcp_erp_modify_port_status(port
, id
, ref
,
1546 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1547 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1548 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1552 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1553 * @port: The "boxed" unit.
1554 * @id: The debug trace id.
1555 * @id: Reference for the debug trace.
1557 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1559 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1560 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1561 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1565 * zfcp_erp_port_access_denied - Adapter denied access to port.
1566 * @port: port where access has been denied
1567 * @id: id for debug trace
1568 * @ref: reference for debug trace
1570 * Since the adapter has denied access, stop using the port and the
1573 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1575 unsigned long flags
;
1577 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1578 zfcp_erp_modify_port_status(port
, id
, ref
,
1579 ZFCP_STATUS_COMMON_ERP_FAILED
|
1580 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1581 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1585 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1586 * @unit: unit where access has been denied
1587 * @id: id for debug trace
1588 * @ref: reference for debug trace
1590 * Since the adapter has denied access, stop using the unit.
1592 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1594 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1595 ZFCP_STATUS_COMMON_ERP_FAILED
|
1596 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1599 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1602 int status
= atomic_read(&unit
->status
);
1603 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1604 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1607 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1610 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1613 struct zfcp_unit
*unit
;
1614 int status
= atomic_read(&port
->status
);
1616 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1617 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1618 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1619 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1623 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1627 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1628 * @adapter: Adapter where the Access Control Table (ACT) changed
1629 * @id: Id for debug trace
1630 * @ref: Reference for debug trace
1632 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1635 struct zfcp_port
*port
;
1636 unsigned long flags
;
1638 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1641 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1642 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1643 zfcp_erp_port_access_changed(port
, id
, ref
);
1644 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);