blob: c75d6f35cb5f64d05e88ac8b423d7cb03e2977e6 [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Error Recovery Procedures (ERP).
Swen Schillig41fa2ad2007-09-07 09:15:31 +02005 *
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01006 * Copyright IBM Corporation 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "zfcp_ext.h"
13
Christof Schmitt287ac012008-07-02 10:56:40 +020014#define ZFCP_MAX_ERPS 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Christof Schmitt287ac012008-07-02 10:56:40 +020016enum zfcp_erp_act_flags {
17 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
18 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
19 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
20 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
21 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
22};
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Christof Schmitt287ac012008-07-02 10:56:40 +020024enum zfcp_erp_steps {
25 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
26 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
27 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
28 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
Christof Schmitt287ac012008-07-02 10:56:40 +020029 ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400,
30 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
31 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
32 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
33};
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Christof Schmitt287ac012008-07-02 10:56:40 +020035enum zfcp_erp_act_type {
36 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
37 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
38 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
39 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
40};
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Christof Schmitt287ac012008-07-02 10:56:40 +020042enum zfcp_erp_act_state {
43 ZFCP_ERP_ACTION_RUNNING = 1,
44 ZFCP_ERP_ACTION_READY = 2,
45};
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Christof Schmitt287ac012008-07-02 10:56:40 +020047enum zfcp_erp_act_result {
48 ZFCP_ERP_SUCCEEDED = 0,
49 ZFCP_ERP_FAILED = 1,
50 ZFCP_ERP_CONTINUES = 2,
51 ZFCP_ERP_EXIT = 3,
52 ZFCP_ERP_DISMISSED = 4,
53 ZFCP_ERP_NOMEM = 5,
54};
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Christof Schmitt287ac012008-07-02 10:56:40 +020056static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
Andreas Herrmann2abbe862006-09-18 22:29:56 +020057{
Swen Schillig5ffd51a2009-03-02 13:09:04 +010058 zfcp_erp_modify_adapter_status(adapter, "erablk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +020059 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
60 ZFCP_CLEAR);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020061}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Christof Schmitt287ac012008-07-02 10:56:40 +020063static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Christof Schmitt287ac012008-07-02 10:56:40 +020065 struct zfcp_erp_action *curr_act;
66
67 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
68 if (act == curr_act)
69 return ZFCP_ERP_ACTION_RUNNING;
70 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
Christof Schmitt287ac012008-07-02 10:56:40 +020073static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Christof Schmitt287ac012008-07-02 10:56:40 +020075 struct zfcp_adapter *adapter = act->adapter;
76
77 list_move(&act->list, &act->adapter->erp_ready_head);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010078 zfcp_rec_dbf_event_action("erardy1", act);
Christof Schmitt287ac012008-07-02 10:56:40 +020079 up(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +010080 zfcp_rec_dbf_event_thread("erardy2", adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Christof Schmitt287ac012008-07-02 10:56:40 +020083static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Christof Schmitt287ac012008-07-02 10:56:40 +020085 act->status |= ZFCP_STATUS_ERP_DISMISSED;
86 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
87 zfcp_erp_action_ready(act);
88}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Christof Schmitt287ac012008-07-02 10:56:40 +020090static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
91{
92 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
93 zfcp_erp_action_dismiss(&unit->erp_action);
94}
95
96static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
97{
98 struct zfcp_unit *unit;
99
100 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
101 zfcp_erp_action_dismiss(&port->erp_action);
102 else
103 list_for_each_entry(unit, &port->unit_list_head, list)
104 zfcp_erp_action_dismiss_unit(unit);
105}
106
107static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
108{
109 struct zfcp_port *port;
110
111 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
112 zfcp_erp_action_dismiss(&adapter->erp_action);
113 else
114 list_for_each_entry(port, &adapter->port_list_head, list)
115 zfcp_erp_action_dismiss_port(port);
116}
117
118static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
119 struct zfcp_port *port,
120 struct zfcp_unit *unit)
121{
122 int need = want;
123 int u_status, p_status, a_status;
124
125 switch (want) {
126 case ZFCP_ERP_ACTION_REOPEN_UNIT:
127 u_status = atomic_read(&unit->status);
128 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
129 return 0;
130 p_status = atomic_read(&port->status);
131 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
132 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
133 return 0;
134 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
135 need = ZFCP_ERP_ACTION_REOPEN_PORT;
136 /* fall through */
137 case ZFCP_ERP_ACTION_REOPEN_PORT:
138 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
139 p_status = atomic_read(&port->status);
140 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
141 return 0;
142 a_status = atomic_read(&adapter->status);
143 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
144 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
145 return 0;
146 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
147 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
148 /* fall through */
149 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
150 a_status = atomic_read(&adapter->status);
151 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
152 return 0;
153 }
154
155 return need;
156}
157
158static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
159 struct zfcp_adapter *adapter,
160 struct zfcp_port *port,
161 struct zfcp_unit *unit)
162{
163 struct zfcp_erp_action *erp_action;
164 u32 status = 0;
165
166 switch (need) {
167 case ZFCP_ERP_ACTION_REOPEN_UNIT:
168 zfcp_unit_get(unit);
169 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
170 erp_action = &unit->erp_action;
171 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
172 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
173 break;
174
175 case ZFCP_ERP_ACTION_REOPEN_PORT:
176 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
177 zfcp_port_get(port);
178 zfcp_erp_action_dismiss_port(port);
179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
180 erp_action = &port->erp_action;
181 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
182 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
183 break;
184
185 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
186 zfcp_adapter_get(adapter);
187 zfcp_erp_action_dismiss_adapter(adapter);
188 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
189 erp_action = &adapter->erp_action;
190 if (!(atomic_read(&adapter->status) &
191 ZFCP_STATUS_COMMON_RUNNING))
192 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
193 break;
194
195 default:
196 return NULL;
197 }
198
199 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
200 erp_action->adapter = adapter;
201 erp_action->port = port;
202 erp_action->unit = unit;
203 erp_action->action = need;
204 erp_action->status = status;
205
206 return erp_action;
207}
208
209static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
210 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100211 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200212{
213 int retval = 1, need;
214 struct zfcp_erp_action *act = NULL;
215
216 if (!(atomic_read(&adapter->status) &
217 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP))
218 return -EIO;
219
220 need = zfcp_erp_required_act(want, adapter, port, unit);
221 if (!need)
222 goto out;
223
224 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
225 act = zfcp_erp_setup_act(need, adapter, port, unit);
226 if (!act)
227 goto out;
228 ++adapter->erp_total_count;
229 list_add_tail(&act->list, &adapter->erp_ready_head);
230 up(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100231 zfcp_rec_dbf_event_thread("eracte1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200232 retval = 0;
233 out:
234 zfcp_rec_dbf_event_trigger(id, ref, want, need, act,
235 adapter, port, unit);
236 return retval;
237}
238
239static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100240 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200241{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100243 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Christof Schmitt287ac012008-07-02 10:56:40 +0200245 /* ensure propagation of failed status to new devices */
246 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100247 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200248 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200250 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
251 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
254/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200255 * zfcp_erp_adapter_reopen - Reopen adapter.
256 * @adapter: Adapter to reopen.
257 * @clear: Status flags to clear.
258 * @id: Id for debug trace event.
259 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200261void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100262 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Christof Schmitt287ac012008-07-02 10:56:40 +0200264 unsigned long flags;
265
266 read_lock_irqsave(&zfcp_data.config_lock, flags);
267 write_lock(&adapter->erp_lock);
268 _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
269 write_unlock(&adapter->erp_lock);
270 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
271}
272
273/**
274 * zfcp_erp_adapter_shutdown - Shutdown adapter.
275 * @adapter: Adapter to shut down.
276 * @clear: Status flags to clear.
277 * @id: Id for debug trace event.
278 * @ref: Reference for debug trace event.
279 */
280void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100281 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200282{
283 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
284 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
285}
286
287/**
288 * zfcp_erp_port_shutdown - Shutdown port
289 * @port: Port to shut down.
290 * @clear: Status flags to clear.
291 * @id: Id for debug trace event.
292 * @ref: Reference for debug trace event.
293 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100294void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
295 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200296{
297 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
298 zfcp_erp_port_reopen(port, clear | flags, id, ref);
299}
300
301/**
302 * zfcp_erp_unit_shutdown - Shutdown unit
303 * @unit: Unit to shut down.
304 * @clear: Status flags to clear.
305 * @id: Id for debug trace event.
306 * @ref: Reference for debug trace event.
307 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100308void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
309 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200310{
311 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
312 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
313}
314
315static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
316{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100317 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200318 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
319 ZFCP_CLEAR);
320}
321
322static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100323 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200324{
325 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100326 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200327
328 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
329 return;
330
331 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
332 port->adapter, port, NULL, id, ref);
333}
334
335/**
336 * zfcp_erp_port_forced_reopen - Forced close of port and open again
337 * @port: Port to force close and to reopen.
338 * @id: Id for debug trace event.
339 * @ref: Reference for debug trace event.
340 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100341void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200342 void *ref)
343{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 unsigned long flags;
345 struct zfcp_adapter *adapter = port->adapter;
346
347 read_lock_irqsave(&zfcp_data.config_lock, flags);
348 write_lock(&adapter->erp_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200349 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
350 write_unlock(&adapter->erp_lock);
351 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
352}
353
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100354static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200355 void *ref)
356{
357 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100358 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200359
360 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
361 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100362 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200363 return -EIO;
364 }
365
366 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
367 port->adapter, port, NULL, id, ref);
368}
369
370/**
371 * zfcp_erp_port_reopen - trigger remote port recovery
372 * @port: port to recover
373 * @clear_mask: flags in port status to be cleared
374 *
375 * Returns 0 if recovery has been triggered, < 0 if not.
376 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100377int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200378{
379 unsigned long flags;
380 int retval;
381 struct zfcp_adapter *adapter = port->adapter;
382
383 read_lock_irqsave(&zfcp_data.config_lock, flags);
384 write_lock(&adapter->erp_lock);
385 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 write_unlock(&adapter->erp_lock);
387 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
388
389 return retval;
390}
391
Christof Schmitt287ac012008-07-02 10:56:40 +0200392static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100394 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200395 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
396 ZFCP_CLEAR);
397}
398
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100399static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200400 void *ref)
401{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 struct zfcp_adapter *adapter = unit->port->adapter;
403
Christof Schmitt287ac012008-07-02 10:56:40 +0200404 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Christof Schmitt287ac012008-07-02 10:56:40 +0200406 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
407 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Christof Schmitt287ac012008-07-02 10:56:40 +0200409 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
410 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
412
413/**
414 * zfcp_erp_unit_reopen - initiate reopen of a unit
415 * @unit: unit to be reopened
416 * @clear_mask: specifies flags in unit status to be cleared
417 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100419void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
420 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200423 struct zfcp_port *port = unit->port;
424 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 read_lock_irqsave(&zfcp_data.config_lock, flags);
427 write_lock(&adapter->erp_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200428 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 write_unlock(&adapter->erp_lock);
430 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431}
432
Christof Schmitt287ac012008-07-02 10:56:40 +0200433static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Christof Schmitt287ac012008-07-02 10:56:40 +0200435 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
Christof Schmitt287ac012008-07-02 10:56:40 +0200438static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100439{
Christof Schmitt287ac012008-07-02 10:56:40 +0200440 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100441}
442
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200443static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Christof Schmitt287ac012008-07-02 10:56:40 +0200445 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100446 zfcp_rec_dbf_event_adapter("eraubl1", NULL, adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200447 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
449
Christof Schmitt287ac012008-07-02 10:56:40 +0200450static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Christof Schmitt287ac012008-07-02 10:56:40 +0200452 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100453 zfcp_rec_dbf_event_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200454 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Christof Schmitt287ac012008-07-02 10:56:40 +0200457static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458{
Christof Schmitt287ac012008-07-02 10:56:40 +0200459 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100460 zfcp_rec_dbf_event_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200461 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462}
463
Christof Schmitt287ac012008-07-02 10:56:40 +0200464static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Christof Schmitt287ac012008-07-02 10:56:40 +0200466 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100467 zfcp_rec_dbf_event_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Christof Schmitt287ac012008-07-02 10:56:40 +0200470static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Christof Schmitt287ac012008-07-02 10:56:40 +0200472 struct zfcp_adapter *adapter = act->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
Christof Schmitt287ac012008-07-02 10:56:40 +0200474 if (!act->fsf_req)
475 return;
476
477 spin_lock(&adapter->req_list_lock);
478 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
479 act->fsf_req->erp_action == act) {
480 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
481 ZFCP_STATUS_ERP_TIMEDOUT)) {
482 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100483 zfcp_rec_dbf_event_action("erscf_1", act);
Martin Petermann7ea633f2008-11-04 16:35:11 +0100484 act->fsf_req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200486 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100487 zfcp_rec_dbf_event_action("erscf_2", act);
Christof Schmitt287ac012008-07-02 10:56:40 +0200488 if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
489 ZFCP_STATUS_FSFREQ_DISMISSED))
490 act->fsf_req = NULL;
491 } else
492 act->fsf_req = NULL;
493 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200496/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200497 * zfcp_erp_notify - Trigger ERP action.
498 * @erp_action: ERP action to continue.
499 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200501void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
503 struct zfcp_adapter *adapter = erp_action->adapter;
504 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200507 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
508 erp_action->status |= set_mask;
509 zfcp_erp_action_ready(erp_action);
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200514/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200515 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
516 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200518void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Christof Schmitt287ac012008-07-02 10:56:40 +0200520 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
521 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Christof Schmitt287ac012008-07-02 10:56:40 +0200524static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Christof Schmitt287ac012008-07-02 10:56:40 +0200526 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
Christof Schmitt287ac012008-07-02 10:56:40 +0200529static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 init_timer(&erp_action->timer);
532 erp_action->timer.function = zfcp_erp_memwait_handler;
533 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200534 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200536}
537
538static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100539 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200540{
541 struct zfcp_port *port;
542
543 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200544 _zfcp_erp_port_reopen(port, clear, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200545}
546
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100547static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
548 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200549{
550 struct zfcp_unit *unit;
551
552 list_for_each_entry(unit, &port->unit_list_head, list)
553 _zfcp_erp_unit_reopen(unit, clear, id, ref);
554}
555
Christof Schmitt85600f72009-07-13 15:06:09 +0200556static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200557{
Christof Schmitt287ac012008-07-02 10:56:40 +0200558 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200559 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200560 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200561 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200562 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200563 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200564 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200565 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200566 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200567 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200568 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200569 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
570 break;
571 }
572}
573
574static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
575{
576 switch (act->action) {
577 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
578 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
579 break;
580 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
581 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
582 break;
583 case ZFCP_ERP_ACTION_REOPEN_PORT:
584 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200585 break;
586 }
587}
588
589static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
590{
591 unsigned long flags;
592
593 read_lock_irqsave(&zfcp_data.config_lock, flags);
594 read_lock(&adapter->erp_lock);
595 if (list_empty(&adapter->erp_ready_head) &&
596 list_empty(&adapter->erp_running_head)) {
597 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
598 &adapter->status);
599 wake_up(&adapter->erp_done_wqh);
600 }
601 read_unlock(&adapter->erp_lock);
602 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
603}
604
605static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
606{
607 if (zfcp_qdio_open(act->adapter))
608 return ZFCP_ERP_FAILED;
609 init_waitqueue_head(&act->adapter->request_wq);
610 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
611 return ZFCP_ERP_SUCCEEDED;
612}
613
614static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
615{
616 struct zfcp_port *port;
617 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
618 adapter->peer_d_id);
619 if (IS_ERR(port)) /* error or port already attached */
620 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100621 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200622}
623
624static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
625{
626 int retries;
627 int sleep = 1;
628 struct zfcp_adapter *adapter = erp_action->adapter;
629
630 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
631
632 for (retries = 7; retries; retries--) {
633 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
634 &adapter->status);
635 write_lock_irq(&adapter->erp_lock);
636 zfcp_erp_action_to_running(erp_action);
637 write_unlock_irq(&adapter->erp_lock);
638 if (zfcp_fsf_exchange_config_data(erp_action)) {
639 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
640 &adapter->status);
641 return ZFCP_ERP_FAILED;
642 }
643
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100644 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200645 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100646 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200647 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
648 break;
649
650 if (!(atomic_read(&adapter->status) &
651 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
652 break;
653
654 ssleep(sleep);
655 sleep *= 2;
656 }
657
658 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
659 &adapter->status);
660
661 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
662 return ZFCP_ERP_FAILED;
663
664 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
665 zfcp_erp_enqueue_ptp_port(adapter);
666
667 return ZFCP_ERP_SUCCEEDED;
668}
669
670static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
671{
672 int ret;
673 struct zfcp_adapter *adapter = act->adapter;
674
Christof Schmitt287ac012008-07-02 10:56:40 +0200675 write_lock_irq(&adapter->erp_lock);
676 zfcp_erp_action_to_running(act);
677 write_unlock_irq(&adapter->erp_lock);
678
679 ret = zfcp_fsf_exchange_port_data(act);
680 if (ret == -EOPNOTSUPP)
681 return ZFCP_ERP_SUCCEEDED;
682 if (ret)
683 return ZFCP_ERP_FAILED;
684
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100685 zfcp_rec_dbf_event_thread_lock("erasox1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200686 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100687 zfcp_rec_dbf_event_thread_lock("erasox2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200688 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
689 return ZFCP_ERP_FAILED;
690
691 return ZFCP_ERP_SUCCEEDED;
692}
693
694static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
695{
696 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
697 return ZFCP_ERP_FAILED;
698
699 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
700 return ZFCP_ERP_FAILED;
701
702 atomic_set(&act->adapter->stat_miss, 16);
703 if (zfcp_status_read_refill(act->adapter))
704 return ZFCP_ERP_FAILED;
705
706 return ZFCP_ERP_SUCCEEDED;
707}
708
Swen Schilligcf13c082009-03-02 13:09:03 +0100709static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200710{
Christof Schmitt287ac012008-07-02 10:56:40 +0200711 struct zfcp_adapter *adapter = act->adapter;
712
Christof Schmitt287ac012008-07-02 10:56:40 +0200713 /* close queues to ensure that buffers are not accessed by adapter */
714 zfcp_qdio_close(adapter);
715 zfcp_fsf_req_dismiss_all(adapter);
716 adapter->fsf_req_seq_no = 0;
Sven Schuetz9d544f22009-04-06 18:31:47 +0200717 zfcp_fc_wka_port_force_offline(&adapter->gs->ds);
Christof Schmitt287ac012008-07-02 10:56:40 +0200718 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100719 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200720 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100721
Christof Schmitt287ac012008-07-02 10:56:40 +0200722 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100723 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
724}
725
726static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
727{
728 struct zfcp_adapter *adapter = act->adapter;
729
730 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
731 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
732 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
733 &adapter->status);
734 return ZFCP_ERP_FAILED;
735 }
736
737 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
738 zfcp_erp_adapter_strategy_close(act);
739 return ZFCP_ERP_FAILED;
740 }
741
742 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
743
744 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200745}
746
747static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
748{
Swen Schilligcf13c082009-03-02 13:09:03 +0100749 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200750
Swen Schilligcf13c082009-03-02 13:09:03 +0100751 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
752 zfcp_erp_adapter_strategy_close(act);
753 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
754 return ZFCP_ERP_EXIT;
755 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200756
Swen Schilligcf13c082009-03-02 13:09:03 +0100757 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200758 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100759 return ZFCP_ERP_FAILED;
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Swen Schilligcf13c082009-03-02 13:09:03 +0100762 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763}
764
Christof Schmitt287ac012008-07-02 10:56:40 +0200765static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Christof Schmitt287ac012008-07-02 10:56:40 +0200767 int retval;
768
769 retval = zfcp_fsf_close_physical_port(act);
770 if (retval == -ENOMEM)
771 return ZFCP_ERP_NOMEM;
772 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
773 if (retval)
774 return ZFCP_ERP_FAILED;
775
776 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Christof Schmitt287ac012008-07-02 10:56:40 +0200779static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100781 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200782}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Christof Schmitt287ac012008-07-02 10:56:40 +0200784static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
785{
786 struct zfcp_port *port = erp_action->port;
787 int status = atomic_read(&port->status);
788
789 switch (erp_action->step) {
790 case ZFCP_ERP_STEP_UNINITIALIZED:
791 zfcp_erp_port_strategy_clearstati(port);
792 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
793 (status & ZFCP_STATUS_COMMON_OPEN))
794 return zfcp_erp_port_forced_strategy_close(erp_action);
795 else
796 return ZFCP_ERP_FAILED;
797
798 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200799 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200800 return ZFCP_ERP_SUCCEEDED;
801 }
802 return ZFCP_ERP_FAILED;
803}
804
805static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
806{
807 int retval;
808
809 retval = zfcp_fsf_close_port(erp_action);
810 if (retval == -ENOMEM)
811 return ZFCP_ERP_NOMEM;
812 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
813 if (retval)
814 return ZFCP_ERP_FAILED;
815 return ZFCP_ERP_CONTINUES;
816}
817
818static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
819{
820 int retval;
821
822 retval = zfcp_fsf_open_port(erp_action);
823 if (retval == -ENOMEM)
824 return ZFCP_ERP_NOMEM;
825 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
826 if (retval)
827 return ZFCP_ERP_FAILED;
828 return ZFCP_ERP_CONTINUES;
829}
830
Christof Schmitt287ac012008-07-02 10:56:40 +0200831static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
832{
833 struct zfcp_adapter *adapter = act->adapter;
834 struct zfcp_port *port = act->port;
835
836 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100837 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200838 return ZFCP_ERP_FAILED;
839 }
840 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200841 return zfcp_erp_port_strategy_open_port(act);
842}
843
Swen Schillig5ab944f2008-10-01 12:42:17 +0200844void 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);
Swen Schillig17a093e2009-07-13 15:06:12 +0200851 if (!retval) {
852 port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
853 goto out;
854 }
855 if (retval == -ENOMEM) {
Christof Schmitt688a1822009-07-13 15:06:05 +0200856 zfcp_erp_notify(&port->erp_action, ZFCP_STATUS_ERP_LOWMEM);
Swen Schillig17a093e2009-07-13 15:06:12 +0200857 goto out;
858 }
859 /* all other error condtions */
860 zfcp_erp_notify(&port->erp_action, 0);
861out:
Swen Schillig947a9ac2009-03-02 13:09:10 +0100862 zfcp_port_put(port);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200863}
864
Christof Schmitt287ac012008-07-02 10:56:40 +0200865static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
866{
867 struct zfcp_adapter *adapter = act->adapter;
868 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200869 int p_status = atomic_read(&port->status);
870
871 switch (act->step) {
872 case ZFCP_ERP_STEP_UNINITIALIZED:
873 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
874 case ZFCP_ERP_STEP_PORT_CLOSING:
875 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
876 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100877 if (!port->d_id) {
Swen Schillig947a9ac2009-03-02 13:09:10 +0100878 zfcp_port_get(port);
879 if (!queue_work(zfcp_data.work_queue,
880 &port->gid_pn_work))
881 zfcp_port_put(port);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200882 return ZFCP_ERP_CONTINUES;
Christof Schmitt287ac012008-07-02 10:56:40 +0200883 }
Christof Schmittdceab652009-05-15 13:18:18 +0200884 /* fall through */
Christof Schmitt287ac012008-07-02 10:56:40 +0200885 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100886 if (!port->d_id)
Christof Schmitt287ac012008-07-02 10:56:40 +0200887 return ZFCP_ERP_FAILED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200888 return zfcp_erp_port_strategy_open_port(act);
889
890 case ZFCP_ERP_STEP_PORT_OPENING:
891 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200892 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmittb98478d2008-12-19 16:56:59 +0100893 if (port->d_id)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200894 return ZFCP_ERP_SUCCEEDED;
895 else {
896 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
897 return ZFCP_ERP_CONTINUES;
898 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200899 }
Swen Schilligea460a82009-05-15 13:18:20 +0200900 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
901 port->d_id = 0;
902 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
903 return ZFCP_ERP_EXIT;
904 }
905 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200906 }
907 return ZFCP_ERP_FAILED;
908}
909
Christof Schmitt287ac012008-07-02 10:56:40 +0200910static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
911{
912 struct zfcp_port *port = erp_action->port;
913
Swen Schillig5ab944f2008-10-01 12:42:17 +0200914 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
915 goto close_init_done;
916
Christof Schmitt287ac012008-07-02 10:56:40 +0200917 switch (erp_action->step) {
918 case ZFCP_ERP_STEP_UNINITIALIZED:
919 zfcp_erp_port_strategy_clearstati(port);
920 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
921 return zfcp_erp_port_strategy_close(erp_action);
922 break;
923
924 case ZFCP_ERP_STEP_PORT_CLOSING:
925 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
926 return ZFCP_ERP_FAILED;
927 break;
928 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200929
930close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200931 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
932 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200933
Swen Schillig5ab944f2008-10-01 12:42:17 +0200934 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Christof Schmitt287ac012008-07-02 10:56:40 +0200937static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200939 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200940 ZFCP_STATUS_UNIT_SHARED |
941 ZFCP_STATUS_UNIT_READONLY,
942 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
Christof Schmitt287ac012008-07-02 10:56:40 +0200945static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
946{
947 int retval = zfcp_fsf_close_unit(erp_action);
948 if (retval == -ENOMEM)
949 return ZFCP_ERP_NOMEM;
950 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
951 if (retval)
952 return ZFCP_ERP_FAILED;
953 return ZFCP_ERP_CONTINUES;
954}
955
956static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
957{
958 int retval = zfcp_fsf_open_unit(erp_action);
959 if (retval == -ENOMEM)
960 return ZFCP_ERP_NOMEM;
961 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
962 if (retval)
963 return ZFCP_ERP_FAILED;
964 return ZFCP_ERP_CONTINUES;
965}
966
967static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
968{
969 struct zfcp_unit *unit = erp_action->unit;
970
971 switch (erp_action->step) {
972 case ZFCP_ERP_STEP_UNINITIALIZED:
973 zfcp_erp_unit_strategy_clearstati(unit);
974 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
975 return zfcp_erp_unit_strategy_close(erp_action);
976 /* already closed, fall through */
977 case ZFCP_ERP_STEP_UNIT_CLOSING:
978 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
979 return ZFCP_ERP_FAILED;
980 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
981 return ZFCP_ERP_EXIT;
982 return zfcp_erp_unit_strategy_open(erp_action);
983
984 case ZFCP_ERP_STEP_UNIT_OPENING:
985 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
986 return ZFCP_ERP_SUCCEEDED;
987 }
988 return ZFCP_ERP_FAILED;
989}
990
991static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
992{
993 switch (result) {
994 case ZFCP_ERP_SUCCEEDED :
995 atomic_set(&unit->erp_counter, 0);
996 zfcp_erp_unit_unblock(unit);
997 break;
998 case ZFCP_ERP_FAILED :
999 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001000 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
1001 dev_err(&unit->port->adapter->ccw_device->dev,
1002 "ERP failed for unit 0x%016Lx on "
1003 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001004 (unsigned long long)unit->fcp_lun,
1005 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001006 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001007 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001008 break;
1009 }
1010
1011 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1012 zfcp_erp_unit_block(unit, 0);
1013 result = ZFCP_ERP_EXIT;
1014 }
1015 return result;
1016}
1017
1018static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1019{
1020 switch (result) {
1021 case ZFCP_ERP_SUCCEEDED :
1022 atomic_set(&port->erp_counter, 0);
1023 zfcp_erp_port_unblock(port);
1024 break;
1025
1026 case ZFCP_ERP_FAILED :
1027 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1028 zfcp_erp_port_block(port, 0);
1029 result = ZFCP_ERP_EXIT;
1030 }
1031 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001032 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1033 dev_err(&port->adapter->ccw_device->dev,
1034 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001035 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001036 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001037 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001038 break;
1039 }
1040
1041 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1042 zfcp_erp_port_block(port, 0);
1043 result = ZFCP_ERP_EXIT;
1044 }
1045 return result;
1046}
1047
1048static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1049 int result)
1050{
1051 switch (result) {
1052 case ZFCP_ERP_SUCCEEDED :
1053 atomic_set(&adapter->erp_counter, 0);
1054 zfcp_erp_adapter_unblock(adapter);
1055 break;
1056
1057 case ZFCP_ERP_FAILED :
1058 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001059 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1060 dev_err(&adapter->ccw_device->dev,
1061 "ERP cannot recover an error "
1062 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001063 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001064 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001065 break;
1066 }
1067
1068 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1069 zfcp_erp_adapter_block(adapter, 0);
1070 result = ZFCP_ERP_EXIT;
1071 }
1072 return result;
1073}
1074
1075static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1076 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
1078 struct zfcp_adapter *adapter = erp_action->adapter;
1079 struct zfcp_port *port = erp_action->port;
1080 struct zfcp_unit *unit = erp_action->unit;
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 switch (erp_action->action) {
1083
1084 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1085 result = zfcp_erp_strategy_check_unit(unit, result);
1086 break;
1087
1088 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1089 case ZFCP_ERP_ACTION_REOPEN_PORT:
1090 result = zfcp_erp_strategy_check_port(port, result);
1091 break;
1092
1093 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1094 result = zfcp_erp_strategy_check_adapter(adapter, result);
1095 break;
1096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 return result;
1098}
1099
Christof Schmitt287ac012008-07-02 10:56:40 +02001100static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Christof Schmitt287ac012008-07-02 10:56:40 +02001102 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Christof Schmitt287ac012008-07-02 10:56:40 +02001104 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1105 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1106 return 1; /* take it online */
1107
1108 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1109 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1110 return 1; /* take it offline */
1111
1112 return 0;
1113}
1114
1115static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1116{
1117 int action = act->action;
1118 struct zfcp_adapter *adapter = act->adapter;
1119 struct zfcp_port *port = act->port;
1120 struct zfcp_unit *unit = act->unit;
1121 u32 erp_status = act->status;
1122
1123 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001125 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1126 _zfcp_erp_adapter_reopen(adapter,
1127 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001128 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001129 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
1131 break;
1132
1133 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1134 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001135 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1136 _zfcp_erp_port_reopen(port,
1137 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001138 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001139 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141 break;
1142
1143 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001144 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1145 _zfcp_erp_unit_reopen(unit,
1146 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001147 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001148 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150 break;
1151 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001152 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Christof Schmitt287ac012008-07-02 10:56:40 +02001155static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Christof Schmitt287ac012008-07-02 10:56:40 +02001157 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Christof Schmitt287ac012008-07-02 10:56:40 +02001159 adapter->erp_total_count--;
1160 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1161 adapter->erp_low_mem_count--;
1162 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164
Christof Schmitt287ac012008-07-02 10:56:40 +02001165 list_del(&erp_action->list);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001166 zfcp_rec_dbf_event_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Christof Schmitt287ac012008-07-02 10:56:40 +02001168 switch (erp_action->action) {
1169 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1170 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1171 &erp_action->unit->status);
1172 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Christof Schmitt287ac012008-07-02 10:56:40 +02001174 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1175 case ZFCP_ERP_ACTION_REOPEN_PORT:
1176 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1177 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001179
1180 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1181 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1182 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 break;
1184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Christof Schmitt287ac012008-07-02 10:56:40 +02001187static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001188{
Christof Schmitt287ac012008-07-02 10:56:40 +02001189 struct zfcp_adapter *adapter = act->adapter;
1190 struct zfcp_port *port = act->port;
1191 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001192
Christof Schmitt287ac012008-07-02 10:56:40 +02001193 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001195 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Swen Schillig92d51932009-04-17 15:08:04 +02001196 zfcp_unit_get(unit);
1197 if (scsi_queue_work(unit->port->adapter->scsi_host,
1198 &unit->scsi_work) <= 0)
1199 zfcp_unit_put(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 zfcp_unit_put(unit);
1202 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1205 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001206 if (result == ZFCP_ERP_SUCCEEDED)
1207 zfcp_scsi_schedule_rport_register(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 zfcp_port_put(port);
1209 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001212 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001213 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001214 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001215 } else
1216 unregister_service_level(&adapter->service_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 zfcp_adapter_put(adapter);
1218 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 }
1220}
1221
Christof Schmitt287ac012008-07-02 10:56:40 +02001222static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1223{
1224 switch (erp_action->action) {
1225 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1226 return zfcp_erp_adapter_strategy(erp_action);
1227 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1228 return zfcp_erp_port_forced_strategy(erp_action);
1229 case ZFCP_ERP_ACTION_REOPEN_PORT:
1230 return zfcp_erp_port_strategy(erp_action);
1231 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1232 return zfcp_erp_unit_strategy(erp_action);
1233 }
1234 return ZFCP_ERP_FAILED;
1235}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Christof Schmitt287ac012008-07-02 10:56:40 +02001237static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1238{
1239 int retval;
1240 struct zfcp_adapter *adapter = erp_action->adapter;
1241 unsigned long flags;
1242
1243 read_lock_irqsave(&zfcp_data.config_lock, flags);
1244 write_lock(&adapter->erp_lock);
1245
1246 zfcp_erp_strategy_check_fsfreq(erp_action);
1247
1248 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1249 zfcp_erp_action_dequeue(erp_action);
1250 retval = ZFCP_ERP_DISMISSED;
1251 goto unlock;
1252 }
1253
1254 zfcp_erp_action_to_running(erp_action);
1255
1256 /* no lock to allow for blocking operations */
1257 write_unlock(&adapter->erp_lock);
1258 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1259 retval = zfcp_erp_strategy_do_action(erp_action);
1260 read_lock_irqsave(&zfcp_data.config_lock, flags);
1261 write_lock(&adapter->erp_lock);
1262
1263 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1264 retval = ZFCP_ERP_CONTINUES;
1265
1266 switch (retval) {
1267 case ZFCP_ERP_NOMEM:
1268 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1269 ++adapter->erp_low_mem_count;
1270 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1271 }
1272 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001273 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001274 else {
1275 zfcp_erp_strategy_memwait(erp_action);
1276 retval = ZFCP_ERP_CONTINUES;
1277 }
1278 goto unlock;
1279
1280 case ZFCP_ERP_CONTINUES:
1281 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1282 --adapter->erp_low_mem_count;
1283 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1284 }
1285 goto unlock;
1286 }
1287
1288 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1289 zfcp_erp_action_dequeue(erp_action);
1290 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1291 if (retval == ZFCP_ERP_EXIT)
1292 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001293 if (retval == ZFCP_ERP_SUCCEEDED)
1294 zfcp_erp_strategy_followup_success(erp_action);
1295 if (retval == ZFCP_ERP_FAILED)
1296 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001297
1298 unlock:
1299 write_unlock(&adapter->erp_lock);
1300 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1301
1302 if (retval != ZFCP_ERP_CONTINUES)
1303 zfcp_erp_action_cleanup(erp_action, retval);
1304
1305 return retval;
1306}
1307
1308static int zfcp_erp_thread(void *data)
1309{
1310 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1311 struct list_head *next;
1312 struct zfcp_erp_action *act;
1313 unsigned long flags;
Heiko Carstens06499fa2008-12-19 16:56:56 +01001314 int ignore;
Christof Schmitt287ac012008-07-02 10:56:40 +02001315
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001316 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
Christof Schmitt287ac012008-07-02 10:56:40 +02001317 /* Block all signals */
1318 siginitsetinv(&current->blocked, 0);
1319 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1320 wake_up(&adapter->erp_thread_wqh);
1321
1322 while (!(atomic_read(&adapter->status) &
1323 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
Swen Schillig94ab4b32009-04-17 15:08:06 +02001324
1325 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
1326 ignore = down_interruptible(&adapter->erp_ready_sem);
1327 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
1328
Christof Schmitt287ac012008-07-02 10:56:40 +02001329 write_lock_irqsave(&adapter->erp_lock, flags);
1330 next = adapter->erp_ready_head.next;
1331 write_unlock_irqrestore(&adapter->erp_lock, flags);
1332
1333 if (next != &adapter->erp_ready_head) {
1334 act = list_entry(next, struct zfcp_erp_action, list);
1335
1336 /* there is more to come after dismission, no notify */
1337 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1338 zfcp_erp_wakeup(adapter);
1339 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001340 }
1341
1342 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1343 wake_up(&adapter->erp_thread_wqh);
1344
1345 return 0;
1346}
1347
1348/**
1349 * zfcp_erp_thread_setup - Start ERP thread for adapter
1350 * @adapter: Adapter to start the ERP thread for
1351 *
1352 * Returns 0 on success or error code from kernel_thread()
1353 */
1354int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1355{
1356 int retval;
1357
1358 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1359 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1360 if (retval < 0) {
1361 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001362 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt287ac012008-07-02 10:56:40 +02001363 return retval;
1364 }
1365 wait_event(adapter->erp_thread_wqh,
1366 atomic_read(&adapter->status) &
1367 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1368 return 0;
1369}
1370
1371/**
1372 * zfcp_erp_thread_kill - Stop ERP thread.
1373 * @adapter: Adapter where the ERP thread should be stopped.
1374 *
1375 * The caller of this routine ensures that the specified adapter has
1376 * been shut down and that this operation has been completed. Thus,
1377 * there are no pending erp_actions which would need to be handled
1378 * here.
1379 */
1380void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1381{
1382 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1383 up(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001384 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +02001385
1386 wait_event(adapter->erp_thread_wqh,
1387 !(atomic_read(&adapter->status) &
1388 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1389
1390 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1391 &adapter->status);
1392}
1393
1394/**
1395 * zfcp_erp_adapter_failed - Set adapter status to failed.
1396 * @adapter: Failed adapter.
1397 * @id: Event id for debug trace.
1398 * @ref: Reference for debug trace.
1399 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001400void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001401{
1402 zfcp_erp_modify_adapter_status(adapter, id, ref,
1403 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001404}
1405
1406/**
1407 * zfcp_erp_port_failed - Set port status to failed.
1408 * @port: Failed port.
1409 * @id: Event id for debug trace.
1410 * @ref: Reference for debug trace.
1411 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001412void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001413{
1414 zfcp_erp_modify_port_status(port, id, ref,
1415 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001416}
1417
1418/**
1419 * zfcp_erp_unit_failed - Set unit status to failed.
1420 * @unit: Failed unit.
1421 * @id: Event id for debug trace.
1422 * @ref: Reference for debug trace.
1423 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001424void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001425{
1426 zfcp_erp_modify_unit_status(unit, id, ref,
1427 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001428}
1429
1430/**
1431 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1432 * @adapter: adapter for which to wait for completion of its error recovery
1433 */
1434void zfcp_erp_wait(struct zfcp_adapter *adapter)
1435{
1436 wait_event(adapter->erp_done_wqh,
1437 !(atomic_read(&adapter->status) &
1438 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1439}
1440
1441/**
1442 * zfcp_erp_modify_adapter_status - change adapter status bits
1443 * @adapter: adapter to change the status
1444 * @id: id for the debug trace
1445 * @ref: reference for the debug trace
1446 * @mask: status bits to change
1447 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1448 *
1449 * Changes in common status bits are propagated to attached ports and units.
1450 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001451void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001452 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 struct zfcp_port *port;
Christof Schmitt287ac012008-07-02 10:56:40 +02001455 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Christof Schmitt287ac012008-07-02 10:56:40 +02001457 if (set_or_clear == ZFCP_SET) {
1458 if (status_change_set(mask, &adapter->status))
1459 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1460 atomic_set_mask(mask, &adapter->status);
1461 } else {
1462 if (status_change_clear(mask, &adapter->status))
1463 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1464 atomic_clear_mask(mask, &adapter->status);
1465 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1466 atomic_set(&adapter->erp_counter, 0);
1467 }
1468
1469 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 list_for_each_entry(port, &adapter->port_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001471 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1472 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
Christof Schmitt287ac012008-07-02 10:56:40 +02001475/**
1476 * zfcp_erp_modify_port_status - change port status bits
1477 * @port: port to change the status bits
1478 * @id: id for the debug trace
1479 * @ref: reference for the debug trace
1480 * @mask: status bits to change
1481 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1482 *
1483 * Changes in common status bits are propagated to attached units.
1484 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001485void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001486 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 struct zfcp_unit *unit;
Christof Schmitt287ac012008-07-02 10:56:40 +02001489 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Christof Schmitt287ac012008-07-02 10:56:40 +02001491 if (set_or_clear == ZFCP_SET) {
1492 if (status_change_set(mask, &port->status))
1493 zfcp_rec_dbf_event_port(id, ref, port);
1494 atomic_set_mask(mask, &port->status);
1495 } else {
1496 if (status_change_clear(mask, &port->status))
1497 zfcp_rec_dbf_event_port(id, ref, port);
1498 atomic_clear_mask(mask, &port->status);
1499 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1500 atomic_set(&port->erp_counter, 0);
1501 }
1502
1503 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 list_for_each_entry(unit, &port->unit_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001505 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1506 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Christof Schmitt287ac012008-07-02 10:56:40 +02001509/**
1510 * zfcp_erp_modify_unit_status - change unit status bits
1511 * @unit: unit to change the status bits
1512 * @id: id for the debug trace
1513 * @ref: reference for the debug trace
1514 * @mask: status bits to change
1515 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1516 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001517void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001518 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
Christof Schmitt287ac012008-07-02 10:56:40 +02001520 if (set_or_clear == ZFCP_SET) {
1521 if (status_change_set(mask, &unit->status))
1522 zfcp_rec_dbf_event_unit(id, ref, unit);
1523 atomic_set_mask(mask, &unit->status);
1524 } else {
1525 if (status_change_clear(mask, &unit->status))
1526 zfcp_rec_dbf_event_unit(id, ref, unit);
1527 atomic_clear_mask(mask, &unit->status);
1528 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1529 atomic_set(&unit->erp_counter, 0);
1530 }
1531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Christof Schmitt287ac012008-07-02 10:56:40 +02001534/**
1535 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1536 * @port: The "boxed" port.
1537 * @id: The debug trace id.
1538 * @id: Reference for the debug trace.
1539 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001540void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001541{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001542 unsigned long flags;
1543
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001544 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001545 zfcp_erp_modify_port_status(port, id, ref,
1546 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001547 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001548 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001549}
1550
Christof Schmitt287ac012008-07-02 10:56:40 +02001551/**
1552 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1553 * @port: The "boxed" unit.
1554 * @id: The debug trace id.
1555 * @id: Reference for the debug trace.
1556 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001557void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001558{
Martin Peschke698ec0162008-03-27 14:22:02 +01001559 zfcp_erp_modify_unit_status(unit, id, ref,
1560 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001561 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001562}
1563
Christof Schmitt287ac012008-07-02 10:56:40 +02001564/**
1565 * zfcp_erp_port_access_denied - Adapter denied access to port.
1566 * @port: port where access has been denied
1567 * @id: id for debug trace
1568 * @ref: reference for debug trace
1569 *
1570 * Since the adapter has denied access, stop using the port and the
1571 * attached units.
1572 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001573void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 unsigned long flags;
1576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001578 zfcp_erp_modify_port_status(port, id, ref,
1579 ZFCP_STATUS_COMMON_ERP_FAILED |
1580 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1582}
1583
Christof Schmitt287ac012008-07-02 10:56:40 +02001584/**
1585 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1586 * @unit: unit where access has been denied
1587 * @id: id for debug trace
1588 * @ref: reference for debug trace
1589 *
1590 * Since the adapter has denied access, stop using the unit.
1591 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001592void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
Martin Peschke698ec0162008-03-27 14:22:02 +01001594 zfcp_erp_modify_unit_status(unit, id, ref,
1595 ZFCP_STATUS_COMMON_ERP_FAILED |
1596 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597}
1598
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001599static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001600 void *ref)
1601{
1602 int status = atomic_read(&unit->status);
1603 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1604 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1605 return;
1606
1607 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1608}
1609
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001610static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001611 void *ref)
1612{
1613 struct zfcp_unit *unit;
1614 int status = atomic_read(&port->status);
1615
1616 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1617 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001618 list_for_each_entry(unit, &port->unit_list_head, list)
1619 zfcp_erp_unit_access_changed(unit, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001620 return;
1621 }
1622
1623 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1624}
1625
1626/**
1627 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1628 * @adapter: Adapter where the Access Control Table (ACT) changed
1629 * @id: Id for debug trace
1630 * @ref: Reference for debug trace
1631 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001632void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001633 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
1635 struct zfcp_port *port;
1636 unsigned long flags;
1637
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001638 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1639 return;
1640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 read_lock_irqsave(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001643 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1645}