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 read_lock(&port
->unit_list_lock
);
104 list_for_each_entry(unit
, &port
->unit_list
, list
)
105 zfcp_erp_action_dismiss_unit(unit
);
106 read_unlock(&port
->unit_list_lock
);
110 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
112 struct zfcp_port
*port
;
114 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
115 zfcp_erp_action_dismiss(&adapter
->erp_action
);
117 read_lock(&adapter
->port_list_lock
);
118 list_for_each_entry(port
, &adapter
->port_list
, list
)
119 zfcp_erp_action_dismiss_port(port
);
120 read_unlock(&adapter
->port_list_lock
);
124 static int zfcp_erp_required_act(int want
, struct zfcp_adapter
*adapter
,
125 struct zfcp_port
*port
,
126 struct zfcp_unit
*unit
)
129 int u_status
, p_status
, a_status
;
132 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
133 u_status
= atomic_read(&unit
->status
);
134 if (u_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
136 p_status
= atomic_read(&port
->status
);
137 if (!(p_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
138 p_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
140 if (!(p_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
141 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
143 case ZFCP_ERP_ACTION_REOPEN_PORT
:
144 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
145 p_status
= atomic_read(&port
->status
);
146 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
148 a_status
= atomic_read(&adapter
->status
);
149 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
150 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
152 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
153 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
155 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
156 a_status
= atomic_read(&adapter
->status
);
157 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
159 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) &&
160 !(a_status
& ZFCP_STATUS_COMMON_OPEN
))
161 return 0; /* shutdown requested for closed adapter */
167 static struct zfcp_erp_action
*zfcp_erp_setup_act(int need
,
168 struct zfcp_adapter
*adapter
,
169 struct zfcp_port
*port
,
170 struct zfcp_unit
*unit
)
172 struct zfcp_erp_action
*erp_action
;
176 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
177 if (!get_device(&unit
->sysfs_device
))
179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &unit
->status
);
180 erp_action
= &unit
->erp_action
;
181 if (!(atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
182 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
185 case ZFCP_ERP_ACTION_REOPEN_PORT
:
186 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
187 if (!get_device(&port
->sysfs_device
))
189 zfcp_erp_action_dismiss_port(port
);
190 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
191 erp_action
= &port
->erp_action
;
192 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
193 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
196 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
197 kref_get(&adapter
->ref
);
198 zfcp_erp_action_dismiss_adapter(adapter
);
199 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
200 erp_action
= &adapter
->erp_action
;
201 if (!(atomic_read(&adapter
->status
) &
202 ZFCP_STATUS_COMMON_RUNNING
))
203 status
= ZFCP_STATUS_ERP_CLOSE_ONLY
;
210 memset(erp_action
, 0, sizeof(struct zfcp_erp_action
));
211 erp_action
->adapter
= adapter
;
212 erp_action
->port
= port
;
213 erp_action
->unit
= unit
;
214 erp_action
->action
= need
;
215 erp_action
->status
= status
;
220 static int zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
221 struct zfcp_port
*port
,
222 struct zfcp_unit
*unit
, char *id
, void *ref
)
224 int retval
= 1, need
;
225 struct zfcp_erp_action
*act
= NULL
;
227 if (!adapter
->erp_thread
)
230 need
= zfcp_erp_required_act(want
, adapter
, port
, unit
);
234 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
235 act
= zfcp_erp_setup_act(need
, adapter
, port
, unit
);
238 ++adapter
->erp_total_count
;
239 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
240 wake_up(&adapter
->erp_ready_wq
);
241 zfcp_dbf_rec_thread("eracte1", adapter
->dbf
);
244 zfcp_dbf_rec_trigger(id
, ref
, want
, need
, act
, adapter
, port
, unit
);
248 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
249 int clear_mask
, char *id
, void *ref
)
251 zfcp_erp_adapter_block(adapter
, clear_mask
);
252 zfcp_scsi_schedule_rports_block(adapter
);
254 /* ensure propagation of failed status to new devices */
255 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
256 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
259 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
260 adapter
, NULL
, NULL
, id
, ref
);
264 * zfcp_erp_adapter_reopen - Reopen adapter.
265 * @adapter: Adapter to reopen.
266 * @clear: Status flags to clear.
267 * @id: Id for debug trace event.
268 * @ref: Reference for debug trace event.
270 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
275 zfcp_erp_adapter_block(adapter
, clear
);
276 zfcp_scsi_schedule_rports_block(adapter
);
278 write_lock_irqsave(&adapter
->erp_lock
, flags
);
279 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
280 zfcp_erp_adapter_failed(adapter
, "erareo1", NULL
);
282 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
, adapter
,
283 NULL
, NULL
, id
, ref
);
284 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
288 * zfcp_erp_adapter_shutdown - Shutdown adapter.
289 * @adapter: Adapter 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_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
297 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
298 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
, ref
);
302 * zfcp_erp_port_shutdown - Shutdown port
303 * @port: Port 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_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
,
311 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
312 zfcp_erp_port_reopen(port
, clear
| flags
, id
, ref
);
316 * zfcp_erp_unit_shutdown - Shutdown unit
317 * @unit: Unit to shut down.
318 * @clear: Status flags to clear.
319 * @id: Id for debug trace event.
320 * @ref: Reference for debug trace event.
322 void zfcp_erp_unit_shutdown(struct zfcp_unit
*unit
, int clear
, char *id
,
325 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
326 zfcp_erp_unit_reopen(unit
, clear
| flags
, id
, ref
);
329 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
331 zfcp_erp_modify_port_status(port
, "erpblk1", NULL
,
332 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
,
336 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
,
337 int clear
, char *id
, void *ref
)
339 zfcp_erp_port_block(port
, clear
);
340 zfcp_scsi_schedule_rport_block(port
);
342 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
345 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
346 port
->adapter
, port
, NULL
, id
, ref
);
350 * zfcp_erp_port_forced_reopen - Forced close of port and open again
351 * @port: Port to force close and to reopen.
352 * @id: Id for debug trace event.
353 * @ref: Reference for debug trace event.
355 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
,
359 struct zfcp_adapter
*adapter
= port
->adapter
;
361 write_lock_irqsave(&adapter
->erp_lock
, flags
);
362 _zfcp_erp_port_forced_reopen(port
, clear
, id
, ref
);
363 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
366 static int _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
,
369 zfcp_erp_port_block(port
, clear
);
370 zfcp_scsi_schedule_rport_block(port
);
372 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
373 /* ensure propagation of failed status to new devices */
374 zfcp_erp_port_failed(port
, "erpreo1", NULL
);
378 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
379 port
->adapter
, port
, NULL
, id
, ref
);
383 * zfcp_erp_port_reopen - trigger remote port recovery
384 * @port: port to recover
385 * @clear_mask: flags in port status to be cleared
387 * Returns 0 if recovery has been triggered, < 0 if not.
389 int zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
, void *ref
)
393 struct zfcp_adapter
*adapter
= port
->adapter
;
395 write_lock_irqsave(&adapter
->erp_lock
, flags
);
396 retval
= _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
397 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
402 static void zfcp_erp_unit_block(struct zfcp_unit
*unit
, int clear_mask
)
404 zfcp_erp_modify_unit_status(unit
, "erublk1", NULL
,
405 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
,
409 static void _zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
412 struct zfcp_adapter
*adapter
= unit
->port
->adapter
;
414 zfcp_erp_unit_block(unit
, clear
);
416 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
419 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT
,
420 adapter
, unit
->port
, unit
, id
, ref
);
424 * zfcp_erp_unit_reopen - initiate reopen of a unit
425 * @unit: unit to be reopened
426 * @clear_mask: specifies flags in unit status to be cleared
427 * Return: 0 on success, < 0 on error
429 void zfcp_erp_unit_reopen(struct zfcp_unit
*unit
, int clear
, char *id
,
433 struct zfcp_port
*port
= unit
->port
;
434 struct zfcp_adapter
*adapter
= port
->adapter
;
436 write_lock_irqsave(&adapter
->erp_lock
, flags
);
437 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
438 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
441 static int status_change_set(unsigned long mask
, atomic_t
*status
)
443 return (atomic_read(status
) ^ mask
) & mask
;
446 static int status_change_clear(unsigned long mask
, atomic_t
*status
)
448 return atomic_read(status
) & mask
;
451 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
453 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
))
454 zfcp_dbf_rec_adapter("eraubl1", NULL
, adapter
->dbf
);
455 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
458 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
460 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
))
461 zfcp_dbf_rec_port("erpubl1", NULL
, port
);
462 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
465 static void zfcp_erp_unit_unblock(struct zfcp_unit
*unit
)
467 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
))
468 zfcp_dbf_rec_unit("eruubl1", NULL
, unit
);
469 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED
, &unit
->status
);
472 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
474 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
475 zfcp_dbf_rec_action("erator1", erp_action
);
478 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
480 struct zfcp_adapter
*adapter
= act
->adapter
;
485 spin_lock(&adapter
->req_list_lock
);
486 if (zfcp_reqlist_find_safe(adapter
, act
->fsf_req
) &&
487 act
->fsf_req
->erp_action
== act
) {
488 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
489 ZFCP_STATUS_ERP_TIMEDOUT
)) {
490 act
->fsf_req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
491 zfcp_dbf_rec_action("erscf_1", act
);
492 act
->fsf_req
->erp_action
= NULL
;
494 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
495 zfcp_dbf_rec_action("erscf_2", act
);
496 if (act
->fsf_req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
500 spin_unlock(&adapter
->req_list_lock
);
504 * zfcp_erp_notify - Trigger ERP action.
505 * @erp_action: ERP action to continue.
506 * @set_mask: ERP action status flags to set.
508 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
510 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
513 write_lock_irqsave(&adapter
->erp_lock
, flags
);
514 if (zfcp_erp_action_exists(erp_action
) == ZFCP_ERP_ACTION_RUNNING
) {
515 erp_action
->status
|= set_mask
;
516 zfcp_erp_action_ready(erp_action
);
518 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
522 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
523 * @data: ERP action (from timer data)
525 void zfcp_erp_timeout_handler(unsigned long data
)
527 struct zfcp_erp_action
*act
= (struct zfcp_erp_action
*) data
;
528 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
531 static void zfcp_erp_memwait_handler(unsigned long data
)
533 zfcp_erp_notify((struct zfcp_erp_action
*)data
, 0);
536 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
538 init_timer(&erp_action
->timer
);
539 erp_action
->timer
.function
= zfcp_erp_memwait_handler
;
540 erp_action
->timer
.data
= (unsigned long) erp_action
;
541 erp_action
->timer
.expires
= jiffies
+ HZ
;
542 add_timer(&erp_action
->timer
);
545 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
546 int clear
, char *id
, void *ref
)
548 struct zfcp_port
*port
;
550 read_lock(&adapter
->port_list_lock
);
551 list_for_each_entry(port
, &adapter
->port_list
, list
)
552 _zfcp_erp_port_reopen(port
, clear
, id
, ref
);
553 read_unlock(&adapter
->port_list_lock
);
556 static void _zfcp_erp_unit_reopen_all(struct zfcp_port
*port
, int clear
,
559 struct zfcp_unit
*unit
;
561 read_lock(&port
->unit_list_lock
);
562 list_for_each_entry(unit
, &port
->unit_list
, list
)
563 _zfcp_erp_unit_reopen(unit
, clear
, id
, ref
);
564 read_unlock(&port
->unit_list_lock
);
567 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
569 switch (act
->action
) {
570 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
571 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1", NULL
);
573 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
574 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2", NULL
);
576 case ZFCP_ERP_ACTION_REOPEN_PORT
:
577 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3", NULL
);
579 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
580 _zfcp_erp_unit_reopen(act
->unit
, 0, "ersff_4", NULL
);
585 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
587 switch (act
->action
) {
588 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
589 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1", NULL
);
591 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
592 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2", NULL
);
594 case ZFCP_ERP_ACTION_REOPEN_PORT
:
595 _zfcp_erp_unit_reopen_all(act
->port
, 0, "ersfs_3", NULL
);
600 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
604 read_lock_irqsave(&adapter
->erp_lock
, flags
);
605 if (list_empty(&adapter
->erp_ready_head
) &&
606 list_empty(&adapter
->erp_running_head
)) {
607 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
609 wake_up(&adapter
->erp_done_wqh
);
611 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
614 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action
*act
)
616 struct zfcp_qdio
*qdio
= act
->adapter
->qdio
;
618 if (zfcp_qdio_open(qdio
))
619 return ZFCP_ERP_FAILED
;
620 init_waitqueue_head(&qdio
->req_q_wq
);
621 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP
, &act
->adapter
->status
);
622 return ZFCP_ERP_SUCCEEDED
;
625 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
627 struct zfcp_port
*port
;
628 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
630 if (IS_ERR(port
)) /* error or port already attached */
632 _zfcp_erp_port_reopen(port
, 0, "ereptp1", NULL
);
635 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
639 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
641 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
643 for (retries
= 7; retries
; retries
--) {
644 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
646 write_lock_irq(&adapter
->erp_lock
);
647 zfcp_erp_action_to_running(erp_action
);
648 write_unlock_irq(&adapter
->erp_lock
);
649 if (zfcp_fsf_exchange_config_data(erp_action
)) {
650 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
652 return ZFCP_ERP_FAILED
;
655 zfcp_dbf_rec_thread_lock("erasfx1", adapter
->dbf
);
656 wait_event(adapter
->erp_ready_wq
,
657 !list_empty(&adapter
->erp_ready_head
));
658 zfcp_dbf_rec_thread_lock("erasfx2", adapter
->dbf
);
659 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
662 if (!(atomic_read(&adapter
->status
) &
663 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
670 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
673 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
674 return ZFCP_ERP_FAILED
;
676 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
677 zfcp_erp_enqueue_ptp_port(adapter
);
679 return ZFCP_ERP_SUCCEEDED
;
682 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
685 struct zfcp_adapter
*adapter
= act
->adapter
;
687 write_lock_irq(&adapter
->erp_lock
);
688 zfcp_erp_action_to_running(act
);
689 write_unlock_irq(&adapter
->erp_lock
);
691 ret
= zfcp_fsf_exchange_port_data(act
);
692 if (ret
== -EOPNOTSUPP
)
693 return ZFCP_ERP_SUCCEEDED
;
695 return ZFCP_ERP_FAILED
;
697 zfcp_dbf_rec_thread_lock("erasox1", adapter
->dbf
);
698 wait_event(adapter
->erp_ready_wq
,
699 !list_empty(&adapter
->erp_ready_head
));
700 zfcp_dbf_rec_thread_lock("erasox2", adapter
->dbf
);
701 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
702 return ZFCP_ERP_FAILED
;
704 return ZFCP_ERP_SUCCEEDED
;
707 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
709 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
710 return ZFCP_ERP_FAILED
;
712 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
713 return ZFCP_ERP_FAILED
;
715 atomic_set(&act
->adapter
->stat_miss
, 16);
716 if (zfcp_status_read_refill(act
->adapter
))
717 return ZFCP_ERP_FAILED
;
719 return ZFCP_ERP_SUCCEEDED
;
722 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
724 struct zfcp_adapter
*adapter
= act
->adapter
;
726 /* close queues to ensure that buffers are not accessed by adapter */
727 zfcp_qdio_close(adapter
->qdio
);
728 zfcp_fsf_req_dismiss_all(adapter
);
729 adapter
->fsf_req_seq_no
= 0;
730 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
731 /* all ports and units are closed */
732 zfcp_erp_modify_adapter_status(adapter
, "erascl1", NULL
,
733 ZFCP_STATUS_COMMON_OPEN
, ZFCP_CLEAR
);
735 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
736 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
739 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
741 struct zfcp_adapter
*adapter
= act
->adapter
;
743 if (zfcp_erp_adapter_strategy_open_qdio(act
)) {
744 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
745 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
747 return ZFCP_ERP_FAILED
;
750 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
751 zfcp_erp_adapter_strategy_close(act
);
752 return ZFCP_ERP_FAILED
;
755 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
757 return ZFCP_ERP_SUCCEEDED
;
760 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
762 struct zfcp_adapter
*adapter
= act
->adapter
;
764 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
765 zfcp_erp_adapter_strategy_close(act
);
766 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
767 return ZFCP_ERP_EXIT
;
770 if (zfcp_erp_adapter_strategy_open(act
)) {
772 return ZFCP_ERP_FAILED
;
775 return ZFCP_ERP_SUCCEEDED
;
778 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
782 retval
= zfcp_fsf_close_physical_port(act
);
783 if (retval
== -ENOMEM
)
784 return ZFCP_ERP_NOMEM
;
785 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
787 return ZFCP_ERP_FAILED
;
789 return ZFCP_ERP_CONTINUES
;
792 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port
*port
)
794 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
, &port
->status
);
797 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
799 struct zfcp_port
*port
= erp_action
->port
;
800 int status
= atomic_read(&port
->status
);
802 switch (erp_action
->step
) {
803 case ZFCP_ERP_STEP_UNINITIALIZED
:
804 zfcp_erp_port_strategy_clearstati(port
);
805 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
806 (status
& ZFCP_STATUS_COMMON_OPEN
))
807 return zfcp_erp_port_forced_strategy_close(erp_action
);
809 return ZFCP_ERP_FAILED
;
811 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
812 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
813 return ZFCP_ERP_SUCCEEDED
;
815 return ZFCP_ERP_FAILED
;
818 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
822 retval
= zfcp_fsf_close_port(erp_action
);
823 if (retval
== -ENOMEM
)
824 return ZFCP_ERP_NOMEM
;
825 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
827 return ZFCP_ERP_FAILED
;
828 return ZFCP_ERP_CONTINUES
;
831 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
835 retval
= zfcp_fsf_open_port(erp_action
);
836 if (retval
== -ENOMEM
)
837 return ZFCP_ERP_NOMEM
;
838 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
840 return ZFCP_ERP_FAILED
;
841 return ZFCP_ERP_CONTINUES
;
844 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
846 struct zfcp_adapter
*adapter
= act
->adapter
;
847 struct zfcp_port
*port
= act
->port
;
849 if (port
->wwpn
!= adapter
->peer_wwpn
) {
850 zfcp_erp_port_failed(port
, "eroptp1", NULL
);
851 return ZFCP_ERP_FAILED
;
853 port
->d_id
= adapter
->peer_d_id
;
854 return zfcp_erp_port_strategy_open_port(act
);
857 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
859 struct zfcp_adapter
*adapter
= act
->adapter
;
860 struct zfcp_port
*port
= act
->port
;
861 int p_status
= atomic_read(&port
->status
);
864 case ZFCP_ERP_STEP_UNINITIALIZED
:
865 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
866 case ZFCP_ERP_STEP_PORT_CLOSING
:
867 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
868 return zfcp_erp_open_ptp_port(act
);
870 zfcp_fc_trigger_did_lookup(port
);
871 return ZFCP_ERP_EXIT
;
873 return zfcp_erp_port_strategy_open_port(act
);
875 case ZFCP_ERP_STEP_PORT_OPENING
:
876 /* D_ID might have changed during open */
877 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
879 zfcp_fc_trigger_did_lookup(port
);
880 return ZFCP_ERP_EXIT
;
882 return ZFCP_ERP_SUCCEEDED
;
884 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
886 _zfcp_erp_port_reopen(port
, 0, "erpsoc1", NULL
);
887 return ZFCP_ERP_EXIT
;
889 /* fall through otherwise */
891 return ZFCP_ERP_FAILED
;
894 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
896 struct zfcp_port
*port
= erp_action
->port
;
897 int p_status
= atomic_read(&port
->status
);
899 if ((p_status
& ZFCP_STATUS_COMMON_NOESC
) &&
900 !(p_status
& ZFCP_STATUS_COMMON_OPEN
))
901 goto close_init_done
;
903 switch (erp_action
->step
) {
904 case ZFCP_ERP_STEP_UNINITIALIZED
:
905 zfcp_erp_port_strategy_clearstati(port
);
906 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
907 return zfcp_erp_port_strategy_close(erp_action
);
910 case ZFCP_ERP_STEP_PORT_CLOSING
:
911 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
912 return ZFCP_ERP_FAILED
;
917 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
918 return ZFCP_ERP_EXIT
;
920 return zfcp_erp_port_strategy_open_common(erp_action
);
923 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit
*unit
)
925 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED
|
926 ZFCP_STATUS_UNIT_SHARED
|
927 ZFCP_STATUS_UNIT_READONLY
,
931 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action
*erp_action
)
933 int retval
= zfcp_fsf_close_unit(erp_action
);
934 if (retval
== -ENOMEM
)
935 return ZFCP_ERP_NOMEM
;
936 erp_action
->step
= ZFCP_ERP_STEP_UNIT_CLOSING
;
938 return ZFCP_ERP_FAILED
;
939 return ZFCP_ERP_CONTINUES
;
942 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action
*erp_action
)
944 int retval
= zfcp_fsf_open_unit(erp_action
);
945 if (retval
== -ENOMEM
)
946 return ZFCP_ERP_NOMEM
;
947 erp_action
->step
= ZFCP_ERP_STEP_UNIT_OPENING
;
949 return ZFCP_ERP_FAILED
;
950 return ZFCP_ERP_CONTINUES
;
953 static int zfcp_erp_unit_strategy(struct zfcp_erp_action
*erp_action
)
955 struct zfcp_unit
*unit
= erp_action
->unit
;
957 switch (erp_action
->step
) {
958 case ZFCP_ERP_STEP_UNINITIALIZED
:
959 zfcp_erp_unit_strategy_clearstati(unit
);
960 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
961 return zfcp_erp_unit_strategy_close(erp_action
);
962 /* already closed, fall through */
963 case ZFCP_ERP_STEP_UNIT_CLOSING
:
964 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
965 return ZFCP_ERP_FAILED
;
966 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
967 return ZFCP_ERP_EXIT
;
968 return zfcp_erp_unit_strategy_open(erp_action
);
970 case ZFCP_ERP_STEP_UNIT_OPENING
:
971 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_OPEN
)
972 return ZFCP_ERP_SUCCEEDED
;
974 return ZFCP_ERP_FAILED
;
977 static int zfcp_erp_strategy_check_unit(struct zfcp_unit
*unit
, int result
)
980 case ZFCP_ERP_SUCCEEDED
:
981 atomic_set(&unit
->erp_counter
, 0);
982 zfcp_erp_unit_unblock(unit
);
984 case ZFCP_ERP_FAILED
:
985 atomic_inc(&unit
->erp_counter
);
986 if (atomic_read(&unit
->erp_counter
) > ZFCP_MAX_ERPS
) {
987 dev_err(&unit
->port
->adapter
->ccw_device
->dev
,
988 "ERP failed for unit 0x%016Lx on "
990 (unsigned long long)unit
->fcp_lun
,
991 (unsigned long long)unit
->port
->wwpn
);
992 zfcp_erp_unit_failed(unit
, "erusck1", NULL
);
997 if (atomic_read(&unit
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
998 zfcp_erp_unit_block(unit
, 0);
999 result
= ZFCP_ERP_EXIT
;
1004 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1007 case ZFCP_ERP_SUCCEEDED
:
1008 atomic_set(&port
->erp_counter
, 0);
1009 zfcp_erp_port_unblock(port
);
1012 case ZFCP_ERP_FAILED
:
1013 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1014 zfcp_erp_port_block(port
, 0);
1015 result
= ZFCP_ERP_EXIT
;
1017 atomic_inc(&port
->erp_counter
);
1018 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1019 dev_err(&port
->adapter
->ccw_device
->dev
,
1020 "ERP failed for remote port 0x%016Lx\n",
1021 (unsigned long long)port
->wwpn
);
1022 zfcp_erp_port_failed(port
, "erpsck1", NULL
);
1027 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1028 zfcp_erp_port_block(port
, 0);
1029 result
= ZFCP_ERP_EXIT
;
1034 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1038 case ZFCP_ERP_SUCCEEDED
:
1039 atomic_set(&adapter
->erp_counter
, 0);
1040 zfcp_erp_adapter_unblock(adapter
);
1043 case ZFCP_ERP_FAILED
:
1044 atomic_inc(&adapter
->erp_counter
);
1045 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1046 dev_err(&adapter
->ccw_device
->dev
,
1047 "ERP cannot recover an error "
1048 "on the FCP device\n");
1049 zfcp_erp_adapter_failed(adapter
, "erasck1", NULL
);
1054 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1055 zfcp_erp_adapter_block(adapter
, 0);
1056 result
= ZFCP_ERP_EXIT
;
1061 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1064 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1065 struct zfcp_port
*port
= erp_action
->port
;
1066 struct zfcp_unit
*unit
= erp_action
->unit
;
1068 switch (erp_action
->action
) {
1070 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1071 result
= zfcp_erp_strategy_check_unit(unit
, result
);
1074 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1075 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1076 result
= zfcp_erp_strategy_check_port(port
, result
);
1079 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1080 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1086 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1088 int status
= atomic_read(target_status
);
1090 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1091 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1092 return 1; /* take it online */
1094 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1095 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1096 return 1; /* take it offline */
1101 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1103 int action
= act
->action
;
1104 struct zfcp_adapter
*adapter
= act
->adapter
;
1105 struct zfcp_port
*port
= act
->port
;
1106 struct zfcp_unit
*unit
= act
->unit
;
1107 u32 erp_status
= act
->status
;
1110 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1111 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1112 _zfcp_erp_adapter_reopen(adapter
,
1113 ZFCP_STATUS_COMMON_ERP_FAILED
,
1115 return ZFCP_ERP_EXIT
;
1119 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1120 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1121 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1122 _zfcp_erp_port_reopen(port
,
1123 ZFCP_STATUS_COMMON_ERP_FAILED
,
1125 return ZFCP_ERP_EXIT
;
1129 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1130 if (zfcp_erp_strat_change_det(&unit
->status
, erp_status
)) {
1131 _zfcp_erp_unit_reopen(unit
,
1132 ZFCP_STATUS_COMMON_ERP_FAILED
,
1134 return ZFCP_ERP_EXIT
;
1141 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1143 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1145 adapter
->erp_total_count
--;
1146 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1147 adapter
->erp_low_mem_count
--;
1148 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1151 list_del(&erp_action
->list
);
1152 zfcp_dbf_rec_action("eractd1", erp_action
);
1154 switch (erp_action
->action
) {
1155 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1156 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1157 &erp_action
->unit
->status
);
1160 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1161 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1162 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1163 &erp_action
->port
->status
);
1166 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1167 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE
,
1168 &erp_action
->adapter
->status
);
1173 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1175 struct zfcp_adapter
*adapter
= act
->adapter
;
1176 struct zfcp_port
*port
= act
->port
;
1177 struct zfcp_unit
*unit
= act
->unit
;
1179 switch (act
->action
) {
1180 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1181 if ((result
== ZFCP_ERP_SUCCEEDED
) && !unit
->device
) {
1182 get_device(&unit
->sysfs_device
);
1183 if (scsi_queue_work(unit
->port
->adapter
->scsi_host
,
1184 &unit
->scsi_work
) <= 0)
1185 put_device(&unit
->sysfs_device
);
1187 put_device(&unit
->sysfs_device
);
1190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1191 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1192 if (result
== ZFCP_ERP_SUCCEEDED
)
1193 zfcp_scsi_schedule_rport_register(port
);
1194 put_device(&port
->sysfs_device
);
1197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1198 if (result
== ZFCP_ERP_SUCCEEDED
) {
1199 register_service_level(&adapter
->service_level
);
1200 queue_work(adapter
->work_queue
, &adapter
->scan_work
);
1202 unregister_service_level(&adapter
->service_level
);
1203 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1208 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1210 switch (erp_action
->action
) {
1211 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1212 return zfcp_erp_adapter_strategy(erp_action
);
1213 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1214 return zfcp_erp_port_forced_strategy(erp_action
);
1215 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1216 return zfcp_erp_port_strategy(erp_action
);
1217 case ZFCP_ERP_ACTION_REOPEN_UNIT
:
1218 return zfcp_erp_unit_strategy(erp_action
);
1220 return ZFCP_ERP_FAILED
;
1223 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1226 unsigned long flags
;
1227 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1229 kref_get(&adapter
->ref
);
1231 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1232 zfcp_erp_strategy_check_fsfreq(erp_action
);
1234 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1235 zfcp_erp_action_dequeue(erp_action
);
1236 retval
= ZFCP_ERP_DISMISSED
;
1240 zfcp_erp_action_to_running(erp_action
);
1242 /* no lock to allow for blocking operations */
1243 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1244 retval
= zfcp_erp_strategy_do_action(erp_action
);
1245 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1247 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1248 retval
= ZFCP_ERP_CONTINUES
;
1251 case ZFCP_ERP_NOMEM
:
1252 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1253 ++adapter
->erp_low_mem_count
;
1254 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1256 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1257 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1", NULL
);
1259 zfcp_erp_strategy_memwait(erp_action
);
1260 retval
= ZFCP_ERP_CONTINUES
;
1264 case ZFCP_ERP_CONTINUES
:
1265 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1266 --adapter
->erp_low_mem_count
;
1267 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1272 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1273 zfcp_erp_action_dequeue(erp_action
);
1274 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1275 if (retval
== ZFCP_ERP_EXIT
)
1277 if (retval
== ZFCP_ERP_SUCCEEDED
)
1278 zfcp_erp_strategy_followup_success(erp_action
);
1279 if (retval
== ZFCP_ERP_FAILED
)
1280 zfcp_erp_strategy_followup_failed(erp_action
);
1283 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1285 if (retval
!= ZFCP_ERP_CONTINUES
)
1286 zfcp_erp_action_cleanup(erp_action
, retval
);
1288 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1292 static int zfcp_erp_thread(void *data
)
1294 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1295 struct list_head
*next
;
1296 struct zfcp_erp_action
*act
;
1297 unsigned long flags
;
1300 zfcp_dbf_rec_thread_lock("erthrd1", adapter
->dbf
);
1301 wait_event_interruptible(adapter
->erp_ready_wq
,
1302 !list_empty(&adapter
->erp_ready_head
) ||
1303 kthread_should_stop());
1304 zfcp_dbf_rec_thread_lock("erthrd2", adapter
->dbf
);
1306 if (kthread_should_stop())
1309 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1310 next
= adapter
->erp_ready_head
.next
;
1311 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1313 if (next
!= &adapter
->erp_ready_head
) {
1314 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1316 /* there is more to come after dismission, no notify */
1317 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1318 zfcp_erp_wakeup(adapter
);
1326 * zfcp_erp_thread_setup - Start ERP thread for adapter
1327 * @adapter: Adapter to start the ERP thread for
1329 * Returns 0 on success or error code from kernel_thread()
1331 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1333 struct task_struct
*thread
;
1335 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1336 dev_name(&adapter
->ccw_device
->dev
));
1337 if (IS_ERR(thread
)) {
1338 dev_err(&adapter
->ccw_device
->dev
,
1339 "Creating an ERP thread for the FCP device failed.\n");
1340 return PTR_ERR(thread
);
1343 adapter
->erp_thread
= thread
;
1348 * zfcp_erp_thread_kill - Stop ERP thread.
1349 * @adapter: Adapter where the ERP thread should be stopped.
1351 * The caller of this routine ensures that the specified adapter has
1352 * been shut down and that this operation has been completed. Thus,
1353 * there are no pending erp_actions which would need to be handled
1356 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1358 kthread_stop(adapter
->erp_thread
);
1359 adapter
->erp_thread
= NULL
;
1360 WARN_ON(!list_empty(&adapter
->erp_ready_head
));
1361 WARN_ON(!list_empty(&adapter
->erp_running_head
));
1365 * zfcp_erp_adapter_failed - Set adapter status to failed.
1366 * @adapter: Failed adapter.
1367 * @id: Event id for debug trace.
1368 * @ref: Reference for debug trace.
1370 void zfcp_erp_adapter_failed(struct zfcp_adapter
*adapter
, char *id
, void *ref
)
1372 zfcp_erp_modify_adapter_status(adapter
, id
, ref
,
1373 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1377 * zfcp_erp_port_failed - Set port status to failed.
1378 * @port: Failed port.
1379 * @id: Event id for debug trace.
1380 * @ref: Reference for debug trace.
1382 void zfcp_erp_port_failed(struct zfcp_port
*port
, char *id
, void *ref
)
1384 zfcp_erp_modify_port_status(port
, id
, ref
,
1385 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1389 * zfcp_erp_unit_failed - Set unit status to failed.
1390 * @unit: Failed unit.
1391 * @id: Event id for debug trace.
1392 * @ref: Reference for debug trace.
1394 void zfcp_erp_unit_failed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1396 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1397 ZFCP_STATUS_COMMON_ERP_FAILED
, ZFCP_SET
);
1401 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1402 * @adapter: adapter for which to wait for completion of its error recovery
1404 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1406 wait_event(adapter
->erp_done_wqh
,
1407 !(atomic_read(&adapter
->status
) &
1408 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1412 * zfcp_erp_modify_adapter_status - change adapter status bits
1413 * @adapter: adapter to change the status
1414 * @id: id for the debug trace
1415 * @ref: reference for the debug trace
1416 * @mask: status bits to change
1417 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1419 * Changes in common status bits are propagated to attached ports and units.
1421 void zfcp_erp_modify_adapter_status(struct zfcp_adapter
*adapter
, char *id
,
1422 void *ref
, u32 mask
, int set_or_clear
)
1424 struct zfcp_port
*port
;
1425 unsigned long flags
;
1426 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1428 if (set_or_clear
== ZFCP_SET
) {
1429 if (status_change_set(mask
, &adapter
->status
))
1430 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1431 atomic_set_mask(mask
, &adapter
->status
);
1433 if (status_change_clear(mask
, &adapter
->status
))
1434 zfcp_dbf_rec_adapter(id
, ref
, adapter
->dbf
);
1435 atomic_clear_mask(mask
, &adapter
->status
);
1436 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1437 atomic_set(&adapter
->erp_counter
, 0);
1441 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1442 list_for_each_entry(port
, &adapter
->port_list
, list
)
1443 zfcp_erp_modify_port_status(port
, id
, ref
, common_mask
,
1445 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1450 * zfcp_erp_modify_port_status - change port status bits
1451 * @port: port to change the status bits
1452 * @id: id for the debug trace
1453 * @ref: reference for the debug trace
1454 * @mask: status bits to change
1455 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1457 * Changes in common status bits are propagated to attached units.
1459 void zfcp_erp_modify_port_status(struct zfcp_port
*port
, char *id
, void *ref
,
1460 u32 mask
, int set_or_clear
)
1462 struct zfcp_unit
*unit
;
1463 unsigned long flags
;
1464 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1466 if (set_or_clear
== ZFCP_SET
) {
1467 if (status_change_set(mask
, &port
->status
))
1468 zfcp_dbf_rec_port(id
, ref
, port
);
1469 atomic_set_mask(mask
, &port
->status
);
1471 if (status_change_clear(mask
, &port
->status
))
1472 zfcp_dbf_rec_port(id
, ref
, port
);
1473 atomic_clear_mask(mask
, &port
->status
);
1474 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1475 atomic_set(&port
->erp_counter
, 0);
1479 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1480 list_for_each_entry(unit
, &port
->unit_list
, list
)
1481 zfcp_erp_modify_unit_status(unit
, id
, ref
, common_mask
,
1483 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1488 * zfcp_erp_modify_unit_status - change unit status bits
1489 * @unit: unit to change the status bits
1490 * @id: id for the debug trace
1491 * @ref: reference for the debug trace
1492 * @mask: status bits to change
1493 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1495 void zfcp_erp_modify_unit_status(struct zfcp_unit
*unit
, char *id
, void *ref
,
1496 u32 mask
, int set_or_clear
)
1498 if (set_or_clear
== ZFCP_SET
) {
1499 if (status_change_set(mask
, &unit
->status
))
1500 zfcp_dbf_rec_unit(id
, ref
, unit
);
1501 atomic_set_mask(mask
, &unit
->status
);
1503 if (status_change_clear(mask
, &unit
->status
))
1504 zfcp_dbf_rec_unit(id
, ref
, unit
);
1505 atomic_clear_mask(mask
, &unit
->status
);
1506 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
) {
1507 atomic_set(&unit
->erp_counter
, 0);
1513 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1514 * @port: The "boxed" port.
1515 * @id: The debug trace id.
1516 * @id: Reference for the debug trace.
1518 void zfcp_erp_port_boxed(struct zfcp_port
*port
, char *id
, void *ref
)
1520 zfcp_erp_modify_port_status(port
, id
, ref
,
1521 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1522 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1526 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1527 * @port: The "boxed" unit.
1528 * @id: The debug trace id.
1529 * @id: Reference for the debug trace.
1531 void zfcp_erp_unit_boxed(struct zfcp_unit
*unit
, char *id
, void *ref
)
1533 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1534 ZFCP_STATUS_COMMON_ACCESS_BOXED
, ZFCP_SET
);
1535 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1539 * zfcp_erp_port_access_denied - Adapter denied access to port.
1540 * @port: port where access has been denied
1541 * @id: id for debug trace
1542 * @ref: reference for debug trace
1544 * Since the adapter has denied access, stop using the port and the
1547 void zfcp_erp_port_access_denied(struct zfcp_port
*port
, char *id
, void *ref
)
1549 zfcp_erp_modify_port_status(port
, id
, ref
,
1550 ZFCP_STATUS_COMMON_ERP_FAILED
|
1551 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1555 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1556 * @unit: unit where access has been denied
1557 * @id: id for debug trace
1558 * @ref: reference for debug trace
1560 * Since the adapter has denied access, stop using the unit.
1562 void zfcp_erp_unit_access_denied(struct zfcp_unit
*unit
, char *id
, void *ref
)
1564 zfcp_erp_modify_unit_status(unit
, id
, ref
,
1565 ZFCP_STATUS_COMMON_ERP_FAILED
|
1566 ZFCP_STATUS_COMMON_ACCESS_DENIED
, ZFCP_SET
);
1569 static void zfcp_erp_unit_access_changed(struct zfcp_unit
*unit
, char *id
,
1572 int status
= atomic_read(&unit
->status
);
1573 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1574 ZFCP_STATUS_COMMON_ACCESS_BOXED
)))
1577 zfcp_erp_unit_reopen(unit
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1580 static void zfcp_erp_port_access_changed(struct zfcp_port
*port
, char *id
,
1583 struct zfcp_unit
*unit
;
1584 unsigned long flags
;
1585 int status
= atomic_read(&port
->status
);
1587 if (!(status
& (ZFCP_STATUS_COMMON_ACCESS_DENIED
|
1588 ZFCP_STATUS_COMMON_ACCESS_BOXED
))) {
1589 read_lock_irqsave(&port
->unit_list_lock
, flags
);
1590 list_for_each_entry(unit
, &port
->unit_list
, list
)
1591 zfcp_erp_unit_access_changed(unit
, id
, ref
);
1592 read_unlock_irqrestore(&port
->unit_list_lock
, flags
);
1596 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
, ref
);
1600 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1601 * @adapter: Adapter where the Access Control Table (ACT) changed
1602 * @id: Id for debug trace
1603 * @ref: Reference for debug trace
1605 void zfcp_erp_adapter_access_changed(struct zfcp_adapter
*adapter
, char *id
,
1608 unsigned long flags
;
1609 struct zfcp_port
*port
;
1611 if (adapter
->connection_features
& FSF_FEATURE_NPIV_MODE
)
1614 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1615 list_for_each_entry(port
, &adapter
->port_list
, list
)
1616 zfcp_erp_port_access_changed(port
, id
, ref
);
1617 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);