1 // SPDX-License-Identifier: GPL-2.0
5 * Error Recovery Procedures (ERP).
7 * Copyright IBM Corp. 2002, 2016
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kthread.h>
15 #include "zfcp_reqlist.h"
17 #define ZFCP_MAX_ERPS 3
19 enum zfcp_erp_act_flags
{
20 ZFCP_STATUS_ERP_TIMEDOUT
= 0x10000000,
21 ZFCP_STATUS_ERP_CLOSE_ONLY
= 0x01000000,
22 ZFCP_STATUS_ERP_DISMISSED
= 0x00200000,
23 ZFCP_STATUS_ERP_LOWMEM
= 0x00400000,
24 ZFCP_STATUS_ERP_NO_REF
= 0x00800000,
28 ZFCP_ERP_STEP_UNINITIALIZED
= 0x0000,
29 ZFCP_ERP_STEP_PHYS_PORT_CLOSING
= 0x0010,
30 ZFCP_ERP_STEP_PORT_CLOSING
= 0x0100,
31 ZFCP_ERP_STEP_PORT_OPENING
= 0x0800,
32 ZFCP_ERP_STEP_LUN_CLOSING
= 0x1000,
33 ZFCP_ERP_STEP_LUN_OPENING
= 0x2000,
37 * enum zfcp_erp_act_type - Type of ERP action object.
38 * @ZFCP_ERP_ACTION_REOPEN_LUN: LUN recovery.
39 * @ZFCP_ERP_ACTION_REOPEN_PORT: Port recovery.
40 * @ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: Forced port recovery.
41 * @ZFCP_ERP_ACTION_REOPEN_ADAPTER: Adapter recovery.
42 * @ZFCP_ERP_ACTION_NONE: Eyecatcher pseudo flag to bitwise or-combine with
43 * either of the first four enum values.
44 * Used to indicate that an ERP action could not be
45 * set up despite a detected need for some recovery.
46 * @ZFCP_ERP_ACTION_FAILED: Eyecatcher pseudo flag to bitwise or-combine with
47 * either of the first four enum values.
48 * Used to indicate that ERP not needed because
49 * the object has ZFCP_STATUS_COMMON_ERP_FAILED.
51 enum zfcp_erp_act_type
{
52 ZFCP_ERP_ACTION_REOPEN_LUN
= 1,
53 ZFCP_ERP_ACTION_REOPEN_PORT
= 2,
54 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
= 3,
55 ZFCP_ERP_ACTION_REOPEN_ADAPTER
= 4,
56 ZFCP_ERP_ACTION_NONE
= 0xc0,
57 ZFCP_ERP_ACTION_FAILED
= 0xe0,
60 enum zfcp_erp_act_result
{
61 ZFCP_ERP_SUCCEEDED
= 0,
63 ZFCP_ERP_CONTINUES
= 2,
65 ZFCP_ERP_DISMISSED
= 4,
69 static void zfcp_erp_adapter_block(struct zfcp_adapter
*adapter
, int mask
)
71 zfcp_erp_clear_adapter_status(adapter
,
72 ZFCP_STATUS_COMMON_UNBLOCKED
| mask
);
75 static bool zfcp_erp_action_is_running(struct zfcp_erp_action
*act
)
77 struct zfcp_erp_action
*curr_act
;
79 list_for_each_entry(curr_act
, &act
->adapter
->erp_running_head
, list
)
85 static void zfcp_erp_action_ready(struct zfcp_erp_action
*act
)
87 struct zfcp_adapter
*adapter
= act
->adapter
;
89 list_move(&act
->list
, &act
->adapter
->erp_ready_head
);
90 zfcp_dbf_rec_run("erardy1", act
);
91 wake_up(&adapter
->erp_ready_wq
);
92 zfcp_dbf_rec_run("erardy2", act
);
95 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*act
)
97 act
->status
|= ZFCP_STATUS_ERP_DISMISSED
;
98 if (zfcp_erp_action_is_running(act
))
99 zfcp_erp_action_ready(act
);
102 static void zfcp_erp_action_dismiss_lun(struct scsi_device
*sdev
)
104 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
106 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
107 zfcp_erp_action_dismiss(&zfcp_sdev
->erp_action
);
110 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*port
)
112 struct scsi_device
*sdev
;
114 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
115 zfcp_erp_action_dismiss(&port
->erp_action
);
117 spin_lock(port
->adapter
->scsi_host
->host_lock
);
118 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
119 if (sdev_to_zfcp(sdev
)->port
== port
)
120 zfcp_erp_action_dismiss_lun(sdev
);
121 spin_unlock(port
->adapter
->scsi_host
->host_lock
);
125 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
127 struct zfcp_port
*port
;
129 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
130 zfcp_erp_action_dismiss(&adapter
->erp_action
);
132 read_lock(&adapter
->port_list_lock
);
133 list_for_each_entry(port
, &adapter
->port_list
, list
)
134 zfcp_erp_action_dismiss_port(port
);
135 read_unlock(&adapter
->port_list_lock
);
139 static int zfcp_erp_handle_failed(int want
, struct zfcp_adapter
*adapter
,
140 struct zfcp_port
*port
,
141 struct scsi_device
*sdev
)
144 struct zfcp_scsi_dev
*zsdev
;
147 case ZFCP_ERP_ACTION_REOPEN_LUN
:
148 zsdev
= sdev_to_zfcp(sdev
);
149 if (atomic_read(&zsdev
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
152 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
153 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
156 case ZFCP_ERP_ACTION_REOPEN_PORT
:
157 if (atomic_read(&port
->status
) &
158 ZFCP_STATUS_COMMON_ERP_FAILED
) {
160 /* ensure propagation of failed status to new devices */
161 zfcp_erp_set_port_status(
162 port
, ZFCP_STATUS_COMMON_ERP_FAILED
);
165 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
166 if (atomic_read(&adapter
->status
) &
167 ZFCP_STATUS_COMMON_ERP_FAILED
) {
169 /* ensure propagation of failed status to new devices */
170 zfcp_erp_set_adapter_status(
171 adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
);
182 static int zfcp_erp_required_act(int want
, struct zfcp_adapter
*adapter
,
183 struct zfcp_port
*port
,
184 struct scsi_device
*sdev
)
187 int l_status
, p_status
, a_status
;
188 struct zfcp_scsi_dev
*zfcp_sdev
;
191 case ZFCP_ERP_ACTION_REOPEN_LUN
:
192 zfcp_sdev
= sdev_to_zfcp(sdev
);
193 l_status
= atomic_read(&zfcp_sdev
->status
);
194 if (l_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
196 p_status
= atomic_read(&port
->status
);
197 if (!(p_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
198 p_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
200 if (!(p_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
201 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
203 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
204 p_status
= atomic_read(&port
->status
);
205 if (!(p_status
& ZFCP_STATUS_COMMON_OPEN
))
206 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
208 case ZFCP_ERP_ACTION_REOPEN_PORT
:
209 p_status
= atomic_read(&port
->status
);
210 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
212 a_status
= atomic_read(&adapter
->status
);
213 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
214 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
216 if (p_status
& ZFCP_STATUS_COMMON_NOESC
)
218 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
219 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
221 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
222 a_status
= atomic_read(&adapter
->status
);
223 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
225 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) &&
226 !(a_status
& ZFCP_STATUS_COMMON_OPEN
))
227 return 0; /* shutdown requested for closed adapter */
233 static struct zfcp_erp_action
*zfcp_erp_setup_act(int need
, u32 act_status
,
234 struct zfcp_adapter
*adapter
,
235 struct zfcp_port
*port
,
236 struct scsi_device
*sdev
)
238 struct zfcp_erp_action
*erp_action
;
239 struct zfcp_scsi_dev
*zfcp_sdev
;
242 case ZFCP_ERP_ACTION_REOPEN_LUN
:
243 zfcp_sdev
= sdev_to_zfcp(sdev
);
244 if (!(act_status
& ZFCP_STATUS_ERP_NO_REF
))
245 if (scsi_device_get(sdev
))
247 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
,
249 erp_action
= &zfcp_sdev
->erp_action
;
250 WARN_ON_ONCE(erp_action
->port
!= port
);
251 WARN_ON_ONCE(erp_action
->sdev
!= sdev
);
252 if (!(atomic_read(&zfcp_sdev
->status
) &
253 ZFCP_STATUS_COMMON_RUNNING
))
254 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
257 case ZFCP_ERP_ACTION_REOPEN_PORT
:
258 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
259 if (!get_device(&port
->dev
))
261 zfcp_erp_action_dismiss_port(port
);
262 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
263 erp_action
= &port
->erp_action
;
264 WARN_ON_ONCE(erp_action
->port
!= port
);
265 WARN_ON_ONCE(erp_action
->sdev
!= NULL
);
266 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
267 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
270 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
271 kref_get(&adapter
->ref
);
272 zfcp_erp_action_dismiss_adapter(adapter
);
273 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
274 erp_action
= &adapter
->erp_action
;
275 WARN_ON_ONCE(erp_action
->port
!= NULL
);
276 WARN_ON_ONCE(erp_action
->sdev
!= NULL
);
277 if (!(atomic_read(&adapter
->status
) &
278 ZFCP_STATUS_COMMON_RUNNING
))
279 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
286 WARN_ON_ONCE(erp_action
->adapter
!= adapter
);
287 memset(&erp_action
->list
, 0, sizeof(erp_action
->list
));
288 memset(&erp_action
->timer
, 0, sizeof(erp_action
->timer
));
289 erp_action
->step
= ZFCP_ERP_STEP_UNINITIALIZED
;
290 erp_action
->fsf_req_id
= 0;
291 erp_action
->action
= need
;
292 erp_action
->status
= act_status
;
297 static void zfcp_erp_action_enqueue(int want
, struct zfcp_adapter
*adapter
,
298 struct zfcp_port
*port
,
299 struct scsi_device
*sdev
,
300 char *id
, u32 act_status
)
303 struct zfcp_erp_action
*act
;
305 need
= zfcp_erp_handle_failed(want
, adapter
, port
, sdev
);
307 need
= ZFCP_ERP_ACTION_FAILED
; /* marker for trace */
311 if (!adapter
->erp_thread
) {
312 need
= ZFCP_ERP_ACTION_NONE
; /* marker for trace */
316 need
= zfcp_erp_required_act(want
, adapter
, port
, sdev
);
320 act
= zfcp_erp_setup_act(need
, act_status
, adapter
, port
, sdev
);
322 need
|= ZFCP_ERP_ACTION_NONE
; /* marker for trace */
325 atomic_or(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
326 ++adapter
->erp_total_count
;
327 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
328 wake_up(&adapter
->erp_ready_wq
);
330 zfcp_dbf_rec_trig(id
, adapter
, port
, sdev
, want
, need
);
333 void zfcp_erp_port_forced_no_port_dbf(char *id
, struct zfcp_adapter
*adapter
,
334 u64 port_name
, u32 port_id
)
337 static /* don't waste stack */ struct zfcp_port tmpport
;
339 write_lock_irqsave(&adapter
->erp_lock
, flags
);
340 /* Stand-in zfcp port with fields just good enough for
341 * zfcp_dbf_rec_trig() and zfcp_dbf_set_common().
342 * Under lock because tmpport is static.
344 atomic_set(&tmpport
.status
, -1); /* unknown */
345 tmpport
.wwpn
= port_name
;
346 tmpport
.d_id
= port_id
;
347 zfcp_dbf_rec_trig(id
, adapter
, &tmpport
, NULL
,
348 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
349 ZFCP_ERP_ACTION_NONE
);
350 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
353 static void _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
354 int clear_mask
, char *id
)
356 zfcp_erp_adapter_block(adapter
, clear_mask
);
357 zfcp_scsi_schedule_rports_block(adapter
);
359 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
360 adapter
, NULL
, NULL
, id
, 0);
364 * zfcp_erp_adapter_reopen - Reopen adapter.
365 * @adapter: Adapter to reopen.
366 * @clear: Status flags to clear.
367 * @id: Id for debug trace event.
369 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
, char *id
)
373 zfcp_erp_adapter_block(adapter
, clear
);
374 zfcp_scsi_schedule_rports_block(adapter
);
376 write_lock_irqsave(&adapter
->erp_lock
, flags
);
377 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
, adapter
,
379 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
383 * zfcp_erp_adapter_shutdown - Shutdown adapter.
384 * @adapter: Adapter to shut down.
385 * @clear: Status flags to clear.
386 * @id: Id for debug trace event.
388 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
391 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
392 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, id
);
396 * zfcp_erp_port_shutdown - Shutdown port
397 * @port: Port to shut down.
398 * @clear: Status flags to clear.
399 * @id: Id for debug trace event.
401 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *id
)
403 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
404 zfcp_erp_port_reopen(port
, clear
| flags
, id
);
407 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
409 zfcp_erp_clear_port_status(port
,
410 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
);
413 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
,
416 zfcp_erp_port_block(port
, clear
);
417 zfcp_scsi_schedule_rport_block(port
);
419 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
420 port
->adapter
, port
, NULL
, id
, 0);
424 * zfcp_erp_port_forced_reopen - Forced close of port and open again
425 * @port: Port to force close and to reopen.
426 * @clear: Status flags to clear.
427 * @id: Id for debug trace event.
429 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
, char *id
)
432 struct zfcp_adapter
*adapter
= port
->adapter
;
434 write_lock_irqsave(&adapter
->erp_lock
, flags
);
435 _zfcp_erp_port_forced_reopen(port
, clear
, id
);
436 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
439 static void _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
)
441 zfcp_erp_port_block(port
, clear
);
442 zfcp_scsi_schedule_rport_block(port
);
444 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
445 port
->adapter
, port
, NULL
, id
, 0);
449 * zfcp_erp_port_reopen - trigger remote port recovery
450 * @port: port to recover
451 * @clear_mask: flags in port status to be cleared
452 * @id: Id for debug trace event.
454 void zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *id
)
457 struct zfcp_adapter
*adapter
= port
->adapter
;
459 write_lock_irqsave(&adapter
->erp_lock
, flags
);
460 _zfcp_erp_port_reopen(port
, clear
, id
);
461 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
464 static void zfcp_erp_lun_block(struct scsi_device
*sdev
, int clear_mask
)
466 zfcp_erp_clear_lun_status(sdev
,
467 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
);
470 static void _zfcp_erp_lun_reopen(struct scsi_device
*sdev
, int clear
, char *id
,
473 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
474 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
476 zfcp_erp_lun_block(sdev
, clear
);
478 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_LUN
, adapter
,
479 zfcp_sdev
->port
, sdev
, id
, act_status
);
483 * zfcp_erp_lun_reopen - initiate reopen of a LUN
484 * @sdev: SCSI device / LUN to be reopened
485 * @clear_mask: specifies flags in LUN status to be cleared
486 * @id: Id for debug trace event.
488 * Return: 0 on success, < 0 on error
490 void zfcp_erp_lun_reopen(struct scsi_device
*sdev
, int clear
, char *id
)
493 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
494 struct zfcp_port
*port
= zfcp_sdev
->port
;
495 struct zfcp_adapter
*adapter
= port
->adapter
;
497 write_lock_irqsave(&adapter
->erp_lock
, flags
);
498 _zfcp_erp_lun_reopen(sdev
, clear
, id
, 0);
499 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
503 * zfcp_erp_lun_shutdown - Shutdown LUN
504 * @sdev: SCSI device / LUN to shut down.
505 * @clear: Status flags to clear.
506 * @id: Id for debug trace event.
508 void zfcp_erp_lun_shutdown(struct scsi_device
*sdev
, int clear
, char *id
)
510 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
511 zfcp_erp_lun_reopen(sdev
, clear
| flags
, id
);
515 * zfcp_erp_lun_shutdown_wait - Shutdown LUN and wait for erp completion
516 * @sdev: SCSI device / LUN to shut down.
517 * @id: Id for debug trace event.
519 * Do not acquire a reference for the LUN when creating the ERP
520 * action. It is safe, because this function waits for the ERP to
521 * complete first. This allows to shutdown the LUN, even when the SCSI
522 * device is in the state SDEV_DEL when scsi_device_get will fail.
524 void zfcp_erp_lun_shutdown_wait(struct scsi_device
*sdev
, char *id
)
527 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
528 struct zfcp_port
*port
= zfcp_sdev
->port
;
529 struct zfcp_adapter
*adapter
= port
->adapter
;
530 int clear
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
532 write_lock_irqsave(&adapter
->erp_lock
, flags
);
533 _zfcp_erp_lun_reopen(sdev
, clear
, id
, ZFCP_STATUS_ERP_NO_REF
);
534 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
536 zfcp_erp_wait(adapter
);
539 static int zfcp_erp_status_change_set(unsigned long mask
, atomic_t
*status
)
541 return (atomic_read(status
) ^ mask
) & mask
;
544 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
546 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
548 zfcp_dbf_rec_run("eraubl1", &adapter
->erp_action
);
549 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
552 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
554 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
556 zfcp_dbf_rec_run("erpubl1", &port
->erp_action
);
557 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
560 static void zfcp_erp_lun_unblock(struct scsi_device
*sdev
)
562 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
564 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
566 zfcp_dbf_rec_run("erlubl1", &sdev_to_zfcp(sdev
)->erp_action
);
567 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &zfcp_sdev
->status
);
570 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
572 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
573 zfcp_dbf_rec_run("erator1", erp_action
);
576 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
578 struct zfcp_adapter
*adapter
= act
->adapter
;
579 struct zfcp_fsf_req
*req
;
581 if (!act
->fsf_req_id
)
584 spin_lock(&adapter
->req_list
->lock
);
585 req
= _zfcp_reqlist_find(adapter
->req_list
, act
->fsf_req_id
);
586 if (req
&& req
->erp_action
== act
) {
587 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
588 ZFCP_STATUS_ERP_TIMEDOUT
)) {
589 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
590 zfcp_dbf_rec_run("erscf_1", act
);
591 req
->erp_action
= NULL
;
593 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
594 zfcp_dbf_rec_run("erscf_2", act
);
595 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
599 spin_unlock(&adapter
->req_list
->lock
);
603 * zfcp_erp_notify - Trigger ERP action.
604 * @erp_action: ERP action to continue.
605 * @set_mask: ERP action status flags to set.
607 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
609 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
612 write_lock_irqsave(&adapter
->erp_lock
, flags
);
613 if (zfcp_erp_action_is_running(erp_action
)) {
614 erp_action
->status
|= set_mask
;
615 zfcp_erp_action_ready(erp_action
);
617 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
621 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
622 * @data: ERP action (from timer data)
624 void zfcp_erp_timeout_handler(struct timer_list
*t
)
626 struct zfcp_fsf_req
*fsf_req
= from_timer(fsf_req
, t
, timer
);
627 struct zfcp_erp_action
*act
= fsf_req
->erp_action
;
629 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
632 static void zfcp_erp_memwait_handler(struct timer_list
*t
)
634 struct zfcp_erp_action
*act
= from_timer(act
, t
, timer
);
636 zfcp_erp_notify(act
, 0);
639 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
641 timer_setup(&erp_action
->timer
, zfcp_erp_memwait_handler
, 0);
642 erp_action
->timer
.expires
= jiffies
+ HZ
;
643 add_timer(&erp_action
->timer
);
646 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
649 struct zfcp_port
*port
;
651 read_lock(&adapter
->port_list_lock
);
652 list_for_each_entry(port
, &adapter
->port_list
, list
)
653 _zfcp_erp_port_reopen(port
, clear
, id
);
654 read_unlock(&adapter
->port_list_lock
);
657 static void _zfcp_erp_lun_reopen_all(struct zfcp_port
*port
, int clear
,
660 struct scsi_device
*sdev
;
662 spin_lock(port
->adapter
->scsi_host
->host_lock
);
663 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
664 if (sdev_to_zfcp(sdev
)->port
== port
)
665 _zfcp_erp_lun_reopen(sdev
, clear
, id
, 0);
666 spin_unlock(port
->adapter
->scsi_host
->host_lock
);
669 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
671 switch (act
->action
) {
672 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
673 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1");
675 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
676 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2");
678 case ZFCP_ERP_ACTION_REOPEN_PORT
:
679 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3");
681 case ZFCP_ERP_ACTION_REOPEN_LUN
:
682 _zfcp_erp_lun_reopen(act
->sdev
, 0, "ersff_4", 0);
687 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
689 switch (act
->action
) {
690 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
691 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1");
693 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
694 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2");
696 case ZFCP_ERP_ACTION_REOPEN_PORT
:
697 _zfcp_erp_lun_reopen_all(act
->port
, 0, "ersfs_3");
702 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
706 read_lock_irqsave(&adapter
->erp_lock
, flags
);
707 if (list_empty(&adapter
->erp_ready_head
) &&
708 list_empty(&adapter
->erp_running_head
)) {
709 atomic_andnot(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
711 wake_up(&adapter
->erp_done_wqh
);
713 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
716 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
718 struct zfcp_port
*port
;
719 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
721 if (IS_ERR(port
)) /* error or port already attached */
723 _zfcp_erp_port_reopen(port
, 0, "ereptp1");
726 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action
*erp_action
)
730 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
732 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
734 for (retries
= 7; retries
; retries
--) {
735 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
737 write_lock_irq(&adapter
->erp_lock
);
738 zfcp_erp_action_to_running(erp_action
);
739 write_unlock_irq(&adapter
->erp_lock
);
740 if (zfcp_fsf_exchange_config_data(erp_action
)) {
741 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
743 return ZFCP_ERP_FAILED
;
746 wait_event(adapter
->erp_ready_wq
,
747 !list_empty(&adapter
->erp_ready_head
));
748 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
751 if (!(atomic_read(&adapter
->status
) &
752 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
759 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
762 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
763 return ZFCP_ERP_FAILED
;
765 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
766 zfcp_erp_enqueue_ptp_port(adapter
);
768 return ZFCP_ERP_SUCCEEDED
;
771 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action
*act
)
774 struct zfcp_adapter
*adapter
= act
->adapter
;
776 write_lock_irq(&adapter
->erp_lock
);
777 zfcp_erp_action_to_running(act
);
778 write_unlock_irq(&adapter
->erp_lock
);
780 ret
= zfcp_fsf_exchange_port_data(act
);
781 if (ret
== -EOPNOTSUPP
)
782 return ZFCP_ERP_SUCCEEDED
;
784 return ZFCP_ERP_FAILED
;
786 zfcp_dbf_rec_run("erasox1", act
);
787 wait_event(adapter
->erp_ready_wq
,
788 !list_empty(&adapter
->erp_ready_head
));
789 zfcp_dbf_rec_run("erasox2", act
);
790 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
791 return ZFCP_ERP_FAILED
;
793 return ZFCP_ERP_SUCCEEDED
;
796 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action
*act
)
798 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
799 return ZFCP_ERP_FAILED
;
801 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
802 return ZFCP_ERP_FAILED
;
804 if (mempool_resize(act
->adapter
->pool
.sr_data
,
805 act
->adapter
->stat_read_buf_num
))
806 return ZFCP_ERP_FAILED
;
808 if (mempool_resize(act
->adapter
->pool
.status_read_req
,
809 act
->adapter
->stat_read_buf_num
))
810 return ZFCP_ERP_FAILED
;
812 atomic_set(&act
->adapter
->stat_miss
, act
->adapter
->stat_read_buf_num
);
813 if (zfcp_status_read_refill(act
->adapter
))
814 return ZFCP_ERP_FAILED
;
816 return ZFCP_ERP_SUCCEEDED
;
819 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
821 struct zfcp_adapter
*adapter
= act
->adapter
;
823 /* close queues to ensure that buffers are not accessed by adapter */
824 zfcp_qdio_close(adapter
->qdio
);
825 zfcp_fsf_req_dismiss_all(adapter
);
826 adapter
->fsf_req_seq_no
= 0;
827 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
828 /* all ports and LUNs are closed */
829 zfcp_erp_clear_adapter_status(adapter
, ZFCP_STATUS_COMMON_OPEN
);
831 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
832 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
835 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action
*act
)
837 struct zfcp_adapter
*adapter
= act
->adapter
;
839 if (zfcp_qdio_open(adapter
->qdio
)) {
840 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
841 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
843 return ZFCP_ERP_FAILED
;
846 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
847 zfcp_erp_adapter_strategy_close(act
);
848 return ZFCP_ERP_FAILED
;
851 atomic_or(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
853 return ZFCP_ERP_SUCCEEDED
;
856 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action
*act
)
858 struct zfcp_adapter
*adapter
= act
->adapter
;
860 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
861 zfcp_erp_adapter_strategy_close(act
);
862 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
863 return ZFCP_ERP_EXIT
;
866 if (zfcp_erp_adapter_strategy_open(act
)) {
868 return ZFCP_ERP_FAILED
;
871 return ZFCP_ERP_SUCCEEDED
;
874 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action
*act
)
878 retval
= zfcp_fsf_close_physical_port(act
);
879 if (retval
== -ENOMEM
)
880 return ZFCP_ERP_NOMEM
;
881 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
883 return ZFCP_ERP_FAILED
;
885 return ZFCP_ERP_CONTINUES
;
888 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action
*erp_action
)
890 struct zfcp_port
*port
= erp_action
->port
;
891 int status
= atomic_read(&port
->status
);
893 switch (erp_action
->step
) {
894 case ZFCP_ERP_STEP_UNINITIALIZED
:
895 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
896 (status
& ZFCP_STATUS_COMMON_OPEN
))
897 return zfcp_erp_port_forced_strategy_close(erp_action
);
899 return ZFCP_ERP_FAILED
;
901 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
902 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
903 return ZFCP_ERP_SUCCEEDED
;
905 return ZFCP_ERP_FAILED
;
908 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action
*erp_action
)
912 retval
= zfcp_fsf_close_port(erp_action
);
913 if (retval
== -ENOMEM
)
914 return ZFCP_ERP_NOMEM
;
915 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
917 return ZFCP_ERP_FAILED
;
918 return ZFCP_ERP_CONTINUES
;
921 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action
*erp_action
)
925 retval
= zfcp_fsf_open_port(erp_action
);
926 if (retval
== -ENOMEM
)
927 return ZFCP_ERP_NOMEM
;
928 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
930 return ZFCP_ERP_FAILED
;
931 return ZFCP_ERP_CONTINUES
;
934 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
936 struct zfcp_adapter
*adapter
= act
->adapter
;
937 struct zfcp_port
*port
= act
->port
;
939 if (port
->wwpn
!= adapter
->peer_wwpn
) {
940 zfcp_erp_set_port_status(port
, ZFCP_STATUS_COMMON_ERP_FAILED
);
941 return ZFCP_ERP_FAILED
;
943 port
->d_id
= adapter
->peer_d_id
;
944 return zfcp_erp_port_strategy_open_port(act
);
947 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action
*act
)
949 struct zfcp_adapter
*adapter
= act
->adapter
;
950 struct zfcp_port
*port
= act
->port
;
951 int p_status
= atomic_read(&port
->status
);
954 case ZFCP_ERP_STEP_UNINITIALIZED
:
955 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
956 case ZFCP_ERP_STEP_PORT_CLOSING
:
957 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
958 return zfcp_erp_open_ptp_port(act
);
960 zfcp_fc_trigger_did_lookup(port
);
961 return ZFCP_ERP_EXIT
;
963 return zfcp_erp_port_strategy_open_port(act
);
965 case ZFCP_ERP_STEP_PORT_OPENING
:
966 /* D_ID might have changed during open */
967 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
969 zfcp_fc_trigger_did_lookup(port
);
970 return ZFCP_ERP_EXIT
;
972 return ZFCP_ERP_SUCCEEDED
;
974 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
976 return ZFCP_ERP_FAILED
;
978 /* fall through otherwise */
980 return ZFCP_ERP_FAILED
;
983 static int zfcp_erp_port_strategy(struct zfcp_erp_action
*erp_action
)
985 struct zfcp_port
*port
= erp_action
->port
;
986 int p_status
= atomic_read(&port
->status
);
988 if ((p_status
& ZFCP_STATUS_COMMON_NOESC
) &&
989 !(p_status
& ZFCP_STATUS_COMMON_OPEN
))
990 goto close_init_done
;
992 switch (erp_action
->step
) {
993 case ZFCP_ERP_STEP_UNINITIALIZED
:
994 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
995 return zfcp_erp_port_strategy_close(erp_action
);
998 case ZFCP_ERP_STEP_PORT_CLOSING
:
999 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
1000 return ZFCP_ERP_FAILED
;
1005 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
1006 return ZFCP_ERP_EXIT
;
1008 return zfcp_erp_port_strategy_open_common(erp_action
);
1011 static void zfcp_erp_lun_strategy_clearstati(struct scsi_device
*sdev
)
1013 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1015 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED
,
1016 &zfcp_sdev
->status
);
1019 static int zfcp_erp_lun_strategy_close(struct zfcp_erp_action
*erp_action
)
1021 int retval
= zfcp_fsf_close_lun(erp_action
);
1022 if (retval
== -ENOMEM
)
1023 return ZFCP_ERP_NOMEM
;
1024 erp_action
->step
= ZFCP_ERP_STEP_LUN_CLOSING
;
1026 return ZFCP_ERP_FAILED
;
1027 return ZFCP_ERP_CONTINUES
;
1030 static int zfcp_erp_lun_strategy_open(struct zfcp_erp_action
*erp_action
)
1032 int retval
= zfcp_fsf_open_lun(erp_action
);
1033 if (retval
== -ENOMEM
)
1034 return ZFCP_ERP_NOMEM
;
1035 erp_action
->step
= ZFCP_ERP_STEP_LUN_OPENING
;
1037 return ZFCP_ERP_FAILED
;
1038 return ZFCP_ERP_CONTINUES
;
1041 static int zfcp_erp_lun_strategy(struct zfcp_erp_action
*erp_action
)
1043 struct scsi_device
*sdev
= erp_action
->sdev
;
1044 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1046 switch (erp_action
->step
) {
1047 case ZFCP_ERP_STEP_UNINITIALIZED
:
1048 zfcp_erp_lun_strategy_clearstati(sdev
);
1049 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1050 return zfcp_erp_lun_strategy_close(erp_action
);
1051 /* already closed, fall through */
1052 case ZFCP_ERP_STEP_LUN_CLOSING
:
1053 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1054 return ZFCP_ERP_FAILED
;
1055 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
1056 return ZFCP_ERP_EXIT
;
1057 return zfcp_erp_lun_strategy_open(erp_action
);
1059 case ZFCP_ERP_STEP_LUN_OPENING
:
1060 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1061 return ZFCP_ERP_SUCCEEDED
;
1063 return ZFCP_ERP_FAILED
;
1066 static int zfcp_erp_strategy_check_lun(struct scsi_device
*sdev
, int result
)
1068 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1071 case ZFCP_ERP_SUCCEEDED
:
1072 atomic_set(&zfcp_sdev
->erp_counter
, 0);
1073 zfcp_erp_lun_unblock(sdev
);
1075 case ZFCP_ERP_FAILED
:
1076 atomic_inc(&zfcp_sdev
->erp_counter
);
1077 if (atomic_read(&zfcp_sdev
->erp_counter
) > ZFCP_MAX_ERPS
) {
1078 dev_err(&zfcp_sdev
->port
->adapter
->ccw_device
->dev
,
1079 "ERP failed for LUN 0x%016Lx on "
1081 (unsigned long long)zfcp_scsi_dev_lun(sdev
),
1082 (unsigned long long)zfcp_sdev
->port
->wwpn
);
1083 zfcp_erp_set_lun_status(sdev
,
1084 ZFCP_STATUS_COMMON_ERP_FAILED
);
1089 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1090 zfcp_erp_lun_block(sdev
, 0);
1091 result
= ZFCP_ERP_EXIT
;
1096 static int zfcp_erp_strategy_check_port(struct zfcp_port
*port
, int result
)
1099 case ZFCP_ERP_SUCCEEDED
:
1100 atomic_set(&port
->erp_counter
, 0);
1101 zfcp_erp_port_unblock(port
);
1104 case ZFCP_ERP_FAILED
:
1105 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1106 zfcp_erp_port_block(port
, 0);
1107 result
= ZFCP_ERP_EXIT
;
1109 atomic_inc(&port
->erp_counter
);
1110 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1111 dev_err(&port
->adapter
->ccw_device
->dev
,
1112 "ERP failed for remote port 0x%016Lx\n",
1113 (unsigned long long)port
->wwpn
);
1114 zfcp_erp_set_port_status(port
,
1115 ZFCP_STATUS_COMMON_ERP_FAILED
);
1120 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1121 zfcp_erp_port_block(port
, 0);
1122 result
= ZFCP_ERP_EXIT
;
1127 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter
*adapter
,
1131 case ZFCP_ERP_SUCCEEDED
:
1132 atomic_set(&adapter
->erp_counter
, 0);
1133 zfcp_erp_adapter_unblock(adapter
);
1136 case ZFCP_ERP_FAILED
:
1137 atomic_inc(&adapter
->erp_counter
);
1138 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1139 dev_err(&adapter
->ccw_device
->dev
,
1140 "ERP cannot recover an error "
1141 "on the FCP device\n");
1142 zfcp_erp_set_adapter_status(adapter
,
1143 ZFCP_STATUS_COMMON_ERP_FAILED
);
1148 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1149 zfcp_erp_adapter_block(adapter
, 0);
1150 result
= ZFCP_ERP_EXIT
;
1155 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action
*erp_action
,
1158 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1159 struct zfcp_port
*port
= erp_action
->port
;
1160 struct scsi_device
*sdev
= erp_action
->sdev
;
1162 switch (erp_action
->action
) {
1164 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1165 result
= zfcp_erp_strategy_check_lun(sdev
, result
);
1168 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1169 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1170 result
= zfcp_erp_strategy_check_port(port
, result
);
1173 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1174 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1180 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1182 int status
= atomic_read(target_status
);
1184 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1185 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1186 return 1; /* take it online */
1188 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1189 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1190 return 1; /* take it offline */
1195 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action
*act
, int ret
)
1197 int action
= act
->action
;
1198 struct zfcp_adapter
*adapter
= act
->adapter
;
1199 struct zfcp_port
*port
= act
->port
;
1200 struct scsi_device
*sdev
= act
->sdev
;
1201 struct zfcp_scsi_dev
*zfcp_sdev
;
1202 u32 erp_status
= act
->status
;
1205 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1206 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1207 _zfcp_erp_adapter_reopen(adapter
,
1208 ZFCP_STATUS_COMMON_ERP_FAILED
,
1210 return ZFCP_ERP_EXIT
;
1214 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1215 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1216 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1217 _zfcp_erp_port_reopen(port
,
1218 ZFCP_STATUS_COMMON_ERP_FAILED
,
1220 return ZFCP_ERP_EXIT
;
1224 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1225 zfcp_sdev
= sdev_to_zfcp(sdev
);
1226 if (zfcp_erp_strat_change_det(&zfcp_sdev
->status
, erp_status
)) {
1227 _zfcp_erp_lun_reopen(sdev
,
1228 ZFCP_STATUS_COMMON_ERP_FAILED
,
1230 return ZFCP_ERP_EXIT
;
1237 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1239 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1240 struct zfcp_scsi_dev
*zfcp_sdev
;
1242 adapter
->erp_total_count
--;
1243 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1244 adapter
->erp_low_mem_count
--;
1245 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1248 list_del(&erp_action
->list
);
1249 zfcp_dbf_rec_run("eractd1", erp_action
);
1251 switch (erp_action
->action
) {
1252 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1253 zfcp_sdev
= sdev_to_zfcp(erp_action
->sdev
);
1254 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1255 &zfcp_sdev
->status
);
1258 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1259 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1260 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1261 &erp_action
->port
->status
);
1264 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1265 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1266 &erp_action
->adapter
->status
);
1272 * zfcp_erp_try_rport_unblock - unblock rport if no more/new recovery
1273 * @port: zfcp_port whose fc_rport we should try to unblock
1275 static void zfcp_erp_try_rport_unblock(struct zfcp_port
*port
)
1277 unsigned long flags
;
1278 struct zfcp_adapter
*adapter
= port
->adapter
;
1280 struct Scsi_Host
*shost
= adapter
->scsi_host
;
1281 struct scsi_device
*sdev
;
1283 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1284 port_status
= atomic_read(&port
->status
);
1285 if ((port_status
& ZFCP_STATUS_COMMON_UNBLOCKED
) == 0 ||
1286 (port_status
& (ZFCP_STATUS_COMMON_ERP_INUSE
|
1287 ZFCP_STATUS_COMMON_ERP_FAILED
)) != 0) {
1288 /* new ERP of severity >= port triggered elsewhere meanwhile or
1289 * local link down (adapter erp_failed but not clear unblock)
1291 zfcp_dbf_rec_run_lvl(4, "ertru_p", &port
->erp_action
);
1292 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1295 spin_lock(shost
->host_lock
);
1296 __shost_for_each_device(sdev
, shost
) {
1297 struct zfcp_scsi_dev
*zsdev
= sdev_to_zfcp(sdev
);
1300 if (zsdev
->port
!= port
)
1302 /* LUN under port of interest */
1303 lun_status
= atomic_read(&zsdev
->status
);
1304 if ((lun_status
& ZFCP_STATUS_COMMON_ERP_FAILED
) != 0)
1305 continue; /* unblock rport despite failed LUNs */
1306 /* LUN recovery not given up yet [maybe follow-up pending] */
1307 if ((lun_status
& ZFCP_STATUS_COMMON_UNBLOCKED
) == 0 ||
1308 (lun_status
& ZFCP_STATUS_COMMON_ERP_INUSE
) != 0) {
1310 * not yet unblocked [LUN recovery pending]
1311 * or meanwhile blocked [new LUN recovery triggered]
1313 zfcp_dbf_rec_run_lvl(4, "ertru_l", &zsdev
->erp_action
);
1314 spin_unlock(shost
->host_lock
);
1315 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1319 /* now port has no child or all children have completed recovery,
1320 * and no ERP of severity >= port was meanwhile triggered elsewhere
1322 zfcp_scsi_schedule_rport_register(port
);
1323 spin_unlock(shost
->host_lock
);
1324 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1327 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
, int result
)
1329 struct zfcp_adapter
*adapter
= act
->adapter
;
1330 struct zfcp_port
*port
= act
->port
;
1331 struct scsi_device
*sdev
= act
->sdev
;
1333 switch (act
->action
) {
1334 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1335 if (!(act
->status
& ZFCP_STATUS_ERP_NO_REF
))
1336 scsi_device_put(sdev
);
1337 zfcp_erp_try_rport_unblock(port
);
1340 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1341 /* This switch case might also happen after a forced reopen
1342 * was successfully done and thus overwritten with a new
1343 * non-forced reopen at `ersfs_2'. In this case, we must not
1344 * do the clean-up of the non-forced version.
1346 if (act
->step
!= ZFCP_ERP_STEP_UNINITIALIZED
)
1347 if (result
== ZFCP_ERP_SUCCEEDED
)
1348 zfcp_erp_try_rport_unblock(port
);
1350 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1351 put_device(&port
->dev
);
1354 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1355 if (result
== ZFCP_ERP_SUCCEEDED
) {
1356 register_service_level(&adapter
->service_level
);
1357 zfcp_fc_conditional_port_scan(adapter
);
1358 queue_work(adapter
->work_queue
, &adapter
->ns_up_work
);
1360 unregister_service_level(&adapter
->service_level
);
1362 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1367 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action
*erp_action
)
1369 switch (erp_action
->action
) {
1370 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1371 return zfcp_erp_adapter_strategy(erp_action
);
1372 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1373 return zfcp_erp_port_forced_strategy(erp_action
);
1374 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1375 return zfcp_erp_port_strategy(erp_action
);
1376 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1377 return zfcp_erp_lun_strategy(erp_action
);
1379 return ZFCP_ERP_FAILED
;
1382 static int zfcp_erp_strategy(struct zfcp_erp_action
*erp_action
)
1385 unsigned long flags
;
1386 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1388 kref_get(&adapter
->ref
);
1390 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1391 zfcp_erp_strategy_check_fsfreq(erp_action
);
1393 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1394 zfcp_erp_action_dequeue(erp_action
);
1395 retval
= ZFCP_ERP_DISMISSED
;
1399 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
1400 retval
= ZFCP_ERP_FAILED
;
1404 zfcp_erp_action_to_running(erp_action
);
1406 /* no lock to allow for blocking operations */
1407 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1408 retval
= zfcp_erp_strategy_do_action(erp_action
);
1409 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1411 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1412 retval
= ZFCP_ERP_CONTINUES
;
1415 case ZFCP_ERP_NOMEM
:
1416 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1417 ++adapter
->erp_low_mem_count
;
1418 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1420 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1421 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1");
1423 zfcp_erp_strategy_memwait(erp_action
);
1424 retval
= ZFCP_ERP_CONTINUES
;
1428 case ZFCP_ERP_CONTINUES
:
1429 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1430 --adapter
->erp_low_mem_count
;
1431 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1437 retval
= zfcp_erp_strategy_check_target(erp_action
, retval
);
1438 zfcp_erp_action_dequeue(erp_action
);
1439 retval
= zfcp_erp_strategy_statechange(erp_action
, retval
);
1440 if (retval
== ZFCP_ERP_EXIT
)
1442 if (retval
== ZFCP_ERP_SUCCEEDED
)
1443 zfcp_erp_strategy_followup_success(erp_action
);
1444 if (retval
== ZFCP_ERP_FAILED
)
1445 zfcp_erp_strategy_followup_failed(erp_action
);
1448 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1450 if (retval
!= ZFCP_ERP_CONTINUES
)
1451 zfcp_erp_action_cleanup(erp_action
, retval
);
1453 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1457 static int zfcp_erp_thread(void *data
)
1459 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1460 struct list_head
*next
;
1461 struct zfcp_erp_action
*act
;
1462 unsigned long flags
;
1465 wait_event_interruptible(adapter
->erp_ready_wq
,
1466 !list_empty(&adapter
->erp_ready_head
) ||
1467 kthread_should_stop());
1469 if (kthread_should_stop())
1472 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1473 next
= adapter
->erp_ready_head
.next
;
1474 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1476 if (next
!= &adapter
->erp_ready_head
) {
1477 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1479 /* there is more to come after dismission, no notify */
1480 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1481 zfcp_erp_wakeup(adapter
);
1489 * zfcp_erp_thread_setup - Start ERP thread for adapter
1490 * @adapter: Adapter to start the ERP thread for
1492 * Returns 0 on success or error code from kernel_thread()
1494 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1496 struct task_struct
*thread
;
1498 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1499 dev_name(&adapter
->ccw_device
->dev
));
1500 if (IS_ERR(thread
)) {
1501 dev_err(&adapter
->ccw_device
->dev
,
1502 "Creating an ERP thread for the FCP device failed.\n");
1503 return PTR_ERR(thread
);
1506 adapter
->erp_thread
= thread
;
1511 * zfcp_erp_thread_kill - Stop ERP thread.
1512 * @adapter: Adapter where the ERP thread should be stopped.
1514 * The caller of this routine ensures that the specified adapter has
1515 * been shut down and that this operation has been completed. Thus,
1516 * there are no pending erp_actions which would need to be handled
1519 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1521 kthread_stop(adapter
->erp_thread
);
1522 adapter
->erp_thread
= NULL
;
1523 WARN_ON(!list_empty(&adapter
->erp_ready_head
));
1524 WARN_ON(!list_empty(&adapter
->erp_running_head
));
1528 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1529 * @adapter: adapter for which to wait for completion of its error recovery
1531 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1533 wait_event(adapter
->erp_done_wqh
,
1534 !(atomic_read(&adapter
->status
) &
1535 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1539 * zfcp_erp_set_adapter_status - set adapter status bits
1540 * @adapter: adapter to change the status
1541 * @mask: status bits to change
1543 * Changes in common status bits are propagated to attached ports and LUNs.
1545 void zfcp_erp_set_adapter_status(struct zfcp_adapter
*adapter
, u32 mask
)
1547 struct zfcp_port
*port
;
1548 struct scsi_device
*sdev
;
1549 unsigned long flags
;
1550 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1552 atomic_or(mask
, &adapter
->status
);
1557 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1558 list_for_each_entry(port
, &adapter
->port_list
, list
)
1559 atomic_or(common_mask
, &port
->status
);
1560 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1562 spin_lock_irqsave(adapter
->scsi_host
->host_lock
, flags
);
1563 __shost_for_each_device(sdev
, adapter
->scsi_host
)
1564 atomic_or(common_mask
, &sdev_to_zfcp(sdev
)->status
);
1565 spin_unlock_irqrestore(adapter
->scsi_host
->host_lock
, flags
);
1569 * zfcp_erp_clear_adapter_status - clear adapter status bits
1570 * @adapter: adapter to change the status
1571 * @mask: status bits to change
1573 * Changes in common status bits are propagated to attached ports and LUNs.
1575 void zfcp_erp_clear_adapter_status(struct zfcp_adapter
*adapter
, u32 mask
)
1577 struct zfcp_port
*port
;
1578 struct scsi_device
*sdev
;
1579 unsigned long flags
;
1580 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1581 u32 clear_counter
= mask
& ZFCP_STATUS_COMMON_ERP_FAILED
;
1583 atomic_andnot(mask
, &adapter
->status
);
1589 atomic_set(&adapter
->erp_counter
, 0);
1591 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1592 list_for_each_entry(port
, &adapter
->port_list
, list
) {
1593 atomic_andnot(common_mask
, &port
->status
);
1595 atomic_set(&port
->erp_counter
, 0);
1597 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1599 spin_lock_irqsave(adapter
->scsi_host
->host_lock
, flags
);
1600 __shost_for_each_device(sdev
, adapter
->scsi_host
) {
1601 atomic_andnot(common_mask
, &sdev_to_zfcp(sdev
)->status
);
1603 atomic_set(&sdev_to_zfcp(sdev
)->erp_counter
, 0);
1605 spin_unlock_irqrestore(adapter
->scsi_host
->host_lock
, flags
);
1609 * zfcp_erp_set_port_status - set port status bits
1610 * @port: port to change the status
1611 * @mask: status bits to change
1613 * Changes in common status bits are propagated to attached LUNs.
1615 void zfcp_erp_set_port_status(struct zfcp_port
*port
, u32 mask
)
1617 struct scsi_device
*sdev
;
1618 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1619 unsigned long flags
;
1621 atomic_or(mask
, &port
->status
);
1626 spin_lock_irqsave(port
->adapter
->scsi_host
->host_lock
, flags
);
1627 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
1628 if (sdev_to_zfcp(sdev
)->port
== port
)
1629 atomic_or(common_mask
,
1630 &sdev_to_zfcp(sdev
)->status
);
1631 spin_unlock_irqrestore(port
->adapter
->scsi_host
->host_lock
, flags
);
1635 * zfcp_erp_clear_port_status - clear port status bits
1636 * @port: adapter to change the status
1637 * @mask: status bits to change
1639 * Changes in common status bits are propagated to attached LUNs.
1641 void zfcp_erp_clear_port_status(struct zfcp_port
*port
, u32 mask
)
1643 struct scsi_device
*sdev
;
1644 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1645 u32 clear_counter
= mask
& ZFCP_STATUS_COMMON_ERP_FAILED
;
1646 unsigned long flags
;
1648 atomic_andnot(mask
, &port
->status
);
1654 atomic_set(&port
->erp_counter
, 0);
1656 spin_lock_irqsave(port
->adapter
->scsi_host
->host_lock
, flags
);
1657 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
1658 if (sdev_to_zfcp(sdev
)->port
== port
) {
1659 atomic_andnot(common_mask
,
1660 &sdev_to_zfcp(sdev
)->status
);
1662 atomic_set(&sdev_to_zfcp(sdev
)->erp_counter
, 0);
1664 spin_unlock_irqrestore(port
->adapter
->scsi_host
->host_lock
, flags
);
1668 * zfcp_erp_set_lun_status - set lun status bits
1669 * @sdev: SCSI device / lun to set the status bits
1670 * @mask: status bits to change
1672 void zfcp_erp_set_lun_status(struct scsi_device
*sdev
, u32 mask
)
1674 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1676 atomic_or(mask
, &zfcp_sdev
->status
);
1680 * zfcp_erp_clear_lun_status - clear lun status bits
1681 * @sdev: SCSi device / lun to clear the status bits
1682 * @mask: status bits to change
1684 void zfcp_erp_clear_lun_status(struct scsi_device
*sdev
, u32 mask
)
1686 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1688 atomic_andnot(mask
, &zfcp_sdev
->status
);
1690 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1691 atomic_set(&zfcp_sdev
->erp_counter
, 0);
1695 * zfcp_erp_adapter_reset_sync() - Really reopen adapter and wait.
1696 * @adapter: Pointer to zfcp_adapter to reopen.
1697 * @id: Trace tag string of length %ZFCP_DBF_TAG_LEN.
1699 void zfcp_erp_adapter_reset_sync(struct zfcp_adapter
*adapter
, char *id
)
1701 zfcp_erp_set_adapter_status(adapter
, ZFCP_STATUS_COMMON_RUNNING
);
1702 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
, id
);
1703 zfcp_erp_wait(adapter
);