4 * Error Recovery Procedures (ERP).
6 * Copyright IBM Corporation 2002, 2008
11 #define ZFCP_MAX_ERPS 3
13 enum zfcp_erp_act_flags {
14 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
15 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
16 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
17 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
18 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
22 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
23 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
24 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
25 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
26 ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
27 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
28 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
29 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
32 enum zfcp_erp_act_type {
33 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
34 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
35 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
36 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
39 enum zfcp_erp_act_state {
40 ZFCP_ERP_ACTION_RUNNING = 1,
41 ZFCP_ERP_ACTION_READY = 2,
44 enum zfcp_erp_act_result {
45 ZFCP_ERP_SUCCEEDED = 0,
47 ZFCP_ERP_CONTINUES = 2,
49 ZFCP_ERP_DISMISSED = 4,
53 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
55 zfcp_erp_modify_adapter_status(adapter, 15, NULL,
56 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
60 static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
62 struct zfcp_erp_action *curr_act;
64 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
66 return ZFCP_ERP_ACTION_RUNNING;
70 static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
72 struct zfcp_adapter *adapter = act->adapter;
74 list_move(&act->list, &act->adapter->erp_ready_head);
75 zfcp_rec_dbf_event_action(146, act);
76 up(&adapter->erp_ready_sem);
77 zfcp_rec_dbf_event_thread(2, adapter);
80 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
82 act->status |= ZFCP_STATUS_ERP_DISMISSED;
83 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
84 zfcp_erp_action_ready(act);
87 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
89 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
90 zfcp_erp_action_dismiss(&unit->erp_action);
93 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
95 struct zfcp_unit *unit;
97 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
98 zfcp_erp_action_dismiss(&port->erp_action);
100 list_for_each_entry(unit, &port->unit_list_head, list)
101 zfcp_erp_action_dismiss_unit(unit);
104 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
106 struct zfcp_port *port;
108 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
109 zfcp_erp_action_dismiss(&adapter->erp_action);
111 list_for_each_entry(port, &adapter->port_list_head, list)
112 zfcp_erp_action_dismiss_port(port);
115 static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
116 struct zfcp_port *port,
117 struct zfcp_unit *unit)
120 int u_status, p_status, a_status;
123 case ZFCP_ERP_ACTION_REOPEN_UNIT:
124 u_status = atomic_read(&unit->status);
125 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
127 p_status = atomic_read(&port->status);
128 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
129 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
131 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
132 need = ZFCP_ERP_ACTION_REOPEN_PORT;
134 case ZFCP_ERP_ACTION_REOPEN_PORT:
135 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
136 p_status = atomic_read(&port->status);
137 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
139 a_status = atomic_read(&adapter->status);
140 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
141 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
143 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
144 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
146 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
147 a_status = atomic_read(&adapter->status);
148 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
155 static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
156 struct zfcp_adapter *adapter,
157 struct zfcp_port *port,
158 struct zfcp_unit *unit)
160 struct zfcp_erp_action *erp_action;
164 case ZFCP_ERP_ACTION_REOPEN_UNIT:
166 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
167 erp_action = &unit->erp_action;
168 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
169 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
172 case ZFCP_ERP_ACTION_REOPEN_PORT:
173 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
175 zfcp_erp_action_dismiss_port(port);
176 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
177 erp_action = &port->erp_action;
178 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
179 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
182 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
183 zfcp_adapter_get(adapter);
184 zfcp_erp_action_dismiss_adapter(adapter);
185 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
186 erp_action = &adapter->erp_action;
187 if (!(atomic_read(&adapter->status) &
188 ZFCP_STATUS_COMMON_RUNNING))
189 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
196 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
197 erp_action->adapter = adapter;
198 erp_action->port = port;
199 erp_action->unit = unit;
200 erp_action->action = need;
201 erp_action->status = status;
206 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
207 struct zfcp_port *port,
208 struct zfcp_unit *unit, u8 id, void *ref)
210 int retval = 1, need;
211 struct zfcp_erp_action *act = NULL;
213 if (!(atomic_read(&adapter->status) &
214 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
217 need = zfcp_erp_required_act(want, adapter, port, unit);
221 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
222 act = zfcp_erp_setup_act(need, adapter, port, unit);
225 ++adapter->erp_total_count;
226 list_add_tail(&act->list, &adapter->erp_ready_head);
227 up(&adapter->erp_ready_sem);
228 zfcp_rec_dbf_event_thread(1, adapter);
231 zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
232 adapter, port, unit);
236 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
237 int clear_mask, u8 id, void *ref)
239 zfcp_erp_adapter_block(adapter, clear_mask);
241 /* ensure propagation of failed status to new devices */
242 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
243 zfcp_erp_adapter_failed(adapter, 13, NULL);
246 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
247 adapter, NULL, NULL, id, ref);
251 * zfcp_erp_adapter_reopen - Reopen adapter.
252 * @adapter: Adapter to reopen.
253 * @clear: Status flags to clear.
254 * @id: Id for debug trace event.
255 * @ref: Reference for debug trace event.
257 void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
262 read_lock_irqsave(&zfcp_data.config_lock, flags);
263 write_lock(&adapter->erp_lock);
264 _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
265 write_unlock(&adapter->erp_lock);
266 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
270 * zfcp_erp_adapter_shutdown - Shutdown adapter.
271 * @adapter: Adapter to shut down.
272 * @clear: Status flags to clear.
273 * @id: Id for debug trace event.
274 * @ref: Reference for debug trace event.
276 void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
279 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
280 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
284 * zfcp_erp_port_shutdown - Shutdown port
285 * @port: Port to shut down.
286 * @clear: Status flags to clear.
287 * @id: Id for debug trace event.
288 * @ref: Reference for debug trace event.
290 void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
292 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
293 zfcp_erp_port_reopen(port, clear | flags, id, ref);
297 * zfcp_erp_unit_shutdown - Shutdown unit
298 * @unit: Unit to shut down.
299 * @clear: Status flags to clear.
300 * @id: Id for debug trace event.
301 * @ref: Reference for debug trace event.
303 void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
305 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
306 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
309 static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
311 zfcp_erp_modify_port_status(port, 17, NULL,
312 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
316 static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
317 int clear, u8 id, void *ref)
319 zfcp_erp_port_block(port, clear);
321 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
324 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
325 port->adapter, port, NULL, id, ref);
329 * zfcp_erp_port_forced_reopen - Forced close of port and open again
330 * @port: Port to force close and to reopen.
331 * @id: Id for debug trace event.
332 * @ref: Reference for debug trace event.
334 void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
338 struct zfcp_adapter *adapter = port->adapter;
340 read_lock_irqsave(&zfcp_data.config_lock, flags);
341 write_lock(&adapter->erp_lock);
342 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
343 write_unlock(&adapter->erp_lock);
344 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
347 static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
350 zfcp_erp_port_block(port, clear);
352 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
353 /* ensure propagation of failed status to new devices */
354 zfcp_erp_port_failed(port, 14, NULL);
358 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
359 port->adapter, port, NULL, id, ref);
363 * zfcp_erp_port_reopen - trigger remote port recovery
364 * @port: port to recover
365 * @clear_mask: flags in port status to be cleared
367 * Returns 0 if recovery has been triggered, < 0 if not.
369 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
373 struct zfcp_adapter *adapter = port->adapter;
375 read_lock_irqsave(&zfcp_data.config_lock, flags);
376 write_lock(&adapter->erp_lock);
377 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
378 write_unlock(&adapter->erp_lock);
379 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
384 static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
386 zfcp_erp_modify_unit_status(unit, 19, NULL,
387 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
391 static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
394 struct zfcp_adapter *adapter = unit->port->adapter;
396 zfcp_erp_unit_block(unit, clear);
398 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
401 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
402 adapter, unit->port, unit, id, ref);
406 * zfcp_erp_unit_reopen - initiate reopen of a unit
407 * @unit: unit to be reopened
408 * @clear_mask: specifies flags in unit status to be cleared
409 * Return: 0 on success, < 0 on error
411 void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
414 struct zfcp_port *port = unit->port;
415 struct zfcp_adapter *adapter = port->adapter;
417 read_lock_irqsave(&zfcp_data.config_lock, flags);
418 write_lock(&adapter->erp_lock);
419 _zfcp_erp_unit_reopen(unit, clear, id, ref);
420 write_unlock(&adapter->erp_lock);
421 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
424 static int status_change_set(unsigned long mask, atomic_t *status)
426 return (atomic_read(status) ^ mask) & mask;
429 static int status_change_clear(unsigned long mask, atomic_t *status)
431 return atomic_read(status) & mask;
434 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
436 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
437 zfcp_rec_dbf_event_adapter(16, NULL, adapter);
438 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
441 static void zfcp_erp_port_unblock(struct zfcp_port *port)
443 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
444 zfcp_rec_dbf_event_port(18, NULL, port);
445 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
448 static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
450 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
451 zfcp_rec_dbf_event_unit(20, NULL, unit);
452 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
455 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
457 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
458 zfcp_rec_dbf_event_action(145, erp_action);
461 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
463 struct zfcp_adapter *adapter = act->adapter;
468 spin_lock(&adapter->req_list_lock);
469 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
470 act->fsf_req->erp_action == act) {
471 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
472 ZFCP_STATUS_ERP_TIMEDOUT)) {
473 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
474 zfcp_rec_dbf_event_action(142, act);
475 act->fsf_req->erp_action = NULL;
477 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
478 zfcp_rec_dbf_event_action(143, act);
479 if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
480 ZFCP_STATUS_FSFREQ_DISMISSED))
484 spin_unlock(&adapter->req_list_lock);
488 * zfcp_erp_notify - Trigger ERP action.
489 * @erp_action: ERP action to continue.
490 * @set_mask: ERP action status flags to set.
492 void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
494 struct zfcp_adapter *adapter = erp_action->adapter;
497 write_lock_irqsave(&adapter->erp_lock, flags);
498 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
499 erp_action->status |= set_mask;
500 zfcp_erp_action_ready(erp_action);
502 write_unlock_irqrestore(&adapter->erp_lock, flags);
506 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
507 * @data: ERP action (from timer data)
509 void zfcp_erp_timeout_handler(unsigned long data)
511 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
512 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
515 static void zfcp_erp_memwait_handler(unsigned long data)
517 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
520 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
522 init_timer(&erp_action->timer);
523 erp_action->timer.function = zfcp_erp_memwait_handler;
524 erp_action->timer.data = (unsigned long) erp_action;
525 erp_action->timer.expires = jiffies + HZ;
526 add_timer(&erp_action->timer);
529 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
530 int clear, u8 id, void *ref)
532 struct zfcp_port *port;
534 list_for_each_entry(port, &adapter->port_list_head, list)
535 _zfcp_erp_port_reopen(port, clear, id, ref);
538 static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
541 struct zfcp_unit *unit;
543 list_for_each_entry(unit, &port->unit_list_head, list)
544 _zfcp_erp_unit_reopen(unit, clear, id, ref);
547 static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
549 struct zfcp_adapter *adapter = act->adapter;
550 struct zfcp_port *port = act->port;
551 struct zfcp_unit *unit = act->unit;
552 u32 status = act->status;
554 /* initiate follow-up actions depending on success of finished action */
555 switch (act->action) {
557 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
558 if (status == ZFCP_ERP_SUCCEEDED)
559 _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
561 _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
564 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
565 if (status == ZFCP_ERP_SUCCEEDED)
566 _zfcp_erp_port_reopen(port, 0, 72, NULL);
568 _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
571 case ZFCP_ERP_ACTION_REOPEN_PORT:
572 if (status == ZFCP_ERP_SUCCEEDED)
573 _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
575 _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
578 case ZFCP_ERP_ACTION_REOPEN_UNIT:
579 if (status != ZFCP_ERP_SUCCEEDED)
580 _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
585 static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
589 read_lock_irqsave(&zfcp_data.config_lock, flags);
590 read_lock(&adapter->erp_lock);
591 if (list_empty(&adapter->erp_ready_head) &&
592 list_empty(&adapter->erp_running_head)) {
593 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
595 wake_up(&adapter->erp_done_wqh);
597 read_unlock(&adapter->erp_lock);
598 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
601 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
603 if (zfcp_qdio_open(act->adapter))
604 return ZFCP_ERP_FAILED;
605 init_waitqueue_head(&act->adapter->request_wq);
606 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
607 return ZFCP_ERP_SUCCEEDED;
610 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
612 struct zfcp_port *port;
613 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
615 if (IS_ERR(port)) /* error or port already attached */
617 _zfcp_erp_port_reopen(port, 0, 150, NULL);
620 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
624 struct zfcp_adapter *adapter = erp_action->adapter;
626 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
628 for (retries = 7; retries; retries--) {
629 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
631 write_lock_irq(&adapter->erp_lock);
632 zfcp_erp_action_to_running(erp_action);
633 write_unlock_irq(&adapter->erp_lock);
634 if (zfcp_fsf_exchange_config_data(erp_action)) {
635 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
637 return ZFCP_ERP_FAILED;
640 zfcp_rec_dbf_event_thread_lock(6, adapter);
641 down(&adapter->erp_ready_sem);
642 zfcp_rec_dbf_event_thread_lock(7, adapter);
643 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
646 if (!(atomic_read(&adapter->status) &
647 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
654 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
657 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
658 return ZFCP_ERP_FAILED;
660 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
661 zfcp_erp_enqueue_ptp_port(adapter);
663 return ZFCP_ERP_SUCCEEDED;
666 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
669 struct zfcp_adapter *adapter = act->adapter;
671 write_lock_irq(&adapter->erp_lock);
672 zfcp_erp_action_to_running(act);
673 write_unlock_irq(&adapter->erp_lock);
675 ret = zfcp_fsf_exchange_port_data(act);
676 if (ret == -EOPNOTSUPP)
677 return ZFCP_ERP_SUCCEEDED;
679 return ZFCP_ERP_FAILED;
681 zfcp_rec_dbf_event_thread_lock(8, adapter);
682 down(&adapter->erp_ready_sem);
683 zfcp_rec_dbf_event_thread_lock(9, adapter);
684 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
685 return ZFCP_ERP_FAILED;
687 return ZFCP_ERP_SUCCEEDED;
690 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
692 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
693 return ZFCP_ERP_FAILED;
695 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
696 return ZFCP_ERP_FAILED;
698 atomic_set(&act->adapter->stat_miss, 16);
699 if (zfcp_status_read_refill(act->adapter))
700 return ZFCP_ERP_FAILED;
702 return ZFCP_ERP_SUCCEEDED;
705 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
708 int retval = ZFCP_ERP_SUCCEEDED;
709 struct zfcp_adapter *adapter = act->adapter;
714 retval = zfcp_erp_adapter_strategy_open_qdio(act);
715 if (retval != ZFCP_ERP_SUCCEEDED)
718 retval = zfcp_erp_adapter_strategy_open_fsf(act);
719 if (retval != ZFCP_ERP_SUCCEEDED)
722 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
724 return ZFCP_ERP_SUCCEEDED;
727 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
728 &act->adapter->status);
731 /* close queues to ensure that buffers are not accessed by adapter */
732 zfcp_qdio_close(adapter);
733 zfcp_fsf_req_dismiss_all(adapter);
734 adapter->fsf_req_seq_no = 0;
735 /* all ports and units are closed */
736 zfcp_erp_modify_adapter_status(adapter, 24, NULL,
737 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
739 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
740 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
741 &act->adapter->status);
745 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
749 zfcp_erp_adapter_strategy_generic(act, 1); /* close */
750 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
751 return ZFCP_ERP_EXIT;
753 retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
755 if (retval == ZFCP_ERP_FAILED)
761 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
765 retval = zfcp_fsf_close_physical_port(act);
766 if (retval == -ENOMEM)
767 return ZFCP_ERP_NOMEM;
768 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
770 return ZFCP_ERP_FAILED;
772 return ZFCP_ERP_CONTINUES;
775 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
777 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
778 ZFCP_STATUS_PORT_PHYS_CLOSING |
779 ZFCP_STATUS_PORT_INVALID_WWPN,
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 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
841 return zfcp_erp_port_strategy_open_port(act);
844 void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
847 struct zfcp_port *port = container_of(work, struct zfcp_port,
850 retval = zfcp_fc_ns_gid_pn(&port->erp_action);
851 if (retval == -ENOMEM)
852 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
853 port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
855 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
859 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
861 struct zfcp_adapter *adapter = act->adapter;
862 struct zfcp_port *port = act->port;
863 int p_status = atomic_read(&port->status);
866 case ZFCP_ERP_STEP_UNINITIALIZED:
867 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
868 case ZFCP_ERP_STEP_PORT_CLOSING:
869 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
870 return zfcp_erp_open_ptp_port(act);
871 if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
872 queue_work(zfcp_data.work_queue, &port->gid_pn_work);
873 return ZFCP_ERP_CONTINUES;
875 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
876 if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) {
877 if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) {
878 zfcp_erp_port_failed(port, 26, NULL);
879 return ZFCP_ERP_EXIT;
881 return ZFCP_ERP_FAILED;
883 return zfcp_erp_port_strategy_open_port(act);
885 case ZFCP_ERP_STEP_PORT_OPENING:
886 /* D_ID might have changed during open */
887 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
888 if (p_status & ZFCP_STATUS_PORT_DID_DID)
889 return ZFCP_ERP_SUCCEEDED;
891 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
892 return ZFCP_ERP_CONTINUES;
894 /* fall through otherwise */
897 return ZFCP_ERP_FAILED;
900 static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
902 struct zfcp_port *port = erp_action->port;
904 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
905 goto close_init_done;
907 switch (erp_action->step) {
908 case ZFCP_ERP_STEP_UNINITIALIZED:
909 zfcp_erp_port_strategy_clearstati(port);
910 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
911 return zfcp_erp_port_strategy_close(erp_action);
914 case ZFCP_ERP_STEP_PORT_CLOSING:
915 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
916 return ZFCP_ERP_FAILED;
921 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
922 return ZFCP_ERP_EXIT;
924 return zfcp_erp_port_strategy_open_common(erp_action);
927 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
929 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
930 ZFCP_STATUS_UNIT_SHARED |
931 ZFCP_STATUS_UNIT_READONLY,
935 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
937 int retval = zfcp_fsf_close_unit(erp_action);
938 if (retval == -ENOMEM)
939 return ZFCP_ERP_NOMEM;
940 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
942 return ZFCP_ERP_FAILED;
943 return ZFCP_ERP_CONTINUES;
946 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
948 int retval = zfcp_fsf_open_unit(erp_action);
949 if (retval == -ENOMEM)
950 return ZFCP_ERP_NOMEM;
951 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
953 return ZFCP_ERP_FAILED;
954 return ZFCP_ERP_CONTINUES;
957 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
959 struct zfcp_unit *unit = erp_action->unit;
961 switch (erp_action->step) {
962 case ZFCP_ERP_STEP_UNINITIALIZED:
963 zfcp_erp_unit_strategy_clearstati(unit);
964 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
965 return zfcp_erp_unit_strategy_close(erp_action);
966 /* already closed, fall through */
967 case ZFCP_ERP_STEP_UNIT_CLOSING:
968 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
969 return ZFCP_ERP_FAILED;
970 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
971 return ZFCP_ERP_EXIT;
972 return zfcp_erp_unit_strategy_open(erp_action);
974 case ZFCP_ERP_STEP_UNIT_OPENING:
975 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
976 return ZFCP_ERP_SUCCEEDED;
978 return ZFCP_ERP_FAILED;
981 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
984 case ZFCP_ERP_SUCCEEDED :
985 atomic_set(&unit->erp_counter, 0);
986 zfcp_erp_unit_unblock(unit);
988 case ZFCP_ERP_FAILED :
989 atomic_inc(&unit->erp_counter);
990 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
991 dev_err(&unit->port->adapter->ccw_device->dev,
992 "ERP failed for unit 0x%016Lx on "
994 (unsigned long long)unit->fcp_lun,
995 (unsigned long long)unit->port->wwpn);
996 zfcp_erp_unit_failed(unit, 21, NULL);
1001 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1002 zfcp_erp_unit_block(unit, 0);
1003 result = ZFCP_ERP_EXIT;
1008 static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1011 case ZFCP_ERP_SUCCEEDED :
1012 atomic_set(&port->erp_counter, 0);
1013 zfcp_erp_port_unblock(port);
1016 case ZFCP_ERP_FAILED :
1017 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1018 zfcp_erp_port_block(port, 0);
1019 result = ZFCP_ERP_EXIT;
1021 atomic_inc(&port->erp_counter);
1022 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1023 dev_err(&port->adapter->ccw_device->dev,
1024 "ERP failed for remote port 0x%016Lx\n",
1025 (unsigned long long)port->wwpn);
1026 zfcp_erp_port_failed(port, 22, NULL);
1031 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1032 zfcp_erp_port_block(port, 0);
1033 result = ZFCP_ERP_EXIT;
1038 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1042 case ZFCP_ERP_SUCCEEDED :
1043 atomic_set(&adapter->erp_counter, 0);
1044 zfcp_erp_adapter_unblock(adapter);
1047 case ZFCP_ERP_FAILED :
1048 atomic_inc(&adapter->erp_counter);
1049 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1050 dev_err(&adapter->ccw_device->dev,
1051 "ERP cannot recover an error "
1052 "on the FCP device\n");
1053 zfcp_erp_adapter_failed(adapter, 23, NULL);
1058 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1059 zfcp_erp_adapter_block(adapter, 0);
1060 result = ZFCP_ERP_EXIT;
1065 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1068 struct zfcp_adapter *adapter = erp_action->adapter;
1069 struct zfcp_port *port = erp_action->port;
1070 struct zfcp_unit *unit = erp_action->unit;
1072 switch (erp_action->action) {
1074 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1075 result = zfcp_erp_strategy_check_unit(unit, result);
1078 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1079 case ZFCP_ERP_ACTION_REOPEN_PORT:
1080 result = zfcp_erp_strategy_check_port(port, result);
1083 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1084 result = zfcp_erp_strategy_check_adapter(adapter, result);
1090 static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
1092 int status = atomic_read(target_status);
1094 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1095 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1096 return 1; /* take it online */
1098 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1099 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1100 return 1; /* take it offline */
1105 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1107 int action = act->action;
1108 struct zfcp_adapter *adapter = act->adapter;
1109 struct zfcp_port *port = act->port;
1110 struct zfcp_unit *unit = act->unit;
1111 u32 erp_status = act->status;
1114 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1115 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1116 _zfcp_erp_adapter_reopen(adapter,
1117 ZFCP_STATUS_COMMON_ERP_FAILED,
1119 return ZFCP_ERP_EXIT;
1123 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1124 case ZFCP_ERP_ACTION_REOPEN_PORT:
1125 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1126 _zfcp_erp_port_reopen(port,
1127 ZFCP_STATUS_COMMON_ERP_FAILED,
1129 return ZFCP_ERP_EXIT;
1133 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1134 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1135 _zfcp_erp_unit_reopen(unit,
1136 ZFCP_STATUS_COMMON_ERP_FAILED,
1138 return ZFCP_ERP_EXIT;
1145 static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
1147 struct zfcp_adapter *adapter = erp_action->adapter;
1149 adapter->erp_total_count--;
1150 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1151 adapter->erp_low_mem_count--;
1152 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1155 list_del(&erp_action->list);
1156 zfcp_rec_dbf_event_action(144, erp_action);
1158 switch (erp_action->action) {
1159 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1160 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1161 &erp_action->unit->status);
1164 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1165 case ZFCP_ERP_ACTION_REOPEN_PORT:
1166 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1167 &erp_action->port->status);
1170 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1171 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1172 &erp_action->adapter->status);
1177 struct zfcp_erp_add_work {
1178 struct zfcp_unit *unit;
1179 struct work_struct work;
1182 static void zfcp_erp_scsi_scan(struct work_struct *work)
1184 struct zfcp_erp_add_work *p =
1185 container_of(work, struct zfcp_erp_add_work, work);
1186 struct zfcp_unit *unit = p->unit;
1187 struct fc_rport *rport = unit->port->rport;
1189 if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
1190 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1191 scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
1192 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1193 zfcp_unit_put(unit);
1194 wake_up(&unit->port->adapter->erp_done_wqh);
1198 static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
1200 struct zfcp_erp_add_work *p;
1202 p = kzalloc(sizeof(*p), GFP_KERNEL);
1204 dev_err(&unit->port->adapter->ccw_device->dev,
1205 "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
1206 (unsigned long long)unit->fcp_lun,
1207 (unsigned long long)unit->port->wwpn);
1211 zfcp_unit_get(unit);
1212 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1213 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1215 queue_work(zfcp_data.work_queue, &p->work);
1218 static void zfcp_erp_rport_register(struct zfcp_port *port)
1220 struct fc_rport_identifiers ids;
1221 ids.node_name = port->wwnn;
1222 ids.port_name = port->wwpn;
1223 ids.port_id = port->d_id;
1224 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
1225 port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
1227 dev_err(&port->adapter->ccw_device->dev,
1228 "Registering port 0x%016Lx failed\n",
1229 (unsigned long long)port->wwpn);
1233 scsi_target_unblock(&port->rport->dev);
1234 port->rport->maxframe_size = port->maxframe_size;
1235 port->rport->supported_classes = port->supported_classes;
1238 static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
1240 struct zfcp_port *port;
1241 list_for_each_entry(port, &adapter->port_list_head, list) {
1244 fc_remote_port_delete(port->rport);
1249 static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1251 struct zfcp_adapter *adapter = act->adapter;
1252 struct zfcp_port *port = act->port;
1253 struct zfcp_unit *unit = act->unit;
1255 switch (act->action) {
1256 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1257 if ((result == ZFCP_ERP_SUCCEEDED) &&
1258 !unit->device && port->rport) {
1259 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
1261 if (!(atomic_read(&unit->status) &
1262 ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
1263 zfcp_erp_schedule_work(unit);
1265 zfcp_unit_put(unit);
1268 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1269 case ZFCP_ERP_ACTION_REOPEN_PORT:
1270 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
1271 zfcp_port_put(port);
1274 if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
1275 zfcp_erp_rport_register(port);
1276 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
1277 fc_remote_port_delete(port->rport);
1280 zfcp_port_put(port);
1283 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1284 if (result != ZFCP_ERP_SUCCEEDED)
1285 zfcp_erp_rports_del(adapter);
1287 schedule_work(&adapter->scan_work);
1288 zfcp_adapter_put(adapter);
1293 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1295 switch (erp_action->action) {
1296 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1297 return zfcp_erp_adapter_strategy(erp_action);
1298 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1299 return zfcp_erp_port_forced_strategy(erp_action);
1300 case ZFCP_ERP_ACTION_REOPEN_PORT:
1301 return zfcp_erp_port_strategy(erp_action);
1302 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1303 return zfcp_erp_unit_strategy(erp_action);
1305 return ZFCP_ERP_FAILED;
1308 static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1311 struct zfcp_adapter *adapter = erp_action->adapter;
1312 unsigned long flags;
1314 read_lock_irqsave(&zfcp_data.config_lock, flags);
1315 write_lock(&adapter->erp_lock);
1317 zfcp_erp_strategy_check_fsfreq(erp_action);
1319 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1320 zfcp_erp_action_dequeue(erp_action);
1321 retval = ZFCP_ERP_DISMISSED;
1325 zfcp_erp_action_to_running(erp_action);
1327 /* no lock to allow for blocking operations */
1328 write_unlock(&adapter->erp_lock);
1329 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1330 retval = zfcp_erp_strategy_do_action(erp_action);
1331 read_lock_irqsave(&zfcp_data.config_lock, flags);
1332 write_lock(&adapter->erp_lock);
1334 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1335 retval = ZFCP_ERP_CONTINUES;
1338 case ZFCP_ERP_NOMEM:
1339 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1340 ++adapter->erp_low_mem_count;
1341 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1343 if (adapter->erp_total_count == adapter->erp_low_mem_count)
1344 _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
1346 zfcp_erp_strategy_memwait(erp_action);
1347 retval = ZFCP_ERP_CONTINUES;
1351 case ZFCP_ERP_CONTINUES:
1352 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1353 --adapter->erp_low_mem_count;
1354 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1359 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1360 zfcp_erp_action_dequeue(erp_action);
1361 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1362 if (retval == ZFCP_ERP_EXIT)
1364 zfcp_erp_strategy_followup_actions(erp_action);
1367 write_unlock(&adapter->erp_lock);
1368 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1370 if (retval != ZFCP_ERP_CONTINUES)
1371 zfcp_erp_action_cleanup(erp_action, retval);
1376 static int zfcp_erp_thread(void *data)
1378 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1379 struct list_head *next;
1380 struct zfcp_erp_action *act;
1381 unsigned long flags;
1383 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
1384 /* Block all signals */
1385 siginitsetinv(¤t->blocked, 0);
1386 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1387 wake_up(&adapter->erp_thread_wqh);
1389 while (!(atomic_read(&adapter->status) &
1390 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
1391 write_lock_irqsave(&adapter->erp_lock, flags);
1392 next = adapter->erp_ready_head.next;
1393 write_unlock_irqrestore(&adapter->erp_lock, flags);
1395 if (next != &adapter->erp_ready_head) {
1396 act = list_entry(next, struct zfcp_erp_action, list);
1398 /* there is more to come after dismission, no notify */
1399 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1400 zfcp_erp_wakeup(adapter);
1403 zfcp_rec_dbf_event_thread_lock(4, adapter);
1404 down_interruptible(&adapter->erp_ready_sem);
1405 zfcp_rec_dbf_event_thread_lock(5, adapter);
1408 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1409 wake_up(&adapter->erp_thread_wqh);
1415 * zfcp_erp_thread_setup - Start ERP thread for adapter
1416 * @adapter: Adapter to start the ERP thread for
1418 * Returns 0 on success or error code from kernel_thread()
1420 int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1424 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1425 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1427 dev_err(&adapter->ccw_device->dev,
1428 "Creating an ERP thread for the FCP device failed.\n");
1431 wait_event(adapter->erp_thread_wqh,
1432 atomic_read(&adapter->status) &
1433 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1438 * zfcp_erp_thread_kill - Stop ERP thread.
1439 * @adapter: Adapter where the ERP thread should be stopped.
1441 * The caller of this routine ensures that the specified adapter has
1442 * been shut down and that this operation has been completed. Thus,
1443 * there are no pending erp_actions which would need to be handled
1446 void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1448 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1449 up(&adapter->erp_ready_sem);
1450 zfcp_rec_dbf_event_thread_lock(3, adapter);
1452 wait_event(adapter->erp_thread_wqh,
1453 !(atomic_read(&adapter->status) &
1454 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1456 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1461 * zfcp_erp_adapter_failed - Set adapter status to failed.
1462 * @adapter: Failed adapter.
1463 * @id: Event id for debug trace.
1464 * @ref: Reference for debug trace.
1466 void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
1468 zfcp_erp_modify_adapter_status(adapter, id, ref,
1469 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1473 * zfcp_erp_port_failed - Set port status to failed.
1474 * @port: Failed port.
1475 * @id: Event id for debug trace.
1476 * @ref: Reference for debug trace.
1478 void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
1480 zfcp_erp_modify_port_status(port, id, ref,
1481 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1485 * zfcp_erp_unit_failed - Set unit status to failed.
1486 * @unit: Failed unit.
1487 * @id: Event id for debug trace.
1488 * @ref: Reference for debug trace.
1490 void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
1492 zfcp_erp_modify_unit_status(unit, id, ref,
1493 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1497 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1498 * @adapter: adapter for which to wait for completion of its error recovery
1500 void zfcp_erp_wait(struct zfcp_adapter *adapter)
1502 wait_event(adapter->erp_done_wqh,
1503 !(atomic_read(&adapter->status) &
1504 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1508 * zfcp_erp_modify_adapter_status - change adapter status bits
1509 * @adapter: adapter to change the status
1510 * @id: id for the debug trace
1511 * @ref: reference for the debug trace
1512 * @mask: status bits to change
1513 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1515 * Changes in common status bits are propagated to attached ports and units.
1517 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1518 void *ref, u32 mask, int set_or_clear)
1520 struct zfcp_port *port;
1521 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1523 if (set_or_clear == ZFCP_SET) {
1524 if (status_change_set(mask, &adapter->status))
1525 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1526 atomic_set_mask(mask, &adapter->status);
1528 if (status_change_clear(mask, &adapter->status))
1529 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1530 atomic_clear_mask(mask, &adapter->status);
1531 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1532 atomic_set(&adapter->erp_counter, 0);
1536 list_for_each_entry(port, &adapter->port_list_head, list)
1537 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1542 * zfcp_erp_modify_port_status - change port status bits
1543 * @port: port to change the status bits
1544 * @id: id for the debug trace
1545 * @ref: reference for the debug trace
1546 * @mask: status bits to change
1547 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1549 * Changes in common status bits are propagated to attached units.
1551 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
1552 u32 mask, int set_or_clear)
1554 struct zfcp_unit *unit;
1555 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1557 if (set_or_clear == ZFCP_SET) {
1558 if (status_change_set(mask, &port->status))
1559 zfcp_rec_dbf_event_port(id, ref, port);
1560 atomic_set_mask(mask, &port->status);
1562 if (status_change_clear(mask, &port->status))
1563 zfcp_rec_dbf_event_port(id, ref, port);
1564 atomic_clear_mask(mask, &port->status);
1565 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1566 atomic_set(&port->erp_counter, 0);
1570 list_for_each_entry(unit, &port->unit_list_head, list)
1571 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1576 * zfcp_erp_modify_unit_status - change unit status bits
1577 * @unit: unit to change the status bits
1578 * @id: id for the debug trace
1579 * @ref: reference for the debug trace
1580 * @mask: status bits to change
1581 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1583 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
1584 u32 mask, int set_or_clear)
1586 if (set_or_clear == ZFCP_SET) {
1587 if (status_change_set(mask, &unit->status))
1588 zfcp_rec_dbf_event_unit(id, ref, unit);
1589 atomic_set_mask(mask, &unit->status);
1591 if (status_change_clear(mask, &unit->status))
1592 zfcp_rec_dbf_event_unit(id, ref, unit);
1593 atomic_clear_mask(mask, &unit->status);
1594 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1595 atomic_set(&unit->erp_counter, 0);
1601 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1602 * @port: The "boxed" port.
1603 * @id: The debug trace id.
1604 * @id: Reference for the debug trace.
1606 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
1608 unsigned long flags;
1610 read_lock_irqsave(&zfcp_data.config_lock, flags);
1611 zfcp_erp_modify_port_status(port, id, ref,
1612 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1613 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1614 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1618 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1619 * @port: The "boxed" unit.
1620 * @id: The debug trace id.
1621 * @id: Reference for the debug trace.
1623 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
1625 zfcp_erp_modify_unit_status(unit, id, ref,
1626 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1627 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1631 * zfcp_erp_port_access_denied - Adapter denied access to port.
1632 * @port: port where access has been denied
1633 * @id: id for debug trace
1634 * @ref: reference for debug trace
1636 * Since the adapter has denied access, stop using the port and the
1639 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
1641 unsigned long flags;
1643 read_lock_irqsave(&zfcp_data.config_lock, flags);
1644 zfcp_erp_modify_port_status(port, id, ref,
1645 ZFCP_STATUS_COMMON_ERP_FAILED |
1646 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1647 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1651 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1652 * @unit: unit where access has been denied
1653 * @id: id for debug trace
1654 * @ref: reference for debug trace
1656 * Since the adapter has denied access, stop using the unit.
1658 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
1660 zfcp_erp_modify_unit_status(unit, id, ref,
1661 ZFCP_STATUS_COMMON_ERP_FAILED |
1662 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1665 static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
1668 int status = atomic_read(&unit->status);
1669 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1670 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1673 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1676 static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
1679 struct zfcp_unit *unit;
1680 int status = atomic_read(&port->status);
1682 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1683 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
1684 list_for_each_entry(unit, &port->unit_list_head, list)
1685 zfcp_erp_unit_access_changed(unit, id, ref);
1689 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1693 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1694 * @adapter: Adapter where the Access Control Table (ACT) changed
1695 * @id: Id for debug trace
1696 * @ref: Reference for debug trace
1698 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
1701 struct zfcp_port *port;
1702 unsigned long flags;
1704 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1707 read_lock_irqsave(&zfcp_data.config_lock, flags);
1708 list_for_each_entry(port, &adapter->port_list_head, list)
1709 zfcp_erp_port_access_changed(port, id, ref);
1710 read_unlock_irqrestore(&zfcp_data.config_lock, flags);