4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2008
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_NAMESERVER_LOOKUP = 0x0400,
30 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
31 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
32 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
35 enum zfcp_erp_act_type {
36 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
37 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
38 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
39 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
42 enum zfcp_erp_act_state {
43 ZFCP_ERP_ACTION_RUNNING = 1,
44 ZFCP_ERP_ACTION_READY = 2,
47 enum zfcp_erp_act_result {
48 ZFCP_ERP_SUCCEEDED = 0,
50 ZFCP_ERP_CONTINUES = 2,
52 ZFCP_ERP_DISMISSED = 4,
56 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
58 zfcp_erp_modify_adapter_status(adapter, 15, NULL,
59 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
63 static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
65 struct zfcp_erp_action *curr_act;
67 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
69 return ZFCP_ERP_ACTION_RUNNING;
73 static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
75 struct zfcp_adapter *adapter = act->adapter;
77 list_move(&act->list, &act->adapter->erp_ready_head);
78 zfcp_rec_dbf_event_action(146, act);
79 up(&adapter->erp_ready_sem);
80 zfcp_rec_dbf_event_thread(2, adapter);
83 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
85 act->status |= ZFCP_STATUS_ERP_DISMISSED;
86 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
87 zfcp_erp_action_ready(act);
90 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
92 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
93 zfcp_erp_action_dismiss(&unit->erp_action);
96 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
98 struct zfcp_unit *unit;
100 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
101 zfcp_erp_action_dismiss(&port->erp_action);
103 list_for_each_entry(unit, &port->unit_list_head, list)
104 zfcp_erp_action_dismiss_unit(unit);
107 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
109 struct zfcp_port *port;
111 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
112 zfcp_erp_action_dismiss(&adapter->erp_action);
114 list_for_each_entry(port, &adapter->port_list_head, list)
115 zfcp_erp_action_dismiss_port(port);
118 static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
119 struct zfcp_port *port,
120 struct zfcp_unit *unit)
123 int u_status, p_status, a_status;
126 case ZFCP_ERP_ACTION_REOPEN_UNIT:
127 u_status = atomic_read(&unit->status);
128 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
130 p_status = atomic_read(&port->status);
131 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
132 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
134 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
135 need = ZFCP_ERP_ACTION_REOPEN_PORT;
137 case ZFCP_ERP_ACTION_REOPEN_PORT:
138 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
139 p_status = atomic_read(&port->status);
140 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
142 a_status = atomic_read(&adapter->status);
143 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
144 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
146 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
147 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
149 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
150 a_status = atomic_read(&adapter->status);
151 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
158 static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
159 struct zfcp_adapter *adapter,
160 struct zfcp_port *port,
161 struct zfcp_unit *unit)
163 struct zfcp_erp_action *erp_action;
167 case ZFCP_ERP_ACTION_REOPEN_UNIT:
169 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
170 erp_action = &unit->erp_action;
171 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
172 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
175 case ZFCP_ERP_ACTION_REOPEN_PORT:
176 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
178 zfcp_erp_action_dismiss_port(port);
179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
180 erp_action = &port->erp_action;
181 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
182 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
185 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
186 zfcp_adapter_get(adapter);
187 zfcp_erp_action_dismiss_adapter(adapter);
188 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
189 erp_action = &adapter->erp_action;
190 if (!(atomic_read(&adapter->status) &
191 ZFCP_STATUS_COMMON_RUNNING))
192 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
199 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
200 erp_action->adapter = adapter;
201 erp_action->port = port;
202 erp_action->unit = unit;
203 erp_action->action = need;
204 erp_action->status = status;
209 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
210 struct zfcp_port *port,
211 struct zfcp_unit *unit, u8 id, void *ref)
213 int retval = 1, need;
214 struct zfcp_erp_action *act = NULL;
216 if (!(atomic_read(&adapter->status) &
217 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
220 need = zfcp_erp_required_act(want, adapter, port, unit);
224 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
225 act = zfcp_erp_setup_act(need, adapter, port, unit);
228 ++adapter->erp_total_count;
229 list_add_tail(&act->list, &adapter->erp_ready_head);
230 up(&adapter->erp_ready_sem);
231 zfcp_rec_dbf_event_thread(1, adapter);
234 zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
235 adapter, port, unit);
239 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
240 int clear_mask, u8 id, void *ref)
242 zfcp_erp_adapter_block(adapter, clear_mask);
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, 13, 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, u8 id, void *ref)
295 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
296 zfcp_erp_port_reopen(port, clear | flags, id, ref);
300 * zfcp_erp_unit_shutdown - Shutdown unit
301 * @unit: Unit to shut down.
302 * @clear: Status flags to clear.
303 * @id: Id for debug trace event.
304 * @ref: Reference for debug trace event.
306 void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
308 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
309 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
312 static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
314 zfcp_erp_modify_port_status(port, 17, NULL,
315 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
319 static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
320 int clear, u8 id, void *ref)
322 zfcp_erp_port_block(port, clear);
324 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
327 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
328 port->adapter, port, NULL, id, ref);
332 * zfcp_erp_port_forced_reopen - Forced close of port and open again
333 * @port: Port to force close and to reopen.
334 * @id: Id for debug trace event.
335 * @ref: Reference for debug trace event.
337 void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
341 struct zfcp_adapter *adapter = port->adapter;
343 read_lock_irqsave(&zfcp_data.config_lock, flags);
344 write_lock(&adapter->erp_lock);
345 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
346 write_unlock(&adapter->erp_lock);
347 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
350 static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
353 zfcp_erp_port_block(port, clear);
355 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
356 /* ensure propagation of failed status to new devices */
357 zfcp_erp_port_failed(port, 14, NULL);
361 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
362 port->adapter, port, NULL, id, ref);
366 * zfcp_erp_port_reopen - trigger remote port recovery
367 * @port: port to recover
368 * @clear_mask: flags in port status to be cleared
370 * Returns 0 if recovery has been triggered, < 0 if not.
372 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
376 struct zfcp_adapter *adapter = port->adapter;
378 read_lock_irqsave(&zfcp_data.config_lock, flags);
379 write_lock(&adapter->erp_lock);
380 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
381 write_unlock(&adapter->erp_lock);
382 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
387 static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
389 zfcp_erp_modify_unit_status(unit, 19, NULL,
390 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
394 static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
397 struct zfcp_adapter *adapter = unit->port->adapter;
399 zfcp_erp_unit_block(unit, clear);
401 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
404 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
405 adapter, unit->port, unit, id, ref);
409 * zfcp_erp_unit_reopen - initiate reopen of a unit
410 * @unit: unit to be reopened
411 * @clear_mask: specifies flags in unit status to be cleared
412 * Return: 0 on success, < 0 on error
414 void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
417 struct zfcp_port *port = unit->port;
418 struct zfcp_adapter *adapter = port->adapter;
420 read_lock_irqsave(&zfcp_data.config_lock, flags);
421 write_lock(&adapter->erp_lock);
422 _zfcp_erp_unit_reopen(unit, clear, id, ref);
423 write_unlock(&adapter->erp_lock);
424 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
427 static int status_change_set(unsigned long mask, atomic_t *status)
429 return (atomic_read(status) ^ mask) & mask;
432 static int status_change_clear(unsigned long mask, atomic_t *status)
434 return atomic_read(status) & mask;
437 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
439 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
440 zfcp_rec_dbf_event_adapter(16, NULL, adapter);
441 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
444 static void zfcp_erp_port_unblock(struct zfcp_port *port)
446 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
447 zfcp_rec_dbf_event_port(18, NULL, port);
448 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
451 static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
453 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
454 zfcp_rec_dbf_event_unit(20, NULL, unit);
455 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
458 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
460 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
461 zfcp_rec_dbf_event_action(145, erp_action);
464 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
466 struct zfcp_adapter *adapter = act->adapter;
471 spin_lock(&adapter->req_list_lock);
472 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
473 act->fsf_req->erp_action == act) {
474 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
475 ZFCP_STATUS_ERP_TIMEDOUT)) {
476 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
477 zfcp_rec_dbf_event_action(142, act);
478 act->fsf_req->erp_action = NULL;
480 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
481 zfcp_rec_dbf_event_action(143, act);
482 if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
483 ZFCP_STATUS_FSFREQ_DISMISSED))
487 spin_unlock(&adapter->req_list_lock);
491 * zfcp_erp_notify - Trigger ERP action.
492 * @erp_action: ERP action to continue.
493 * @set_mask: ERP action status flags to set.
495 void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
497 struct zfcp_adapter *adapter = erp_action->adapter;
500 write_lock_irqsave(&adapter->erp_lock, flags);
501 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
502 erp_action->status |= set_mask;
503 zfcp_erp_action_ready(erp_action);
505 write_unlock_irqrestore(&adapter->erp_lock, flags);
509 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
510 * @data: ERP action (from timer data)
512 void zfcp_erp_timeout_handler(unsigned long data)
514 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
515 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
518 static void zfcp_erp_memwait_handler(unsigned long data)
520 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
523 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
525 init_timer(&erp_action->timer);
526 erp_action->timer.function = zfcp_erp_memwait_handler;
527 erp_action->timer.data = (unsigned long) erp_action;
528 erp_action->timer.expires = jiffies + HZ;
529 add_timer(&erp_action->timer);
532 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
533 int clear, u8 id, void *ref)
535 struct zfcp_port *port;
537 list_for_each_entry(port, &adapter->port_list_head, list)
538 _zfcp_erp_port_reopen(port, clear, id, ref);
541 static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
544 struct zfcp_unit *unit;
546 list_for_each_entry(unit, &port->unit_list_head, list)
547 _zfcp_erp_unit_reopen(unit, clear, id, ref);
550 static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
552 struct zfcp_adapter *adapter = act->adapter;
553 struct zfcp_port *port = act->port;
554 struct zfcp_unit *unit = act->unit;
555 u32 status = act->status;
557 /* initiate follow-up actions depending on success of finished action */
558 switch (act->action) {
560 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
561 if (status == ZFCP_ERP_SUCCEEDED)
562 _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
564 _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
567 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
568 if (status == ZFCP_ERP_SUCCEEDED)
569 _zfcp_erp_port_reopen(port, 0, 72, NULL);
571 _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
574 case ZFCP_ERP_ACTION_REOPEN_PORT:
575 if (status == ZFCP_ERP_SUCCEEDED)
576 _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
578 _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
581 case ZFCP_ERP_ACTION_REOPEN_UNIT:
582 if (status != ZFCP_ERP_SUCCEEDED)
583 _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
588 static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
592 read_lock_irqsave(&zfcp_data.config_lock, flags);
593 read_lock(&adapter->erp_lock);
594 if (list_empty(&adapter->erp_ready_head) &&
595 list_empty(&adapter->erp_running_head)) {
596 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
598 wake_up(&adapter->erp_done_wqh);
600 read_unlock(&adapter->erp_lock);
601 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
604 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
606 if (zfcp_qdio_open(act->adapter))
607 return ZFCP_ERP_FAILED;
608 init_waitqueue_head(&act->adapter->request_wq);
609 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
610 return ZFCP_ERP_SUCCEEDED;
613 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
615 struct zfcp_port *port;
616 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
618 if (IS_ERR(port)) /* error or port already attached */
620 _zfcp_erp_port_reopen(port, 0, 150, NULL);
623 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
627 struct zfcp_adapter *adapter = erp_action->adapter;
629 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
631 for (retries = 7; retries; retries--) {
632 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
634 write_lock_irq(&adapter->erp_lock);
635 zfcp_erp_action_to_running(erp_action);
636 write_unlock_irq(&adapter->erp_lock);
637 if (zfcp_fsf_exchange_config_data(erp_action)) {
638 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
640 return ZFCP_ERP_FAILED;
643 zfcp_rec_dbf_event_thread_lock(6, adapter);
644 down(&adapter->erp_ready_sem);
645 zfcp_rec_dbf_event_thread_lock(7, adapter);
646 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
649 if (!(atomic_read(&adapter->status) &
650 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
657 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
660 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
661 return ZFCP_ERP_FAILED;
663 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
664 zfcp_erp_enqueue_ptp_port(adapter);
666 return ZFCP_ERP_SUCCEEDED;
669 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
672 struct zfcp_adapter *adapter = act->adapter;
674 write_lock_irq(&adapter->erp_lock);
675 zfcp_erp_action_to_running(act);
676 write_unlock_irq(&adapter->erp_lock);
678 ret = zfcp_fsf_exchange_port_data(act);
679 if (ret == -EOPNOTSUPP)
680 return ZFCP_ERP_SUCCEEDED;
682 return ZFCP_ERP_FAILED;
684 zfcp_rec_dbf_event_thread_lock(8, adapter);
685 down(&adapter->erp_ready_sem);
686 zfcp_rec_dbf_event_thread_lock(9, adapter);
687 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
688 return ZFCP_ERP_FAILED;
690 return ZFCP_ERP_SUCCEEDED;
693 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
695 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
696 return ZFCP_ERP_FAILED;
698 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
699 return ZFCP_ERP_FAILED;
701 atomic_set(&act->adapter->stat_miss, 16);
702 if (zfcp_status_read_refill(act->adapter))
703 return ZFCP_ERP_FAILED;
705 return ZFCP_ERP_SUCCEEDED;
708 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
711 int retval = ZFCP_ERP_SUCCEEDED;
712 struct zfcp_adapter *adapter = act->adapter;
717 retval = zfcp_erp_adapter_strategy_open_qdio(act);
718 if (retval != ZFCP_ERP_SUCCEEDED)
721 retval = zfcp_erp_adapter_strategy_open_fsf(act);
722 if (retval != ZFCP_ERP_SUCCEEDED)
725 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
727 return ZFCP_ERP_SUCCEEDED;
730 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
731 &act->adapter->status);
734 /* close queues to ensure that buffers are not accessed by adapter */
735 zfcp_qdio_close(adapter);
736 zfcp_fsf_req_dismiss_all(adapter);
737 adapter->fsf_req_seq_no = 0;
738 /* all ports and units are closed */
739 zfcp_erp_modify_adapter_status(adapter, 24, NULL,
740 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
742 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
743 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
744 &act->adapter->status);
748 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
752 zfcp_erp_adapter_strategy_generic(act, 1); /* close */
753 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
754 return ZFCP_ERP_EXIT;
756 retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
758 if (retval == ZFCP_ERP_FAILED)
764 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
768 retval = zfcp_fsf_close_physical_port(act);
769 if (retval == -ENOMEM)
770 return ZFCP_ERP_NOMEM;
771 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
773 return ZFCP_ERP_FAILED;
775 return ZFCP_ERP_CONTINUES;
778 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
780 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
783 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
785 struct zfcp_port *port = erp_action->port;
786 int status = atomic_read(&port->status);
788 switch (erp_action->step) {
789 case ZFCP_ERP_STEP_UNINITIALIZED:
790 zfcp_erp_port_strategy_clearstati(port);
791 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
792 (status & ZFCP_STATUS_COMMON_OPEN))
793 return zfcp_erp_port_forced_strategy_close(erp_action);
795 return ZFCP_ERP_FAILED;
797 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
798 if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
799 return ZFCP_ERP_SUCCEEDED;
801 return ZFCP_ERP_FAILED;
804 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
808 retval = zfcp_fsf_close_port(erp_action);
809 if (retval == -ENOMEM)
810 return ZFCP_ERP_NOMEM;
811 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
813 return ZFCP_ERP_FAILED;
814 return ZFCP_ERP_CONTINUES;
817 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
821 retval = zfcp_fsf_open_port(erp_action);
822 if (retval == -ENOMEM)
823 return ZFCP_ERP_NOMEM;
824 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
826 return ZFCP_ERP_FAILED;
827 return ZFCP_ERP_CONTINUES;
830 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
832 struct zfcp_adapter *adapter = act->adapter;
833 struct zfcp_port *port = act->port;
835 if (port->wwpn != adapter->peer_wwpn) {
836 zfcp_erp_port_failed(port, 25, NULL);
837 return ZFCP_ERP_FAILED;
839 port->d_id = adapter->peer_d_id;
840 return zfcp_erp_port_strategy_open_port(act);
843 void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
846 struct zfcp_port *port = container_of(work, struct zfcp_port,
849 retval = zfcp_fc_ns_gid_pn(&port->erp_action);
850 if (retval == -ENOMEM)
851 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
852 port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
854 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
858 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
860 struct zfcp_adapter *adapter = act->adapter;
861 struct zfcp_port *port = act->port;
862 int p_status = atomic_read(&port->status);
865 case ZFCP_ERP_STEP_UNINITIALIZED:
866 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
867 case ZFCP_ERP_STEP_PORT_CLOSING:
868 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
869 return zfcp_erp_open_ptp_port(act);
871 queue_work(zfcp_data.work_queue, &port->gid_pn_work);
872 return ZFCP_ERP_CONTINUES;
874 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
876 return ZFCP_ERP_FAILED;
877 return zfcp_erp_port_strategy_open_port(act);
879 case ZFCP_ERP_STEP_PORT_OPENING:
880 /* D_ID might have changed during open */
881 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
883 return ZFCP_ERP_SUCCEEDED;
885 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
886 return ZFCP_ERP_CONTINUES;
888 /* fall through otherwise */
891 return ZFCP_ERP_FAILED;
894 static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
896 struct zfcp_port *port = erp_action->port;
898 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
899 goto close_init_done;
901 switch (erp_action->step) {
902 case ZFCP_ERP_STEP_UNINITIALIZED:
903 zfcp_erp_port_strategy_clearstati(port);
904 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
905 return zfcp_erp_port_strategy_close(erp_action);
908 case ZFCP_ERP_STEP_PORT_CLOSING:
909 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
910 return ZFCP_ERP_FAILED;
915 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
916 return ZFCP_ERP_EXIT;
918 return zfcp_erp_port_strategy_open_common(erp_action);
921 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
923 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
924 ZFCP_STATUS_UNIT_SHARED |
925 ZFCP_STATUS_UNIT_READONLY,
929 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
931 int retval = zfcp_fsf_close_unit(erp_action);
932 if (retval == -ENOMEM)
933 return ZFCP_ERP_NOMEM;
934 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
936 return ZFCP_ERP_FAILED;
937 return ZFCP_ERP_CONTINUES;
940 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
942 int retval = zfcp_fsf_open_unit(erp_action);
943 if (retval == -ENOMEM)
944 return ZFCP_ERP_NOMEM;
945 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
947 return ZFCP_ERP_FAILED;
948 return ZFCP_ERP_CONTINUES;
951 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
953 struct zfcp_unit *unit = erp_action->unit;
955 switch (erp_action->step) {
956 case ZFCP_ERP_STEP_UNINITIALIZED:
957 zfcp_erp_unit_strategy_clearstati(unit);
958 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
959 return zfcp_erp_unit_strategy_close(erp_action);
960 /* already closed, fall through */
961 case ZFCP_ERP_STEP_UNIT_CLOSING:
962 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
963 return ZFCP_ERP_FAILED;
964 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
965 return ZFCP_ERP_EXIT;
966 return zfcp_erp_unit_strategy_open(erp_action);
968 case ZFCP_ERP_STEP_UNIT_OPENING:
969 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
970 return ZFCP_ERP_SUCCEEDED;
972 return ZFCP_ERP_FAILED;
975 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
978 case ZFCP_ERP_SUCCEEDED :
979 atomic_set(&unit->erp_counter, 0);
980 zfcp_erp_unit_unblock(unit);
982 case ZFCP_ERP_FAILED :
983 atomic_inc(&unit->erp_counter);
984 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
985 dev_err(&unit->port->adapter->ccw_device->dev,
986 "ERP failed for unit 0x%016Lx on "
988 (unsigned long long)unit->fcp_lun,
989 (unsigned long long)unit->port->wwpn);
990 zfcp_erp_unit_failed(unit, 21, NULL);
995 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
996 zfcp_erp_unit_block(unit, 0);
997 result = ZFCP_ERP_EXIT;
1002 static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1005 case ZFCP_ERP_SUCCEEDED :
1006 atomic_set(&port->erp_counter, 0);
1007 zfcp_erp_port_unblock(port);
1010 case ZFCP_ERP_FAILED :
1011 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1012 zfcp_erp_port_block(port, 0);
1013 result = ZFCP_ERP_EXIT;
1015 atomic_inc(&port->erp_counter);
1016 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1017 dev_err(&port->adapter->ccw_device->dev,
1018 "ERP failed for remote port 0x%016Lx\n",
1019 (unsigned long long)port->wwpn);
1020 zfcp_erp_port_failed(port, 22, NULL);
1025 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1026 zfcp_erp_port_block(port, 0);
1027 result = ZFCP_ERP_EXIT;
1032 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1036 case ZFCP_ERP_SUCCEEDED :
1037 atomic_set(&adapter->erp_counter, 0);
1038 zfcp_erp_adapter_unblock(adapter);
1041 case ZFCP_ERP_FAILED :
1042 atomic_inc(&adapter->erp_counter);
1043 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1044 dev_err(&adapter->ccw_device->dev,
1045 "ERP cannot recover an error "
1046 "on the FCP device\n");
1047 zfcp_erp_adapter_failed(adapter, 23, NULL);
1052 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1053 zfcp_erp_adapter_block(adapter, 0);
1054 result = ZFCP_ERP_EXIT;
1059 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1062 struct zfcp_adapter *adapter = erp_action->adapter;
1063 struct zfcp_port *port = erp_action->port;
1064 struct zfcp_unit *unit = erp_action->unit;
1066 switch (erp_action->action) {
1068 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1069 result = zfcp_erp_strategy_check_unit(unit, result);
1072 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1073 case ZFCP_ERP_ACTION_REOPEN_PORT:
1074 result = zfcp_erp_strategy_check_port(port, result);
1077 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1078 result = zfcp_erp_strategy_check_adapter(adapter, result);
1084 static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
1086 int status = atomic_read(target_status);
1088 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1089 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1090 return 1; /* take it online */
1092 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1093 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1094 return 1; /* take it offline */
1099 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1101 int action = act->action;
1102 struct zfcp_adapter *adapter = act->adapter;
1103 struct zfcp_port *port = act->port;
1104 struct zfcp_unit *unit = act->unit;
1105 u32 erp_status = act->status;
1108 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1109 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1110 _zfcp_erp_adapter_reopen(adapter,
1111 ZFCP_STATUS_COMMON_ERP_FAILED,
1113 return ZFCP_ERP_EXIT;
1117 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1118 case ZFCP_ERP_ACTION_REOPEN_PORT:
1119 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1120 _zfcp_erp_port_reopen(port,
1121 ZFCP_STATUS_COMMON_ERP_FAILED,
1123 return ZFCP_ERP_EXIT;
1127 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1128 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1129 _zfcp_erp_unit_reopen(unit,
1130 ZFCP_STATUS_COMMON_ERP_FAILED,
1132 return ZFCP_ERP_EXIT;
1139 static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
1141 struct zfcp_adapter *adapter = erp_action->adapter;
1143 adapter->erp_total_count--;
1144 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1145 adapter->erp_low_mem_count--;
1146 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1149 list_del(&erp_action->list);
1150 zfcp_rec_dbf_event_action(144, erp_action);
1152 switch (erp_action->action) {
1153 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1154 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1155 &erp_action->unit->status);
1158 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1159 case ZFCP_ERP_ACTION_REOPEN_PORT:
1160 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1161 &erp_action->port->status);
1164 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1165 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1166 &erp_action->adapter->status);
1171 struct zfcp_erp_add_work {
1172 struct zfcp_unit *unit;
1173 struct work_struct work;
1176 static void zfcp_erp_scsi_scan(struct work_struct *work)
1178 struct zfcp_erp_add_work *p =
1179 container_of(work, struct zfcp_erp_add_work, work);
1180 struct zfcp_unit *unit = p->unit;
1181 struct fc_rport *rport = unit->port->rport;
1183 if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
1184 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1185 scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
1186 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1187 zfcp_unit_put(unit);
1188 wake_up(&unit->port->adapter->erp_done_wqh);
1192 static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
1194 struct zfcp_erp_add_work *p;
1196 p = kzalloc(sizeof(*p), GFP_KERNEL);
1198 dev_err(&unit->port->adapter->ccw_device->dev,
1199 "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
1200 (unsigned long long)unit->fcp_lun,
1201 (unsigned long long)unit->port->wwpn);
1205 zfcp_unit_get(unit);
1206 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1207 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1209 queue_work(zfcp_data.work_queue, &p->work);
1212 static void zfcp_erp_rport_register(struct zfcp_port *port)
1214 struct fc_rport_identifiers ids;
1215 ids.node_name = port->wwnn;
1216 ids.port_name = port->wwpn;
1217 ids.port_id = port->d_id;
1218 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
1219 port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
1221 dev_err(&port->adapter->ccw_device->dev,
1222 "Registering port 0x%016Lx failed\n",
1223 (unsigned long long)port->wwpn);
1227 scsi_target_unblock(&port->rport->dev);
1228 port->rport->maxframe_size = port->maxframe_size;
1229 port->rport->supported_classes = port->supported_classes;
1232 static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
1234 struct zfcp_port *port;
1235 list_for_each_entry(port, &adapter->port_list_head, list) {
1238 fc_remote_port_delete(port->rport);
1243 static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1245 struct zfcp_adapter *adapter = act->adapter;
1246 struct zfcp_port *port = act->port;
1247 struct zfcp_unit *unit = act->unit;
1249 switch (act->action) {
1250 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1251 if ((result == ZFCP_ERP_SUCCEEDED) &&
1252 !unit->device && port->rport) {
1253 if (!(atomic_read(&unit->status) &
1254 ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
1255 zfcp_erp_schedule_work(unit);
1257 zfcp_unit_put(unit);
1260 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1261 case ZFCP_ERP_ACTION_REOPEN_PORT:
1262 if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
1263 zfcp_erp_rport_register(port);
1264 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
1265 fc_remote_port_delete(port->rport);
1268 zfcp_port_put(port);
1271 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1272 if (result != ZFCP_ERP_SUCCEEDED) {
1273 unregister_service_level(&adapter->service_level);
1274 zfcp_erp_rports_del(adapter);
1276 register_service_level(&adapter->service_level);
1277 schedule_work(&adapter->scan_work);
1279 zfcp_adapter_put(adapter);
1284 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1286 switch (erp_action->action) {
1287 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1288 return zfcp_erp_adapter_strategy(erp_action);
1289 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1290 return zfcp_erp_port_forced_strategy(erp_action);
1291 case ZFCP_ERP_ACTION_REOPEN_PORT:
1292 return zfcp_erp_port_strategy(erp_action);
1293 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1294 return zfcp_erp_unit_strategy(erp_action);
1296 return ZFCP_ERP_FAILED;
1299 static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1302 struct zfcp_adapter *adapter = erp_action->adapter;
1303 unsigned long flags;
1305 read_lock_irqsave(&zfcp_data.config_lock, flags);
1306 write_lock(&adapter->erp_lock);
1308 zfcp_erp_strategy_check_fsfreq(erp_action);
1310 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1311 zfcp_erp_action_dequeue(erp_action);
1312 retval = ZFCP_ERP_DISMISSED;
1316 zfcp_erp_action_to_running(erp_action);
1318 /* no lock to allow for blocking operations */
1319 write_unlock(&adapter->erp_lock);
1320 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1321 retval = zfcp_erp_strategy_do_action(erp_action);
1322 read_lock_irqsave(&zfcp_data.config_lock, flags);
1323 write_lock(&adapter->erp_lock);
1325 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1326 retval = ZFCP_ERP_CONTINUES;
1329 case ZFCP_ERP_NOMEM:
1330 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1331 ++adapter->erp_low_mem_count;
1332 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1334 if (adapter->erp_total_count == adapter->erp_low_mem_count)
1335 _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
1337 zfcp_erp_strategy_memwait(erp_action);
1338 retval = ZFCP_ERP_CONTINUES;
1342 case ZFCP_ERP_CONTINUES:
1343 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1344 --adapter->erp_low_mem_count;
1345 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1350 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1351 zfcp_erp_action_dequeue(erp_action);
1352 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1353 if (retval == ZFCP_ERP_EXIT)
1355 zfcp_erp_strategy_followup_actions(erp_action);
1358 write_unlock(&adapter->erp_lock);
1359 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1361 if (retval != ZFCP_ERP_CONTINUES)
1362 zfcp_erp_action_cleanup(erp_action, retval);
1367 static int zfcp_erp_thread(void *data)
1369 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1370 struct list_head *next;
1371 struct zfcp_erp_action *act;
1372 unsigned long flags;
1375 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
1376 /* Block all signals */
1377 siginitsetinv(¤t->blocked, 0);
1378 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1379 wake_up(&adapter->erp_thread_wqh);
1381 while (!(atomic_read(&adapter->status) &
1382 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
1383 write_lock_irqsave(&adapter->erp_lock, flags);
1384 next = adapter->erp_ready_head.next;
1385 write_unlock_irqrestore(&adapter->erp_lock, flags);
1387 if (next != &adapter->erp_ready_head) {
1388 act = list_entry(next, struct zfcp_erp_action, list);
1390 /* there is more to come after dismission, no notify */
1391 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1392 zfcp_erp_wakeup(adapter);
1395 zfcp_rec_dbf_event_thread_lock(4, adapter);
1396 ignore = down_interruptible(&adapter->erp_ready_sem);
1397 zfcp_rec_dbf_event_thread_lock(5, adapter);
1400 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1401 wake_up(&adapter->erp_thread_wqh);
1407 * zfcp_erp_thread_setup - Start ERP thread for adapter
1408 * @adapter: Adapter to start the ERP thread for
1410 * Returns 0 on success or error code from kernel_thread()
1412 int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1416 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1417 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1419 dev_err(&adapter->ccw_device->dev,
1420 "Creating an ERP thread for the FCP device failed.\n");
1423 wait_event(adapter->erp_thread_wqh,
1424 atomic_read(&adapter->status) &
1425 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1430 * zfcp_erp_thread_kill - Stop ERP thread.
1431 * @adapter: Adapter where the ERP thread should be stopped.
1433 * The caller of this routine ensures that the specified adapter has
1434 * been shut down and that this operation has been completed. Thus,
1435 * there are no pending erp_actions which would need to be handled
1438 void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1440 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1441 up(&adapter->erp_ready_sem);
1442 zfcp_rec_dbf_event_thread_lock(3, adapter);
1444 wait_event(adapter->erp_thread_wqh,
1445 !(atomic_read(&adapter->status) &
1446 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1448 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1453 * zfcp_erp_adapter_failed - Set adapter status to failed.
1454 * @adapter: Failed adapter.
1455 * @id: Event id for debug trace.
1456 * @ref: Reference for debug trace.
1458 void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
1460 zfcp_erp_modify_adapter_status(adapter, id, ref,
1461 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1465 * zfcp_erp_port_failed - Set port status to failed.
1466 * @port: Failed port.
1467 * @id: Event id for debug trace.
1468 * @ref: Reference for debug trace.
1470 void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
1472 zfcp_erp_modify_port_status(port, id, ref,
1473 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1477 * zfcp_erp_unit_failed - Set unit status to failed.
1478 * @unit: Failed unit.
1479 * @id: Event id for debug trace.
1480 * @ref: Reference for debug trace.
1482 void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
1484 zfcp_erp_modify_unit_status(unit, id, ref,
1485 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1489 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1490 * @adapter: adapter for which to wait for completion of its error recovery
1492 void zfcp_erp_wait(struct zfcp_adapter *adapter)
1494 wait_event(adapter->erp_done_wqh,
1495 !(atomic_read(&adapter->status) &
1496 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1500 * zfcp_erp_modify_adapter_status - change adapter status bits
1501 * @adapter: adapter to change the status
1502 * @id: id for the debug trace
1503 * @ref: reference for the debug trace
1504 * @mask: status bits to change
1505 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1507 * Changes in common status bits are propagated to attached ports and units.
1509 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1510 void *ref, u32 mask, int set_or_clear)
1512 struct zfcp_port *port;
1513 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1515 if (set_or_clear == ZFCP_SET) {
1516 if (status_change_set(mask, &adapter->status))
1517 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1518 atomic_set_mask(mask, &adapter->status);
1520 if (status_change_clear(mask, &adapter->status))
1521 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1522 atomic_clear_mask(mask, &adapter->status);
1523 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1524 atomic_set(&adapter->erp_counter, 0);
1528 list_for_each_entry(port, &adapter->port_list_head, list)
1529 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1534 * zfcp_erp_modify_port_status - change port status bits
1535 * @port: port to change the status bits
1536 * @id: id for the debug trace
1537 * @ref: reference for the debug trace
1538 * @mask: status bits to change
1539 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1541 * Changes in common status bits are propagated to attached units.
1543 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
1544 u32 mask, int set_or_clear)
1546 struct zfcp_unit *unit;
1547 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1549 if (set_or_clear == ZFCP_SET) {
1550 if (status_change_set(mask, &port->status))
1551 zfcp_rec_dbf_event_port(id, ref, port);
1552 atomic_set_mask(mask, &port->status);
1554 if (status_change_clear(mask, &port->status))
1555 zfcp_rec_dbf_event_port(id, ref, port);
1556 atomic_clear_mask(mask, &port->status);
1557 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1558 atomic_set(&port->erp_counter, 0);
1562 list_for_each_entry(unit, &port->unit_list_head, list)
1563 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1568 * zfcp_erp_modify_unit_status - change unit status bits
1569 * @unit: unit to change the status bits
1570 * @id: id for the debug trace
1571 * @ref: reference for the debug trace
1572 * @mask: status bits to change
1573 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1575 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
1576 u32 mask, int set_or_clear)
1578 if (set_or_clear == ZFCP_SET) {
1579 if (status_change_set(mask, &unit->status))
1580 zfcp_rec_dbf_event_unit(id, ref, unit);
1581 atomic_set_mask(mask, &unit->status);
1583 if (status_change_clear(mask, &unit->status))
1584 zfcp_rec_dbf_event_unit(id, ref, unit);
1585 atomic_clear_mask(mask, &unit->status);
1586 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1587 atomic_set(&unit->erp_counter, 0);
1593 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1594 * @port: The "boxed" port.
1595 * @id: The debug trace id.
1596 * @id: Reference for the debug trace.
1598 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
1600 unsigned long flags;
1602 read_lock_irqsave(&zfcp_data.config_lock, flags);
1603 zfcp_erp_modify_port_status(port, id, ref,
1604 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1605 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1606 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1610 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1611 * @port: The "boxed" unit.
1612 * @id: The debug trace id.
1613 * @id: Reference for the debug trace.
1615 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
1617 zfcp_erp_modify_unit_status(unit, id, ref,
1618 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1619 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1623 * zfcp_erp_port_access_denied - Adapter denied access to port.
1624 * @port: port where access has been denied
1625 * @id: id for debug trace
1626 * @ref: reference for debug trace
1628 * Since the adapter has denied access, stop using the port and the
1631 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
1633 unsigned long flags;
1635 read_lock_irqsave(&zfcp_data.config_lock, flags);
1636 zfcp_erp_modify_port_status(port, id, ref,
1637 ZFCP_STATUS_COMMON_ERP_FAILED |
1638 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1639 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1643 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1644 * @unit: unit where access has been denied
1645 * @id: id for debug trace
1646 * @ref: reference for debug trace
1648 * Since the adapter has denied access, stop using the unit.
1650 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
1652 zfcp_erp_modify_unit_status(unit, id, ref,
1653 ZFCP_STATUS_COMMON_ERP_FAILED |
1654 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1657 static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
1660 int status = atomic_read(&unit->status);
1661 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1662 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1665 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1668 static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
1671 struct zfcp_unit *unit;
1672 int status = atomic_read(&port->status);
1674 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1675 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
1676 list_for_each_entry(unit, &port->unit_list_head, list)
1677 zfcp_erp_unit_access_changed(unit, id, ref);
1681 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1685 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1686 * @adapter: Adapter where the Access Control Table (ACT) changed
1687 * @id: Id for debug trace
1688 * @ref: Reference for debug trace
1690 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
1693 struct zfcp_port *port;
1694 unsigned long flags;
1696 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1699 read_lock_irqsave(&zfcp_data.config_lock, flags);
1700 list_for_each_entry(port, &adapter->port_list_head, list)
1701 zfcp_erp_port_access_changed(port, id, ref);
1702 read_unlock_irqrestore(&zfcp_data.config_lock, flags);