blob: e3dbeda97179bccc814e424c705a53255ef61f54 [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 Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2002, 2010
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
Christof Schmitt347c6a92009-08-18 15:43:25 +020012#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "zfcp_ext.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010014#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Christof Schmitt287ac012008-07-02 10:56:40 +020016#define ZFCP_MAX_ERPS 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Christof Schmitt287ac012008-07-02 10:56:40 +020018enum zfcp_erp_act_flags {
19 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
20 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
21 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
22 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
23 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
24};
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Christof Schmitt287ac012008-07-02 10:56:40 +020026enum zfcp_erp_steps {
27 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
28 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
29 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
30 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
Christof Schmitt287ac012008-07-02 10:56:40 +020031 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
32 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
33 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
34};
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Christof Schmitt287ac012008-07-02 10:56:40 +020036enum zfcp_erp_act_type {
37 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
38 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
39 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
40 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
41};
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Christof Schmitt287ac012008-07-02 10:56:40 +020043enum zfcp_erp_act_state {
44 ZFCP_ERP_ACTION_RUNNING = 1,
45 ZFCP_ERP_ACTION_READY = 2,
46};
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Christof Schmitt287ac012008-07-02 10:56:40 +020048enum zfcp_erp_act_result {
49 ZFCP_ERP_SUCCEEDED = 0,
50 ZFCP_ERP_FAILED = 1,
51 ZFCP_ERP_CONTINUES = 2,
52 ZFCP_ERP_EXIT = 3,
53 ZFCP_ERP_DISMISSED = 4,
54 ZFCP_ERP_NOMEM = 5,
55};
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Christof Schmitt287ac012008-07-02 10:56:40 +020057static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
Andreas Herrmann2abbe862006-09-18 22:29:56 +020058{
Swen Schillig5ffd51a2009-03-02 13:09:04 +010059 zfcp_erp_modify_adapter_status(adapter, "erablk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +020060 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
61 ZFCP_CLEAR);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020062}
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Christof Schmitt287ac012008-07-02 10:56:40 +020064static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Christof Schmitt287ac012008-07-02 10:56:40 +020066 struct zfcp_erp_action *curr_act;
67
68 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
69 if (act == curr_act)
70 return ZFCP_ERP_ACTION_RUNNING;
71 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Christof Schmitt287ac012008-07-02 10:56:40 +020074static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Christof Schmitt287ac012008-07-02 10:56:40 +020076 struct zfcp_adapter *adapter = act->adapter;
77
78 list_move(&act->list, &act->adapter->erp_ready_head);
Swen Schillig57717102009-08-18 15:43:21 +020079 zfcp_dbf_rec_action("erardy1", act);
Christof Schmitt347c6a92009-08-18 15:43:25 +020080 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +020081 zfcp_dbf_rec_thread("erardy2", adapter->dbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Christof Schmitt287ac012008-07-02 10:56:40 +020084static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Christof Schmitt287ac012008-07-02 10:56:40 +020086 act->status |= ZFCP_STATUS_ERP_DISMISSED;
87 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
88 zfcp_erp_action_ready(act);
89}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Christof Schmitt287ac012008-07-02 10:56:40 +020091static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
92{
93 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
94 zfcp_erp_action_dismiss(&unit->erp_action);
95}
96
97static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
98{
99 struct zfcp_unit *unit;
100
101 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
102 zfcp_erp_action_dismiss(&port->erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +0100103 else {
104 read_lock(&port->unit_list_lock);
105 list_for_each_entry(unit, &port->unit_list, list)
106 zfcp_erp_action_dismiss_unit(unit);
107 read_unlock(&port->unit_list_lock);
108 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200109}
110
111static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
112{
113 struct zfcp_port *port;
114
115 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
116 zfcp_erp_action_dismiss(&adapter->erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +0100117 else {
118 read_lock(&adapter->port_list_lock);
119 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200120 zfcp_erp_action_dismiss_port(port);
Swen Schilligecf0c772009-11-24 16:53:58 +0100121 read_unlock(&adapter->port_list_lock);
122 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200123}
124
125static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
126 struct zfcp_port *port,
127 struct zfcp_unit *unit)
128{
129 int need = want;
130 int u_status, p_status, a_status;
131
132 switch (want) {
133 case ZFCP_ERP_ACTION_REOPEN_UNIT:
134 u_status = atomic_read(&unit->status);
135 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
136 return 0;
137 p_status = atomic_read(&port->status);
138 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
139 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
140 return 0;
141 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
142 need = ZFCP_ERP_ACTION_REOPEN_PORT;
143 /* fall through */
144 case ZFCP_ERP_ACTION_REOPEN_PORT:
145 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
146 p_status = atomic_read(&port->status);
147 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
148 return 0;
149 a_status = atomic_read(&adapter->status);
150 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
151 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
152 return 0;
153 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
154 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
155 /* fall through */
156 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
157 a_status = atomic_read(&adapter->status);
158 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
159 return 0;
Christof Schmitt143bb6b2009-08-18 15:43:27 +0200160 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) &&
161 !(a_status & ZFCP_STATUS_COMMON_OPEN))
162 return 0; /* shutdown requested for closed adapter */
Christof Schmitt287ac012008-07-02 10:56:40 +0200163 }
164
165 return need;
166}
167
168static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
169 struct zfcp_adapter *adapter,
170 struct zfcp_port *port,
171 struct zfcp_unit *unit)
172{
173 struct zfcp_erp_action *erp_action;
174 u32 status = 0;
175
176 switch (need) {
177 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt615f59e2010-02-17 11:18:56 +0100178 if (!get_device(&unit->dev))
Swen Schillig6b1833342009-11-24 16:54:05 +0100179 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200180 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
181 erp_action = &unit->erp_action;
182 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
183 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
184 break;
185
186 case ZFCP_ERP_ACTION_REOPEN_PORT:
187 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt615f59e2010-02-17 11:18:56 +0100188 if (!get_device(&port->dev))
Swen Schillig6b1833342009-11-24 16:54:05 +0100189 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200190 zfcp_erp_action_dismiss_port(port);
191 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
192 erp_action = &port->erp_action;
193 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
194 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
195 break;
196
197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Swen Schilligf3450c72009-11-24 16:53:59 +0100198 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200199 zfcp_erp_action_dismiss_adapter(adapter);
200 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
201 erp_action = &adapter->erp_action;
202 if (!(atomic_read(&adapter->status) &
203 ZFCP_STATUS_COMMON_RUNNING))
204 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
205 break;
206
207 default:
208 return NULL;
209 }
210
211 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
212 erp_action->adapter = adapter;
213 erp_action->port = port;
214 erp_action->unit = unit;
215 erp_action->action = need;
216 erp_action->status = status;
217
218 return erp_action;
219}
220
221static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
222 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100223 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200224{
225 int retval = 1, need;
226 struct zfcp_erp_action *act = NULL;
227
Christof Schmitt347c6a92009-08-18 15:43:25 +0200228 if (!adapter->erp_thread)
Christof Schmitt287ac012008-07-02 10:56:40 +0200229 return -EIO;
230
231 need = zfcp_erp_required_act(want, adapter, port, unit);
232 if (!need)
233 goto out;
234
235 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
236 act = zfcp_erp_setup_act(need, adapter, port, unit);
237 if (!act)
238 goto out;
239 ++adapter->erp_total_count;
240 list_add_tail(&act->list, &adapter->erp_ready_head);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200241 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +0200242 zfcp_dbf_rec_thread("eracte1", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200243 retval = 0;
244 out:
Swen Schillig57717102009-08-18 15:43:21 +0200245 zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200246 return retval;
247}
248
249static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100250 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200251{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100253 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Christof Schmitt287ac012008-07-02 10:56:40 +0200255 /* ensure propagation of failed status to new devices */
256 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100257 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200260 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
261 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
264/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200265 * zfcp_erp_adapter_reopen - Reopen adapter.
266 * @adapter: Adapter to reopen.
267 * @clear: Status flags to clear.
268 * @id: Id for debug trace event.
269 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200271void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100272 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Christof Schmitt287ac012008-07-02 10:56:40 +0200274 unsigned long flags;
275
Swen Schilligecf0c772009-11-24 16:53:58 +0100276 zfcp_erp_adapter_block(adapter, clear);
277 zfcp_scsi_schedule_rports_block(adapter);
278
279 write_lock_irqsave(&adapter->erp_lock, flags);
280 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
281 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
282 else
283 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
284 NULL, NULL, id, ref);
285 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200286}
287
288/**
289 * zfcp_erp_adapter_shutdown - Shutdown adapter.
290 * @adapter: Adapter to shut down.
291 * @clear: Status flags to clear.
292 * @id: Id for debug trace event.
293 * @ref: Reference for debug trace event.
294 */
295void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100296 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200297{
298 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
299 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
300}
301
302/**
303 * zfcp_erp_port_shutdown - Shutdown port
304 * @port: Port to shut down.
305 * @clear: Status flags to clear.
306 * @id: Id for debug trace event.
307 * @ref: Reference for debug trace event.
308 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100309void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
310 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200311{
312 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
313 zfcp_erp_port_reopen(port, clear | flags, id, ref);
314}
315
316/**
317 * zfcp_erp_unit_shutdown - Shutdown unit
318 * @unit: Unit to shut down.
319 * @clear: Status flags to clear.
320 * @id: Id for debug trace event.
321 * @ref: Reference for debug trace event.
322 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100323void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
324 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200325{
326 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
327 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
328}
329
330static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
331{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100332 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200333 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
334 ZFCP_CLEAR);
335}
336
337static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100338 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200339{
340 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100341 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200342
343 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
344 return;
345
346 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
347 port->adapter, port, NULL, id, ref);
348}
349
350/**
351 * zfcp_erp_port_forced_reopen - Forced close of port and open again
352 * @port: Port to force close and to reopen.
353 * @id: Id for debug trace event.
354 * @ref: Reference for debug trace event.
355 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100356void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200357 void *ref)
358{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 unsigned long flags;
360 struct zfcp_adapter *adapter = port->adapter;
361
Swen Schilligecf0c772009-11-24 16:53:58 +0100362 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200363 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100364 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200365}
366
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100367static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200368 void *ref)
369{
370 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100371 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200372
373 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
374 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100375 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200376 return -EIO;
377 }
378
379 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
380 port->adapter, port, NULL, id, ref);
381}
382
383/**
384 * zfcp_erp_port_reopen - trigger remote port recovery
385 * @port: port to recover
386 * @clear_mask: flags in port status to be cleared
387 *
388 * Returns 0 if recovery has been triggered, < 0 if not.
389 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100390int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200391{
Christof Schmitt287ac012008-07-02 10:56:40 +0200392 int retval;
Swen Schilligecf0c772009-11-24 16:53:58 +0100393 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200394 struct zfcp_adapter *adapter = port->adapter;
395
Swen Schilligecf0c772009-11-24 16:53:58 +0100396 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200397 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100398 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 return retval;
401}
402
Christof Schmitt287ac012008-07-02 10:56:40 +0200403static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100405 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200406 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
407 ZFCP_CLEAR);
408}
409
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100410static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200411 void *ref)
412{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 struct zfcp_adapter *adapter = unit->port->adapter;
414
Christof Schmitt287ac012008-07-02 10:56:40 +0200415 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Christof Schmitt287ac012008-07-02 10:56:40 +0200417 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
418 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Christof Schmitt287ac012008-07-02 10:56:40 +0200420 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
421 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
424/**
425 * zfcp_erp_unit_reopen - initiate reopen of a unit
426 * @unit: unit to be reopened
427 * @clear_mask: specifies flags in unit status to be cleared
428 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100430void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
431 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200434 struct zfcp_port *port = unit->port;
435 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Swen Schilligecf0c772009-11-24 16:53:58 +0100437 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200438 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100439 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Christof Schmitt287ac012008-07-02 10:56:40 +0200442static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443{
Christof Schmitt287ac012008-07-02 10:56:40 +0200444 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445}
446
Christof Schmitt287ac012008-07-02 10:56:40 +0200447static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100448{
Christof Schmitt287ac012008-07-02 10:56:40 +0200449 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100450}
451
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200452static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Christof Schmitt287ac012008-07-02 10:56:40 +0200454 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +0200455 zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200456 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457}
458
Christof Schmitt287ac012008-07-02 10:56:40 +0200459static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Christof Schmitt287ac012008-07-02 10:56:40 +0200461 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +0200462 zfcp_dbf_rec_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200463 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Christof Schmitt287ac012008-07-02 10:56:40 +0200466static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
Christof Schmitt287ac012008-07-02 10:56:40 +0200468 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +0200469 zfcp_dbf_rec_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200470 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471}
472
Christof Schmitt287ac012008-07-02 10:56:40 +0200473static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Christof Schmitt287ac012008-07-02 10:56:40 +0200475 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig57717102009-08-18 15:43:21 +0200476 zfcp_dbf_rec_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
Christof Schmitt287ac012008-07-02 10:56:40 +0200479static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Christof Schmitt287ac012008-07-02 10:56:40 +0200481 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitte60a6d62010-02-17 11:18:49 +0100482 struct zfcp_fsf_req *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Christof Schmitte60a6d62010-02-17 11:18:49 +0100484 if (!act->fsf_req_id)
Christof Schmitt287ac012008-07-02 10:56:40 +0200485 return;
486
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100487 spin_lock(&adapter->req_list->lock);
488 req = _zfcp_reqlist_find(adapter->req_list, act->fsf_req_id);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100489 if (req && req->erp_action == act) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200490 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
491 ZFCP_STATUS_ERP_TIMEDOUT)) {
Christof Schmitte60a6d62010-02-17 11:18:49 +0100492 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig57717102009-08-18 15:43:21 +0200493 zfcp_dbf_rec_action("erscf_1", act);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100494 req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200496 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig57717102009-08-18 15:43:21 +0200497 zfcp_dbf_rec_action("erscf_2", act);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100498 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
499 act->fsf_req_id = 0;
Christof Schmitt287ac012008-07-02 10:56:40 +0200500 } else
Christof Schmitte60a6d62010-02-17 11:18:49 +0100501 act->fsf_req_id = 0;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100502 spin_unlock(&adapter->req_list->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503}
504
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200505/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200506 * zfcp_erp_notify - Trigger ERP action.
507 * @erp_action: ERP action to continue.
508 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200510void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
512 struct zfcp_adapter *adapter = erp_action->adapter;
513 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200516 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
517 erp_action->status |= set_mask;
518 zfcp_erp_action_ready(erp_action);
519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521}
522
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200523/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200524 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
525 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200527void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Christof Schmitt287ac012008-07-02 10:56:40 +0200529 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
530 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
Christof Schmitt287ac012008-07-02 10:56:40 +0200533static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Christof Schmitt287ac012008-07-02 10:56:40 +0200535 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
Christof Schmitt287ac012008-07-02 10:56:40 +0200538static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 init_timer(&erp_action->timer);
541 erp_action->timer.function = zfcp_erp_memwait_handler;
542 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200543 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200545}
546
547static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100548 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200549{
550 struct zfcp_port *port;
551
Swen Schilligecf0c772009-11-24 16:53:58 +0100552 read_lock(&adapter->port_list_lock);
553 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200554 _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100555 read_unlock(&adapter->port_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200556}
557
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100558static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
559 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200560{
561 struct zfcp_unit *unit;
562
Swen Schilligecf0c772009-11-24 16:53:58 +0100563 read_lock(&port->unit_list_lock);
564 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200565 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100566 read_unlock(&port->unit_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200567}
568
Christof Schmitt85600f72009-07-13 15:06:09 +0200569static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200570{
Christof Schmitt287ac012008-07-02 10:56:40 +0200571 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200572 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200573 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200574 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200575 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200576 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200577 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200578 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200579 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200580 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200581 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200582 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
583 break;
584 }
585}
586
587static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
588{
589 switch (act->action) {
590 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
591 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
592 break;
593 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
594 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
595 break;
596 case ZFCP_ERP_ACTION_REOPEN_PORT:
597 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200598 break;
599 }
600}
601
602static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
603{
604 unsigned long flags;
605
Swen Schilligecf0c772009-11-24 16:53:58 +0100606 read_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200607 if (list_empty(&adapter->erp_ready_head) &&
608 list_empty(&adapter->erp_running_head)) {
609 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
610 &adapter->status);
611 wake_up(&adapter->erp_done_wqh);
612 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100613 read_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200614}
615
616static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
617{
Swen Schillig564e1c82009-08-18 15:43:19 +0200618 struct zfcp_qdio *qdio = act->adapter->qdio;
619
620 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200621 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200622 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200623 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
624 return ZFCP_ERP_SUCCEEDED;
625}
626
627static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
628{
629 struct zfcp_port *port;
630 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
631 adapter->peer_d_id);
632 if (IS_ERR(port)) /* error or port already attached */
633 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100634 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200635}
636
637static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
638{
639 int retries;
640 int sleep = 1;
641 struct zfcp_adapter *adapter = erp_action->adapter;
642
643 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
644
645 for (retries = 7; retries; retries--) {
646 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
647 &adapter->status);
648 write_lock_irq(&adapter->erp_lock);
649 zfcp_erp_action_to_running(erp_action);
650 write_unlock_irq(&adapter->erp_lock);
651 if (zfcp_fsf_exchange_config_data(erp_action)) {
652 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
653 &adapter->status);
654 return ZFCP_ERP_FAILED;
655 }
656
Swen Schillig57717102009-08-18 15:43:21 +0200657 zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200658 wait_event(adapter->erp_ready_wq,
659 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200660 zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200661 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
662 break;
663
664 if (!(atomic_read(&adapter->status) &
665 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
666 break;
667
668 ssleep(sleep);
669 sleep *= 2;
670 }
671
672 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
673 &adapter->status);
674
675 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
676 return ZFCP_ERP_FAILED;
677
678 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
679 zfcp_erp_enqueue_ptp_port(adapter);
680
681 return ZFCP_ERP_SUCCEEDED;
682}
683
684static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
685{
686 int ret;
687 struct zfcp_adapter *adapter = act->adapter;
688
Christof Schmitt287ac012008-07-02 10:56:40 +0200689 write_lock_irq(&adapter->erp_lock);
690 zfcp_erp_action_to_running(act);
691 write_unlock_irq(&adapter->erp_lock);
692
693 ret = zfcp_fsf_exchange_port_data(act);
694 if (ret == -EOPNOTSUPP)
695 return ZFCP_ERP_SUCCEEDED;
696 if (ret)
697 return ZFCP_ERP_FAILED;
698
Swen Schillig57717102009-08-18 15:43:21 +0200699 zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200700 wait_event(adapter->erp_ready_wq,
701 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200702 zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200703 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
704 return ZFCP_ERP_FAILED;
705
706 return ZFCP_ERP_SUCCEEDED;
707}
708
709static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
710{
711 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
712 return ZFCP_ERP_FAILED;
713
714 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
715 return ZFCP_ERP_FAILED;
716
Christof Schmitt64deb6e2010-04-30 18:09:36 +0200717 atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num);
Christof Schmitt287ac012008-07-02 10:56:40 +0200718 if (zfcp_status_read_refill(act->adapter))
719 return ZFCP_ERP_FAILED;
720
721 return ZFCP_ERP_SUCCEEDED;
722}
723
Swen Schilligcf13c082009-03-02 13:09:03 +0100724static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200725{
Christof Schmitt287ac012008-07-02 10:56:40 +0200726 struct zfcp_adapter *adapter = act->adapter;
727
Christof Schmitt287ac012008-07-02 10:56:40 +0200728 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200729 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200730 zfcp_fsf_req_dismiss_all(adapter);
731 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200732 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200733 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100734 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200735 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100736
Christof Schmitt287ac012008-07-02 10:56:40 +0200737 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100738 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
739}
740
741static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
742{
743 struct zfcp_adapter *adapter = act->adapter;
744
745 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
746 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
747 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
748 &adapter->status);
749 return ZFCP_ERP_FAILED;
750 }
751
752 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
753 zfcp_erp_adapter_strategy_close(act);
754 return ZFCP_ERP_FAILED;
755 }
756
757 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
758
759 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200760}
761
762static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
763{
Swen Schilligcf13c082009-03-02 13:09:03 +0100764 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200765
Swen Schilligcf13c082009-03-02 13:09:03 +0100766 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
767 zfcp_erp_adapter_strategy_close(act);
768 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
769 return ZFCP_ERP_EXIT;
770 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200771
Swen Schilligcf13c082009-03-02 13:09:03 +0100772 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200773 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100774 return ZFCP_ERP_FAILED;
775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Swen Schilligcf13c082009-03-02 13:09:03 +0100777 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778}
779
Christof Schmitt287ac012008-07-02 10:56:40 +0200780static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Christof Schmitt287ac012008-07-02 10:56:40 +0200782 int retval;
783
784 retval = zfcp_fsf_close_physical_port(act);
785 if (retval == -ENOMEM)
786 return ZFCP_ERP_NOMEM;
787 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
788 if (retval)
789 return ZFCP_ERP_FAILED;
790
791 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792}
793
Christof Schmitt287ac012008-07-02 10:56:40 +0200794static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100796 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200797}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
Christof Schmitt287ac012008-07-02 10:56:40 +0200799static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
800{
801 struct zfcp_port *port = erp_action->port;
802 int status = atomic_read(&port->status);
803
804 switch (erp_action->step) {
805 case ZFCP_ERP_STEP_UNINITIALIZED:
806 zfcp_erp_port_strategy_clearstati(port);
807 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
808 (status & ZFCP_STATUS_COMMON_OPEN))
809 return zfcp_erp_port_forced_strategy_close(erp_action);
810 else
811 return ZFCP_ERP_FAILED;
812
813 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200814 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200815 return ZFCP_ERP_SUCCEEDED;
816 }
817 return ZFCP_ERP_FAILED;
818}
819
820static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
821{
822 int retval;
823
824 retval = zfcp_fsf_close_port(erp_action);
825 if (retval == -ENOMEM)
826 return ZFCP_ERP_NOMEM;
827 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
828 if (retval)
829 return ZFCP_ERP_FAILED;
830 return ZFCP_ERP_CONTINUES;
831}
832
833static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
834{
835 int retval;
836
837 retval = zfcp_fsf_open_port(erp_action);
838 if (retval == -ENOMEM)
839 return ZFCP_ERP_NOMEM;
840 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
841 if (retval)
842 return ZFCP_ERP_FAILED;
843 return ZFCP_ERP_CONTINUES;
844}
845
Christof Schmitt287ac012008-07-02 10:56:40 +0200846static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
847{
848 struct zfcp_adapter *adapter = act->adapter;
849 struct zfcp_port *port = act->port;
850
851 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100852 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200853 return ZFCP_ERP_FAILED;
854 }
855 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200856 return zfcp_erp_port_strategy_open_port(act);
857}
858
859static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
860{
861 struct zfcp_adapter *adapter = act->adapter;
862 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200863 int p_status = atomic_read(&port->status);
864
865 switch (act->step) {
866 case ZFCP_ERP_STEP_UNINITIALIZED:
867 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
868 case ZFCP_ERP_STEP_PORT_CLOSING:
869 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
870 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100871 if (!port->d_id) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200872 zfcp_fc_trigger_did_lookup(port);
Christof Schmitt799b76d2009-08-18 15:43:20 +0200873 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200874 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200875 return zfcp_erp_port_strategy_open_port(act);
876
877 case ZFCP_ERP_STEP_PORT_OPENING:
878 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200879 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200880 if (!port->d_id) {
881 zfcp_fc_trigger_did_lookup(port);
882 return ZFCP_ERP_EXIT;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200883 }
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200884 return ZFCP_ERP_SUCCEEDED;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200885 }
Swen Schilligea460a82009-05-15 13:18:20 +0200886 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
887 port->d_id = 0;
888 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
889 return ZFCP_ERP_EXIT;
890 }
891 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200892 }
893 return ZFCP_ERP_FAILED;
894}
895
Christof Schmitt287ac012008-07-02 10:56:40 +0200896static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
897{
898 struct zfcp_port *port = erp_action->port;
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200899 int p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200900
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200901 if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
902 !(p_status & ZFCP_STATUS_COMMON_OPEN))
Swen Schillig5ab944f2008-10-01 12:42:17 +0200903 goto close_init_done;
904
Christof Schmitt287ac012008-07-02 10:56:40 +0200905 switch (erp_action->step) {
906 case ZFCP_ERP_STEP_UNINITIALIZED:
907 zfcp_erp_port_strategy_clearstati(port);
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200908 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200909 return zfcp_erp_port_strategy_close(erp_action);
910 break;
911
912 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200913 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200914 return ZFCP_ERP_FAILED;
915 break;
916 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200917
918close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200919 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
920 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200921
Swen Schillig5ab944f2008-10-01 12:42:17 +0200922 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
Christof Schmitt287ac012008-07-02 10:56:40 +0200925static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200927 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200928 ZFCP_STATUS_UNIT_SHARED |
929 ZFCP_STATUS_UNIT_READONLY,
930 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931}
932
Christof Schmitt287ac012008-07-02 10:56:40 +0200933static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
934{
935 int retval = zfcp_fsf_close_unit(erp_action);
936 if (retval == -ENOMEM)
937 return ZFCP_ERP_NOMEM;
938 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
939 if (retval)
940 return ZFCP_ERP_FAILED;
941 return ZFCP_ERP_CONTINUES;
942}
943
944static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
945{
946 int retval = zfcp_fsf_open_unit(erp_action);
947 if (retval == -ENOMEM)
948 return ZFCP_ERP_NOMEM;
949 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
950 if (retval)
951 return ZFCP_ERP_FAILED;
952 return ZFCP_ERP_CONTINUES;
953}
954
955static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
956{
957 struct zfcp_unit *unit = erp_action->unit;
958
959 switch (erp_action->step) {
960 case ZFCP_ERP_STEP_UNINITIALIZED:
961 zfcp_erp_unit_strategy_clearstati(unit);
962 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
963 return zfcp_erp_unit_strategy_close(erp_action);
964 /* already closed, fall through */
965 case ZFCP_ERP_STEP_UNIT_CLOSING:
966 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
967 return ZFCP_ERP_FAILED;
968 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
969 return ZFCP_ERP_EXIT;
970 return zfcp_erp_unit_strategy_open(erp_action);
971
972 case ZFCP_ERP_STEP_UNIT_OPENING:
973 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
974 return ZFCP_ERP_SUCCEEDED;
975 }
976 return ZFCP_ERP_FAILED;
977}
978
979static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
980{
981 switch (result) {
982 case ZFCP_ERP_SUCCEEDED :
983 atomic_set(&unit->erp_counter, 0);
984 zfcp_erp_unit_unblock(unit);
985 break;
986 case ZFCP_ERP_FAILED :
987 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200988 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
989 dev_err(&unit->port->adapter->ccw_device->dev,
990 "ERP failed for unit 0x%016Lx on "
991 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +0200992 (unsigned long long)unit->fcp_lun,
993 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100994 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200995 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200996 break;
997 }
998
999 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1000 zfcp_erp_unit_block(unit, 0);
1001 result = ZFCP_ERP_EXIT;
1002 }
1003 return result;
1004}
1005
1006static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1007{
1008 switch (result) {
1009 case ZFCP_ERP_SUCCEEDED :
1010 atomic_set(&port->erp_counter, 0);
1011 zfcp_erp_port_unblock(port);
1012 break;
1013
1014 case ZFCP_ERP_FAILED :
1015 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1016 zfcp_erp_port_block(port, 0);
1017 result = ZFCP_ERP_EXIT;
1018 }
1019 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001020 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1021 dev_err(&port->adapter->ccw_device->dev,
1022 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001023 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001024 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001025 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001026 break;
1027 }
1028
1029 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1030 zfcp_erp_port_block(port, 0);
1031 result = ZFCP_ERP_EXIT;
1032 }
1033 return result;
1034}
1035
1036static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1037 int result)
1038{
1039 switch (result) {
1040 case ZFCP_ERP_SUCCEEDED :
1041 atomic_set(&adapter->erp_counter, 0);
1042 zfcp_erp_adapter_unblock(adapter);
1043 break;
1044
1045 case ZFCP_ERP_FAILED :
1046 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001047 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1048 dev_err(&adapter->ccw_device->dev,
1049 "ERP cannot recover an error "
1050 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001051 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001052 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001053 break;
1054 }
1055
1056 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1057 zfcp_erp_adapter_block(adapter, 0);
1058 result = ZFCP_ERP_EXIT;
1059 }
1060 return result;
1061}
1062
1063static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1064 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065{
1066 struct zfcp_adapter *adapter = erp_action->adapter;
1067 struct zfcp_port *port = erp_action->port;
1068 struct zfcp_unit *unit = erp_action->unit;
1069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 switch (erp_action->action) {
1071
1072 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1073 result = zfcp_erp_strategy_check_unit(unit, result);
1074 break;
1075
1076 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1077 case ZFCP_ERP_ACTION_REOPEN_PORT:
1078 result = zfcp_erp_strategy_check_port(port, result);
1079 break;
1080
1081 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1082 result = zfcp_erp_strategy_check_adapter(adapter, result);
1083 break;
1084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return result;
1086}
1087
Christof Schmitt287ac012008-07-02 10:56:40 +02001088static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089{
Christof Schmitt287ac012008-07-02 10:56:40 +02001090 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Christof Schmitt287ac012008-07-02 10:56:40 +02001092 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1093 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1094 return 1; /* take it online */
1095
1096 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1097 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1098 return 1; /* take it offline */
1099
1100 return 0;
1101}
1102
1103static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1104{
1105 int action = act->action;
1106 struct zfcp_adapter *adapter = act->adapter;
1107 struct zfcp_port *port = act->port;
1108 struct zfcp_unit *unit = act->unit;
1109 u32 erp_status = act->status;
1110
1111 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001113 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1114 _zfcp_erp_adapter_reopen(adapter,
1115 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001116 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001117 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
1119 break;
1120
1121 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1122 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001123 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1124 _zfcp_erp_port_reopen(port,
1125 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001126 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001127 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
1129 break;
1130
1131 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001132 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1133 _zfcp_erp_unit_reopen(unit,
1134 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001135 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001136 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 }
1138 break;
1139 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001140 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Christof Schmitt287ac012008-07-02 10:56:40 +02001143static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144{
Christof Schmitt287ac012008-07-02 10:56:40 +02001145 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Christof Schmitt287ac012008-07-02 10:56:40 +02001147 adapter->erp_total_count--;
1148 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1149 adapter->erp_low_mem_count--;
1150 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 }
1152
Christof Schmitt287ac012008-07-02 10:56:40 +02001153 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001154 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Christof Schmitt287ac012008-07-02 10:56:40 +02001156 switch (erp_action->action) {
1157 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1158 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1159 &erp_action->unit->status);
1160 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
Christof Schmitt287ac012008-07-02 10:56:40 +02001162 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1163 case ZFCP_ERP_ACTION_REOPEN_PORT:
1164 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1165 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001167
1168 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1169 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1170 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 break;
1172 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Christof Schmitt287ac012008-07-02 10:56:40 +02001175static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001176{
Christof Schmitt287ac012008-07-02 10:56:40 +02001177 struct zfcp_adapter *adapter = act->adapter;
1178 struct zfcp_port *port = act->port;
1179 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001180
Christof Schmitt287ac012008-07-02 10:56:40 +02001181 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001183 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Christof Schmitt615f59e2010-02-17 11:18:56 +01001184 get_device(&unit->dev);
Swen Schillig92d51932009-04-17 15:08:04 +02001185 if (scsi_queue_work(unit->port->adapter->scsi_host,
1186 &unit->scsi_work) <= 0)
Christof Schmitt615f59e2010-02-17 11:18:56 +01001187 put_device(&unit->dev);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001188 }
Christof Schmitt615f59e2010-02-17 11:18:56 +01001189 put_device(&unit->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1193 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001194 if (result == ZFCP_ERP_SUCCEEDED)
1195 zfcp_scsi_schedule_rport_register(port);
Christof Schmitt615f59e2010-02-17 11:18:56 +01001196 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001200 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001201 register_service_level(&adapter->service_level);
Swen Schillig9eae07e2009-11-24 16:54:06 +01001202 queue_work(adapter->work_queue, &adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001203 } else
1204 unregister_service_level(&adapter->service_level);
Swen Schilligf3450c72009-11-24 16:53:59 +01001205 kref_put(&adapter->ref, zfcp_adapter_release);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208}
1209
Christof Schmitt287ac012008-07-02 10:56:40 +02001210static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1211{
1212 switch (erp_action->action) {
1213 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1214 return zfcp_erp_adapter_strategy(erp_action);
1215 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1216 return zfcp_erp_port_forced_strategy(erp_action);
1217 case ZFCP_ERP_ACTION_REOPEN_PORT:
1218 return zfcp_erp_port_strategy(erp_action);
1219 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1220 return zfcp_erp_unit_strategy(erp_action);
1221 }
1222 return ZFCP_ERP_FAILED;
1223}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Christof Schmitt287ac012008-07-02 10:56:40 +02001225static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1226{
1227 int retval;
Christof Schmitt287ac012008-07-02 10:56:40 +02001228 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001229 struct zfcp_adapter *adapter = erp_action->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +02001230
Swen Schilligf3450c72009-11-24 16:53:59 +01001231 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001232
Swen Schilligf3450c72009-11-24 16:53:59 +01001233 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001234 zfcp_erp_strategy_check_fsfreq(erp_action);
1235
1236 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1237 zfcp_erp_action_dequeue(erp_action);
1238 retval = ZFCP_ERP_DISMISSED;
1239 goto unlock;
1240 }
1241
1242 zfcp_erp_action_to_running(erp_action);
1243
1244 /* no lock to allow for blocking operations */
Swen Schilligecf0c772009-11-24 16:53:58 +01001245 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001246 retval = zfcp_erp_strategy_do_action(erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +01001247 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001248
1249 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1250 retval = ZFCP_ERP_CONTINUES;
1251
1252 switch (retval) {
1253 case ZFCP_ERP_NOMEM:
1254 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1255 ++adapter->erp_low_mem_count;
1256 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1257 }
1258 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001259 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001260 else {
1261 zfcp_erp_strategy_memwait(erp_action);
1262 retval = ZFCP_ERP_CONTINUES;
1263 }
1264 goto unlock;
1265
1266 case ZFCP_ERP_CONTINUES:
1267 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1268 --adapter->erp_low_mem_count;
1269 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1270 }
1271 goto unlock;
1272 }
1273
1274 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1275 zfcp_erp_action_dequeue(erp_action);
1276 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1277 if (retval == ZFCP_ERP_EXIT)
1278 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001279 if (retval == ZFCP_ERP_SUCCEEDED)
1280 zfcp_erp_strategy_followup_success(erp_action);
1281 if (retval == ZFCP_ERP_FAILED)
1282 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001283
1284 unlock:
Swen Schilligecf0c772009-11-24 16:53:58 +01001285 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001286
1287 if (retval != ZFCP_ERP_CONTINUES)
1288 zfcp_erp_action_cleanup(erp_action, retval);
1289
Swen Schilligf3450c72009-11-24 16:53:59 +01001290 kref_put(&adapter->ref, zfcp_adapter_release);
Christof Schmitt287ac012008-07-02 10:56:40 +02001291 return retval;
1292}
1293
1294static int zfcp_erp_thread(void *data)
1295{
1296 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1297 struct list_head *next;
1298 struct zfcp_erp_action *act;
1299 unsigned long flags;
1300
Christof Schmitt347c6a92009-08-18 15:43:25 +02001301 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001302 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001303 wait_event_interruptible(adapter->erp_ready_wq,
1304 !list_empty(&adapter->erp_ready_head) ||
1305 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001306 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001307
Christof Schmitt347c6a92009-08-18 15:43:25 +02001308 if (kthread_should_stop())
1309 break;
1310
Christof Schmitt287ac012008-07-02 10:56:40 +02001311 write_lock_irqsave(&adapter->erp_lock, flags);
1312 next = adapter->erp_ready_head.next;
1313 write_unlock_irqrestore(&adapter->erp_lock, flags);
1314
1315 if (next != &adapter->erp_ready_head) {
1316 act = list_entry(next, struct zfcp_erp_action, list);
1317
1318 /* there is more to come after dismission, no notify */
1319 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1320 zfcp_erp_wakeup(adapter);
1321 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001322 }
1323
Christof Schmitt287ac012008-07-02 10:56:40 +02001324 return 0;
1325}
1326
1327/**
1328 * zfcp_erp_thread_setup - Start ERP thread for adapter
1329 * @adapter: Adapter to start the ERP thread for
1330 *
1331 * Returns 0 on success or error code from kernel_thread()
1332 */
1333int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1334{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001335 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001336
Christof Schmitt347c6a92009-08-18 15:43:25 +02001337 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1338 dev_name(&adapter->ccw_device->dev));
1339 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001340 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001341 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001342 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001343 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001344
1345 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001346 return 0;
1347}
1348
1349/**
1350 * zfcp_erp_thread_kill - Stop ERP thread.
1351 * @adapter: Adapter where the ERP thread should be stopped.
1352 *
1353 * The caller of this routine ensures that the specified adapter has
1354 * been shut down and that this operation has been completed. Thus,
1355 * there are no pending erp_actions which would need to be handled
1356 * here.
1357 */
1358void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1359{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001360 kthread_stop(adapter->erp_thread);
1361 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001362 WARN_ON(!list_empty(&adapter->erp_ready_head));
1363 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001364}
1365
1366/**
1367 * zfcp_erp_adapter_failed - Set adapter status to failed.
1368 * @adapter: Failed adapter.
1369 * @id: Event id for debug trace.
1370 * @ref: Reference for debug trace.
1371 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001372void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001373{
1374 zfcp_erp_modify_adapter_status(adapter, id, ref,
1375 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001376}
1377
1378/**
1379 * zfcp_erp_port_failed - Set port status to failed.
1380 * @port: Failed port.
1381 * @id: Event id for debug trace.
1382 * @ref: Reference for debug trace.
1383 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001384void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001385{
1386 zfcp_erp_modify_port_status(port, id, ref,
1387 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001388}
1389
1390/**
1391 * zfcp_erp_unit_failed - Set unit status to failed.
1392 * @unit: Failed unit.
1393 * @id: Event id for debug trace.
1394 * @ref: Reference for debug trace.
1395 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001396void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001397{
1398 zfcp_erp_modify_unit_status(unit, id, ref,
1399 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001400}
1401
1402/**
1403 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1404 * @adapter: adapter for which to wait for completion of its error recovery
1405 */
1406void zfcp_erp_wait(struct zfcp_adapter *adapter)
1407{
1408 wait_event(adapter->erp_done_wqh,
1409 !(atomic_read(&adapter->status) &
1410 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1411}
1412
1413/**
1414 * zfcp_erp_modify_adapter_status - change adapter status bits
1415 * @adapter: adapter to change the status
1416 * @id: id for the debug trace
1417 * @ref: reference for the debug trace
1418 * @mask: status bits to change
1419 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1420 *
1421 * Changes in common status bits are propagated to attached ports and units.
1422 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001423void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001424 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 struct zfcp_port *port;
Swen Schilligecf0c772009-11-24 16:53:58 +01001427 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001428 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Christof Schmitt287ac012008-07-02 10:56:40 +02001430 if (set_or_clear == ZFCP_SET) {
1431 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001432 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001433 atomic_set_mask(mask, &adapter->status);
1434 } else {
1435 if (status_change_clear(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001436 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001437 atomic_clear_mask(mask, &adapter->status);
1438 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1439 atomic_set(&adapter->erp_counter, 0);
1440 }
1441
Swen Schilligecf0c772009-11-24 16:53:58 +01001442 if (common_mask) {
1443 read_lock_irqsave(&adapter->port_list_lock, flags);
1444 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001445 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1446 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001447 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}
1450
Christof Schmitt287ac012008-07-02 10:56:40 +02001451/**
1452 * zfcp_erp_modify_port_status - change port status bits
1453 * @port: port to change the status bits
1454 * @id: id for the debug trace
1455 * @ref: reference for the debug trace
1456 * @mask: status bits to change
1457 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1458 *
1459 * Changes in common status bits are propagated to attached units.
1460 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001461void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001462 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001465 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001466 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Christof Schmitt287ac012008-07-02 10:56:40 +02001468 if (set_or_clear == ZFCP_SET) {
1469 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001470 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001471 atomic_set_mask(mask, &port->status);
1472 } else {
1473 if (status_change_clear(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001474 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001475 atomic_clear_mask(mask, &port->status);
1476 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1477 atomic_set(&port->erp_counter, 0);
1478 }
1479
Swen Schilligecf0c772009-11-24 16:53:58 +01001480 if (common_mask) {
1481 read_lock_irqsave(&port->unit_list_lock, flags);
1482 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001483 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1484 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001485 read_unlock_irqrestore(&port->unit_list_lock, flags);
1486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487}
1488
Christof Schmitt287ac012008-07-02 10:56:40 +02001489/**
1490 * zfcp_erp_modify_unit_status - change unit status bits
1491 * @unit: unit to change the status bits
1492 * @id: id for the debug trace
1493 * @ref: reference for the debug trace
1494 * @mask: status bits to change
1495 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1496 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001497void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001498 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Christof Schmitt287ac012008-07-02 10:56:40 +02001500 if (set_or_clear == ZFCP_SET) {
1501 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001502 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001503 atomic_set_mask(mask, &unit->status);
1504 } else {
1505 if (status_change_clear(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001506 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001507 atomic_clear_mask(mask, &unit->status);
1508 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1509 atomic_set(&unit->erp_counter, 0);
1510 }
1511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512}
1513
Christof Schmitt287ac012008-07-02 10:56:40 +02001514/**
1515 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1516 * @port: The "boxed" port.
1517 * @id: The debug trace id.
1518 * @id: Reference for the debug trace.
1519 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001520void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001521{
Martin Peschke698ec0162008-03-27 14:22:02 +01001522 zfcp_erp_modify_port_status(port, id, ref,
1523 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001524 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001525}
1526
Christof Schmitt287ac012008-07-02 10:56:40 +02001527/**
1528 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1529 * @port: The "boxed" unit.
1530 * @id: The debug trace id.
1531 * @id: Reference for the debug trace.
1532 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001533void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001534{
Martin Peschke698ec0162008-03-27 14:22:02 +01001535 zfcp_erp_modify_unit_status(unit, id, ref,
1536 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001537 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001538}
1539
Christof Schmitt287ac012008-07-02 10:56:40 +02001540/**
1541 * zfcp_erp_port_access_denied - Adapter denied access to port.
1542 * @port: port where access has been denied
1543 * @id: id for debug trace
1544 * @ref: reference for debug trace
1545 *
1546 * Since the adapter has denied access, stop using the port and the
1547 * attached units.
1548 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001549void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Martin Peschke698ec0162008-03-27 14:22:02 +01001551 zfcp_erp_modify_port_status(port, id, ref,
1552 ZFCP_STATUS_COMMON_ERP_FAILED |
1553 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Christof Schmitt287ac012008-07-02 10:56:40 +02001556/**
1557 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1558 * @unit: unit where access has been denied
1559 * @id: id for debug trace
1560 * @ref: reference for debug trace
1561 *
1562 * Since the adapter has denied access, stop using the unit.
1563 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001564void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565{
Martin Peschke698ec0162008-03-27 14:22:02 +01001566 zfcp_erp_modify_unit_status(unit, id, ref,
1567 ZFCP_STATUS_COMMON_ERP_FAILED |
1568 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569}
1570
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001571static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001572 void *ref)
1573{
1574 int status = atomic_read(&unit->status);
1575 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1576 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1577 return;
1578
1579 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1580}
1581
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001582static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001583 void *ref)
1584{
1585 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001586 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001587 int status = atomic_read(&port->status);
1588
1589 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1590 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schilligecf0c772009-11-24 16:53:58 +01001591 read_lock_irqsave(&port->unit_list_lock, flags);
1592 list_for_each_entry(unit, &port->unit_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001593 zfcp_erp_unit_access_changed(unit, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001594 read_unlock_irqrestore(&port->unit_list_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001595 return;
1596 }
1597
1598 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1599}
1600
1601/**
1602 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1603 * @adapter: Adapter where the Access Control Table (ACT) changed
1604 * @id: Id for debug trace
1605 * @ref: Reference for debug trace
1606 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001607void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001608 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001611 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001613 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1614 return;
1615
Swen Schilligecf0c772009-11-24 16:53:58 +01001616 read_lock_irqsave(&adapter->port_list_lock, flags);
1617 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001618 zfcp_erp_port_access_changed(port, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001619 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}