Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6] / drivers / s390 / scsi / zfcp_erp.c
1 /*
2  * zfcp device driver
3  *
4  * Error Recovery Procedures (ERP).
5  *
6  * Copyright IBM Corporation 2002, 2008
7  */
8
9 #include "zfcp_ext.h"
10
11 #define ZFCP_MAX_ERPS                   3
12
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,
19 };
20
21 enum zfcp_erp_steps {
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,
30 };
31
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,
37 };
38
39 enum zfcp_erp_act_state {
40         ZFCP_ERP_ACTION_RUNNING = 1,
41         ZFCP_ERP_ACTION_READY   = 2,
42 };
43
44 enum zfcp_erp_act_result {
45         ZFCP_ERP_SUCCEEDED = 0,
46         ZFCP_ERP_FAILED    = 1,
47         ZFCP_ERP_CONTINUES = 2,
48         ZFCP_ERP_EXIT      = 3,
49         ZFCP_ERP_DISMISSED = 4,
50         ZFCP_ERP_NOMEM     = 5,
51 };
52
53 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
54 {
55         zfcp_erp_modify_adapter_status(adapter, 15, NULL,
56                                        ZFCP_STATUS_COMMON_UNBLOCKED | mask,
57                                        ZFCP_CLEAR);
58 }
59
60 static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
61 {
62         struct zfcp_erp_action *curr_act;
63
64         list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
65                 if (act == curr_act)
66                         return ZFCP_ERP_ACTION_RUNNING;
67         return 0;
68 }
69
70 static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
71 {
72         struct zfcp_adapter *adapter = act->adapter;
73
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);
78 }
79
80 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
81 {
82         act->status |= ZFCP_STATUS_ERP_DISMISSED;
83         if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
84                 zfcp_erp_action_ready(act);
85 }
86
87 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
88 {
89         if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
90                 zfcp_erp_action_dismiss(&unit->erp_action);
91 }
92
93 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
94 {
95         struct zfcp_unit *unit;
96
97         if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
98                 zfcp_erp_action_dismiss(&port->erp_action);
99         else
100                 list_for_each_entry(unit, &port->unit_list_head, list)
101                     zfcp_erp_action_dismiss_unit(unit);
102 }
103
104 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
105 {
106         struct zfcp_port *port;
107
108         if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
109                 zfcp_erp_action_dismiss(&adapter->erp_action);
110         else
111                 list_for_each_entry(port, &adapter->port_list_head, list)
112                     zfcp_erp_action_dismiss_port(port);
113 }
114
115 static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
116                                  struct zfcp_port *port,
117                                  struct zfcp_unit *unit)
118 {
119         int need = want;
120         int u_status, p_status, a_status;
121
122         switch (want) {
123         case ZFCP_ERP_ACTION_REOPEN_UNIT:
124                 u_status = atomic_read(&unit->status);
125                 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
126                         return 0;
127                 p_status = atomic_read(&port->status);
128                 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
129                       p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
130                         return 0;
131                 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
132                         need = ZFCP_ERP_ACTION_REOPEN_PORT;
133                 /* fall through */
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)
138                         return 0;
139                 a_status = atomic_read(&adapter->status);
140                 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
141                       a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
142                         return 0;
143                 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
144                         need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
145                 /* fall through */
146         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
147                 a_status = atomic_read(&adapter->status);
148                 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
149                         return 0;
150         }
151
152         return need;
153 }
154
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)
159 {
160         struct zfcp_erp_action *erp_action;
161         u32 status = 0;
162
163         switch (need) {
164         case ZFCP_ERP_ACTION_REOPEN_UNIT:
165                 zfcp_unit_get(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;
170                 break;
171
172         case ZFCP_ERP_ACTION_REOPEN_PORT:
173         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
174                 zfcp_port_get(port);
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;
180                 break;
181
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;
190                 break;
191
192         default:
193                 return NULL;
194         }
195
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;
202
203         return erp_action;
204 }
205
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)
209 {
210         int retval = 1, need;
211         struct zfcp_erp_action *act = NULL;
212
213         if (!(atomic_read(&adapter->status) &
214               ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
215                 return -EIO;
216
217         need = zfcp_erp_required_act(want, adapter, port, unit);
218         if (!need)
219                 goto out;
220
221         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
222         act = zfcp_erp_setup_act(need, adapter, port, unit);
223         if (!act)
224                 goto out;
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);
229         retval = 0;
230  out:
231         zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
232                                    adapter, port, unit);
233         return retval;
234 }
235
236 static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
237                                     int clear_mask, u8 id, void *ref)
238 {
239         zfcp_erp_adapter_block(adapter, clear_mask);
240
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);
244                 return -EIO;
245         }
246         return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
247                                        adapter, NULL, NULL, id, ref);
248 }
249
250 /**
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.
256  */
257 void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
258                              u8 id, void *ref)
259 {
260         unsigned long flags;
261
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);
267 }
268
269 /**
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.
275  */
276 void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
277                                u8 id, void *ref)
278 {
279         int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
280         zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
281 }
282
283 /**
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.
289  */
290 void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref)
291 {
292         int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
293         zfcp_erp_port_reopen(port, clear | flags, id, ref);
294 }
295
296 /**
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.
302  */
303 void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref)
304 {
305         int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
306         zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
307 }
308
309 static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
310 {
311         zfcp_erp_modify_port_status(port, 17, NULL,
312                                     ZFCP_STATUS_COMMON_UNBLOCKED | clear,
313                                     ZFCP_CLEAR);
314 }
315
316 static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
317                                          int clear, u8 id, void *ref)
318 {
319         zfcp_erp_port_block(port, clear);
320
321         if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
322                 return;
323
324         zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
325                                 port->adapter, port, NULL, id, ref);
326 }
327
328 /**
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.
333  */
334 void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id,
335                                  void *ref)
336 {
337         unsigned long flags;
338         struct zfcp_adapter *adapter = port->adapter;
339
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);
345 }
346
347 static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id,
348                                  void *ref)
349 {
350         zfcp_erp_port_block(port, clear);
351
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);
355                 return -EIO;
356         }
357
358         return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
359                                        port->adapter, port, NULL, id, ref);
360 }
361
362 /**
363  * zfcp_erp_port_reopen - trigger remote port recovery
364  * @port: port to recover
365  * @clear_mask: flags in port status to be cleared
366  *
367  * Returns 0 if recovery has been triggered, < 0 if not.
368  */
369 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref)
370 {
371         unsigned long flags;
372         int retval;
373         struct zfcp_adapter *adapter = port->adapter;
374
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);
380
381         return retval;
382 }
383
384 static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
385 {
386         zfcp_erp_modify_unit_status(unit, 19, NULL,
387                                     ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
388                                     ZFCP_CLEAR);
389 }
390
391 static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id,
392                                   void *ref)
393 {
394         struct zfcp_adapter *adapter = unit->port->adapter;
395
396         zfcp_erp_unit_block(unit, clear);
397
398         if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
399                 return;
400
401         zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
402                                 adapter, unit->port, unit, id, ref);
403 }
404
405 /**
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
410  */
411 void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref)
412 {
413         unsigned long flags;
414         struct zfcp_port *port = unit->port;
415         struct zfcp_adapter *adapter = port->adapter;
416
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);
422 }
423
424 static int status_change_set(unsigned long mask, atomic_t *status)
425 {
426         return (atomic_read(status) ^ mask) & mask;
427 }
428
429 static int status_change_clear(unsigned long mask, atomic_t *status)
430 {
431         return atomic_read(status) & mask;
432 }
433
434 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
435 {
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);
439 }
440
441 static void zfcp_erp_port_unblock(struct zfcp_port *port)
442 {
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);
446 }
447
448 static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
449 {
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);
453 }
454
455 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
456 {
457         list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
458         zfcp_rec_dbf_event_action(145, erp_action);
459 }
460
461 static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
462 {
463         struct zfcp_adapter *adapter = act->adapter;
464
465         if (!act->fsf_req)
466                 return;
467
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                 }
476                 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
477                         zfcp_rec_dbf_event_action(143, act);
478                 if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
479                                             ZFCP_STATUS_FSFREQ_DISMISSED))
480                         act->fsf_req = NULL;
481         } else
482                 act->fsf_req = NULL;
483         spin_unlock(&adapter->req_list_lock);
484 }
485
486 /**
487  * zfcp_erp_notify - Trigger ERP action.
488  * @erp_action: ERP action to continue.
489  * @set_mask: ERP action status flags to set.
490  */
491 void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
492 {
493         struct zfcp_adapter *adapter = erp_action->adapter;
494         unsigned long flags;
495
496         write_lock_irqsave(&adapter->erp_lock, flags);
497         if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
498                 erp_action->status |= set_mask;
499                 zfcp_erp_action_ready(erp_action);
500         }
501         write_unlock_irqrestore(&adapter->erp_lock, flags);
502 }
503
504 /**
505  * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
506  * @data: ERP action (from timer data)
507  */
508 void zfcp_erp_timeout_handler(unsigned long data)
509 {
510         struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
511         zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
512 }
513
514 static void zfcp_erp_memwait_handler(unsigned long data)
515 {
516         zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
517 }
518
519 static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
520 {
521         init_timer(&erp_action->timer);
522         erp_action->timer.function = zfcp_erp_memwait_handler;
523         erp_action->timer.data = (unsigned long) erp_action;
524         erp_action->timer.expires = jiffies + HZ;
525         add_timer(&erp_action->timer);
526 }
527
528 static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
529                                       int clear, u8 id, void *ref)
530 {
531         struct zfcp_port *port;
532
533         list_for_each_entry(port, &adapter->port_list_head, list)
534                 _zfcp_erp_port_reopen(port, clear, id, ref);
535 }
536
537 static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id,
538                                       void *ref)
539 {
540         struct zfcp_unit *unit;
541
542         list_for_each_entry(unit, &port->unit_list_head, list)
543                 _zfcp_erp_unit_reopen(unit, clear, id, ref);
544 }
545
546 static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
547 {
548         struct zfcp_adapter *adapter = act->adapter;
549         struct zfcp_port *port = act->port;
550         struct zfcp_unit *unit = act->unit;
551         u32 status = act->status;
552
553         /* initiate follow-up actions depending on success of finished action */
554         switch (act->action) {
555
556         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
557                 if (status == ZFCP_ERP_SUCCEEDED)
558                         _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL);
559                 else
560                         _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL);
561                 break;
562
563         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
564                 if (status == ZFCP_ERP_SUCCEEDED)
565                         _zfcp_erp_port_reopen(port, 0, 72, NULL);
566                 else
567                         _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL);
568                 break;
569
570         case ZFCP_ERP_ACTION_REOPEN_PORT:
571                 if (status == ZFCP_ERP_SUCCEEDED)
572                         _zfcp_erp_unit_reopen_all(port, 0, 74, NULL);
573                 else
574                         _zfcp_erp_port_forced_reopen(port, 0, 75, NULL);
575                 break;
576
577         case ZFCP_ERP_ACTION_REOPEN_UNIT:
578                 if (status != ZFCP_ERP_SUCCEEDED)
579                         _zfcp_erp_port_reopen(unit->port, 0, 76, NULL);
580                 break;
581         }
582 }
583
584 static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
585 {
586         unsigned long flags;
587
588         read_lock_irqsave(&zfcp_data.config_lock, flags);
589         read_lock(&adapter->erp_lock);
590         if (list_empty(&adapter->erp_ready_head) &&
591             list_empty(&adapter->erp_running_head)) {
592                         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
593                                           &adapter->status);
594                         wake_up(&adapter->erp_done_wqh);
595         }
596         read_unlock(&adapter->erp_lock);
597         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
598 }
599
600 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
601 {
602         if (zfcp_qdio_open(act->adapter))
603                 return ZFCP_ERP_FAILED;
604         init_waitqueue_head(&act->adapter->request_wq);
605         atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
606         return ZFCP_ERP_SUCCEEDED;
607 }
608
609 static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
610 {
611         struct zfcp_port *port;
612         port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
613                                  adapter->peer_d_id);
614         if (IS_ERR(port)) /* error or port already attached */
615                 return;
616         _zfcp_erp_port_reopen(port, 0, 150, NULL);
617 }
618
619 static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
620 {
621         int retries;
622         int sleep = 1;
623         struct zfcp_adapter *adapter = erp_action->adapter;
624
625         atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
626
627         for (retries = 7; retries; retries--) {
628                 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
629                                   &adapter->status);
630                 write_lock_irq(&adapter->erp_lock);
631                 zfcp_erp_action_to_running(erp_action);
632                 write_unlock_irq(&adapter->erp_lock);
633                 if (zfcp_fsf_exchange_config_data(erp_action)) {
634                         atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
635                                           &adapter->status);
636                         return ZFCP_ERP_FAILED;
637                 }
638
639                 zfcp_rec_dbf_event_thread_lock(6, adapter);
640                 down(&adapter->erp_ready_sem);
641                 zfcp_rec_dbf_event_thread_lock(7, adapter);
642                 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
643                         break;
644
645                 if (!(atomic_read(&adapter->status) &
646                       ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
647                         break;
648
649                 ssleep(sleep);
650                 sleep *= 2;
651         }
652
653         atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
654                           &adapter->status);
655
656         if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
657                 return ZFCP_ERP_FAILED;
658
659         if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
660                 zfcp_erp_enqueue_ptp_port(adapter);
661
662         return ZFCP_ERP_SUCCEEDED;
663 }
664
665 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
666 {
667         int ret;
668         struct zfcp_adapter *adapter = act->adapter;
669
670         write_lock_irq(&adapter->erp_lock);
671         zfcp_erp_action_to_running(act);
672         write_unlock_irq(&adapter->erp_lock);
673
674         ret = zfcp_fsf_exchange_port_data(act);
675         if (ret == -EOPNOTSUPP)
676                 return ZFCP_ERP_SUCCEEDED;
677         if (ret)
678                 return ZFCP_ERP_FAILED;
679
680         zfcp_rec_dbf_event_thread_lock(8, adapter);
681         down(&adapter->erp_ready_sem);
682         zfcp_rec_dbf_event_thread_lock(9, adapter);
683         if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
684                 return ZFCP_ERP_FAILED;
685
686         return ZFCP_ERP_SUCCEEDED;
687 }
688
689 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
690 {
691         if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
692                 return ZFCP_ERP_FAILED;
693
694         if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
695                 return ZFCP_ERP_FAILED;
696
697         atomic_set(&act->adapter->stat_miss, 16);
698         if (zfcp_status_read_refill(act->adapter))
699                 return ZFCP_ERP_FAILED;
700
701         return ZFCP_ERP_SUCCEEDED;
702 }
703
704 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act,
705                                              int close)
706 {
707         int retval = ZFCP_ERP_SUCCEEDED;
708         struct zfcp_adapter *adapter = act->adapter;
709
710         if (close)
711                 goto close_only;
712
713         retval = zfcp_erp_adapter_strategy_open_qdio(act);
714         if (retval != ZFCP_ERP_SUCCEEDED)
715                 goto failed_qdio;
716
717         retval = zfcp_erp_adapter_strategy_open_fsf(act);
718         if (retval != ZFCP_ERP_SUCCEEDED)
719                 goto failed_openfcp;
720
721         atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status);
722         schedule_work(&act->adapter->scan_work);
723
724         return ZFCP_ERP_SUCCEEDED;
725
726  close_only:
727         atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
728                           &act->adapter->status);
729
730  failed_openfcp:
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);
738  failed_qdio:
739         atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
740                           ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
741                           &act->adapter->status);
742         return retval;
743 }
744
745 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
746 {
747         int retval;
748
749         zfcp_erp_adapter_strategy_generic(act, 1); /* close */
750         if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
751                 return ZFCP_ERP_EXIT;
752
753         retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */
754
755         if (retval == ZFCP_ERP_FAILED)
756                 ssleep(8);
757
758         return retval;
759 }
760
761 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
762 {
763         int retval;
764
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;
769         if (retval)
770                 return ZFCP_ERP_FAILED;
771
772         return ZFCP_ERP_CONTINUES;
773 }
774
775 static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
776 {
777         atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
778                           ZFCP_STATUS_PORT_PHYS_CLOSING |
779                           ZFCP_STATUS_PORT_INVALID_WWPN,
780                           &port->status);
781 }
782
783 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
784 {
785         struct zfcp_port *port = erp_action->port;
786         int status = atomic_read(&port->status);
787
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);
794                 else
795                         return ZFCP_ERP_FAILED;
796
797         case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
798                 if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
799                         return ZFCP_ERP_SUCCEEDED;
800         }
801         return ZFCP_ERP_FAILED;
802 }
803
804 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
805 {
806         int retval;
807
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;
812         if (retval)
813                 return ZFCP_ERP_FAILED;
814         return ZFCP_ERP_CONTINUES;
815 }
816
817 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
818 {
819         int retval;
820
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;
825         if (retval)
826                 return ZFCP_ERP_FAILED;
827         return ZFCP_ERP_CONTINUES;
828 }
829
830 static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
831 {
832         struct zfcp_adapter *adapter = act->adapter;
833         struct zfcp_port *port = act->port;
834
835         if (port->wwpn != adapter->peer_wwpn) {
836                 zfcp_erp_port_failed(port, 25, NULL);
837                 return ZFCP_ERP_FAILED;
838         }
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);
842 }
843
844 void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
845 {
846         int retval;
847         struct zfcp_port *port = container_of(work, struct zfcp_port,
848                                               gid_pn_work);
849
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;
854         if (retval)
855                 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
856
857 }
858
859 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
860 {
861         struct zfcp_adapter *adapter = act->adapter;
862         struct zfcp_port *port = act->port;
863         int p_status = atomic_read(&port->status);
864
865         switch (act->step) {
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;
874                 }
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;
880                         }
881                         return ZFCP_ERP_FAILED;
882                 }
883                 return zfcp_erp_port_strategy_open_port(act);
884
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;
890                         else {
891                                 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
892                                 return ZFCP_ERP_CONTINUES;
893                         }
894                 /* fall through otherwise */
895                 }
896         }
897         return ZFCP_ERP_FAILED;
898 }
899
900 static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
901 {
902         struct zfcp_port *port = erp_action->port;
903
904         if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
905                 goto close_init_done;
906
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);
912                 break;
913
914         case ZFCP_ERP_STEP_PORT_CLOSING:
915                 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
916                         return ZFCP_ERP_FAILED;
917                 break;
918         }
919
920 close_init_done:
921         if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
922                 return ZFCP_ERP_EXIT;
923
924         return zfcp_erp_port_strategy_open_common(erp_action);
925 }
926
927 static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
928 {
929         atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
930                           ZFCP_STATUS_UNIT_SHARED |
931                           ZFCP_STATUS_UNIT_READONLY,
932                           &unit->status);
933 }
934
935 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
936 {
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;
941         if (retval)
942                 return ZFCP_ERP_FAILED;
943         return ZFCP_ERP_CONTINUES;
944 }
945
946 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
947 {
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;
952         if (retval)
953                 return  ZFCP_ERP_FAILED;
954         return ZFCP_ERP_CONTINUES;
955 }
956
957 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
958 {
959         struct zfcp_unit *unit = erp_action->unit;
960
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);
973
974         case ZFCP_ERP_STEP_UNIT_OPENING:
975                 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
976                         return ZFCP_ERP_SUCCEEDED;
977         }
978         return ZFCP_ERP_FAILED;
979 }
980
981 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
982 {
983         switch (result) {
984         case ZFCP_ERP_SUCCEEDED :
985                 atomic_set(&unit->erp_counter, 0);
986                 zfcp_erp_unit_unblock(unit);
987                 break;
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 "
993                                 "port 0x%016Lx\n",
994                                 (unsigned long long)unit->fcp_lun,
995                                 (unsigned long long)unit->port->wwpn);
996                         zfcp_erp_unit_failed(unit, 21, NULL);
997                 }
998                 break;
999         }
1000
1001         if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1002                 zfcp_erp_unit_block(unit, 0);
1003                 result = ZFCP_ERP_EXIT;
1004         }
1005         return result;
1006 }
1007
1008 static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1009 {
1010         switch (result) {
1011         case ZFCP_ERP_SUCCEEDED :
1012                 atomic_set(&port->erp_counter, 0);
1013                 zfcp_erp_port_unblock(port);
1014                 break;
1015
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;
1020                 }
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);
1027                 }
1028                 break;
1029         }
1030
1031         if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1032                 zfcp_erp_port_block(port, 0);
1033                 result = ZFCP_ERP_EXIT;
1034         }
1035         return result;
1036 }
1037
1038 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1039                                            int result)
1040 {
1041         switch (result) {
1042         case ZFCP_ERP_SUCCEEDED :
1043                 atomic_set(&adapter->erp_counter, 0);
1044                 zfcp_erp_adapter_unblock(adapter);
1045                 break;
1046
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);
1054                 }
1055                 break;
1056         }
1057
1058         if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1059                 zfcp_erp_adapter_block(adapter, 0);
1060                 result = ZFCP_ERP_EXIT;
1061         }
1062         return result;
1063 }
1064
1065 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1066                                           int result)
1067 {
1068         struct zfcp_adapter *adapter = erp_action->adapter;
1069         struct zfcp_port *port = erp_action->port;
1070         struct zfcp_unit *unit = erp_action->unit;
1071
1072         switch (erp_action->action) {
1073
1074         case ZFCP_ERP_ACTION_REOPEN_UNIT:
1075                 result = zfcp_erp_strategy_check_unit(unit, result);
1076                 break;
1077
1078         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1079         case ZFCP_ERP_ACTION_REOPEN_PORT:
1080                 result = zfcp_erp_strategy_check_port(port, result);
1081                 break;
1082
1083         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1084                 result = zfcp_erp_strategy_check_adapter(adapter, result);
1085                 break;
1086         }
1087         return result;
1088 }
1089
1090 static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
1091 {
1092         int status = atomic_read(target_status);
1093
1094         if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1095             (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1096                 return 1; /* take it online */
1097
1098         if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1099             !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1100                 return 1; /* take it offline */
1101
1102         return 0;
1103 }
1104
1105 static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1106 {
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;
1112
1113         switch (action) {
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,
1118                                                  67, NULL);
1119                         return ZFCP_ERP_EXIT;
1120                 }
1121                 break;
1122
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,
1128                                               68, NULL);
1129                         return ZFCP_ERP_EXIT;
1130                 }
1131                 break;
1132
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,
1137                                               69, NULL);
1138                         return ZFCP_ERP_EXIT;
1139                 }
1140                 break;
1141         }
1142         return ret;
1143 }
1144
1145 static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
1146 {
1147         struct zfcp_adapter *adapter = erp_action->adapter;
1148
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;
1153         }
1154
1155         list_del(&erp_action->list);
1156         zfcp_rec_dbf_event_action(144, erp_action);
1157
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);
1162                 break;
1163
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);
1168                 break;
1169
1170         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1171                 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1172                                   &erp_action->adapter->status);
1173                 break;
1174         }
1175 }
1176
1177 struct zfcp_erp_add_work {
1178         struct zfcp_unit  *unit;
1179         struct work_struct work;
1180 };
1181
1182 static void zfcp_erp_scsi_scan(struct work_struct *work)
1183 {
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;
1188         scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1189                          scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
1190         atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1191         zfcp_unit_put(unit);
1192         wake_up(&unit->port->adapter->erp_done_wqh);
1193         kfree(p);
1194 }
1195
1196 static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
1197 {
1198         struct zfcp_erp_add_work *p;
1199
1200         p = kzalloc(sizeof(*p), GFP_KERNEL);
1201         if (!p) {
1202                 dev_err(&unit->port->adapter->ccw_device->dev,
1203                         "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
1204                         (unsigned long long)unit->fcp_lun,
1205                         (unsigned long long)unit->port->wwpn);
1206                 return;
1207         }
1208
1209         zfcp_unit_get(unit);
1210         atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1211         INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1212         p->unit = unit;
1213         queue_work(zfcp_data.work_queue, &p->work);
1214 }
1215
1216 static void zfcp_erp_rport_register(struct zfcp_port *port)
1217 {
1218         struct fc_rport_identifiers ids;
1219         ids.node_name = port->wwnn;
1220         ids.port_name = port->wwpn;
1221         ids.port_id = port->d_id;
1222         ids.roles = FC_RPORT_ROLE_FCP_TARGET;
1223         port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids);
1224         if (!port->rport) {
1225                 dev_err(&port->adapter->ccw_device->dev,
1226                         "Registering port 0x%016Lx failed\n",
1227                         (unsigned long long)port->wwpn);
1228                 return;
1229         }
1230
1231         scsi_target_unblock(&port->rport->dev);
1232         port->rport->maxframe_size = port->maxframe_size;
1233         port->rport->supported_classes = port->supported_classes;
1234 }
1235
1236 static void zfcp_erp_rports_del(struct zfcp_adapter *adapter)
1237 {
1238         struct zfcp_port *port;
1239         list_for_each_entry(port, &adapter->port_list_head, list) {
1240                 if (!port->rport)
1241                         continue;
1242                 fc_remote_port_delete(port->rport);
1243                 port->rport = NULL;
1244         }
1245 }
1246
1247 static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
1248 {
1249         struct zfcp_adapter *adapter = act->adapter;
1250         struct zfcp_port *port = act->port;
1251         struct zfcp_unit *unit = act->unit;
1252
1253         switch (act->action) {
1254         case ZFCP_ERP_ACTION_REOPEN_UNIT:
1255                 if ((result == ZFCP_ERP_SUCCEEDED) &&
1256                     !unit->device && port->rport) {
1257                         atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
1258                                         &unit->status);
1259                         if (!(atomic_read(&unit->status) &
1260                               ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
1261                                 zfcp_erp_schedule_work(unit);
1262                 }
1263                 zfcp_unit_put(unit);
1264                 break;
1265
1266         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1267         case ZFCP_ERP_ACTION_REOPEN_PORT:
1268                 if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) {
1269                         zfcp_port_put(port);
1270                         return;
1271                 }
1272                 if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport)
1273                         zfcp_erp_rport_register(port);
1274                 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
1275                         fc_remote_port_delete(port->rport);
1276                         port->rport = NULL;
1277                 }
1278                 zfcp_port_put(port);
1279                 break;
1280
1281         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1282                 if (result != ZFCP_ERP_SUCCEEDED)
1283                         zfcp_erp_rports_del(adapter);
1284                 zfcp_adapter_put(adapter);
1285                 break;
1286         }
1287 }
1288
1289 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1290 {
1291         switch (erp_action->action) {
1292         case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1293                 return zfcp_erp_adapter_strategy(erp_action);
1294         case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1295                 return zfcp_erp_port_forced_strategy(erp_action);
1296         case ZFCP_ERP_ACTION_REOPEN_PORT:
1297                 return zfcp_erp_port_strategy(erp_action);
1298         case ZFCP_ERP_ACTION_REOPEN_UNIT:
1299                 return zfcp_erp_unit_strategy(erp_action);
1300         }
1301         return ZFCP_ERP_FAILED;
1302 }
1303
1304 static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1305 {
1306         int retval;
1307         struct zfcp_adapter *adapter = erp_action->adapter;
1308         unsigned long flags;
1309
1310         read_lock_irqsave(&zfcp_data.config_lock, flags);
1311         write_lock(&adapter->erp_lock);
1312
1313         zfcp_erp_strategy_check_fsfreq(erp_action);
1314
1315         if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1316                 zfcp_erp_action_dequeue(erp_action);
1317                 retval = ZFCP_ERP_DISMISSED;
1318                 goto unlock;
1319         }
1320
1321         zfcp_erp_action_to_running(erp_action);
1322
1323         /* no lock to allow for blocking operations */
1324         write_unlock(&adapter->erp_lock);
1325         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1326         retval = zfcp_erp_strategy_do_action(erp_action);
1327         read_lock_irqsave(&zfcp_data.config_lock, flags);
1328         write_lock(&adapter->erp_lock);
1329
1330         if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1331                 retval = ZFCP_ERP_CONTINUES;
1332
1333         switch (retval) {
1334         case ZFCP_ERP_NOMEM:
1335                 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1336                         ++adapter->erp_low_mem_count;
1337                         erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1338                 }
1339                 if (adapter->erp_total_count == adapter->erp_low_mem_count)
1340                         _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL);
1341                 else {
1342                         zfcp_erp_strategy_memwait(erp_action);
1343                         retval = ZFCP_ERP_CONTINUES;
1344                 }
1345                 goto unlock;
1346
1347         case ZFCP_ERP_CONTINUES:
1348                 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1349                         --adapter->erp_low_mem_count;
1350                         erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1351                 }
1352                 goto unlock;
1353         }
1354
1355         retval = zfcp_erp_strategy_check_target(erp_action, retval);
1356         zfcp_erp_action_dequeue(erp_action);
1357         retval = zfcp_erp_strategy_statechange(erp_action, retval);
1358         if (retval == ZFCP_ERP_EXIT)
1359                 goto unlock;
1360         zfcp_erp_strategy_followup_actions(erp_action);
1361
1362  unlock:
1363         write_unlock(&adapter->erp_lock);
1364         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1365
1366         if (retval != ZFCP_ERP_CONTINUES)
1367                 zfcp_erp_action_cleanup(erp_action, retval);
1368
1369         return retval;
1370 }
1371
1372 static int zfcp_erp_thread(void *data)
1373 {
1374         struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1375         struct list_head *next;
1376         struct zfcp_erp_action *act;
1377         unsigned long flags;
1378
1379         daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
1380         /* Block all signals */
1381         siginitsetinv(&current->blocked, 0);
1382         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1383         wake_up(&adapter->erp_thread_wqh);
1384
1385         while (!(atomic_read(&adapter->status) &
1386                  ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
1387                 write_lock_irqsave(&adapter->erp_lock, flags);
1388                 next = adapter->erp_ready_head.next;
1389                 write_unlock_irqrestore(&adapter->erp_lock, flags);
1390
1391                 if (next != &adapter->erp_ready_head) {
1392                         act = list_entry(next, struct zfcp_erp_action, list);
1393
1394                         /* there is more to come after dismission, no notify */
1395                         if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1396                                 zfcp_erp_wakeup(adapter);
1397                 }
1398
1399                 zfcp_rec_dbf_event_thread_lock(4, adapter);
1400                 down_interruptible(&adapter->erp_ready_sem);
1401                 zfcp_rec_dbf_event_thread_lock(5, adapter);
1402         }
1403
1404         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1405         wake_up(&adapter->erp_thread_wqh);
1406
1407         return 0;
1408 }
1409
1410 /**
1411  * zfcp_erp_thread_setup - Start ERP thread for adapter
1412  * @adapter: Adapter to start the ERP thread for
1413  *
1414  * Returns 0 on success or error code from kernel_thread()
1415  */
1416 int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1417 {
1418         int retval;
1419
1420         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1421         retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1422         if (retval < 0) {
1423                 dev_err(&adapter->ccw_device->dev,
1424                         "Creating an ERP thread for the FCP device failed.\n");
1425                 return retval;
1426         }
1427         wait_event(adapter->erp_thread_wqh,
1428                    atomic_read(&adapter->status) &
1429                         ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1430         return 0;
1431 }
1432
1433 /**
1434  * zfcp_erp_thread_kill - Stop ERP thread.
1435  * @adapter: Adapter where the ERP thread should be stopped.
1436  *
1437  * The caller of this routine ensures that the specified adapter has
1438  * been shut down and that this operation has been completed. Thus,
1439  * there are no pending erp_actions which would need to be handled
1440  * here.
1441  */
1442 void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1443 {
1444         atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1445         up(&adapter->erp_ready_sem);
1446         zfcp_rec_dbf_event_thread_lock(3, adapter);
1447
1448         wait_event(adapter->erp_thread_wqh,
1449                    !(atomic_read(&adapter->status) &
1450                                 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1451
1452         atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1453                           &adapter->status);
1454 }
1455
1456 /**
1457  * zfcp_erp_adapter_failed - Set adapter status to failed.
1458  * @adapter: Failed adapter.
1459  * @id: Event id for debug trace.
1460  * @ref: Reference for debug trace.
1461  */
1462 void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
1463 {
1464         zfcp_erp_modify_adapter_status(adapter, id, ref,
1465                                        ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1466 }
1467
1468 /**
1469  * zfcp_erp_port_failed - Set port status to failed.
1470  * @port: Failed port.
1471  * @id: Event id for debug trace.
1472  * @ref: Reference for debug trace.
1473  */
1474 void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
1475 {
1476         zfcp_erp_modify_port_status(port, id, ref,
1477                                     ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1478 }
1479
1480 /**
1481  * zfcp_erp_unit_failed - Set unit status to failed.
1482  * @unit: Failed unit.
1483  * @id: Event id for debug trace.
1484  * @ref: Reference for debug trace.
1485  */
1486 void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
1487 {
1488         zfcp_erp_modify_unit_status(unit, id, ref,
1489                                     ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1490 }
1491
1492 /**
1493  * zfcp_erp_wait - wait for completion of error recovery on an adapter
1494  * @adapter: adapter for which to wait for completion of its error recovery
1495  */
1496 void zfcp_erp_wait(struct zfcp_adapter *adapter)
1497 {
1498         wait_event(adapter->erp_done_wqh,
1499                    !(atomic_read(&adapter->status) &
1500                         ZFCP_STATUS_ADAPTER_ERP_PENDING));
1501 }
1502
1503 /**
1504  * zfcp_erp_modify_adapter_status - change adapter status bits
1505  * @adapter: adapter to change the status
1506  * @id: id for the debug trace
1507  * @ref: reference for the debug trace
1508  * @mask: status bits to change
1509  * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1510  *
1511  * Changes in common status bits are propagated to attached ports and units.
1512  */
1513 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1514                                     void *ref, u32 mask, int set_or_clear)
1515 {
1516         struct zfcp_port *port;
1517         u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1518
1519         if (set_or_clear == ZFCP_SET) {
1520                 if (status_change_set(mask, &adapter->status))
1521                         zfcp_rec_dbf_event_adapter(id, ref, adapter);
1522                 atomic_set_mask(mask, &adapter->status);
1523         } else {
1524                 if (status_change_clear(mask, &adapter->status))
1525                         zfcp_rec_dbf_event_adapter(id, ref, adapter);
1526                 atomic_clear_mask(mask, &adapter->status);
1527                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1528                         atomic_set(&adapter->erp_counter, 0);
1529         }
1530
1531         if (common_mask)
1532                 list_for_each_entry(port, &adapter->port_list_head, list)
1533                         zfcp_erp_modify_port_status(port, id, ref, common_mask,
1534                                                     set_or_clear);
1535 }
1536
1537 /**
1538  * zfcp_erp_modify_port_status - change port status bits
1539  * @port: port to change the status bits
1540  * @id: id for the debug trace
1541  * @ref: reference for the debug trace
1542  * @mask: status bits to change
1543  * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1544  *
1545  * Changes in common status bits are propagated to attached units.
1546  */
1547 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
1548                                  u32 mask, int set_or_clear)
1549 {
1550         struct zfcp_unit *unit;
1551         u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1552
1553         if (set_or_clear == ZFCP_SET) {
1554                 if (status_change_set(mask, &port->status))
1555                         zfcp_rec_dbf_event_port(id, ref, port);
1556                 atomic_set_mask(mask, &port->status);
1557         } else {
1558                 if (status_change_clear(mask, &port->status))
1559                         zfcp_rec_dbf_event_port(id, ref, port);
1560                 atomic_clear_mask(mask, &port->status);
1561                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1562                         atomic_set(&port->erp_counter, 0);
1563         }
1564
1565         if (common_mask)
1566                 list_for_each_entry(unit, &port->unit_list_head, list)
1567                         zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1568                                                     set_or_clear);
1569 }
1570
1571 /**
1572  * zfcp_erp_modify_unit_status - change unit status bits
1573  * @unit: unit to change the status bits
1574  * @id: id for the debug trace
1575  * @ref: reference for the debug trace
1576  * @mask: status bits to change
1577  * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1578  */
1579 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
1580                                  u32 mask, int set_or_clear)
1581 {
1582         if (set_or_clear == ZFCP_SET) {
1583                 if (status_change_set(mask, &unit->status))
1584                         zfcp_rec_dbf_event_unit(id, ref, unit);
1585                 atomic_set_mask(mask, &unit->status);
1586         } else {
1587                 if (status_change_clear(mask, &unit->status))
1588                         zfcp_rec_dbf_event_unit(id, ref, unit);
1589                 atomic_clear_mask(mask, &unit->status);
1590                 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1591                         atomic_set(&unit->erp_counter, 0);
1592                 }
1593         }
1594 }
1595
1596 /**
1597  * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1598  * @port: The "boxed" port.
1599  * @id: The debug trace id.
1600  * @id: Reference for the debug trace.
1601  */
1602 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
1603 {
1604         unsigned long flags;
1605
1606         read_lock_irqsave(&zfcp_data.config_lock, flags);
1607         zfcp_erp_modify_port_status(port, id, ref,
1608                                     ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1609         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1610         zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1611 }
1612
1613 /**
1614  * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1615  * @port: The "boxed" unit.
1616  * @id: The debug trace id.
1617  * @id: Reference for the debug trace.
1618  */
1619 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
1620 {
1621         zfcp_erp_modify_unit_status(unit, id, ref,
1622                                     ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
1623         zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1624 }
1625
1626 /**
1627  * zfcp_erp_port_access_denied - Adapter denied access to port.
1628  * @port: port where access has been denied
1629  * @id: id for debug trace
1630  * @ref: reference for debug trace
1631  *
1632  * Since the adapter has denied access, stop using the port and the
1633  * attached units.
1634  */
1635 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
1636 {
1637         unsigned long flags;
1638
1639         read_lock_irqsave(&zfcp_data.config_lock, flags);
1640         zfcp_erp_modify_port_status(port, id, ref,
1641                                     ZFCP_STATUS_COMMON_ERP_FAILED |
1642                                     ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1643         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1644 }
1645
1646 /**
1647  * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1648  * @unit: unit where access has been denied
1649  * @id: id for debug trace
1650  * @ref: reference for debug trace
1651  *
1652  * Since the adapter has denied access, stop using the unit.
1653  */
1654 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
1655 {
1656         zfcp_erp_modify_unit_status(unit, id, ref,
1657                                     ZFCP_STATUS_COMMON_ERP_FAILED |
1658                                     ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
1659 }
1660
1661 static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id,
1662                                          void *ref)
1663 {
1664         int status = atomic_read(&unit->status);
1665         if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1666                         ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1667                 return;
1668
1669         zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1670 }
1671
1672 static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id,
1673                                          void *ref)
1674 {
1675         struct zfcp_unit *unit;
1676         int status = atomic_read(&port->status);
1677
1678         if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1679                         ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
1680                 list_for_each_entry(unit, &port->unit_list_head, list)
1681                                     zfcp_erp_unit_access_changed(unit, id, ref);
1682                 return;
1683         }
1684
1685         zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1686 }
1687
1688 /**
1689  * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1690  * @adapter: Adapter where the Access Control Table (ACT) changed
1691  * @id: Id for debug trace
1692  * @ref: Reference for debug trace
1693  */
1694 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
1695                                      void *ref)
1696 {
1697         struct zfcp_port *port;
1698         unsigned long flags;
1699
1700         if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1701                 return;
1702
1703         read_lock_irqsave(&zfcp_data.config_lock, flags);
1704         list_for_each_entry(port, &adapter->port_list_head, list)
1705                 zfcp_erp_port_access_changed(port, id, ref);
1706         read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1707 }