1 // SPDX-License-Identifier: GPL-2.0
5 * Error Recovery Procedures (ERP).
7 * Copyright IBM Corp. 2002, 2017
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kthread.h>
14 #include <linux/bug.h>
16 #include "zfcp_reqlist.h"
18 #define ZFCP_MAX_ERPS 3
20 enum zfcp_erp_act_flags
{
21 ZFCP_STATUS_ERP_TIMEDOUT
= 0x10000000,
22 ZFCP_STATUS_ERP_CLOSE_ONLY
= 0x01000000,
23 ZFCP_STATUS_ERP_DISMISSED
= 0x00200000,
24 ZFCP_STATUS_ERP_LOWMEM
= 0x00400000,
25 ZFCP_STATUS_ERP_NO_REF
= 0x00800000,
29 * Eyecatcher pseudo flag to bitwise or-combine with enum zfcp_erp_act_type.
30 * Used to indicate that an ERP action could not be set up despite a detected
31 * need for some recovery.
33 #define ZFCP_ERP_ACTION_NONE 0xc0
35 * Eyecatcher pseudo flag to bitwise or-combine with enum zfcp_erp_act_type.
36 * Used to indicate that ERP not needed because the object has
37 * ZFCP_STATUS_COMMON_ERP_FAILED.
39 #define ZFCP_ERP_ACTION_FAILED 0xe0
41 enum zfcp_erp_act_result
{
42 ZFCP_ERP_SUCCEEDED
= 0,
44 ZFCP_ERP_CONTINUES
= 2,
46 ZFCP_ERP_DISMISSED
= 4,
50 static void zfcp_erp_adapter_block(struct zfcp_adapter
*adapter
, int mask
)
52 zfcp_erp_clear_adapter_status(adapter
,
53 ZFCP_STATUS_COMMON_UNBLOCKED
| mask
);
56 static bool zfcp_erp_action_is_running(struct zfcp_erp_action
*act
)
58 struct zfcp_erp_action
*curr_act
;
60 list_for_each_entry(curr_act
, &act
->adapter
->erp_running_head
, list
)
66 static void zfcp_erp_action_ready(struct zfcp_erp_action
*act
)
68 struct zfcp_adapter
*adapter
= act
->adapter
;
70 list_move(&act
->list
, &act
->adapter
->erp_ready_head
);
71 zfcp_dbf_rec_run("erardy1", act
);
72 wake_up(&adapter
->erp_ready_wq
);
73 zfcp_dbf_rec_run("erardy2", act
);
76 static void zfcp_erp_action_dismiss(struct zfcp_erp_action
*act
)
78 act
->status
|= ZFCP_STATUS_ERP_DISMISSED
;
79 if (zfcp_erp_action_is_running(act
))
80 zfcp_erp_action_ready(act
);
83 static void zfcp_erp_action_dismiss_lun(struct scsi_device
*sdev
)
85 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
87 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
88 zfcp_erp_action_dismiss(&zfcp_sdev
->erp_action
);
91 static void zfcp_erp_action_dismiss_port(struct zfcp_port
*port
)
93 struct scsi_device
*sdev
;
95 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
96 zfcp_erp_action_dismiss(&port
->erp_action
);
98 spin_lock(port
->adapter
->scsi_host
->host_lock
);
99 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
100 if (sdev_to_zfcp(sdev
)->port
== port
)
101 zfcp_erp_action_dismiss_lun(sdev
);
102 spin_unlock(port
->adapter
->scsi_host
->host_lock
);
106 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter
*adapter
)
108 struct zfcp_port
*port
;
110 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_INUSE
)
111 zfcp_erp_action_dismiss(&adapter
->erp_action
);
113 read_lock(&adapter
->port_list_lock
);
114 list_for_each_entry(port
, &adapter
->port_list
, list
)
115 zfcp_erp_action_dismiss_port(port
);
116 read_unlock(&adapter
->port_list_lock
);
120 static enum zfcp_erp_act_type
zfcp_erp_handle_failed(
121 enum zfcp_erp_act_type want
, struct zfcp_adapter
*adapter
,
122 struct zfcp_port
*port
, struct scsi_device
*sdev
)
124 enum zfcp_erp_act_type need
= want
;
125 struct zfcp_scsi_dev
*zsdev
;
128 case ZFCP_ERP_ACTION_REOPEN_LUN
:
129 zsdev
= sdev_to_zfcp(sdev
);
130 if (atomic_read(&zsdev
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
133 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
134 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
137 case ZFCP_ERP_ACTION_REOPEN_PORT
:
138 if (atomic_read(&port
->status
) &
139 ZFCP_STATUS_COMMON_ERP_FAILED
) {
141 /* ensure propagation of failed status to new devices */
142 zfcp_erp_set_port_status(
143 port
, ZFCP_STATUS_COMMON_ERP_FAILED
);
146 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
147 if (atomic_read(&adapter
->status
) &
148 ZFCP_STATUS_COMMON_ERP_FAILED
) {
150 /* ensure propagation of failed status to new devices */
151 zfcp_erp_set_adapter_status(
152 adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
);
160 static enum zfcp_erp_act_type
zfcp_erp_required_act(enum zfcp_erp_act_type want
,
161 struct zfcp_adapter
*adapter
,
162 struct zfcp_port
*port
,
163 struct scsi_device
*sdev
)
165 enum zfcp_erp_act_type need
= want
;
166 int l_status
, p_status
, a_status
;
167 struct zfcp_scsi_dev
*zfcp_sdev
;
170 case ZFCP_ERP_ACTION_REOPEN_LUN
:
171 zfcp_sdev
= sdev_to_zfcp(sdev
);
172 l_status
= atomic_read(&zfcp_sdev
->status
);
173 if (l_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
175 p_status
= atomic_read(&port
->status
);
176 if (!(p_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
177 p_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
179 if (!(p_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
180 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
182 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
183 p_status
= atomic_read(&port
->status
);
184 if (!(p_status
& ZFCP_STATUS_COMMON_OPEN
))
185 need
= ZFCP_ERP_ACTION_REOPEN_PORT
;
187 case ZFCP_ERP_ACTION_REOPEN_PORT
:
188 p_status
= atomic_read(&port
->status
);
189 if (p_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
191 a_status
= atomic_read(&adapter
->status
);
192 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) ||
193 a_status
& ZFCP_STATUS_COMMON_ERP_FAILED
)
195 if (p_status
& ZFCP_STATUS_COMMON_NOESC
)
197 if (!(a_status
& ZFCP_STATUS_COMMON_UNBLOCKED
))
198 need
= ZFCP_ERP_ACTION_REOPEN_ADAPTER
;
200 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
201 a_status
= atomic_read(&adapter
->status
);
202 if (a_status
& ZFCP_STATUS_COMMON_ERP_INUSE
)
204 if (!(a_status
& ZFCP_STATUS_COMMON_RUNNING
) &&
205 !(a_status
& ZFCP_STATUS_COMMON_OPEN
))
206 return 0; /* shutdown requested for closed adapter */
212 static struct zfcp_erp_action
*zfcp_erp_setup_act(enum zfcp_erp_act_type need
,
214 struct zfcp_adapter
*adapter
,
215 struct zfcp_port
*port
,
216 struct scsi_device
*sdev
)
218 struct zfcp_erp_action
*erp_action
;
219 struct zfcp_scsi_dev
*zfcp_sdev
;
221 if (WARN_ON_ONCE(need
!= ZFCP_ERP_ACTION_REOPEN_LUN
&&
222 need
!= ZFCP_ERP_ACTION_REOPEN_PORT
&&
223 need
!= ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
&&
224 need
!= ZFCP_ERP_ACTION_REOPEN_ADAPTER
))
228 case ZFCP_ERP_ACTION_REOPEN_LUN
:
229 zfcp_sdev
= sdev_to_zfcp(sdev
);
230 if (!(act_status
& ZFCP_STATUS_ERP_NO_REF
))
231 if (scsi_device_get(sdev
))
233 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
,
235 erp_action
= &zfcp_sdev
->erp_action
;
236 WARN_ON_ONCE(erp_action
->port
!= port
);
237 WARN_ON_ONCE(erp_action
->sdev
!= sdev
);
238 if (!(atomic_read(&zfcp_sdev
->status
) &
239 ZFCP_STATUS_COMMON_RUNNING
))
240 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
243 case ZFCP_ERP_ACTION_REOPEN_PORT
:
244 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
245 if (!get_device(&port
->dev
))
247 zfcp_erp_action_dismiss_port(port
);
248 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
, &port
->status
);
249 erp_action
= &port
->erp_action
;
250 WARN_ON_ONCE(erp_action
->port
!= port
);
251 WARN_ON_ONCE(erp_action
->sdev
!= NULL
);
252 if (!(atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_RUNNING
))
253 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
256 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
257 kref_get(&adapter
->ref
);
258 zfcp_erp_action_dismiss_adapter(adapter
);
259 atomic_or(ZFCP_STATUS_COMMON_ERP_INUSE
, &adapter
->status
);
260 erp_action
= &adapter
->erp_action
;
261 WARN_ON_ONCE(erp_action
->port
!= NULL
);
262 WARN_ON_ONCE(erp_action
->sdev
!= NULL
);
263 if (!(atomic_read(&adapter
->status
) &
264 ZFCP_STATUS_COMMON_RUNNING
))
265 act_status
|= ZFCP_STATUS_ERP_CLOSE_ONLY
;
269 WARN_ON_ONCE(erp_action
->adapter
!= adapter
);
270 memset(&erp_action
->list
, 0, sizeof(erp_action
->list
));
271 memset(&erp_action
->timer
, 0, sizeof(erp_action
->timer
));
272 erp_action
->step
= ZFCP_ERP_STEP_UNINITIALIZED
;
273 erp_action
->fsf_req_id
= 0;
274 erp_action
->type
= need
;
275 erp_action
->status
= act_status
;
280 static void zfcp_erp_action_enqueue(enum zfcp_erp_act_type want
,
281 struct zfcp_adapter
*adapter
,
282 struct zfcp_port
*port
,
283 struct scsi_device
*sdev
,
284 char *dbftag
, u32 act_status
)
286 enum zfcp_erp_act_type need
;
287 struct zfcp_erp_action
*act
;
289 need
= zfcp_erp_handle_failed(want
, adapter
, port
, sdev
);
291 need
= ZFCP_ERP_ACTION_FAILED
; /* marker for trace */
295 if (!adapter
->erp_thread
) {
296 need
= ZFCP_ERP_ACTION_NONE
; /* marker for trace */
300 need
= zfcp_erp_required_act(want
, adapter
, port
, sdev
);
304 act
= zfcp_erp_setup_act(need
, act_status
, adapter
, port
, sdev
);
306 need
|= ZFCP_ERP_ACTION_NONE
; /* marker for trace */
309 atomic_or(ZFCP_STATUS_ADAPTER_ERP_PENDING
, &adapter
->status
);
310 ++adapter
->erp_total_count
;
311 list_add_tail(&act
->list
, &adapter
->erp_ready_head
);
312 wake_up(&adapter
->erp_ready_wq
);
314 zfcp_dbf_rec_trig(dbftag
, adapter
, port
, sdev
, want
, need
);
317 void zfcp_erp_port_forced_no_port_dbf(char *dbftag
,
318 struct zfcp_adapter
*adapter
,
319 u64 port_name
, u32 port_id
)
322 static /* don't waste stack */ struct zfcp_port tmpport
;
324 write_lock_irqsave(&adapter
->erp_lock
, flags
);
325 /* Stand-in zfcp port with fields just good enough for
326 * zfcp_dbf_rec_trig() and zfcp_dbf_set_common().
327 * Under lock because tmpport is static.
329 atomic_set(&tmpport
.status
, -1); /* unknown */
330 tmpport
.wwpn
= port_name
;
331 tmpport
.d_id
= port_id
;
332 zfcp_dbf_rec_trig(dbftag
, adapter
, &tmpport
, NULL
,
333 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
334 ZFCP_ERP_ACTION_NONE
);
335 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
338 static void _zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
,
339 int clear_mask
, char *dbftag
)
341 zfcp_erp_adapter_block(adapter
, clear_mask
);
342 zfcp_scsi_schedule_rports_block(adapter
);
344 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
,
345 adapter
, NULL
, NULL
, dbftag
, 0);
349 * zfcp_erp_adapter_reopen - Reopen adapter.
350 * @adapter: Adapter to reopen.
351 * @clear: Status flags to clear.
352 * @dbftag: Tag for debug trace event.
354 void zfcp_erp_adapter_reopen(struct zfcp_adapter
*adapter
, int clear
,
359 zfcp_erp_adapter_block(adapter
, clear
);
360 zfcp_scsi_schedule_rports_block(adapter
);
362 write_lock_irqsave(&adapter
->erp_lock
, flags
);
363 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER
, adapter
,
364 NULL
, NULL
, dbftag
, 0);
365 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
369 * zfcp_erp_adapter_shutdown - Shutdown adapter.
370 * @adapter: Adapter to shut down.
371 * @clear: Status flags to clear.
372 * @dbftag: Tag for debug trace event.
374 void zfcp_erp_adapter_shutdown(struct zfcp_adapter
*adapter
, int clear
,
377 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
378 zfcp_erp_adapter_reopen(adapter
, clear
| flags
, dbftag
);
382 * zfcp_erp_port_shutdown - Shutdown port
383 * @port: Port to shut down.
384 * @clear: Status flags to clear.
385 * @dbftag: Tag for debug trace event.
387 void zfcp_erp_port_shutdown(struct zfcp_port
*port
, int clear
, char *dbftag
)
389 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
390 zfcp_erp_port_reopen(port
, clear
| flags
, dbftag
);
393 static void zfcp_erp_port_block(struct zfcp_port
*port
, int clear
)
395 zfcp_erp_clear_port_status(port
,
396 ZFCP_STATUS_COMMON_UNBLOCKED
| clear
);
399 static void _zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
,
402 zfcp_erp_port_block(port
, clear
);
403 zfcp_scsi_schedule_rport_block(port
);
405 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
,
406 port
->adapter
, port
, NULL
, dbftag
, 0);
410 * zfcp_erp_port_forced_reopen - Forced close of port and open again
411 * @port: Port to force close and to reopen.
412 * @clear: Status flags to clear.
413 * @dbftag: Tag for debug trace event.
415 void zfcp_erp_port_forced_reopen(struct zfcp_port
*port
, int clear
,
419 struct zfcp_adapter
*adapter
= port
->adapter
;
421 write_lock_irqsave(&adapter
->erp_lock
, flags
);
422 _zfcp_erp_port_forced_reopen(port
, clear
, dbftag
);
423 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
426 static void _zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
,
429 zfcp_erp_port_block(port
, clear
);
430 zfcp_scsi_schedule_rport_block(port
);
432 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT
,
433 port
->adapter
, port
, NULL
, dbftag
, 0);
437 * zfcp_erp_port_reopen - trigger remote port recovery
438 * @port: port to recover
439 * @clear: flags in port status to be cleared
440 * @dbftag: Tag for debug trace event.
442 void zfcp_erp_port_reopen(struct zfcp_port
*port
, int clear
, char *dbftag
)
445 struct zfcp_adapter
*adapter
= port
->adapter
;
447 write_lock_irqsave(&adapter
->erp_lock
, flags
);
448 _zfcp_erp_port_reopen(port
, clear
, dbftag
);
449 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
452 static void zfcp_erp_lun_block(struct scsi_device
*sdev
, int clear_mask
)
454 zfcp_erp_clear_lun_status(sdev
,
455 ZFCP_STATUS_COMMON_UNBLOCKED
| clear_mask
);
458 static void _zfcp_erp_lun_reopen(struct scsi_device
*sdev
, int clear
,
459 char *dbftag
, u32 act_status
)
461 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
462 struct zfcp_adapter
*adapter
= zfcp_sdev
->port
->adapter
;
464 zfcp_erp_lun_block(sdev
, clear
);
466 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_LUN
, adapter
,
467 zfcp_sdev
->port
, sdev
, dbftag
, act_status
);
471 * zfcp_erp_lun_reopen - initiate reopen of a LUN
472 * @sdev: SCSI device / LUN to be reopened
473 * @clear: specifies flags in LUN status to be cleared
474 * @dbftag: Tag for debug trace event.
476 * Return: 0 on success, < 0 on error
478 void zfcp_erp_lun_reopen(struct scsi_device
*sdev
, int clear
, char *dbftag
)
481 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
482 struct zfcp_port
*port
= zfcp_sdev
->port
;
483 struct zfcp_adapter
*adapter
= port
->adapter
;
485 write_lock_irqsave(&adapter
->erp_lock
, flags
);
486 _zfcp_erp_lun_reopen(sdev
, clear
, dbftag
, 0);
487 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
491 * zfcp_erp_lun_shutdown - Shutdown LUN
492 * @sdev: SCSI device / LUN to shut down.
493 * @clear: Status flags to clear.
494 * @dbftag: Tag for debug trace event.
496 void zfcp_erp_lun_shutdown(struct scsi_device
*sdev
, int clear
, char *dbftag
)
498 int flags
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
499 zfcp_erp_lun_reopen(sdev
, clear
| flags
, dbftag
);
503 * zfcp_erp_lun_shutdown_wait - Shutdown LUN and wait for erp completion
504 * @sdev: SCSI device / LUN to shut down.
505 * @dbftag: Tag for debug trace event.
507 * Do not acquire a reference for the LUN when creating the ERP
508 * action. It is safe, because this function waits for the ERP to
509 * complete first. This allows to shutdown the LUN, even when the SCSI
510 * device is in the state SDEV_DEL when scsi_device_get will fail.
512 void zfcp_erp_lun_shutdown_wait(struct scsi_device
*sdev
, char *dbftag
)
515 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
516 struct zfcp_port
*port
= zfcp_sdev
->port
;
517 struct zfcp_adapter
*adapter
= port
->adapter
;
518 int clear
= ZFCP_STATUS_COMMON_RUNNING
| ZFCP_STATUS_COMMON_ERP_FAILED
;
520 write_lock_irqsave(&adapter
->erp_lock
, flags
);
521 _zfcp_erp_lun_reopen(sdev
, clear
, dbftag
, ZFCP_STATUS_ERP_NO_REF
);
522 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
524 zfcp_erp_wait(adapter
);
527 static int zfcp_erp_status_change_set(unsigned long mask
, atomic_t
*status
)
529 return (atomic_read(status
) ^ mask
) & mask
;
532 static void zfcp_erp_adapter_unblock(struct zfcp_adapter
*adapter
)
534 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
536 zfcp_dbf_rec_run("eraubl1", &adapter
->erp_action
);
537 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &adapter
->status
);
540 static void zfcp_erp_port_unblock(struct zfcp_port
*port
)
542 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
544 zfcp_dbf_rec_run("erpubl1", &port
->erp_action
);
545 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &port
->status
);
548 static void zfcp_erp_lun_unblock(struct scsi_device
*sdev
)
550 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
552 if (zfcp_erp_status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED
,
554 zfcp_dbf_rec_run("erlubl1", &sdev_to_zfcp(sdev
)->erp_action
);
555 atomic_or(ZFCP_STATUS_COMMON_UNBLOCKED
, &zfcp_sdev
->status
);
558 static void zfcp_erp_action_to_running(struct zfcp_erp_action
*erp_action
)
560 list_move(&erp_action
->list
, &erp_action
->adapter
->erp_running_head
);
561 zfcp_dbf_rec_run("erator1", erp_action
);
564 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action
*act
)
566 struct zfcp_adapter
*adapter
= act
->adapter
;
567 struct zfcp_fsf_req
*req
;
569 if (!act
->fsf_req_id
)
572 spin_lock(&adapter
->req_list
->lock
);
573 req
= _zfcp_reqlist_find(adapter
->req_list
, act
->fsf_req_id
);
574 if (req
&& req
->erp_action
== act
) {
575 if (act
->status
& (ZFCP_STATUS_ERP_DISMISSED
|
576 ZFCP_STATUS_ERP_TIMEDOUT
)) {
577 req
->status
|= ZFCP_STATUS_FSFREQ_DISMISSED
;
578 zfcp_dbf_rec_run("erscf_1", act
);
579 req
->erp_action
= NULL
;
581 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
582 zfcp_dbf_rec_run("erscf_2", act
);
583 if (req
->status
& ZFCP_STATUS_FSFREQ_DISMISSED
)
587 spin_unlock(&adapter
->req_list
->lock
);
591 * zfcp_erp_notify - Trigger ERP action.
592 * @erp_action: ERP action to continue.
593 * @set_mask: ERP action status flags to set.
595 void zfcp_erp_notify(struct zfcp_erp_action
*erp_action
, unsigned long set_mask
)
597 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
600 write_lock_irqsave(&adapter
->erp_lock
, flags
);
601 if (zfcp_erp_action_is_running(erp_action
)) {
602 erp_action
->status
|= set_mask
;
603 zfcp_erp_action_ready(erp_action
);
605 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
609 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
610 * @t: timer list entry embedded in zfcp FSF request
612 void zfcp_erp_timeout_handler(struct timer_list
*t
)
614 struct zfcp_fsf_req
*fsf_req
= from_timer(fsf_req
, t
, timer
);
615 struct zfcp_erp_action
*act
= fsf_req
->erp_action
;
617 zfcp_erp_notify(act
, ZFCP_STATUS_ERP_TIMEDOUT
);
620 static void zfcp_erp_memwait_handler(struct timer_list
*t
)
622 struct zfcp_erp_action
*act
= from_timer(act
, t
, timer
);
624 zfcp_erp_notify(act
, 0);
627 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action
*erp_action
)
629 timer_setup(&erp_action
->timer
, zfcp_erp_memwait_handler
, 0);
630 erp_action
->timer
.expires
= jiffies
+ HZ
;
631 add_timer(&erp_action
->timer
);
634 void zfcp_erp_port_forced_reopen_all(struct zfcp_adapter
*adapter
,
635 int clear
, char *dbftag
)
638 struct zfcp_port
*port
;
640 write_lock_irqsave(&adapter
->erp_lock
, flags
);
641 read_lock(&adapter
->port_list_lock
);
642 list_for_each_entry(port
, &adapter
->port_list
, list
)
643 _zfcp_erp_port_forced_reopen(port
, clear
, dbftag
);
644 read_unlock(&adapter
->port_list_lock
);
645 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
648 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter
*adapter
,
649 int clear
, char *dbftag
)
651 struct zfcp_port
*port
;
653 read_lock(&adapter
->port_list_lock
);
654 list_for_each_entry(port
, &adapter
->port_list
, list
)
655 _zfcp_erp_port_reopen(port
, clear
, dbftag
);
656 read_unlock(&adapter
->port_list_lock
);
659 static void _zfcp_erp_lun_reopen_all(struct zfcp_port
*port
, int clear
,
662 struct scsi_device
*sdev
;
664 spin_lock(port
->adapter
->scsi_host
->host_lock
);
665 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
666 if (sdev_to_zfcp(sdev
)->port
== port
)
667 _zfcp_erp_lun_reopen(sdev
, clear
, dbftag
, 0);
668 spin_unlock(port
->adapter
->scsi_host
->host_lock
);
671 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action
*act
)
674 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
675 _zfcp_erp_adapter_reopen(act
->adapter
, 0, "ersff_1");
677 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
678 _zfcp_erp_port_forced_reopen(act
->port
, 0, "ersff_2");
680 case ZFCP_ERP_ACTION_REOPEN_PORT
:
681 _zfcp_erp_port_reopen(act
->port
, 0, "ersff_3");
683 case ZFCP_ERP_ACTION_REOPEN_LUN
:
684 _zfcp_erp_lun_reopen(act
->sdev
, 0, "ersff_4", 0);
689 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action
*act
)
692 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
693 _zfcp_erp_port_reopen_all(act
->adapter
, 0, "ersfs_1");
695 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
696 _zfcp_erp_port_reopen(act
->port
, 0, "ersfs_2");
698 case ZFCP_ERP_ACTION_REOPEN_PORT
:
699 _zfcp_erp_lun_reopen_all(act
->port
, 0, "ersfs_3");
701 case ZFCP_ERP_ACTION_REOPEN_LUN
:
707 static void zfcp_erp_wakeup(struct zfcp_adapter
*adapter
)
711 read_lock_irqsave(&adapter
->erp_lock
, flags
);
712 if (list_empty(&adapter
->erp_ready_head
) &&
713 list_empty(&adapter
->erp_running_head
)) {
714 atomic_andnot(ZFCP_STATUS_ADAPTER_ERP_PENDING
,
716 wake_up(&adapter
->erp_done_wqh
);
718 read_unlock_irqrestore(&adapter
->erp_lock
, flags
);
721 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter
*adapter
)
723 struct zfcp_port
*port
;
724 port
= zfcp_port_enqueue(adapter
, adapter
->peer_wwpn
, 0,
726 if (IS_ERR(port
)) /* error or port already attached */
728 _zfcp_erp_port_reopen(port
, 0, "ereptp1");
731 static enum zfcp_erp_act_result
zfcp_erp_adapter_strat_fsf_xconf(
732 struct zfcp_erp_action
*erp_action
)
736 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
738 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
, &adapter
->status
);
740 for (retries
= 7; retries
; retries
--) {
741 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
743 write_lock_irq(&adapter
->erp_lock
);
744 zfcp_erp_action_to_running(erp_action
);
745 write_unlock_irq(&adapter
->erp_lock
);
746 if (zfcp_fsf_exchange_config_data(erp_action
)) {
747 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
749 return ZFCP_ERP_FAILED
;
752 wait_event(adapter
->erp_ready_wq
,
753 !list_empty(&adapter
->erp_ready_head
));
754 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
757 if (!(atomic_read(&adapter
->status
) &
758 ZFCP_STATUS_ADAPTER_HOST_CON_INIT
))
765 atomic_andnot(ZFCP_STATUS_ADAPTER_HOST_CON_INIT
,
768 if (!(atomic_read(&adapter
->status
) & ZFCP_STATUS_ADAPTER_XCONFIG_OK
))
769 return ZFCP_ERP_FAILED
;
771 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
772 zfcp_erp_enqueue_ptp_port(adapter
);
774 return ZFCP_ERP_SUCCEEDED
;
777 static enum zfcp_erp_act_result
zfcp_erp_adapter_strategy_open_fsf_xport(
778 struct zfcp_erp_action
*act
)
781 struct zfcp_adapter
*adapter
= act
->adapter
;
783 write_lock_irq(&adapter
->erp_lock
);
784 zfcp_erp_action_to_running(act
);
785 write_unlock_irq(&adapter
->erp_lock
);
787 ret
= zfcp_fsf_exchange_port_data(act
);
788 if (ret
== -EOPNOTSUPP
)
789 return ZFCP_ERP_SUCCEEDED
;
791 return ZFCP_ERP_FAILED
;
793 zfcp_dbf_rec_run("erasox1", act
);
794 wait_event(adapter
->erp_ready_wq
,
795 !list_empty(&adapter
->erp_ready_head
));
796 zfcp_dbf_rec_run("erasox2", act
);
797 if (act
->status
& ZFCP_STATUS_ERP_TIMEDOUT
)
798 return ZFCP_ERP_FAILED
;
800 return ZFCP_ERP_SUCCEEDED
;
803 static enum zfcp_erp_act_result
zfcp_erp_adapter_strategy_open_fsf(
804 struct zfcp_erp_action
*act
)
806 if (zfcp_erp_adapter_strat_fsf_xconf(act
) == ZFCP_ERP_FAILED
)
807 return ZFCP_ERP_FAILED
;
809 if (zfcp_erp_adapter_strategy_open_fsf_xport(act
) == ZFCP_ERP_FAILED
)
810 return ZFCP_ERP_FAILED
;
812 if (mempool_resize(act
->adapter
->pool
.sr_data
,
813 act
->adapter
->stat_read_buf_num
))
814 return ZFCP_ERP_FAILED
;
816 if (mempool_resize(act
->adapter
->pool
.status_read_req
,
817 act
->adapter
->stat_read_buf_num
))
818 return ZFCP_ERP_FAILED
;
820 atomic_set(&act
->adapter
->stat_miss
, act
->adapter
->stat_read_buf_num
);
821 if (zfcp_status_read_refill(act
->adapter
))
822 return ZFCP_ERP_FAILED
;
824 return ZFCP_ERP_SUCCEEDED
;
827 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action
*act
)
829 struct zfcp_adapter
*adapter
= act
->adapter
;
831 /* close queues to ensure that buffers are not accessed by adapter */
832 zfcp_qdio_close(adapter
->qdio
);
833 zfcp_fsf_req_dismiss_all(adapter
);
834 adapter
->fsf_req_seq_no
= 0;
835 zfcp_fc_wka_ports_force_offline(adapter
->gs
);
836 /* all ports and LUNs are closed */
837 zfcp_erp_clear_adapter_status(adapter
, ZFCP_STATUS_COMMON_OPEN
);
839 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
840 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
, &adapter
->status
);
843 static enum zfcp_erp_act_result
zfcp_erp_adapter_strategy_open(
844 struct zfcp_erp_action
*act
)
846 struct zfcp_adapter
*adapter
= act
->adapter
;
848 if (zfcp_qdio_open(adapter
->qdio
)) {
849 atomic_andnot(ZFCP_STATUS_ADAPTER_XCONFIG_OK
|
850 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
,
852 return ZFCP_ERP_FAILED
;
855 if (zfcp_erp_adapter_strategy_open_fsf(act
)) {
856 zfcp_erp_adapter_strategy_close(act
);
857 return ZFCP_ERP_FAILED
;
860 atomic_or(ZFCP_STATUS_COMMON_OPEN
, &adapter
->status
);
862 return ZFCP_ERP_SUCCEEDED
;
865 static enum zfcp_erp_act_result
zfcp_erp_adapter_strategy(
866 struct zfcp_erp_action
*act
)
868 struct zfcp_adapter
*adapter
= act
->adapter
;
870 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_OPEN
) {
871 zfcp_erp_adapter_strategy_close(act
);
872 if (act
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
873 return ZFCP_ERP_EXIT
;
876 if (zfcp_erp_adapter_strategy_open(act
)) {
878 return ZFCP_ERP_FAILED
;
881 return ZFCP_ERP_SUCCEEDED
;
884 static enum zfcp_erp_act_result
zfcp_erp_port_forced_strategy_close(
885 struct zfcp_erp_action
*act
)
889 retval
= zfcp_fsf_close_physical_port(act
);
890 if (retval
== -ENOMEM
)
891 return ZFCP_ERP_NOMEM
;
892 act
->step
= ZFCP_ERP_STEP_PHYS_PORT_CLOSING
;
894 return ZFCP_ERP_FAILED
;
896 return ZFCP_ERP_CONTINUES
;
899 static enum zfcp_erp_act_result
zfcp_erp_port_forced_strategy(
900 struct zfcp_erp_action
*erp_action
)
902 struct zfcp_port
*port
= erp_action
->port
;
903 int status
= atomic_read(&port
->status
);
905 switch (erp_action
->step
) {
906 case ZFCP_ERP_STEP_UNINITIALIZED
:
907 if ((status
& ZFCP_STATUS_PORT_PHYS_OPEN
) &&
908 (status
& ZFCP_STATUS_COMMON_OPEN
))
909 return zfcp_erp_port_forced_strategy_close(erp_action
);
911 return ZFCP_ERP_FAILED
;
913 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
914 if (!(status
& ZFCP_STATUS_PORT_PHYS_OPEN
))
915 return ZFCP_ERP_SUCCEEDED
;
917 case ZFCP_ERP_STEP_PORT_CLOSING
:
918 case ZFCP_ERP_STEP_PORT_OPENING
:
919 case ZFCP_ERP_STEP_LUN_CLOSING
:
920 case ZFCP_ERP_STEP_LUN_OPENING
:
924 return ZFCP_ERP_FAILED
;
927 static enum zfcp_erp_act_result
zfcp_erp_port_strategy_close(
928 struct zfcp_erp_action
*erp_action
)
932 retval
= zfcp_fsf_close_port(erp_action
);
933 if (retval
== -ENOMEM
)
934 return ZFCP_ERP_NOMEM
;
935 erp_action
->step
= ZFCP_ERP_STEP_PORT_CLOSING
;
937 return ZFCP_ERP_FAILED
;
938 return ZFCP_ERP_CONTINUES
;
941 static enum zfcp_erp_act_result
zfcp_erp_port_strategy_open_port(
942 struct zfcp_erp_action
*erp_action
)
946 retval
= zfcp_fsf_open_port(erp_action
);
947 if (retval
== -ENOMEM
)
948 return ZFCP_ERP_NOMEM
;
949 erp_action
->step
= ZFCP_ERP_STEP_PORT_OPENING
;
951 return ZFCP_ERP_FAILED
;
952 return ZFCP_ERP_CONTINUES
;
955 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action
*act
)
957 struct zfcp_adapter
*adapter
= act
->adapter
;
958 struct zfcp_port
*port
= act
->port
;
960 if (port
->wwpn
!= adapter
->peer_wwpn
) {
961 zfcp_erp_set_port_status(port
, ZFCP_STATUS_COMMON_ERP_FAILED
);
962 return ZFCP_ERP_FAILED
;
964 port
->d_id
= adapter
->peer_d_id
;
965 return zfcp_erp_port_strategy_open_port(act
);
968 static enum zfcp_erp_act_result
zfcp_erp_port_strategy_open_common(
969 struct zfcp_erp_action
*act
)
971 struct zfcp_adapter
*adapter
= act
->adapter
;
972 struct zfcp_port
*port
= act
->port
;
973 int p_status
= atomic_read(&port
->status
);
976 case ZFCP_ERP_STEP_UNINITIALIZED
:
977 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
978 case ZFCP_ERP_STEP_PORT_CLOSING
:
979 if (fc_host_port_type(adapter
->scsi_host
) == FC_PORTTYPE_PTP
)
980 return zfcp_erp_open_ptp_port(act
);
982 zfcp_fc_trigger_did_lookup(port
);
983 return ZFCP_ERP_EXIT
;
985 return zfcp_erp_port_strategy_open_port(act
);
987 case ZFCP_ERP_STEP_PORT_OPENING
:
988 /* D_ID might have changed during open */
989 if (p_status
& ZFCP_STATUS_COMMON_OPEN
) {
991 zfcp_fc_trigger_did_lookup(port
);
992 return ZFCP_ERP_EXIT
;
994 return ZFCP_ERP_SUCCEEDED
;
996 if (port
->d_id
&& !(p_status
& ZFCP_STATUS_COMMON_NOESC
)) {
998 return ZFCP_ERP_FAILED
;
1000 /* no early return otherwise, continue after switch case */
1002 case ZFCP_ERP_STEP_LUN_CLOSING
:
1003 case ZFCP_ERP_STEP_LUN_OPENING
:
1007 return ZFCP_ERP_FAILED
;
1010 static enum zfcp_erp_act_result
zfcp_erp_port_strategy(
1011 struct zfcp_erp_action
*erp_action
)
1013 struct zfcp_port
*port
= erp_action
->port
;
1014 int p_status
= atomic_read(&port
->status
);
1016 if ((p_status
& ZFCP_STATUS_COMMON_NOESC
) &&
1017 !(p_status
& ZFCP_STATUS_COMMON_OPEN
))
1018 goto close_init_done
;
1020 switch (erp_action
->step
) {
1021 case ZFCP_ERP_STEP_UNINITIALIZED
:
1022 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
1023 return zfcp_erp_port_strategy_close(erp_action
);
1026 case ZFCP_ERP_STEP_PORT_CLOSING
:
1027 if (p_status
& ZFCP_STATUS_COMMON_OPEN
)
1028 return ZFCP_ERP_FAILED
;
1030 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
1031 case ZFCP_ERP_STEP_PORT_OPENING
:
1032 case ZFCP_ERP_STEP_LUN_CLOSING
:
1033 case ZFCP_ERP_STEP_LUN_OPENING
:
1039 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
1040 return ZFCP_ERP_EXIT
;
1042 return zfcp_erp_port_strategy_open_common(erp_action
);
1045 static void zfcp_erp_lun_strategy_clearstati(struct scsi_device
*sdev
)
1047 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1049 atomic_andnot(ZFCP_STATUS_COMMON_ACCESS_DENIED
,
1050 &zfcp_sdev
->status
);
1053 static enum zfcp_erp_act_result
zfcp_erp_lun_strategy_close(
1054 struct zfcp_erp_action
*erp_action
)
1056 int retval
= zfcp_fsf_close_lun(erp_action
);
1057 if (retval
== -ENOMEM
)
1058 return ZFCP_ERP_NOMEM
;
1059 erp_action
->step
= ZFCP_ERP_STEP_LUN_CLOSING
;
1061 return ZFCP_ERP_FAILED
;
1062 return ZFCP_ERP_CONTINUES
;
1065 static enum zfcp_erp_act_result
zfcp_erp_lun_strategy_open(
1066 struct zfcp_erp_action
*erp_action
)
1068 int retval
= zfcp_fsf_open_lun(erp_action
);
1069 if (retval
== -ENOMEM
)
1070 return ZFCP_ERP_NOMEM
;
1071 erp_action
->step
= ZFCP_ERP_STEP_LUN_OPENING
;
1073 return ZFCP_ERP_FAILED
;
1074 return ZFCP_ERP_CONTINUES
;
1077 static enum zfcp_erp_act_result
zfcp_erp_lun_strategy(
1078 struct zfcp_erp_action
*erp_action
)
1080 struct scsi_device
*sdev
= erp_action
->sdev
;
1081 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1083 switch (erp_action
->step
) {
1084 case ZFCP_ERP_STEP_UNINITIALIZED
:
1085 zfcp_erp_lun_strategy_clearstati(sdev
);
1086 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1087 return zfcp_erp_lun_strategy_close(erp_action
);
1088 /* already closed */
1090 case ZFCP_ERP_STEP_LUN_CLOSING
:
1091 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1092 return ZFCP_ERP_FAILED
;
1093 if (erp_action
->status
& ZFCP_STATUS_ERP_CLOSE_ONLY
)
1094 return ZFCP_ERP_EXIT
;
1095 return zfcp_erp_lun_strategy_open(erp_action
);
1097 case ZFCP_ERP_STEP_LUN_OPENING
:
1098 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_OPEN
)
1099 return ZFCP_ERP_SUCCEEDED
;
1101 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING
:
1102 case ZFCP_ERP_STEP_PORT_CLOSING
:
1103 case ZFCP_ERP_STEP_PORT_OPENING
:
1107 return ZFCP_ERP_FAILED
;
1110 static enum zfcp_erp_act_result
zfcp_erp_strategy_check_lun(
1111 struct scsi_device
*sdev
, enum zfcp_erp_act_result result
)
1113 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1116 case ZFCP_ERP_SUCCEEDED
:
1117 atomic_set(&zfcp_sdev
->erp_counter
, 0);
1118 zfcp_erp_lun_unblock(sdev
);
1120 case ZFCP_ERP_FAILED
:
1121 atomic_inc(&zfcp_sdev
->erp_counter
);
1122 if (atomic_read(&zfcp_sdev
->erp_counter
) > ZFCP_MAX_ERPS
) {
1123 dev_err(&zfcp_sdev
->port
->adapter
->ccw_device
->dev
,
1124 "ERP failed for LUN 0x%016Lx on "
1126 (unsigned long long)zfcp_scsi_dev_lun(sdev
),
1127 (unsigned long long)zfcp_sdev
->port
->wwpn
);
1128 zfcp_erp_set_lun_status(sdev
,
1129 ZFCP_STATUS_COMMON_ERP_FAILED
);
1132 case ZFCP_ERP_CONTINUES
:
1134 case ZFCP_ERP_DISMISSED
:
1135 case ZFCP_ERP_NOMEM
:
1140 if (atomic_read(&zfcp_sdev
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1141 zfcp_erp_lun_block(sdev
, 0);
1142 result
= ZFCP_ERP_EXIT
;
1147 static enum zfcp_erp_act_result
zfcp_erp_strategy_check_port(
1148 struct zfcp_port
*port
, enum zfcp_erp_act_result result
)
1151 case ZFCP_ERP_SUCCEEDED
:
1152 atomic_set(&port
->erp_counter
, 0);
1153 zfcp_erp_port_unblock(port
);
1156 case ZFCP_ERP_FAILED
:
1157 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_NOESC
) {
1158 zfcp_erp_port_block(port
, 0);
1159 result
= ZFCP_ERP_EXIT
;
1161 atomic_inc(&port
->erp_counter
);
1162 if (atomic_read(&port
->erp_counter
) > ZFCP_MAX_ERPS
) {
1163 dev_err(&port
->adapter
->ccw_device
->dev
,
1164 "ERP failed for remote port 0x%016Lx\n",
1165 (unsigned long long)port
->wwpn
);
1166 zfcp_erp_set_port_status(port
,
1167 ZFCP_STATUS_COMMON_ERP_FAILED
);
1170 case ZFCP_ERP_CONTINUES
:
1172 case ZFCP_ERP_DISMISSED
:
1173 case ZFCP_ERP_NOMEM
:
1178 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1179 zfcp_erp_port_block(port
, 0);
1180 result
= ZFCP_ERP_EXIT
;
1185 static enum zfcp_erp_act_result
zfcp_erp_strategy_check_adapter(
1186 struct zfcp_adapter
*adapter
, enum zfcp_erp_act_result result
)
1189 case ZFCP_ERP_SUCCEEDED
:
1190 atomic_set(&adapter
->erp_counter
, 0);
1191 zfcp_erp_adapter_unblock(adapter
);
1194 case ZFCP_ERP_FAILED
:
1195 atomic_inc(&adapter
->erp_counter
);
1196 if (atomic_read(&adapter
->erp_counter
) > ZFCP_MAX_ERPS
) {
1197 dev_err(&adapter
->ccw_device
->dev
,
1198 "ERP cannot recover an error "
1199 "on the FCP device\n");
1200 zfcp_erp_set_adapter_status(adapter
,
1201 ZFCP_STATUS_COMMON_ERP_FAILED
);
1204 case ZFCP_ERP_CONTINUES
:
1206 case ZFCP_ERP_DISMISSED
:
1207 case ZFCP_ERP_NOMEM
:
1212 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
) {
1213 zfcp_erp_adapter_block(adapter
, 0);
1214 result
= ZFCP_ERP_EXIT
;
1219 static enum zfcp_erp_act_result
zfcp_erp_strategy_check_target(
1220 struct zfcp_erp_action
*erp_action
, enum zfcp_erp_act_result result
)
1222 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1223 struct zfcp_port
*port
= erp_action
->port
;
1224 struct scsi_device
*sdev
= erp_action
->sdev
;
1226 switch (erp_action
->type
) {
1228 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1229 result
= zfcp_erp_strategy_check_lun(sdev
, result
);
1232 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1233 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1234 result
= zfcp_erp_strategy_check_port(port
, result
);
1237 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1238 result
= zfcp_erp_strategy_check_adapter(adapter
, result
);
1244 static int zfcp_erp_strat_change_det(atomic_t
*target_status
, u32 erp_status
)
1246 int status
= atomic_read(target_status
);
1248 if ((status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1249 (erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1250 return 1; /* take it online */
1252 if (!(status
& ZFCP_STATUS_COMMON_RUNNING
) &&
1253 !(erp_status
& ZFCP_STATUS_ERP_CLOSE_ONLY
))
1254 return 1; /* take it offline */
1259 static enum zfcp_erp_act_result
zfcp_erp_strategy_statechange(
1260 struct zfcp_erp_action
*act
, enum zfcp_erp_act_result result
)
1262 enum zfcp_erp_act_type type
= act
->type
;
1263 struct zfcp_adapter
*adapter
= act
->adapter
;
1264 struct zfcp_port
*port
= act
->port
;
1265 struct scsi_device
*sdev
= act
->sdev
;
1266 struct zfcp_scsi_dev
*zfcp_sdev
;
1267 u32 erp_status
= act
->status
;
1270 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1271 if (zfcp_erp_strat_change_det(&adapter
->status
, erp_status
)) {
1272 _zfcp_erp_adapter_reopen(adapter
,
1273 ZFCP_STATUS_COMMON_ERP_FAILED
,
1275 return ZFCP_ERP_EXIT
;
1279 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1280 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1281 if (zfcp_erp_strat_change_det(&port
->status
, erp_status
)) {
1282 _zfcp_erp_port_reopen(port
,
1283 ZFCP_STATUS_COMMON_ERP_FAILED
,
1285 return ZFCP_ERP_EXIT
;
1289 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1290 zfcp_sdev
= sdev_to_zfcp(sdev
);
1291 if (zfcp_erp_strat_change_det(&zfcp_sdev
->status
, erp_status
)) {
1292 _zfcp_erp_lun_reopen(sdev
,
1293 ZFCP_STATUS_COMMON_ERP_FAILED
,
1295 return ZFCP_ERP_EXIT
;
1302 static void zfcp_erp_action_dequeue(struct zfcp_erp_action
*erp_action
)
1304 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1305 struct zfcp_scsi_dev
*zfcp_sdev
;
1307 adapter
->erp_total_count
--;
1308 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1309 adapter
->erp_low_mem_count
--;
1310 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1313 list_del(&erp_action
->list
);
1314 zfcp_dbf_rec_run("eractd1", erp_action
);
1316 switch (erp_action
->type
) {
1317 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1318 zfcp_sdev
= sdev_to_zfcp(erp_action
->sdev
);
1319 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1320 &zfcp_sdev
->status
);
1323 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1324 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1325 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1326 &erp_action
->port
->status
);
1329 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1330 atomic_andnot(ZFCP_STATUS_COMMON_ERP_INUSE
,
1331 &erp_action
->adapter
->status
);
1337 * zfcp_erp_try_rport_unblock - unblock rport if no more/new recovery
1338 * @port: zfcp_port whose fc_rport we should try to unblock
1340 static void zfcp_erp_try_rport_unblock(struct zfcp_port
*port
)
1342 unsigned long flags
;
1343 struct zfcp_adapter
*adapter
= port
->adapter
;
1345 struct Scsi_Host
*shost
= adapter
->scsi_host
;
1346 struct scsi_device
*sdev
;
1348 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1349 port_status
= atomic_read(&port
->status
);
1350 if ((port_status
& ZFCP_STATUS_COMMON_UNBLOCKED
) == 0 ||
1351 (port_status
& (ZFCP_STATUS_COMMON_ERP_INUSE
|
1352 ZFCP_STATUS_COMMON_ERP_FAILED
)) != 0) {
1353 /* new ERP of severity >= port triggered elsewhere meanwhile or
1354 * local link down (adapter erp_failed but not clear unblock)
1356 zfcp_dbf_rec_run_lvl(4, "ertru_p", &port
->erp_action
);
1357 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1360 spin_lock(shost
->host_lock
);
1361 __shost_for_each_device(sdev
, shost
) {
1362 struct zfcp_scsi_dev
*zsdev
= sdev_to_zfcp(sdev
);
1365 if (sdev
->sdev_state
== SDEV_DEL
||
1366 sdev
->sdev_state
== SDEV_CANCEL
)
1368 if (zsdev
->port
!= port
)
1370 /* LUN under port of interest */
1371 lun_status
= atomic_read(&zsdev
->status
);
1372 if ((lun_status
& ZFCP_STATUS_COMMON_ERP_FAILED
) != 0)
1373 continue; /* unblock rport despite failed LUNs */
1374 /* LUN recovery not given up yet [maybe follow-up pending] */
1375 if ((lun_status
& ZFCP_STATUS_COMMON_UNBLOCKED
) == 0 ||
1376 (lun_status
& ZFCP_STATUS_COMMON_ERP_INUSE
) != 0) {
1378 * not yet unblocked [LUN recovery pending]
1379 * or meanwhile blocked [new LUN recovery triggered]
1381 zfcp_dbf_rec_run_lvl(4, "ertru_l", &zsdev
->erp_action
);
1382 spin_unlock(shost
->host_lock
);
1383 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1387 /* now port has no child or all children have completed recovery,
1388 * and no ERP of severity >= port was meanwhile triggered elsewhere
1390 zfcp_scsi_schedule_rport_register(port
);
1391 spin_unlock(shost
->host_lock
);
1392 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1395 static void zfcp_erp_action_cleanup(struct zfcp_erp_action
*act
,
1396 enum zfcp_erp_act_result result
)
1398 struct zfcp_adapter
*adapter
= act
->adapter
;
1399 struct zfcp_port
*port
= act
->port
;
1400 struct scsi_device
*sdev
= act
->sdev
;
1402 switch (act
->type
) {
1403 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1404 if (!(act
->status
& ZFCP_STATUS_ERP_NO_REF
))
1405 scsi_device_put(sdev
);
1406 zfcp_erp_try_rport_unblock(port
);
1409 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1410 /* This switch case might also happen after a forced reopen
1411 * was successfully done and thus overwritten with a new
1412 * non-forced reopen at `ersfs_2'. In this case, we must not
1413 * do the clean-up of the non-forced version.
1415 if (act
->step
!= ZFCP_ERP_STEP_UNINITIALIZED
)
1416 if (result
== ZFCP_ERP_SUCCEEDED
)
1417 zfcp_erp_try_rport_unblock(port
);
1419 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1420 put_device(&port
->dev
);
1423 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1424 if (result
== ZFCP_ERP_SUCCEEDED
) {
1425 register_service_level(&adapter
->service_level
);
1426 zfcp_fc_conditional_port_scan(adapter
);
1427 queue_work(adapter
->work_queue
, &adapter
->ns_up_work
);
1429 unregister_service_level(&adapter
->service_level
);
1431 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1436 static enum zfcp_erp_act_result
zfcp_erp_strategy_do_action(
1437 struct zfcp_erp_action
*erp_action
)
1439 switch (erp_action
->type
) {
1440 case ZFCP_ERP_ACTION_REOPEN_ADAPTER
:
1441 return zfcp_erp_adapter_strategy(erp_action
);
1442 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED
:
1443 return zfcp_erp_port_forced_strategy(erp_action
);
1444 case ZFCP_ERP_ACTION_REOPEN_PORT
:
1445 return zfcp_erp_port_strategy(erp_action
);
1446 case ZFCP_ERP_ACTION_REOPEN_LUN
:
1447 return zfcp_erp_lun_strategy(erp_action
);
1449 return ZFCP_ERP_FAILED
;
1452 static enum zfcp_erp_act_result
zfcp_erp_strategy(
1453 struct zfcp_erp_action
*erp_action
)
1455 enum zfcp_erp_act_result result
;
1456 unsigned long flags
;
1457 struct zfcp_adapter
*adapter
= erp_action
->adapter
;
1459 kref_get(&adapter
->ref
);
1461 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1462 zfcp_erp_strategy_check_fsfreq(erp_action
);
1464 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
) {
1465 zfcp_erp_action_dequeue(erp_action
);
1466 result
= ZFCP_ERP_DISMISSED
;
1470 if (erp_action
->status
& ZFCP_STATUS_ERP_TIMEDOUT
) {
1471 result
= ZFCP_ERP_FAILED
;
1475 zfcp_erp_action_to_running(erp_action
);
1477 /* no lock to allow for blocking operations */
1478 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1479 result
= zfcp_erp_strategy_do_action(erp_action
);
1480 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1482 if (erp_action
->status
& ZFCP_STATUS_ERP_DISMISSED
)
1483 result
= ZFCP_ERP_CONTINUES
;
1486 case ZFCP_ERP_NOMEM
:
1487 if (!(erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
)) {
1488 ++adapter
->erp_low_mem_count
;
1489 erp_action
->status
|= ZFCP_STATUS_ERP_LOWMEM
;
1491 if (adapter
->erp_total_count
== adapter
->erp_low_mem_count
)
1492 _zfcp_erp_adapter_reopen(adapter
, 0, "erstgy1");
1494 zfcp_erp_strategy_memwait(erp_action
);
1495 result
= ZFCP_ERP_CONTINUES
;
1499 case ZFCP_ERP_CONTINUES
:
1500 if (erp_action
->status
& ZFCP_STATUS_ERP_LOWMEM
) {
1501 --adapter
->erp_low_mem_count
;
1502 erp_action
->status
&= ~ZFCP_STATUS_ERP_LOWMEM
;
1505 case ZFCP_ERP_SUCCEEDED
:
1506 case ZFCP_ERP_FAILED
:
1508 case ZFCP_ERP_DISMISSED
:
1514 result
= zfcp_erp_strategy_check_target(erp_action
, result
);
1515 zfcp_erp_action_dequeue(erp_action
);
1516 result
= zfcp_erp_strategy_statechange(erp_action
, result
);
1517 if (result
== ZFCP_ERP_EXIT
)
1519 if (result
== ZFCP_ERP_SUCCEEDED
)
1520 zfcp_erp_strategy_followup_success(erp_action
);
1521 if (result
== ZFCP_ERP_FAILED
)
1522 zfcp_erp_strategy_followup_failed(erp_action
);
1525 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1527 if (result
!= ZFCP_ERP_CONTINUES
)
1528 zfcp_erp_action_cleanup(erp_action
, result
);
1530 kref_put(&adapter
->ref
, zfcp_adapter_release
);
1534 static int zfcp_erp_thread(void *data
)
1536 struct zfcp_adapter
*adapter
= (struct zfcp_adapter
*) data
;
1537 struct list_head
*next
;
1538 struct zfcp_erp_action
*act
;
1539 unsigned long flags
;
1542 wait_event_interruptible(adapter
->erp_ready_wq
,
1543 !list_empty(&adapter
->erp_ready_head
) ||
1544 kthread_should_stop());
1546 if (kthread_should_stop())
1549 write_lock_irqsave(&adapter
->erp_lock
, flags
);
1550 next
= adapter
->erp_ready_head
.next
;
1551 write_unlock_irqrestore(&adapter
->erp_lock
, flags
);
1553 if (next
!= &adapter
->erp_ready_head
) {
1554 act
= list_entry(next
, struct zfcp_erp_action
, list
);
1556 /* there is more to come after dismission, no notify */
1557 if (zfcp_erp_strategy(act
) != ZFCP_ERP_DISMISSED
)
1558 zfcp_erp_wakeup(adapter
);
1566 * zfcp_erp_thread_setup - Start ERP thread for adapter
1567 * @adapter: Adapter to start the ERP thread for
1569 * Return: 0 on success, or error code from kthread_run().
1571 int zfcp_erp_thread_setup(struct zfcp_adapter
*adapter
)
1573 struct task_struct
*thread
;
1575 thread
= kthread_run(zfcp_erp_thread
, adapter
, "zfcperp%s",
1576 dev_name(&adapter
->ccw_device
->dev
));
1577 if (IS_ERR(thread
)) {
1578 dev_err(&adapter
->ccw_device
->dev
,
1579 "Creating an ERP thread for the FCP device failed.\n");
1580 return PTR_ERR(thread
);
1583 adapter
->erp_thread
= thread
;
1588 * zfcp_erp_thread_kill - Stop ERP thread.
1589 * @adapter: Adapter where the ERP thread should be stopped.
1591 * The caller of this routine ensures that the specified adapter has
1592 * been shut down and that this operation has been completed. Thus,
1593 * there are no pending erp_actions which would need to be handled
1596 void zfcp_erp_thread_kill(struct zfcp_adapter
*adapter
)
1598 kthread_stop(adapter
->erp_thread
);
1599 adapter
->erp_thread
= NULL
;
1600 WARN_ON(!list_empty(&adapter
->erp_ready_head
));
1601 WARN_ON(!list_empty(&adapter
->erp_running_head
));
1605 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1606 * @adapter: adapter for which to wait for completion of its error recovery
1608 void zfcp_erp_wait(struct zfcp_adapter
*adapter
)
1610 wait_event(adapter
->erp_done_wqh
,
1611 !(atomic_read(&adapter
->status
) &
1612 ZFCP_STATUS_ADAPTER_ERP_PENDING
));
1616 * zfcp_erp_set_adapter_status - set adapter status bits
1617 * @adapter: adapter to change the status
1618 * @mask: status bits to change
1620 * Changes in common status bits are propagated to attached ports and LUNs.
1622 void zfcp_erp_set_adapter_status(struct zfcp_adapter
*adapter
, u32 mask
)
1624 struct zfcp_port
*port
;
1625 struct scsi_device
*sdev
;
1626 unsigned long flags
;
1627 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1629 atomic_or(mask
, &adapter
->status
);
1634 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1635 list_for_each_entry(port
, &adapter
->port_list
, list
)
1636 atomic_or(common_mask
, &port
->status
);
1637 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1639 spin_lock_irqsave(adapter
->scsi_host
->host_lock
, flags
);
1640 __shost_for_each_device(sdev
, adapter
->scsi_host
)
1641 atomic_or(common_mask
, &sdev_to_zfcp(sdev
)->status
);
1642 spin_unlock_irqrestore(adapter
->scsi_host
->host_lock
, flags
);
1646 * zfcp_erp_clear_adapter_status - clear adapter status bits
1647 * @adapter: adapter to change the status
1648 * @mask: status bits to change
1650 * Changes in common status bits are propagated to attached ports and LUNs.
1652 void zfcp_erp_clear_adapter_status(struct zfcp_adapter
*adapter
, u32 mask
)
1654 struct zfcp_port
*port
;
1655 struct scsi_device
*sdev
;
1656 unsigned long flags
;
1657 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1658 u32 clear_counter
= mask
& ZFCP_STATUS_COMMON_ERP_FAILED
;
1660 atomic_andnot(mask
, &adapter
->status
);
1666 atomic_set(&adapter
->erp_counter
, 0);
1668 read_lock_irqsave(&adapter
->port_list_lock
, flags
);
1669 list_for_each_entry(port
, &adapter
->port_list
, list
) {
1670 atomic_andnot(common_mask
, &port
->status
);
1672 atomic_set(&port
->erp_counter
, 0);
1674 read_unlock_irqrestore(&adapter
->port_list_lock
, flags
);
1676 spin_lock_irqsave(adapter
->scsi_host
->host_lock
, flags
);
1677 __shost_for_each_device(sdev
, adapter
->scsi_host
) {
1678 atomic_andnot(common_mask
, &sdev_to_zfcp(sdev
)->status
);
1680 atomic_set(&sdev_to_zfcp(sdev
)->erp_counter
, 0);
1682 spin_unlock_irqrestore(adapter
->scsi_host
->host_lock
, flags
);
1686 * zfcp_erp_set_port_status - set port status bits
1687 * @port: port to change the status
1688 * @mask: status bits to change
1690 * Changes in common status bits are propagated to attached LUNs.
1692 void zfcp_erp_set_port_status(struct zfcp_port
*port
, u32 mask
)
1694 struct scsi_device
*sdev
;
1695 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1696 unsigned long flags
;
1698 atomic_or(mask
, &port
->status
);
1703 spin_lock_irqsave(port
->adapter
->scsi_host
->host_lock
, flags
);
1704 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
1705 if (sdev_to_zfcp(sdev
)->port
== port
)
1706 atomic_or(common_mask
,
1707 &sdev_to_zfcp(sdev
)->status
);
1708 spin_unlock_irqrestore(port
->adapter
->scsi_host
->host_lock
, flags
);
1712 * zfcp_erp_clear_port_status - clear port status bits
1713 * @port: adapter to change the status
1714 * @mask: status bits to change
1716 * Changes in common status bits are propagated to attached LUNs.
1718 void zfcp_erp_clear_port_status(struct zfcp_port
*port
, u32 mask
)
1720 struct scsi_device
*sdev
;
1721 u32 common_mask
= mask
& ZFCP_COMMON_FLAGS
;
1722 u32 clear_counter
= mask
& ZFCP_STATUS_COMMON_ERP_FAILED
;
1723 unsigned long flags
;
1725 atomic_andnot(mask
, &port
->status
);
1731 atomic_set(&port
->erp_counter
, 0);
1733 spin_lock_irqsave(port
->adapter
->scsi_host
->host_lock
, flags
);
1734 __shost_for_each_device(sdev
, port
->adapter
->scsi_host
)
1735 if (sdev_to_zfcp(sdev
)->port
== port
) {
1736 atomic_andnot(common_mask
,
1737 &sdev_to_zfcp(sdev
)->status
);
1739 atomic_set(&sdev_to_zfcp(sdev
)->erp_counter
, 0);
1741 spin_unlock_irqrestore(port
->adapter
->scsi_host
->host_lock
, flags
);
1745 * zfcp_erp_set_lun_status - set lun status bits
1746 * @sdev: SCSI device / lun to set the status bits
1747 * @mask: status bits to change
1749 void zfcp_erp_set_lun_status(struct scsi_device
*sdev
, u32 mask
)
1751 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1753 atomic_or(mask
, &zfcp_sdev
->status
);
1757 * zfcp_erp_clear_lun_status - clear lun status bits
1758 * @sdev: SCSi device / lun to clear the status bits
1759 * @mask: status bits to change
1761 void zfcp_erp_clear_lun_status(struct scsi_device
*sdev
, u32 mask
)
1763 struct zfcp_scsi_dev
*zfcp_sdev
= sdev_to_zfcp(sdev
);
1765 atomic_andnot(mask
, &zfcp_sdev
->status
);
1767 if (mask
& ZFCP_STATUS_COMMON_ERP_FAILED
)
1768 atomic_set(&zfcp_sdev
->erp_counter
, 0);
1772 * zfcp_erp_adapter_reset_sync() - Really reopen adapter and wait.
1773 * @adapter: Pointer to zfcp_adapter to reopen.
1774 * @dbftag: Trace tag string of length %ZFCP_DBF_TAG_LEN.
1776 void zfcp_erp_adapter_reset_sync(struct zfcp_adapter
*adapter
, char *dbftag
)
1778 zfcp_erp_set_adapter_status(adapter
, ZFCP_STATUS_COMMON_RUNNING
);
1779 zfcp_erp_adapter_reopen(adapter
, ZFCP_STATUS_COMMON_ERP_FAILED
, dbftag
);
1780 zfcp_erp_wait(adapter
);