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_DISMISSED
)
492 spin_unlock(&adapter
->req_list_lock
);
496 * zfcp_erp_notify - Trigger ERP action.
497 * @erp_action: ERP action to continue.
498 * @set_mask: ERP action status flags to set.
500 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
502 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
505 write_lock_irqsave(&adapter
->erp_lock
, flags
);
506 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
507 erp_action
->status
|= set_mask
;
508 zfcp_erp_action_ready(erp_action
);
510 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
514 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
515 * @data: ERP action (from timer data)
517 void zfcp_erp_timeout_handler(unsigned long data
)
519 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
520 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
523 static void zfcp_erp_memwait_handler(unsigned long data
)
525 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
528 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
530 init_timer(&erp_action
->timer
);
531 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
532 erp_action
->timer
.data
= (unsigned long) erp_action
;
533 erp_action
->timer
.expires
= jiffies
+ HZ
;
534 add_timer(&erp_action
->timer
);
537 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
538 int clear
, char *id
, void *ref
)
540 struct zfcp_port
*port
;
542 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
543 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
546 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
549 struct zfcp_unit
*unit
;
551 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
552 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
555 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
557 switch (act
->action
) {
558 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
559 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
561 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
562 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
564 case ZFCP_ERP_ACTION_REOPEN_PORT
:
565 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
567 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
568 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
573 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
575 switch (act
->action
) {
576 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
577 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
579 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
580 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
582 case ZFCP_ERP_ACTION_REOPEN_PORT
:
583 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
588 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
592 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
593 read_lock(&adapter
->erp_lock
);
594 if (list_empty(&adapter
->erp_ready_head
) &&
595 list_empty(&adapter
->erp_running_head
)) {
596 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
598 wake_up(&adapter
->erp_done_wqh
);
600 read_unlock(&adapter
->erp_lock
);
601 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
604 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
606 if (zfcp_qdio_open(act
->adapter
))
607 return ZFCP_ERP_FAILED
;
608 init_waitqueue_head(&act
->adapter
->request_wq
);
609 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &act
->adapter
->status
);
610 return ZFCP_ERP_SUCCEEDED
;
613 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
615 struct zfcp_port
*port
;
616 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
618 if (IS_ERR(port
)) /* error or port already attached */
620 _zfcp_erp_port_reopen(port
, 0, "ereptp1", NULL
);
623 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
627 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
629 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
631 for (retries
= 7; retries
; retries
--) {
632 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
634 write_lock_irq(&adapter
->erp_lock
);
635 zfcp_erp_action_to_running(erp_action
);
636 write_unlock_irq(&adapter
->erp_lock
);
637 if (zfcp_fsf_exchange_config_data(erp_action
)) {
638 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
640 return ZFCP_ERP_FAILED
;
643 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter
);
644 down(&adapter
->erp_ready_sem
);
645 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter
);
646 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
649 if (!(atomic_read(&adapter
->status
) &
650 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
657 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
660 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
661 return ZFCP_ERP_FAILED
;
663 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
664 zfcp_erp_enqueue_ptp_port(adapter
);
666 return ZFCP_ERP_SUCCEEDED
;
669 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
672 struct zfcp_adapter
*adapter
= act
->adapter
;
674 write_lock_irq(&adapter
->erp_lock
);
675 zfcp_erp_action_to_running(act
);
676 write_unlock_irq(&adapter
->erp_lock
);
678 ret
= zfcp_fsf_exchange_port_data(act
);
679 if (ret
== -EOPNOTSUPP
)
680 return ZFCP_ERP_SUCCEEDED
;
682 return ZFCP_ERP_FAILED
;
684 zfcp_rec_dbf_event_thread_lock("erasox1", adapter
);
685 down(&adapter
->erp_ready_sem
);
686 zfcp_rec_dbf_event_thread_lock("erasox2", adapter
);
687 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
688 return ZFCP_ERP_FAILED
;
690 return ZFCP_ERP_SUCCEEDED
;
693 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
695 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
696 return ZFCP_ERP_FAILED
;
698 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
699 return ZFCP_ERP_FAILED
;
701 atomic_set(&act
->adapter
->stat_miss
, 16);
702 if (zfcp_status_read_refill(act
->adapter
))
703 return ZFCP_ERP_FAILED
;
705 return ZFCP_ERP_SUCCEEDED
;
708 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
710 struct zfcp_adapter
*adapter
= act
->adapter
;
712 /* close queues to ensure that buffers are not accessed by adapter */
713 zfcp_qdio_close(adapter
);
714 zfcp_fsf_req_dismiss_all(adapter
);
715 adapter
->fsf_req_seq_no
= 0;
716 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
717 /* all ports and units are closed */
718 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
719 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
721 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
722 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
725 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
727 struct zfcp_adapter
*adapter
= act
->adapter
;
729 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
730 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
731 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
733 return ZFCP_ERP_FAILED
;
736 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
737 zfcp_erp_adapter_strategy_close(act
);
738 return ZFCP_ERP_FAILED
;
741 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
743 return ZFCP_ERP_SUCCEEDED
;
746 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
748 struct zfcp_adapter
*adapter
= act
->adapter
;
750 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
751 zfcp_erp_adapter_strategy_close(act
);
752 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
753 return ZFCP_ERP_EXIT
;
756 if (zfcp_erp_adapter_strategy_open(act
)) {
758 return ZFCP_ERP_FAILED
;
761 return ZFCP_ERP_SUCCEEDED
;
764 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
768 retval
= zfcp_fsf_close_physical_port(act
);
769 if (retval
== -ENOMEM
)
770 return ZFCP_ERP_NOMEM
;
771 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
773 return ZFCP_ERP_FAILED
;
775 return ZFCP_ERP_CONTINUES
;
778 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
780 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
783 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
785 struct zfcp_port
*port
= erp_action
->port
;
786 int status
= atomic_read(&port
->status
);
788 switch (erp_action
->step
) {
789 case ZFCP_ERP_STEP_UNINITIALIZED
:
790 zfcp_erp_port_strategy_clearstati(port
);
791 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
792 (status
& ZFCP_STATUS_COMMON_OPEN
))
793 return zfcp_erp_port_forced_strategy_close(erp_action
);
795 return ZFCP_ERP_FAILED
;
797 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
798 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
799 return ZFCP_ERP_SUCCEEDED
;
801 return ZFCP_ERP_FAILED
;
804 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
808 retval
= zfcp_fsf_close_port(erp_action
);
809 if (retval
== -ENOMEM
)
810 return ZFCP_ERP_NOMEM
;
811 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
813 return ZFCP_ERP_FAILED
;
814 return ZFCP_ERP_CONTINUES
;
817 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
821 retval
= zfcp_fsf_open_port(erp_action
);
822 if (retval
== -ENOMEM
)
823 return ZFCP_ERP_NOMEM
;
824 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
826 return ZFCP_ERP_FAILED
;
827 return ZFCP_ERP_CONTINUES
;
830 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
832 struct zfcp_adapter
*adapter
= act
->adapter
;
833 struct zfcp_port
*port
= act
->port
;
835 if (port
->wwpn
!= adapter
->peer_wwpn
) {
836 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
837 return ZFCP_ERP_FAILED
;
839 port
->d_id
= adapter
->peer_d_id
;
840 return zfcp_erp_port_strategy_open_port(act
);
843 void zfcp_erp_port_strategy_open_lookup(struct work_struct
*work
)
846 struct zfcp_port
*port
= container_of(work
, struct zfcp_port
,
849 retval
= zfcp_fc_ns_gid_pn(&port
->erp_action
);
851 port
->erp_action
.step
= ZFCP_ERP_STEP_NAMESERVER_LOOKUP
;
854 if (retval
== -ENOMEM
) {
855 zfcp_erp_notify(&port
->erp_action
, ZFCP_STATUS_ERP_LOWMEM
);
858 /* all other error condtions */
859 zfcp_erp_notify(&port
->erp_action
, 0);
864 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
866 struct zfcp_adapter
*adapter
= act
->adapter
;
867 struct zfcp_port
*port
= act
->port
;
868 int p_status
= atomic_read(&port
->status
);
871 case ZFCP_ERP_STEP_UNINITIALIZED
:
872 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
873 case ZFCP_ERP_STEP_PORT_CLOSING
:
874 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
875 return zfcp_erp_open_ptp_port(act
);
878 if (!queue_work(zfcp_data
.work_queue
,
881 return ZFCP_ERP_CONTINUES
;
884 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP
:
886 return ZFCP_ERP_FAILED
;
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 return ZFCP_ERP_SUCCEEDED
;
895 act
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
896 return ZFCP_ERP_CONTINUES
;
899 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
901 _zfcp_erp_port_reopen(port
, 0, "erpsoc1", NULL
);
902 return ZFCP_ERP_EXIT
;
904 /* fall through otherwise */
906 return ZFCP_ERP_FAILED
;
909 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
911 struct zfcp_port
*port
= erp_action
->port
;
913 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
)
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 (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_OPEN
)
920 return zfcp_erp_port_strategy_close(erp_action
);
923 case ZFCP_ERP_STEP_PORT_CLOSING
:
924 if (atomic_read(&port
->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_rec_dbf_event_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 if ((result
== ZFCP_ERP_SUCCEEDED
) && !unit
->device
) {
1195 zfcp_unit_get(unit
);
1196 if (scsi_queue_work(unit
->port
->adapter
->scsi_host
,
1197 &unit
->scsi_work
) <= 0)
1198 zfcp_unit_put(unit
);
1200 zfcp_unit_put(unit
);
1203 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1204 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1205 if (result
== ZFCP_ERP_SUCCEEDED
)
1206 zfcp_scsi_schedule_rport_register(port
);
1207 zfcp_port_put(port
);
1210 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1211 if (result
== ZFCP_ERP_SUCCEEDED
) {
1212 register_service_level(&adapter
->service_level
);
1213 schedule_work(&adapter
->scan_work
);
1215 unregister_service_level(&adapter
->service_level
);
1216 zfcp_adapter_put(adapter
);
1221 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1223 switch (erp_action
->action
) {
1224 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1225 return zfcp_erp_adapter_strategy(erp_action
);
1226 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1227 return zfcp_erp_port_forced_strategy(erp_action
);
1228 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1229 return zfcp_erp_port_strategy(erp_action
);
1230 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1231 return zfcp_erp_unit_strategy(erp_action
);
1233 return ZFCP_ERP_FAILED
;
1236 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1239 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1240 unsigned long flags
;
1242 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1243 write_lock(&adapter
->erp_lock
);
1245 zfcp_erp_strategy_check_fsfreq(erp_action
);
1247 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1248 zfcp_erp_action_dequeue(erp_action
);
1249 retval
= ZFCP_ERP_DISMISSED
;
1253 zfcp_erp_action_to_running(erp_action
);
1255 /* no lock to allow for blocking operations */
1256 write_unlock(&adapter
->erp_lock
);
1257 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1258 retval
= zfcp_erp_strategy_do_action(erp_action
);
1259 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1260 write_lock(&adapter
->erp_lock
);
1262 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1263 retval
= ZFCP_ERP_CONTINUES
;
1266 case ZFCP_ERP_NOMEM
:
1267 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1268 ++adapter
->erp_low_mem_count
;
1269 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1271 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1272 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1274 zfcp_erp_strategy_memwait(erp_action
);
1275 retval
= ZFCP_ERP_CONTINUES
;
1279 case ZFCP_ERP_CONTINUES
:
1280 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1281 --adapter
->erp_low_mem_count
;
1282 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1287 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1288 zfcp_erp_action_dequeue(erp_action
);
1289 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1290 if (retval
== ZFCP_ERP_EXIT
)
1292 if (retval
== ZFCP_ERP_SUCCEEDED
)
1293 zfcp_erp_strategy_followup_success(erp_action
);
1294 if (retval
== ZFCP_ERP_FAILED
)
1295 zfcp_erp_strategy_followup_failed(erp_action
);
1298 write_unlock(&adapter
->erp_lock
);
1299 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1301 if (retval
!= ZFCP_ERP_CONTINUES
)
1302 zfcp_erp_action_cleanup(erp_action
, retval
);
1307 static int zfcp_erp_thread(void *data
)
1309 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1310 struct list_head
*next
;
1311 struct zfcp_erp_action
*act
;
1312 unsigned long flags
;
1315 daemonize("zfcperp%s", dev_name(&adapter
->ccw_device
->dev
));
1316 /* Block all signals */
1317 siginitsetinv(¤t
->blocked
, 0);
1318 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1319 wake_up(&adapter
->erp_thread_wqh
);
1321 while (!(atomic_read(&adapter
->status
) &
1322 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
)) {
1324 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter
);
1325 ignore
= down_interruptible(&adapter
->erp_ready_sem
);
1326 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter
);
1328 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1329 next
= adapter
->erp_ready_head
.next
;
1330 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1332 if (next
!= &adapter
->erp_ready_head
) {
1333 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1335 /* there is more to come after dismission, no notify */
1336 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1337 zfcp_erp_wakeup(adapter
);
1341 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1342 wake_up(&adapter
->erp_thread_wqh
);
1348 * zfcp_erp_thread_setup - Start ERP thread for adapter
1349 * @adapter: Adapter to start the ERP thread for
1351 * Returns 0 on success or error code from kernel_thread()
1353 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1357 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
, &adapter
->status
);
1358 retval
= kernel_thread(zfcp_erp_thread
, adapter
, SIGCHLD
);
1360 dev_err(&adapter
->ccw_device
->dev
,
1361 "Creating an ERP thread for the FCP device failed.\n");
1364 wait_event(adapter
->erp_thread_wqh
,
1365 atomic_read(&adapter
->status
) &
1366 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
);
1371 * zfcp_erp_thread_kill - Stop ERP thread.
1372 * @adapter: Adapter where the ERP thread should be stopped.
1374 * The caller of this routine ensures that the specified adapter has
1375 * been shut down and that this operation has been completed. Thus,
1376 * there are no pending erp_actions which would need to be handled
1379 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1381 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
, &adapter
->status
);
1382 up(&adapter
->erp_ready_sem
);
1383 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter
);
1385 wait_event(adapter
->erp_thread_wqh
,
1386 !(atomic_read(&adapter
->status
) &
1387 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP
));
1389 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL
,
1394 * zfcp_erp_adapter_failed - Set adapter status to failed.
1395 * @adapter: Failed adapter.
1396 * @id: Event id for debug trace.
1397 * @ref: Reference for debug trace.
1399 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1401 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1402 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1406 * zfcp_erp_port_failed - Set port status to failed.
1407 * @port: Failed port.
1408 * @id: Event id for debug trace.
1409 * @ref: Reference for debug trace.
1411 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1413 zfcp_erp_modify_port_status(port
, id
, ref
,
1414 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1418 * zfcp_erp_unit_failed - Set unit status to failed.
1419 * @unit: Failed unit.
1420 * @id: Event id for debug trace.
1421 * @ref: Reference for debug trace.
1423 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1425 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1426 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1430 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1431 * @adapter: adapter for which to wait for completion of its error recovery
1433 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1435 wait_event(adapter
->erp_done_wqh
,
1436 !(atomic_read(&adapter
->status
) &
1437 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1441 * zfcp_erp_modify_adapter_status - change adapter status bits
1442 * @adapter: adapter to change the status
1443 * @id: id for the debug trace
1444 * @ref: reference for the debug trace
1445 * @mask: status bits to change
1446 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1448 * Changes in common status bits are propagated to attached ports and units.
1450 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1451 void *ref
, u32 mask
, int set_or_clear
)
1453 struct zfcp_port
*port
;
1454 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1456 if (set_or_clear
== ZFCP_SET
) {
1457 if (status_change_set(mask
, &adapter
->status
))
1458 zfcp_rec_dbf_event_adapter(id
, ref
, adapter
);
1459 atomic_set_mask(mask
, &adapter
->status
);
1461 if (status_change_clear(mask
, &adapter
->status
))
1462 zfcp_rec_dbf_event_adapter(id
, ref
, adapter
);
1463 atomic_clear_mask(mask
, &adapter
->status
);
1464 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1465 atomic_set(&adapter
->erp_counter
, 0);
1469 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1470 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1475 * zfcp_erp_modify_port_status - change port status bits
1476 * @port: port to change the status bits
1477 * @id: id for the debug trace
1478 * @ref: reference for the debug trace
1479 * @mask: status bits to change
1480 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1482 * Changes in common status bits are propagated to attached units.
1484 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1485 u32 mask
, int set_or_clear
)
1487 struct zfcp_unit
*unit
;
1488 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1490 if (set_or_clear
== ZFCP_SET
) {
1491 if (status_change_set(mask
, &port
->status
))
1492 zfcp_rec_dbf_event_port(id
, ref
, port
);
1493 atomic_set_mask(mask
, &port
->status
);
1495 if (status_change_clear(mask
, &port
->status
))
1496 zfcp_rec_dbf_event_port(id
, ref
, port
);
1497 atomic_clear_mask(mask
, &port
->status
);
1498 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1499 atomic_set(&port
->erp_counter
, 0);
1503 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1504 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1509 * zfcp_erp_modify_unit_status - change unit status bits
1510 * @unit: unit to change the status bits
1511 * @id: id for the debug trace
1512 * @ref: reference for the debug trace
1513 * @mask: status bits to change
1514 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1516 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1517 u32 mask
, int set_or_clear
)
1519 if (set_or_clear
== ZFCP_SET
) {
1520 if (status_change_set(mask
, &unit
->status
))
1521 zfcp_rec_dbf_event_unit(id
, ref
, unit
);
1522 atomic_set_mask(mask
, &unit
->status
);
1524 if (status_change_clear(mask
, &unit
->status
))
1525 zfcp_rec_dbf_event_unit(id
, ref
, unit
);
1526 atomic_clear_mask(mask
, &unit
->status
);
1527 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1528 atomic_set(&unit
->erp_counter
, 0);
1534 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1535 * @port: The "boxed" port.
1536 * @id: The debug trace id.
1537 * @id: Reference for the debug trace.
1539 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1541 unsigned long flags
;
1543 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1544 zfcp_erp_modify_port_status(port
, id
, ref
,
1545 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1546 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1547 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1551 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1552 * @port: The "boxed" unit.
1553 * @id: The debug trace id.
1554 * @id: Reference for the debug trace.
1556 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1558 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1559 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1560 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1564 * zfcp_erp_port_access_denied - Adapter denied access to port.
1565 * @port: port where access has been denied
1566 * @id: id for debug trace
1567 * @ref: reference for debug trace
1569 * Since the adapter has denied access, stop using the port and the
1572 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1574 unsigned long flags
;
1576 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1577 zfcp_erp_modify_port_status(port
, id
, ref
,
1578 ZFCP_STATUS_COMMON_ERP_FAILED
|
1579 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1580 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1584 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1585 * @unit: unit where access has been denied
1586 * @id: id for debug trace
1587 * @ref: reference for debug trace
1589 * Since the adapter has denied access, stop using the unit.
1591 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1593 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1594 ZFCP_STATUS_COMMON_ERP_FAILED
|
1595 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1598 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1601 int status
= atomic_read(&unit
->status
);
1602 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1603 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1606 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1609 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1612 struct zfcp_unit
*unit
;
1613 int status
= atomic_read(&port
->status
);
1615 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1616 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1617 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1618 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1622 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1626 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1627 * @adapter: Adapter where the Access Control Table (ACT) changed
1628 * @id: Id for debug trace
1629 * @ref: Reference for debug trace
1631 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1634 struct zfcp_port
*port
;
1635 unsigned long flags
;
1637 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1640 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1641 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1642 zfcp_erp_port_access_changed(port
, id
, ref
);
1643 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);