blob: dee1cc3ce21b2614467ad577941b54027e652958 [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
556static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act)
557{
558 struct zfcp_adapter *adapter = act->adapter;
559 struct zfcp_port *port = act->port;
560 struct zfcp_unit *unit = act->unit;
561 u32 status = act->status;
562
563 /* initiate follow-up actions depending on success of finished action */
564 switch (act->action) {
565
566 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
567 if (status == ZFCP_ERP_SUCCEEDED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100568 _zfcp_erp_port_reopen_all(adapter, 0, "ersfa_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200569 else
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100570 _zfcp_erp_adapter_reopen(adapter, 0, "ersfa_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200571 break;
572
573 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
574 if (status == ZFCP_ERP_SUCCEEDED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100575 _zfcp_erp_port_reopen(port, 0, "ersfa_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200576 else
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100577 _zfcp_erp_adapter_reopen(adapter, 0, "ersfa_4", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200578 break;
579
580 case ZFCP_ERP_ACTION_REOPEN_PORT:
581 if (status == ZFCP_ERP_SUCCEEDED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100582 _zfcp_erp_unit_reopen_all(port, 0, "ersfa_5", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200583 else
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100584 _zfcp_erp_port_forced_reopen(port, 0, "ersfa_6", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200585 break;
586
587 case ZFCP_ERP_ACTION_REOPEN_UNIT:
588 if (status != ZFCP_ERP_SUCCEEDED)
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100589 _zfcp_erp_port_reopen(unit->port, 0, "ersfa_7", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200590 break;
591 }
592}
593
594static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
595{
596 unsigned long flags;
597
598 read_lock_irqsave(&zfcp_data.config_lock, flags);
599 read_lock(&adapter->erp_lock);
600 if (list_empty(&adapter->erp_ready_head) &&
601 list_empty(&adapter->erp_running_head)) {
602 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
603 &adapter->status);
604 wake_up(&adapter->erp_done_wqh);
605 }
606 read_unlock(&adapter->erp_lock);
607 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
608}
609
610static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
611{
612 if (zfcp_qdio_open(act->adapter))
613 return ZFCP_ERP_FAILED;
614 init_waitqueue_head(&act->adapter->request_wq);
615 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
616 return ZFCP_ERP_SUCCEEDED;
617}
618
619static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
620{
621 struct zfcp_port *port;
622 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
623 adapter->peer_d_id);
624 if (IS_ERR(port)) /* error or port already attached */
625 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100626 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200627}
628
629static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
630{
631 int retries;
632 int sleep = 1;
633 struct zfcp_adapter *adapter = erp_action->adapter;
634
635 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
636
637 for (retries = 7; retries; retries--) {
638 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
639 &adapter->status);
640 write_lock_irq(&adapter->erp_lock);
641 zfcp_erp_action_to_running(erp_action);
642 write_unlock_irq(&adapter->erp_lock);
643 if (zfcp_fsf_exchange_config_data(erp_action)) {
644 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
645 &adapter->status);
646 return ZFCP_ERP_FAILED;
647 }
648
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100649 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200650 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100651 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200652 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
653 break;
654
655 if (!(atomic_read(&adapter->status) &
656 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
657 break;
658
659 ssleep(sleep);
660 sleep *= 2;
661 }
662
663 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
664 &adapter->status);
665
666 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
667 return ZFCP_ERP_FAILED;
668
669 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
670 zfcp_erp_enqueue_ptp_port(adapter);
671
672 return ZFCP_ERP_SUCCEEDED;
673}
674
675static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
676{
677 int ret;
678 struct zfcp_adapter *adapter = act->adapter;
679
Christof Schmitt287ac012008-07-02 10:56:40 +0200680 write_lock_irq(&adapter->erp_lock);
681 zfcp_erp_action_to_running(act);
682 write_unlock_irq(&adapter->erp_lock);
683
684 ret = zfcp_fsf_exchange_port_data(act);
685 if (ret == -EOPNOTSUPP)
686 return ZFCP_ERP_SUCCEEDED;
687 if (ret)
688 return ZFCP_ERP_FAILED;
689
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100690 zfcp_rec_dbf_event_thread_lock("erasox1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200691 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100692 zfcp_rec_dbf_event_thread_lock("erasox2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200693 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
694 return ZFCP_ERP_FAILED;
695
696 return ZFCP_ERP_SUCCEEDED;
697}
698
699static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
700{
701 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
702 return ZFCP_ERP_FAILED;
703
704 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
705 return ZFCP_ERP_FAILED;
706
707 atomic_set(&act->adapter->stat_miss, 16);
708 if (zfcp_status_read_refill(act->adapter))
709 return ZFCP_ERP_FAILED;
710
711 return ZFCP_ERP_SUCCEEDED;
712}
713
Swen Schilligcf13c082009-03-02 13:09:03 +0100714static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200715{
Christof Schmitt287ac012008-07-02 10:56:40 +0200716 struct zfcp_adapter *adapter = act->adapter;
717
Christof Schmitt287ac012008-07-02 10:56:40 +0200718 /* close queues to ensure that buffers are not accessed by adapter */
719 zfcp_qdio_close(adapter);
720 zfcp_fsf_req_dismiss_all(adapter);
721 adapter->fsf_req_seq_no = 0;
722 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100723 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200724 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100725
Christof Schmitt287ac012008-07-02 10:56:40 +0200726 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100727 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
728}
729
730static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
731{
732 struct zfcp_adapter *adapter = act->adapter;
733
734 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
735 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
736 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
737 &adapter->status);
738 return ZFCP_ERP_FAILED;
739 }
740
741 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
742 zfcp_erp_adapter_strategy_close(act);
743 return ZFCP_ERP_FAILED;
744 }
745
746 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
747
748 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200749}
750
751static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
752{
Swen Schilligcf13c082009-03-02 13:09:03 +0100753 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200754
Swen Schilligcf13c082009-03-02 13:09:03 +0100755 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
756 zfcp_erp_adapter_strategy_close(act);
757 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
758 return ZFCP_ERP_EXIT;
759 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200760
Swen Schilligcf13c082009-03-02 13:09:03 +0100761 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200762 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100763 return ZFCP_ERP_FAILED;
764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Swen Schilligcf13c082009-03-02 13:09:03 +0100766 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
Christof Schmitt287ac012008-07-02 10:56:40 +0200769static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Christof Schmitt287ac012008-07-02 10:56:40 +0200771 int retval;
772
773 retval = zfcp_fsf_close_physical_port(act);
774 if (retval == -ENOMEM)
775 return ZFCP_ERP_NOMEM;
776 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
777 if (retval)
778 return ZFCP_ERP_FAILED;
779
780 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
Christof Schmitt287ac012008-07-02 10:56:40 +0200783static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100785 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200786}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Christof Schmitt287ac012008-07-02 10:56:40 +0200788static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
789{
790 struct zfcp_port *port = erp_action->port;
791 int status = atomic_read(&port->status);
792
793 switch (erp_action->step) {
794 case ZFCP_ERP_STEP_UNINITIALIZED:
795 zfcp_erp_port_strategy_clearstati(port);
796 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
797 (status & ZFCP_STATUS_COMMON_OPEN))
798 return zfcp_erp_port_forced_strategy_close(erp_action);
799 else
800 return ZFCP_ERP_FAILED;
801
802 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
803 if (status & ZFCP_STATUS_PORT_PHYS_OPEN)
804 return ZFCP_ERP_SUCCEEDED;
805 }
806 return ZFCP_ERP_FAILED;
807}
808
809static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
810{
811 int retval;
812
813 retval = zfcp_fsf_close_port(erp_action);
814 if (retval == -ENOMEM)
815 return ZFCP_ERP_NOMEM;
816 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
817 if (retval)
818 return ZFCP_ERP_FAILED;
819 return ZFCP_ERP_CONTINUES;
820}
821
822static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
823{
824 int retval;
825
826 retval = zfcp_fsf_open_port(erp_action);
827 if (retval == -ENOMEM)
828 return ZFCP_ERP_NOMEM;
829 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
830 if (retval)
831 return ZFCP_ERP_FAILED;
832 return ZFCP_ERP_CONTINUES;
833}
834
Christof Schmitt287ac012008-07-02 10:56:40 +0200835static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
836{
837 struct zfcp_adapter *adapter = act->adapter;
838 struct zfcp_port *port = act->port;
839
840 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100841 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200842 return ZFCP_ERP_FAILED;
843 }
844 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200845 return zfcp_erp_port_strategy_open_port(act);
846}
847
Swen Schillig5ab944f2008-10-01 12:42:17 +0200848void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
849{
850 int retval;
851 struct zfcp_port *port = container_of(work, struct zfcp_port,
852 gid_pn_work);
853
854 retval = zfcp_fc_ns_gid_pn(&port->erp_action);
855 if (retval == -ENOMEM)
856 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM);
857 port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
858 if (retval)
859 zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED);
860
861}
862
Christof Schmitt287ac012008-07-02 10:56:40 +0200863static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
864{
865 struct zfcp_adapter *adapter = act->adapter;
866 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200867 int p_status = atomic_read(&port->status);
868
869 switch (act->step) {
870 case ZFCP_ERP_STEP_UNINITIALIZED:
871 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
872 case ZFCP_ERP_STEP_PORT_CLOSING:
873 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
874 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100875 if (!port->d_id) {
Swen Schilligb7f15f32008-10-01 12:42:22 +0200876 queue_work(zfcp_data.work_queue, &port->gid_pn_work);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200877 return ZFCP_ERP_CONTINUES;
Christof Schmitt287ac012008-07-02 10:56:40 +0200878 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200879 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100880 if (!port->d_id)
Christof Schmitt287ac012008-07-02 10:56:40 +0200881 return ZFCP_ERP_FAILED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200882 return zfcp_erp_port_strategy_open_port(act);
883
884 case ZFCP_ERP_STEP_PORT_OPENING:
885 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200886 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmittb98478d2008-12-19 16:56:59 +0100887 if (port->d_id)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200888 return ZFCP_ERP_SUCCEEDED;
889 else {
890 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
891 return ZFCP_ERP_CONTINUES;
892 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200893 /* fall through otherwise */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200894 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200895 }
896 return ZFCP_ERP_FAILED;
897}
898
Christof Schmitt287ac012008-07-02 10:56:40 +0200899static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
900{
901 struct zfcp_port *port = erp_action->port;
902
Swen Schillig5ab944f2008-10-01 12:42:17 +0200903 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
904 goto close_init_done;
905
Christof Schmitt287ac012008-07-02 10:56:40 +0200906 switch (erp_action->step) {
907 case ZFCP_ERP_STEP_UNINITIALIZED:
908 zfcp_erp_port_strategy_clearstati(port);
909 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
910 return zfcp_erp_port_strategy_close(erp_action);
911 break;
912
913 case ZFCP_ERP_STEP_PORT_CLOSING:
914 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
915 return ZFCP_ERP_FAILED;
916 break;
917 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200918
919close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200920 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
921 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200922
Swen Schillig5ab944f2008-10-01 12:42:17 +0200923 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
Christof Schmitt287ac012008-07-02 10:56:40 +0200926static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200928 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200929 ZFCP_STATUS_UNIT_SHARED |
930 ZFCP_STATUS_UNIT_READONLY,
931 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
Christof Schmitt287ac012008-07-02 10:56:40 +0200934static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
935{
936 int retval = zfcp_fsf_close_unit(erp_action);
937 if (retval == -ENOMEM)
938 return ZFCP_ERP_NOMEM;
939 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
940 if (retval)
941 return ZFCP_ERP_FAILED;
942 return ZFCP_ERP_CONTINUES;
943}
944
945static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
946{
947 int retval = zfcp_fsf_open_unit(erp_action);
948 if (retval == -ENOMEM)
949 return ZFCP_ERP_NOMEM;
950 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
951 if (retval)
952 return ZFCP_ERP_FAILED;
953 return ZFCP_ERP_CONTINUES;
954}
955
956static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
957{
958 struct zfcp_unit *unit = erp_action->unit;
959
960 switch (erp_action->step) {
961 case ZFCP_ERP_STEP_UNINITIALIZED:
962 zfcp_erp_unit_strategy_clearstati(unit);
963 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
964 return zfcp_erp_unit_strategy_close(erp_action);
965 /* already closed, fall through */
966 case ZFCP_ERP_STEP_UNIT_CLOSING:
967 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
968 return ZFCP_ERP_FAILED;
969 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
970 return ZFCP_ERP_EXIT;
971 return zfcp_erp_unit_strategy_open(erp_action);
972
973 case ZFCP_ERP_STEP_UNIT_OPENING:
974 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
975 return ZFCP_ERP_SUCCEEDED;
976 }
977 return ZFCP_ERP_FAILED;
978}
979
980static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
981{
982 switch (result) {
983 case ZFCP_ERP_SUCCEEDED :
984 atomic_set(&unit->erp_counter, 0);
985 zfcp_erp_unit_unblock(unit);
986 break;
987 case ZFCP_ERP_FAILED :
988 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200989 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
990 dev_err(&unit->port->adapter->ccw_device->dev,
991 "ERP failed for unit 0x%016Lx on "
992 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +0200993 (unsigned long long)unit->fcp_lun,
994 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100995 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200996 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200997 break;
998 }
999
1000 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1001 zfcp_erp_unit_block(unit, 0);
1002 result = ZFCP_ERP_EXIT;
1003 }
1004 return result;
1005}
1006
1007static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1008{
1009 switch (result) {
1010 case ZFCP_ERP_SUCCEEDED :
1011 atomic_set(&port->erp_counter, 0);
1012 zfcp_erp_port_unblock(port);
1013 break;
1014
1015 case ZFCP_ERP_FAILED :
1016 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1017 zfcp_erp_port_block(port, 0);
1018 result = ZFCP_ERP_EXIT;
1019 }
1020 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001021 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1022 dev_err(&port->adapter->ccw_device->dev,
1023 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001024 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001025 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001026 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001027 break;
1028 }
1029
1030 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1031 zfcp_erp_port_block(port, 0);
1032 result = ZFCP_ERP_EXIT;
1033 }
1034 return result;
1035}
1036
1037static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1038 int result)
1039{
1040 switch (result) {
1041 case ZFCP_ERP_SUCCEEDED :
1042 atomic_set(&adapter->erp_counter, 0);
1043 zfcp_erp_adapter_unblock(adapter);
1044 break;
1045
1046 case ZFCP_ERP_FAILED :
1047 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001048 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1049 dev_err(&adapter->ccw_device->dev,
1050 "ERP cannot recover an error "
1051 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001052 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001053 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001054 break;
1055 }
1056
1057 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1058 zfcp_erp_adapter_block(adapter, 0);
1059 result = ZFCP_ERP_EXIT;
1060 }
1061 return result;
1062}
1063
1064static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1065 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 struct zfcp_adapter *adapter = erp_action->adapter;
1068 struct zfcp_port *port = erp_action->port;
1069 struct zfcp_unit *unit = erp_action->unit;
1070
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 switch (erp_action->action) {
1072
1073 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1074 result = zfcp_erp_strategy_check_unit(unit, result);
1075 break;
1076
1077 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1078 case ZFCP_ERP_ACTION_REOPEN_PORT:
1079 result = zfcp_erp_strategy_check_port(port, result);
1080 break;
1081
1082 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1083 result = zfcp_erp_strategy_check_adapter(adapter, result);
1084 break;
1085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 return result;
1087}
1088
Christof Schmitt287ac012008-07-02 10:56:40 +02001089static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Christof Schmitt287ac012008-07-02 10:56:40 +02001091 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Christof Schmitt287ac012008-07-02 10:56:40 +02001093 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1094 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1095 return 1; /* take it online */
1096
1097 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1098 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1099 return 1; /* take it offline */
1100
1101 return 0;
1102}
1103
1104static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1105{
1106 int action = act->action;
1107 struct zfcp_adapter *adapter = act->adapter;
1108 struct zfcp_port *port = act->port;
1109 struct zfcp_unit *unit = act->unit;
1110 u32 erp_status = act->status;
1111
1112 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001114 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1115 _zfcp_erp_adapter_reopen(adapter,
1116 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001117 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001118 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 break;
1121
1122 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1123 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001124 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1125 _zfcp_erp_port_reopen(port,
1126 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001127 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001128 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130 break;
1131
1132 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001133 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1134 _zfcp_erp_unit_reopen(unit,
1135 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001136 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001137 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 }
1139 break;
1140 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001141 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
1143
Christof Schmitt287ac012008-07-02 10:56:40 +02001144static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145{
Christof Schmitt287ac012008-07-02 10:56:40 +02001146 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Christof Schmitt287ac012008-07-02 10:56:40 +02001148 adapter->erp_total_count--;
1149 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1150 adapter->erp_low_mem_count--;
1151 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 }
1153
Christof Schmitt287ac012008-07-02 10:56:40 +02001154 list_del(&erp_action->list);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001155 zfcp_rec_dbf_event_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Christof Schmitt287ac012008-07-02 10:56:40 +02001157 switch (erp_action->action) {
1158 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1159 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1160 &erp_action->unit->status);
1161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Christof Schmitt287ac012008-07-02 10:56:40 +02001163 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1164 case ZFCP_ERP_ACTION_REOPEN_PORT:
1165 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1166 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001168
1169 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1170 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1171 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 break;
1173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Christof Schmitt5f852be2007-05-08 11:16:52 +02001176struct zfcp_erp_add_work {
1177 struct zfcp_unit *unit;
1178 struct work_struct work;
1179};
1180
Christof Schmitt5f852be2007-05-08 11:16:52 +02001181static void zfcp_erp_scsi_scan(struct work_struct *work)
1182{
1183 struct zfcp_erp_add_work *p =
1184 container_of(work, struct zfcp_erp_add_work, work);
1185 struct zfcp_unit *unit = p->unit;
1186 struct fc_rport *rport = unit->port->rport;
Swen Schillig26871c92008-11-26 18:07:38 +01001187
1188 if (rport && rport->port_state == FC_PORTSTATE_ONLINE)
1189 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
Christof Schmitt04062892008-10-01 12:42:20 +02001190 scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001191 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001192 zfcp_unit_put(unit);
Swen Schillig091694a2008-10-01 12:42:25 +02001193 wake_up(&unit->port->adapter->erp_done_wqh);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001194 kfree(p);
1195}
1196
Christof Schmitt287ac012008-07-02 10:56:40 +02001197static void zfcp_erp_schedule_work(struct zfcp_unit *unit)
Christof Schmitt5f852be2007-05-08 11:16:52 +02001198{
1199 struct zfcp_erp_add_work *p;
1200
Swen Schillig0d661322007-07-18 10:55:08 +02001201 p = kzalloc(sizeof(*p), GFP_KERNEL);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001202 if (!p) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001203 dev_err(&unit->port->adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001204 "Registering unit 0x%016Lx on port 0x%016Lx failed\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001205 (unsigned long long)unit->fcp_lun,
1206 (unsigned long long)unit->port->wwpn);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001207 return;
1208 }
1209
1210 zfcp_unit_get(unit);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001211 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1212 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1213 p->unit = unit;
Swen Schilligb7f15f32008-10-01 12:42:22 +02001214 queue_work(zfcp_data.work_queue, &p->work);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001215}
1216
Christof Schmitt287ac012008-07-02 10:56:40 +02001217static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001218{
Christof Schmitt287ac012008-07-02 10:56:40 +02001219 struct zfcp_adapter *adapter = act->adapter;
1220 struct zfcp_port *port = act->port;
1221 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001222
Christof Schmitt287ac012008-07-02 10:56:40 +02001223 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001225 flush_work(&port->rport_work);
1226 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001227 if (!(atomic_read(&unit->status) &
1228 ZFCP_STATUS_UNIT_SCSI_WORK_PENDING))
Christof Schmitt5f852be2007-05-08 11:16:52 +02001229 zfcp_erp_schedule_work(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 zfcp_unit_put(unit);
1232 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1235 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001236 if (result == ZFCP_ERP_SUCCEEDED)
1237 zfcp_scsi_schedule_rport_register(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 zfcp_port_put(port);
1239 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001242 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001243 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001244 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001245 } else
1246 unregister_service_level(&adapter->service_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 zfcp_adapter_put(adapter);
1248 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
1250}
1251
Christof Schmitt287ac012008-07-02 10:56:40 +02001252static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1253{
1254 switch (erp_action->action) {
1255 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1256 return zfcp_erp_adapter_strategy(erp_action);
1257 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1258 return zfcp_erp_port_forced_strategy(erp_action);
1259 case ZFCP_ERP_ACTION_REOPEN_PORT:
1260 return zfcp_erp_port_strategy(erp_action);
1261 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1262 return zfcp_erp_unit_strategy(erp_action);
1263 }
1264 return ZFCP_ERP_FAILED;
1265}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Christof Schmitt287ac012008-07-02 10:56:40 +02001267static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1268{
1269 int retval;
1270 struct zfcp_adapter *adapter = erp_action->adapter;
1271 unsigned long flags;
1272
1273 read_lock_irqsave(&zfcp_data.config_lock, flags);
1274 write_lock(&adapter->erp_lock);
1275
1276 zfcp_erp_strategy_check_fsfreq(erp_action);
1277
1278 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1279 zfcp_erp_action_dequeue(erp_action);
1280 retval = ZFCP_ERP_DISMISSED;
1281 goto unlock;
1282 }
1283
1284 zfcp_erp_action_to_running(erp_action);
1285
1286 /* no lock to allow for blocking operations */
1287 write_unlock(&adapter->erp_lock);
1288 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1289 retval = zfcp_erp_strategy_do_action(erp_action);
1290 read_lock_irqsave(&zfcp_data.config_lock, flags);
1291 write_lock(&adapter->erp_lock);
1292
1293 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1294 retval = ZFCP_ERP_CONTINUES;
1295
1296 switch (retval) {
1297 case ZFCP_ERP_NOMEM:
1298 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1299 ++adapter->erp_low_mem_count;
1300 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1301 }
1302 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001303 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001304 else {
1305 zfcp_erp_strategy_memwait(erp_action);
1306 retval = ZFCP_ERP_CONTINUES;
1307 }
1308 goto unlock;
1309
1310 case ZFCP_ERP_CONTINUES:
1311 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1312 --adapter->erp_low_mem_count;
1313 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1314 }
1315 goto unlock;
1316 }
1317
1318 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1319 zfcp_erp_action_dequeue(erp_action);
1320 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1321 if (retval == ZFCP_ERP_EXIT)
1322 goto unlock;
1323 zfcp_erp_strategy_followup_actions(erp_action);
1324
1325 unlock:
1326 write_unlock(&adapter->erp_lock);
1327 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1328
1329 if (retval != ZFCP_ERP_CONTINUES)
1330 zfcp_erp_action_cleanup(erp_action, retval);
1331
1332 return retval;
1333}
1334
1335static int zfcp_erp_thread(void *data)
1336{
1337 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1338 struct list_head *next;
1339 struct zfcp_erp_action *act;
1340 unsigned long flags;
Heiko Carstens06499fa2008-12-19 16:56:56 +01001341 int ignore;
Christof Schmitt287ac012008-07-02 10:56:40 +02001342
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001343 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
Christof Schmitt287ac012008-07-02 10:56:40 +02001344 /* Block all signals */
1345 siginitsetinv(&current->blocked, 0);
1346 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1347 wake_up(&adapter->erp_thread_wqh);
1348
1349 while (!(atomic_read(&adapter->status) &
1350 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
1351 write_lock_irqsave(&adapter->erp_lock, flags);
1352 next = adapter->erp_ready_head.next;
1353 write_unlock_irqrestore(&adapter->erp_lock, flags);
1354
1355 if (next != &adapter->erp_ready_head) {
1356 act = list_entry(next, struct zfcp_erp_action, list);
1357
1358 /* there is more to come after dismission, no notify */
1359 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1360 zfcp_erp_wakeup(adapter);
1361 }
1362
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001363 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
Heiko Carstens06499fa2008-12-19 16:56:56 +01001364 ignore = down_interruptible(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001365 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +02001366 }
1367
1368 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1369 wake_up(&adapter->erp_thread_wqh);
1370
1371 return 0;
1372}
1373
1374/**
1375 * zfcp_erp_thread_setup - Start ERP thread for adapter
1376 * @adapter: Adapter to start the ERP thread for
1377 *
1378 * Returns 0 on success or error code from kernel_thread()
1379 */
1380int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1381{
1382 int retval;
1383
1384 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1385 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1386 if (retval < 0) {
1387 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001388 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt287ac012008-07-02 10:56:40 +02001389 return retval;
1390 }
1391 wait_event(adapter->erp_thread_wqh,
1392 atomic_read(&adapter->status) &
1393 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1394 return 0;
1395}
1396
1397/**
1398 * zfcp_erp_thread_kill - Stop ERP thread.
1399 * @adapter: Adapter where the ERP thread should be stopped.
1400 *
1401 * The caller of this routine ensures that the specified adapter has
1402 * been shut down and that this operation has been completed. Thus,
1403 * there are no pending erp_actions which would need to be handled
1404 * here.
1405 */
1406void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1407{
1408 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1409 up(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001410 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +02001411
1412 wait_event(adapter->erp_thread_wqh,
1413 !(atomic_read(&adapter->status) &
1414 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1415
1416 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1417 &adapter->status);
1418}
1419
1420/**
1421 * zfcp_erp_adapter_failed - Set adapter status to failed.
1422 * @adapter: Failed adapter.
1423 * @id: Event id for debug trace.
1424 * @ref: Reference for debug trace.
1425 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001426void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001427{
1428 zfcp_erp_modify_adapter_status(adapter, id, ref,
1429 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001430}
1431
1432/**
1433 * zfcp_erp_port_failed - Set port status to failed.
1434 * @port: Failed port.
1435 * @id: Event id for debug trace.
1436 * @ref: Reference for debug trace.
1437 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001438void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001439{
1440 zfcp_erp_modify_port_status(port, id, ref,
1441 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001442}
1443
1444/**
1445 * zfcp_erp_unit_failed - Set unit status to failed.
1446 * @unit: Failed unit.
1447 * @id: Event id for debug trace.
1448 * @ref: Reference for debug trace.
1449 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001450void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001451{
1452 zfcp_erp_modify_unit_status(unit, id, ref,
1453 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001454}
1455
1456/**
1457 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1458 * @adapter: adapter for which to wait for completion of its error recovery
1459 */
1460void zfcp_erp_wait(struct zfcp_adapter *adapter)
1461{
1462 wait_event(adapter->erp_done_wqh,
1463 !(atomic_read(&adapter->status) &
1464 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1465}
1466
1467/**
1468 * zfcp_erp_modify_adapter_status - change adapter status bits
1469 * @adapter: adapter to change the status
1470 * @id: id for the debug trace
1471 * @ref: reference for the debug trace
1472 * @mask: status bits to change
1473 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1474 *
1475 * Changes in common status bits are propagated to attached ports and units.
1476 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001477void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001478 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 struct zfcp_port *port;
Christof Schmitt287ac012008-07-02 10:56:40 +02001481 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Christof Schmitt287ac012008-07-02 10:56:40 +02001483 if (set_or_clear == ZFCP_SET) {
1484 if (status_change_set(mask, &adapter->status))
1485 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1486 atomic_set_mask(mask, &adapter->status);
1487 } else {
1488 if (status_change_clear(mask, &adapter->status))
1489 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1490 atomic_clear_mask(mask, &adapter->status);
1491 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1492 atomic_set(&adapter->erp_counter, 0);
1493 }
1494
1495 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 list_for_each_entry(port, &adapter->port_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001497 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1498 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
Christof Schmitt287ac012008-07-02 10:56:40 +02001501/**
1502 * zfcp_erp_modify_port_status - change port status bits
1503 * @port: port to change the status bits
1504 * @id: id for the debug trace
1505 * @ref: reference for the debug trace
1506 * @mask: status bits to change
1507 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1508 *
1509 * Changes in common status bits are propagated to attached units.
1510 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001511void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001512 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 struct zfcp_unit *unit;
Christof Schmitt287ac012008-07-02 10:56:40 +02001515 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
Christof Schmitt287ac012008-07-02 10:56:40 +02001517 if (set_or_clear == ZFCP_SET) {
1518 if (status_change_set(mask, &port->status))
1519 zfcp_rec_dbf_event_port(id, ref, port);
1520 atomic_set_mask(mask, &port->status);
1521 } else {
1522 if (status_change_clear(mask, &port->status))
1523 zfcp_rec_dbf_event_port(id, ref, port);
1524 atomic_clear_mask(mask, &port->status);
1525 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1526 atomic_set(&port->erp_counter, 0);
1527 }
1528
1529 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 list_for_each_entry(unit, &port->unit_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001531 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1532 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Christof Schmitt287ac012008-07-02 10:56:40 +02001535/**
1536 * zfcp_erp_modify_unit_status - change unit status bits
1537 * @unit: unit to change the status bits
1538 * @id: id for the debug trace
1539 * @ref: reference for the debug trace
1540 * @mask: status bits to change
1541 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1542 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001543void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001544 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Christof Schmitt287ac012008-07-02 10:56:40 +02001546 if (set_or_clear == ZFCP_SET) {
1547 if (status_change_set(mask, &unit->status))
1548 zfcp_rec_dbf_event_unit(id, ref, unit);
1549 atomic_set_mask(mask, &unit->status);
1550 } else {
1551 if (status_change_clear(mask, &unit->status))
1552 zfcp_rec_dbf_event_unit(id, ref, unit);
1553 atomic_clear_mask(mask, &unit->status);
1554 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1555 atomic_set(&unit->erp_counter, 0);
1556 }
1557 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Christof Schmitt287ac012008-07-02 10:56:40 +02001560/**
1561 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1562 * @port: The "boxed" port.
1563 * @id: The debug trace id.
1564 * @id: Reference for the debug trace.
1565 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001566void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001567{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001568 unsigned long flags;
1569
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001570 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001571 zfcp_erp_modify_port_status(port, id, ref,
1572 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001573 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001574 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001575}
1576
Christof Schmitt287ac012008-07-02 10:56:40 +02001577/**
1578 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1579 * @port: The "boxed" unit.
1580 * @id: The debug trace id.
1581 * @id: Reference for the debug trace.
1582 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001583void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001584{
Martin Peschke698ec0162008-03-27 14:22:02 +01001585 zfcp_erp_modify_unit_status(unit, id, ref,
1586 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001587 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001588}
1589
Christof Schmitt287ac012008-07-02 10:56:40 +02001590/**
1591 * zfcp_erp_port_access_denied - Adapter denied access to port.
1592 * @port: port where access has been denied
1593 * @id: id for debug trace
1594 * @ref: reference for debug trace
1595 *
1596 * Since the adapter has denied access, stop using the port and the
1597 * attached units.
1598 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001599void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 unsigned long flags;
1602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001604 zfcp_erp_modify_port_status(port, id, ref,
1605 ZFCP_STATUS_COMMON_ERP_FAILED |
1606 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1608}
1609
Christof Schmitt287ac012008-07-02 10:56:40 +02001610/**
1611 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1612 * @unit: unit where access has been denied
1613 * @id: id for debug trace
1614 * @ref: reference for debug trace
1615 *
1616 * Since the adapter has denied access, stop using the unit.
1617 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001618void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
Martin Peschke698ec0162008-03-27 14:22:02 +01001620 zfcp_erp_modify_unit_status(unit, id, ref,
1621 ZFCP_STATUS_COMMON_ERP_FAILED |
1622 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623}
1624
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001625static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001626 void *ref)
1627{
1628 int status = atomic_read(&unit->status);
1629 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1630 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1631 return;
1632
1633 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1634}
1635
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001636static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001637 void *ref)
1638{
1639 struct zfcp_unit *unit;
1640 int status = atomic_read(&port->status);
1641
1642 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1643 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644 list_for_each_entry(unit, &port->unit_list_head, list)
1645 zfcp_erp_unit_access_changed(unit, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001646 return;
1647 }
1648
1649 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1650}
1651
1652/**
1653 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1654 * @adapter: Adapter where the Access Control Table (ACT) changed
1655 * @id: Id for debug trace
1656 * @ref: Reference for debug trace
1657 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001658void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001659 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
1661 struct zfcp_port *port;
1662 unsigned long flags;
1663
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001664 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1665 return;
1666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 read_lock_irqsave(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001669 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1671}