blob: feda1db56b236d87a4da30341927952219ee67d5 [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);
Swen Schillig058b8642009-08-18 15:43:14 +0200488 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
Christof Schmitt287ac012008-07-02 10:56:40 +0200489 act->fsf_req = NULL;
490 } else
491 act->fsf_req = NULL;
492 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493}
494
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200495/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200496 * zfcp_erp_notify - Trigger ERP action.
497 * @erp_action: ERP action to continue.
498 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200500void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 struct zfcp_adapter *adapter = erp_action->adapter;
503 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200506 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
507 erp_action->status |= set_mask;
508 zfcp_erp_action_ready(erp_action);
509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511}
512
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200513/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200514 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
515 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200517void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Christof Schmitt287ac012008-07-02 10:56:40 +0200519 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
520 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
Christof Schmitt287ac012008-07-02 10:56:40 +0200523static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Christof Schmitt287ac012008-07-02 10:56:40 +0200525 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
Christof Schmitt287ac012008-07-02 10:56:40 +0200528static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 init_timer(&erp_action->timer);
531 erp_action->timer.function = zfcp_erp_memwait_handler;
532 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200533 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200535}
536
537static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100538 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200539{
540 struct zfcp_port *port;
541
542 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200543 _zfcp_erp_port_reopen(port, clear, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200544}
545
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100546static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
547 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200548{
549 struct zfcp_unit *unit;
550
551 list_for_each_entry(unit, &port->unit_list_head, list)
552 _zfcp_erp_unit_reopen(unit, clear, id, ref);
553}
554
Christof Schmitt85600f72009-07-13 15:06:09 +0200555static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200556{
Christof Schmitt287ac012008-07-02 10:56:40 +0200557 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200558 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200559 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200560 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200561 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200562 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200563 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200564 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200565 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200566 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200567 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200568 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
569 break;
570 }
571}
572
573static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
574{
575 switch (act->action) {
576 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
577 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
578 break;
579 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
580 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
581 break;
582 case ZFCP_ERP_ACTION_REOPEN_PORT:
583 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200584 break;
585 }
586}
587
588static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
589{
590 unsigned long flags;
591
592 read_lock_irqsave(&zfcp_data.config_lock, flags);
593 read_lock(&adapter->erp_lock);
594 if (list_empty(&adapter->erp_ready_head) &&
595 list_empty(&adapter->erp_running_head)) {
596 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
597 &adapter->status);
598 wake_up(&adapter->erp_done_wqh);
599 }
600 read_unlock(&adapter->erp_lock);
601 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
602}
603
604static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
605{
Swen Schillig564e1c82009-08-18 15:43:19 +0200606 struct zfcp_qdio *qdio = act->adapter->qdio;
607
608 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200609 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200610 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200611 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
612 return ZFCP_ERP_SUCCEEDED;
613}
614
615static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
616{
617 struct zfcp_port *port;
618 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
619 adapter->peer_d_id);
620 if (IS_ERR(port)) /* error or port already attached */
621 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100622 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200623}
624
625static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
626{
627 int retries;
628 int sleep = 1;
629 struct zfcp_adapter *adapter = erp_action->adapter;
630
631 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
632
633 for (retries = 7; retries; retries--) {
634 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
635 &adapter->status);
636 write_lock_irq(&adapter->erp_lock);
637 zfcp_erp_action_to_running(erp_action);
638 write_unlock_irq(&adapter->erp_lock);
639 if (zfcp_fsf_exchange_config_data(erp_action)) {
640 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
641 &adapter->status);
642 return ZFCP_ERP_FAILED;
643 }
644
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100645 zfcp_rec_dbf_event_thread_lock("erasfx1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200646 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100647 zfcp_rec_dbf_event_thread_lock("erasfx2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200648 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
649 break;
650
651 if (!(atomic_read(&adapter->status) &
652 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
653 break;
654
655 ssleep(sleep);
656 sleep *= 2;
657 }
658
659 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
660 &adapter->status);
661
662 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
663 return ZFCP_ERP_FAILED;
664
665 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
666 zfcp_erp_enqueue_ptp_port(adapter);
667
668 return ZFCP_ERP_SUCCEEDED;
669}
670
671static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
672{
673 int ret;
674 struct zfcp_adapter *adapter = act->adapter;
675
Christof Schmitt287ac012008-07-02 10:56:40 +0200676 write_lock_irq(&adapter->erp_lock);
677 zfcp_erp_action_to_running(act);
678 write_unlock_irq(&adapter->erp_lock);
679
680 ret = zfcp_fsf_exchange_port_data(act);
681 if (ret == -EOPNOTSUPP)
682 return ZFCP_ERP_SUCCEEDED;
683 if (ret)
684 return ZFCP_ERP_FAILED;
685
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100686 zfcp_rec_dbf_event_thread_lock("erasox1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200687 down(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100688 zfcp_rec_dbf_event_thread_lock("erasox2", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +0200689 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
690 return ZFCP_ERP_FAILED;
691
692 return ZFCP_ERP_SUCCEEDED;
693}
694
695static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
696{
697 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
698 return ZFCP_ERP_FAILED;
699
700 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
701 return ZFCP_ERP_FAILED;
702
703 atomic_set(&act->adapter->stat_miss, 16);
704 if (zfcp_status_read_refill(act->adapter))
705 return ZFCP_ERP_FAILED;
706
707 return ZFCP_ERP_SUCCEEDED;
708}
709
Swen Schilligcf13c082009-03-02 13:09:03 +0100710static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200711{
Christof Schmitt287ac012008-07-02 10:56:40 +0200712 struct zfcp_adapter *adapter = act->adapter;
713
Christof Schmitt287ac012008-07-02 10:56:40 +0200714 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200715 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200716 zfcp_fsf_req_dismiss_all(adapter);
717 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200718 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200719 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100720 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200721 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100722
Christof Schmitt287ac012008-07-02 10:56:40 +0200723 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100724 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
725}
726
727static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
728{
729 struct zfcp_adapter *adapter = act->adapter;
730
731 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
732 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
733 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
734 &adapter->status);
735 return ZFCP_ERP_FAILED;
736 }
737
738 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
739 zfcp_erp_adapter_strategy_close(act);
740 return ZFCP_ERP_FAILED;
741 }
742
743 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
744
745 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200746}
747
748static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
749{
Swen Schilligcf13c082009-03-02 13:09:03 +0100750 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200751
Swen Schilligcf13c082009-03-02 13:09:03 +0100752 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
753 zfcp_erp_adapter_strategy_close(act);
754 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
755 return ZFCP_ERP_EXIT;
756 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200757
Swen Schilligcf13c082009-03-02 13:09:03 +0100758 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200759 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100760 return ZFCP_ERP_FAILED;
761 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Swen Schilligcf13c082009-03-02 13:09:03 +0100763 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
Christof Schmitt287ac012008-07-02 10:56:40 +0200766static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Christof Schmitt287ac012008-07-02 10:56:40 +0200768 int retval;
769
770 retval = zfcp_fsf_close_physical_port(act);
771 if (retval == -ENOMEM)
772 return ZFCP_ERP_NOMEM;
773 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
774 if (retval)
775 return ZFCP_ERP_FAILED;
776
777 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
Christof Schmitt287ac012008-07-02 10:56:40 +0200780static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100782 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200783}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Christof Schmitt287ac012008-07-02 10:56:40 +0200785static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
786{
787 struct zfcp_port *port = erp_action->port;
788 int status = atomic_read(&port->status);
789
790 switch (erp_action->step) {
791 case ZFCP_ERP_STEP_UNINITIALIZED:
792 zfcp_erp_port_strategy_clearstati(port);
793 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
794 (status & ZFCP_STATUS_COMMON_OPEN))
795 return zfcp_erp_port_forced_strategy_close(erp_action);
796 else
797 return ZFCP_ERP_FAILED;
798
799 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200800 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200801 return ZFCP_ERP_SUCCEEDED;
802 }
803 return ZFCP_ERP_FAILED;
804}
805
806static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
807{
808 int retval;
809
810 retval = zfcp_fsf_close_port(erp_action);
811 if (retval == -ENOMEM)
812 return ZFCP_ERP_NOMEM;
813 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
814 if (retval)
815 return ZFCP_ERP_FAILED;
816 return ZFCP_ERP_CONTINUES;
817}
818
819static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
820{
821 int retval;
822
823 retval = zfcp_fsf_open_port(erp_action);
824 if (retval == -ENOMEM)
825 return ZFCP_ERP_NOMEM;
826 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
827 if (retval)
828 return ZFCP_ERP_FAILED;
829 return ZFCP_ERP_CONTINUES;
830}
831
Christof Schmitt287ac012008-07-02 10:56:40 +0200832static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
833{
834 struct zfcp_adapter *adapter = act->adapter;
835 struct zfcp_port *port = act->port;
836
837 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100838 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200839 return ZFCP_ERP_FAILED;
840 }
841 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200842 return zfcp_erp_port_strategy_open_port(act);
843}
844
Swen Schillig5ab944f2008-10-01 12:42:17 +0200845void zfcp_erp_port_strategy_open_lookup(struct work_struct *work)
846{
847 int retval;
848 struct zfcp_port *port = container_of(work, struct zfcp_port,
849 gid_pn_work);
850
851 retval = zfcp_fc_ns_gid_pn(&port->erp_action);
Swen Schillig17a093e2009-07-13 15:06:12 +0200852 if (!retval) {
853 port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
854 goto out;
855 }
856 if (retval == -ENOMEM) {
Christof Schmitt688a1822009-07-13 15:06:05 +0200857 zfcp_erp_notify(&port->erp_action, ZFCP_STATUS_ERP_LOWMEM);
Swen Schillig17a093e2009-07-13 15:06:12 +0200858 goto out;
859 }
860 /* all other error condtions */
861 zfcp_erp_notify(&port->erp_action, 0);
862out:
Swen Schillig947a9ac2009-03-02 13:09:10 +0100863 zfcp_port_put(port);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200864}
865
Christof Schmitt287ac012008-07-02 10:56:40 +0200866static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
867{
868 struct zfcp_adapter *adapter = act->adapter;
869 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200870 int p_status = atomic_read(&port->status);
871
872 switch (act->step) {
873 case ZFCP_ERP_STEP_UNINITIALIZED:
874 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
875 case ZFCP_ERP_STEP_PORT_CLOSING:
876 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
877 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100878 if (!port->d_id) {
Swen Schillig947a9ac2009-03-02 13:09:10 +0100879 zfcp_port_get(port);
Swen Schillig45446832009-08-18 15:43:17 +0200880 if (!queue_work(adapter->work_queue,
Swen Schillig947a9ac2009-03-02 13:09:10 +0100881 &port->gid_pn_work))
882 zfcp_port_put(port);
Swen Schillig5ab944f2008-10-01 12:42:17 +0200883 return ZFCP_ERP_CONTINUES;
Christof Schmitt287ac012008-07-02 10:56:40 +0200884 }
Christof Schmittdceab652009-05-15 13:18:18 +0200885 /* fall through */
Christof Schmitt287ac012008-07-02 10:56:40 +0200886 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100887 if (!port->d_id)
Christof Schmitt287ac012008-07-02 10:56:40 +0200888 return ZFCP_ERP_FAILED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200889 return zfcp_erp_port_strategy_open_port(act);
890
891 case ZFCP_ERP_STEP_PORT_OPENING:
892 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200893 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmittb98478d2008-12-19 16:56:59 +0100894 if (port->d_id)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200895 return ZFCP_ERP_SUCCEEDED;
896 else {
897 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
898 return ZFCP_ERP_CONTINUES;
899 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200900 }
Swen Schilligea460a82009-05-15 13:18:20 +0200901 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
902 port->d_id = 0;
903 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
904 return ZFCP_ERP_EXIT;
905 }
906 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200907 }
908 return ZFCP_ERP_FAILED;
909}
910
Christof Schmitt287ac012008-07-02 10:56:40 +0200911static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
912{
913 struct zfcp_port *port = erp_action->port;
914
Swen Schillig5ab944f2008-10-01 12:42:17 +0200915 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
916 goto close_init_done;
917
Christof Schmitt287ac012008-07-02 10:56:40 +0200918 switch (erp_action->step) {
919 case ZFCP_ERP_STEP_UNINITIALIZED:
920 zfcp_erp_port_strategy_clearstati(port);
921 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
922 return zfcp_erp_port_strategy_close(erp_action);
923 break;
924
925 case ZFCP_ERP_STEP_PORT_CLOSING:
926 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
927 return ZFCP_ERP_FAILED;
928 break;
929 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200930
931close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200932 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
933 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200934
Swen Schillig5ab944f2008-10-01 12:42:17 +0200935 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
Christof Schmitt287ac012008-07-02 10:56:40 +0200938static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200940 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200941 ZFCP_STATUS_UNIT_SHARED |
942 ZFCP_STATUS_UNIT_READONLY,
943 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944}
945
Christof Schmitt287ac012008-07-02 10:56:40 +0200946static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
947{
948 int retval = zfcp_fsf_close_unit(erp_action);
949 if (retval == -ENOMEM)
950 return ZFCP_ERP_NOMEM;
951 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
952 if (retval)
953 return ZFCP_ERP_FAILED;
954 return ZFCP_ERP_CONTINUES;
955}
956
957static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
958{
959 int retval = zfcp_fsf_open_unit(erp_action);
960 if (retval == -ENOMEM)
961 return ZFCP_ERP_NOMEM;
962 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
963 if (retval)
964 return ZFCP_ERP_FAILED;
965 return ZFCP_ERP_CONTINUES;
966}
967
968static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
969{
970 struct zfcp_unit *unit = erp_action->unit;
971
972 switch (erp_action->step) {
973 case ZFCP_ERP_STEP_UNINITIALIZED:
974 zfcp_erp_unit_strategy_clearstati(unit);
975 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
976 return zfcp_erp_unit_strategy_close(erp_action);
977 /* already closed, fall through */
978 case ZFCP_ERP_STEP_UNIT_CLOSING:
979 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
980 return ZFCP_ERP_FAILED;
981 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
982 return ZFCP_ERP_EXIT;
983 return zfcp_erp_unit_strategy_open(erp_action);
984
985 case ZFCP_ERP_STEP_UNIT_OPENING:
986 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
987 return ZFCP_ERP_SUCCEEDED;
988 }
989 return ZFCP_ERP_FAILED;
990}
991
992static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
993{
994 switch (result) {
995 case ZFCP_ERP_SUCCEEDED :
996 atomic_set(&unit->erp_counter, 0);
997 zfcp_erp_unit_unblock(unit);
998 break;
999 case ZFCP_ERP_FAILED :
1000 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001001 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
1002 dev_err(&unit->port->adapter->ccw_device->dev,
1003 "ERP failed for unit 0x%016Lx on "
1004 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001005 (unsigned long long)unit->fcp_lun,
1006 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001007 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001008 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001009 break;
1010 }
1011
1012 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1013 zfcp_erp_unit_block(unit, 0);
1014 result = ZFCP_ERP_EXIT;
1015 }
1016 return result;
1017}
1018
1019static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1020{
1021 switch (result) {
1022 case ZFCP_ERP_SUCCEEDED :
1023 atomic_set(&port->erp_counter, 0);
1024 zfcp_erp_port_unblock(port);
1025 break;
1026
1027 case ZFCP_ERP_FAILED :
1028 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1029 zfcp_erp_port_block(port, 0);
1030 result = ZFCP_ERP_EXIT;
1031 }
1032 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001033 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1034 dev_err(&port->adapter->ccw_device->dev,
1035 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001036 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001037 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001038 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001039 break;
1040 }
1041
1042 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1043 zfcp_erp_port_block(port, 0);
1044 result = ZFCP_ERP_EXIT;
1045 }
1046 return result;
1047}
1048
1049static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1050 int result)
1051{
1052 switch (result) {
1053 case ZFCP_ERP_SUCCEEDED :
1054 atomic_set(&adapter->erp_counter, 0);
1055 zfcp_erp_adapter_unblock(adapter);
1056 break;
1057
1058 case ZFCP_ERP_FAILED :
1059 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001060 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1061 dev_err(&adapter->ccw_device->dev,
1062 "ERP cannot recover an error "
1063 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001064 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001065 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001066 break;
1067 }
1068
1069 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1070 zfcp_erp_adapter_block(adapter, 0);
1071 result = ZFCP_ERP_EXIT;
1072 }
1073 return result;
1074}
1075
1076static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1077 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
1079 struct zfcp_adapter *adapter = erp_action->adapter;
1080 struct zfcp_port *port = erp_action->port;
1081 struct zfcp_unit *unit = erp_action->unit;
1082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 switch (erp_action->action) {
1084
1085 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1086 result = zfcp_erp_strategy_check_unit(unit, result);
1087 break;
1088
1089 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1090 case ZFCP_ERP_ACTION_REOPEN_PORT:
1091 result = zfcp_erp_strategy_check_port(port, result);
1092 break;
1093
1094 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1095 result = zfcp_erp_strategy_check_adapter(adapter, result);
1096 break;
1097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 return result;
1099}
1100
Christof Schmitt287ac012008-07-02 10:56:40 +02001101static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Christof Schmitt287ac012008-07-02 10:56:40 +02001103 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Christof Schmitt287ac012008-07-02 10:56:40 +02001105 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1106 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1107 return 1; /* take it online */
1108
1109 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1110 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1111 return 1; /* take it offline */
1112
1113 return 0;
1114}
1115
1116static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1117{
1118 int action = act->action;
1119 struct zfcp_adapter *adapter = act->adapter;
1120 struct zfcp_port *port = act->port;
1121 struct zfcp_unit *unit = act->unit;
1122 u32 erp_status = act->status;
1123
1124 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001126 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1127 _zfcp_erp_adapter_reopen(adapter,
1128 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001129 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001130 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 }
1132 break;
1133
1134 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1135 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001136 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1137 _zfcp_erp_port_reopen(port,
1138 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001139 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001140 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 }
1142 break;
1143
1144 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001145 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1146 _zfcp_erp_unit_reopen(unit,
1147 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001148 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001149 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 }
1151 break;
1152 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001153 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
Christof Schmitt287ac012008-07-02 10:56:40 +02001156static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157{
Christof Schmitt287ac012008-07-02 10:56:40 +02001158 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Christof Schmitt287ac012008-07-02 10:56:40 +02001160 adapter->erp_total_count--;
1161 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1162 adapter->erp_low_mem_count--;
1163 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
1165
Christof Schmitt287ac012008-07-02 10:56:40 +02001166 list_del(&erp_action->list);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001167 zfcp_rec_dbf_event_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Christof Schmitt287ac012008-07-02 10:56:40 +02001169 switch (erp_action->action) {
1170 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1171 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1172 &erp_action->unit->status);
1173 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Christof Schmitt287ac012008-07-02 10:56:40 +02001175 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1176 case ZFCP_ERP_ACTION_REOPEN_PORT:
1177 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1178 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001180
1181 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1182 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1183 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Christof Schmitt287ac012008-07-02 10:56:40 +02001188static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001189{
Christof Schmitt287ac012008-07-02 10:56:40 +02001190 struct zfcp_adapter *adapter = act->adapter;
1191 struct zfcp_port *port = act->port;
1192 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001193
Christof Schmitt287ac012008-07-02 10:56:40 +02001194 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001196 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Swen Schillig92d51932009-04-17 15:08:04 +02001197 zfcp_unit_get(unit);
1198 if (scsi_queue_work(unit->port->adapter->scsi_host,
1199 &unit->scsi_work) <= 0)
1200 zfcp_unit_put(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 zfcp_unit_put(unit);
1203 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1206 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001207 if (result == ZFCP_ERP_SUCCEEDED)
1208 zfcp_scsi_schedule_rport_register(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 zfcp_port_put(port);
1210 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001213 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001214 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001215 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001216 } else
1217 unregister_service_level(&adapter->service_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 zfcp_adapter_put(adapter);
1219 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
1221}
1222
Christof Schmitt287ac012008-07-02 10:56:40 +02001223static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1224{
1225 switch (erp_action->action) {
1226 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1227 return zfcp_erp_adapter_strategy(erp_action);
1228 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1229 return zfcp_erp_port_forced_strategy(erp_action);
1230 case ZFCP_ERP_ACTION_REOPEN_PORT:
1231 return zfcp_erp_port_strategy(erp_action);
1232 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1233 return zfcp_erp_unit_strategy(erp_action);
1234 }
1235 return ZFCP_ERP_FAILED;
1236}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Christof Schmitt287ac012008-07-02 10:56:40 +02001238static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1239{
1240 int retval;
1241 struct zfcp_adapter *adapter = erp_action->adapter;
1242 unsigned long flags;
1243
1244 read_lock_irqsave(&zfcp_data.config_lock, flags);
1245 write_lock(&adapter->erp_lock);
1246
1247 zfcp_erp_strategy_check_fsfreq(erp_action);
1248
1249 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1250 zfcp_erp_action_dequeue(erp_action);
1251 retval = ZFCP_ERP_DISMISSED;
1252 goto unlock;
1253 }
1254
1255 zfcp_erp_action_to_running(erp_action);
1256
1257 /* no lock to allow for blocking operations */
1258 write_unlock(&adapter->erp_lock);
1259 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1260 retval = zfcp_erp_strategy_do_action(erp_action);
1261 read_lock_irqsave(&zfcp_data.config_lock, flags);
1262 write_lock(&adapter->erp_lock);
1263
1264 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1265 retval = ZFCP_ERP_CONTINUES;
1266
1267 switch (retval) {
1268 case ZFCP_ERP_NOMEM:
1269 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1270 ++adapter->erp_low_mem_count;
1271 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1272 }
1273 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001274 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001275 else {
1276 zfcp_erp_strategy_memwait(erp_action);
1277 retval = ZFCP_ERP_CONTINUES;
1278 }
1279 goto unlock;
1280
1281 case ZFCP_ERP_CONTINUES:
1282 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1283 --adapter->erp_low_mem_count;
1284 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1285 }
1286 goto unlock;
1287 }
1288
1289 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1290 zfcp_erp_action_dequeue(erp_action);
1291 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1292 if (retval == ZFCP_ERP_EXIT)
1293 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001294 if (retval == ZFCP_ERP_SUCCEEDED)
1295 zfcp_erp_strategy_followup_success(erp_action);
1296 if (retval == ZFCP_ERP_FAILED)
1297 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001298
1299 unlock:
1300 write_unlock(&adapter->erp_lock);
1301 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1302
1303 if (retval != ZFCP_ERP_CONTINUES)
1304 zfcp_erp_action_cleanup(erp_action, retval);
1305
1306 return retval;
1307}
1308
1309static int zfcp_erp_thread(void *data)
1310{
1311 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1312 struct list_head *next;
1313 struct zfcp_erp_action *act;
1314 unsigned long flags;
Heiko Carstens06499fa2008-12-19 16:56:56 +01001315 int ignore;
Christof Schmitt287ac012008-07-02 10:56:40 +02001316
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02001317 daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev));
Christof Schmitt287ac012008-07-02 10:56:40 +02001318 /* Block all signals */
1319 siginitsetinv(&current->blocked, 0);
1320 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1321 wake_up(&adapter->erp_thread_wqh);
1322
1323 while (!(atomic_read(&adapter->status) &
1324 ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) {
Swen Schillig94ab4b32009-04-17 15:08:06 +02001325
1326 zfcp_rec_dbf_event_thread_lock("erthrd1", adapter);
1327 ignore = down_interruptible(&adapter->erp_ready_sem);
1328 zfcp_rec_dbf_event_thread_lock("erthrd2", adapter);
1329
Christof Schmitt287ac012008-07-02 10:56:40 +02001330 write_lock_irqsave(&adapter->erp_lock, flags);
1331 next = adapter->erp_ready_head.next;
1332 write_unlock_irqrestore(&adapter->erp_lock, flags);
1333
1334 if (next != &adapter->erp_ready_head) {
1335 act = list_entry(next, struct zfcp_erp_action, list);
1336
1337 /* there is more to come after dismission, no notify */
1338 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1339 zfcp_erp_wakeup(adapter);
1340 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001341 }
1342
1343 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1344 wake_up(&adapter->erp_thread_wqh);
1345
1346 return 0;
1347}
1348
1349/**
1350 * zfcp_erp_thread_setup - Start ERP thread for adapter
1351 * @adapter: Adapter to start the ERP thread for
1352 *
1353 * Returns 0 on success or error code from kernel_thread()
1354 */
1355int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1356{
1357 int retval;
1358
1359 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1360 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1361 if (retval < 0) {
1362 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001363 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt287ac012008-07-02 10:56:40 +02001364 return retval;
1365 }
1366 wait_event(adapter->erp_thread_wqh,
1367 atomic_read(&adapter->status) &
1368 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP);
1369 return 0;
1370}
1371
1372/**
1373 * zfcp_erp_thread_kill - Stop ERP thread.
1374 * @adapter: Adapter where the ERP thread should be stopped.
1375 *
1376 * The caller of this routine ensures that the specified adapter has
1377 * been shut down and that this operation has been completed. Thus,
1378 * there are no pending erp_actions which would need to be handled
1379 * here.
1380 */
1381void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1382{
1383 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1384 up(&adapter->erp_ready_sem);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001385 zfcp_rec_dbf_event_thread_lock("erthrk1", adapter);
Christof Schmitt287ac012008-07-02 10:56:40 +02001386
1387 wait_event(adapter->erp_thread_wqh,
1388 !(atomic_read(&adapter->status) &
1389 ZFCP_STATUS_ADAPTER_ERP_THREAD_UP));
1390
1391 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1392 &adapter->status);
1393}
1394
1395/**
1396 * zfcp_erp_adapter_failed - Set adapter status to failed.
1397 * @adapter: Failed adapter.
1398 * @id: Event id for debug trace.
1399 * @ref: Reference for debug trace.
1400 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001401void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001402{
1403 zfcp_erp_modify_adapter_status(adapter, id, ref,
1404 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001405}
1406
1407/**
1408 * zfcp_erp_port_failed - Set port status to failed.
1409 * @port: Failed port.
1410 * @id: Event id for debug trace.
1411 * @ref: Reference for debug trace.
1412 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001413void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001414{
1415 zfcp_erp_modify_port_status(port, id, ref,
1416 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001417}
1418
1419/**
1420 * zfcp_erp_unit_failed - Set unit status to failed.
1421 * @unit: Failed unit.
1422 * @id: Event id for debug trace.
1423 * @ref: Reference for debug trace.
1424 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001425void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001426{
1427 zfcp_erp_modify_unit_status(unit, id, ref,
1428 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001429}
1430
1431/**
1432 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1433 * @adapter: adapter for which to wait for completion of its error recovery
1434 */
1435void zfcp_erp_wait(struct zfcp_adapter *adapter)
1436{
1437 wait_event(adapter->erp_done_wqh,
1438 !(atomic_read(&adapter->status) &
1439 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1440}
1441
1442/**
1443 * zfcp_erp_modify_adapter_status - change adapter status bits
1444 * @adapter: adapter to change the status
1445 * @id: id for the debug trace
1446 * @ref: reference for the debug trace
1447 * @mask: status bits to change
1448 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1449 *
1450 * Changes in common status bits are propagated to attached ports and units.
1451 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001452void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001453 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 struct zfcp_port *port;
Christof Schmitt287ac012008-07-02 10:56:40 +02001456 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Christof Schmitt287ac012008-07-02 10:56:40 +02001458 if (set_or_clear == ZFCP_SET) {
1459 if (status_change_set(mask, &adapter->status))
1460 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1461 atomic_set_mask(mask, &adapter->status);
1462 } else {
1463 if (status_change_clear(mask, &adapter->status))
1464 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1465 atomic_clear_mask(mask, &adapter->status);
1466 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1467 atomic_set(&adapter->erp_counter, 0);
1468 }
1469
1470 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 list_for_each_entry(port, &adapter->port_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001472 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1473 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
Christof Schmitt287ac012008-07-02 10:56:40 +02001476/**
1477 * zfcp_erp_modify_port_status - change port status bits
1478 * @port: port to change the status bits
1479 * @id: id for the debug trace
1480 * @ref: reference for the debug trace
1481 * @mask: status bits to change
1482 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1483 *
1484 * Changes in common status bits are propagated to attached units.
1485 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001486void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001487 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 struct zfcp_unit *unit;
Christof Schmitt287ac012008-07-02 10:56:40 +02001490 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Christof Schmitt287ac012008-07-02 10:56:40 +02001492 if (set_or_clear == ZFCP_SET) {
1493 if (status_change_set(mask, &port->status))
1494 zfcp_rec_dbf_event_port(id, ref, port);
1495 atomic_set_mask(mask, &port->status);
1496 } else {
1497 if (status_change_clear(mask, &port->status))
1498 zfcp_rec_dbf_event_port(id, ref, port);
1499 atomic_clear_mask(mask, &port->status);
1500 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1501 atomic_set(&port->erp_counter, 0);
1502 }
1503
1504 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 list_for_each_entry(unit, &port->unit_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001506 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1507 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}
1509
Christof Schmitt287ac012008-07-02 10:56:40 +02001510/**
1511 * zfcp_erp_modify_unit_status - change unit status bits
1512 * @unit: unit to change the status bits
1513 * @id: id for the debug trace
1514 * @ref: reference for the debug trace
1515 * @mask: status bits to change
1516 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1517 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001518void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001519 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Christof Schmitt287ac012008-07-02 10:56:40 +02001521 if (set_or_clear == ZFCP_SET) {
1522 if (status_change_set(mask, &unit->status))
1523 zfcp_rec_dbf_event_unit(id, ref, unit);
1524 atomic_set_mask(mask, &unit->status);
1525 } else {
1526 if (status_change_clear(mask, &unit->status))
1527 zfcp_rec_dbf_event_unit(id, ref, unit);
1528 atomic_clear_mask(mask, &unit->status);
1529 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1530 atomic_set(&unit->erp_counter, 0);
1531 }
1532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533}
1534
Christof Schmitt287ac012008-07-02 10:56:40 +02001535/**
1536 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1537 * @port: The "boxed" port.
1538 * @id: The debug trace id.
1539 * @id: Reference for the debug trace.
1540 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001541void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001542{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001543 unsigned long flags;
1544
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001545 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001546 zfcp_erp_modify_port_status(port, id, ref,
1547 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001548 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001549 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001550}
1551
Christof Schmitt287ac012008-07-02 10:56:40 +02001552/**
1553 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1554 * @port: The "boxed" unit.
1555 * @id: The debug trace id.
1556 * @id: Reference for the debug trace.
1557 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001558void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001559{
Martin Peschke698ec0162008-03-27 14:22:02 +01001560 zfcp_erp_modify_unit_status(unit, id, ref,
1561 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001562 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001563}
1564
Christof Schmitt287ac012008-07-02 10:56:40 +02001565/**
1566 * zfcp_erp_port_access_denied - Adapter denied access to port.
1567 * @port: port where access has been denied
1568 * @id: id for debug trace
1569 * @ref: reference for debug trace
1570 *
1571 * Since the adapter has denied access, stop using the port and the
1572 * attached units.
1573 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001574void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 unsigned long flags;
1577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001579 zfcp_erp_modify_port_status(port, id, ref,
1580 ZFCP_STATUS_COMMON_ERP_FAILED |
1581 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1583}
1584
Christof Schmitt287ac012008-07-02 10:56:40 +02001585/**
1586 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1587 * @unit: unit where access has been denied
1588 * @id: id for debug trace
1589 * @ref: reference for debug trace
1590 *
1591 * Since the adapter has denied access, stop using the unit.
1592 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001593void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
Martin Peschke698ec0162008-03-27 14:22:02 +01001595 zfcp_erp_modify_unit_status(unit, id, ref,
1596 ZFCP_STATUS_COMMON_ERP_FAILED |
1597 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598}
1599
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001600static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001601 void *ref)
1602{
1603 int status = atomic_read(&unit->status);
1604 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1605 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1606 return;
1607
1608 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1609}
1610
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001611static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001612 void *ref)
1613{
1614 struct zfcp_unit *unit;
1615 int status = atomic_read(&port->status);
1616
1617 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1618 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001619 list_for_each_entry(unit, &port->unit_list_head, list)
1620 zfcp_erp_unit_access_changed(unit, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001621 return;
1622 }
1623
1624 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1625}
1626
1627/**
1628 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1629 * @adapter: Adapter where the Access Control Table (ACT) changed
1630 * @id: Id for debug trace
1631 * @ref: Reference for debug trace
1632 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001633void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001634 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
1636 struct zfcp_port *port;
1637 unsigned long flags;
1638
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001639 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1640 return;
1641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 read_lock_irqsave(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001644 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1646}