4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kthread.h>
15 #define ZFCP_MAX_ERPS 3
17 enum zfcp_erp_act_flags
{
18 ZFCP_STATUS_ERP_TIMEDOUT
= 0x10000000,
19 ZFCP_STATUS_ERP_CLOSE_ONLY
= 0x01000000,
20 ZFCP_STATUS_ERP_DISMISSING
= 0x00100000,
21 ZFCP_STATUS_ERP_DISMISSED
= 0x00200000,
22 ZFCP_STATUS_ERP_LOWMEM
= 0x00400000,
26 ZFCP_ERP_STEP_UNINITIALIZED
= 0x0000,
27 ZFCP_ERP_STEP_FSF_XCONFIG
= 0x0001,
28 ZFCP_ERP_STEP_PHYS_PORT_CLOSING
= 0x0010,
29 ZFCP_ERP_STEP_PORT_CLOSING
= 0x0100,
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_dbf_rec_action("erardy1", act
);
79 wake_up(&adapter
->erp_ready_wq
);
80 zfcp_dbf_rec_thread("erardy2", adapter
->dbf
);
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 (!adapter
->erp_thread
)
219 need
= zfcp_erp_required_act(want
, adapter
, port
, unit
);
223 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
224 act
= zfcp_erp_setup_act(need
, adapter
, port
, unit
);
227 ++adapter
->erp_total_count
;
228 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
229 wake_up(&adapter
->erp_ready_wq
);
230 zfcp_dbf_rec_thread("eracte1", adapter
->dbf
);
233 zfcp_dbf_rec_trigger(id
, ref
, want
, need
, act
, adapter
, port
, unit
);
237 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
238 int clear_mask
, char *id
, void *ref
)
240 zfcp_erp_adapter_block(adapter
, clear_mask
);
241 zfcp_scsi_schedule_rports_block(adapter
);
243 /* ensure propagation of failed status to new devices */
244 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
245 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
248 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
249 adapter
, NULL
, NULL
, id
, ref
);
253 * zfcp_erp_adapter_reopen - Reopen adapter.
254 * @adapter: Adapter to reopen.
255 * @clear: Status flags to clear.
256 * @id: Id for debug trace event.
257 * @ref: Reference for debug trace event.
259 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
264 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
265 write_lock(&adapter
->erp_lock
);
266 _zfcp_erp_adapter_reopen(adapter
, clear
, id
, ref
);
267 write_unlock(&adapter
->erp_lock
);
268 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
272 * zfcp_erp_adapter_shutdown - Shutdown adapter.
273 * @adapter: Adapter to shut down.
274 * @clear: Status flags to clear.
275 * @id: Id for debug trace event.
276 * @ref: Reference for debug trace event.
278 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
281 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
282 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
, ref
);
286 * zfcp_erp_port_shutdown - Shutdown port
287 * @port: Port to shut down.
288 * @clear: Status flags to clear.
289 * @id: Id for debug trace event.
290 * @ref: Reference for debug trace event.
292 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
,
295 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
296 zfcp_erp_port_reopen(port
, clear
| flags
, id
, ref
);
300 * zfcp_erp_unit_shutdown - Shutdown unit
301 * @unit: Unit to shut down.
302 * @clear: Status flags to clear.
303 * @id: Id for debug trace event.
304 * @ref: Reference for debug trace event.
306 void zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear
, char *id
,
309 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
310 zfcp_erp_unit_reopen(unit
, clear
| flags
, id
, ref
);
313 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
315 zfcp_erp_modify_port_status(port
, "erpblk1", NULL
,
316 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
,
320 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
,
321 int clear
, char *id
, void *ref
)
323 zfcp_erp_port_block(port
, clear
);
324 zfcp_scsi_schedule_rport_block(port
);
326 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
329 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
330 port
->adapter
, port
, NULL
, id
, ref
);
334 * zfcp_erp_port_forced_reopen - Forced close of port and open again
335 * @port: Port to force close and to reopen.
336 * @id: Id for debug trace event.
337 * @ref: Reference for debug trace event.
339 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
,
343 struct zfcp_adapter
*adapter
= port
->adapter
;
345 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
346 write_lock(&adapter
->erp_lock
);
347 _zfcp_erp_port_forced_reopen(port
, clear
, id
, ref
);
348 write_unlock(&adapter
->erp_lock
);
349 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
352 static int _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
,
355 zfcp_erp_port_block(port
, clear
);
356 zfcp_scsi_schedule_rport_block(port
);
358 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
359 /* ensure propagation of failed status to new devices */
360 zfcp_erp_port_failed(port
, "erpreo1", NULL
);
364 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
365 port
->adapter
, port
, NULL
, id
, ref
);
369 * zfcp_erp_port_reopen - trigger remote port recovery
370 * @port: port to recover
371 * @clear_mask: flags in port status to be cleared
373 * Returns 0 if recovery has been triggered, < 0 if not.
375 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
, void *ref
)
379 struct zfcp_adapter
*adapter
= port
->adapter
;
381 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
382 write_lock(&adapter
->erp_lock
);
383 retval
= _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
384 write_unlock(&adapter
->erp_lock
);
385 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
390 static void zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
392 zfcp_erp_modify_unit_status(unit
, "erublk1", NULL
,
393 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
397 static void _zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
400 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
402 zfcp_erp_unit_block(unit
, clear
);
404 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
407 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
408 adapter
, unit
->port
, unit
, id
, ref
);
412 * zfcp_erp_unit_reopen - initiate reopen of a unit
413 * @unit: unit to be reopened
414 * @clear_mask: specifies flags in unit status to be cleared
415 * Return: 0 on success, < 0 on error
417 void zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
421 struct zfcp_port
*port
= unit
->port
;
422 struct zfcp_adapter
*adapter
= port
->adapter
;
424 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
425 write_lock(&adapter
->erp_lock
);
426 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
427 write_unlock(&adapter
->erp_lock
);
428 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
431 static int status_change_set(unsigned long mask
, atomic_t
*status
)
433 return (atomic_read(status
) ^ mask
) & mask
;
436 static int status_change_clear(unsigned long mask
, atomic_t
*status
)
438 return atomic_read(status
) & mask
;
441 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
443 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
444 zfcp_dbf_rec_adapter("eraubl1", NULL
, adapter
->dbf
);
445 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
448 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
450 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
451 zfcp_dbf_rec_port("erpubl1", NULL
, port
);
452 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
455 static void zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
457 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
))
458 zfcp_dbf_rec_unit("eruubl1", NULL
, unit
);
459 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
);
462 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
464 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
465 zfcp_dbf_rec_action("erator1", erp_action
);
468 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
470 struct zfcp_adapter
*adapter
= act
->adapter
;
475 spin_lock(&adapter
->req_list_lock
);
476 if (zfcp_reqlist_find_safe(adapter
, act
->fsf_req
) &&
477 act
->fsf_req
->erp_action
== act
) {
478 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
479 ZFCP_STATUS_ERP_TIMEDOUT
)) {
480 act
->fsf_req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
481 zfcp_dbf_rec_action("erscf_1", act
);
482 act
->fsf_req
->erp_action
= NULL
;
484 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
485 zfcp_dbf_rec_action("erscf_2", act
);
486 if (act
->fsf_req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
490 spin_unlock(&adapter
->req_list_lock
);
494 * zfcp_erp_notify - Trigger ERP action.
495 * @erp_action: ERP action to continue.
496 * @set_mask: ERP action status flags to set.
498 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
500 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
503 write_lock_irqsave(&adapter
->erp_lock
, flags
);
504 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
505 erp_action
->status
|= set_mask
;
506 zfcp_erp_action_ready(erp_action
);
508 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
512 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
513 * @data: ERP action (from timer data)
515 void zfcp_erp_timeout_handler(unsigned long data
)
517 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
518 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
521 static void zfcp_erp_memwait_handler(unsigned long data
)
523 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
526 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
528 init_timer(&erp_action
->timer
);
529 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
530 erp_action
->timer
.data
= (unsigned long) erp_action
;
531 erp_action
->timer
.expires
= jiffies
+ HZ
;
532 add_timer(&erp_action
->timer
);
535 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
536 int clear
, char *id
, void *ref
)
538 struct zfcp_port
*port
;
540 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
541 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
544 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
547 struct zfcp_unit
*unit
;
549 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
550 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
553 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
555 switch (act
->action
) {
556 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
557 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
559 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
560 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
562 case ZFCP_ERP_ACTION_REOPEN_PORT
:
563 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
565 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
566 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
571 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
573 switch (act
->action
) {
574 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
575 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
577 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
578 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
580 case ZFCP_ERP_ACTION_REOPEN_PORT
:
581 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
586 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
590 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
591 read_lock(&adapter
->erp_lock
);
592 if (list_empty(&adapter
->erp_ready_head
) &&
593 list_empty(&adapter
->erp_running_head
)) {
594 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
596 wake_up(&adapter
->erp_done_wqh
);
598 read_unlock(&adapter
->erp_lock
);
599 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
602 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
604 struct zfcp_qdio
*qdio
= act
->adapter
->qdio
;
606 if (zfcp_qdio_open(qdio
))
607 return ZFCP_ERP_FAILED
;
608 init_waitqueue_head(&qdio
->req_q_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_dbf_rec_thread_lock("erasfx1", adapter
->dbf
);
644 wait_event(adapter
->erp_ready_wq
,
645 !list_empty(&adapter
->erp_ready_head
));
646 zfcp_dbf_rec_thread_lock("erasfx2", adapter
->dbf
);
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_dbf_rec_thread_lock("erasox1", adapter
->dbf
);
686 wait_event(adapter
->erp_ready_wq
,
687 !list_empty(&adapter
->erp_ready_head
));
688 zfcp_dbf_rec_thread_lock("erasox2", adapter
->dbf
);
689 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
690 return ZFCP_ERP_FAILED
;
692 return ZFCP_ERP_SUCCEEDED
;
695 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
697 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
698 return ZFCP_ERP_FAILED
;
700 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
701 return ZFCP_ERP_FAILED
;
703 atomic_set(&act
->adapter
->stat_miss
, 16);
704 if (zfcp_status_read_refill(act
->adapter
))
705 return ZFCP_ERP_FAILED
;
707 return ZFCP_ERP_SUCCEEDED
;
710 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
712 struct zfcp_adapter
*adapter
= act
->adapter
;
714 /* close queues to ensure that buffers are not accessed by adapter */
715 zfcp_qdio_close(adapter
->qdio
);
716 zfcp_fsf_req_dismiss_all(adapter
);
717 adapter
->fsf_req_seq_no
= 0;
718 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
719 /* all ports and units are closed */
720 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
721 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
723 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
724 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
727 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
729 struct zfcp_adapter
*adapter
= act
->adapter
;
731 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
732 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
733 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
735 return ZFCP_ERP_FAILED
;
738 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
739 zfcp_erp_adapter_strategy_close(act
);
740 return ZFCP_ERP_FAILED
;
743 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
745 return ZFCP_ERP_SUCCEEDED
;
748 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
750 struct zfcp_adapter
*adapter
= act
->adapter
;
752 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
753 zfcp_erp_adapter_strategy_close(act
);
754 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
755 return ZFCP_ERP_EXIT
;
758 if (zfcp_erp_adapter_strategy_open(act
)) {
760 return ZFCP_ERP_FAILED
;
763 return ZFCP_ERP_SUCCEEDED
;
766 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
770 retval
= zfcp_fsf_close_physical_port(act
);
771 if (retval
== -ENOMEM
)
772 return ZFCP_ERP_NOMEM
;
773 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
775 return ZFCP_ERP_FAILED
;
777 return ZFCP_ERP_CONTINUES
;
780 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
782 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
785 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
787 struct zfcp_port
*port
= erp_action
->port
;
788 int status
= atomic_read(&port
->status
);
790 switch (erp_action
->step
) {
791 case ZFCP_ERP_STEP_UNINITIALIZED
:
792 zfcp_erp_port_strategy_clearstati(port
);
793 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
794 (status
& ZFCP_STATUS_COMMON_OPEN
))
795 return zfcp_erp_port_forced_strategy_close(erp_action
);
797 return ZFCP_ERP_FAILED
;
799 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
800 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
801 return ZFCP_ERP_SUCCEEDED
;
803 return ZFCP_ERP_FAILED
;
806 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
810 retval
= zfcp_fsf_close_port(erp_action
);
811 if (retval
== -ENOMEM
)
812 return ZFCP_ERP_NOMEM
;
813 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
815 return ZFCP_ERP_FAILED
;
816 return ZFCP_ERP_CONTINUES
;
819 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
823 retval
= zfcp_fsf_open_port(erp_action
);
824 if (retval
== -ENOMEM
)
825 return ZFCP_ERP_NOMEM
;
826 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
828 return ZFCP_ERP_FAILED
;
829 return ZFCP_ERP_CONTINUES
;
832 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
834 struct zfcp_adapter
*adapter
= act
->adapter
;
835 struct zfcp_port
*port
= act
->port
;
837 if (port
->wwpn
!= adapter
->peer_wwpn
) {
838 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
839 return ZFCP_ERP_FAILED
;
841 port
->d_id
= adapter
->peer_d_id
;
842 return zfcp_erp_port_strategy_open_port(act
);
845 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
847 struct zfcp_adapter
*adapter
= act
->adapter
;
848 struct zfcp_port
*port
= act
->port
;
849 int p_status
= atomic_read(&port
->status
);
852 case ZFCP_ERP_STEP_UNINITIALIZED
:
853 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
854 case ZFCP_ERP_STEP_PORT_CLOSING
:
855 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
856 return zfcp_erp_open_ptp_port(act
);
859 if (!queue_work(adapter
->work_queue
,
862 return ZFCP_ERP_EXIT
;
864 return zfcp_erp_port_strategy_open_port(act
);
866 case ZFCP_ERP_STEP_PORT_OPENING
:
867 /* D_ID might have changed during open */
868 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
870 return ZFCP_ERP_SUCCEEDED
;
872 act
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
873 return ZFCP_ERP_CONTINUES
;
876 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
878 _zfcp_erp_port_reopen(port
, 0, "erpsoc1", NULL
);
879 return ZFCP_ERP_EXIT
;
881 /* fall through otherwise */
883 return ZFCP_ERP_FAILED
;
886 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
888 struct zfcp_port
*port
= erp_action
->port
;
890 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
)
891 goto close_init_done
;
893 switch (erp_action
->step
) {
894 case ZFCP_ERP_STEP_UNINITIALIZED
:
895 zfcp_erp_port_strategy_clearstati(port
);
896 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_OPEN
)
897 return zfcp_erp_port_strategy_close(erp_action
);
900 case ZFCP_ERP_STEP_PORT_CLOSING
:
901 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_OPEN
)
902 return ZFCP_ERP_FAILED
;
907 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
908 return ZFCP_ERP_EXIT
;
910 return zfcp_erp_port_strategy_open_common(erp_action
);
913 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
915 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
916 ZFCP_STATUS_UNIT_SHARED
|
917 ZFCP_STATUS_UNIT_READONLY
,
921 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
923 int retval
= zfcp_fsf_close_unit(erp_action
);
924 if (retval
== -ENOMEM
)
925 return ZFCP_ERP_NOMEM
;
926 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
928 return ZFCP_ERP_FAILED
;
929 return ZFCP_ERP_CONTINUES
;
932 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
934 int retval
= zfcp_fsf_open_unit(erp_action
);
935 if (retval
== -ENOMEM
)
936 return ZFCP_ERP_NOMEM
;
937 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
939 return ZFCP_ERP_FAILED
;
940 return ZFCP_ERP_CONTINUES
;
943 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
945 struct zfcp_unit
*unit
= erp_action
->unit
;
947 switch (erp_action
->step
) {
948 case ZFCP_ERP_STEP_UNINITIALIZED
:
949 zfcp_erp_unit_strategy_clearstati(unit
);
950 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
951 return zfcp_erp_unit_strategy_close(erp_action
);
952 /* already closed, fall through */
953 case ZFCP_ERP_STEP_UNIT_CLOSING
:
954 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
955 return ZFCP_ERP_FAILED
;
956 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
957 return ZFCP_ERP_EXIT
;
958 return zfcp_erp_unit_strategy_open(erp_action
);
960 case ZFCP_ERP_STEP_UNIT_OPENING
:
961 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
962 return ZFCP_ERP_SUCCEEDED
;
964 return ZFCP_ERP_FAILED
;
967 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
970 case ZFCP_ERP_SUCCEEDED
:
971 atomic_set(&unit
->erp_counter
, 0);
972 zfcp_erp_unit_unblock(unit
);
974 case ZFCP_ERP_FAILED
:
975 atomic_inc(&unit
->erp_counter
);
976 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
) {
977 dev_err(&unit
->port
->adapter
->ccw_device
->dev
,
978 "ERP failed for unit 0x%016Lx on "
980 (unsigned long long)unit
->fcp_lun
,
981 (unsigned long long)unit
->port
->wwpn
);
982 zfcp_erp_unit_failed(unit
, "erusck1", NULL
);
987 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
988 zfcp_erp_unit_block(unit
, 0);
989 result
= ZFCP_ERP_EXIT
;
994 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
997 case ZFCP_ERP_SUCCEEDED
:
998 atomic_set(&port
->erp_counter
, 0);
999 zfcp_erp_port_unblock(port
);
1002 case ZFCP_ERP_FAILED
:
1003 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1004 zfcp_erp_port_block(port
, 0);
1005 result
= ZFCP_ERP_EXIT
;
1007 atomic_inc(&port
->erp_counter
);
1008 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1009 dev_err(&port
->adapter
->ccw_device
->dev
,
1010 "ERP failed for remote port 0x%016Lx\n",
1011 (unsigned long long)port
->wwpn
);
1012 zfcp_erp_port_failed(port
, "erpsck1", NULL
);
1017 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1018 zfcp_erp_port_block(port
, 0);
1019 result
= ZFCP_ERP_EXIT
;
1024 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1028 case ZFCP_ERP_SUCCEEDED
:
1029 atomic_set(&adapter
->erp_counter
, 0);
1030 zfcp_erp_adapter_unblock(adapter
);
1033 case ZFCP_ERP_FAILED
:
1034 atomic_inc(&adapter
->erp_counter
);
1035 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1036 dev_err(&adapter
->ccw_device
->dev
,
1037 "ERP cannot recover an error "
1038 "on the FCP device\n");
1039 zfcp_erp_adapter_failed(adapter
, "erasck1", NULL
);
1044 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1045 zfcp_erp_adapter_block(adapter
, 0);
1046 result
= ZFCP_ERP_EXIT
;
1051 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1054 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1055 struct zfcp_port
*port
= erp_action
->port
;
1056 struct zfcp_unit
*unit
= erp_action
->unit
;
1058 switch (erp_action
->action
) {
1060 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1061 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1064 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1065 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1066 result
= zfcp_erp_strategy_check_port(port
, result
);
1069 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1070 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1076 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1078 int status
= atomic_read(target_status
);
1080 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1081 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1082 return 1; /* take it online */
1084 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1085 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1086 return 1; /* take it offline */
1091 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1093 int action
= act
->action
;
1094 struct zfcp_adapter
*adapter
= act
->adapter
;
1095 struct zfcp_port
*port
= act
->port
;
1096 struct zfcp_unit
*unit
= act
->unit
;
1097 u32 erp_status
= act
->status
;
1100 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1101 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1102 _zfcp_erp_adapter_reopen(adapter
,
1103 ZFCP_STATUS_COMMON_ERP_FAILED
,
1105 return ZFCP_ERP_EXIT
;
1109 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1110 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1111 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1112 _zfcp_erp_port_reopen(port
,
1113 ZFCP_STATUS_COMMON_ERP_FAILED
,
1115 return ZFCP_ERP_EXIT
;
1119 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1120 if (zfcp_erp_strat_change_det(&unit
->status
, erp_status
)) {
1121 _zfcp_erp_unit_reopen(unit
,
1122 ZFCP_STATUS_COMMON_ERP_FAILED
,
1124 return ZFCP_ERP_EXIT
;
1131 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1133 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1135 adapter
->erp_total_count
--;
1136 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1137 adapter
->erp_low_mem_count
--;
1138 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1141 list_del(&erp_action
->list
);
1142 zfcp_dbf_rec_action("eractd1", erp_action
);
1144 switch (erp_action
->action
) {
1145 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1146 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1147 &erp_action
->unit
->status
);
1150 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1151 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1152 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1153 &erp_action
->port
->status
);
1156 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1157 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1158 &erp_action
->adapter
->status
);
1163 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1165 struct zfcp_adapter
*adapter
= act
->adapter
;
1166 struct zfcp_port
*port
= act
->port
;
1167 struct zfcp_unit
*unit
= act
->unit
;
1169 switch (act
->action
) {
1170 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1171 if ((result
== ZFCP_ERP_SUCCEEDED
) && !unit
->device
) {
1172 zfcp_unit_get(unit
);
1173 if (scsi_queue_work(unit
->port
->adapter
->scsi_host
,
1174 &unit
->scsi_work
) <= 0)
1175 zfcp_unit_put(unit
);
1177 zfcp_unit_put(unit
);
1180 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1181 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1182 if (result
== ZFCP_ERP_SUCCEEDED
)
1183 zfcp_scsi_schedule_rport_register(port
);
1184 zfcp_port_put(port
);
1187 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1188 if (result
== ZFCP_ERP_SUCCEEDED
) {
1189 register_service_level(&adapter
->service_level
);
1190 schedule_work(&adapter
->scan_work
);
1192 unregister_service_level(&adapter
->service_level
);
1193 zfcp_adapter_put(adapter
);
1198 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1200 switch (erp_action
->action
) {
1201 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1202 return zfcp_erp_adapter_strategy(erp_action
);
1203 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1204 return zfcp_erp_port_forced_strategy(erp_action
);
1205 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1206 return zfcp_erp_port_strategy(erp_action
);
1207 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1208 return zfcp_erp_unit_strategy(erp_action
);
1210 return ZFCP_ERP_FAILED
;
1213 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1216 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1217 unsigned long flags
;
1219 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1220 write_lock(&adapter
->erp_lock
);
1222 zfcp_erp_strategy_check_fsfreq(erp_action
);
1224 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1225 zfcp_erp_action_dequeue(erp_action
);
1226 retval
= ZFCP_ERP_DISMISSED
;
1230 zfcp_erp_action_to_running(erp_action
);
1232 /* no lock to allow for blocking operations */
1233 write_unlock(&adapter
->erp_lock
);
1234 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1235 retval
= zfcp_erp_strategy_do_action(erp_action
);
1236 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1237 write_lock(&adapter
->erp_lock
);
1239 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1240 retval
= ZFCP_ERP_CONTINUES
;
1243 case ZFCP_ERP_NOMEM
:
1244 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1245 ++adapter
->erp_low_mem_count
;
1246 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1248 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1249 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1251 zfcp_erp_strategy_memwait(erp_action
);
1252 retval
= ZFCP_ERP_CONTINUES
;
1256 case ZFCP_ERP_CONTINUES
:
1257 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1258 --adapter
->erp_low_mem_count
;
1259 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1264 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1265 zfcp_erp_action_dequeue(erp_action
);
1266 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1267 if (retval
== ZFCP_ERP_EXIT
)
1269 if (retval
== ZFCP_ERP_SUCCEEDED
)
1270 zfcp_erp_strategy_followup_success(erp_action
);
1271 if (retval
== ZFCP_ERP_FAILED
)
1272 zfcp_erp_strategy_followup_failed(erp_action
);
1275 write_unlock(&adapter
->erp_lock
);
1276 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1278 if (retval
!= ZFCP_ERP_CONTINUES
)
1279 zfcp_erp_action_cleanup(erp_action
, retval
);
1284 static int zfcp_erp_thread(void *data
)
1286 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1287 struct list_head
*next
;
1288 struct zfcp_erp_action
*act
;
1289 unsigned long flags
;
1292 zfcp_dbf_rec_thread_lock("erthrd1", adapter
->dbf
);
1293 wait_event_interruptible(adapter
->erp_ready_wq
,
1294 !list_empty(&adapter
->erp_ready_head
) ||
1295 kthread_should_stop());
1296 zfcp_dbf_rec_thread_lock("erthrd2", adapter
->dbf
);
1298 if (kthread_should_stop())
1301 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1302 next
= adapter
->erp_ready_head
.next
;
1303 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1305 if (next
!= &adapter
->erp_ready_head
) {
1306 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1308 /* there is more to come after dismission, no notify */
1309 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1310 zfcp_erp_wakeup(adapter
);
1318 * zfcp_erp_thread_setup - Start ERP thread for adapter
1319 * @adapter: Adapter to start the ERP thread for
1321 * Returns 0 on success or error code from kernel_thread()
1323 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1325 struct task_struct
*thread
;
1327 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1328 dev_name(&adapter
->ccw_device
->dev
));
1329 if (IS_ERR(thread
)) {
1330 dev_err(&adapter
->ccw_device
->dev
,
1331 "Creating an ERP thread for the FCP device failed.\n");
1332 return PTR_ERR(thread
);
1335 adapter
->erp_thread
= thread
;
1340 * zfcp_erp_thread_kill - Stop ERP thread.
1341 * @adapter: Adapter where the ERP thread should be stopped.
1343 * The caller of this routine ensures that the specified adapter has
1344 * been shut down and that this operation has been completed. Thus,
1345 * there are no pending erp_actions which would need to be handled
1348 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1350 kthread_stop(adapter
->erp_thread
);
1351 adapter
->erp_thread
= NULL
;
1355 * zfcp_erp_adapter_failed - Set adapter status to failed.
1356 * @adapter: Failed adapter.
1357 * @id: Event id for debug trace.
1358 * @ref: Reference for debug trace.
1360 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1362 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1363 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1367 * zfcp_erp_port_failed - Set port status to failed.
1368 * @port: Failed port.
1369 * @id: Event id for debug trace.
1370 * @ref: Reference for debug trace.
1372 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1374 zfcp_erp_modify_port_status(port
, id
, ref
,
1375 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1379 * zfcp_erp_unit_failed - Set unit status to failed.
1380 * @unit: Failed unit.
1381 * @id: Event id for debug trace.
1382 * @ref: Reference for debug trace.
1384 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1386 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1387 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1391 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1392 * @adapter: adapter for which to wait for completion of its error recovery
1394 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1396 wait_event(adapter
->erp_done_wqh
,
1397 !(atomic_read(&adapter
->status
) &
1398 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1402 * zfcp_erp_modify_adapter_status - change adapter status bits
1403 * @adapter: adapter to change the status
1404 * @id: id for the debug trace
1405 * @ref: reference for the debug trace
1406 * @mask: status bits to change
1407 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1409 * Changes in common status bits are propagated to attached ports and units.
1411 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1412 void *ref
, u32 mask
, int set_or_clear
)
1414 struct zfcp_port
*port
;
1415 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1417 if (set_or_clear
== ZFCP_SET
) {
1418 if (status_change_set(mask
, &adapter
->status
))
1419 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1420 atomic_set_mask(mask
, &adapter
->status
);
1422 if (status_change_clear(mask
, &adapter
->status
))
1423 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1424 atomic_clear_mask(mask
, &adapter
->status
);
1425 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1426 atomic_set(&adapter
->erp_counter
, 0);
1430 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1431 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1436 * zfcp_erp_modify_port_status - change port status bits
1437 * @port: port to change the status bits
1438 * @id: id for the debug trace
1439 * @ref: reference for the debug trace
1440 * @mask: status bits to change
1441 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1443 * Changes in common status bits are propagated to attached units.
1445 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1446 u32 mask
, int set_or_clear
)
1448 struct zfcp_unit
*unit
;
1449 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1451 if (set_or_clear
== ZFCP_SET
) {
1452 if (status_change_set(mask
, &port
->status
))
1453 zfcp_dbf_rec_port(id
, ref
, port
);
1454 atomic_set_mask(mask
, &port
->status
);
1456 if (status_change_clear(mask
, &port
->status
))
1457 zfcp_dbf_rec_port(id
, ref
, port
);
1458 atomic_clear_mask(mask
, &port
->status
);
1459 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1460 atomic_set(&port
->erp_counter
, 0);
1464 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1465 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1470 * zfcp_erp_modify_unit_status - change unit status bits
1471 * @unit: unit to change the status bits
1472 * @id: id for the debug trace
1473 * @ref: reference for the debug trace
1474 * @mask: status bits to change
1475 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1477 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1478 u32 mask
, int set_or_clear
)
1480 if (set_or_clear
== ZFCP_SET
) {
1481 if (status_change_set(mask
, &unit
->status
))
1482 zfcp_dbf_rec_unit(id
, ref
, unit
);
1483 atomic_set_mask(mask
, &unit
->status
);
1485 if (status_change_clear(mask
, &unit
->status
))
1486 zfcp_dbf_rec_unit(id
, ref
, unit
);
1487 atomic_clear_mask(mask
, &unit
->status
);
1488 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1489 atomic_set(&unit
->erp_counter
, 0);
1495 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1496 * @port: The "boxed" port.
1497 * @id: The debug trace id.
1498 * @id: Reference for the debug trace.
1500 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1502 unsigned long flags
;
1504 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1505 zfcp_erp_modify_port_status(port
, id
, ref
,
1506 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1507 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1508 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1512 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1513 * @port: The "boxed" unit.
1514 * @id: The debug trace id.
1515 * @id: Reference for the debug trace.
1517 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1519 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1520 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1521 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1525 * zfcp_erp_port_access_denied - Adapter denied access to port.
1526 * @port: port where access has been denied
1527 * @id: id for debug trace
1528 * @ref: reference for debug trace
1530 * Since the adapter has denied access, stop using the port and the
1533 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1535 unsigned long flags
;
1537 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1538 zfcp_erp_modify_port_status(port
, id
, ref
,
1539 ZFCP_STATUS_COMMON_ERP_FAILED
|
1540 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1541 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);
1545 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1546 * @unit: unit where access has been denied
1547 * @id: id for debug trace
1548 * @ref: reference for debug trace
1550 * Since the adapter has denied access, stop using the unit.
1552 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1554 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1555 ZFCP_STATUS_COMMON_ERP_FAILED
|
1556 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1559 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1562 int status
= atomic_read(&unit
->status
);
1563 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1564 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1567 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1570 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1573 struct zfcp_unit
*unit
;
1574 int status
= atomic_read(&port
->status
);
1576 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1577 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1578 list_for_each_entry(unit
, &port
->unit_list_head
, list
)
1579 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1583 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1587 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1588 * @adapter: Adapter where the Access Control Table (ACT) changed
1589 * @id: Id for debug trace
1590 * @ref: Reference for debug trace
1592 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1595 struct zfcp_port
*port
;
1596 unsigned long flags
;
1598 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1601 read_lock_irqsave(&zfcp_data
.config_lock
, flags
);
1602 list_for_each_entry(port
, &adapter
->port_list_head
, list
)
1603 zfcp_erp_port_access_changed(port
, id
, ref
);
1604 read_unlock_irqrestore(&zfcp_data
.config_lock
, flags
);