blob: 64471ba6ac09ffa5a6faa75bb6b38ba342012b3c [file] [log] [blame]
Swen Schillig41fa2ada2007-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 Schillig41fa2ada2007-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 Schillig6b1833342009-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 Schillig6b1833342009-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;
900 _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL);
901 return ZFCP_ERP_EXIT;
902 }
903 /* fall through otherwise */
Christof Schmitt287ac012008-07-02 10:56:40 +0200904 }
905 return ZFCP_ERP_FAILED;
906}
907
Christof Schmitt287ac012008-07-02 10:56:40 +0200908static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
909{
910 struct zfcp_port *port = erp_action->port;
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200911 int p_status = atomic_read(&port->status);
Christof Schmitt287ac012008-07-02 10:56:40 +0200912
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200913 if ((p_status & ZFCP_STATUS_COMMON_NOESC) &&
914 !(p_status & ZFCP_STATUS_COMMON_OPEN))
Swen Schillig5ab944f2008-10-01 12:42:17 +0200915 goto close_init_done;
916
Christof Schmitt287ac012008-07-02 10:56:40 +0200917 switch (erp_action->step) {
918 case ZFCP_ERP_STEP_UNINITIALIZED:
919 zfcp_erp_port_strategy_clearstati(port);
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200920 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200921 return zfcp_erp_port_strategy_close(erp_action);
922 break;
923
924 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt934aeb5872009-10-14 11:00:43 +0200925 if (p_status & ZFCP_STATUS_COMMON_OPEN)
Christof Schmitt287ac012008-07-02 10:56:40 +0200926 return ZFCP_ERP_FAILED;
927 break;
928 }
Swen Schillig5ab944f2008-10-01 12:42:17 +0200929
930close_init_done:
Christof Schmitt287ac012008-07-02 10:56:40 +0200931 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
932 return ZFCP_ERP_EXIT;
Christof Schmitt287ac012008-07-02 10:56:40 +0200933
Swen Schillig5ab944f2008-10-01 12:42:17 +0200934 return zfcp_erp_port_strategy_open_common(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Christof Schmitt287ac012008-07-02 10:56:40 +0200937static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938{
Swen Schillig44cc76f2008-10-01 12:42:16 +0200939 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
Christof Schmitt287ac012008-07-02 10:56:40 +0200940 ZFCP_STATUS_UNIT_SHARED |
941 ZFCP_STATUS_UNIT_READONLY,
942 &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943}
944
Christof Schmitt287ac012008-07-02 10:56:40 +0200945static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
946{
947 int retval = zfcp_fsf_close_unit(erp_action);
948 if (retval == -ENOMEM)
949 return ZFCP_ERP_NOMEM;
950 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
951 if (retval)
952 return ZFCP_ERP_FAILED;
953 return ZFCP_ERP_CONTINUES;
954}
955
956static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
957{
958 int retval = zfcp_fsf_open_unit(erp_action);
959 if (retval == -ENOMEM)
960 return ZFCP_ERP_NOMEM;
961 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
962 if (retval)
963 return ZFCP_ERP_FAILED;
964 return ZFCP_ERP_CONTINUES;
965}
966
967static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
968{
969 struct zfcp_unit *unit = erp_action->unit;
970
971 switch (erp_action->step) {
972 case ZFCP_ERP_STEP_UNINITIALIZED:
973 zfcp_erp_unit_strategy_clearstati(unit);
974 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
975 return zfcp_erp_unit_strategy_close(erp_action);
976 /* already closed, fall through */
977 case ZFCP_ERP_STEP_UNIT_CLOSING:
978 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
979 return ZFCP_ERP_FAILED;
980 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
981 return ZFCP_ERP_EXIT;
982 return zfcp_erp_unit_strategy_open(erp_action);
983
984 case ZFCP_ERP_STEP_UNIT_OPENING:
985 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN)
986 return ZFCP_ERP_SUCCEEDED;
987 }
988 return ZFCP_ERP_FAILED;
989}
990
991static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
992{
993 switch (result) {
994 case ZFCP_ERP_SUCCEEDED :
995 atomic_set(&unit->erp_counter, 0);
996 zfcp_erp_unit_unblock(unit);
997 break;
998 case ZFCP_ERP_FAILED :
999 atomic_inc(&unit->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001000 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) {
1001 dev_err(&unit->port->adapter->ccw_device->dev,
1002 "ERP failed for unit 0x%016Lx on "
1003 "port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001004 (unsigned long long)unit->fcp_lun,
1005 (unsigned long long)unit->port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001006 zfcp_erp_unit_failed(unit, "erusck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001007 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001008 break;
1009 }
1010
1011 if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1012 zfcp_erp_unit_block(unit, 0);
1013 result = ZFCP_ERP_EXIT;
1014 }
1015 return result;
1016}
1017
1018static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1019{
1020 switch (result) {
1021 case ZFCP_ERP_SUCCEEDED :
1022 atomic_set(&port->erp_counter, 0);
1023 zfcp_erp_port_unblock(port);
1024 break;
1025
1026 case ZFCP_ERP_FAILED :
1027 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) {
1028 zfcp_erp_port_block(port, 0);
1029 result = ZFCP_ERP_EXIT;
1030 }
1031 atomic_inc(&port->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001032 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) {
1033 dev_err(&port->adapter->ccw_device->dev,
1034 "ERP failed for remote port 0x%016Lx\n",
Swen Schillig7ba58c92008-10-01 12:42:18 +02001035 (unsigned long long)port->wwpn);
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001036 zfcp_erp_port_failed(port, "erpsck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001037 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001038 break;
1039 }
1040
1041 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1042 zfcp_erp_port_block(port, 0);
1043 result = ZFCP_ERP_EXIT;
1044 }
1045 return result;
1046}
1047
1048static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter,
1049 int result)
1050{
1051 switch (result) {
1052 case ZFCP_ERP_SUCCEEDED :
1053 atomic_set(&adapter->erp_counter, 0);
1054 zfcp_erp_adapter_unblock(adapter);
1055 break;
1056
1057 case ZFCP_ERP_FAILED :
1058 atomic_inc(&adapter->erp_counter);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001059 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) {
1060 dev_err(&adapter->ccw_device->dev,
1061 "ERP cannot recover an error "
1062 "on the FCP device\n");
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001063 zfcp_erp_adapter_failed(adapter, "erasck1", NULL);
Christof Schmittff3b24f2008-10-01 12:42:15 +02001064 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001065 break;
1066 }
1067
1068 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) {
1069 zfcp_erp_adapter_block(adapter, 0);
1070 result = ZFCP_ERP_EXIT;
1071 }
1072 return result;
1073}
1074
1075static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action,
1076 int result)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
1078 struct zfcp_adapter *adapter = erp_action->adapter;
1079 struct zfcp_port *port = erp_action->port;
1080 struct zfcp_unit *unit = erp_action->unit;
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 switch (erp_action->action) {
1083
1084 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1085 result = zfcp_erp_strategy_check_unit(unit, result);
1086 break;
1087
1088 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1089 case ZFCP_ERP_ACTION_REOPEN_PORT:
1090 result = zfcp_erp_strategy_check_port(port, result);
1091 break;
1092
1093 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1094 result = zfcp_erp_strategy_check_adapter(adapter, result);
1095 break;
1096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 return result;
1098}
1099
Christof Schmitt287ac012008-07-02 10:56:40 +02001100static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Christof Schmitt287ac012008-07-02 10:56:40 +02001102 int status = atomic_read(target_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
Christof Schmitt287ac012008-07-02 10:56:40 +02001104 if ((status & ZFCP_STATUS_COMMON_RUNNING) &&
1105 (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1106 return 1; /* take it online */
1107
1108 if (!(status & ZFCP_STATUS_COMMON_RUNNING) &&
1109 !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY))
1110 return 1; /* take it offline */
1111
1112 return 0;
1113}
1114
1115static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret)
1116{
1117 int action = act->action;
1118 struct zfcp_adapter *adapter = act->adapter;
1119 struct zfcp_port *port = act->port;
1120 struct zfcp_unit *unit = act->unit;
1121 u32 erp_status = act->status;
1122
1123 switch (action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitt287ac012008-07-02 10:56:40 +02001125 if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) {
1126 _zfcp_erp_adapter_reopen(adapter,
1127 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001128 "ersscg1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001129 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
1131 break;
1132
1133 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1134 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001135 if (zfcp_erp_strat_change_det(&port->status, erp_status)) {
1136 _zfcp_erp_port_reopen(port,
1137 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001138 "ersscg2", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001139 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141 break;
1142
1143 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt287ac012008-07-02 10:56:40 +02001144 if (zfcp_erp_strat_change_det(&unit->status, erp_status)) {
1145 _zfcp_erp_unit_reopen(unit,
1146 ZFCP_STATUS_COMMON_ERP_FAILED,
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001147 "ersscg3", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001148 return ZFCP_ERP_EXIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150 break;
1151 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001152 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Christof Schmitt287ac012008-07-02 10:56:40 +02001155static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Christof Schmitt287ac012008-07-02 10:56:40 +02001157 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
Christof Schmitt287ac012008-07-02 10:56:40 +02001159 adapter->erp_total_count--;
1160 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1161 adapter->erp_low_mem_count--;
1162 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164
Christof Schmitt287ac012008-07-02 10:56:40 +02001165 list_del(&erp_action->list);
Swen Schillig57717102009-08-18 15:43:21 +02001166 zfcp_dbf_rec_action("eractd1", erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Christof Schmitt287ac012008-07-02 10:56:40 +02001168 switch (erp_action->action) {
1169 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1170 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1171 &erp_action->unit->status);
1172 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Christof Schmitt287ac012008-07-02 10:56:40 +02001174 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1175 case ZFCP_ERP_ACTION_REOPEN_PORT:
1176 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1177 &erp_action->port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001179
1180 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1181 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
1182 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 break;
1184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Christof Schmitt287ac012008-07-02 10:56:40 +02001187static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001188{
Christof Schmitt287ac012008-07-02 10:56:40 +02001189 struct zfcp_adapter *adapter = act->adapter;
1190 struct zfcp_port *port = act->port;
1191 struct zfcp_unit *unit = act->unit;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001192
Christof Schmitt287ac012008-07-02 10:56:40 +02001193 switch (act->action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001195 put_device(&unit->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 case ZFCP_ERP_ACTION_REOPEN_PORT:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001199 if (result == ZFCP_ERP_SUCCEEDED)
1200 zfcp_scsi_schedule_rport_register(port);
Christof Schmitt57676202010-07-08 09:53:05 +02001201 /* fall through */
1202 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Christof Schmitt615f59e2010-02-17 11:18:56 +01001203 put_device(&port->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 break;
Christof Schmitt287ac012008-07-02 10:56:40 +02001205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001207 if (result == ZFCP_ERP_SUCCEEDED) {
Christof Schmittbd43a42b72008-12-25 13:38:50 +01001208 register_service_level(&adapter->service_level);
Swen Schillig9eae07e2009-11-24 16:54:06 +01001209 queue_work(adapter->work_queue, &adapter->scan_work);
Christof Schmitta2fa0ae2009-03-02 13:09:08 +01001210 } else
1211 unregister_service_level(&adapter->service_level);
Swen Schilligf3450c72009-11-24 16:53:59 +01001212 kref_put(&adapter->ref, zfcp_adapter_release);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215}
1216
Christof Schmitt287ac012008-07-02 10:56:40 +02001217static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1218{
1219 switch (erp_action->action) {
1220 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1221 return zfcp_erp_adapter_strategy(erp_action);
1222 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1223 return zfcp_erp_port_forced_strategy(erp_action);
1224 case ZFCP_ERP_ACTION_REOPEN_PORT:
1225 return zfcp_erp_port_strategy(erp_action);
1226 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1227 return zfcp_erp_unit_strategy(erp_action);
1228 }
1229 return ZFCP_ERP_FAILED;
1230}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Christof Schmitt287ac012008-07-02 10:56:40 +02001232static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1233{
1234 int retval;
Christof Schmitt287ac012008-07-02 10:56:40 +02001235 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001236 struct zfcp_adapter *adapter = erp_action->adapter;
Christof Schmitt287ac012008-07-02 10:56:40 +02001237
Swen Schilligf3450c72009-11-24 16:53:59 +01001238 kref_get(&adapter->ref);
Christof Schmitt287ac012008-07-02 10:56:40 +02001239
Swen Schilligf3450c72009-11-24 16:53:59 +01001240 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001241 zfcp_erp_strategy_check_fsfreq(erp_action);
1242
1243 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1244 zfcp_erp_action_dequeue(erp_action);
1245 retval = ZFCP_ERP_DISMISSED;
1246 goto unlock;
1247 }
1248
Christof Schmitt9c785d92010-07-08 09:53:09 +02001249 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1250 retval = ZFCP_ERP_FAILED;
1251 goto check_target;
1252 }
1253
Christof Schmitt287ac012008-07-02 10:56:40 +02001254 zfcp_erp_action_to_running(erp_action);
1255
1256 /* no lock to allow for blocking operations */
Swen Schilligecf0c772009-11-24 16:53:58 +01001257 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001258 retval = zfcp_erp_strategy_do_action(erp_action);
Swen Schilligecf0c772009-11-24 16:53:58 +01001259 write_lock_irqsave(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001260
1261 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1262 retval = ZFCP_ERP_CONTINUES;
1263
1264 switch (retval) {
1265 case ZFCP_ERP_NOMEM:
1266 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1267 ++adapter->erp_low_mem_count;
1268 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1269 }
1270 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001271 _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL);
Christof Schmitt287ac012008-07-02 10:56:40 +02001272 else {
1273 zfcp_erp_strategy_memwait(erp_action);
1274 retval = ZFCP_ERP_CONTINUES;
1275 }
1276 goto unlock;
1277
1278 case ZFCP_ERP_CONTINUES:
1279 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1280 --adapter->erp_low_mem_count;
1281 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1282 }
1283 goto unlock;
1284 }
1285
Christof Schmitt9c785d92010-07-08 09:53:09 +02001286check_target:
Christof Schmitt287ac012008-07-02 10:56:40 +02001287 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1288 zfcp_erp_action_dequeue(erp_action);
1289 retval = zfcp_erp_strategy_statechange(erp_action, retval);
1290 if (retval == ZFCP_ERP_EXIT)
1291 goto unlock;
Christof Schmitt85600f72009-07-13 15:06:09 +02001292 if (retval == ZFCP_ERP_SUCCEEDED)
1293 zfcp_erp_strategy_followup_success(erp_action);
1294 if (retval == ZFCP_ERP_FAILED)
1295 zfcp_erp_strategy_followup_failed(erp_action);
Christof Schmitt287ac012008-07-02 10:56:40 +02001296
1297 unlock:
Swen Schilligecf0c772009-11-24 16:53:58 +01001298 write_unlock_irqrestore(&adapter->erp_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001299
1300 if (retval != ZFCP_ERP_CONTINUES)
1301 zfcp_erp_action_cleanup(erp_action, retval);
1302
Swen Schilligf3450c72009-11-24 16:53:59 +01001303 kref_put(&adapter->ref, zfcp_adapter_release);
Christof Schmitt287ac012008-07-02 10:56:40 +02001304 return retval;
1305}
1306
1307static int zfcp_erp_thread(void *data)
1308{
1309 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1310 struct list_head *next;
1311 struct zfcp_erp_action *act;
1312 unsigned long flags;
1313
Christof Schmitt347c6a92009-08-18 15:43:25 +02001314 for (;;) {
Swen Schillig57717102009-08-18 15:43:21 +02001315 zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf);
Christof Schmitt347c6a92009-08-18 15:43:25 +02001316 wait_event_interruptible(adapter->erp_ready_wq,
1317 !list_empty(&adapter->erp_ready_head) ||
1318 kthread_should_stop());
Swen Schillig57717102009-08-18 15:43:21 +02001319 zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf);
Swen Schillig94ab4b32009-04-17 15:08:06 +02001320
Christof Schmitt347c6a92009-08-18 15:43:25 +02001321 if (kthread_should_stop())
1322 break;
1323
Christof Schmitt287ac012008-07-02 10:56:40 +02001324 write_lock_irqsave(&adapter->erp_lock, flags);
1325 next = adapter->erp_ready_head.next;
1326 write_unlock_irqrestore(&adapter->erp_lock, flags);
1327
1328 if (next != &adapter->erp_ready_head) {
1329 act = list_entry(next, struct zfcp_erp_action, list);
1330
1331 /* there is more to come after dismission, no notify */
1332 if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED)
1333 zfcp_erp_wakeup(adapter);
1334 }
Christof Schmitt287ac012008-07-02 10:56:40 +02001335 }
1336
Christof Schmitt287ac012008-07-02 10:56:40 +02001337 return 0;
1338}
1339
1340/**
1341 * zfcp_erp_thread_setup - Start ERP thread for adapter
1342 * @adapter: Adapter to start the ERP thread for
1343 *
1344 * Returns 0 on success or error code from kernel_thread()
1345 */
1346int zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1347{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001348 struct task_struct *thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001349
Christof Schmitt347c6a92009-08-18 15:43:25 +02001350 thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s",
1351 dev_name(&adapter->ccw_device->dev));
1352 if (IS_ERR(thread)) {
Christof Schmitt287ac012008-07-02 10:56:40 +02001353 dev_err(&adapter->ccw_device->dev,
Christof Schmittff3b24f2008-10-01 12:42:15 +02001354 "Creating an ERP thread for the FCP device failed.\n");
Christof Schmitt347c6a92009-08-18 15:43:25 +02001355 return PTR_ERR(thread);
Christof Schmitt287ac012008-07-02 10:56:40 +02001356 }
Christof Schmitt347c6a92009-08-18 15:43:25 +02001357
1358 adapter->erp_thread = thread;
Christof Schmitt287ac012008-07-02 10:56:40 +02001359 return 0;
1360}
1361
1362/**
1363 * zfcp_erp_thread_kill - Stop ERP thread.
1364 * @adapter: Adapter where the ERP thread should be stopped.
1365 *
1366 * The caller of this routine ensures that the specified adapter has
1367 * been shut down and that this operation has been completed. Thus,
1368 * there are no pending erp_actions which would need to be handled
1369 * here.
1370 */
1371void zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1372{
Christof Schmitt347c6a92009-08-18 15:43:25 +02001373 kthread_stop(adapter->erp_thread);
1374 adapter->erp_thread = NULL;
Christof Schmitt143bb6b2009-08-18 15:43:27 +02001375 WARN_ON(!list_empty(&adapter->erp_ready_head));
1376 WARN_ON(!list_empty(&adapter->erp_running_head));
Christof Schmitt287ac012008-07-02 10:56:40 +02001377}
1378
1379/**
1380 * zfcp_erp_adapter_failed - Set adapter status to failed.
1381 * @adapter: Failed adapter.
1382 * @id: Event id for debug trace.
1383 * @ref: Reference for debug trace.
1384 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001385void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001386{
1387 zfcp_erp_modify_adapter_status(adapter, id, ref,
1388 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001389}
1390
1391/**
1392 * zfcp_erp_port_failed - Set port status to failed.
1393 * @port: Failed port.
1394 * @id: Event id for debug trace.
1395 * @ref: Reference for debug trace.
1396 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001397void zfcp_erp_port_failed(struct zfcp_port *port, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001398{
1399 zfcp_erp_modify_port_status(port, id, ref,
1400 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001401}
1402
1403/**
1404 * zfcp_erp_unit_failed - Set unit status to failed.
1405 * @unit: Failed unit.
1406 * @id: Event id for debug trace.
1407 * @ref: Reference for debug trace.
1408 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001409void zfcp_erp_unit_failed(struct zfcp_unit *unit, char *id, void *ref)
Christof Schmitt287ac012008-07-02 10:56:40 +02001410{
1411 zfcp_erp_modify_unit_status(unit, id, ref,
1412 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt287ac012008-07-02 10:56:40 +02001413}
1414
1415/**
1416 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1417 * @adapter: adapter for which to wait for completion of its error recovery
1418 */
1419void zfcp_erp_wait(struct zfcp_adapter *adapter)
1420{
1421 wait_event(adapter->erp_done_wqh,
1422 !(atomic_read(&adapter->status) &
1423 ZFCP_STATUS_ADAPTER_ERP_PENDING));
1424}
1425
1426/**
1427 * zfcp_erp_modify_adapter_status - change adapter status bits
1428 * @adapter: adapter to change the status
1429 * @id: id for the debug trace
1430 * @ref: reference for the debug trace
1431 * @mask: status bits to change
1432 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1433 *
1434 * Changes in common status bits are propagated to attached ports and units.
1435 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001436void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001437 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 struct zfcp_port *port;
Swen Schilligecf0c772009-11-24 16:53:58 +01001440 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001441 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Christof Schmitt287ac012008-07-02 10:56:40 +02001443 if (set_or_clear == ZFCP_SET) {
1444 if (status_change_set(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001445 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001446 atomic_set_mask(mask, &adapter->status);
1447 } else {
1448 if (status_change_clear(mask, &adapter->status))
Swen Schillig57717102009-08-18 15:43:21 +02001449 zfcp_dbf_rec_adapter(id, ref, adapter->dbf);
Christof Schmitt287ac012008-07-02 10:56:40 +02001450 atomic_clear_mask(mask, &adapter->status);
1451 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1452 atomic_set(&adapter->erp_counter, 0);
1453 }
1454
Swen Schilligecf0c772009-11-24 16:53:58 +01001455 if (common_mask) {
1456 read_lock_irqsave(&adapter->port_list_lock, flags);
1457 list_for_each_entry(port, &adapter->port_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001458 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1459 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001460 read_unlock_irqrestore(&adapter->port_list_lock, flags);
1461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
Christof Schmitt287ac012008-07-02 10:56:40 +02001464/**
1465 * zfcp_erp_modify_port_status - change port status bits
1466 * @port: port to change the status bits
1467 * @id: id for the debug trace
1468 * @ref: reference for the debug trace
1469 * @mask: status bits to change
1470 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1471 *
1472 * Changes in common status bits are propagated to attached units.
1473 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001474void zfcp_erp_modify_port_status(struct zfcp_port *port, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001475 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001478 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001479 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Christof Schmitt287ac012008-07-02 10:56:40 +02001481 if (set_or_clear == ZFCP_SET) {
1482 if (status_change_set(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001483 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001484 atomic_set_mask(mask, &port->status);
1485 } else {
1486 if (status_change_clear(mask, &port->status))
Swen Schillig57717102009-08-18 15:43:21 +02001487 zfcp_dbf_rec_port(id, ref, port);
Christof Schmitt287ac012008-07-02 10:56:40 +02001488 atomic_clear_mask(mask, &port->status);
1489 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1490 atomic_set(&port->erp_counter, 0);
1491 }
1492
Swen Schilligecf0c772009-11-24 16:53:58 +01001493 if (common_mask) {
1494 read_lock_irqsave(&port->unit_list_lock, flags);
1495 list_for_each_entry(unit, &port->unit_list, list)
Christof Schmitt287ac012008-07-02 10:56:40 +02001496 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1497 set_or_clear);
Swen Schilligecf0c772009-11-24 16:53:58 +01001498 read_unlock_irqrestore(&port->unit_list_lock, flags);
1499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
Christof Schmitt287ac012008-07-02 10:56:40 +02001502/**
1503 * zfcp_erp_modify_unit_status - change unit status bits
1504 * @unit: unit to change the status bits
1505 * @id: id for the debug trace
1506 * @ref: reference for the debug trace
1507 * @mask: status bits to change
1508 * @set_or_clear: ZFCP_SET or ZFCP_CLEAR
1509 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001510void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, char *id, void *ref,
Christof Schmitt287ac012008-07-02 10:56:40 +02001511 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512{
Christof Schmitt287ac012008-07-02 10:56:40 +02001513 if (set_or_clear == ZFCP_SET) {
1514 if (status_change_set(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001515 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001516 atomic_set_mask(mask, &unit->status);
1517 } else {
1518 if (status_change_clear(mask, &unit->status))
Swen Schillig57717102009-08-18 15:43:21 +02001519 zfcp_dbf_rec_unit(id, ref, unit);
Christof Schmitt287ac012008-07-02 10:56:40 +02001520 atomic_clear_mask(mask, &unit->status);
1521 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1522 atomic_set(&unit->erp_counter, 0);
1523 }
1524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Christof Schmitt287ac012008-07-02 10:56:40 +02001527/**
1528 * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP
1529 * @port: The "boxed" port.
1530 * @id: The debug trace id.
1531 * @id: Reference for the debug trace.
1532 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001533void zfcp_erp_port_boxed(struct zfcp_port *port, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001534{
Martin Peschke698ec0162008-03-27 14:22:02 +01001535 zfcp_erp_modify_port_status(port, id, ref,
1536 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001537 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001538}
1539
Christof Schmitt287ac012008-07-02 10:56:40 +02001540/**
1541 * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP
1542 * @port: The "boxed" unit.
1543 * @id: The debug trace id.
1544 * @id: Reference for the debug trace.
1545 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001546void zfcp_erp_unit_boxed(struct zfcp_unit *unit, char *id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001547{
Martin Peschke698ec0162008-03-27 14:22:02 +01001548 zfcp_erp_modify_unit_status(unit, id, ref,
1549 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001550 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02001551}
1552
Christof Schmitt287ac012008-07-02 10:56:40 +02001553/**
1554 * zfcp_erp_port_access_denied - Adapter denied access to port.
1555 * @port: port where access has been denied
1556 * @id: id for debug trace
1557 * @ref: reference for debug trace
1558 *
1559 * Since the adapter has denied access, stop using the port and the
1560 * attached units.
1561 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001562void zfcp_erp_port_access_denied(struct zfcp_port *port, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Martin Peschke698ec0162008-03-27 14:22:02 +01001564 zfcp_erp_modify_port_status(port, id, ref,
1565 ZFCP_STATUS_COMMON_ERP_FAILED |
1566 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
Christof Schmitt287ac012008-07-02 10:56:40 +02001569/**
1570 * zfcp_erp_unit_access_denied - Adapter denied access to unit.
1571 * @unit: unit where access has been denied
1572 * @id: id for debug trace
1573 * @ref: reference for debug trace
1574 *
1575 * Since the adapter has denied access, stop using the unit.
1576 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001577void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, char *id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
Martin Peschke698ec0162008-03-27 14:22:02 +01001579 zfcp_erp_modify_unit_status(unit, id, ref,
1580 ZFCP_STATUS_COMMON_ERP_FAILED |
1581 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
1583
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001584static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001585 void *ref)
1586{
1587 int status = atomic_read(&unit->status);
1588 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1589 ZFCP_STATUS_COMMON_ACCESS_BOXED)))
1590 return;
1591
1592 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1593}
1594
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001595static void zfcp_erp_port_access_changed(struct zfcp_port *port, char *id,
Christof Schmitt287ac012008-07-02 10:56:40 +02001596 void *ref)
1597{
1598 struct zfcp_unit *unit;
Swen Schilligecf0c772009-11-24 16:53:58 +01001599 unsigned long flags;
Christof Schmitt287ac012008-07-02 10:56:40 +02001600 int status = atomic_read(&port->status);
1601
1602 if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED |
1603 ZFCP_STATUS_COMMON_ACCESS_BOXED))) {
Swen Schilligecf0c772009-11-24 16:53:58 +01001604 read_lock_irqsave(&port->unit_list_lock, flags);
1605 list_for_each_entry(unit, &port->unit_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001606 zfcp_erp_unit_access_changed(unit, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001607 read_unlock_irqrestore(&port->unit_list_lock, flags);
Christof Schmitt287ac012008-07-02 10:56:40 +02001608 return;
1609 }
1610
1611 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
1612}
1613
1614/**
1615 * zfcp_erp_adapter_access_changed - Process change in adapter ACT
1616 * @adapter: Adapter where the Access Control Table (ACT) changed
1617 * @id: Id for debug trace
1618 * @ref: Reference for debug trace
1619 */
Swen Schillig5ffd51a2009-03-02 13:09:04 +01001620void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001621 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 unsigned long flags;
Swen Schilligecf0c772009-11-24 16:53:58 +01001624 struct zfcp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001626 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
1627 return;
1628
Swen Schilligecf0c772009-11-24 16:53:58 +01001629 read_lock_irqsave(&adapter->port_list_lock, flags);
1630 list_for_each_entry(port, &adapter->port_list, list)
Swen Schillig5ab944f2008-10-01 12:42:17 +02001631 zfcp_erp_port_access_changed(port, id, ref);
Swen Schilligecf0c772009-11-24 16:53:58 +01001632 read_unlock_irqrestore(&adapter->port_list_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}