blob: 3454c2a3b6b13cf5acd75a4a571faa04a2e20cee [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
Christof Schmitt347c6a92009-08-18 15:43:25 +020012#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "zfcp_ext.h"
14
Christof Schmitt287ac012008-07-02 10:56:40 +020015#define ZFCP_MAX_ERPS 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Christof Schmitt287ac012008-07-02 10:56:40 +020017enum zfcp_erp_act_flags {
18 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
19 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
20 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
21 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
22 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
23};
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Christof Schmitt287ac012008-07-02 10:56:40 +020025enum zfcp_erp_steps {
26 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
27 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
28 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
29 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
Christof Schmitt287ac012008-07-02 10:56:40 +020030 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 Schillig57717102009-08-18 15:43:21 +020078 zfcp_dbf_rec_action("erardy1", act);
Christof Schmitt347c6a92009-08-18 15:43:25 +020079 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +020080 zfcp_dbf_rec_thread("erardy2", adapter->dbf);
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);
Swen Schilligecf0c772009-11-24 16:53:58 +0100102 else {
103 read_lock(&port->unit_list_lock);
104 list_for_each_entry(unit, &port->unit_list, list)
105 zfcp_erp_action_dismiss_unit(unit);
106 read_unlock(&port->unit_list_lock);
107 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200108}
109
110static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
111{
112 struct zfcp_port *port;
113
114 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
115 zfcp_erp_action_dismiss(&adapter->erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +0100116 else {
117 read_lock(&adapter->port_list_lock);
118 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200119 zfcp_erp_action_dismiss_port(port);
Swen Schilligecf0c772009-11-24 16:53:58 +0100120 read_unlock(&adapter->port_list_lock);
121 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200122}
123
124static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
125 struct zfcp_port *port,
126 struct zfcp_unit *unit)
127{
128 int need = want;
129 int u_status, p_status, a_status;
130
131 switch (want) {
132 case ZFCP_ERP_ACTION_REOPEN_UNIT:
133 u_status = atomic_read(&unit->status);
134 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
135 return 0;
136 p_status = atomic_read(&port->status);
137 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
138 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
139 return 0;
140 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
141 need = ZFCP_ERP_ACTION_REOPEN_PORT;
142 /* fall through */
143 case ZFCP_ERP_ACTION_REOPEN_PORT:
144 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
145 p_status = atomic_read(&port->status);
146 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
147 return 0;
148 a_status = atomic_read(&adapter->status);
149 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
150 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
151 return 0;
152 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
153 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
154 /* fall through */
155 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
156 a_status = atomic_read(&adapter->status);
157 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
158 return 0;
Christof Schmitt143bb6b2009-08-18 15:43:27 +0200159 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) &&
160 !(a_status & ZFCP_STATUS_COMMON_OPEN))
161 return 0; /* shutdown requested for closed adapter */
Christof Schmitt287ac012008-07-02 10:56:40 +0200162 }
163
164 return need;
165}
166
167static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
168 struct zfcp_adapter *adapter,
169 struct zfcp_port *port,
170 struct zfcp_unit *unit)
171{
172 struct zfcp_erp_action *erp_action;
173 u32 status = 0;
174
175 switch (need) {
176 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Swen Schillig6b183332009-11-24 16:54:05 +0100177 if (!get_device(&unit->sysfs_device))
178 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200179 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
180 erp_action = &unit->erp_action;
181 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
182 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
183 break;
184
185 case ZFCP_ERP_ACTION_REOPEN_PORT:
186 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Swen Schillig6b183332009-11-24 16:54:05 +0100187 if (!get_device(&port->sysfs_device))
188 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200189 zfcp_erp_action_dismiss_port(port);
190 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
191 erp_action = &port->erp_action;
192 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
193 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
194 break;
195
196 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Swen Schilligf3450c72009-11-24 16:53:59 +0100197 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200198 zfcp_erp_action_dismiss_adapter(adapter);
199 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
200 erp_action = &adapter->erp_action;
201 if (!(atomic_read(&adapter->status) &
202 ZFCP_STATUS_COMMON_RUNNING))
203 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
204 break;
205
206 default:
207 return NULL;
208 }
209
210 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
211 erp_action->adapter = adapter;
212 erp_action->port = port;
213 erp_action->unit = unit;
214 erp_action->action = need;
215 erp_action->status = status;
216
217 return erp_action;
218}
219
220static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
221 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100222 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200223{
224 int retval = 1, need;
225 struct zfcp_erp_action *act = NULL;
226
Christof Schmitt347c6a92009-08-18 15:43:25 +0200227 if (!adapter->erp_thread)
Christof Schmitt287ac012008-07-02 10:56:40 +0200228 return -EIO;
229
230 need = zfcp_erp_required_act(want, adapter, port, unit);
231 if (!need)
232 goto out;
233
234 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
235 act = zfcp_erp_setup_act(need, adapter, port, unit);
236 if (!act)
237 goto out;
238 ++adapter->erp_total_count;
239 list_add_tail(&act->list, &adapter->erp_ready_head);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200240 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +0200241 zfcp_dbf_rec_thread("eracte1", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200242 retval = 0;
243 out:
Swen Schillig57717102009-08-18 15:43:21 +0200244 zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200245 return retval;
246}
247
248static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100249 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200250{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100252 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Christof Schmitt287ac012008-07-02 10:56:40 +0200254 /* ensure propagation of failed status to new devices */
255 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100256 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200257 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200259 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
260 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
263/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200264 * zfcp_erp_adapter_reopen - Reopen adapter.
265 * @adapter: Adapter to reopen.
266 * @clear: Status flags to clear.
267 * @id: Id for debug trace event.
268 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200270void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100271 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Christof Schmitt287ac012008-07-02 10:56:40 +0200273 unsigned long flags;
274
Swen Schilligecf0c772009-11-24 16:53:58 +0100275 zfcp_erp_adapter_block(adapter, clear);
276 zfcp_scsi_schedule_rports_block(adapter);
277
278 write_lock_irqsave(&adapter->erp_lock, flags);
279 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
280 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
281 else
282 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
283 NULL, NULL, id, ref);
284 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200285}
286
287/**
288 * zfcp_erp_adapter_shutdown - Shutdown adapter.
289 * @adapter: Adapter to shut down.
290 * @clear: Status flags to clear.
291 * @id: Id for debug trace event.
292 * @ref: Reference for debug trace event.
293 */
294void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100295 char *id, 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_adapter_reopen(adapter, clear | flags, id, ref);
299}
300
301/**
302 * zfcp_erp_port_shutdown - Shutdown port
303 * @port: Port 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_port_shutdown(struct zfcp_port *port, 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_port_reopen(port, clear | flags, id, ref);
313}
314
315/**
316 * zfcp_erp_unit_shutdown - Shutdown unit
317 * @unit: Unit to shut down.
318 * @clear: Status flags to clear.
319 * @id: Id for debug trace event.
320 * @ref: Reference for debug trace event.
321 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100322void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
323 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200324{
325 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
326 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
327}
328
329static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
330{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100331 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200332 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
333 ZFCP_CLEAR);
334}
335
336static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100337 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200338{
339 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100340 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200341
342 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
343 return;
344
345 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
346 port->adapter, port, NULL, id, ref);
347}
348
349/**
350 * zfcp_erp_port_forced_reopen - Forced close of port and open again
351 * @port: Port to force close and to reopen.
352 * @id: Id for debug trace event.
353 * @ref: Reference for debug trace event.
354 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100355void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200356 void *ref)
357{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 unsigned long flags;
359 struct zfcp_adapter *adapter = port->adapter;
360
Swen Schilligecf0c772009-11-24 16:53:58 +0100361 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200362 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100363 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200364}
365
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100366static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200367 void *ref)
368{
369 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100370 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200371
372 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
373 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100374 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200375 return -EIO;
376 }
377
378 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
379 port->adapter, port, NULL, id, ref);
380}
381
382/**
383 * zfcp_erp_port_reopen - trigger remote port recovery
384 * @port: port to recover
385 * @clear_mask: flags in port status to be cleared
386 *
387 * Returns 0 if recovery has been triggered, < 0 if not.
388 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100389int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200390{
Christof Schmitt287ac012008-07-02 10:56:40 +0200391 int retval;
Swen Schilligecf0c772009-11-24 16:53:58 +0100392 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200393 struct zfcp_adapter *adapter = port->adapter;
394
Swen Schilligecf0c772009-11-24 16:53:58 +0100395 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200396 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100397 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 return retval;
400}
401
Christof Schmitt287ac012008-07-02 10:56:40 +0200402static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100404 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200405 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
406 ZFCP_CLEAR);
407}
408
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100409static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200410 void *ref)
411{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 struct zfcp_adapter *adapter = unit->port->adapter;
413
Christof Schmitt287ac012008-07-02 10:56:40 +0200414 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Christof Schmitt287ac012008-07-02 10:56:40 +0200416 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
417 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Christof Schmitt287ac012008-07-02 10:56:40 +0200419 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
420 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
423/**
424 * zfcp_erp_unit_reopen - initiate reopen of a unit
425 * @unit: unit to be reopened
426 * @clear_mask: specifies flags in unit status to be cleared
427 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100429void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
430 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200433 struct zfcp_port *port = unit->port;
434 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Swen Schilligecf0c772009-11-24 16:53:58 +0100436 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200437 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100438 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
Christof Schmitt287ac012008-07-02 10:56:40 +0200441static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Christof Schmitt287ac012008-07-02 10:56:40 +0200443 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
Christof Schmitt287ac012008-07-02 10:56:40 +0200446static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100447{
Christof Schmitt287ac012008-07-02 10:56:40 +0200448 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100449}
450
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200451static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Christof Schmitt287ac012008-07-02 10:56:40 +0200453 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +0200454 zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200455 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
Christof Schmitt287ac012008-07-02 10:56:40 +0200458static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Christof Schmitt287ac012008-07-02 10:56:40 +0200460 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +0200461 zfcp_dbf_rec_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200462 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
Christof Schmitt287ac012008-07-02 10:56:40 +0200465static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Christof Schmitt287ac012008-07-02 10:56:40 +0200467 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +0200468 zfcp_dbf_rec_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200469 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Christof Schmitt287ac012008-07-02 10:56:40 +0200472static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Christof Schmitt287ac012008-07-02 10:56:40 +0200474 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig57717102009-08-18 15:43:21 +0200475 zfcp_dbf_rec_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476}
477
Christof Schmitt287ac012008-07-02 10:56:40 +0200478static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Christof Schmitt287ac012008-07-02 10:56:40 +0200480 struct zfcp_adapter *adapter = act->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Christof Schmitt287ac012008-07-02 10:56:40 +0200482 if (!act->fsf_req)
483 return;
484
485 spin_lock(&adapter->req_list_lock);
486 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
487 act->fsf_req->erp_action == act) {
488 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
489 ZFCP_STATUS_ERP_TIMEDOUT)) {
490 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig57717102009-08-18 15:43:21 +0200491 zfcp_dbf_rec_action("erscf_1", act);
Martin Petermann7ea633f2008-11-04 16:35:11 +0100492 act->fsf_req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200494 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig57717102009-08-18 15:43:21 +0200495 zfcp_dbf_rec_action("erscf_2", act);
Swen Schillig058b8642009-08-18 15:43:14 +0200496 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
Christof Schmitt287ac012008-07-02 10:56:40 +0200497 act->fsf_req = NULL;
498 } else
499 act->fsf_req = NULL;
500 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200503/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200504 * zfcp_erp_notify - Trigger ERP action.
505 * @erp_action: ERP action to continue.
506 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200508void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
510 struct zfcp_adapter *adapter = erp_action->adapter;
511 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200514 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
515 erp_action->status |= set_mask;
516 zfcp_erp_action_ready(erp_action);
517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200521/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200522 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
523 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200525void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Christof Schmitt287ac012008-07-02 10:56:40 +0200527 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
528 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529}
530
Christof Schmitt287ac012008-07-02 10:56:40 +0200531static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Christof Schmitt287ac012008-07-02 10:56:40 +0200533 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
535
Christof Schmitt287ac012008-07-02 10:56:40 +0200536static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 init_timer(&erp_action->timer);
539 erp_action->timer.function = zfcp_erp_memwait_handler;
540 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200541 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200543}
544
545static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100546 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200547{
548 struct zfcp_port *port;
549
Swen Schilligecf0c772009-11-24 16:53:58 +0100550 read_lock(&adapter->port_list_lock);
551 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200552 _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100553 read_unlock(&adapter->port_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200554}
555
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100556static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
557 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200558{
559 struct zfcp_unit *unit;
560
Swen Schilligecf0c772009-11-24 16:53:58 +0100561 read_lock(&port->unit_list_lock);
562 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200563 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100564 read_unlock(&port->unit_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200565}
566
Christof Schmitt85600f72009-07-13 15:06:09 +0200567static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200568{
Christof Schmitt287ac012008-07-02 10:56:40 +0200569 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200570 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200571 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200572 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200573 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200574 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200575 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200576 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200577 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200578 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200579 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200580 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
581 break;
582 }
583}
584
585static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
586{
587 switch (act->action) {
588 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
589 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
590 break;
591 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
592 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
593 break;
594 case ZFCP_ERP_ACTION_REOPEN_PORT:
595 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200596 break;
597 }
598}
599
600static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
601{
602 unsigned long flags;
603
Swen Schilligecf0c772009-11-24 16:53:58 +0100604 read_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200605 if (list_empty(&adapter->erp_ready_head) &&
606 list_empty(&adapter->erp_running_head)) {
607 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
608 &adapter->status);
609 wake_up(&adapter->erp_done_wqh);
610 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100611 read_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200612}
613
614static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
615{
Swen Schillig564e1c82009-08-18 15:43:19 +0200616 struct zfcp_qdio *qdio = act->adapter->qdio;
617
618 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200619 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200620 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200621 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
622 return ZFCP_ERP_SUCCEEDED;
623}
624
625static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
626{
627 struct zfcp_port *port;
628 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
629 adapter->peer_d_id);
630 if (IS_ERR(port)) /* error or port already attached */
631 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100632 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200633}
634
635static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
636{
637 int retries;
638 int sleep = 1;
639 struct zfcp_adapter *adapter = erp_action->adapter;
640
641 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
642
643 for (retries = 7; retries; retries--) {
644 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
645 &adapter->status);
646 write_lock_irq(&adapter->erp_lock);
647 zfcp_erp_action_to_running(erp_action);
648 write_unlock_irq(&adapter->erp_lock);
649 if (zfcp_fsf_exchange_config_data(erp_action)) {
650 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
651 &adapter->status);
652 return ZFCP_ERP_FAILED;
653 }
654
Swen Schillig57717102009-08-18 15:43:21 +0200655 zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200656 wait_event(adapter->erp_ready_wq,
657 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200658 zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200659 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
660 break;
661
662 if (!(atomic_read(&adapter->status) &
663 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
664 break;
665
666 ssleep(sleep);
667 sleep *= 2;
668 }
669
670 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
671 &adapter->status);
672
673 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
674 return ZFCP_ERP_FAILED;
675
676 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
677 zfcp_erp_enqueue_ptp_port(adapter);
678
679 return ZFCP_ERP_SUCCEEDED;
680}
681
682static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
683{
684 int ret;
685 struct zfcp_adapter *adapter = act->adapter;
686
Christof Schmitt287ac012008-07-02 10:56:40 +0200687 write_lock_irq(&adapter->erp_lock);
688 zfcp_erp_action_to_running(act);
689 write_unlock_irq(&adapter->erp_lock);
690
691 ret = zfcp_fsf_exchange_port_data(act);
692 if (ret == -EOPNOTSUPP)
693 return ZFCP_ERP_SUCCEEDED;
694 if (ret)
695 return ZFCP_ERP_FAILED;
696
Swen Schillig57717102009-08-18 15:43:21 +0200697 zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200698 wait_event(adapter->erp_ready_wq,
699 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200700 zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200701 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
702 return ZFCP_ERP_FAILED;
703
704 return ZFCP_ERP_SUCCEEDED;
705}
706
707static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
708{
709 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
710 return ZFCP_ERP_FAILED;
711
712 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
713 return ZFCP_ERP_FAILED;
714
715 atomic_set(&act->adapter->stat_miss, 16);
716 if (zfcp_status_read_refill(act->adapter))
717 return ZFCP_ERP_FAILED;
718
719 return ZFCP_ERP_SUCCEEDED;
720}
721
Swen Schilligcf13c082009-03-02 13:09:03 +0100722static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200723{
Christof Schmitt287ac012008-07-02 10:56:40 +0200724 struct zfcp_adapter *adapter = act->adapter;
725
Christof Schmitt287ac012008-07-02 10:56:40 +0200726 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200727 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200728 zfcp_fsf_req_dismiss_all(adapter);
729 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200730 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200731 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100732 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200733 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100734
Christof Schmitt287ac012008-07-02 10:56:40 +0200735 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100736 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
737}
738
739static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
740{
741 struct zfcp_adapter *adapter = act->adapter;
742
743 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
744 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
745 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
746 &adapter->status);
747 return ZFCP_ERP_FAILED;
748 }
749
750 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
751 zfcp_erp_adapter_strategy_close(act);
752 return ZFCP_ERP_FAILED;
753 }
754
755 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
756
757 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200758}
759
760static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
761{
Swen Schilligcf13c082009-03-02 13:09:03 +0100762 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200763
Swen Schilligcf13c082009-03-02 13:09:03 +0100764 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
765 zfcp_erp_adapter_strategy_close(act);
766 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
767 return ZFCP_ERP_EXIT;
768 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200769
Swen Schilligcf13c082009-03-02 13:09:03 +0100770 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200771 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100772 return ZFCP_ERP_FAILED;
773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Swen Schilligcf13c082009-03-02 13:09:03 +0100775 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
Christof Schmitt287ac012008-07-02 10:56:40 +0200778static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Christof Schmitt287ac012008-07-02 10:56:40 +0200780 int retval;
781
782 retval = zfcp_fsf_close_physical_port(act);
783 if (retval == -ENOMEM)
784 return ZFCP_ERP_NOMEM;
785 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
786 if (retval)
787 return ZFCP_ERP_FAILED;
788
789 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
Christof Schmitt287ac012008-07-02 10:56:40 +0200792static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100794 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200795}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Christof Schmitt287ac012008-07-02 10:56:40 +0200797static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
798{
799 struct zfcp_port *port = erp_action->port;
800 int status = atomic_read(&port->status);
801
802 switch (erp_action->step) {
803 case ZFCP_ERP_STEP_UNINITIALIZED:
804 zfcp_erp_port_strategy_clearstati(port);
805 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
806 (status & ZFCP_STATUS_COMMON_OPEN))
807 return zfcp_erp_port_forced_strategy_close(erp_action);
808 else
809 return ZFCP_ERP_FAILED;
810
811 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200812 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200813 return ZFCP_ERP_SUCCEEDED;
814 }
815 return ZFCP_ERP_FAILED;
816}
817
818static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
819{
820 int retval;
821
822 retval = zfcp_fsf_close_port(erp_action);
823 if (retval == -ENOMEM)
824 return ZFCP_ERP_NOMEM;
825 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
826 if (retval)
827 return ZFCP_ERP_FAILED;
828 return ZFCP_ERP_CONTINUES;
829}
830
831static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
832{
833 int retval;
834
835 retval = zfcp_fsf_open_port(erp_action);
836 if (retval == -ENOMEM)
837 return ZFCP_ERP_NOMEM;
838 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
839 if (retval)
840 return ZFCP_ERP_FAILED;
841 return ZFCP_ERP_CONTINUES;
842}
843
Christof Schmitt287ac012008-07-02 10:56:40 +0200844static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
845{
846 struct zfcp_adapter *adapter = act->adapter;
847 struct zfcp_port *port = act->port;
848
849 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100850 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200851 return ZFCP_ERP_FAILED;
852 }
853 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200854 return zfcp_erp_port_strategy_open_port(act);
855}
856
857static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
858{
859 struct zfcp_adapter *adapter = act->adapter;
860 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200861 int p_status = atomic_read(&port->status);
862
863 switch (act->step) {
864 case ZFCP_ERP_STEP_UNINITIALIZED:
865 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
866 case ZFCP_ERP_STEP_PORT_CLOSING:
867 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
868 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100869 if (!port->d_id) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200870 zfcp_fc_trigger_did_lookup(port);
Christof Schmitt799b76d2009-08-18 15:43:20 +0200871 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200872 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200873 return zfcp_erp_port_strategy_open_port(act);
874
875 case ZFCP_ERP_STEP_PORT_OPENING:
876 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200877 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200878 if (!port->d_id) {
879 zfcp_fc_trigger_did_lookup(port);
880 return ZFCP_ERP_EXIT;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200881 }
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200882 return ZFCP_ERP_SUCCEEDED;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200883 }
Swen Schilligea460a82009-05-15 13:18:20 +0200884 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
885 port->d_id = 0;
886 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
887 return ZFCP_ERP_EXIT;
888 }
889 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200890 }
891 return ZFCP_ERP_FAILED;
892}
893
Christof Schmitt287ac012008-07-02 10:56:40 +0200894static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
895{
896 struct zfcp_port *port = erp_action->port;
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200897 int p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200898
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200899 if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
900 !(p_status & ZFCP_STATUS_COMMON_OPEN))
Swen Schillig5ab944f2008-10-01 12:42:17 +0200901 goto close_init_done;
902
Christof Schmitt287ac012008-07-02 10:56:40 +0200903 switch (erp_action->step) {
904 case ZFCP_ERP_STEP_UNINITIALIZED:
905 zfcp_erp_port_strategy_clearstati(port);
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200906 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200907 return zfcp_erp_port_strategy_close(erp_action);
908 break;
909
910 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200911 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200912 return ZFCP_ERP_FAILED;
913 break;
914 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200915
916close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200917 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
918 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200919
Swen Schillig5ab944f2008-10-01 12:42:17 +0200920 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922
Christof Schmitt287ac012008-07-02 10:56:40 +0200923static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200925 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200926 ZFCP_STATUS_UNIT_SHARED |
927 ZFCP_STATUS_UNIT_READONLY,
928 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Christof Schmitt287ac012008-07-02 10:56:40 +0200931static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
932{
933 int retval = zfcp_fsf_close_unit(erp_action);
934 if (retval == -ENOMEM)
935 return ZFCP_ERP_NOMEM;
936 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
937 if (retval)
938 return ZFCP_ERP_FAILED;
939 return ZFCP_ERP_CONTINUES;
940}
941
942static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
943{
944 int retval = zfcp_fsf_open_unit(erp_action);
945 if (retval == -ENOMEM)
946 return ZFCP_ERP_NOMEM;
947 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
948 if (retval)
949 return ZFCP_ERP_FAILED;
950 return ZFCP_ERP_CONTINUES;
951}
952
953static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
954{
955 struct zfcp_unit *unit = erp_action->unit;
956
957 switch (erp_action->step) {
958 case ZFCP_ERP_STEP_UNINITIALIZED:
959 zfcp_erp_unit_strategy_clearstati(unit);
960 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
961 return zfcp_erp_unit_strategy_close(erp_action);
962 /* already closed, fall through */
963 case ZFCP_ERP_STEP_UNIT_CLOSING:
964 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
965 return ZFCP_ERP_FAILED;
966 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
967 return ZFCP_ERP_EXIT;
968 return zfcp_erp_unit_strategy_open(erp_action);
969
970 case ZFCP_ERP_STEP_UNIT_OPENING:
971 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
972 return ZFCP_ERP_SUCCEEDED;
973 }
974 return ZFCP_ERP_FAILED;
975}
976
977static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
978{
979 switch (result) {
980 case ZFCP_ERP_SUCCEEDED :
981 atomic_set(&unit->erp_counter, 0);
982 zfcp_erp_unit_unblock(unit);
983 break;
984 case ZFCP_ERP_FAILED :
985 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200986 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
987 dev_err(&unit->port->adapter->ccw_device->dev,
988 "ERP failed for unit 0x%016Lx on "
989 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +0200990 (unsigned long long)unit->fcp_lun,
991 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100992 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200993 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200994 break;
995 }
996
997 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
998 zfcp_erp_unit_block(unit, 0);
999 result = ZFCP_ERP_EXIT;
1000 }
1001 return result;
1002}
1003
1004static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1005{
1006 switch (result) {
1007 case ZFCP_ERP_SUCCEEDED :
1008 atomic_set(&port->erp_counter, 0);
1009 zfcp_erp_port_unblock(port);
1010 break;
1011
1012 case ZFCP_ERP_FAILED :
1013 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1014 zfcp_erp_port_block(port, 0);
1015 result = ZFCP_ERP_EXIT;
1016 }
1017 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001018 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1019 dev_err(&port->adapter->ccw_device->dev,
1020 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001021 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001022 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001023 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001024 break;
1025 }
1026
1027 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1028 zfcp_erp_port_block(port, 0);
1029 result = ZFCP_ERP_EXIT;
1030 }
1031 return result;
1032}
1033
1034static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1035 int result)
1036{
1037 switch (result) {
1038 case ZFCP_ERP_SUCCEEDED :
1039 atomic_set(&adapter->erp_counter, 0);
1040 zfcp_erp_adapter_unblock(adapter);
1041 break;
1042
1043 case ZFCP_ERP_FAILED :
1044 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001045 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1046 dev_err(&adapter->ccw_device->dev,
1047 "ERP cannot recover an error "
1048 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001049 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001050 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001051 break;
1052 }
1053
1054 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1055 zfcp_erp_adapter_block(adapter, 0);
1056 result = ZFCP_ERP_EXIT;
1057 }
1058 return result;
1059}
1060
1061static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1062 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 struct zfcp_adapter *adapter = erp_action->adapter;
1065 struct zfcp_port *port = erp_action->port;
1066 struct zfcp_unit *unit = erp_action->unit;
1067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 switch (erp_action->action) {
1069
1070 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1071 result = zfcp_erp_strategy_check_unit(unit, result);
1072 break;
1073
1074 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1075 case ZFCP_ERP_ACTION_REOPEN_PORT:
1076 result = zfcp_erp_strategy_check_port(port, result);
1077 break;
1078
1079 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1080 result = zfcp_erp_strategy_check_adapter(adapter, result);
1081 break;
1082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return result;
1084}
1085
Christof Schmitt287ac012008-07-02 10:56:40 +02001086static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087{
Christof Schmitt287ac012008-07-02 10:56:40 +02001088 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
Christof Schmitt287ac012008-07-02 10:56:40 +02001090 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1091 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1092 return 1; /* take it online */
1093
1094 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1095 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1096 return 1; /* take it offline */
1097
1098 return 0;
1099}
1100
1101static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1102{
1103 int action = act->action;
1104 struct zfcp_adapter *adapter = act->adapter;
1105 struct zfcp_port *port = act->port;
1106 struct zfcp_unit *unit = act->unit;
1107 u32 erp_status = act->status;
1108
1109 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001111 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1112 _zfcp_erp_adapter_reopen(adapter,
1113 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001114 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001115 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
1117 break;
1118
1119 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1120 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001121 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1122 _zfcp_erp_port_reopen(port,
1123 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001124 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001125 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 }
1127 break;
1128
1129 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001130 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1131 _zfcp_erp_unit_reopen(unit,
1132 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001133 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001134 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 }
1136 break;
1137 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001138 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Christof Schmitt287ac012008-07-02 10:56:40 +02001141static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Christof Schmitt287ac012008-07-02 10:56:40 +02001143 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Christof Schmitt287ac012008-07-02 10:56:40 +02001145 adapter->erp_total_count--;
1146 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1147 adapter->erp_low_mem_count--;
1148 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150
Christof Schmitt287ac012008-07-02 10:56:40 +02001151 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001152 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153
Christof Schmitt287ac012008-07-02 10:56:40 +02001154 switch (erp_action->action) {
1155 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1156 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1157 &erp_action->unit->status);
1158 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
Christof Schmitt287ac012008-07-02 10:56:40 +02001160 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1161 case ZFCP_ERP_ACTION_REOPEN_PORT:
1162 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1163 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001165
1166 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1167 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1168 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 break;
1170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171}
1172
Christof Schmitt287ac012008-07-02 10:56:40 +02001173static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001174{
Christof Schmitt287ac012008-07-02 10:56:40 +02001175 struct zfcp_adapter *adapter = act->adapter;
1176 struct zfcp_port *port = act->port;
1177 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001178
Christof Schmitt287ac012008-07-02 10:56:40 +02001179 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001181 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Swen Schilligf3450c72009-11-24 16:53:59 +01001182 get_device(&unit->sysfs_device);
Swen Schillig92d51932009-04-17 15:08:04 +02001183 if (scsi_queue_work(unit->port->adapter->scsi_host,
1184 &unit->scsi_work) <= 0)
Swen Schilligf3450c72009-11-24 16:53:59 +01001185 put_device(&unit->sysfs_device);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001186 }
Swen Schilligf3450c72009-11-24 16:53:59 +01001187 put_device(&unit->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1191 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001192 if (result == ZFCP_ERP_SUCCEEDED)
1193 zfcp_scsi_schedule_rport_register(port);
Swen Schilligf3450c72009-11-24 16:53:59 +01001194 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001198 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a422008-12-25 13:38:50 +01001199 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001200 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001201 } else
1202 unregister_service_level(&adapter->service_level);
Swen Schilligf3450c72009-11-24 16:53:59 +01001203 kref_put(&adapter->ref, zfcp_adapter_release);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206}
1207
Christof Schmitt287ac012008-07-02 10:56:40 +02001208static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1209{
1210 switch (erp_action->action) {
1211 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1212 return zfcp_erp_adapter_strategy(erp_action);
1213 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1214 return zfcp_erp_port_forced_strategy(erp_action);
1215 case ZFCP_ERP_ACTION_REOPEN_PORT:
1216 return zfcp_erp_port_strategy(erp_action);
1217 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1218 return zfcp_erp_unit_strategy(erp_action);
1219 }
1220 return ZFCP_ERP_FAILED;
1221}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
Christof Schmitt287ac012008-07-02 10:56:40 +02001223static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1224{
1225 int retval;
Christof Schmitt287ac012008-07-02 10:56:40 +02001226 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001227 struct zfcp_adapter *adapter = erp_action->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +02001228
Swen Schilligf3450c72009-11-24 16:53:59 +01001229 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001230
Swen Schilligf3450c72009-11-24 16:53:59 +01001231 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001232 zfcp_erp_strategy_check_fsfreq(erp_action);
1233
1234 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1235 zfcp_erp_action_dequeue(erp_action);
1236 retval = ZFCP_ERP_DISMISSED;
1237 goto unlock;
1238 }
1239
1240 zfcp_erp_action_to_running(erp_action);
1241
1242 /* no lock to allow for blocking operations */
Swen Schilligecf0c772009-11-24 16:53:58 +01001243 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001244 retval = zfcp_erp_strategy_do_action(erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +01001245 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001246
1247 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1248 retval = ZFCP_ERP_CONTINUES;
1249
1250 switch (retval) {
1251 case ZFCP_ERP_NOMEM:
1252 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1253 ++adapter->erp_low_mem_count;
1254 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1255 }
1256 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001257 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001258 else {
1259 zfcp_erp_strategy_memwait(erp_action);
1260 retval = ZFCP_ERP_CONTINUES;
1261 }
1262 goto unlock;
1263
1264 case ZFCP_ERP_CONTINUES:
1265 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1266 --adapter->erp_low_mem_count;
1267 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1268 }
1269 goto unlock;
1270 }
1271
1272 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1273 zfcp_erp_action_dequeue(erp_action);
1274 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1275 if (retval == ZFCP_ERP_EXIT)
1276 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001277 if (retval == ZFCP_ERP_SUCCEEDED)
1278 zfcp_erp_strategy_followup_success(erp_action);
1279 if (retval == ZFCP_ERP_FAILED)
1280 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001281
1282 unlock:
Swen Schilligecf0c772009-11-24 16:53:58 +01001283 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001284
1285 if (retval != ZFCP_ERP_CONTINUES)
1286 zfcp_erp_action_cleanup(erp_action, retval);
1287
Swen Schilligf3450c72009-11-24 16:53:59 +01001288 kref_put(&adapter->ref, zfcp_adapter_release);
Christof Schmitt287ac012008-07-02 10:56:40 +02001289 return retval;
1290}
1291
1292static int zfcp_erp_thread(void *data)
1293{
1294 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1295 struct list_head *next;
1296 struct zfcp_erp_action *act;
1297 unsigned long flags;
1298
Christof Schmitt347c6a92009-08-18 15:43:25 +02001299 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001300 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001301 wait_event_interruptible(adapter->erp_ready_wq,
1302 !list_empty(&adapter->erp_ready_head) ||
1303 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001304 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001305
Christof Schmitt347c6a92009-08-18 15:43:25 +02001306 if (kthread_should_stop())
1307 break;
1308
Christof Schmitt287ac012008-07-02 10:56:40 +02001309 write_lock_irqsave(&adapter->erp_lock, flags);
1310 next = adapter->erp_ready_head.next;
1311 write_unlock_irqrestore(&adapter->erp_lock, flags);
1312
1313 if (next != &adapter->erp_ready_head) {
1314 act = list_entry(next, struct zfcp_erp_action, list);
1315
1316 /* there is more to come after dismission, no notify */
1317 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1318 zfcp_erp_wakeup(adapter);
1319 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001320 }
1321
Christof Schmitt287ac012008-07-02 10:56:40 +02001322 return 0;
1323}
1324
1325/**
1326 * zfcp_erp_thread_setup - Start ERP thread for adapter
1327 * @adapter: Adapter to start the ERP thread for
1328 *
1329 * Returns 0 on success or error code from kernel_thread()
1330 */
1331int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1332{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001333 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001334
Christof Schmitt347c6a92009-08-18 15:43:25 +02001335 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1336 dev_name(&adapter->ccw_device->dev));
1337 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001338 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001339 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001340 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001341 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001342
1343 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001344 return 0;
1345}
1346
1347/**
1348 * zfcp_erp_thread_kill - Stop ERP thread.
1349 * @adapter: Adapter where the ERP thread should be stopped.
1350 *
1351 * The caller of this routine ensures that the specified adapter has
1352 * been shut down and that this operation has been completed. Thus,
1353 * there are no pending erp_actions which would need to be handled
1354 * here.
1355 */
1356void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1357{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001358 kthread_stop(adapter->erp_thread);
1359 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001360 WARN_ON(!list_empty(&adapter->erp_ready_head));
1361 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001362}
1363
1364/**
1365 * zfcp_erp_adapter_failed - Set adapter status to failed.
1366 * @adapter: Failed adapter.
1367 * @id: Event id for debug trace.
1368 * @ref: Reference for debug trace.
1369 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001370void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001371{
1372 zfcp_erp_modify_adapter_status(adapter, id, ref,
1373 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001374}
1375
1376/**
1377 * zfcp_erp_port_failed - Set port status to failed.
1378 * @port: Failed port.
1379 * @id: Event id for debug trace.
1380 * @ref: Reference for debug trace.
1381 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001382void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001383{
1384 zfcp_erp_modify_port_status(port, id, ref,
1385 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001386}
1387
1388/**
1389 * zfcp_erp_unit_failed - Set unit status to failed.
1390 * @unit: Failed unit.
1391 * @id: Event id for debug trace.
1392 * @ref: Reference for debug trace.
1393 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001394void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001395{
1396 zfcp_erp_modify_unit_status(unit, id, ref,
1397 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001398}
1399
1400/**
1401 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1402 * @adapter: adapter for which to wait for completion of its error recovery
1403 */
1404void zfcp_erp_wait(struct zfcp_adapter *adapter)
1405{
1406 wait_event(adapter->erp_done_wqh,
1407 !(atomic_read(&adapter->status) &
1408 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1409}
1410
1411/**
1412 * zfcp_erp_modify_adapter_status - change adapter status bits
1413 * @adapter: adapter to change the status
1414 * @id: id for the debug trace
1415 * @ref: reference for the debug trace
1416 * @mask: status bits to change
1417 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1418 *
1419 * Changes in common status bits are propagated to attached ports and units.
1420 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001421void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001422 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 struct zfcp_port *port;
Swen Schilligecf0c772009-11-24 16:53:58 +01001425 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001426 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
Christof Schmitt287ac012008-07-02 10:56:40 +02001428 if (set_or_clear == ZFCP_SET) {
1429 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001430 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001431 atomic_set_mask(mask, &adapter->status);
1432 } else {
1433 if (status_change_clear(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001434 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001435 atomic_clear_mask(mask, &adapter->status);
1436 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1437 atomic_set(&adapter->erp_counter, 0);
1438 }
1439
Swen Schilligecf0c772009-11-24 16:53:58 +01001440 if (common_mask) {
1441 read_lock_irqsave(&adapter->port_list_lock, flags);
1442 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001443 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1444 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001445 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447}
1448
Christof Schmitt287ac012008-07-02 10:56:40 +02001449/**
1450 * zfcp_erp_modify_port_status - change port status bits
1451 * @port: port to change the status bits
1452 * @id: id for the debug trace
1453 * @ref: reference for the debug trace
1454 * @mask: status bits to change
1455 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1456 *
1457 * Changes in common status bits are propagated to attached units.
1458 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001459void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001460 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001463 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001464 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Christof Schmitt287ac012008-07-02 10:56:40 +02001466 if (set_or_clear == ZFCP_SET) {
1467 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001468 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001469 atomic_set_mask(mask, &port->status);
1470 } else {
1471 if (status_change_clear(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001472 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001473 atomic_clear_mask(mask, &port->status);
1474 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1475 atomic_set(&port->erp_counter, 0);
1476 }
1477
Swen Schilligecf0c772009-11-24 16:53:58 +01001478 if (common_mask) {
1479 read_lock_irqsave(&port->unit_list_lock, flags);
1480 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001481 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1482 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001483 read_unlock_irqrestore(&port->unit_list_lock, flags);
1484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485}
1486
Christof Schmitt287ac012008-07-02 10:56:40 +02001487/**
1488 * zfcp_erp_modify_unit_status - change unit status bits
1489 * @unit: unit to change the status bits
1490 * @id: id for the debug trace
1491 * @ref: reference for the debug trace
1492 * @mask: status bits to change
1493 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1494 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001495void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001496 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497{
Christof Schmitt287ac012008-07-02 10:56:40 +02001498 if (set_or_clear == ZFCP_SET) {
1499 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001500 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001501 atomic_set_mask(mask, &unit->status);
1502 } else {
1503 if (status_change_clear(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001504 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001505 atomic_clear_mask(mask, &unit->status);
1506 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1507 atomic_set(&unit->erp_counter, 0);
1508 }
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Christof Schmitt287ac012008-07-02 10:56:40 +02001512/**
1513 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1514 * @port: The "boxed" port.
1515 * @id: The debug trace id.
1516 * @id: Reference for the debug trace.
1517 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001518void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001519{
Martin Peschke698ec0162008-03-27 14:22:02 +01001520 zfcp_erp_modify_port_status(port, id, ref,
1521 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001522 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001523}
1524
Christof Schmitt287ac012008-07-02 10:56:40 +02001525/**
1526 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1527 * @port: The "boxed" unit.
1528 * @id: The debug trace id.
1529 * @id: Reference for the debug trace.
1530 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001531void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001532{
Martin Peschke698ec0162008-03-27 14:22:02 +01001533 zfcp_erp_modify_unit_status(unit, id, ref,
1534 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001535 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001536}
1537
Christof Schmitt287ac012008-07-02 10:56:40 +02001538/**
1539 * zfcp_erp_port_access_denied - Adapter denied access to port.
1540 * @port: port where access has been denied
1541 * @id: id for debug trace
1542 * @ref: reference for debug trace
1543 *
1544 * Since the adapter has denied access, stop using the port and the
1545 * attached units.
1546 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001547void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Martin Peschke698ec0162008-03-27 14:22:02 +01001549 zfcp_erp_modify_port_status(port, id, ref,
1550 ZFCP_STATUS_COMMON_ERP_FAILED |
1551 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Christof Schmitt287ac012008-07-02 10:56:40 +02001554/**
1555 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1556 * @unit: unit where access has been denied
1557 * @id: id for debug trace
1558 * @ref: reference for debug trace
1559 *
1560 * Since the adapter has denied access, stop using the unit.
1561 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001562void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Martin Peschke698ec0162008-03-27 14:22:02 +01001564 zfcp_erp_modify_unit_status(unit, id, ref,
1565 ZFCP_STATUS_COMMON_ERP_FAILED |
1566 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001569static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001570 void *ref)
1571{
1572 int status = atomic_read(&unit->status);
1573 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1574 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1575 return;
1576
1577 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1578}
1579
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001580static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001581 void *ref)
1582{
1583 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001584 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001585 int status = atomic_read(&port->status);
1586
1587 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1588 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schilligecf0c772009-11-24 16:53:58 +01001589 read_lock_irqsave(&port->unit_list_lock, flags);
1590 list_for_each_entry(unit, &port->unit_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001591 zfcp_erp_unit_access_changed(unit, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001592 read_unlock_irqrestore(&port->unit_list_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001593 return;
1594 }
1595
1596 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1597}
1598
1599/**
1600 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1601 * @adapter: Adapter where the Access Control Table (ACT) changed
1602 * @id: Id for debug trace
1603 * @ref: Reference for debug trace
1604 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001605void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001606 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001609 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001611 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1612 return;
1613
Swen Schilligecf0c772009-11-24 16:53:58 +01001614 read_lock_irqsave(&adapter->port_list_lock, flags);
1615 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001616 zfcp_erp_port_access_changed(port, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001617 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618}