4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2009
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #define ZFCP_MAX_ERPS 3
16 enum zfcp_erp_act_flags {
17 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
18 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
19 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
20 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
21 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
25 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
26 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
27 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
28 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
29 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
30 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
31 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
34 enum zfcp_erp_act_type {
35 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
36 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
37 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
38 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
41 enum zfcp_erp_act_state {
42 ZFCP_ERP_ACTION_RUNNING = 1,
43 ZFCP_ERP_ACTION_READY = 2,
46 enum zfcp_erp_act_result {
47 ZFCP_ERP_SUCCEEDED = 0,
49 ZFCP_ERP_CONTINUES = 2,
51 ZFCP_ERP_DISMISSED = 4,
55 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
57 zfcp_erp_modify_adapter_status(adapter, "erablk1", NULL,
58 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
62 static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
64 struct zfcp_erp_action *curr_act;
66 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
68 return ZFCP_ERP_ACTION_RUNNING;
72 static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
74 struct zfcp_adapter *adapter = act->adapter;
76 list_move(&act->list, &act->adapter->erp_ready_head);
77 zfcp_rec_dbf_event_action("erardy1", act);
78 up(&adapter->erp_ready_sem);
79 zfcp_rec_dbf_event_thread("erardy2", adapter);
82 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
84 act->status |= ZFCP_STATUS_ERP_DISMISSED;
85 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
86 zfcp_erp_action_ready(act);
89 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
91 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
92 zfcp_erp_action_dismiss(&unit->erp_action);
95 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
97 struct zfcp_unit *unit;
99 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
100 zfcp_erp_action_dismiss(&port->erp_action);
102 list_for_each_entry(unit, &port->unit_list_head, list)
103 zfcp_erp_action_dismiss_unit(unit);
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 list_for_each_entry(port, &adapter->port_list_head, list)
114 zfcp_erp_action_dismiss_port(port);
117 static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
118 struct zfcp_port *port,
119 struct zfcp_unit *unit)
122 int u_status, p_status, a_status;
125 case ZFCP_ERP_ACTION_REOPEN_UNIT:
126 u_status = atomic_read(&unit->status);
127 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
129 p_status = atomic_read(&port->status);
130 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
131 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
133 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
134 need = ZFCP_ERP_ACTION_REOPEN_PORT;
136 case ZFCP_ERP_ACTION_REOPEN_PORT:
137 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
138 p_status = atomic_read(&port->status);
139 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
141 a_status = atomic_read(&adapter->status);
142 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
143 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
145 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
146 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
148 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
149 a_status = atomic_read(&adapter->status);
150 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
157 static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
158 struct zfcp_adapter *adapter,
159 struct zfcp_port *port,
160 struct zfcp_unit *unit)
162 struct zfcp_erp_action *erp_action;
166 case ZFCP_ERP_ACTION_REOPEN_UNIT:
168 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
169 erp_action = &unit->erp_action;
170 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
171 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
174 case ZFCP_ERP_ACTION_REOPEN_PORT:
175 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
177 zfcp_erp_action_dismiss_port(port);
178 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
179 erp_action = &port->erp_action;
180 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
181 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
184 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
185 zfcp_adapter_get(adapter);
186 zfcp_erp_action_dismiss_adapter(adapter);
187 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
188 erp_action = &adapter->erp_action;
189 if (!(atomic_read(&adapter->status) &
190 ZFCP_STATUS_COMMON_RUNNING))
191 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
198 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
199 erp_action->adapter = adapter;
200 erp_action->port = port;
201 erp_action->unit = unit;
202 erp_action->action = need;
203 erp_action->status = status;
208 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
209 struct zfcp_port *port,
210 struct zfcp_unit *unit, char *id, void *ref)
212 int retval = 1, need;
213 struct zfcp_erp_action *act = NULL;
215 if (!(atomic_read(&adapter->status) &
216 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
219 need = zfcp_erp_required_act(want, adapter, port, unit);
223 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
224 act = zfcp_erp_setup_act(need, adapter, port, unit);
227 ++adapter->erp_total_count;
228 list_add_tail(&act->list, &adapter->erp_ready_head);
229 up(&adapter->erp_ready_sem);
230 zfcp_rec_dbf_event_thread("eracte1", adapter);
233 zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
234 adapter, port, unit);
238 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
239 int clear_mask, char *id, void *ref)
241 zfcp_erp_adapter_block(adapter, clear_mask);
242 zfcp_scsi_schedule_rports_block(adapter);
244 /* ensure propagation of failed status to new devices */
245 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
246 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
249 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
250 adapter, NULL, NULL, id, ref);
254 * zfcp_erp_adapter_reopen - Reopen adapter.
255 * @adapter: Adapter to reopen.
256 * @clear: Status flags to clear.
257 * @id: Id for debug trace event.
258 * @ref: Reference for debug trace event.
260 void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
265 read_lock_irqsave(&zfcp_data.config_lock, flags);
266 write_lock(&adapter->erp_lock);
267 _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
268 write_unlock(&adapter->erp_lock);
269 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
273 * zfcp_erp_adapter_shutdown - Shutdown adapter.
274 * @adapter: Adapter to shut down.
275 * @clear: Status flags to clear.
276 * @id: Id for debug trace event.
277 * @ref: Reference for debug trace event.
279 void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
282 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
283 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
287 * zfcp_erp_port_shutdown - Shutdown port
288 * @port: Port to shut down.
289 * @clear: Status flags to clear.
290 * @id: Id for debug trace event.
291 * @ref: Reference for debug trace event.
293 void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
296 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
297 zfcp_erp_port_reopen(port, clear | flags, id, ref);
301 * zfcp_erp_unit_shutdown - Shutdown unit
302 * @unit: Unit to shut down.
303 * @clear: Status flags to clear.
304 * @id: Id for debug trace event.
305 * @ref: Reference for debug trace event.
307 void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
310 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
311 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
314 static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
316 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
317 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
321 static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
322 int clear, char *id, void *ref)
324 zfcp_erp_port_block(port, clear);
325 zfcp_scsi_schedule_rport_block(port);
327 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
330 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
331 port->adapter, port, NULL, id, ref);
335 * zfcp_erp_port_forced_reopen - Forced close of port and open again
336 * @port: Port to force close and to reopen.
337 * @id: Id for debug trace event.
338 * @ref: Reference for debug trace event.
340 void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
344 struct zfcp_adapter *adapter = port->adapter;
346 read_lock_irqsave(&zfcp_data.config_lock, flags);
347 write_lock(&adapter->erp_lock);
348 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
349 write_unlock(&adapter->erp_lock);
350 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
353 static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
356 zfcp_erp_port_block(port, clear);
357 zfcp_scsi_schedule_rport_block(port);
359 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
360 /* ensure propagation of failed status to new devices */
361 zfcp_erp_port_failed(port, "erpreo1", NULL);
365 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
366 port->adapter, port, NULL, id, ref);
370 * zfcp_erp_port_reopen - trigger remote port recovery
371 * @port: port to recover
372 * @clear_mask: flags in port status to be cleared
374 * Returns 0 if recovery has been triggered, < 0 if not.
376 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
380 struct zfcp_adapter *adapter = port->adapter;
382 read_lock_irqsave(&zfcp_data.config_lock, flags);
383 write_lock(&adapter->erp_lock);
384 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
385 write_unlock(&adapter->erp_lock);
386 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
391 static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
393 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
394 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
398 static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
401 struct zfcp_adapter *adapter = unit->port->adapter;
403 zfcp_erp_unit_block(unit, clear);
405 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
408 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
409 adapter, unit->port, unit, id, ref);
413 * zfcp_erp_unit_reopen - initiate reopen of a unit
414 * @unit: unit to be reopened
415 * @clear_mask: specifies flags in unit status to be cleared
416 * Return: 0 on success, < 0 on error
418 void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
422 struct zfcp_port *port = unit->port;
423 struct zfcp_adapter *adapter = port->adapter;
425 read_lock_irqsave(&zfcp_data.config_lock, flags);
426 write_lock(&adapter->erp_lock);
427 _zfcp_erp_unit_reopen(unit, clear, id, ref);
428 write_unlock(&adapter->erp_lock);
429 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
432 static int status_change_set(unsigned long mask, atomic_t *status)
434 return (atomic_read(status) ^ mask) & mask;
437 static int status_change_clear(unsigned long mask, atomic_t *status)
439 return atomic_read(status) & mask;
442 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
444 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
445 zfcp_rec_dbf_event_adapter("eraubl1", NULL, adapter);
446 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
449 static void zfcp_erp_port_unblock(struct zfcp_port *port)
451 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
452 zfcp_rec_dbf_event_port("erpubl1", NULL, port);
453 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
456 static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
458 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
459 zfcp_rec_dbf_event_unit("eruubl1", NULL, unit);
460 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
463 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
465 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
466 zfcp_rec_dbf_event_action("erator1", erp_action);
469 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
471 struct zfcp_adapter *adapter = act->adapter;
476 spin_lock(&adapter->req_list_lock);
477 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
478 act->fsf_req->erp_action == act) {
479 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
480 ZFCP_STATUS_ERP_TIMEDOUT)) {
481 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
482 zfcp_rec_dbf_event_action("erscf_1", act);
483 act->fsf_req->erp_action = NULL;
485 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
486 zfcp_rec_dbf_event_action("erscf_2", act);
487 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
491 spin_unlock(&adapter->req_list_lock);
495 * zfcp_erp_notify - Trigger ERP action.
496 * @erp_action: ERP action to continue.
497 * @set_mask: ERP action status flags to set.
499 void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
501 struct zfcp_adapter *adapter = erp_action->adapter;
504 write_lock_irqsave(&adapter->erp_lock, flags);
505 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
506 erp_action->status |= set_mask;
507 zfcp_erp_action_ready(erp_action);
509 write_unlock_irqrestore(&adapter->erp_lock, flags);
513 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
514 * @data: ERP action (from timer data)
516 void zfcp_erp_timeout_handler(unsigned long data)
518 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
519 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
522 static void zfcp_erp_memwait_handler(unsigned long data)
524 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
527 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
529 init_timer(&erp_action->timer);
530 erp_action->timer.function = zfcp_erp_memwait_handler;
531 erp_action->timer.data = (unsigned long) erp_action;
532 erp_action->timer.expires = jiffies + HZ;
533 add_timer(&erp_action->timer);
536 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
537 int clear, char *id, void *ref)
539 struct zfcp_port *port;
541 list_for_each_entry(port, &adapter->port_list_head, list)
542 _zfcp_erp_port_reopen(port, clear, id, ref);
545 static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
548 struct zfcp_unit *unit;
550 list_for_each_entry(unit, &port->unit_list_head, list)
551 _zfcp_erp_unit_reopen(unit, clear, id, ref);
554 static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
556 switch (act->action) {
557 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
558 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
560 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
561 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
563 case ZFCP_ERP_ACTION_REOPEN_PORT:
564 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
566 case ZFCP_ERP_ACTION_REOPEN_UNIT:
567 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
572 static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
574 switch (act->action) {
575 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
576 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
578 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
579 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
581 case ZFCP_ERP_ACTION_REOPEN_PORT:
582 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
587 static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
591 read_lock_irqsave(&zfcp_data.config_lock, flags);
592 read_lock(&adapter->erp_lock);
593 if (list_empty(&adapter->erp_ready_head) &&
594 list_empty(&adapter->erp_running_head)) {
595 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
597 wake_up(&adapter->erp_done_wqh);
599 read_unlock(&adapter->erp_lock);
600 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
603 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
605 struct zfcp_qdio *qdio = act->adapter->qdio;
607 if (zfcp_qdio_open(qdio))
608 return ZFCP_ERP_FAILED;
609 init_waitqueue_head(&qdio->req_q_wq);
610 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
611 return ZFCP_ERP_SUCCEEDED;
614 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
616 struct zfcp_port *port;
617 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
619 if (IS_ERR(port)) /* error or port already attached */
621 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
624 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
628 struct zfcp_adapter *adapter = erp_action->adapter;
630 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
632 for (retries = 7; retries; retries--) {
633 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
635 write_lock_irq(&adapter->erp_lock);
636 zfcp_erp_action_to_running(erp_action);
637 write_unlock_irq(&adapter->erp_lock);
638 if (zfcp_fsf_exchange_config_data(erp_action)) {
639 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
641 return ZFCP_ERP_FAILED;
644 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter);
645 down(&adapter->erp_ready_sem);
646 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter);
647 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
650 if (!(atomic_read(&adapter->status) &
651 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
658 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
661 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
662 return ZFCP_ERP_FAILED;
664 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
665 zfcp_erp_enqueue_ptp_port(adapter);
667 return ZFCP_ERP_SUCCEEDED;
670 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
673 struct zfcp_adapter *adapter = act->adapter;
675 write_lock_irq(&adapter->erp_lock);
676 zfcp_erp_action_to_running(act);
677 write_unlock_irq(&adapter->erp_lock);
679 ret = zfcp_fsf_exchange_port_data(act);
680 if (ret == -EOPNOTSUPP)
681 return ZFCP_ERP_SUCCEEDED;
683 return ZFCP_ERP_FAILED;
685 zfcp_rec_dbf_event_thread_lock("erasox1", adapter);
686 down(&adapter->erp_ready_sem);
687 zfcp_rec_dbf_event_thread_lock("erasox2", adapter);
688 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
689 return ZFCP_ERP_FAILED;
691 return ZFCP_ERP_SUCCEEDED;
694 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
696 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
697 return ZFCP_ERP_FAILED;
699 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
700 return ZFCP_ERP_FAILED;
702 atomic_set(&act->adapter->stat_miss, 16);
703 if (zfcp_status_read_refill(act->adapter))
704 return ZFCP_ERP_FAILED;
706 return ZFCP_ERP_SUCCEEDED;
709 static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
711 struct zfcp_adapter *adapter = act->adapter;
713 /* close queues to ensure that buffers are not accessed by adapter */
714 zfcp_qdio_close(adapter->qdio);
715 zfcp_fsf_req_dismiss_all(adapter);
716 adapter->fsf_req_seq_no = 0;
717 zfcp_fc_wka_ports_force_offline(adapter->gs);
718 /* all ports and units are closed */
719 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
720 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
722 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
723 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
726 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
728 struct zfcp_adapter *adapter = act->adapter;
730 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
731 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
732 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
734 return ZFCP_ERP_FAILED;
737 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
738 zfcp_erp_adapter_strategy_close(act);
739 return ZFCP_ERP_FAILED;
742 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
744 return ZFCP_ERP_SUCCEEDED;
747 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
749 struct zfcp_adapter *adapter = act->adapter;
751 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
752 zfcp_erp_adapter_strategy_close(act);
753 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
754 return ZFCP_ERP_EXIT;
757 if (zfcp_erp_adapter_strategy_open(act)) {
759 return ZFCP_ERP_FAILED;
762 return ZFCP_ERP_SUCCEEDED;
765 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
769 retval = zfcp_fsf_close_physical_port(act);
770 if (retval == -ENOMEM)
771 return ZFCP_ERP_NOMEM;
772 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
774 return ZFCP_ERP_FAILED;
776 return ZFCP_ERP_CONTINUES;
779 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
781 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
784 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
786 struct zfcp_port *port = erp_action->port;
787 int status = atomic_read(&port->status);
789 switch (erp_action->step) {
790 case ZFCP_ERP_STEP_UNINITIALIZED:
791 zfcp_erp_port_strategy_clearstati(port);
792 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
793 (status & ZFCP_STATUS_COMMON_OPEN))
794 return zfcp_erp_port_forced_strategy_close(erp_action);
796 return ZFCP_ERP_FAILED;
798 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
799 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
800 return ZFCP_ERP_SUCCEEDED;
802 return ZFCP_ERP_FAILED;
805 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
809 retval = zfcp_fsf_close_port(erp_action);
810 if (retval == -ENOMEM)
811 return ZFCP_ERP_NOMEM;
812 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
814 return ZFCP_ERP_FAILED;
815 return ZFCP_ERP_CONTINUES;
818 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
822 retval = zfcp_fsf_open_port(erp_action);
823 if (retval == -ENOMEM)
824 return ZFCP_ERP_NOMEM;
825 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
827 return ZFCP_ERP_FAILED;
828 return ZFCP_ERP_CONTINUES;
831 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
833 struct zfcp_adapter *adapter = act->adapter;
834 struct zfcp_port *port = act->port;
836 if (port->wwpn != adapter->peer_wwpn) {
837 zfcp_erp_port_failed(port, "eroptp1", NULL);
838 return ZFCP_ERP_FAILED;
840 port->d_id = adapter->peer_d_id;
841 return zfcp_erp_port_strategy_open_port(act);
844 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
846 struct zfcp_adapter *adapter = act->adapter;
847 struct zfcp_port *port = act->port;
848 int p_status = atomic_read(&port->status);
851 case ZFCP_ERP_STEP_UNINITIALIZED:
852 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
853 case ZFCP_ERP_STEP_PORT_CLOSING:
854 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
855 return zfcp_erp_open_ptp_port(act);
858 if (!queue_work(adapter->work_queue,
861 return ZFCP_ERP_EXIT;
863 return zfcp_erp_port_strategy_open_port(act);
865 case ZFCP_ERP_STEP_PORT_OPENING:
866 /* D_ID might have changed during open */
867 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
869 return ZFCP_ERP_SUCCEEDED;
871 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
872 return ZFCP_ERP_CONTINUES;
875 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
877 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
878 return ZFCP_ERP_EXIT;
880 /* fall through otherwise */
882 return ZFCP_ERP_FAILED;
885 static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
887 struct zfcp_port *port = erp_action->port;
889 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
890 goto close_init_done;
892 switch (erp_action->step) {
893 case ZFCP_ERP_STEP_UNINITIALIZED:
894 zfcp_erp_port_strategy_clearstati(port);
895 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
896 return zfcp_erp_port_strategy_close(erp_action);
899 case ZFCP_ERP_STEP_PORT_CLOSING:
900 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
901 return ZFCP_ERP_FAILED;
906 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
907 return ZFCP_ERP_EXIT;
909 return zfcp_erp_port_strategy_open_common(erp_action);
912 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
914 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
915 ZFCP_STATUS_UNIT_SHARED |
916 ZFCP_STATUS_UNIT_READONLY,
920 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
922 int retval = zfcp_fsf_close_unit(erp_action);
923 if (retval == -ENOMEM)
924 return ZFCP_ERP_NOMEM;
925 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
927 return ZFCP_ERP_FAILED;
928 return ZFCP_ERP_CONTINUES;
931 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
933 int retval = zfcp_fsf_open_unit(erp_action);
934 if (retval == -ENOMEM)
935 return ZFCP_ERP_NOMEM;
936 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
938 return ZFCP_ERP_FAILED;
939 return ZFCP_ERP_CONTINUES;
942 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
944 struct zfcp_unit *unit = erp_action->unit;
946 switch (erp_action->step) {
947 case ZFCP_ERP_STEP_UNINITIALIZED:
948 zfcp_erp_unit_strategy_clearstati(unit);
949 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
950 return zfcp_erp_unit_strategy_close(erp_action);
951 /* already closed, fall through */
952 case ZFCP_ERP_STEP_UNIT_CLOSING:
953 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
954 return ZFCP_ERP_FAILED;
955 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
956 return ZFCP_ERP_EXIT;
957 return zfcp_erp_unit_strategy_open(erp_action);
959 case ZFCP_ERP_STEP_UNIT_OPENING:
960 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
961 return ZFCP_ERP_SUCCEEDED;
963 return ZFCP_ERP_FAILED;
966 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
969 case ZFCP_ERP_SUCCEEDED :
970 atomic_set(&unit->erp_counter, 0);
971 zfcp_erp_unit_unblock(unit);
973 case ZFCP_ERP_FAILED :
974 atomic_inc(&unit->erp_counter);
975 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
976 dev_err(&unit->port->adapter->ccw_device->dev,
977 "ERP failed for unit 0x%016Lx on "
979 (unsigned long long)unit->fcp_lun,
980 (unsigned long long)unit->port->wwpn);
981 zfcp_erp_unit_failed(unit, "erusck1", NULL);
986 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
987 zfcp_erp_unit_block(unit, 0);
988 result = ZFCP_ERP_EXIT;
993 static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
996 case ZFCP_ERP_SUCCEEDED :
997 atomic_set(&port->erp_counter, 0);
998 zfcp_erp_port_unblock(port);
1001 case ZFCP_ERP_FAILED :
1002 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1003 zfcp_erp_port_block(port, 0);
1004 result = ZFCP_ERP_EXIT;
1006 atomic_inc(&port->erp_counter);
1007 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1008 dev_err(&port->adapter->ccw_device->dev,
1009 "ERP failed for remote port 0x%016Lx\n",
1010 (unsigned long long)port->wwpn);
1011 zfcp_erp_port_failed(port, "erpsck1", NULL);
1016 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1017 zfcp_erp_port_block(port, 0);
1018 result = ZFCP_ERP_EXIT;
1023 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1027 case ZFCP_ERP_SUCCEEDED :
1028 atomic_set(&adapter->erp_counter, 0);
1029 zfcp_erp_adapter_unblock(adapter);
1032 case ZFCP_ERP_FAILED :
1033 atomic_inc(&adapter->erp_counter);
1034 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1035 dev_err(&adapter->ccw_device->dev,
1036 "ERP cannot recover an error "
1037 "on the FCP device\n");
1038 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
1043 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1044 zfcp_erp_adapter_block(adapter, 0);
1045 result = ZFCP_ERP_EXIT;
1050 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1053 struct zfcp_adapter *adapter = erp_action->adapter;
1054 struct zfcp_port *port = erp_action->port;
1055 struct zfcp_unit *unit = erp_action->unit;
1057 switch (erp_action->action) {
1059 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1060 result = zfcp_erp_strategy_check_unit(unit, result);
1063 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1064 case ZFCP_ERP_ACTION_REOPEN_PORT:
1065 result = zfcp_erp_strategy_check_port(port, result);
1068 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1069 result = zfcp_erp_strategy_check_adapter(adapter, result);
1075 static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
1077 int status = atomic_read(target_status);
1079 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1080 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1081 return 1; /* take it online */
1083 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1084 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1085 return 1; /* take it offline */
1090 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1092 int action = act->action;
1093 struct zfcp_adapter *adapter = act->adapter;
1094 struct zfcp_port *port = act->port;
1095 struct zfcp_unit *unit = act->unit;
1096 u32 erp_status = act->status;
1099 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1100 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1101 _zfcp_erp_adapter_reopen(adapter,
1102 ZFCP_STATUS_COMMON_ERP_FAILED,
1104 return ZFCP_ERP_EXIT;
1108 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1109 case ZFCP_ERP_ACTION_REOPEN_PORT:
1110 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1111 _zfcp_erp_port_reopen(port,
1112 ZFCP_STATUS_COMMON_ERP_FAILED,
1114 return ZFCP_ERP_EXIT;
1118 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1119 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1120 _zfcp_erp_unit_reopen(unit,
1121 ZFCP_STATUS_COMMON_ERP_FAILED,
1123 return ZFCP_ERP_EXIT;
1130 static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
1132 struct zfcp_adapter *adapter = erp_action->adapter;
1134 adapter->erp_total_count--;
1135 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1136 adapter->erp_low_mem_count--;
1137 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1140 list_del(&erp_action->list);
1141 zfcp_rec_dbf_event_action("eractd1", erp_action);
1143 switch (erp_action->action) {
1144 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1145 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1146 &erp_action->unit->status);
1149 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1150 case ZFCP_ERP_ACTION_REOPEN_PORT:
1151 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1152 &erp_action->port->status);
1155 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1156 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1157 &erp_action->adapter->status);
1162 static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1164 struct zfcp_adapter *adapter = act->adapter;
1165 struct zfcp_port *port = act->port;
1166 struct zfcp_unit *unit = act->unit;
1168 switch (act->action) {
1169 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1170 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
1171 zfcp_unit_get(unit);
1172 if (scsi_queue_work(unit->port->adapter->scsi_host,
1173 &unit->scsi_work) <= 0)
1174 zfcp_unit_put(unit);
1176 zfcp_unit_put(unit);
1179 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1180 case ZFCP_ERP_ACTION_REOPEN_PORT:
1181 if (result == ZFCP_ERP_SUCCEEDED)
1182 zfcp_scsi_schedule_rport_register(port);
1183 zfcp_port_put(port);
1186 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1187 if (result == ZFCP_ERP_SUCCEEDED) {
1188 register_service_level(&adapter->service_level);
1189 schedule_work(&adapter->scan_work);
1191 unregister_service_level(&adapter->service_level);
1192 zfcp_adapter_put(adapter);
1197 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1199 switch (erp_action->action) {
1200 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1201 return zfcp_erp_adapter_strategy(erp_action);
1202 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1203 return zfcp_erp_port_forced_strategy(erp_action);
1204 case ZFCP_ERP_ACTION_REOPEN_PORT:
1205 return zfcp_erp_port_strategy(erp_action);
1206 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1207 return zfcp_erp_unit_strategy(erp_action);
1209 return ZFCP_ERP_FAILED;
1212 static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1215 struct zfcp_adapter *adapter = erp_action->adapter;
1216 unsigned long flags;
1218 read_lock_irqsave(&zfcp_data.config_lock, flags);
1219 write_lock(&adapter->erp_lock);
1221 zfcp_erp_strategy_check_fsfreq(erp_action);
1223 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1224 zfcp_erp_action_dequeue(erp_action);
1225 retval = ZFCP_ERP_DISMISSED;
1229 zfcp_erp_action_to_running(erp_action);
1231 /* no lock to allow for blocking operations */
1232 write_unlock(&adapter->erp_lock);
1233 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1234 retval = zfcp_erp_strategy_do_action(erp_action);
1235 read_lock_irqsave(&zfcp_data.config_lock, flags);
1236 write_lock(&adapter->erp_lock);
1238 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1239 retval = ZFCP_ERP_CONTINUES;
1242 case ZFCP_ERP_NOMEM:
1243 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1244 ++adapter->erp_low_mem_count;
1245 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1247 if (adapter->erp_total_count == adapter->erp_low_mem_count)
1248 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
1250 zfcp_erp_strategy_memwait(erp_action);
1251 retval = ZFCP_ERP_CONTINUES;
1255 case ZFCP_ERP_CONTINUES:
1256 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1257 --adapter->erp_low_mem_count;
1258 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1263 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1264 zfcp_erp_action_dequeue(erp_action);
1265 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1266 if (retval == ZFCP_ERP_EXIT)
1268 if (retval == ZFCP_ERP_SUCCEEDED)
1269 zfcp_erp_strategy_followup_success(erp_action);
1270 if (retval == ZFCP_ERP_FAILED)
1271 zfcp_erp_strategy_followup_failed(erp_action);
1274 write_unlock(&adapter->erp_lock);
1275 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1277 if (retval != ZFCP_ERP_CONTINUES)
1278 zfcp_erp_action_cleanup(erp_action, retval);
1283 static int zfcp_erp_thread(void *data)
1285 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1286 struct list_head *next;
1287 struct zfcp_erp_action *act;
1288 unsigned long flags;
1291 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
1292 /* Block all signals */
1293 siginitsetinv(¤t->blocked, 0);
1294 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1295 wake_up(&adapter->erp_thread_wqh);
1297 while (!(atomic_read(&adapter->status) &
1298 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
1300 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
1301 ignore = down_interruptible(&adapter->erp_ready_sem);
1302 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
1304 write_lock_irqsave(&adapter->erp_lock, flags);
1305 next = adapter->erp_ready_head.next;
1306 write_unlock_irqrestore(&adapter->erp_lock, flags);
1308 if (next != &adapter->erp_ready_head) {
1309 act = list_entry(next, struct zfcp_erp_action, list);
1311 /* there is more to come after dismission, no notify */
1312 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1313 zfcp_erp_wakeup(adapter);
1317 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1318 wake_up(&adapter->erp_thread_wqh);
1324 * zfcp_erp_thread_setup - Start ERP thread for adapter
1325 * @adapter: Adapter to start the ERP thread for
1327 * Returns 0 on success or error code from kernel_thread()
1329 int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1333 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1334 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1336 dev_err(&adapter->ccw_device->dev,
1337 "Creating an ERP thread for the FCP device failed.\n");
1340 wait_event(adapter->erp_thread_wqh,
1341 atomic_read(&adapter->status) &
1342 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1347 * zfcp_erp_thread_kill - Stop ERP thread.
1348 * @adapter: Adapter where the ERP thread should be stopped.
1350 * The caller of this routine ensures that the specified adapter has
1351 * been shut down and that this operation has been completed. Thus,
1352 * there are no pending erp_actions which would need to be handled
1355 void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1357 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1358 up(&adapter->erp_ready_sem);
1359 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
1361 wait_event(adapter->erp_thread_wqh,
1362 !(atomic_read(&adapter->status) &
1363 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1365 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1370 * zfcp_erp_adapter_failed - Set adapter status to failed.
1371 * @adapter: Failed adapter.
1372 * @id: Event id for debug trace.
1373 * @ref: Reference for debug trace.
1375 void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
1377 zfcp_erp_modify_adapter_status(adapter, id, ref,
1378 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1382 * zfcp_erp_port_failed - Set port status to failed.
1383 * @port: Failed port.
1384 * @id: Event id for debug trace.
1385 * @ref: Reference for debug trace.
1387 void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
1389 zfcp_erp_modify_port_status(port, id, ref,
1390 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1394 * zfcp_erp_unit_failed - Set unit status to failed.
1395 * @unit: Failed unit.
1396 * @id: Event id for debug trace.
1397 * @ref: Reference for debug trace.
1399 void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
1401 zfcp_erp_modify_unit_status(unit, id, ref,
1402 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1406 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1407 * @adapter: adapter for which to wait for completion of its error recovery
1409 void zfcp_erp_wait(struct zfcp_adapter *adapter)
1411 wait_event(adapter->erp_done_wqh,
1412 !(atomic_read(&adapter->status) &
1413 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1417 * zfcp_erp_modify_adapter_status - change adapter status bits
1418 * @adapter: adapter to change the status
1419 * @id: id for the debug trace
1420 * @ref: reference for the debug trace
1421 * @mask: status bits to change
1422 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1424 * Changes in common status bits are propagated to attached ports and units.
1426 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
1427 void *ref, u32 mask, int set_or_clear)
1429 struct zfcp_port *port;
1430 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1432 if (set_or_clear == ZFCP_SET) {
1433 if (status_change_set(mask, &adapter->status))
1434 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1435 atomic_set_mask(mask, &adapter->status);
1437 if (status_change_clear(mask, &adapter->status))
1438 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1439 atomic_clear_mask(mask, &adapter->status);
1440 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1441 atomic_set(&adapter->erp_counter, 0);
1445 list_for_each_entry(port, &adapter->port_list_head, list)
1446 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1451 * zfcp_erp_modify_port_status - change port status bits
1452 * @port: port to change the status bits
1453 * @id: id for the debug trace
1454 * @ref: reference for the debug trace
1455 * @mask: status bits to change
1456 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1458 * Changes in common status bits are propagated to attached units.
1460 void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
1461 u32 mask, int set_or_clear)
1463 struct zfcp_unit *unit;
1464 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1466 if (set_or_clear == ZFCP_SET) {
1467 if (status_change_set(mask, &port->status))
1468 zfcp_rec_dbf_event_port(id, ref, port);
1469 atomic_set_mask(mask, &port->status);
1471 if (status_change_clear(mask, &port->status))
1472 zfcp_rec_dbf_event_port(id, ref, port);
1473 atomic_clear_mask(mask, &port->status);
1474 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1475 atomic_set(&port->erp_counter, 0);
1479 list_for_each_entry(unit, &port->unit_list_head, list)
1480 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1485 * zfcp_erp_modify_unit_status - change unit status bits
1486 * @unit: unit to change the status bits
1487 * @id: id for the debug trace
1488 * @ref: reference for the debug trace
1489 * @mask: status bits to change
1490 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1492 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
1493 u32 mask, int set_or_clear)
1495 if (set_or_clear == ZFCP_SET) {
1496 if (status_change_set(mask, &unit->status))
1497 zfcp_rec_dbf_event_unit(id, ref, unit);
1498 atomic_set_mask(mask, &unit->status);
1500 if (status_change_clear(mask, &unit->status))
1501 zfcp_rec_dbf_event_unit(id, ref, unit);
1502 atomic_clear_mask(mask, &unit->status);
1503 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1504 atomic_set(&unit->erp_counter, 0);
1510 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1511 * @port: The "boxed" port.
1512 * @id: The debug trace id.
1513 * @id: Reference for the debug trace.
1515 void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
1517 unsigned long flags;
1519 read_lock_irqsave(&zfcp_data.config_lock, flags);
1520 zfcp_erp_modify_port_status(port, id, ref,
1521 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1522 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1523 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1527 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1528 * @port: The "boxed" unit.
1529 * @id: The debug trace id.
1530 * @id: Reference for the debug trace.
1532 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
1534 zfcp_erp_modify_unit_status(unit, id, ref,
1535 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1536 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1540 * zfcp_erp_port_access_denied - Adapter denied access to port.
1541 * @port: port where access has been denied
1542 * @id: id for debug trace
1543 * @ref: reference for debug trace
1545 * Since the adapter has denied access, stop using the port and the
1548 void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
1550 unsigned long flags;
1552 read_lock_irqsave(&zfcp_data.config_lock, flags);
1553 zfcp_erp_modify_port_status(port, id, ref,
1554 ZFCP_STATUS_COMMON_ERP_FAILED |
1555 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1556 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1560 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1561 * @unit: unit where access has been denied
1562 * @id: id for debug trace
1563 * @ref: reference for debug trace
1565 * Since the adapter has denied access, stop using the unit.
1567 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
1569 zfcp_erp_modify_unit_status(unit, id, ref,
1570 ZFCP_STATUS_COMMON_ERP_FAILED |
1571 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1574 static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
1577 int status = atomic_read(&unit->status);
1578 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1579 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1582 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1585 static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
1588 struct zfcp_unit *unit;
1589 int status = atomic_read(&port->status);
1591 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1592 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
1593 list_for_each_entry(unit, &port->unit_list_head, list)
1594 zfcp_erp_unit_access_changed(unit, id, ref);
1598 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1602 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1603 * @adapter: Adapter where the Access Control Table (ACT) changed
1604 * @id: Id for debug trace
1605 * @ref: Reference for debug trace
1607 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
1610 struct zfcp_port *port;
1611 unsigned long flags;
1613 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1616 read_lock_irqsave(&zfcp_data.config_lock, flags);
1617 list_for_each_entry(port, &adapter->port_list_head, list)
1618 zfcp_erp_port_access_changed(port, id, ref);
1619 read_unlock_irqrestore(&zfcp_data.config_lock, flags);