blob: 160b432c907f393cb1d134f0398964874ede3cdc [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Christof Schmitt553448f2008-06-10 18:20:58 +02002 * zfcp device driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Christof Schmitt553448f2008-06-10 18:20:58 +02004 * Error Recovery Procedures (ERP).
Swen Schillig41fa2ad2007-09-07 09:15:31 +02005 *
Christof Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2002, 2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Christof Schmitt347c6a92009-08-18 15:43:25 +020012#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include "zfcp_ext.h"
Christof Schmittb6bd2fb2010-02-17 11:18:50 +010014#include "zfcp_reqlist.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Christof Schmitt287ac012008-07-02 10:56:40 +020016#define ZFCP_MAX_ERPS 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Christof Schmitt287ac012008-07-02 10:56:40 +020018enum zfcp_erp_act_flags {
19 ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000,
20 ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000,
21 ZFCP_STATUS_ERP_DISMISSING = 0x00100000,
22 ZFCP_STATUS_ERP_DISMISSED = 0x00200000,
23 ZFCP_STATUS_ERP_LOWMEM = 0x00400000,
24};
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Christof Schmitt287ac012008-07-02 10:56:40 +020026enum zfcp_erp_steps {
27 ZFCP_ERP_STEP_UNINITIALIZED = 0x0000,
28 ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001,
29 ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010,
30 ZFCP_ERP_STEP_PORT_CLOSING = 0x0100,
Christof Schmitt287ac012008-07-02 10:56:40 +020031 ZFCP_ERP_STEP_PORT_OPENING = 0x0800,
32 ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000,
33 ZFCP_ERP_STEP_UNIT_OPENING = 0x2000,
34};
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Christof Schmitt287ac012008-07-02 10:56:40 +020036enum zfcp_erp_act_type {
37 ZFCP_ERP_ACTION_REOPEN_UNIT = 1,
38 ZFCP_ERP_ACTION_REOPEN_PORT = 2,
39 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3,
40 ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4,
41};
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Christof Schmitt287ac012008-07-02 10:56:40 +020043enum zfcp_erp_act_state {
44 ZFCP_ERP_ACTION_RUNNING = 1,
45 ZFCP_ERP_ACTION_READY = 2,
46};
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Christof Schmitt287ac012008-07-02 10:56:40 +020048enum zfcp_erp_act_result {
49 ZFCP_ERP_SUCCEEDED = 0,
50 ZFCP_ERP_FAILED = 1,
51 ZFCP_ERP_CONTINUES = 2,
52 ZFCP_ERP_EXIT = 3,
53 ZFCP_ERP_DISMISSED = 4,
54 ZFCP_ERP_NOMEM = 5,
55};
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Christof Schmitt287ac012008-07-02 10:56:40 +020057static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask)
Andreas Herrmann2abbe862006-09-18 22:29:56 +020058{
Swen Schillig5ffd51a2009-03-02 13:09:04 +010059 zfcp_erp_modify_adapter_status(adapter, "erablk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +020060 ZFCP_STATUS_COMMON_UNBLOCKED | mask,
61 ZFCP_CLEAR);
Andreas Herrmann2abbe862006-09-18 22:29:56 +020062}
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Christof Schmitt287ac012008-07-02 10:56:40 +020064static int zfcp_erp_action_exists(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Christof Schmitt287ac012008-07-02 10:56:40 +020066 struct zfcp_erp_action *curr_act;
67
68 list_for_each_entry(curr_act, &act->adapter->erp_running_head, list)
69 if (act == curr_act)
70 return ZFCP_ERP_ACTION_RUNNING;
71 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Christof Schmitt287ac012008-07-02 10:56:40 +020074static void zfcp_erp_action_ready(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Christof Schmitt287ac012008-07-02 10:56:40 +020076 struct zfcp_adapter *adapter = act->adapter;
77
78 list_move(&act->list, &act->adapter->erp_ready_head);
Swen Schillig57717102009-08-18 15:43:21 +020079 zfcp_dbf_rec_action("erardy1", act);
Christof Schmitt347c6a92009-08-18 15:43:25 +020080 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +020081 zfcp_dbf_rec_thread("erardy2", adapter->dbf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Christof Schmitt287ac012008-07-02 10:56:40 +020084static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Christof Schmitt287ac012008-07-02 10:56:40 +020086 act->status |= ZFCP_STATUS_ERP_DISMISSED;
87 if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING)
88 zfcp_erp_action_ready(act);
89}
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Christof Schmitt287ac012008-07-02 10:56:40 +020091static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
92{
93 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
94 zfcp_erp_action_dismiss(&unit->erp_action);
95}
96
97static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
98{
99 struct zfcp_unit *unit;
100
101 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
102 zfcp_erp_action_dismiss(&port->erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +0100103 else {
104 read_lock(&port->unit_list_lock);
105 list_for_each_entry(unit, &port->unit_list, list)
106 zfcp_erp_action_dismiss_unit(unit);
107 read_unlock(&port->unit_list_lock);
108 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200109}
110
111static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
112{
113 struct zfcp_port *port;
114
115 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE)
116 zfcp_erp_action_dismiss(&adapter->erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +0100117 else {
118 read_lock(&adapter->port_list_lock);
119 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200120 zfcp_erp_action_dismiss_port(port);
Swen Schilligecf0c772009-11-24 16:53:58 +0100121 read_unlock(&adapter->port_list_lock);
122 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200123}
124
125static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter,
126 struct zfcp_port *port,
127 struct zfcp_unit *unit)
128{
129 int need = want;
130 int u_status, p_status, a_status;
131
132 switch (want) {
133 case ZFCP_ERP_ACTION_REOPEN_UNIT:
134 u_status = atomic_read(&unit->status);
135 if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE)
136 return 0;
137 p_status = atomic_read(&port->status);
138 if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) ||
139 p_status & ZFCP_STATUS_COMMON_ERP_FAILED)
140 return 0;
141 if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED))
142 need = ZFCP_ERP_ACTION_REOPEN_PORT;
143 /* fall through */
Christof Schmitt287ac012008-07-02 10:56:40 +0200144 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
145 p_status = atomic_read(&port->status);
Christof Schmitt097ef3b2010-07-08 09:53:06 +0200146 if (!(p_status & ZFCP_STATUS_COMMON_OPEN))
147 need = ZFCP_ERP_ACTION_REOPEN_PORT;
148 /* fall through */
149 case ZFCP_ERP_ACTION_REOPEN_PORT:
150 p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200151 if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE)
152 return 0;
153 a_status = atomic_read(&adapter->status);
154 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) ||
155 a_status & ZFCP_STATUS_COMMON_ERP_FAILED)
156 return 0;
157 if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED))
158 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
159 /* fall through */
160 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
161 a_status = atomic_read(&adapter->status);
162 if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE)
163 return 0;
Christof Schmitt143bb6b2009-08-18 15:43:27 +0200164 if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) &&
165 !(a_status & ZFCP_STATUS_COMMON_OPEN))
166 return 0; /* shutdown requested for closed adapter */
Christof Schmitt287ac012008-07-02 10:56:40 +0200167 }
168
169 return need;
170}
171
172static struct zfcp_erp_action *zfcp_erp_setup_act(int need,
173 struct zfcp_adapter *adapter,
174 struct zfcp_port *port,
175 struct zfcp_unit *unit)
176{
177 struct zfcp_erp_action *erp_action;
178 u32 status = 0;
179
180 switch (need) {
181 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt615f59e2010-02-17 11:18:56 +0100182 if (!get_device(&unit->dev))
Swen Schillig6b183332009-11-24 16:54:05 +0100183 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200184 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
185 erp_action = &unit->erp_action;
186 if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING))
187 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
188 break;
189
190 case ZFCP_ERP_ACTION_REOPEN_PORT:
191 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt615f59e2010-02-17 11:18:56 +0100192 if (!get_device(&port->dev))
Swen Schillig6b183332009-11-24 16:54:05 +0100193 return NULL;
Christof Schmitt287ac012008-07-02 10:56:40 +0200194 zfcp_erp_action_dismiss_port(port);
195 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
196 erp_action = &port->erp_action;
197 if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING))
198 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
199 break;
200
201 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Swen Schilligf3450c72009-11-24 16:53:59 +0100202 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +0200203 zfcp_erp_action_dismiss_adapter(adapter);
204 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
205 erp_action = &adapter->erp_action;
206 if (!(atomic_read(&adapter->status) &
207 ZFCP_STATUS_COMMON_RUNNING))
208 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
209 break;
210
211 default:
212 return NULL;
213 }
214
215 memset(erp_action, 0, sizeof(struct zfcp_erp_action));
216 erp_action->adapter = adapter;
217 erp_action->port = port;
218 erp_action->unit = unit;
219 erp_action->action = need;
220 erp_action->status = status;
221
222 return erp_action;
223}
224
225static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
226 struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100227 struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200228{
229 int retval = 1, need;
230 struct zfcp_erp_action *act = NULL;
231
Christof Schmitt347c6a92009-08-18 15:43:25 +0200232 if (!adapter->erp_thread)
Christof Schmitt287ac012008-07-02 10:56:40 +0200233 return -EIO;
234
235 need = zfcp_erp_required_act(want, adapter, port, unit);
236 if (!need)
237 goto out;
238
239 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
240 act = zfcp_erp_setup_act(need, adapter, port, unit);
241 if (!act)
242 goto out;
243 ++adapter->erp_total_count;
244 list_add_tail(&act->list, &adapter->erp_ready_head);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200245 wake_up(&adapter->erp_ready_wq);
Swen Schillig57717102009-08-18 15:43:21 +0200246 zfcp_dbf_rec_thread("eracte1", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200247 retval = 0;
248 out:
Swen Schillig57717102009-08-18 15:43:21 +0200249 zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200250 return retval;
251}
252
253static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100254 int clear_mask, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200255{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 zfcp_erp_adapter_block(adapter, clear_mask);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100257 zfcp_scsi_schedule_rports_block(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Christof Schmitt287ac012008-07-02 10:56:40 +0200259 /* ensure propagation of failed status to new devices */
260 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100261 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200262 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200264 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
265 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200269 * zfcp_erp_adapter_reopen - Reopen adapter.
270 * @adapter: Adapter to reopen.
271 * @clear: Status flags to clear.
272 * @id: Id for debug trace event.
273 * @ref: Reference for debug trace event.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200275void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100276 char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Christof Schmitt287ac012008-07-02 10:56:40 +0200278 unsigned long flags;
279
Swen Schilligecf0c772009-11-24 16:53:58 +0100280 zfcp_erp_adapter_block(adapter, clear);
281 zfcp_scsi_schedule_rports_block(adapter);
282
283 write_lock_irqsave(&adapter->erp_lock, flags);
284 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
285 zfcp_erp_adapter_failed(adapter, "erareo1", NULL);
286 else
287 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, adapter,
288 NULL, NULL, id, ref);
289 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200290}
291
292/**
293 * zfcp_erp_adapter_shutdown - Shutdown adapter.
294 * @adapter: Adapter to shut down.
295 * @clear: Status flags to clear.
296 * @id: Id for debug trace event.
297 * @ref: Reference for debug trace event.
298 */
299void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100300 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200301{
302 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
303 zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref);
304}
305
306/**
307 * zfcp_erp_port_shutdown - Shutdown port
308 * @port: Port to shut down.
309 * @clear: Status flags to clear.
310 * @id: Id for debug trace event.
311 * @ref: Reference for debug trace event.
312 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100313void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id,
314 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200315{
316 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
317 zfcp_erp_port_reopen(port, clear | flags, id, ref);
318}
319
320/**
321 * zfcp_erp_unit_shutdown - Shutdown unit
322 * @unit: Unit to shut down.
323 * @clear: Status flags to clear.
324 * @id: Id for debug trace event.
325 * @ref: Reference for debug trace event.
326 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100327void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id,
328 void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200329{
330 int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED;
331 zfcp_erp_unit_reopen(unit, clear | flags, id, ref);
332}
333
334static void zfcp_erp_port_block(struct zfcp_port *port, int clear)
335{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100336 zfcp_erp_modify_port_status(port, "erpblk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200337 ZFCP_STATUS_COMMON_UNBLOCKED | clear,
338 ZFCP_CLEAR);
339}
340
341static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100342 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200343{
344 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100345 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200346
347 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
348 return;
349
350 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
351 port->adapter, port, NULL, id, ref);
352}
353
354/**
355 * zfcp_erp_port_forced_reopen - Forced close of port and open again
356 * @port: Port to force close and to reopen.
357 * @id: Id for debug trace event.
358 * @ref: Reference for debug trace event.
359 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100360void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200361 void *ref)
362{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 unsigned long flags;
364 struct zfcp_adapter *adapter = port->adapter;
365
Swen Schilligecf0c772009-11-24 16:53:58 +0100366 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200367 _zfcp_erp_port_forced_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100368 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200369}
370
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100371static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200372 void *ref)
373{
374 zfcp_erp_port_block(port, clear);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +0100375 zfcp_scsi_schedule_rport_block(port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200376
377 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
378 /* ensure propagation of failed status to new devices */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100379 zfcp_erp_port_failed(port, "erpreo1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200380 return -EIO;
381 }
382
383 return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
384 port->adapter, port, NULL, id, ref);
385}
386
387/**
388 * zfcp_erp_port_reopen - trigger remote port recovery
389 * @port: port to recover
390 * @clear_mask: flags in port status to be cleared
391 *
392 * Returns 0 if recovery has been triggered, < 0 if not.
393 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100394int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200395{
Christof Schmitt287ac012008-07-02 10:56:40 +0200396 int retval;
Swen Schilligecf0c772009-11-24 16:53:58 +0100397 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200398 struct zfcp_adapter *adapter = port->adapter;
399
Swen Schilligecf0c772009-11-24 16:53:58 +0100400 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200401 retval = _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100402 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 return retval;
405}
406
Christof Schmitt287ac012008-07-02 10:56:40 +0200407static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100409 zfcp_erp_modify_unit_status(unit, "erublk1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200410 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
411 ZFCP_CLEAR);
412}
413
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100414static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +0200415 void *ref)
416{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 struct zfcp_adapter *adapter = unit->port->adapter;
418
Christof Schmitt287ac012008-07-02 10:56:40 +0200419 zfcp_erp_unit_block(unit, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Christof Schmitt287ac012008-07-02 10:56:40 +0200421 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
422 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Christof Schmitt287ac012008-07-02 10:56:40 +0200424 zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
425 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
428/**
429 * zfcp_erp_unit_reopen - initiate reopen of a unit
430 * @unit: unit to be reopened
431 * @clear_mask: specifies flags in unit status to be cleared
432 * Return: 0 on success, < 0 on error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100434void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id,
435 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +0200438 struct zfcp_port *port = unit->port;
439 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Swen Schilligecf0c772009-11-24 16:53:58 +0100441 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200442 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100443 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444}
445
Christof Schmitt287ac012008-07-02 10:56:40 +0200446static int status_change_set(unsigned long mask, atomic_t *status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Christof Schmitt287ac012008-07-02 10:56:40 +0200448 return (atomic_read(status) ^ mask) & mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449}
450
Christof Schmitt287ac012008-07-02 10:56:40 +0200451static int status_change_clear(unsigned long mask, atomic_t *status)
Martin Peschke698ec0162008-03-27 14:22:02 +0100452{
Christof Schmitt287ac012008-07-02 10:56:40 +0200453 return atomic_read(status) & mask;
Martin Peschke698ec0162008-03-27 14:22:02 +0100454}
455
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200456static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457{
Christof Schmitt287ac012008-07-02 10:56:40 +0200458 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +0200459 zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200460 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
Christof Schmitt287ac012008-07-02 10:56:40 +0200463static void zfcp_erp_port_unblock(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Christof Schmitt287ac012008-07-02 10:56:40 +0200465 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +0200466 zfcp_dbf_rec_port("erpubl1", NULL, port);
Christof Schmitt287ac012008-07-02 10:56:40 +0200467 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Christof Schmitt287ac012008-07-02 10:56:40 +0200470static void zfcp_erp_unit_unblock(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Christof Schmitt287ac012008-07-02 10:56:40 +0200472 if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +0200473 zfcp_dbf_rec_unit("eruubl1", NULL, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +0200474 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
Christof Schmitt287ac012008-07-02 10:56:40 +0200477static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Christof Schmitt287ac012008-07-02 10:56:40 +0200479 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Swen Schillig57717102009-08-18 15:43:21 +0200480 zfcp_dbf_rec_action("erator1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481}
482
Christof Schmitt287ac012008-07-02 10:56:40 +0200483static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Christof Schmitt287ac012008-07-02 10:56:40 +0200485 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitte60a6d62010-02-17 11:18:49 +0100486 struct zfcp_fsf_req *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Christof Schmitte60a6d62010-02-17 11:18:49 +0100488 if (!act->fsf_req_id)
Christof Schmitt287ac012008-07-02 10:56:40 +0200489 return;
490
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100491 spin_lock(&adapter->req_list->lock);
492 req = _zfcp_reqlist_find(adapter->req_list, act->fsf_req_id);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100493 if (req && req->erp_action == act) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200494 if (act->status & (ZFCP_STATUS_ERP_DISMISSED |
495 ZFCP_STATUS_ERP_TIMEDOUT)) {
Christof Schmitte60a6d62010-02-17 11:18:49 +0100496 req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
Swen Schillig57717102009-08-18 15:43:21 +0200497 zfcp_dbf_rec_action("erscf_1", act);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100498 req->erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200500 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
Swen Schillig57717102009-08-18 15:43:21 +0200501 zfcp_dbf_rec_action("erscf_2", act);
Christof Schmitte60a6d62010-02-17 11:18:49 +0100502 if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED)
503 act->fsf_req_id = 0;
Christof Schmitt287ac012008-07-02 10:56:40 +0200504 } else
Christof Schmitte60a6d62010-02-17 11:18:49 +0100505 act->fsf_req_id = 0;
Christof Schmittb6bd2fb2010-02-17 11:18:50 +0100506 spin_unlock(&adapter->req_list->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200509/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200510 * zfcp_erp_notify - Trigger ERP action.
511 * @erp_action: ERP action to continue.
512 * @set_mask: ERP action status flags to set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200514void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 struct zfcp_adapter *adapter = erp_action->adapter;
517 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
519 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200520 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
521 erp_action->status |= set_mask;
522 zfcp_erp_action_ready(erp_action);
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200527/**
Christof Schmitt287ac012008-07-02 10:56:40 +0200528 * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request
529 * @data: ERP action (from timer data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 */
Christof Schmitt287ac012008-07-02 10:56:40 +0200531void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532{
Christof Schmitt287ac012008-07-02 10:56:40 +0200533 struct zfcp_erp_action *act = (struct zfcp_erp_action *) data;
534 zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
Christof Schmitt287ac012008-07-02 10:56:40 +0200537static void zfcp_erp_memwait_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Christof Schmitt287ac012008-07-02 10:56:40 +0200539 zfcp_erp_notify((struct zfcp_erp_action *)data, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540}
541
Christof Schmitt287ac012008-07-02 10:56:40 +0200542static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 init_timer(&erp_action->timer);
545 erp_action->timer.function = zfcp_erp_memwait_handler;
546 erp_action->timer.data = (unsigned long) erp_action;
Christof Schmitt287ac012008-07-02 10:56:40 +0200547 erp_action->timer.expires = jiffies + HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 add_timer(&erp_action->timer);
Christof Schmitt287ac012008-07-02 10:56:40 +0200549}
550
551static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter,
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100552 int clear, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200553{
554 struct zfcp_port *port;
555
Swen Schilligecf0c772009-11-24 16:53:58 +0100556 read_lock(&adapter->port_list_lock);
557 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +0200558 _zfcp_erp_port_reopen(port, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100559 read_unlock(&adapter->port_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200560}
561
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100562static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear,
563 char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +0200564{
565 struct zfcp_unit *unit;
566
Swen Schilligecf0c772009-11-24 16:53:58 +0100567 read_lock(&port->unit_list_lock);
568 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +0200569 _zfcp_erp_unit_reopen(unit, clear, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +0100570 read_unlock(&port->unit_list_lock);
Christof Schmitt287ac012008-07-02 10:56:40 +0200571}
572
Christof Schmitt85600f72009-07-13 15:06:09 +0200573static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200574{
Christof Schmitt287ac012008-07-02 10:56:40 +0200575 switch (act->action) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200576 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt85600f72009-07-13 15:06:09 +0200577 _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200578 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200579 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt85600f72009-07-13 15:06:09 +0200580 _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200581 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200582 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200583 _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200584 break;
Christof Schmitt287ac012008-07-02 10:56:40 +0200585 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt85600f72009-07-13 15:06:09 +0200586 _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL);
587 break;
588 }
589}
590
591static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act)
592{
593 switch (act->action) {
594 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
595 _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL);
596 break;
597 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
598 _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL);
599 break;
600 case ZFCP_ERP_ACTION_REOPEN_PORT:
601 _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200602 break;
603 }
604}
605
606static void zfcp_erp_wakeup(struct zfcp_adapter *adapter)
607{
608 unsigned long flags;
609
Swen Schilligecf0c772009-11-24 16:53:58 +0100610 read_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200611 if (list_empty(&adapter->erp_ready_head) &&
612 list_empty(&adapter->erp_running_head)) {
613 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
614 &adapter->status);
615 wake_up(&adapter->erp_done_wqh);
616 }
Swen Schilligecf0c772009-11-24 16:53:58 +0100617 read_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +0200618}
619
620static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act)
621{
Swen Schillig564e1c82009-08-18 15:43:19 +0200622 struct zfcp_qdio *qdio = act->adapter->qdio;
623
624 if (zfcp_qdio_open(qdio))
Christof Schmitt287ac012008-07-02 10:56:40 +0200625 return ZFCP_ERP_FAILED;
Swen Schillig564e1c82009-08-18 15:43:19 +0200626 init_waitqueue_head(&qdio->req_q_wq);
Christof Schmitt287ac012008-07-02 10:56:40 +0200627 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status);
628 return ZFCP_ERP_SUCCEEDED;
629}
630
631static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter)
632{
633 struct zfcp_port *port;
634 port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0,
635 adapter->peer_d_id);
636 if (IS_ERR(port)) /* error or port already attached */
637 return;
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100638 _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200639}
640
641static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action)
642{
643 int retries;
644 int sleep = 1;
645 struct zfcp_adapter *adapter = erp_action->adapter;
646
647 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
648
649 for (retries = 7; retries; retries--) {
650 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
651 &adapter->status);
652 write_lock_irq(&adapter->erp_lock);
653 zfcp_erp_action_to_running(erp_action);
654 write_unlock_irq(&adapter->erp_lock);
655 if (zfcp_fsf_exchange_config_data(erp_action)) {
656 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
657 &adapter->status);
658 return ZFCP_ERP_FAILED;
659 }
660
Swen Schillig57717102009-08-18 15:43:21 +0200661 zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200662 wait_event(adapter->erp_ready_wq,
663 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200664 zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200665 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
666 break;
667
668 if (!(atomic_read(&adapter->status) &
669 ZFCP_STATUS_ADAPTER_HOST_CON_INIT))
670 break;
671
672 ssleep(sleep);
673 sleep *= 2;
674 }
675
676 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
677 &adapter->status);
678
679 if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK))
680 return ZFCP_ERP_FAILED;
681
682 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
683 zfcp_erp_enqueue_ptp_port(adapter);
684
685 return ZFCP_ERP_SUCCEEDED;
686}
687
688static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act)
689{
690 int ret;
691 struct zfcp_adapter *adapter = act->adapter;
692
Christof Schmitt287ac012008-07-02 10:56:40 +0200693 write_lock_irq(&adapter->erp_lock);
694 zfcp_erp_action_to_running(act);
695 write_unlock_irq(&adapter->erp_lock);
696
697 ret = zfcp_fsf_exchange_port_data(act);
698 if (ret == -EOPNOTSUPP)
699 return ZFCP_ERP_SUCCEEDED;
700 if (ret)
701 return ZFCP_ERP_FAILED;
702
Swen Schillig57717102009-08-18 15:43:21 +0200703 zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +0200704 wait_event(adapter->erp_ready_wq,
705 !list_empty(&adapter->erp_ready_head));
Swen Schillig57717102009-08-18 15:43:21 +0200706 zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +0200707 if (act->status & ZFCP_STATUS_ERP_TIMEDOUT)
708 return ZFCP_ERP_FAILED;
709
710 return ZFCP_ERP_SUCCEEDED;
711}
712
713static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act)
714{
715 if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED)
716 return ZFCP_ERP_FAILED;
717
718 if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED)
719 return ZFCP_ERP_FAILED;
720
Christof Schmitt8d88cf32010-06-21 10:11:33 +0200721 if (mempool_resize(act->adapter->pool.status_read_data,
722 act->adapter->stat_read_buf_num, GFP_KERNEL))
723 return ZFCP_ERP_FAILED;
724
725 if (mempool_resize(act->adapter->pool.status_read_req,
726 act->adapter->stat_read_buf_num, GFP_KERNEL))
727 return ZFCP_ERP_FAILED;
728
Christof Schmitt64deb6e2010-04-30 18:09:36 +0200729 atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num);
Christof Schmitt287ac012008-07-02 10:56:40 +0200730 if (zfcp_status_read_refill(act->adapter))
731 return ZFCP_ERP_FAILED;
732
733 return ZFCP_ERP_SUCCEEDED;
734}
735
Swen Schilligcf13c082009-03-02 13:09:03 +0100736static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act)
Christof Schmitt287ac012008-07-02 10:56:40 +0200737{
Christof Schmitt287ac012008-07-02 10:56:40 +0200738 struct zfcp_adapter *adapter = act->adapter;
739
Christof Schmitt287ac012008-07-02 10:56:40 +0200740 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig564e1c82009-08-18 15:43:19 +0200741 zfcp_qdio_close(adapter->qdio);
Christof Schmitt287ac012008-07-02 10:56:40 +0200742 zfcp_fsf_req_dismiss_all(adapter);
743 adapter->fsf_req_seq_no = 0;
Christof Schmitt55c770f2009-08-18 15:43:12 +0200744 zfcp_fc_wka_ports_force_offline(adapter->gs);
Christof Schmitt287ac012008-07-02 10:56:40 +0200745 /* all ports and units are closed */
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100746 zfcp_erp_modify_adapter_status(adapter, "erascl1", NULL,
Christof Schmitt287ac012008-07-02 10:56:40 +0200747 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
Swen Schilligcf13c082009-03-02 13:09:03 +0100748
Christof Schmitt287ac012008-07-02 10:56:40 +0200749 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
Swen Schilligcf13c082009-03-02 13:09:03 +0100750 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
751}
752
753static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act)
754{
755 struct zfcp_adapter *adapter = act->adapter;
756
757 if (zfcp_erp_adapter_strategy_open_qdio(act)) {
758 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
759 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
760 &adapter->status);
761 return ZFCP_ERP_FAILED;
762 }
763
764 if (zfcp_erp_adapter_strategy_open_fsf(act)) {
765 zfcp_erp_adapter_strategy_close(act);
766 return ZFCP_ERP_FAILED;
767 }
768
769 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status);
770
771 return ZFCP_ERP_SUCCEEDED;
Christof Schmitt287ac012008-07-02 10:56:40 +0200772}
773
774static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act)
775{
Swen Schilligcf13c082009-03-02 13:09:03 +0100776 struct zfcp_adapter *adapter = act->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +0200777
Swen Schilligcf13c082009-03-02 13:09:03 +0100778 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) {
779 zfcp_erp_adapter_strategy_close(act);
780 if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
781 return ZFCP_ERP_EXIT;
782 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200783
Swen Schilligcf13c082009-03-02 13:09:03 +0100784 if (zfcp_erp_adapter_strategy_open(act)) {
Christof Schmitt287ac012008-07-02 10:56:40 +0200785 ssleep(8);
Swen Schilligcf13c082009-03-02 13:09:03 +0100786 return ZFCP_ERP_FAILED;
787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Swen Schilligcf13c082009-03-02 13:09:03 +0100789 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790}
791
Christof Schmitt287ac012008-07-02 10:56:40 +0200792static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793{
Christof Schmitt287ac012008-07-02 10:56:40 +0200794 int retval;
795
796 retval = zfcp_fsf_close_physical_port(act);
797 if (retval == -ENOMEM)
798 return ZFCP_ERP_NOMEM;
799 act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
800 if (retval)
801 return ZFCP_ERP_FAILED;
802
803 return ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
Christof Schmitt287ac012008-07-02 10:56:40 +0200806static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Christof Schmitta5b11dd2009-03-02 13:08:54 +0100808 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200809}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Christof Schmitt287ac012008-07-02 10:56:40 +0200811static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
812{
813 struct zfcp_port *port = erp_action->port;
814 int status = atomic_read(&port->status);
815
816 switch (erp_action->step) {
817 case ZFCP_ERP_STEP_UNINITIALIZED:
818 zfcp_erp_port_strategy_clearstati(port);
819 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
820 (status & ZFCP_STATUS_COMMON_OPEN))
821 return zfcp_erp_port_forced_strategy_close(erp_action);
822 else
823 return ZFCP_ERP_FAILED;
824
825 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
Christof Schmittddb3e0c2009-07-13 15:06:08 +0200826 if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN))
Christof Schmitt287ac012008-07-02 10:56:40 +0200827 return ZFCP_ERP_SUCCEEDED;
828 }
829 return ZFCP_ERP_FAILED;
830}
831
832static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
833{
834 int retval;
835
836 retval = zfcp_fsf_close_port(erp_action);
837 if (retval == -ENOMEM)
838 return ZFCP_ERP_NOMEM;
839 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
840 if (retval)
841 return ZFCP_ERP_FAILED;
842 return ZFCP_ERP_CONTINUES;
843}
844
845static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
846{
847 int retval;
848
849 retval = zfcp_fsf_open_port(erp_action);
850 if (retval == -ENOMEM)
851 return ZFCP_ERP_NOMEM;
852 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
853 if (retval)
854 return ZFCP_ERP_FAILED;
855 return ZFCP_ERP_CONTINUES;
856}
857
Christof Schmitt287ac012008-07-02 10:56:40 +0200858static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act)
859{
860 struct zfcp_adapter *adapter = act->adapter;
861 struct zfcp_port *port = act->port;
862
863 if (port->wwpn != adapter->peer_wwpn) {
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100864 zfcp_erp_port_failed(port, "eroptp1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +0200865 return ZFCP_ERP_FAILED;
866 }
867 port->d_id = adapter->peer_d_id;
Christof Schmitt287ac012008-07-02 10:56:40 +0200868 return zfcp_erp_port_strategy_open_port(act);
869}
870
871static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act)
872{
873 struct zfcp_adapter *adapter = act->adapter;
874 struct zfcp_port *port = act->port;
Christof Schmitt287ac012008-07-02 10:56:40 +0200875 int p_status = atomic_read(&port->status);
876
877 switch (act->step) {
878 case ZFCP_ERP_STEP_UNINITIALIZED:
879 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
880 case ZFCP_ERP_STEP_PORT_CLOSING:
881 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP)
882 return zfcp_erp_open_ptp_port(act);
Christof Schmittb98478d2008-12-19 16:56:59 +0100883 if (!port->d_id) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200884 zfcp_fc_trigger_did_lookup(port);
Christof Schmitt799b76d2009-08-18 15:43:20 +0200885 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200886 }
Christof Schmitt287ac012008-07-02 10:56:40 +0200887 return zfcp_erp_port_strategy_open_port(act);
888
889 case ZFCP_ERP_STEP_PORT_OPENING:
890 /* D_ID might have changed during open */
Swen Schillig5ab944f2008-10-01 12:42:17 +0200891 if (p_status & ZFCP_STATUS_COMMON_OPEN) {
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200892 if (!port->d_id) {
893 zfcp_fc_trigger_did_lookup(port);
894 return ZFCP_ERP_EXIT;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200895 }
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200896 return ZFCP_ERP_SUCCEEDED;
Swen Schillig5ab944f2008-10-01 12:42:17 +0200897 }
Swen Schilligea460a82009-05-15 13:18:20 +0200898 if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) {
899 port->d_id = 0;
Christof Schmittf7bd7c32010-07-08 09:53:10 +0200900 return ZFCP_ERP_FAILED;
Swen Schilligea460a82009-05-15 13:18:20 +0200901 }
902 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200903 }
904 return ZFCP_ERP_FAILED;
905}
906
Christof Schmitt287ac012008-07-02 10:56:40 +0200907static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
908{
909 struct zfcp_port *port = erp_action->port;
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200910 int p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200911
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200912 if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
913 !(p_status & ZFCP_STATUS_COMMON_OPEN))
Swen Schillig5ab944f2008-10-01 12:42:17 +0200914 goto close_init_done;
915
Christof Schmitt287ac012008-07-02 10:56:40 +0200916 switch (erp_action->step) {
917 case ZFCP_ERP_STEP_UNINITIALIZED:
918 zfcp_erp_port_strategy_clearstati(port);
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200919 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200920 return zfcp_erp_port_strategy_close(erp_action);
921 break;
922
923 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200924 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200925 return ZFCP_ERP_FAILED;
926 break;
927 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200928
929close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200930 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
931 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200932
Swen Schillig5ab944f2008-10-01 12:42:17 +0200933 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
Christof Schmitt287ac012008-07-02 10:56:40 +0200936static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200938 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200939 ZFCP_STATUS_UNIT_SHARED |
940 ZFCP_STATUS_UNIT_READONLY,
941 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
Christof Schmitt287ac012008-07-02 10:56:40 +0200944static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
945{
946 int retval = zfcp_fsf_close_unit(erp_action);
947 if (retval == -ENOMEM)
948 return ZFCP_ERP_NOMEM;
949 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
950 if (retval)
951 return ZFCP_ERP_FAILED;
952 return ZFCP_ERP_CONTINUES;
953}
954
955static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
956{
957 int retval = zfcp_fsf_open_unit(erp_action);
958 if (retval == -ENOMEM)
959 return ZFCP_ERP_NOMEM;
960 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
961 if (retval)
962 return ZFCP_ERP_FAILED;
963 return ZFCP_ERP_CONTINUES;
964}
965
966static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
967{
968 struct zfcp_unit *unit = erp_action->unit;
969
970 switch (erp_action->step) {
971 case ZFCP_ERP_STEP_UNINITIALIZED:
972 zfcp_erp_unit_strategy_clearstati(unit);
973 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
974 return zfcp_erp_unit_strategy_close(erp_action);
975 /* already closed, fall through */
976 case ZFCP_ERP_STEP_UNIT_CLOSING:
977 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
978 return ZFCP_ERP_FAILED;
979 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
980 return ZFCP_ERP_EXIT;
981 return zfcp_erp_unit_strategy_open(erp_action);
982
983 case ZFCP_ERP_STEP_UNIT_OPENING:
984 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
985 return ZFCP_ERP_SUCCEEDED;
986 }
987 return ZFCP_ERP_FAILED;
988}
989
990static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
991{
992 switch (result) {
993 case ZFCP_ERP_SUCCEEDED :
994 atomic_set(&unit->erp_counter, 0);
995 zfcp_erp_unit_unblock(unit);
996 break;
997 case ZFCP_ERP_FAILED :
998 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +0200999 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
1000 dev_err(&unit->port->adapter->ccw_device->dev,
1001 "ERP failed for unit 0x%016Lx on "
1002 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001003 (unsigned long long)unit->fcp_lun,
1004 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001005 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001006 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001007 break;
1008 }
1009
1010 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1011 zfcp_erp_unit_block(unit, 0);
1012 result = ZFCP_ERP_EXIT;
1013 }
1014 return result;
1015}
1016
1017static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1018{
1019 switch (result) {
1020 case ZFCP_ERP_SUCCEEDED :
1021 atomic_set(&port->erp_counter, 0);
1022 zfcp_erp_port_unblock(port);
1023 break;
1024
1025 case ZFCP_ERP_FAILED :
1026 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1027 zfcp_erp_port_block(port, 0);
1028 result = ZFCP_ERP_EXIT;
1029 }
1030 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001031 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1032 dev_err(&port->adapter->ccw_device->dev,
1033 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001034 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001035 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001036 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001037 break;
1038 }
1039
1040 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1041 zfcp_erp_port_block(port, 0);
1042 result = ZFCP_ERP_EXIT;
1043 }
1044 return result;
1045}
1046
1047static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1048 int result)
1049{
1050 switch (result) {
1051 case ZFCP_ERP_SUCCEEDED :
1052 atomic_set(&adapter->erp_counter, 0);
1053 zfcp_erp_adapter_unblock(adapter);
1054 break;
1055
1056 case ZFCP_ERP_FAILED :
1057 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001058 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1059 dev_err(&adapter->ccw_device->dev,
1060 "ERP cannot recover an error "
1061 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001062 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001063 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001064 break;
1065 }
1066
1067 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1068 zfcp_erp_adapter_block(adapter, 0);
1069 result = ZFCP_ERP_EXIT;
1070 }
1071 return result;
1072}
1073
1074static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1075 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076{
1077 struct zfcp_adapter *adapter = erp_action->adapter;
1078 struct zfcp_port *port = erp_action->port;
1079 struct zfcp_unit *unit = erp_action->unit;
1080
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 switch (erp_action->action) {
1082
1083 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1084 result = zfcp_erp_strategy_check_unit(unit, result);
1085 break;
1086
1087 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1088 case ZFCP_ERP_ACTION_REOPEN_PORT:
1089 result = zfcp_erp_strategy_check_port(port, result);
1090 break;
1091
1092 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1093 result = zfcp_erp_strategy_check_adapter(adapter, result);
1094 break;
1095 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 return result;
1097}
1098
Christof Schmitt287ac012008-07-02 10:56:40 +02001099static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100{
Christof Schmitt287ac012008-07-02 10:56:40 +02001101 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
Christof Schmitt287ac012008-07-02 10:56:40 +02001103 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1104 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1105 return 1; /* take it online */
1106
1107 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1108 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1109 return 1; /* take it offline */
1110
1111 return 0;
1112}
1113
1114static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1115{
1116 int action = act->action;
1117 struct zfcp_adapter *adapter = act->adapter;
1118 struct zfcp_port *port = act->port;
1119 struct zfcp_unit *unit = act->unit;
1120 u32 erp_status = act->status;
1121
1122 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001124 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1125 _zfcp_erp_adapter_reopen(adapter,
1126 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001127 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001128 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 }
1130 break;
1131
1132 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1133 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001134 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1135 _zfcp_erp_port_reopen(port,
1136 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001137 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001138 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140 break;
1141
1142 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001143 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1144 _zfcp_erp_unit_reopen(unit,
1145 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001146 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001147 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
1149 break;
1150 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001151 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Christof Schmitt287ac012008-07-02 10:56:40 +02001154static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Christof Schmitt287ac012008-07-02 10:56:40 +02001156 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Christof Schmitt287ac012008-07-02 10:56:40 +02001158 adapter->erp_total_count--;
1159 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1160 adapter->erp_low_mem_count--;
1161 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 }
1163
Christof Schmitt287ac012008-07-02 10:56:40 +02001164 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001165 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Christof Schmitt287ac012008-07-02 10:56:40 +02001167 switch (erp_action->action) {
1168 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1169 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1170 &erp_action->unit->status);
1171 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
Christof Schmitt287ac012008-07-02 10:56:40 +02001173 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1174 case ZFCP_ERP_ACTION_REOPEN_PORT:
1175 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1176 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001178
1179 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1180 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1181 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 break;
1183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184}
1185
Christof Schmitt287ac012008-07-02 10:56:40 +02001186static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001187{
Christof Schmitt287ac012008-07-02 10:56:40 +02001188 struct zfcp_adapter *adapter = act->adapter;
1189 struct zfcp_port *port = act->port;
1190 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001191
Christof Schmitt287ac012008-07-02 10:56:40 +02001192 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001194 put_device(&unit->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001198 if (result == ZFCP_ERP_SUCCEEDED)
1199 zfcp_scsi_schedule_rport_register(port);
Christof Schmitt57676202010-07-08 09:53:05 +02001200 /* fall through */
1201 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001202 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001206 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a422008-12-25 13:38:50 +01001207 register_service_level(&adapter->service_level);
Swen Schillig9eae07e2009-11-24 16:54:06 +01001208 queue_work(adapter->work_queue, &adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001209 } else
1210 unregister_service_level(&adapter->service_level);
Swen Schilligf3450c72009-11-24 16:53:59 +01001211 kref_put(&adapter->ref, zfcp_adapter_release);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214}
1215
Christof Schmitt287ac012008-07-02 10:56:40 +02001216static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1217{
1218 switch (erp_action->action) {
1219 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1220 return zfcp_erp_adapter_strategy(erp_action);
1221 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1222 return zfcp_erp_port_forced_strategy(erp_action);
1223 case ZFCP_ERP_ACTION_REOPEN_PORT:
1224 return zfcp_erp_port_strategy(erp_action);
1225 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1226 return zfcp_erp_unit_strategy(erp_action);
1227 }
1228 return ZFCP_ERP_FAILED;
1229}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Christof Schmitt287ac012008-07-02 10:56:40 +02001231static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1232{
1233 int retval;
Christof Schmitt287ac012008-07-02 10:56:40 +02001234 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001235 struct zfcp_adapter *adapter = erp_action->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +02001236
Swen Schilligf3450c72009-11-24 16:53:59 +01001237 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001238
Swen Schilligf3450c72009-11-24 16:53:59 +01001239 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001240 zfcp_erp_strategy_check_fsfreq(erp_action);
1241
1242 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1243 zfcp_erp_action_dequeue(erp_action);
1244 retval = ZFCP_ERP_DISMISSED;
1245 goto unlock;
1246 }
1247
Christof Schmitt9c785d92010-07-08 09:53:09 +02001248 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1249 retval = ZFCP_ERP_FAILED;
1250 goto check_target;
1251 }
1252
Christof Schmitt287ac012008-07-02 10:56:40 +02001253 zfcp_erp_action_to_running(erp_action);
1254
1255 /* no lock to allow for blocking operations */
Swen Schilligecf0c772009-11-24 16:53:58 +01001256 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001257 retval = zfcp_erp_strategy_do_action(erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +01001258 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001259
1260 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1261 retval = ZFCP_ERP_CONTINUES;
1262
1263 switch (retval) {
1264 case ZFCP_ERP_NOMEM:
1265 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1266 ++adapter->erp_low_mem_count;
1267 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1268 }
1269 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001270 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001271 else {
1272 zfcp_erp_strategy_memwait(erp_action);
1273 retval = ZFCP_ERP_CONTINUES;
1274 }
1275 goto unlock;
1276
1277 case ZFCP_ERP_CONTINUES:
1278 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1279 --adapter->erp_low_mem_count;
1280 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1281 }
1282 goto unlock;
1283 }
1284
Christof Schmitt9c785d92010-07-08 09:53:09 +02001285check_target:
Christof Schmitt287ac012008-07-02 10:56:40 +02001286 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1287 zfcp_erp_action_dequeue(erp_action);
1288 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1289 if (retval == ZFCP_ERP_EXIT)
1290 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001291 if (retval == ZFCP_ERP_SUCCEEDED)
1292 zfcp_erp_strategy_followup_success(erp_action);
1293 if (retval == ZFCP_ERP_FAILED)
1294 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001295
1296 unlock:
Swen Schilligecf0c772009-11-24 16:53:58 +01001297 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001298
1299 if (retval != ZFCP_ERP_CONTINUES)
1300 zfcp_erp_action_cleanup(erp_action, retval);
1301
Swen Schilligf3450c72009-11-24 16:53:59 +01001302 kref_put(&adapter->ref, zfcp_adapter_release);
Christof Schmitt287ac012008-07-02 10:56:40 +02001303 return retval;
1304}
1305
1306static int zfcp_erp_thread(void *data)
1307{
1308 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1309 struct list_head *next;
1310 struct zfcp_erp_action *act;
1311 unsigned long flags;
1312
Christof Schmitt347c6a92009-08-18 15:43:25 +02001313 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001314 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001315 wait_event_interruptible(adapter->erp_ready_wq,
1316 !list_empty(&adapter->erp_ready_head) ||
1317 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001318 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001319
Christof Schmitt347c6a92009-08-18 15:43:25 +02001320 if (kthread_should_stop())
1321 break;
1322
Christof Schmitt287ac012008-07-02 10:56:40 +02001323 write_lock_irqsave(&adapter->erp_lock, flags);
1324 next = adapter->erp_ready_head.next;
1325 write_unlock_irqrestore(&adapter->erp_lock, flags);
1326
1327 if (next != &adapter->erp_ready_head) {
1328 act = list_entry(next, struct zfcp_erp_action, list);
1329
1330 /* there is more to come after dismission, no notify */
1331 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1332 zfcp_erp_wakeup(adapter);
1333 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001334 }
1335
Christof Schmitt287ac012008-07-02 10:56:40 +02001336 return 0;
1337}
1338
1339/**
1340 * zfcp_erp_thread_setup - Start ERP thread for adapter
1341 * @adapter: Adapter to start the ERP thread for
1342 *
1343 * Returns 0 on success or error code from kernel_thread()
1344 */
1345int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1346{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001347 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001348
Christof Schmitt347c6a92009-08-18 15:43:25 +02001349 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1350 dev_name(&adapter->ccw_device->dev));
1351 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001352 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001353 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001354 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001355 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001356
1357 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001358 return 0;
1359}
1360
1361/**
1362 * zfcp_erp_thread_kill - Stop ERP thread.
1363 * @adapter: Adapter where the ERP thread should be stopped.
1364 *
1365 * The caller of this routine ensures that the specified adapter has
1366 * been shut down and that this operation has been completed. Thus,
1367 * there are no pending erp_actions which would need to be handled
1368 * here.
1369 */
1370void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1371{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001372 kthread_stop(adapter->erp_thread);
1373 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001374 WARN_ON(!list_empty(&adapter->erp_ready_head));
1375 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001376}
1377
1378/**
1379 * zfcp_erp_adapter_failed - Set adapter status to failed.
1380 * @adapter: Failed adapter.
1381 * @id: Event id for debug trace.
1382 * @ref: Reference for debug trace.
1383 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001384void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001385{
1386 zfcp_erp_modify_adapter_status(adapter, id, ref,
1387 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001388}
1389
1390/**
1391 * zfcp_erp_port_failed - Set port status to failed.
1392 * @port: Failed port.
1393 * @id: Event id for debug trace.
1394 * @ref: Reference for debug trace.
1395 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001396void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001397{
1398 zfcp_erp_modify_port_status(port, id, ref,
1399 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001400}
1401
1402/**
1403 * zfcp_erp_unit_failed - Set unit status to failed.
1404 * @unit: Failed unit.
1405 * @id: Event id for debug trace.
1406 * @ref: Reference for debug trace.
1407 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001408void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001409{
1410 zfcp_erp_modify_unit_status(unit, id, ref,
1411 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001412}
1413
1414/**
1415 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1416 * @adapter: adapter for which to wait for completion of its error recovery
1417 */
1418void zfcp_erp_wait(struct zfcp_adapter *adapter)
1419{
1420 wait_event(adapter->erp_done_wqh,
1421 !(atomic_read(&adapter->status) &
1422 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1423}
1424
1425/**
1426 * zfcp_erp_modify_adapter_status - change adapter status bits
1427 * @adapter: adapter to change the status
1428 * @id: id for the debug trace
1429 * @ref: reference for the debug trace
1430 * @mask: status bits to change
1431 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1432 *
1433 * Changes in common status bits are propagated to attached ports and units.
1434 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001435void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001436 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 struct zfcp_port *port;
Swen Schilligecf0c772009-11-24 16:53:58 +01001439 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001440 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
Christof Schmitt287ac012008-07-02 10:56:40 +02001442 if (set_or_clear == ZFCP_SET) {
1443 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001444 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001445 atomic_set_mask(mask, &adapter->status);
1446 } else {
1447 if (status_change_clear(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001448 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001449 atomic_clear_mask(mask, &adapter->status);
1450 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1451 atomic_set(&adapter->erp_counter, 0);
1452 }
1453
Swen Schilligecf0c772009-11-24 16:53:58 +01001454 if (common_mask) {
1455 read_lock_irqsave(&adapter->port_list_lock, flags);
1456 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001457 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1458 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001459 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
Christof Schmitt287ac012008-07-02 10:56:40 +02001463/**
1464 * zfcp_erp_modify_port_status - change port status bits
1465 * @port: port to change the status bits
1466 * @id: id for the debug trace
1467 * @ref: reference for the debug trace
1468 * @mask: status bits to change
1469 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1470 *
1471 * Changes in common status bits are propagated to attached units.
1472 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001473void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001474 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001477 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001478 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Christof Schmitt287ac012008-07-02 10:56:40 +02001480 if (set_or_clear == ZFCP_SET) {
1481 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001482 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001483 atomic_set_mask(mask, &port->status);
1484 } else {
1485 if (status_change_clear(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001486 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001487 atomic_clear_mask(mask, &port->status);
1488 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1489 atomic_set(&port->erp_counter, 0);
1490 }
1491
Swen Schilligecf0c772009-11-24 16:53:58 +01001492 if (common_mask) {
1493 read_lock_irqsave(&port->unit_list_lock, flags);
1494 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001495 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1496 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001497 read_unlock_irqrestore(&port->unit_list_lock, flags);
1498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
Christof Schmitt287ac012008-07-02 10:56:40 +02001501/**
1502 * zfcp_erp_modify_unit_status - change unit status bits
1503 * @unit: unit to change the status bits
1504 * @id: id for the debug trace
1505 * @ref: reference for the debug trace
1506 * @mask: status bits to change
1507 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1508 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001509void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001510 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Christof Schmitt287ac012008-07-02 10:56:40 +02001512 if (set_or_clear == ZFCP_SET) {
1513 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001514 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001515 atomic_set_mask(mask, &unit->status);
1516 } else {
1517 if (status_change_clear(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001518 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001519 atomic_clear_mask(mask, &unit->status);
1520 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1521 atomic_set(&unit->erp_counter, 0);
1522 }
1523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524}
1525
Christof Schmitt287ac012008-07-02 10:56:40 +02001526/**
1527 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1528 * @port: The "boxed" port.
1529 * @id: The debug trace id.
1530 * @id: Reference for the debug trace.
1531 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001532void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001533{
Martin Peschke698ec0162008-03-27 14:22:02 +01001534 zfcp_erp_modify_port_status(port, id, ref,
1535 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001536 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001537}
1538
Christof Schmitt287ac012008-07-02 10:56:40 +02001539/**
1540 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1541 * @port: The "boxed" unit.
1542 * @id: The debug trace id.
1543 * @id: Reference for the debug trace.
1544 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001545void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a272005-06-13 13:23:57 +02001546{
Martin Peschke698ec0162008-03-27 14:22:02 +01001547 zfcp_erp_modify_unit_status(unit, id, ref,
1548 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001549 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a272005-06-13 13:23:57 +02001550}
1551
Christof Schmitt287ac012008-07-02 10:56:40 +02001552/**
1553 * zfcp_erp_port_access_denied - Adapter denied access to port.
1554 * @port: port 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 port and the
1559 * attached units.
1560 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001561void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562{
Martin Peschke698ec0162008-03-27 14:22:02 +01001563 zfcp_erp_modify_port_status(port, id, ref,
1564 ZFCP_STATUS_COMMON_ERP_FAILED |
1565 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566}
1567
Christof Schmitt287ac012008-07-02 10:56:40 +02001568/**
1569 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1570 * @unit: unit where access has been denied
1571 * @id: id for debug trace
1572 * @ref: reference for debug trace
1573 *
1574 * Since the adapter has denied access, stop using the unit.
1575 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001576void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
Martin Peschke698ec0162008-03-27 14:22:02 +01001578 zfcp_erp_modify_unit_status(unit, id, ref,
1579 ZFCP_STATUS_COMMON_ERP_FAILED |
1580 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581}
1582
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001583static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001584 void *ref)
1585{
1586 int status = atomic_read(&unit->status);
1587 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1588 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1589 return;
1590
1591 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1592}
1593
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001594static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001595 void *ref)
1596{
1597 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001598 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001599 int status = atomic_read(&port->status);
1600
1601 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1602 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schilligecf0c772009-11-24 16:53:58 +01001603 read_lock_irqsave(&port->unit_list_lock, flags);
1604 list_for_each_entry(unit, &port->unit_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001605 zfcp_erp_unit_access_changed(unit, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001606 read_unlock_irqrestore(&port->unit_list_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001607 return;
1608 }
1609
1610 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1611}
1612
1613/**
1614 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1615 * @adapter: Adapter where the Access Control Table (ACT) changed
1616 * @id: Id for debug trace
1617 * @ref: Reference for debug trace
1618 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001619void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001620 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001623 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001625 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1626 return;
1627
Swen Schilligecf0c772009-11-24 16:53:58 +01001628 read_lock_irqsave(&adapter->port_list_lock, flags);
1629 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001630 zfcp_erp_port_access_changed(port, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001631 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}