blob: 788fd3a4cd232bb52a24c795cc813f53636fbfbe [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 Schilligf3450c72009-11-24 16:53:59 +0100177 get_device(&unit->sysfs_device);
Christof Schmitt287ac012008-07-02 10:56:40 +0200178 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
179 erp_action = &unit->erp_action;
180 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
181 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
182 break;
183
184 case ZFCP_ERP_ACTION_REOPEN_PORT:
185 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Swen Schilligf3450c72009-11-24 16:53:59 +0100186 get_device(&port->sysfs_device);
Christof Schmitt287ac012008-07-02 10:56:40 +0200187 zfcp_erp_action_dismiss_port(port);
188 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
189 erp_action = &port->erp_action;
190 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
191 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
192 break;
193
194 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Swen Schilligf3450c72009-11-24 16:53:59 +0100195 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200196 zfcp_erp_action_dismiss_adapter(adapter);
197 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
198 erp_action = &adapter->erp_action;
199 if (!(atomic_read(&adapter->status) &
200 ZFCP_STATUS_COMMON_RUNNING))
201 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
202 break;
203
204 default:
205 return NULL;
206 }
207
208 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
209 erp_action->adapter = adapter;
210 erp_action->port = port;
211 erp_action->unit = unit;
212 erp_action->action = need;
213 erp_action->status = status;
214
215 return erp_action;
216}
217
218static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
219 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100220 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200221{
222 int retval = 1, need;
223 struct zfcp_erp_action *act = NULL;
224
Christof Schmitt347c6a92009-08-18 15:43:25 +0200225 if (!adapter->erp_thread)
Christof Schmitt287ac012008-07-02 10:56:40 +0200226 return -EIO;
227
228 need = zfcp_erp_required_act(want, adapter, port, unit);
229 if (!need)
230 goto out;
231
232 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
233 act = zfcp_erp_setup_act(need, adapter, port, unit);
234 if (!act)
235 goto out;
236 ++adapter->erp_total_count;
237 list_add_tail(&act->list, &adapter->erp_ready_head);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200238 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +0200239 zfcp_dbf_rec_thread("eracte1", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200240 retval = 0;
241 out:
Swen Schillig57717102009-08-18 15:43:21 +0200242 zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200243 return retval;
244}
245
246static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100247 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200248{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100250 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Christof Schmitt287ac012008-07-02 10:56:40 +0200252 /* ensure propagation of failed status to new devices */
253 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100254 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200255 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200257 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
258 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200262 * zfcp_erp_adapter_reopen - Reopen adapter.
263 * @adapter: Adapter to reopen.
264 * @clear: Status flags to clear.
265 * @id: Id for debug trace event.
266 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200268void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100269 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Christof Schmitt287ac012008-07-02 10:56:40 +0200271 unsigned long flags;
272
Swen Schilligecf0c772009-11-24 16:53:58 +0100273 zfcp_erp_adapter_block(adapter, clear);
274 zfcp_scsi_schedule_rports_block(adapter);
275
276 write_lock_irqsave(&adapter->erp_lock, flags);
277 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
278 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
279 else
280 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
281 NULL, NULL, id, ref);
282 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200283}
284
285/**
286 * zfcp_erp_adapter_shutdown - Shutdown adapter.
287 * @adapter: Adapter to shut down.
288 * @clear: Status flags to clear.
289 * @id: Id for debug trace event.
290 * @ref: Reference for debug trace event.
291 */
292void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100293 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200294{
295 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
296 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
297}
298
299/**
300 * zfcp_erp_port_shutdown - Shutdown port
301 * @port: Port to shut down.
302 * @clear: Status flags to clear.
303 * @id: Id for debug trace event.
304 * @ref: Reference for debug trace event.
305 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100306void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
307 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200308{
309 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
310 zfcp_erp_port_reopen(port, clear | flags, id, ref);
311}
312
313/**
314 * zfcp_erp_unit_shutdown - Shutdown unit
315 * @unit: Unit to shut down.
316 * @clear: Status flags to clear.
317 * @id: Id for debug trace event.
318 * @ref: Reference for debug trace event.
319 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100320void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
321 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200322{
323 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
324 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
325}
326
327static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
328{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100329 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200330 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
331 ZFCP_CLEAR);
332}
333
334static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100335 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200336{
337 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100338 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200339
340 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
341 return;
342
343 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
344 port->adapter, port, NULL, id, ref);
345}
346
347/**
348 * zfcp_erp_port_forced_reopen - Forced close of port and open again
349 * @port: Port to force close and to reopen.
350 * @id: Id for debug trace event.
351 * @ref: Reference for debug trace event.
352 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100353void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200354 void *ref)
355{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 unsigned long flags;
357 struct zfcp_adapter *adapter = port->adapter;
358
Swen Schilligecf0c772009-11-24 16:53:58 +0100359 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200360 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100361 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200362}
363
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100364static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200365 void *ref)
366{
367 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100368 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200369
370 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
371 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100372 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200373 return -EIO;
374 }
375
376 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
377 port->adapter, port, NULL, id, ref);
378}
379
380/**
381 * zfcp_erp_port_reopen - trigger remote port recovery
382 * @port: port to recover
383 * @clear_mask: flags in port status to be cleared
384 *
385 * Returns 0 if recovery has been triggered, < 0 if not.
386 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100387int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200388{
Christof Schmitt287ac012008-07-02 10:56:40 +0200389 int retval;
Swen Schilligecf0c772009-11-24 16:53:58 +0100390 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200391 struct zfcp_adapter *adapter = port->adapter;
392
Swen Schilligecf0c772009-11-24 16:53:58 +0100393 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200394 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100395 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 return retval;
398}
399
Christof Schmitt287ac012008-07-02 10:56:40 +0200400static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100402 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200403 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
404 ZFCP_CLEAR);
405}
406
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100407static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200408 void *ref)
409{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 struct zfcp_adapter *adapter = unit->port->adapter;
411
Christof Schmitt287ac012008-07-02 10:56:40 +0200412 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Christof Schmitt287ac012008-07-02 10:56:40 +0200414 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
415 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Christof Schmitt287ac012008-07-02 10:56:40 +0200417 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
418 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421/**
422 * zfcp_erp_unit_reopen - initiate reopen of a unit
423 * @unit: unit to be reopened
424 * @clear_mask: specifies flags in unit status to be cleared
425 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100427void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
428 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200431 struct zfcp_port *port = unit->port;
432 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Swen Schilligecf0c772009-11-24 16:53:58 +0100434 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200435 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100436 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Christof Schmitt287ac012008-07-02 10:56:40 +0200439static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Christof Schmitt287ac012008-07-02 10:56:40 +0200441 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442}
443
Christof Schmitt287ac012008-07-02 10:56:40 +0200444static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100445{
Christof Schmitt287ac012008-07-02 10:56:40 +0200446 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100447}
448
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200449static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Christof Schmitt287ac012008-07-02 10:56:40 +0200451 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +0200452 zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200453 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
Christof Schmitt287ac012008-07-02 10:56:40 +0200456static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Christof Schmitt287ac012008-07-02 10:56:40 +0200458 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +0200459 zfcp_dbf_rec_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200460 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Christof Schmitt287ac012008-07-02 10:56:40 +0200463static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Christof Schmitt287ac012008-07-02 10:56:40 +0200465 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +0200466 zfcp_dbf_rec_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200467 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Christof Schmitt287ac012008-07-02 10:56:40 +0200470static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Christof Schmitt287ac012008-07-02 10:56:40 +0200472 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig57717102009-08-18 15:43:21 +0200473 zfcp_dbf_rec_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Christof Schmitt287ac012008-07-02 10:56:40 +0200476static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Christof Schmitt287ac012008-07-02 10:56:40 +0200478 struct zfcp_adapter *adapter = act->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Christof Schmitt287ac012008-07-02 10:56:40 +0200480 if (!act->fsf_req)
481 return;
482
483 spin_lock(&adapter->req_list_lock);
484 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
485 act->fsf_req->erp_action == act) {
486 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
487 ZFCP_STATUS_ERP_TIMEDOUT)) {
488 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig57717102009-08-18 15:43:21 +0200489 zfcp_dbf_rec_action("erscf_1", act);
Martin Petermann7ea633f2008-11-04 16:35:11 +0100490 act->fsf_req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200492 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig57717102009-08-18 15:43:21 +0200493 zfcp_dbf_rec_action("erscf_2", act);
Swen Schillig058b8642009-08-18 15:43:14 +0200494 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
Christof Schmitt287ac012008-07-02 10:56:40 +0200495 act->fsf_req = NULL;
496 } else
497 act->fsf_req = NULL;
498 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200501/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200502 * zfcp_erp_notify - Trigger ERP action.
503 * @erp_action: ERP action to continue.
504 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200506void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508 struct zfcp_adapter *adapter = erp_action->adapter;
509 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200512 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
513 erp_action->status |= set_mask;
514 zfcp_erp_action_ready(erp_action);
515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200519/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200520 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
521 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200523void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Christof Schmitt287ac012008-07-02 10:56:40 +0200525 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
526 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
Christof Schmitt287ac012008-07-02 10:56:40 +0200529static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Christof Schmitt287ac012008-07-02 10:56:40 +0200531 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Christof Schmitt287ac012008-07-02 10:56:40 +0200534static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 init_timer(&erp_action->timer);
537 erp_action->timer.function = zfcp_erp_memwait_handler;
538 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200539 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200541}
542
543static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100544 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200545{
546 struct zfcp_port *port;
547
Swen Schilligecf0c772009-11-24 16:53:58 +0100548 read_lock(&adapter->port_list_lock);
549 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200550 _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100551 read_unlock(&adapter->port_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200552}
553
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100554static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
555 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200556{
557 struct zfcp_unit *unit;
558
Swen Schilligecf0c772009-11-24 16:53:58 +0100559 read_lock(&port->unit_list_lock);
560 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200561 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100562 read_unlock(&port->unit_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200563}
564
Christof Schmitt85600f72009-07-13 15:06:09 +0200565static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200566{
Christof Schmitt287ac012008-07-02 10:56:40 +0200567 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200568 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200569 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200570 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200571 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200572 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200573 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200574 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200575 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200576 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200577 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200578 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
579 break;
580 }
581}
582
583static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
584{
585 switch (act->action) {
586 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
587 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
588 break;
589 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
590 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
591 break;
592 case ZFCP_ERP_ACTION_REOPEN_PORT:
593 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200594 break;
595 }
596}
597
598static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
599{
600 unsigned long flags;
601
Swen Schilligecf0c772009-11-24 16:53:58 +0100602 read_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200603 if (list_empty(&adapter->erp_ready_head) &&
604 list_empty(&adapter->erp_running_head)) {
605 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
606 &adapter->status);
607 wake_up(&adapter->erp_done_wqh);
608 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100609 read_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200610}
611
612static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
613{
Swen Schillig564e1c82009-08-18 15:43:19 +0200614 struct zfcp_qdio *qdio = act->adapter->qdio;
615
616 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200617 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200618 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200619 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
620 return ZFCP_ERP_SUCCEEDED;
621}
622
623static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
624{
625 struct zfcp_port *port;
626 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
627 adapter->peer_d_id);
628 if (IS_ERR(port)) /* error or port already attached */
629 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100630 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200631}
632
633static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
634{
635 int retries;
636 int sleep = 1;
637 struct zfcp_adapter *adapter = erp_action->adapter;
638
639 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
640
641 for (retries = 7; retries; retries--) {
642 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
643 &adapter->status);
644 write_lock_irq(&adapter->erp_lock);
645 zfcp_erp_action_to_running(erp_action);
646 write_unlock_irq(&adapter->erp_lock);
647 if (zfcp_fsf_exchange_config_data(erp_action)) {
648 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
649 &adapter->status);
650 return ZFCP_ERP_FAILED;
651 }
652
Swen Schillig57717102009-08-18 15:43:21 +0200653 zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200654 wait_event(adapter->erp_ready_wq,
655 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200656 zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200657 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
658 break;
659
660 if (!(atomic_read(&adapter->status) &
661 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
662 break;
663
664 ssleep(sleep);
665 sleep *= 2;
666 }
667
668 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
669 &adapter->status);
670
671 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
672 return ZFCP_ERP_FAILED;
673
674 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
675 zfcp_erp_enqueue_ptp_port(adapter);
676
677 return ZFCP_ERP_SUCCEEDED;
678}
679
680static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
681{
682 int ret;
683 struct zfcp_adapter *adapter = act->adapter;
684
Christof Schmitt287ac012008-07-02 10:56:40 +0200685 write_lock_irq(&adapter->erp_lock);
686 zfcp_erp_action_to_running(act);
687 write_unlock_irq(&adapter->erp_lock);
688
689 ret = zfcp_fsf_exchange_port_data(act);
690 if (ret == -EOPNOTSUPP)
691 return ZFCP_ERP_SUCCEEDED;
692 if (ret)
693 return ZFCP_ERP_FAILED;
694
Swen Schillig57717102009-08-18 15:43:21 +0200695 zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200696 wait_event(adapter->erp_ready_wq,
697 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200698 zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200699 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
700 return ZFCP_ERP_FAILED;
701
702 return ZFCP_ERP_SUCCEEDED;
703}
704
705static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
706{
707 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
708 return ZFCP_ERP_FAILED;
709
710 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
711 return ZFCP_ERP_FAILED;
712
713 atomic_set(&act->adapter->stat_miss, 16);
714 if (zfcp_status_read_refill(act->adapter))
715 return ZFCP_ERP_FAILED;
716
717 return ZFCP_ERP_SUCCEEDED;
718}
719
Swen Schilligcf13c082009-03-02 13:09:03 +0100720static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200721{
Christof Schmitt287ac012008-07-02 10:56:40 +0200722 struct zfcp_adapter *adapter = act->adapter;
723
Christof Schmitt287ac012008-07-02 10:56:40 +0200724 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200725 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200726 zfcp_fsf_req_dismiss_all(adapter);
727 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200728 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200729 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100730 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200731 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100732
Christof Schmitt287ac012008-07-02 10:56:40 +0200733 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100734 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
735}
736
737static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
738{
739 struct zfcp_adapter *adapter = act->adapter;
740
741 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
742 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
743 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
744 &adapter->status);
745 return ZFCP_ERP_FAILED;
746 }
747
748 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
749 zfcp_erp_adapter_strategy_close(act);
750 return ZFCP_ERP_FAILED;
751 }
752
753 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
754
755 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200756}
757
758static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
759{
Swen Schilligcf13c082009-03-02 13:09:03 +0100760 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200761
Swen Schilligcf13c082009-03-02 13:09:03 +0100762 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
763 zfcp_erp_adapter_strategy_close(act);
764 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
765 return ZFCP_ERP_EXIT;
766 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200767
Swen Schilligcf13c082009-03-02 13:09:03 +0100768 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200769 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100770 return ZFCP_ERP_FAILED;
771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Swen Schilligcf13c082009-03-02 13:09:03 +0100773 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774}
775
Christof Schmitt287ac012008-07-02 10:56:40 +0200776static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777{
Christof Schmitt287ac012008-07-02 10:56:40 +0200778 int retval;
779
780 retval = zfcp_fsf_close_physical_port(act);
781 if (retval == -ENOMEM)
782 return ZFCP_ERP_NOMEM;
783 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
784 if (retval)
785 return ZFCP_ERP_FAILED;
786
787 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788}
789
Christof Schmitt287ac012008-07-02 10:56:40 +0200790static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100792 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200793}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Christof Schmitt287ac012008-07-02 10:56:40 +0200795static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
796{
797 struct zfcp_port *port = erp_action->port;
798 int status = atomic_read(&port->status);
799
800 switch (erp_action->step) {
801 case ZFCP_ERP_STEP_UNINITIALIZED:
802 zfcp_erp_port_strategy_clearstati(port);
803 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
804 (status & ZFCP_STATUS_COMMON_OPEN))
805 return zfcp_erp_port_forced_strategy_close(erp_action);
806 else
807 return ZFCP_ERP_FAILED;
808
809 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200810 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200811 return ZFCP_ERP_SUCCEEDED;
812 }
813 return ZFCP_ERP_FAILED;
814}
815
816static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
817{
818 int retval;
819
820 retval = zfcp_fsf_close_port(erp_action);
821 if (retval == -ENOMEM)
822 return ZFCP_ERP_NOMEM;
823 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
824 if (retval)
825 return ZFCP_ERP_FAILED;
826 return ZFCP_ERP_CONTINUES;
827}
828
829static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
830{
831 int retval;
832
833 retval = zfcp_fsf_open_port(erp_action);
834 if (retval == -ENOMEM)
835 return ZFCP_ERP_NOMEM;
836 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
837 if (retval)
838 return ZFCP_ERP_FAILED;
839 return ZFCP_ERP_CONTINUES;
840}
841
Christof Schmitt287ac012008-07-02 10:56:40 +0200842static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
843{
844 struct zfcp_adapter *adapter = act->adapter;
845 struct zfcp_port *port = act->port;
846
847 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100848 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200849 return ZFCP_ERP_FAILED;
850 }
851 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200852 return zfcp_erp_port_strategy_open_port(act);
853}
854
855static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
856{
857 struct zfcp_adapter *adapter = act->adapter;
858 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200859 int p_status = atomic_read(&port->status);
860
861 switch (act->step) {
862 case ZFCP_ERP_STEP_UNINITIALIZED:
863 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
864 case ZFCP_ERP_STEP_PORT_CLOSING:
865 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
866 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100867 if (!port->d_id) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200868 zfcp_fc_trigger_did_lookup(port);
Christof Schmitt799b76d2009-08-18 15:43:20 +0200869 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200870 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200871 return zfcp_erp_port_strategy_open_port(act);
872
873 case ZFCP_ERP_STEP_PORT_OPENING:
874 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200875 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200876 if (!port->d_id) {
877 zfcp_fc_trigger_did_lookup(port);
878 return ZFCP_ERP_EXIT;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200879 }
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200880 return ZFCP_ERP_SUCCEEDED;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200881 }
Swen Schilligea460a82009-05-15 13:18:20 +0200882 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
883 port->d_id = 0;
884 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
885 return ZFCP_ERP_EXIT;
886 }
887 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200888 }
889 return ZFCP_ERP_FAILED;
890}
891
Christof Schmitt287ac012008-07-02 10:56:40 +0200892static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
893{
894 struct zfcp_port *port = erp_action->port;
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200895 int p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200896
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200897 if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
898 !(p_status & ZFCP_STATUS_COMMON_OPEN))
Swen Schillig5ab944f2008-10-01 12:42:17 +0200899 goto close_init_done;
900
Christof Schmitt287ac012008-07-02 10:56:40 +0200901 switch (erp_action->step) {
902 case ZFCP_ERP_STEP_UNINITIALIZED:
903 zfcp_erp_port_strategy_clearstati(port);
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200904 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200905 return zfcp_erp_port_strategy_close(erp_action);
906 break;
907
908 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200909 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200910 return ZFCP_ERP_FAILED;
911 break;
912 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200913
914close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200915 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
916 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200917
Swen Schillig5ab944f2008-10-01 12:42:17 +0200918 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
Christof Schmitt287ac012008-07-02 10:56:40 +0200921static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200923 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200924 ZFCP_STATUS_UNIT_SHARED |
925 ZFCP_STATUS_UNIT_READONLY,
926 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
Christof Schmitt287ac012008-07-02 10:56:40 +0200929static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
930{
931 int retval = zfcp_fsf_close_unit(erp_action);
932 if (retval == -ENOMEM)
933 return ZFCP_ERP_NOMEM;
934 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
935 if (retval)
936 return ZFCP_ERP_FAILED;
937 return ZFCP_ERP_CONTINUES;
938}
939
940static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
941{
942 int retval = zfcp_fsf_open_unit(erp_action);
943 if (retval == -ENOMEM)
944 return ZFCP_ERP_NOMEM;
945 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
946 if (retval)
947 return ZFCP_ERP_FAILED;
948 return ZFCP_ERP_CONTINUES;
949}
950
951static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
952{
953 struct zfcp_unit *unit = erp_action->unit;
954
955 switch (erp_action->step) {
956 case ZFCP_ERP_STEP_UNINITIALIZED:
957 zfcp_erp_unit_strategy_clearstati(unit);
958 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
959 return zfcp_erp_unit_strategy_close(erp_action);
960 /* already closed, fall through */
961 case ZFCP_ERP_STEP_UNIT_CLOSING:
962 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
963 return ZFCP_ERP_FAILED;
964 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
965 return ZFCP_ERP_EXIT;
966 return zfcp_erp_unit_strategy_open(erp_action);
967
968 case ZFCP_ERP_STEP_UNIT_OPENING:
969 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
970 return ZFCP_ERP_SUCCEEDED;
971 }
972 return ZFCP_ERP_FAILED;
973}
974
975static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
976{
977 switch (result) {
978 case ZFCP_ERP_SUCCEEDED :
979 atomic_set(&unit->erp_counter, 0);
980 zfcp_erp_unit_unblock(unit);
981 break;
982 case ZFCP_ERP_FAILED :
983 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200984 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
985 dev_err(&unit->port->adapter->ccw_device->dev,
986 "ERP failed for unit 0x%016Lx on "
987 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +0200988 (unsigned long long)unit->fcp_lun,
989 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100990 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200991 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200992 break;
993 }
994
995 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
996 zfcp_erp_unit_block(unit, 0);
997 result = ZFCP_ERP_EXIT;
998 }
999 return result;
1000}
1001
1002static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1003{
1004 switch (result) {
1005 case ZFCP_ERP_SUCCEEDED :
1006 atomic_set(&port->erp_counter, 0);
1007 zfcp_erp_port_unblock(port);
1008 break;
1009
1010 case ZFCP_ERP_FAILED :
1011 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1012 zfcp_erp_port_block(port, 0);
1013 result = ZFCP_ERP_EXIT;
1014 }
1015 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001016 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1017 dev_err(&port->adapter->ccw_device->dev,
1018 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001019 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001020 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001021 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001022 break;
1023 }
1024
1025 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1026 zfcp_erp_port_block(port, 0);
1027 result = ZFCP_ERP_EXIT;
1028 }
1029 return result;
1030}
1031
1032static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1033 int result)
1034{
1035 switch (result) {
1036 case ZFCP_ERP_SUCCEEDED :
1037 atomic_set(&adapter->erp_counter, 0);
1038 zfcp_erp_adapter_unblock(adapter);
1039 break;
1040
1041 case ZFCP_ERP_FAILED :
1042 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001043 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1044 dev_err(&adapter->ccw_device->dev,
1045 "ERP cannot recover an error "
1046 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001047 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001048 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001049 break;
1050 }
1051
1052 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1053 zfcp_erp_adapter_block(adapter, 0);
1054 result = ZFCP_ERP_EXIT;
1055 }
1056 return result;
1057}
1058
1059static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1060 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 struct zfcp_adapter *adapter = erp_action->adapter;
1063 struct zfcp_port *port = erp_action->port;
1064 struct zfcp_unit *unit = erp_action->unit;
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 switch (erp_action->action) {
1067
1068 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1069 result = zfcp_erp_strategy_check_unit(unit, result);
1070 break;
1071
1072 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1073 case ZFCP_ERP_ACTION_REOPEN_PORT:
1074 result = zfcp_erp_strategy_check_port(port, result);
1075 break;
1076
1077 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1078 result = zfcp_erp_strategy_check_adapter(adapter, result);
1079 break;
1080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 return result;
1082}
1083
Christof Schmitt287ac012008-07-02 10:56:40 +02001084static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085{
Christof Schmitt287ac012008-07-02 10:56:40 +02001086 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Christof Schmitt287ac012008-07-02 10:56:40 +02001088 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1089 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1090 return 1; /* take it online */
1091
1092 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1093 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1094 return 1; /* take it offline */
1095
1096 return 0;
1097}
1098
1099static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1100{
1101 int action = act->action;
1102 struct zfcp_adapter *adapter = act->adapter;
1103 struct zfcp_port *port = act->port;
1104 struct zfcp_unit *unit = act->unit;
1105 u32 erp_status = act->status;
1106
1107 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001109 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1110 _zfcp_erp_adapter_reopen(adapter,
1111 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001112 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001113 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 }
1115 break;
1116
1117 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1118 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001119 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1120 _zfcp_erp_port_reopen(port,
1121 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001122 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001123 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 }
1125 break;
1126
1127 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001128 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1129 _zfcp_erp_unit_reopen(unit,
1130 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001131 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001132 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
1134 break;
1135 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001136 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Christof Schmitt287ac012008-07-02 10:56:40 +02001139static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140{
Christof Schmitt287ac012008-07-02 10:56:40 +02001141 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142
Christof Schmitt287ac012008-07-02 10:56:40 +02001143 adapter->erp_total_count--;
1144 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1145 adapter->erp_low_mem_count--;
1146 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
1148
Christof Schmitt287ac012008-07-02 10:56:40 +02001149 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001150 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Christof Schmitt287ac012008-07-02 10:56:40 +02001152 switch (erp_action->action) {
1153 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1154 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1155 &erp_action->unit->status);
1156 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Christof Schmitt287ac012008-07-02 10:56:40 +02001158 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1159 case ZFCP_ERP_ACTION_REOPEN_PORT:
1160 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1161 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001163
1164 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1165 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1166 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 break;
1168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Christof Schmitt287ac012008-07-02 10:56:40 +02001171static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001172{
Christof Schmitt287ac012008-07-02 10:56:40 +02001173 struct zfcp_adapter *adapter = act->adapter;
1174 struct zfcp_port *port = act->port;
1175 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001176
Christof Schmitt287ac012008-07-02 10:56:40 +02001177 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001179 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Swen Schilligf3450c72009-11-24 16:53:59 +01001180 get_device(&unit->sysfs_device);
Swen Schillig92d51932009-04-17 15:08:04 +02001181 if (scsi_queue_work(unit->port->adapter->scsi_host,
1182 &unit->scsi_work) <= 0)
Swen Schilligf3450c72009-11-24 16:53:59 +01001183 put_device(&unit->sysfs_device);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001184 }
Swen Schilligf3450c72009-11-24 16:53:59 +01001185 put_device(&unit->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1189 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001190 if (result == ZFCP_ERP_SUCCEEDED)
1191 zfcp_scsi_schedule_rport_register(port);
Swen Schilligf3450c72009-11-24 16:53:59 +01001192 put_device(&port->sysfs_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001194
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001196 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a422008-12-25 13:38:50 +01001197 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001198 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001199 } else
1200 unregister_service_level(&adapter->service_level);
Swen Schilligf3450c72009-11-24 16:53:59 +01001201 kref_put(&adapter->ref, zfcp_adapter_release);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
1204}
1205
Christof Schmitt287ac012008-07-02 10:56:40 +02001206static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1207{
1208 switch (erp_action->action) {
1209 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1210 return zfcp_erp_adapter_strategy(erp_action);
1211 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1212 return zfcp_erp_port_forced_strategy(erp_action);
1213 case ZFCP_ERP_ACTION_REOPEN_PORT:
1214 return zfcp_erp_port_strategy(erp_action);
1215 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1216 return zfcp_erp_unit_strategy(erp_action);
1217 }
1218 return ZFCP_ERP_FAILED;
1219}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
Christof Schmitt287ac012008-07-02 10:56:40 +02001221static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1222{
1223 int retval;
Christof Schmitt287ac012008-07-02 10:56:40 +02001224 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001225 struct zfcp_adapter *adapter = erp_action->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +02001226
Swen Schilligf3450c72009-11-24 16:53:59 +01001227 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001228
Swen Schilligf3450c72009-11-24 16:53:59 +01001229 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001230 zfcp_erp_strategy_check_fsfreq(erp_action);
1231
1232 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1233 zfcp_erp_action_dequeue(erp_action);
1234 retval = ZFCP_ERP_DISMISSED;
1235 goto unlock;
1236 }
1237
1238 zfcp_erp_action_to_running(erp_action);
1239
1240 /* no lock to allow for blocking operations */
Swen Schilligecf0c772009-11-24 16:53:58 +01001241 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001242 retval = zfcp_erp_strategy_do_action(erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +01001243 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001244
1245 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1246 retval = ZFCP_ERP_CONTINUES;
1247
1248 switch (retval) {
1249 case ZFCP_ERP_NOMEM:
1250 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1251 ++adapter->erp_low_mem_count;
1252 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1253 }
1254 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001255 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001256 else {
1257 zfcp_erp_strategy_memwait(erp_action);
1258 retval = ZFCP_ERP_CONTINUES;
1259 }
1260 goto unlock;
1261
1262 case ZFCP_ERP_CONTINUES:
1263 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1264 --adapter->erp_low_mem_count;
1265 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1266 }
1267 goto unlock;
1268 }
1269
1270 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1271 zfcp_erp_action_dequeue(erp_action);
1272 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1273 if (retval == ZFCP_ERP_EXIT)
1274 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001275 if (retval == ZFCP_ERP_SUCCEEDED)
1276 zfcp_erp_strategy_followup_success(erp_action);
1277 if (retval == ZFCP_ERP_FAILED)
1278 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001279
1280 unlock:
Swen Schilligecf0c772009-11-24 16:53:58 +01001281 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001282
1283 if (retval != ZFCP_ERP_CONTINUES)
1284 zfcp_erp_action_cleanup(erp_action, retval);
1285
Swen Schilligf3450c72009-11-24 16:53:59 +01001286 kref_put(&adapter->ref, zfcp_adapter_release);
Christof Schmitt287ac012008-07-02 10:56:40 +02001287 return retval;
1288}
1289
1290static int zfcp_erp_thread(void *data)
1291{
1292 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1293 struct list_head *next;
1294 struct zfcp_erp_action *act;
1295 unsigned long flags;
1296
Christof Schmitt347c6a92009-08-18 15:43:25 +02001297 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001298 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001299 wait_event_interruptible(adapter->erp_ready_wq,
1300 !list_empty(&adapter->erp_ready_head) ||
1301 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001302 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001303
Christof Schmitt347c6a92009-08-18 15:43:25 +02001304 if (kthread_should_stop())
1305 break;
1306
Christof Schmitt287ac012008-07-02 10:56:40 +02001307 write_lock_irqsave(&adapter->erp_lock, flags);
1308 next = adapter->erp_ready_head.next;
1309 write_unlock_irqrestore(&adapter->erp_lock, flags);
1310
1311 if (next != &adapter->erp_ready_head) {
1312 act = list_entry(next, struct zfcp_erp_action, list);
1313
1314 /* there is more to come after dismission, no notify */
1315 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1316 zfcp_erp_wakeup(adapter);
1317 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001318 }
1319
Christof Schmitt287ac012008-07-02 10:56:40 +02001320 return 0;
1321}
1322
1323/**
1324 * zfcp_erp_thread_setup - Start ERP thread for adapter
1325 * @adapter: Adapter to start the ERP thread for
1326 *
1327 * Returns 0 on success or error code from kernel_thread()
1328 */
1329int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1330{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001331 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001332
Christof Schmitt347c6a92009-08-18 15:43:25 +02001333 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1334 dev_name(&adapter->ccw_device->dev));
1335 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001336 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001337 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001338 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001339 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001340
1341 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001342 return 0;
1343}
1344
1345/**
1346 * zfcp_erp_thread_kill - Stop ERP thread.
1347 * @adapter: Adapter where the ERP thread should be stopped.
1348 *
1349 * The caller of this routine ensures that the specified adapter has
1350 * been shut down and that this operation has been completed. Thus,
1351 * there are no pending erp_actions which would need to be handled
1352 * here.
1353 */
1354void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1355{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001356 kthread_stop(adapter->erp_thread);
1357 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001358 WARN_ON(!list_empty(&adapter->erp_ready_head));
1359 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001360}
1361
1362/**
1363 * zfcp_erp_adapter_failed - Set adapter status to failed.
1364 * @adapter: Failed adapter.
1365 * @id: Event id for debug trace.
1366 * @ref: Reference for debug trace.
1367 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001368void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001369{
1370 zfcp_erp_modify_adapter_status(adapter, id, ref,
1371 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001372}
1373
1374/**
1375 * zfcp_erp_port_failed - Set port status to failed.
1376 * @port: Failed port.
1377 * @id: Event id for debug trace.
1378 * @ref: Reference for debug trace.
1379 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001380void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001381{
1382 zfcp_erp_modify_port_status(port, id, ref,
1383 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001384}
1385
1386/**
1387 * zfcp_erp_unit_failed - Set unit status to failed.
1388 * @unit: Failed unit.
1389 * @id: Event id for debug trace.
1390 * @ref: Reference for debug trace.
1391 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001392void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001393{
1394 zfcp_erp_modify_unit_status(unit, id, ref,
1395 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001396}
1397
1398/**
1399 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1400 * @adapter: adapter for which to wait for completion of its error recovery
1401 */
1402void zfcp_erp_wait(struct zfcp_adapter *adapter)
1403{
1404 wait_event(adapter->erp_done_wqh,
1405 !(atomic_read(&adapter->status) &
1406 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1407}
1408
1409/**
1410 * zfcp_erp_modify_adapter_status - change adapter status bits
1411 * @adapter: adapter to change the status
1412 * @id: id for the debug trace
1413 * @ref: reference for the debug trace
1414 * @mask: status bits to change
1415 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1416 *
1417 * Changes in common status bits are propagated to attached ports and units.
1418 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001419void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001420 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 struct zfcp_port *port;
Swen Schilligecf0c772009-11-24 16:53:58 +01001423 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001424 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425
Christof Schmitt287ac012008-07-02 10:56:40 +02001426 if (set_or_clear == ZFCP_SET) {
1427 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001428 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001429 atomic_set_mask(mask, &adapter->status);
1430 } else {
1431 if (status_change_clear(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_clear_mask(mask, &adapter->status);
1434 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1435 atomic_set(&adapter->erp_counter, 0);
1436 }
1437
Swen Schilligecf0c772009-11-24 16:53:58 +01001438 if (common_mask) {
1439 read_lock_irqsave(&adapter->port_list_lock, flags);
1440 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001441 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1442 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001443 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445}
1446
Christof Schmitt287ac012008-07-02 10:56:40 +02001447/**
1448 * zfcp_erp_modify_port_status - change port status bits
1449 * @port: port to change the status bits
1450 * @id: id for the debug trace
1451 * @ref: reference for the debug trace
1452 * @mask: status bits to change
1453 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1454 *
1455 * Changes in common status bits are propagated to attached units.
1456 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001457void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001458 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001461 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001462 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Christof Schmitt287ac012008-07-02 10:56:40 +02001464 if (set_or_clear == ZFCP_SET) {
1465 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001466 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001467 atomic_set_mask(mask, &port->status);
1468 } else {
1469 if (status_change_clear(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_clear_mask(mask, &port->status);
1472 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1473 atomic_set(&port->erp_counter, 0);
1474 }
1475
Swen Schilligecf0c772009-11-24 16:53:58 +01001476 if (common_mask) {
1477 read_lock_irqsave(&port->unit_list_lock, flags);
1478 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001479 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1480 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001481 read_unlock_irqrestore(&port->unit_list_lock, flags);
1482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483}
1484
Christof Schmitt287ac012008-07-02 10:56:40 +02001485/**
1486 * zfcp_erp_modify_unit_status - change unit status bits
1487 * @unit: unit to change the status bits
1488 * @id: id for the debug trace
1489 * @ref: reference for the debug trace
1490 * @mask: status bits to change
1491 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1492 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001493void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001494 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
Christof Schmitt287ac012008-07-02 10:56:40 +02001496 if (set_or_clear == ZFCP_SET) {
1497 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001498 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001499 atomic_set_mask(mask, &unit->status);
1500 } else {
1501 if (status_change_clear(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_clear_mask(mask, &unit->status);
1504 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1505 atomic_set(&unit->erp_counter, 0);
1506 }
1507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}
1509
Christof Schmitt287ac012008-07-02 10:56:40 +02001510/**
1511 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1512 * @port: The "boxed" port.
1513 * @id: The debug trace id.
1514 * @id: Reference for the debug trace.
1515 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001516void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001517{
Martin Peschke698ec0162008-03-27 14:22:02 +01001518 zfcp_erp_modify_port_status(port, id, ref,
1519 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001520 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001521}
1522
Christof Schmitt287ac012008-07-02 10:56:40 +02001523/**
1524 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1525 * @port: The "boxed" unit.
1526 * @id: The debug trace id.
1527 * @id: Reference for the debug trace.
1528 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001529void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001530{
Martin Peschke698ec0162008-03-27 14:22:02 +01001531 zfcp_erp_modify_unit_status(unit, id, ref,
1532 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001533 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001534}
1535
Christof Schmitt287ac012008-07-02 10:56:40 +02001536/**
1537 * zfcp_erp_port_access_denied - Adapter denied access to port.
1538 * @port: port where access has been denied
1539 * @id: id for debug trace
1540 * @ref: reference for debug trace
1541 *
1542 * Since the adapter has denied access, stop using the port and the
1543 * attached units.
1544 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001545void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Martin Peschke698ec0162008-03-27 14:22:02 +01001547 zfcp_erp_modify_port_status(port, id, ref,
1548 ZFCP_STATUS_COMMON_ERP_FAILED |
1549 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550}
1551
Christof Schmitt287ac012008-07-02 10:56:40 +02001552/**
1553 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1554 * @unit: unit where access has been denied
1555 * @id: id for debug trace
1556 * @ref: reference for debug trace
1557 *
1558 * Since the adapter has denied access, stop using the unit.
1559 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001560void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Martin Peschke698ec0162008-03-27 14:22:02 +01001562 zfcp_erp_modify_unit_status(unit, id, ref,
1563 ZFCP_STATUS_COMMON_ERP_FAILED |
1564 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001567static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001568 void *ref)
1569{
1570 int status = atomic_read(&unit->status);
1571 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1572 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1573 return;
1574
1575 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1576}
1577
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001578static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001579 void *ref)
1580{
1581 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001582 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001583 int status = atomic_read(&port->status);
1584
1585 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1586 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schilligecf0c772009-11-24 16:53:58 +01001587 read_lock_irqsave(&port->unit_list_lock, flags);
1588 list_for_each_entry(unit, &port->unit_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001589 zfcp_erp_unit_access_changed(unit, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001590 read_unlock_irqrestore(&port->unit_list_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001591 return;
1592 }
1593
1594 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1595}
1596
1597/**
1598 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1599 * @adapter: Adapter where the Access Control Table (ACT) changed
1600 * @id: Id for debug trace
1601 * @ref: Reference for debug trace
1602 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001603void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001604 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001607 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001609 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1610 return;
1611
Swen Schilligecf0c772009-11-24 16:53:58 +01001612 read_lock_irqsave(&adapter->port_list_lock, flags);
1613 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001614 zfcp_erp_port_access_changed(port, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001615 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}