blob: 73d366ba31e593755d2854d4591888b9e949bba9 [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);
102 else
103 list_for_each_entry(unit, &port->unit_list_head, list)
104 zfcp_erp_action_dismiss_unit(unit);
105}
106
107static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
108{
109 struct zfcp_port *port;
110
111 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
112 zfcp_erp_action_dismiss(&adapter->erp_action);
113 else
114 list_for_each_entry(port, &adapter->port_list_head, list)
115 zfcp_erp_action_dismiss_port(port);
116}
117
118static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
119 struct zfcp_port *port,
120 struct zfcp_unit *unit)
121{
122 int need = want;
123 int u_status, p_status, a_status;
124
125 switch (want) {
126 case ZFCP_ERP_ACTION_REOPEN_UNIT:
127 u_status = atomic_read(&unit->status);
128 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
129 return 0;
130 p_status = atomic_read(&port->status);
131 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
132 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
133 return 0;
134 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
135 need = ZFCP_ERP_ACTION_REOPEN_PORT;
136 /* fall through */
137 case ZFCP_ERP_ACTION_REOPEN_PORT:
138 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
139 p_status = atomic_read(&port->status);
140 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
141 return 0;
142 a_status = atomic_read(&adapter->status);
143 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
144 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
145 return 0;
146 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
147 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
148 /* fall through */
149 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
150 a_status = atomic_read(&adapter->status);
151 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
152 return 0;
Christof Schmitt143bb6b2009-08-18 15:43:27 +0200153 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) &&
154 !(a_status & ZFCP_STATUS_COMMON_OPEN))
155 return 0; /* shutdown requested for closed adapter */
Christof Schmitt287ac012008-07-02 10:56:40 +0200156 }
157
158 return need;
159}
160
161static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
162 struct zfcp_adapter *adapter,
163 struct zfcp_port *port,
164 struct zfcp_unit *unit)
165{
166 struct zfcp_erp_action *erp_action;
167 u32 status = 0;
168
169 switch (need) {
170 case ZFCP_ERP_ACTION_REOPEN_UNIT:
171 zfcp_unit_get(unit);
172 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
173 erp_action = &unit->erp_action;
174 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
175 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
176 break;
177
178 case ZFCP_ERP_ACTION_REOPEN_PORT:
179 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
180 zfcp_port_get(port);
181 zfcp_erp_action_dismiss_port(port);
182 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
183 erp_action = &port->erp_action;
184 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
185 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
186 break;
187
188 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
189 zfcp_adapter_get(adapter);
190 zfcp_erp_action_dismiss_adapter(adapter);
191 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
192 erp_action = &adapter->erp_action;
193 if (!(atomic_read(&adapter->status) &
194 ZFCP_STATUS_COMMON_RUNNING))
195 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
196 break;
197
198 default:
199 return NULL;
200 }
201
202 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
203 erp_action->adapter = adapter;
204 erp_action->port = port;
205 erp_action->unit = unit;
206 erp_action->action = need;
207 erp_action->status = status;
208
209 return erp_action;
210}
211
212static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
213 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100214 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200215{
216 int retval = 1, need;
217 struct zfcp_erp_action *act = NULL;
218
Christof Schmitt347c6a92009-08-18 15:43:25 +0200219 if (!adapter->erp_thread)
Christof Schmitt287ac012008-07-02 10:56:40 +0200220 return -EIO;
221
222 need = zfcp_erp_required_act(want, adapter, port, unit);
223 if (!need)
224 goto out;
225
226 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
227 act = zfcp_erp_setup_act(need, adapter, port, unit);
228 if (!act)
229 goto out;
230 ++adapter->erp_total_count;
231 list_add_tail(&act->list, &adapter->erp_ready_head);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200232 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +0200233 zfcp_dbf_rec_thread("eracte1", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200234 retval = 0;
235 out:
Swen Schillig57717102009-08-18 15:43:21 +0200236 zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200237 return retval;
238}
239
240static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100241 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200242{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100244 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Christof Schmitt287ac012008-07-02 10:56:40 +0200246 /* ensure propagation of failed status to new devices */
247 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100248 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200249 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200251 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
252 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200256 * zfcp_erp_adapter_reopen - Reopen adapter.
257 * @adapter: Adapter to reopen.
258 * @clear: Status flags to clear.
259 * @id: Id for debug trace event.
260 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200262void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100263 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
Christof Schmitt287ac012008-07-02 10:56:40 +0200265 unsigned long flags;
266
267 read_lock_irqsave(&zfcp_data.config_lock, flags);
268 write_lock(&adapter->erp_lock);
269 _zfcp_erp_adapter_reopen(adapter, clear, id, ref);
270 write_unlock(&adapter->erp_lock);
271 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
272}
273
274/**
275 * zfcp_erp_adapter_shutdown - Shutdown adapter.
276 * @adapter: Adapter to shut down.
277 * @clear: Status flags to clear.
278 * @id: Id for debug trace event.
279 * @ref: Reference for debug trace event.
280 */
281void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100282 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200283{
284 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
285 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
286}
287
288/**
289 * zfcp_erp_port_shutdown - Shutdown port
290 * @port: Port to shut down.
291 * @clear: Status flags to clear.
292 * @id: Id for debug trace event.
293 * @ref: Reference for debug trace event.
294 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100295void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
296 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200297{
298 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
299 zfcp_erp_port_reopen(port, clear | flags, id, ref);
300}
301
302/**
303 * zfcp_erp_unit_shutdown - Shutdown unit
304 * @unit: Unit to shut down.
305 * @clear: Status flags to clear.
306 * @id: Id for debug trace event.
307 * @ref: Reference for debug trace event.
308 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100309void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
310 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200311{
312 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
313 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
314}
315
316static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
317{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100318 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200319 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
320 ZFCP_CLEAR);
321}
322
323static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100324 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200325{
326 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100327 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200328
329 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
330 return;
331
332 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
333 port->adapter, port, NULL, id, ref);
334}
335
336/**
337 * zfcp_erp_port_forced_reopen - Forced close of port and open again
338 * @port: Port to force close and to reopen.
339 * @id: Id for debug trace event.
340 * @ref: Reference for debug trace event.
341 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100342void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200343 void *ref)
344{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 unsigned long flags;
346 struct zfcp_adapter *adapter = port->adapter;
347
348 read_lock_irqsave(&zfcp_data.config_lock, flags);
349 write_lock(&adapter->erp_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200350 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
351 write_unlock(&adapter->erp_lock);
352 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
353}
354
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100355static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200356 void *ref)
357{
358 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100359 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200360
361 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
362 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100363 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200364 return -EIO;
365 }
366
367 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
368 port->adapter, port, NULL, id, ref);
369}
370
371/**
372 * zfcp_erp_port_reopen - trigger remote port recovery
373 * @port: port to recover
374 * @clear_mask: flags in port status to be cleared
375 *
376 * Returns 0 if recovery has been triggered, < 0 if not.
377 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100378int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200379{
380 unsigned long flags;
381 int retval;
382 struct zfcp_adapter *adapter = port->adapter;
383
384 read_lock_irqsave(&zfcp_data.config_lock, flags);
385 write_lock(&adapter->erp_lock);
386 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 write_unlock(&adapter->erp_lock);
388 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
389
390 return retval;
391}
392
Christof Schmitt287ac012008-07-02 10:56:40 +0200393static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100395 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200396 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
397 ZFCP_CLEAR);
398}
399
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100400static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200401 void *ref)
402{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 struct zfcp_adapter *adapter = unit->port->adapter;
404
Christof Schmitt287ac012008-07-02 10:56:40 +0200405 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Christof Schmitt287ac012008-07-02 10:56:40 +0200407 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
408 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Christof Schmitt287ac012008-07-02 10:56:40 +0200410 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
411 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414/**
415 * zfcp_erp_unit_reopen - initiate reopen of a unit
416 * @unit: unit to be reopened
417 * @clear_mask: specifies flags in unit status to be cleared
418 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100420void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
421 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200424 struct zfcp_port *port = unit->port;
425 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 read_lock_irqsave(&zfcp_data.config_lock, flags);
428 write_lock(&adapter->erp_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200429 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 write_unlock(&adapter->erp_lock);
431 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
Christof Schmitt287ac012008-07-02 10:56:40 +0200434static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Christof Schmitt287ac012008-07-02 10:56:40 +0200436 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Christof Schmitt287ac012008-07-02 10:56:40 +0200439static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100440{
Christof Schmitt287ac012008-07-02 10:56:40 +0200441 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100442}
443
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200444static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445{
Christof Schmitt287ac012008-07-02 10:56:40 +0200446 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +0200447 zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200448 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
450
Christof Schmitt287ac012008-07-02 10:56:40 +0200451static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452{
Christof Schmitt287ac012008-07-02 10:56:40 +0200453 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +0200454 zfcp_dbf_rec_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200455 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
Christof Schmitt287ac012008-07-02 10:56:40 +0200458static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Christof Schmitt287ac012008-07-02 10:56:40 +0200460 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +0200461 zfcp_dbf_rec_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200462 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463}
464
Christof Schmitt287ac012008-07-02 10:56:40 +0200465static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466{
Christof Schmitt287ac012008-07-02 10:56:40 +0200467 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig57717102009-08-18 15:43:21 +0200468 zfcp_dbf_rec_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
Christof Schmitt287ac012008-07-02 10:56:40 +0200471static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Christof Schmitt287ac012008-07-02 10:56:40 +0200473 struct zfcp_adapter *adapter = act->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Christof Schmitt287ac012008-07-02 10:56:40 +0200475 if (!act->fsf_req)
476 return;
477
478 spin_lock(&adapter->req_list_lock);
479 if (zfcp_reqlist_find_safe(adapter, act->fsf_req) &&
480 act->fsf_req->erp_action == act) {
481 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
482 ZFCP_STATUS_ERP_TIMEDOUT)) {
483 act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig57717102009-08-18 15:43:21 +0200484 zfcp_dbf_rec_action("erscf_1", act);
Martin Petermann7ea633f2008-11-04 16:35:11 +0100485 act->fsf_req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200487 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig57717102009-08-18 15:43:21 +0200488 zfcp_dbf_rec_action("erscf_2", act);
Swen Schillig058b8642009-08-18 15:43:14 +0200489 if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
Christof Schmitt287ac012008-07-02 10:56:40 +0200490 act->fsf_req = NULL;
491 } else
492 act->fsf_req = NULL;
493 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200496/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200497 * zfcp_erp_notify - Trigger ERP action.
498 * @erp_action: ERP action to continue.
499 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200501void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
503 struct zfcp_adapter *adapter = erp_action->adapter;
504 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200507 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
508 erp_action->status |= set_mask;
509 zfcp_erp_action_ready(erp_action);
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512}
513
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200514/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200515 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
516 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200518void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Christof Schmitt287ac012008-07-02 10:56:40 +0200520 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
521 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522}
523
Christof Schmitt287ac012008-07-02 10:56:40 +0200524static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Christof Schmitt287ac012008-07-02 10:56:40 +0200526 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527}
528
Christof Schmitt287ac012008-07-02 10:56:40 +0200529static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 init_timer(&erp_action->timer);
532 erp_action->timer.function = zfcp_erp_memwait_handler;
533 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200534 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200536}
537
538static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100539 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200540{
541 struct zfcp_port *port;
542
543 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200544 _zfcp_erp_port_reopen(port, clear, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200545}
546
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100547static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
548 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200549{
550 struct zfcp_unit *unit;
551
552 list_for_each_entry(unit, &port->unit_list_head, list)
553 _zfcp_erp_unit_reopen(unit, clear, id, ref);
554}
555
Christof Schmitt85600f72009-07-13 15:06:09 +0200556static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200557{
Christof Schmitt287ac012008-07-02 10:56:40 +0200558 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200559 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200560 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200561 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200562 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200563 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200564 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200565 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200566 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200567 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200568 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200569 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
570 break;
571 }
572}
573
574static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
575{
576 switch (act->action) {
577 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
578 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
579 break;
580 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
581 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
582 break;
583 case ZFCP_ERP_ACTION_REOPEN_PORT:
584 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200585 break;
586 }
587}
588
589static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
590{
591 unsigned long flags;
592
593 read_lock_irqsave(&zfcp_data.config_lock, flags);
594 read_lock(&adapter->erp_lock);
595 if (list_empty(&adapter->erp_ready_head) &&
596 list_empty(&adapter->erp_running_head)) {
597 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
598 &adapter->status);
599 wake_up(&adapter->erp_done_wqh);
600 }
601 read_unlock(&adapter->erp_lock);
602 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
603}
604
605static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
606{
Swen Schillig564e1c82009-08-18 15:43:19 +0200607 struct zfcp_qdio *qdio = act->adapter->qdio;
608
609 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200610 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200611 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200612 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
613 return ZFCP_ERP_SUCCEEDED;
614}
615
616static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
617{
618 struct zfcp_port *port;
619 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
620 adapter->peer_d_id);
621 if (IS_ERR(port)) /* error or port already attached */
622 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100623 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200624}
625
626static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
627{
628 int retries;
629 int sleep = 1;
630 struct zfcp_adapter *adapter = erp_action->adapter;
631
632 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
633
634 for (retries = 7; retries; retries--) {
635 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
636 &adapter->status);
637 write_lock_irq(&adapter->erp_lock);
638 zfcp_erp_action_to_running(erp_action);
639 write_unlock_irq(&adapter->erp_lock);
640 if (zfcp_fsf_exchange_config_data(erp_action)) {
641 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
642 &adapter->status);
643 return ZFCP_ERP_FAILED;
644 }
645
Swen Schillig57717102009-08-18 15:43:21 +0200646 zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200647 wait_event(adapter->erp_ready_wq,
648 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200649 zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200650 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
651 break;
652
653 if (!(atomic_read(&adapter->status) &
654 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
655 break;
656
657 ssleep(sleep);
658 sleep *= 2;
659 }
660
661 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
662 &adapter->status);
663
664 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
665 return ZFCP_ERP_FAILED;
666
667 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
668 zfcp_erp_enqueue_ptp_port(adapter);
669
670 return ZFCP_ERP_SUCCEEDED;
671}
672
673static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
674{
675 int ret;
676 struct zfcp_adapter *adapter = act->adapter;
677
Christof Schmitt287ac012008-07-02 10:56:40 +0200678 write_lock_irq(&adapter->erp_lock);
679 zfcp_erp_action_to_running(act);
680 write_unlock_irq(&adapter->erp_lock);
681
682 ret = zfcp_fsf_exchange_port_data(act);
683 if (ret == -EOPNOTSUPP)
684 return ZFCP_ERP_SUCCEEDED;
685 if (ret)
686 return ZFCP_ERP_FAILED;
687
Swen Schillig57717102009-08-18 15:43:21 +0200688 zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200689 wait_event(adapter->erp_ready_wq,
690 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200691 zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200692 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
693 return ZFCP_ERP_FAILED;
694
695 return ZFCP_ERP_SUCCEEDED;
696}
697
698static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
699{
700 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
701 return ZFCP_ERP_FAILED;
702
703 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
704 return ZFCP_ERP_FAILED;
705
706 atomic_set(&act->adapter->stat_miss, 16);
707 if (zfcp_status_read_refill(act->adapter))
708 return ZFCP_ERP_FAILED;
709
710 return ZFCP_ERP_SUCCEEDED;
711}
712
Swen Schilligcf13c082009-03-02 13:09:03 +0100713static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200714{
Christof Schmitt287ac012008-07-02 10:56:40 +0200715 struct zfcp_adapter *adapter = act->adapter;
716
Christof Schmitt287ac012008-07-02 10:56:40 +0200717 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200718 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200719 zfcp_fsf_req_dismiss_all(adapter);
720 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200721 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200722 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100723 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200724 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100725
Christof Schmitt287ac012008-07-02 10:56:40 +0200726 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100727 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
728}
729
730static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
731{
732 struct zfcp_adapter *adapter = act->adapter;
733
734 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
735 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
736 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
737 &adapter->status);
738 return ZFCP_ERP_FAILED;
739 }
740
741 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
742 zfcp_erp_adapter_strategy_close(act);
743 return ZFCP_ERP_FAILED;
744 }
745
746 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
747
748 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200749}
750
751static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
752{
Swen Schilligcf13c082009-03-02 13:09:03 +0100753 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200754
Swen Schilligcf13c082009-03-02 13:09:03 +0100755 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
756 zfcp_erp_adapter_strategy_close(act);
757 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
758 return ZFCP_ERP_EXIT;
759 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200760
Swen Schilligcf13c082009-03-02 13:09:03 +0100761 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200762 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100763 return ZFCP_ERP_FAILED;
764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Swen Schilligcf13c082009-03-02 13:09:03 +0100766 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
Christof Schmitt287ac012008-07-02 10:56:40 +0200769static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
Christof Schmitt287ac012008-07-02 10:56:40 +0200771 int retval;
772
773 retval = zfcp_fsf_close_physical_port(act);
774 if (retval == -ENOMEM)
775 return ZFCP_ERP_NOMEM;
776 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
777 if (retval)
778 return ZFCP_ERP_FAILED;
779
780 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781}
782
Christof Schmitt287ac012008-07-02 10:56:40 +0200783static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100785 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200786}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Christof Schmitt287ac012008-07-02 10:56:40 +0200788static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
789{
790 struct zfcp_port *port = erp_action->port;
791 int status = atomic_read(&port->status);
792
793 switch (erp_action->step) {
794 case ZFCP_ERP_STEP_UNINITIALIZED:
795 zfcp_erp_port_strategy_clearstati(port);
796 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
797 (status & ZFCP_STATUS_COMMON_OPEN))
798 return zfcp_erp_port_forced_strategy_close(erp_action);
799 else
800 return ZFCP_ERP_FAILED;
801
802 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200803 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200804 return ZFCP_ERP_SUCCEEDED;
805 }
806 return ZFCP_ERP_FAILED;
807}
808
809static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
810{
811 int retval;
812
813 retval = zfcp_fsf_close_port(erp_action);
814 if (retval == -ENOMEM)
815 return ZFCP_ERP_NOMEM;
816 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
817 if (retval)
818 return ZFCP_ERP_FAILED;
819 return ZFCP_ERP_CONTINUES;
820}
821
822static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
823{
824 int retval;
825
826 retval = zfcp_fsf_open_port(erp_action);
827 if (retval == -ENOMEM)
828 return ZFCP_ERP_NOMEM;
829 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
830 if (retval)
831 return ZFCP_ERP_FAILED;
832 return ZFCP_ERP_CONTINUES;
833}
834
Christof Schmitt287ac012008-07-02 10:56:40 +0200835static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
836{
837 struct zfcp_adapter *adapter = act->adapter;
838 struct zfcp_port *port = act->port;
839
840 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100841 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200842 return ZFCP_ERP_FAILED;
843 }
844 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200845 return zfcp_erp_port_strategy_open_port(act);
846}
847
848static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
849{
850 struct zfcp_adapter *adapter = act->adapter;
851 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200852 int p_status = atomic_read(&port->status);
853
854 switch (act->step) {
855 case ZFCP_ERP_STEP_UNINITIALIZED:
856 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
857 case ZFCP_ERP_STEP_PORT_CLOSING:
858 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
859 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100860 if (!port->d_id) {
Swen Schillig947a9ac2009-03-02 13:09:10 +0100861 zfcp_port_get(port);
Swen Schillig45446832009-08-18 15:43:17 +0200862 if (!queue_work(adapter->work_queue,
Swen Schillig947a9ac2009-03-02 13:09:10 +0100863 &port->gid_pn_work))
864 zfcp_port_put(port);
Christof Schmitt799b76d2009-08-18 15:43:20 +0200865 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200866 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200867 return zfcp_erp_port_strategy_open_port(act);
868
869 case ZFCP_ERP_STEP_PORT_OPENING:
870 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200871 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmittb98478d2008-12-19 16:56:59 +0100872 if (port->d_id)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200873 return ZFCP_ERP_SUCCEEDED;
874 else {
875 act->step = ZFCP_ERP_STEP_PORT_CLOSING;
876 return ZFCP_ERP_CONTINUES;
877 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200878 }
Swen Schilligea460a82009-05-15 13:18:20 +0200879 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
880 port->d_id = 0;
881 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
882 return ZFCP_ERP_EXIT;
883 }
884 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200885 }
886 return ZFCP_ERP_FAILED;
887}
888
Christof Schmitt287ac012008-07-02 10:56:40 +0200889static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
890{
891 struct zfcp_port *port = erp_action->port;
892
Swen Schillig5ab944f2008-10-01 12:42:17 +0200893 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC)
894 goto close_init_done;
895
Christof Schmitt287ac012008-07-02 10:56:40 +0200896 switch (erp_action->step) {
897 case ZFCP_ERP_STEP_UNINITIALIZED:
898 zfcp_erp_port_strategy_clearstati(port);
899 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
900 return zfcp_erp_port_strategy_close(erp_action);
901 break;
902
903 case ZFCP_ERP_STEP_PORT_CLOSING:
904 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN)
905 return ZFCP_ERP_FAILED;
906 break;
907 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200908
909close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200910 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
911 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200912
Swen Schillig5ab944f2008-10-01 12:42:17 +0200913 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914}
915
Christof Schmitt287ac012008-07-02 10:56:40 +0200916static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200918 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200919 ZFCP_STATUS_UNIT_SHARED |
920 ZFCP_STATUS_UNIT_READONLY,
921 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922}
923
Christof Schmitt287ac012008-07-02 10:56:40 +0200924static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
925{
926 int retval = zfcp_fsf_close_unit(erp_action);
927 if (retval == -ENOMEM)
928 return ZFCP_ERP_NOMEM;
929 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
930 if (retval)
931 return ZFCP_ERP_FAILED;
932 return ZFCP_ERP_CONTINUES;
933}
934
935static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
936{
937 int retval = zfcp_fsf_open_unit(erp_action);
938 if (retval == -ENOMEM)
939 return ZFCP_ERP_NOMEM;
940 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
941 if (retval)
942 return ZFCP_ERP_FAILED;
943 return ZFCP_ERP_CONTINUES;
944}
945
946static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
947{
948 struct zfcp_unit *unit = erp_action->unit;
949
950 switch (erp_action->step) {
951 case ZFCP_ERP_STEP_UNINITIALIZED:
952 zfcp_erp_unit_strategy_clearstati(unit);
953 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
954 return zfcp_erp_unit_strategy_close(erp_action);
955 /* already closed, fall through */
956 case ZFCP_ERP_STEP_UNIT_CLOSING:
957 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
958 return ZFCP_ERP_FAILED;
959 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
960 return ZFCP_ERP_EXIT;
961 return zfcp_erp_unit_strategy_open(erp_action);
962
963 case ZFCP_ERP_STEP_UNIT_OPENING:
964 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
965 return ZFCP_ERP_SUCCEEDED;
966 }
967 return ZFCP_ERP_FAILED;
968}
969
970static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
971{
972 switch (result) {
973 case ZFCP_ERP_SUCCEEDED :
974 atomic_set(&unit->erp_counter, 0);
975 zfcp_erp_unit_unblock(unit);
976 break;
977 case ZFCP_ERP_FAILED :
978 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200979 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
980 dev_err(&unit->port->adapter->ccw_device->dev,
981 "ERP failed for unit 0x%016Lx on "
982 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +0200983 (unsigned long long)unit->fcp_lun,
984 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100985 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200986 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200987 break;
988 }
989
990 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
991 zfcp_erp_unit_block(unit, 0);
992 result = ZFCP_ERP_EXIT;
993 }
994 return result;
995}
996
997static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
998{
999 switch (result) {
1000 case ZFCP_ERP_SUCCEEDED :
1001 atomic_set(&port->erp_counter, 0);
1002 zfcp_erp_port_unblock(port);
1003 break;
1004
1005 case ZFCP_ERP_FAILED :
1006 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1007 zfcp_erp_port_block(port, 0);
1008 result = ZFCP_ERP_EXIT;
1009 }
1010 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001011 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1012 dev_err(&port->adapter->ccw_device->dev,
1013 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001014 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001015 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001016 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001017 break;
1018 }
1019
1020 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1021 zfcp_erp_port_block(port, 0);
1022 result = ZFCP_ERP_EXIT;
1023 }
1024 return result;
1025}
1026
1027static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1028 int result)
1029{
1030 switch (result) {
1031 case ZFCP_ERP_SUCCEEDED :
1032 atomic_set(&adapter->erp_counter, 0);
1033 zfcp_erp_adapter_unblock(adapter);
1034 break;
1035
1036 case ZFCP_ERP_FAILED :
1037 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001038 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1039 dev_err(&adapter->ccw_device->dev,
1040 "ERP cannot recover an error "
1041 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001042 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001043 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001044 break;
1045 }
1046
1047 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1048 zfcp_erp_adapter_block(adapter, 0);
1049 result = ZFCP_ERP_EXIT;
1050 }
1051 return result;
1052}
1053
1054static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1055 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
1057 struct zfcp_adapter *adapter = erp_action->adapter;
1058 struct zfcp_port *port = erp_action->port;
1059 struct zfcp_unit *unit = erp_action->unit;
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 switch (erp_action->action) {
1062
1063 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1064 result = zfcp_erp_strategy_check_unit(unit, result);
1065 break;
1066
1067 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1068 case ZFCP_ERP_ACTION_REOPEN_PORT:
1069 result = zfcp_erp_strategy_check_port(port, result);
1070 break;
1071
1072 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1073 result = zfcp_erp_strategy_check_adapter(adapter, result);
1074 break;
1075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 return result;
1077}
1078
Christof Schmitt287ac012008-07-02 10:56:40 +02001079static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Christof Schmitt287ac012008-07-02 10:56:40 +02001081 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Christof Schmitt287ac012008-07-02 10:56:40 +02001083 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1084 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1085 return 1; /* take it online */
1086
1087 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1088 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1089 return 1; /* take it offline */
1090
1091 return 0;
1092}
1093
1094static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1095{
1096 int action = act->action;
1097 struct zfcp_adapter *adapter = act->adapter;
1098 struct zfcp_port *port = act->port;
1099 struct zfcp_unit *unit = act->unit;
1100 u32 erp_status = act->status;
1101
1102 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001104 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1105 _zfcp_erp_adapter_reopen(adapter,
1106 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001107 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001108 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 }
1110 break;
1111
1112 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1113 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001114 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1115 _zfcp_erp_port_reopen(port,
1116 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001117 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001118 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 break;
1121
1122 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001123 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1124 _zfcp_erp_unit_reopen(unit,
1125 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001126 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001127 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 }
1129 break;
1130 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001131 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Christof Schmitt287ac012008-07-02 10:56:40 +02001134static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135{
Christof Schmitt287ac012008-07-02 10:56:40 +02001136 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
Christof Schmitt287ac012008-07-02 10:56:40 +02001138 adapter->erp_total_count--;
1139 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1140 adapter->erp_low_mem_count--;
1141 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 }
1143
Christof Schmitt287ac012008-07-02 10:56:40 +02001144 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001145 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Christof Schmitt287ac012008-07-02 10:56:40 +02001147 switch (erp_action->action) {
1148 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1149 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1150 &erp_action->unit->status);
1151 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Christof Schmitt287ac012008-07-02 10:56:40 +02001153 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1154 case ZFCP_ERP_ACTION_REOPEN_PORT:
1155 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1156 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001158
1159 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1160 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1161 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
1163 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Christof Schmitt287ac012008-07-02 10:56:40 +02001166static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001167{
Christof Schmitt287ac012008-07-02 10:56:40 +02001168 struct zfcp_adapter *adapter = act->adapter;
1169 struct zfcp_port *port = act->port;
1170 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001171
Christof Schmitt287ac012008-07-02 10:56:40 +02001172 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001174 if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) {
Swen Schillig92d51932009-04-17 15:08:04 +02001175 zfcp_unit_get(unit);
1176 if (scsi_queue_work(unit->port->adapter->scsi_host,
1177 &unit->scsi_work) <= 0)
1178 zfcp_unit_put(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01001179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 zfcp_unit_put(unit);
1181 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1184 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001185 if (result == ZFCP_ERP_SUCCEEDED)
1186 zfcp_scsi_schedule_rport_register(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 zfcp_port_put(port);
1188 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001191 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001192 register_service_level(&adapter->service_level);
Swen Schilligfca55b62008-11-26 18:07:40 +01001193 schedule_work(&adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001194 } else
1195 unregister_service_level(&adapter->service_level);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 zfcp_adapter_put(adapter);
1197 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 }
1199}
1200
Christof Schmitt287ac012008-07-02 10:56:40 +02001201static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1202{
1203 switch (erp_action->action) {
1204 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1205 return zfcp_erp_adapter_strategy(erp_action);
1206 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1207 return zfcp_erp_port_forced_strategy(erp_action);
1208 case ZFCP_ERP_ACTION_REOPEN_PORT:
1209 return zfcp_erp_port_strategy(erp_action);
1210 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1211 return zfcp_erp_unit_strategy(erp_action);
1212 }
1213 return ZFCP_ERP_FAILED;
1214}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Christof Schmitt287ac012008-07-02 10:56:40 +02001216static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1217{
1218 int retval;
1219 struct zfcp_adapter *adapter = erp_action->adapter;
1220 unsigned long flags;
1221
1222 read_lock_irqsave(&zfcp_data.config_lock, flags);
1223 write_lock(&adapter->erp_lock);
1224
1225 zfcp_erp_strategy_check_fsfreq(erp_action);
1226
1227 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1228 zfcp_erp_action_dequeue(erp_action);
1229 retval = ZFCP_ERP_DISMISSED;
1230 goto unlock;
1231 }
1232
1233 zfcp_erp_action_to_running(erp_action);
1234
1235 /* no lock to allow for blocking operations */
1236 write_unlock(&adapter->erp_lock);
1237 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1238 retval = zfcp_erp_strategy_do_action(erp_action);
1239 read_lock_irqsave(&zfcp_data.config_lock, flags);
1240 write_lock(&adapter->erp_lock);
1241
1242 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1243 retval = ZFCP_ERP_CONTINUES;
1244
1245 switch (retval) {
1246 case ZFCP_ERP_NOMEM:
1247 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1248 ++adapter->erp_low_mem_count;
1249 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1250 }
1251 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001252 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001253 else {
1254 zfcp_erp_strategy_memwait(erp_action);
1255 retval = ZFCP_ERP_CONTINUES;
1256 }
1257 goto unlock;
1258
1259 case ZFCP_ERP_CONTINUES:
1260 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1261 --adapter->erp_low_mem_count;
1262 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1263 }
1264 goto unlock;
1265 }
1266
1267 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1268 zfcp_erp_action_dequeue(erp_action);
1269 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1270 if (retval == ZFCP_ERP_EXIT)
1271 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001272 if (retval == ZFCP_ERP_SUCCEEDED)
1273 zfcp_erp_strategy_followup_success(erp_action);
1274 if (retval == ZFCP_ERP_FAILED)
1275 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001276
1277 unlock:
1278 write_unlock(&adapter->erp_lock);
1279 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1280
1281 if (retval != ZFCP_ERP_CONTINUES)
1282 zfcp_erp_action_cleanup(erp_action, retval);
1283
1284 return retval;
1285}
1286
1287static int zfcp_erp_thread(void *data)
1288{
1289 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1290 struct list_head *next;
1291 struct zfcp_erp_action *act;
1292 unsigned long flags;
1293
Christof Schmitt347c6a92009-08-18 15:43:25 +02001294 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001295 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001296 wait_event_interruptible(adapter->erp_ready_wq,
1297 !list_empty(&adapter->erp_ready_head) ||
1298 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001299 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001300
Christof Schmitt347c6a92009-08-18 15:43:25 +02001301 if (kthread_should_stop())
1302 break;
1303
Christof Schmitt287ac012008-07-02 10:56:40 +02001304 write_lock_irqsave(&adapter->erp_lock, flags);
1305 next = adapter->erp_ready_head.next;
1306 write_unlock_irqrestore(&adapter->erp_lock, flags);
1307
1308 if (next != &adapter->erp_ready_head) {
1309 act = list_entry(next, struct zfcp_erp_action, list);
1310
1311 /* there is more to come after dismission, no notify */
1312 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1313 zfcp_erp_wakeup(adapter);
1314 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001315 }
1316
Christof Schmitt287ac012008-07-02 10:56:40 +02001317 return 0;
1318}
1319
1320/**
1321 * zfcp_erp_thread_setup - Start ERP thread for adapter
1322 * @adapter: Adapter to start the ERP thread for
1323 *
1324 * Returns 0 on success or error code from kernel_thread()
1325 */
1326int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1327{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001328 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001329
Christof Schmitt347c6a92009-08-18 15:43:25 +02001330 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1331 dev_name(&adapter->ccw_device->dev));
1332 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001333 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001334 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001335 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001336 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001337
1338 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001339 return 0;
1340}
1341
1342/**
1343 * zfcp_erp_thread_kill - Stop ERP thread.
1344 * @adapter: Adapter where the ERP thread should be stopped.
1345 *
1346 * The caller of this routine ensures that the specified adapter has
1347 * been shut down and that this operation has been completed. Thus,
1348 * there are no pending erp_actions which would need to be handled
1349 * here.
1350 */
1351void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1352{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001353 kthread_stop(adapter->erp_thread);
1354 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001355 WARN_ON(!list_empty(&adapter->erp_ready_head));
1356 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001357}
1358
1359/**
1360 * zfcp_erp_adapter_failed - Set adapter status to failed.
1361 * @adapter: Failed adapter.
1362 * @id: Event id for debug trace.
1363 * @ref: Reference for debug trace.
1364 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001365void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001366{
1367 zfcp_erp_modify_adapter_status(adapter, id, ref,
1368 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001369}
1370
1371/**
1372 * zfcp_erp_port_failed - Set port status to failed.
1373 * @port: Failed port.
1374 * @id: Event id for debug trace.
1375 * @ref: Reference for debug trace.
1376 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001377void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001378{
1379 zfcp_erp_modify_port_status(port, id, ref,
1380 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001381}
1382
1383/**
1384 * zfcp_erp_unit_failed - Set unit status to failed.
1385 * @unit: Failed unit.
1386 * @id: Event id for debug trace.
1387 * @ref: Reference for debug trace.
1388 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001389void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001390{
1391 zfcp_erp_modify_unit_status(unit, id, ref,
1392 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001393}
1394
1395/**
1396 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1397 * @adapter: adapter for which to wait for completion of its error recovery
1398 */
1399void zfcp_erp_wait(struct zfcp_adapter *adapter)
1400{
1401 wait_event(adapter->erp_done_wqh,
1402 !(atomic_read(&adapter->status) &
1403 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1404}
1405
1406/**
1407 * zfcp_erp_modify_adapter_status - change adapter status bits
1408 * @adapter: adapter to change the status
1409 * @id: id for the debug trace
1410 * @ref: reference for the debug trace
1411 * @mask: status bits to change
1412 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1413 *
1414 * Changes in common status bits are propagated to attached ports and units.
1415 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001416void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001417 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 struct zfcp_port *port;
Christof Schmitt287ac012008-07-02 10:56:40 +02001420 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Christof Schmitt287ac012008-07-02 10:56:40 +02001422 if (set_or_clear == ZFCP_SET) {
1423 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001424 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001425 atomic_set_mask(mask, &adapter->status);
1426 } else {
1427 if (status_change_clear(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_clear_mask(mask, &adapter->status);
1430 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1431 atomic_set(&adapter->erp_counter, 0);
1432 }
1433
1434 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 list_for_each_entry(port, &adapter->port_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001436 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1437 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438}
1439
Christof Schmitt287ac012008-07-02 10:56:40 +02001440/**
1441 * zfcp_erp_modify_port_status - change port status bits
1442 * @port: port to change the status bits
1443 * @id: id for the debug trace
1444 * @ref: reference for the debug trace
1445 * @mask: status bits to change
1446 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1447 *
1448 * Changes in common status bits are propagated to attached units.
1449 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001450void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001451 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 struct zfcp_unit *unit;
Christof Schmitt287ac012008-07-02 10:56:40 +02001454 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
Christof Schmitt287ac012008-07-02 10:56:40 +02001456 if (set_or_clear == ZFCP_SET) {
1457 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001458 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001459 atomic_set_mask(mask, &port->status);
1460 } else {
1461 if (status_change_clear(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001462 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001463 atomic_clear_mask(mask, &port->status);
1464 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1465 atomic_set(&port->erp_counter, 0);
1466 }
1467
1468 if (common_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 list_for_each_entry(unit, &port->unit_list_head, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001470 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1471 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Christof Schmitt287ac012008-07-02 10:56:40 +02001474/**
1475 * zfcp_erp_modify_unit_status - change unit status bits
1476 * @unit: unit to change the status bits
1477 * @id: id for the debug trace
1478 * @ref: reference for the debug trace
1479 * @mask: status bits to change
1480 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1481 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001482void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001483 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484{
Christof Schmitt287ac012008-07-02 10:56:40 +02001485 if (set_or_clear == ZFCP_SET) {
1486 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001487 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001488 atomic_set_mask(mask, &unit->status);
1489 } else {
1490 if (status_change_clear(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001491 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001492 atomic_clear_mask(mask, &unit->status);
1493 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1494 atomic_set(&unit->erp_counter, 0);
1495 }
1496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497}
1498
Christof Schmitt287ac012008-07-02 10:56:40 +02001499/**
1500 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1501 * @port: The "boxed" port.
1502 * @id: The debug trace id.
1503 * @id: Reference for the debug trace.
1504 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001505void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001506{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001507 unsigned long flags;
1508
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001509 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001510 zfcp_erp_modify_port_status(port, id, ref,
1511 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001512 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001513 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001514}
1515
Christof Schmitt287ac012008-07-02 10:56:40 +02001516/**
1517 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1518 * @port: The "boxed" unit.
1519 * @id: The debug trace id.
1520 * @id: Reference for the debug trace.
1521 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001522void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001523{
Martin Peschke698ec0162008-03-27 14:22:02 +01001524 zfcp_erp_modify_unit_status(unit, id, ref,
1525 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001526 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001527}
1528
Christof Schmitt287ac012008-07-02 10:56:40 +02001529/**
1530 * zfcp_erp_port_access_denied - Adapter denied access to port.
1531 * @port: port where access has been denied
1532 * @id: id for debug trace
1533 * @ref: reference for debug trace
1534 *
1535 * Since the adapter has denied access, stop using the port and the
1536 * attached units.
1537 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001538void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 unsigned long flags;
1541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01001543 zfcp_erp_modify_port_status(port, id, ref,
1544 ZFCP_STATUS_COMMON_ERP_FAILED |
1545 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1547}
1548
Christof Schmitt287ac012008-07-02 10:56:40 +02001549/**
1550 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1551 * @unit: unit where access has been denied
1552 * @id: id for debug trace
1553 * @ref: reference for debug trace
1554 *
1555 * Since the adapter has denied access, stop using the unit.
1556 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001557void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
Martin Peschke698ec0162008-03-27 14:22:02 +01001559 zfcp_erp_modify_unit_status(unit, id, ref,
1560 ZFCP_STATUS_COMMON_ERP_FAILED |
1561 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562}
1563
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001564static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001565 void *ref)
1566{
1567 int status = atomic_read(&unit->status);
1568 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1569 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1570 return;
1571
1572 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1573}
1574
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001575static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001576 void *ref)
1577{
1578 struct zfcp_unit *unit;
1579 int status = atomic_read(&port->status);
1580
1581 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1582 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schillig5ab944f2008-10-01 12:42:17 +02001583 list_for_each_entry(unit, &port->unit_list_head, list)
1584 zfcp_erp_unit_access_changed(unit, id, ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001585 return;
1586 }
1587
1588 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1589}
1590
1591/**
1592 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1593 * @adapter: Adapter where the Access Control Table (ACT) changed
1594 * @id: Id for debug trace
1595 * @ref: Reference for debug trace
1596 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001597void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001598 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
1600 struct zfcp_port *port;
1601 unsigned long flags;
1602
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001603 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1604 return;
1605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 read_lock_irqsave(&zfcp_data.config_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 list_for_each_entry(port, &adapter->port_list_head, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001608 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1610}