blob: c06156b288ea395ae533a60c9bde1ba3da42a9f7 [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 Schmitt553448f2008-06-10 18:20:58 +02006 * Copyright IBM Corporation 2002, 2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include "zfcp_ext.h"
10
Martin Peschke9467a9b2008-03-27 14:22:03 +010011static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020012 void *);
Martin Peschke9467a9b2008-03-27 14:22:03 +010013static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020014 void *);
15static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int, u8, void *);
16static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int, u8, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Martin Peschke9467a9b2008-03-27 14:22:03 +010018static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020019 void *);
20static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int, u8,
21 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
24static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
25static void zfcp_erp_port_block(struct zfcp_port *, int);
26static void zfcp_erp_port_unblock(struct zfcp_port *);
27static void zfcp_erp_unit_block(struct zfcp_unit *, int);
28static void zfcp_erp_unit_unblock(struct zfcp_unit *);
29
30static int zfcp_erp_thread(void *);
31
32static int zfcp_erp_strategy(struct zfcp_erp_action *);
33
34static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
35static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
36static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
37static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
38static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
39static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
40static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
41 struct zfcp_port *,
42 struct zfcp_unit *, int);
Heiko Carstens364c8552007-10-12 16:11:35 +020043static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
45 struct zfcp_port *,
46 struct zfcp_unit *, int);
47static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
48static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
49
50static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
51static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
52static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
54static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
55static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
56static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020057static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058static int zfcp_erp_adapter_strategy_open_fsf_statusread(
59 struct zfcp_erp_action *);
60
61static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
62static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
63
64static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
65static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
66static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
67static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
68static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
69static int zfcp_erp_port_strategy_open_nameserver_wakeup(
70 struct zfcp_erp_action *);
71static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
72static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
73static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
74
75static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
76static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
77static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
78static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
79
Andreas Herrmann81654282006-09-18 22:30:36 +020080static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020081static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
82static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
83static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
Martin Peschke9467a9b2008-03-27 14:22:03 +010086 struct zfcp_port *, struct zfcp_unit *,
Martin Peschke1f6f7122008-04-18 12:51:55 +020087 u8 id, void *ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
89static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
90 struct zfcp_port *, struct zfcp_unit *,
91 int);
92
93static void zfcp_erp_action_ready(struct zfcp_erp_action *);
94static int zfcp_erp_action_exists(struct zfcp_erp_action *);
95
Heiko Carstens364c8552007-10-12 16:11:35 +020096static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
97static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99static void zfcp_erp_memwait_handler(unsigned long);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200100
101/**
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200102 * zfcp_close_fsf - stop FSF operations for an adapter
103 *
104 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
105 * requests waiting for completion; especially this returns SCSI commands
106 * with error state).
107 */
108static void zfcp_close_fsf(struct zfcp_adapter *adapter)
109{
110 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig00bab912008-06-10 18:20:57 +0200111 zfcp_qdio_close(adapter);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200112 zfcp_fsf_req_dismiss_all(adapter);
113 /* reset FSF request sequence number */
114 adapter->fsf_req_seq_no = 0;
115 /* all ports and units are closed */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200116 zfcp_erp_modify_adapter_status(adapter, 24, NULL,
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200117 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120/**
121 * zfcp_fsf_request_timeout_handler - called if a request timed out
122 * @data: pointer to adapter for handler function
123 *
124 * This function needs to be called if requests (ELS, Generic Service,
125 * or SCSI commands) exceed a certain time limit. The assumption is
126 * that after the time limit the adapter get stuck. So we trigger a reopen of
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200127 * the adapter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200129static void zfcp_fsf_request_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200131 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200132 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
133 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134}
135
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200136void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200138 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
139 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
Christof Schmitt9e3738f2007-03-28 14:20:40 +0200140 fsf_req->timer.expires = jiffies + timeout;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200141 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200145 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 *
147 * purpose: called if an adapter failed,
148 * initiates adapter recovery which is done
149 * asynchronously
150 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200151 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 * <0 - failed to initiate action
153 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100154static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200155 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
157 int retval;
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 zfcp_erp_adapter_block(adapter, clear_mask);
160
161 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* ensure propagation of failed status to new devices */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200163 zfcp_erp_adapter_failed(adapter, 13, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 retval = -EIO;
165 goto out;
166 }
167 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100168 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 out:
171 return retval;
172}
173
174/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200175 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 *
177 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
178 * used to ensure the correct locking
179 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200180 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 * <0 - failed to initiate action
182 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100183int zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200184 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
186 int retval;
187 unsigned long flags;
188
189 read_lock_irqsave(&zfcp_data.config_lock, flags);
190 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100191 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 write_unlock(&adapter->erp_lock);
193 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
194
195 return retval;
196}
197
Martin Peschke9467a9b2008-03-27 14:22:03 +0100198int zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200199 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200{
201 int retval;
202
203 retval = zfcp_erp_adapter_reopen(adapter,
204 ZFCP_STATUS_COMMON_RUNNING |
205 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100206 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 return retval;
209}
210
Martin Peschke9467a9b2008-03-27 14:22:03 +0100211int zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200212 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
214 int retval;
215
216 retval = zfcp_erp_port_reopen(port,
217 ZFCP_STATUS_COMMON_RUNNING |
218 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100219 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 return retval;
222}
223
Martin Peschke9467a9b2008-03-27 14:22:03 +0100224int zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200225 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 int retval;
228
229 retval = zfcp_erp_unit_reopen(unit,
230 ZFCP_STATUS_COMMON_RUNNING |
231 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100232 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 return retval;
235}
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200238 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 *
240 * purpose: called if a port failed to be opened normally
241 * initiates Forced Reopen recovery which is done
242 * asynchronously
243 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200244 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 * <0 - failed to initiate action
246 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100247static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200248 int clear_mask, u8 id,
249 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
251 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 zfcp_erp_port_block(port, clear_mask);
254
255 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 retval = -EIO;
257 goto out;
258 }
259
260 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100261 port->adapter, port, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 out:
264 return retval;
265}
266
267/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200268 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 *
270 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
271 * used to ensure the correct locking
272 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200273 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 * <0 - failed to initiate action
275 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100276int zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200277 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
279 int retval;
280 unsigned long flags;
281 struct zfcp_adapter *adapter;
282
283 adapter = port->adapter;
284 read_lock_irqsave(&zfcp_data.config_lock, flags);
285 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100286 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask, id,
287 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 write_unlock(&adapter->erp_lock);
289 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
290
291 return retval;
292}
293
294/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200295 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 *
297 * purpose: called if a port is to be opened
298 * initiates Reopen recovery which is done
299 * asynchronously
300 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200301 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * <0 - failed to initiate action
303 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100304static int zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200305 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306{
307 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 zfcp_erp_port_block(port, clear_mask);
310
311 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 /* ensure propagation of failed status to new devices */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200313 zfcp_erp_port_failed(port, 14, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 retval = -EIO;
315 goto out;
316 }
317
318 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100319 port->adapter, port, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 out:
322 return retval;
323}
324
325/**
326 * zfcp_erp_port_reopen - initiate reopen of a remote port
327 * @port: port to be reopened
328 * @clear_mask: specifies flags in port status to be cleared
329 * Return: 0 on success, < 0 on error
330 *
331 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
332 * correct locking. An error recovery task is initiated to do the reopen.
333 * To wait for the completion of the reopen zfcp_erp_wait should be used.
334 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200335int zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask, u8 id,
336 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 int retval;
339 unsigned long flags;
340 struct zfcp_adapter *adapter = port->adapter;
341
342 read_lock_irqsave(&zfcp_data.config_lock, flags);
343 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100344 retval = zfcp_erp_port_reopen_internal(port, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 write_unlock(&adapter->erp_lock);
346 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
347
348 return retval;
349}
350
351/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200352 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 *
354 * purpose: called if a unit is to be opened
355 * initiates Reopen recovery which is done
356 * asynchronously
357 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200358 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 * <0 - failed to initiate action
360 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100361static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200362 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 int retval;
365 struct zfcp_adapter *adapter = unit->port->adapter;
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 zfcp_erp_unit_block(unit, clear_mask);
368
369 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 retval = -EIO;
371 goto out;
372 }
373
374 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100375 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 out:
377 return retval;
378}
379
380/**
381 * zfcp_erp_unit_reopen - initiate reopen of a unit
382 * @unit: unit to be reopened
383 * @clear_mask: specifies flags in unit status to be cleared
384 * Return: 0 on success, < 0 on error
385 *
386 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
387 * locking. An error recovery task is initiated to do the reopen.
388 * To wait for the completion of the reopen zfcp_erp_wait should be used.
389 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200390int zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask, u8 id,
391 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 int retval;
394 unsigned long flags;
395 struct zfcp_adapter *adapter;
396 struct zfcp_port *port;
397
398 port = unit->port;
399 adapter = port->adapter;
400
401 read_lock_irqsave(&zfcp_data.config_lock, flags);
402 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100403 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 write_unlock(&adapter->erp_lock);
405 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
406
407 return retval;
408}
409
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200410/**
411 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200413static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200415 zfcp_erp_modify_adapter_status(adapter, 15, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 ZFCP_STATUS_COMMON_UNBLOCKED |
417 clear_mask, ZFCP_CLEAR);
418}
419
Martin Peschke698ec0162008-03-27 14:22:02 +0100420/* FIXME: isn't really atomic */
421/*
422 * returns the mask which has not been set so far, i.e.
423 * 0 if no bit has been changed, !0 if some bit has been changed
424 */
425static int atomic_test_and_set_mask(unsigned long mask, atomic_t *v)
426{
427 int changed_bits = (atomic_read(v) /*XOR*/^ mask) & mask;
428 atomic_set_mask(mask, v);
429 return changed_bits;
430}
431
432/* FIXME: isn't really atomic */
433/*
434 * returns the mask which has not been cleared so far, i.e.
435 * 0 if no bit has been changed, !0 if some bit has been changed
436 */
437static int atomic_test_and_clear_mask(unsigned long mask, atomic_t *v)
438{
439 int changed_bits = atomic_read(v) & mask;
440 atomic_clear_mask(mask, v);
441 return changed_bits;
442}
443
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200444/**
445 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200447static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448{
Martin Peschke698ec0162008-03-27 14:22:02 +0100449 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
450 &adapter->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200451 zfcp_rec_dbf_event_adapter(16, NULL, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200455 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 *
457 * purpose: disable I/O,
458 * return any open requests and clean them up,
459 * aim: no pending and incoming I/O
460 *
461 * returns:
462 */
463static void
464zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
465{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200466 zfcp_erp_modify_port_status(port, 17, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
468 ZFCP_CLEAR);
469}
470
471/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200472 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 *
474 * purpose: enable I/O
475 *
476 * returns:
477 */
478static void
479zfcp_erp_port_unblock(struct zfcp_port *port)
480{
Martin Peschke698ec0162008-03-27 14:22:02 +0100481 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
482 &port->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200483 zfcp_rec_dbf_event_port(18, NULL, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
486/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200487 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 *
489 * purpose: disable I/O,
490 * return any open requests and clean them up,
491 * aim: no pending and incoming I/O
492 *
493 * returns:
494 */
495static void
496zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
497{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200498 zfcp_erp_modify_unit_status(unit, 19, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
500 ZFCP_CLEAR);
501}
502
503/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200504 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 *
506 * purpose: enable I/O
507 *
508 * returns:
509 */
510static void
511zfcp_erp_unit_unblock(struct zfcp_unit *unit)
512{
Martin Peschke698ec0162008-03-27 14:22:02 +0100513 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
514 &unit->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200515 zfcp_rec_dbf_event_unit(20, NULL, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518static void
519zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
520{
521 struct zfcp_adapter *adapter = erp_action->adapter;
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 zfcp_erp_action_to_ready(erp_action);
524 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200525 zfcp_rec_dbf_event_thread(2, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
528/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200529 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 *
531 * purpose:
532 *
533 * returns: <0 erp_action not found in any list
534 * ZFCP_ERP_ACTION_READY erp_action is in ready list
535 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
536 *
537 * locks: erp_lock must be held
538 */
539static int
540zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
541{
542 int retval = -EINVAL;
543 struct list_head *entry;
544 struct zfcp_erp_action *entry_erp_action;
545 struct zfcp_adapter *adapter = erp_action->adapter;
546
547 /* search in running list */
548 list_for_each(entry, &adapter->erp_running_head) {
549 entry_erp_action =
550 list_entry(entry, struct zfcp_erp_action, list);
551 if (entry_erp_action == erp_action) {
552 retval = ZFCP_ERP_ACTION_RUNNING;
553 goto out;
554 }
555 }
556 /* search in ready list */
557 list_for_each(entry, &adapter->erp_ready_head) {
558 entry_erp_action =
559 list_entry(entry, struct zfcp_erp_action, list);
560 if (entry_erp_action == erp_action) {
561 retval = ZFCP_ERP_ACTION_READY;
562 goto out;
563 }
564 }
565
566 out:
567 return retval;
568}
569
570/*
571 * purpose: checks current status of action (timed out, dismissed, ...)
572 * and does appropriate preparations (dismiss fsf request, ...)
573 *
574 * locks: called under erp_lock (disabled interrupts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 */
Swen Schilligca880cf2007-02-09 10:00:14 +0100576static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
578{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 struct zfcp_adapter *adapter = erp_action->adapter;
580
581 if (erp_action->fsf_req) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200582 /* take lock to ensure that request is not deleted meanwhile */
583 spin_lock(&adapter->req_list_lock);
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100584 if (zfcp_reqlist_find_safe(adapter, erp_action->fsf_req) &&
585 erp_action->fsf_req->erp_action == erp_action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* fsf_req still exists */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200587 /* dismiss fsf_req of timed out/dismissed erp_action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
589 ZFCP_STATUS_ERP_TIMEDOUT)) {
Swen Schilligca880cf2007-02-09 10:00:14 +0100590 erp_action->fsf_req->status |=
591 ZFCP_STATUS_FSFREQ_DISMISSED;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100592 zfcp_rec_dbf_event_action(142, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Christof Schmitt553448f2008-06-10 18:20:58 +0200594 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
Martin Peschke6f4f3652008-03-27 14:22:04 +0100595 zfcp_rec_dbf_event_action(143, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 /*
597 * If fsf_req is neither dismissed nor completed
598 * then keep it running asynchronously and don't mess
599 * with the association of erp_action and fsf_req.
600 */
Swen Schilligca880cf2007-02-09 10:00:14 +0100601 if (erp_action->fsf_req->status &
602 (ZFCP_STATUS_FSFREQ_COMPLETED |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 ZFCP_STATUS_FSFREQ_DISMISSED)) {
604 /* forget about association between fsf_req
605 and erp_action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 erp_action->fsf_req = NULL;
607 }
608 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 /*
610 * even if this fsf_req has gone, forget about
611 * association between erp_action and fsf_req
612 */
613 erp_action->fsf_req = NULL;
614 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200615 spin_unlock(&adapter->req_list_lock);
Martin Peschke507e4962008-03-27 14:22:05 +0100616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200619/**
620 * zfcp_erp_async_handler_nolock - complete erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200622 * Used for normal completion, time-out, dismissal and failure after
623 * low memory condition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200625static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
626 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 erp_action->status |= set_mask;
630 zfcp_erp_action_ready(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 } else {
632 /* action is ready or gone - nothing to do */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
635
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200636/**
637 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200639void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
640 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
642 struct zfcp_adapter *adapter = erp_action->adapter;
643 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 write_lock_irqsave(&adapter->erp_lock, flags);
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200646 zfcp_erp_async_handler_nolock(erp_action, set_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648}
649
650/*
651 * purpose: is called for erp_action which was slept waiting for
652 * memory becoming avaliable,
653 * will trigger that this action will be continued
654 */
655static void
656zfcp_erp_memwait_handler(unsigned long data)
657{
658 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 zfcp_erp_async_handler(erp_action, 0);
661}
662
663/*
664 * purpose: is called if an asynchronous erp step timed out,
665 * action gets an appropriate flag and will be processed
666 * accordingly
667 */
Heiko Carstens364c8552007-10-12 16:11:35 +0200668static void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
670 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
672 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
673}
674
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200675/**
676 * zfcp_erp_action_dismiss - dismiss an erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200678 * adapter->erp_lock must be held
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200679 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200680 * Dismissal of an erp_action is usually required if an erp_action of
681 * higher priority is generated.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200683static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Martin Peschked0076f72007-11-15 13:57:08 +0100685 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
686 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
687 zfcp_erp_action_ready(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690int
691zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
692{
693 int retval = 0;
694
695 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
Christof Schmitt553448f2008-06-10 18:20:58 +0200698 if (retval < 0)
699 dev_err(&adapter->ccw_device->dev,
700 "Creation of ERP thread failed.\n");
701 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 wait_event(adapter->erp_thread_wqh,
703 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
704 &adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706
707 return (retval < 0);
708}
709
710/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200711 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200713 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 *
715 * returns:
716 *
717 * context: process (i.e. proc-fs or rmmod/insmod)
718 *
719 * note: The caller of this routine ensures that the specified
720 * adapter has been shut down and that this operation
721 * has been completed. Thus, there are no pending erp_actions
722 * which would need to be handled here.
723 */
724int
725zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
726{
727 int retval = 0;
728
729 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
730 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200731 zfcp_rec_dbf_event_thread_lock(2, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 wait_event(adapter->erp_thread_wqh,
734 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
735 &adapter->status));
736
737 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
738 &adapter->status);
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 return retval;
741}
742
743/*
744 * purpose: is run as a kernel thread,
745 * goes through list of error recovery actions of associated adapter
746 * and delegates single action to execution
747 *
748 * returns: 0
749 */
750static int
751zfcp_erp_thread(void *data)
752{
753 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
754 struct list_head *next;
755 struct zfcp_erp_action *erp_action;
756 unsigned long flags;
757
758 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
759 /* Block all signals */
760 siginitsetinv(&current->blocked, 0);
761 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 wake_up(&adapter->erp_thread_wqh);
763
764 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
765 &adapter->status)) {
766
767 write_lock_irqsave(&adapter->erp_lock, flags);
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100768 next = adapter->erp_ready_head.next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 write_unlock_irqrestore(&adapter->erp_lock, flags);
770
771 if (next != &adapter->erp_ready_head) {
772 erp_action =
773 list_entry(next, struct zfcp_erp_action, list);
774 /*
775 * process action (incl. [re]moving it
776 * from 'ready' queue)
777 */
778 zfcp_erp_strategy(erp_action);
779 }
780
781 /*
782 * sleep as long as there is nothing to do, i.e.
783 * no action in 'ready' queue to be processed and
784 * thread is not to be killed
785 */
Christof Schmittaa0fec62008-05-19 12:17:47 +0200786 zfcp_rec_dbf_event_thread_lock(4, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 down_interruptible(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200788 zfcp_rec_dbf_event_thread_lock(5, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 }
790
791 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 wake_up(&adapter->erp_thread_wqh);
793
794 return 0;
795}
796
797/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200798 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 *
800 * purpose: drives single error recovery action and schedules higher and
801 * subordinate actions, if necessary
802 *
803 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
804 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
805 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
806 * ZFCP_ERP_EXIT - action finished (dequeued), offline
807 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
808 */
809static int
810zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
811{
812 int retval = 0;
813 struct zfcp_adapter *adapter = erp_action->adapter;
814 struct zfcp_port *port = erp_action->port;
815 struct zfcp_unit *unit = erp_action->unit;
816 int action = erp_action->action;
817 u32 status = erp_action->status;
818 unsigned long flags;
819
820 /* serialise dismissing, timing out, moving, enqueueing */
821 read_lock_irqsave(&zfcp_data.config_lock, flags);
822 write_lock(&adapter->erp_lock);
823
824 /* dequeue dismissed action and leave, if required */
825 retval = zfcp_erp_strategy_check_action(erp_action, retval);
826 if (retval == ZFCP_ERP_DISMISSED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 goto unlock;
828 }
829
830 /*
831 * move action to 'running' queue before processing it
832 * (to avoid a race condition regarding moving the
833 * action to the 'running' queue and back)
834 */
835 zfcp_erp_action_to_running(erp_action);
836
837 /*
838 * try to process action as far as possible,
839 * no lock to allow for blocking operations (kmalloc, qdio, ...),
840 * afterwards the lock is required again for the following reasons:
841 * - dequeueing of finished action and enqueueing of
842 * follow-up actions must be atomic so that any other
843 * reopen-routine does not believe there is nothing to do
844 * and that it is safe to enqueue something else,
845 * - we want to force any control thread which is dismissing
846 * actions to finish this before we decide about
847 * necessary steps to be taken here further
848 */
849 write_unlock(&adapter->erp_lock);
850 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
851 retval = zfcp_erp_strategy_do_action(erp_action);
852 read_lock_irqsave(&zfcp_data.config_lock, flags);
853 write_lock(&adapter->erp_lock);
854
855 /*
856 * check for dismissed status again to avoid follow-up actions,
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100857 * failing of targets and so on for dismissed actions,
858 * we go through down() here because there has been an up()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 */
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100860 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
861 retval = ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
863 switch (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 case ZFCP_ERP_NOMEM:
865 /* no memory to continue immediately, let it sleep */
866 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
867 ++adapter->erp_low_mem_count;
868 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
869 }
870 /* This condition is true if there is no memory available
871 for any erp_action on this adapter. This implies that there
872 are no elements in the memory pool(s) left for erp_actions.
873 This might happen if an erp_action that used a memory pool
874 element was timed out.
875 */
Christof Schmitt553448f2008-06-10 18:20:58 +0200876 if (adapter->erp_total_count == adapter->erp_low_mem_count)
Martin Peschke1f6f7122008-04-18 12:51:55 +0200877 zfcp_erp_adapter_reopen_internal(adapter, 0, 66, NULL);
Christof Schmitt553448f2008-06-10 18:20:58 +0200878 else
879 retval = zfcp_erp_strategy_memwait(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 goto unlock;
881 case ZFCP_ERP_CONTINUES:
882 /* leave since this action runs asynchronously */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
884 --adapter->erp_low_mem_count;
885 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
886 }
887 goto unlock;
888 }
889 /* ok, finished action (whatever its result is) */
890
891 /* check for unrecoverable targets */
892 retval = zfcp_erp_strategy_check_target(erp_action, retval);
893
894 /* action must be dequeued (here to allow for further ones) */
895 zfcp_erp_action_dequeue(erp_action);
896
897 /*
898 * put this target through the erp mill again if someone has
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200899 * requested to change the status of a target being online
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 * to offline or the other way around
901 * (old retval is preserved if nothing has to be done here)
902 */
903 retval = zfcp_erp_strategy_statechange(action, status, adapter,
904 port, unit, retval);
905
906 /*
907 * leave if target is in permanent error state or if
908 * action is repeated in order to process state change
909 */
910 if (retval == ZFCP_ERP_EXIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 goto unlock;
912 }
913
914 /* trigger follow up actions */
915 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
916
917 unlock:
918 write_unlock(&adapter->erp_lock);
919 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (retval != ZFCP_ERP_CONTINUES)
922 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
923
924 /*
925 * a few tasks remain when the erp queues are empty
926 * (don't do that if the last action evaluated was dismissed
927 * since this clearly indicates that there is more to come) :
928 * - close the name server port if it is open yet
929 * (enqueues another [probably] final action)
930 * - otherwise, wake up whoever wants to be woken when we are
931 * done with erp
932 */
933 if (retval != ZFCP_ERP_DISMISSED)
934 zfcp_erp_strategy_check_queues(adapter);
935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 return retval;
937}
938
939/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200940 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200942 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 *
944 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
945 * retval - otherwise
946 */
947static int
948zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
949{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 zfcp_erp_strategy_check_fsfreq(erp_action);
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 zfcp_erp_action_dequeue(erp_action);
954 retval = ZFCP_ERP_DISMISSED;
Martin Peschke507e4962008-03-27 14:22:05 +0100955 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 return retval;
958}
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960static int
961zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
962{
963 int retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 /*
966 * try to execute/continue action as far as possible,
967 * note: no lock in subsequent strategy routines
968 * (this allows these routine to call schedule, e.g.
969 * kmalloc with such flags or qdio_initialize & friends)
Joe Perches5d67d162008-01-26 14:11:20 +0100970 * Note: in case of timeout, the separate strategies will fail
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 * anyhow. No need for a special action. Even worse, a nameserver
972 * failure would not wake up waiting ports without the call.
973 */
974 switch (erp_action->action) {
975
976 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
977 retval = zfcp_erp_adapter_strategy(erp_action);
978 break;
979
980 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
981 retval = zfcp_erp_port_forced_strategy(erp_action);
982 break;
983
984 case ZFCP_ERP_ACTION_REOPEN_PORT:
985 retval = zfcp_erp_port_strategy(erp_action);
986 break;
987
988 case ZFCP_ERP_ACTION_REOPEN_UNIT:
989 retval = zfcp_erp_unit_strategy(erp_action);
990 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992
993 return retval;
994}
995
996/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200997 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 *
999 * purpose: triggers retry of this action after a certain amount of time
1000 * by means of timer provided by erp_action
1001 *
1002 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1003 */
1004static int
1005zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1006{
1007 int retval = ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 init_timer(&erp_action->timer);
1010 erp_action->timer.function = zfcp_erp_memwait_handler;
1011 erp_action->timer.data = (unsigned long) erp_action;
1012 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1013 add_timer(&erp_action->timer);
1014
1015 return retval;
1016}
1017
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001018/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 * function: zfcp_erp_adapter_failed
1020 *
1021 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1022 *
1023 */
1024void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001025zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Martin Peschke698ec0162008-03-27 14:22:02 +01001027 zfcp_erp_modify_adapter_status(adapter, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
Christof Schmitt553448f2008-06-10 18:20:58 +02001029 dev_err(&adapter->ccw_device->dev, "Adapter ERP failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001032/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 * function: zfcp_erp_port_failed
1034 *
1035 * purpose: sets the port and all underlying devices to ERP_FAILED
1036 *
1037 */
1038void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001039zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
Martin Peschke698ec0162008-03-27 14:22:02 +01001041 zfcp_erp_modify_port_status(port, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1043
1044 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
Christof Schmitt553448f2008-06-10 18:20:58 +02001045 dev_err(&port->adapter->ccw_device->dev,
1046 "Port ERP failed for WKA port d_id=0x%06x.\n",
1047 port->d_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 else
Christof Schmitt553448f2008-06-10 18:20:58 +02001049 dev_err(&port->adapter->ccw_device->dev,
1050 "Port ERP failed for port wwpn=0x%016Lx.\n",
1051 port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001054/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 * function: zfcp_erp_unit_failed
1056 *
1057 * purpose: sets the unit to ERP_FAILED
1058 *
1059 */
1060void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001061zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Martin Peschke698ec0162008-03-27 14:22:02 +01001063 zfcp_erp_modify_unit_status(unit, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1065
Christof Schmitt553448f2008-06-10 18:20:58 +02001066 dev_err(&unit->port->adapter->ccw_device->dev,
1067 "Unit ERP failed for unit 0x%016Lx on port 0x%016Lx.\n",
1068 unit->fcp_lun, unit->port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069}
1070
1071/*
1072 * function: zfcp_erp_strategy_check_target
1073 *
1074 * purpose: increments the erp action count on the device currently in
1075 * recovery if the action failed or resets the count in case of
1076 * success. If a maximum count is exceeded the device is marked
1077 * as ERP_FAILED.
1078 * The 'blocked' state of a target which has been recovered
1079 * successfully is reset.
1080 *
1081 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001082 * ZFCP_ERP_SUCCEEDED - action finished successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 * ZFCP_ERP_EXIT - action failed and will not continue
1084 */
1085static int
1086zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1087{
1088 struct zfcp_adapter *adapter = erp_action->adapter;
1089 struct zfcp_port *port = erp_action->port;
1090 struct zfcp_unit *unit = erp_action->unit;
1091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 switch (erp_action->action) {
1093
1094 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1095 result = zfcp_erp_strategy_check_unit(unit, result);
1096 break;
1097
1098 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1099 case ZFCP_ERP_ACTION_REOPEN_PORT:
1100 result = zfcp_erp_strategy_check_port(port, result);
1101 break;
1102
1103 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1104 result = zfcp_erp_strategy_check_adapter(adapter, result);
1105 break;
1106 }
1107
1108 return result;
1109}
1110
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111static int
1112zfcp_erp_strategy_statechange(int action,
1113 u32 status,
1114 struct zfcp_adapter *adapter,
1115 struct zfcp_port *port,
1116 struct zfcp_unit *unit, int retval)
1117{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 switch (action) {
1119
1120 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1121 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1122 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001123 zfcp_erp_adapter_reopen_internal(adapter,
1124 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001125 67, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 retval = ZFCP_ERP_EXIT;
1127 }
1128 break;
1129
1130 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1131 case ZFCP_ERP_ACTION_REOPEN_PORT:
1132 if (zfcp_erp_strategy_statechange_detected(&port->status,
1133 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001134 zfcp_erp_port_reopen_internal(port,
1135 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001136 68, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 retval = ZFCP_ERP_EXIT;
1138 }
1139 break;
1140
1141 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1142 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1143 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001144 zfcp_erp_unit_reopen_internal(unit,
1145 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001146 69, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 retval = ZFCP_ERP_EXIT;
1148 }
1149 break;
1150 }
1151
1152 return retval;
1153}
1154
Heiko Carstens364c8552007-10-12 16:11:35 +02001155static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1157{
1158 return
1159 /* take it online */
1160 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1161 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1162 /* take it offline */
1163 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1164 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1165}
1166
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167static int
1168zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1169{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 switch (result) {
1171 case ZFCP_ERP_SUCCEEDED :
1172 atomic_set(&unit->erp_counter, 0);
1173 zfcp_erp_unit_unblock(unit);
1174 break;
1175 case ZFCP_ERP_FAILED :
1176 atomic_inc(&unit->erp_counter);
1177 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001178 zfcp_erp_unit_failed(unit, 21, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 break;
1180 case ZFCP_ERP_EXIT :
1181 /* nothing */
1182 break;
1183 }
1184
1185 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1186 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1187 result = ZFCP_ERP_EXIT;
1188 }
1189
1190 return result;
1191}
1192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193static int
1194zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1195{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 switch (result) {
1197 case ZFCP_ERP_SUCCEEDED :
1198 atomic_set(&port->erp_counter, 0);
1199 zfcp_erp_port_unblock(port);
1200 break;
1201 case ZFCP_ERP_FAILED :
1202 atomic_inc(&port->erp_counter);
1203 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001204 zfcp_erp_port_failed(port, 22, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 break;
1206 case ZFCP_ERP_EXIT :
1207 /* nothing */
1208 break;
1209 }
1210
1211 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1212 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1213 result = ZFCP_ERP_EXIT;
1214 }
1215
1216 return result;
1217}
1218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219static int
1220zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1221{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 switch (result) {
1223 case ZFCP_ERP_SUCCEEDED :
1224 atomic_set(&adapter->erp_counter, 0);
1225 zfcp_erp_adapter_unblock(adapter);
1226 break;
1227 case ZFCP_ERP_FAILED :
1228 atomic_inc(&adapter->erp_counter);
1229 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001230 zfcp_erp_adapter_failed(adapter, 23, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 break;
1232 case ZFCP_ERP_EXIT :
1233 /* nothing */
1234 break;
1235 }
1236
1237 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1238 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1239 result = ZFCP_ERP_EXIT;
1240 }
1241
1242 return result;
1243}
1244
Christof Schmitt5f852be2007-05-08 11:16:52 +02001245struct zfcp_erp_add_work {
1246 struct zfcp_unit *unit;
1247 struct work_struct work;
1248};
1249
1250/**
1251 * zfcp_erp_scsi_scan
1252 * @data: pointer to a struct zfcp_erp_add_work
1253 *
1254 * Registers a logical unit with the SCSI stack.
1255 */
1256static void zfcp_erp_scsi_scan(struct work_struct *work)
1257{
1258 struct zfcp_erp_add_work *p =
1259 container_of(work, struct zfcp_erp_add_work, work);
1260 struct zfcp_unit *unit = p->unit;
1261 struct fc_rport *rport = unit->port->rport;
1262 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1263 unit->scsi_lun, 0);
1264 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001265 zfcp_unit_put(unit);
1266 kfree(p);
1267}
1268
1269/**
1270 * zfcp_erp_schedule_work
1271 * @unit: pointer to unit which should be registered with SCSI stack
1272 *
1273 * Schedules work which registers a unit with the SCSI stack
1274 */
1275static void
1276zfcp_erp_schedule_work(struct zfcp_unit *unit)
1277{
1278 struct zfcp_erp_add_work *p;
1279
Swen Schillig0d661322007-07-18 10:55:08 +02001280 p = kzalloc(sizeof(*p), GFP_KERNEL);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001281 if (!p) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001282 dev_err(&unit->port->adapter->ccw_device->dev,
1283 "Out of resources. Could not register unit 0x%016Lx "
1284 "on port 0x%016Lx with SCSI stack.\n",
1285 unit->fcp_lun, unit->port->wwpn);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001286 return;
1287 }
1288
1289 zfcp_unit_get(unit);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001290 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1291 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1292 p->unit = unit;
1293 schedule_work(&p->work);
1294}
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001297 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 *
1299 * purpose: remaining things in good cases,
1300 * escalation in bad cases
1301 *
1302 * returns:
1303 */
1304static int
1305zfcp_erp_strategy_followup_actions(int action,
1306 struct zfcp_adapter *adapter,
1307 struct zfcp_port *port,
1308 struct zfcp_unit *unit, int status)
1309{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 /* initiate follow-up actions depending on success of finished action */
1311 switch (action) {
1312
1313 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1314 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001315 zfcp_erp_port_reopen_all_internal(adapter, 0, 70, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001317 zfcp_erp_adapter_reopen_internal(adapter, 0, 71, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 break;
1319
1320 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1321 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001322 zfcp_erp_port_reopen_internal(port, 0, 72, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001324 zfcp_erp_adapter_reopen_internal(adapter, 0, 73, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 break;
1326
1327 case ZFCP_ERP_ACTION_REOPEN_PORT:
1328 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001329 zfcp_erp_unit_reopen_all_internal(port, 0, 74, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001331 zfcp_erp_port_forced_reopen_internal(port, 0, 75, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 break;
1333
1334 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Heiko Carstenscc16ceb2007-08-28 09:30:42 +02001335 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1336 if (status != ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001337 zfcp_erp_port_reopen_internal(unit->port, 0, 76, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 break;
1339 }
1340
1341 return 0;
1342}
1343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344static int
1345zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1346{
1347 unsigned long flags;
1348
1349 read_lock_irqsave(&zfcp_data.config_lock, flags);
1350 read_lock(&adapter->erp_lock);
1351 if (list_empty(&adapter->erp_ready_head) &&
1352 list_empty(&adapter->erp_running_head)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1354 &adapter->status);
1355 wake_up(&adapter->erp_done_wqh);
Martin Peschke507e4962008-03-27 14:22:05 +01001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 read_unlock(&adapter->erp_lock);
1358 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1359
1360 return 0;
1361}
1362
1363/**
1364 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1365 * @adapter: adapter for which to wait for completion of its error recovery
1366 * Return: 0
1367 */
1368int
1369zfcp_erp_wait(struct zfcp_adapter *adapter)
1370{
1371 int retval = 0;
1372
1373 wait_event(adapter->erp_done_wqh,
1374 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1375 &adapter->status));
1376
1377 return retval;
1378}
1379
Martin Peschke698ec0162008-03-27 14:22:02 +01001380void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001381 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
1383 struct zfcp_port *port;
Martin Peschke698ec0162008-03-27 14:22:02 +01001384 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001387 changed = atomic_test_and_set_mask(mask, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001389 changed = atomic_test_and_clear_mask(mask, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1391 atomic_set(&adapter->erp_counter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001393 if (changed)
1394 zfcp_rec_dbf_event_adapter(id, ref, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
1396 /* Deal with all underlying devices, only pass common_mask */
1397 if (common_mask)
1398 list_for_each_entry(port, &adapter->port_list_head, list)
Martin Peschke698ec0162008-03-27 14:22:02 +01001399 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1400 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
1403/*
1404 * function: zfcp_erp_modify_port_status
1405 *
1406 * purpose: sets the port and all underlying devices to ERP_FAILED
1407 *
1408 */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001409void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +01001410 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 struct zfcp_unit *unit;
Martin Peschke698ec0162008-03-27 14:22:02 +01001413 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001416 changed = atomic_test_and_set_mask(mask, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001418 changed = atomic_test_and_clear_mask(mask, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1420 atomic_set(&port->erp_counter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001422 if (changed)
1423 zfcp_rec_dbf_event_port(id, ref, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 /* Modify status of all underlying devices, only pass common mask */
1426 if (common_mask)
1427 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke698ec0162008-03-27 14:22:02 +01001428 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1429 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430}
1431
1432/*
1433 * function: zfcp_erp_modify_unit_status
1434 *
1435 * purpose: sets the unit to ERP_FAILED
1436 *
1437 */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001438void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +01001439 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Martin Peschke698ec0162008-03-27 14:22:02 +01001441 u32 changed;
1442
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001444 changed = atomic_test_and_set_mask(mask, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001446 changed = atomic_test_and_clear_mask(mask, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1448 atomic_set(&unit->erp_counter, 0);
1449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001451 if (changed)
1452 zfcp_rec_dbf_event_unit(id, ref, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453}
1454
1455/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001456 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 *
1458 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1459 * used to ensure the correct locking
1460 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001461 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 * <0 - failed to initiate action
1463 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001464int zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001465 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
1467 int retval;
1468 unsigned long flags;
1469
1470 read_lock_irqsave(&zfcp_data.config_lock, flags);
1471 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001472 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask, id,
1473 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 write_unlock(&adapter->erp_lock);
1475 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1476
1477 return retval;
1478}
1479
Martin Peschke9467a9b2008-03-27 14:22:03 +01001480static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001481 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
1483 int retval = 0;
1484 struct zfcp_port *port;
1485
1486 list_for_each_entry(port, &adapter->port_list_head, list)
1487 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
Martin Peschke9467a9b2008-03-27 14:22:03 +01001488 zfcp_erp_port_reopen_internal(port, clear_mask, id,
1489 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491 return retval;
1492}
1493
1494/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001495 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001497 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 *
1499 * returns: FIXME
1500 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001501static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001502 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 int retval = 0;
1505 struct zfcp_unit *unit;
1506
1507 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke9467a9b2008-03-27 14:22:03 +01001508 zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 return retval;
1511}
1512
1513/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001514 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 *
1516 * purpose: this routine executes the 'Reopen Adapter' action
1517 * (the entire action is processed synchronously, since
1518 * there are no actions which might be run concurrently
1519 * per definition)
1520 *
1521 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1522 * ZFCP_ERP_FAILED - action finished unsuccessfully
1523 */
1524static int
1525zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1526{
1527 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 retval = zfcp_erp_adapter_strategy_close(erp_action);
1530 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1531 retval = ZFCP_ERP_EXIT;
1532 else
1533 retval = zfcp_erp_adapter_strategy_open(erp_action);
1534
Christof Schmitt553448f2008-06-10 18:20:58 +02001535 if (retval == ZFCP_ERP_FAILED)
Christof Schmitt18edcdb2007-11-05 12:37:45 +01001536 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 return retval;
1539}
1540
1541/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001542 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001544 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 *
1546 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1547 * ZFCP_ERP_FAILED - action finished unsuccessfully
1548 */
1549static int
1550zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1551{
1552 int retval;
1553
1554 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1555 &erp_action->adapter->status);
1556 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1557 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1558 &erp_action->adapter->status);
1559
1560 return retval;
1561}
1562
1563/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001564 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001566 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 *
1568 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1569 * ZFCP_ERP_FAILED - action finished unsuccessfully
1570 */
1571static int
1572zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1573{
1574 int retval;
1575
1576 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1577 &erp_action->adapter->status);
1578 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1579 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1580 &erp_action->adapter->status);
1581
1582 return retval;
1583}
1584
1585/*
1586 * function: zfcp_register_adapter
1587 *
1588 * purpose: allocate the irq associated with this devno and register
1589 * the FSF adapter with the SCSI stack
1590 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001591 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 */
1593static int
1594zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1595{
1596 int retval = ZFCP_ERP_SUCCEEDED;
1597
1598 if (close)
1599 goto close_only;
1600
1601 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1602 if (retval != ZFCP_ERP_SUCCEEDED)
1603 goto failed_qdio;
1604
1605 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1606 if (retval != ZFCP_ERP_SUCCEEDED)
1607 goto failed_openfcp;
1608
1609 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1610 goto out;
1611
1612 close_only:
1613 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1614 &erp_action->adapter->status);
1615
1616 failed_openfcp:
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001617 zfcp_close_fsf(erp_action->adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 failed_qdio:
Volker Sameskec7f6b3a2007-05-29 15:29:49 +02001619 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1620 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1621 ZFCP_STATUS_ADAPTER_XPORT_OK,
1622 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 out:
1624 return retval;
1625}
1626
1627/*
1628 * function: zfcp_qdio_init
1629 *
1630 * purpose: setup QDIO operation for specified adapter
1631 *
1632 * returns: 0 - successful setup
1633 * !0 - failed setup
1634 */
Heiko Carstens364c8552007-10-12 16:11:35 +02001635static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1637{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 struct zfcp_adapter *adapter = erp_action->adapter;
1639
Swen Schillig00bab912008-06-10 18:20:57 +02001640 if (zfcp_qdio_open(adapter))
1641 return ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 /* initialize waitqueue used to wait for free SBALs in requests queue */
1644 init_waitqueue_head(&adapter->request_wq);
1645
1646 /* ok, we did it - skip all cleanups for different failures */
1647 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
Swen Schillig00bab912008-06-10 18:20:57 +02001648 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652static int
1653zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
1654{
Andreas Herrmann2448c452005-12-01 02:50:36 +01001655 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Andreas Herrmann2448c452005-12-01 02:50:36 +01001657 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
1658 if (retval == ZFCP_ERP_FAILED)
1659 return ZFCP_ERP_FAILED;
1660
1661 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
1662 if (retval == ZFCP_ERP_FAILED)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001663 return ZFCP_ERP_FAILED;
1664
1665 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666}
1667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668static int
1669zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
1670{
1671 int retval = ZFCP_ERP_SUCCEEDED;
1672 int retries;
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001673 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 struct zfcp_adapter *adapter = erp_action->adapter;
1675
1676 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001678 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1680 &adapter->status);
Heiko Carstens9f09c542006-07-03 17:32:20 -07001681 write_lock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07001683 write_unlock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (zfcp_fsf_exchange_config_data(erp_action)) {
1685 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 break;
1687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
1689 /*
1690 * Why this works:
1691 * Both the normal completion handler as well as the timeout
1692 * handler will do an 'up' when the 'exchange config data'
1693 * request completes or times out. Thus, the signal to go on
1694 * won't be lost utilizing this semaphore.
1695 * Furthermore, this 'adapter_reopen' action is
1696 * guaranteed to be the only action being there (highest action
1697 * which prevents other actions from being created).
1698 * Resulting from that, the wake signal recognized here
1699 * _must_ be the one belonging to the 'exchange config
1700 * data' request.
1701 */
Christof Schmittaa0fec62008-05-19 12:17:47 +02001702 zfcp_rec_dbf_event_thread_lock(6, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 down(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02001704 zfcp_rec_dbf_event_thread_lock(7, adapter);
Christof Schmitt553448f2008-06-10 18:20:58 +02001705 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 break;
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001707
1708 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1709 &adapter->status))
1710 break;
1711
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001712 /* sleep a little bit before retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +01001713 ssleep(sleep);
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001714 sleep *= 2;
1715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Volker Sameskec7f6b3a2007-05-29 15:29:49 +02001717 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1718 &adapter->status);
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
Christof Schmitt553448f2008-06-10 18:20:58 +02001721 &adapter->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
1724 return retval;
1725}
1726
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001727static int
1728zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
1729{
Andreas Herrmann2448c452005-12-01 02:50:36 +01001730 int ret;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001731 struct zfcp_adapter *adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001732
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001733 adapter = erp_action->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001734 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
1735
Heiko Carstens9f09c542006-07-03 17:32:20 -07001736 write_lock_irq(&adapter->erp_lock);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001737 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07001738 write_unlock_irq(&adapter->erp_lock);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001739
Swen Schillig52ef11a2007-08-28 09:31:09 +02001740 ret = zfcp_fsf_exchange_port_data(erp_action);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001741 if (ret == -EOPNOTSUPP) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001742 return ZFCP_ERP_SUCCEEDED;
1743 } else if (ret) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001744 return ZFCP_ERP_FAILED;
1745 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001746
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001747 ret = ZFCP_ERP_SUCCEEDED;
Christof Schmittaa0fec62008-05-19 12:17:47 +02001748 zfcp_rec_dbf_event_thread_lock(8, adapter);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001749 down(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02001750 zfcp_rec_dbf_event_thread_lock(9, adapter);
Christof Schmitt553448f2008-06-10 18:20:58 +02001751 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT)
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001752 ret = ZFCP_ERP_FAILED;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001753
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001754 return ret;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001755}
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757static int
1758zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
1759 *erp_action)
1760{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
Swen Schilligd26ab062008-05-19 12:17:37 +02001763 atomic_set(&adapter->stat_miss, 16);
1764 return zfcp_status_read_refill(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765}
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001768 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 *
1770 * purpose: this routine executes the 'Reopen Physical Port' action
1771 *
1772 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1773 * ZFCP_ERP_SUCCEEDED - action finished successfully
1774 * ZFCP_ERP_FAILED - action finished unsuccessfully
1775 */
1776static int
1777zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
1778{
1779 int retval = ZFCP_ERP_FAILED;
1780 struct zfcp_port *port = erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 switch (erp_action->step) {
1783
1784 /*
1785 * FIXME:
1786 * the ULP spec. begs for waiting for oustanding commands
1787 */
1788 case ZFCP_ERP_STEP_UNINITIALIZED:
1789 zfcp_erp_port_strategy_clearstati(port);
1790 /*
1791 * it would be sufficient to test only the normal open flag
1792 * since the phys. open flag cannot be set if the normal
1793 * open flag is unset - however, this is for readabilty ...
1794 */
1795 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
1796 ZFCP_STATUS_COMMON_OPEN),
1797 &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 retval =
1799 zfcp_erp_port_forced_strategy_close(erp_action);
1800 } else
1801 retval = ZFCP_ERP_FAILED;
1802 break;
1803
1804 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
1805 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
1806 &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 retval = ZFCP_ERP_FAILED;
1808 } else
1809 retval = ZFCP_ERP_SUCCEEDED;
1810 break;
1811 }
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 return retval;
1814}
1815
1816/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001817 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 *
1819 * purpose: this routine executes the 'Reopen Port' action
1820 *
1821 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1822 * ZFCP_ERP_SUCCEEDED - action finished successfully
1823 * ZFCP_ERP_FAILED - action finished unsuccessfully
1824 */
1825static int
1826zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
1827{
1828 int retval = ZFCP_ERP_FAILED;
1829 struct zfcp_port *port = erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831 switch (erp_action->step) {
1832
1833 /*
1834 * FIXME:
1835 * the ULP spec. begs for waiting for oustanding commands
1836 */
1837 case ZFCP_ERP_STEP_UNINITIALIZED:
1838 zfcp_erp_port_strategy_clearstati(port);
1839 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 retval = zfcp_erp_port_strategy_close(erp_action);
1841 goto out;
1842 } /* else it's already closed, open it */
1843 break;
1844
1845 case ZFCP_ERP_STEP_PORT_CLOSING:
1846 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 retval = ZFCP_ERP_FAILED;
1848 goto out;
1849 } /* else it's closed now, open it */
1850 break;
1851 }
1852 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1853 retval = ZFCP_ERP_EXIT;
1854 else
1855 retval = zfcp_erp_port_strategy_open(erp_action);
1856
1857 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 return retval;
1859}
1860
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861static int
1862zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
1863{
1864 int retval;
1865
1866 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
1867 &erp_action->port->status))
1868 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
1869 else
1870 retval = zfcp_erp_port_strategy_open_common(erp_action);
1871
1872 return retval;
1873}
1874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875static int
1876zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
1877{
1878 int retval = 0;
1879 struct zfcp_adapter *adapter = erp_action->adapter;
1880 struct zfcp_port *port = erp_action->port;
1881
1882 switch (erp_action->step) {
1883
1884 case ZFCP_ERP_STEP_UNINITIALIZED:
1885 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
1886 case ZFCP_ERP_STEP_PORT_CLOSING:
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001887 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
6f71d9b2005-04-10 23:04:28 -05001888 if (port->wwpn != adapter->peer_wwpn) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001889 dev_err(&adapter->ccw_device->dev,
1890 "Failed to open port 0x%016Lx, "
1891 "Peer WWPN 0x%016Lx does not match.\n",
1892 port->wwpn, adapter->peer_wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001893 zfcp_erp_port_failed(port, 25, NULL);
6f71d9b2005-04-10 23:04:28 -05001894 retval = ZFCP_ERP_FAILED;
1895 break;
1896 }
1897 port->d_id = adapter->peer_d_id;
1898 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1899 retval = zfcp_erp_port_strategy_open_port(erp_action);
1900 break;
1901 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 if (!(adapter->nameserver_port)) {
1903 retval = zfcp_nameserver_enqueue(adapter);
1904 if (retval != 0) {
Christof Schmitt553448f2008-06-10 18:20:58 +02001905 dev_err(&adapter->ccw_device->dev,
1906 "Nameserver port unavailable.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 retval = ZFCP_ERP_FAILED;
1908 break;
1909 }
1910 }
1911 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1912 &adapter->nameserver_port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 /* nameserver port may live again */
1914 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
1915 &adapter->nameserver_port->status);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001916 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001917 77, erp_action) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 erp_action->step =
1919 ZFCP_ERP_STEP_NAMESERVER_OPEN;
1920 retval = ZFCP_ERP_CONTINUES;
1921 } else
1922 retval = ZFCP_ERP_FAILED;
1923 break;
1924 }
1925 /* else nameserver port is already open, fall through */
1926 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
1927 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
Christof Schmitt553448f2008-06-10 18:20:58 +02001928 &adapter->nameserver_port->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 retval = ZFCP_ERP_FAILED;
Christof Schmitt553448f2008-06-10 18:20:58 +02001930 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 retval = zfcp_erp_port_strategy_open_common_lookup
1932 (erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 break;
1934
1935 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
1936 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
1937 if (atomic_test_mask
1938 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
Martin Peschke1f6f7122008-04-18 12:51:55 +02001939 zfcp_erp_port_failed(port, 26, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 retval = ZFCP_ERP_EXIT;
Christof Schmitt553448f2008-06-10 18:20:58 +02001941 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 retval = ZFCP_ERP_FAILED;
Christof Schmitt553448f2008-06-10 18:20:58 +02001943 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 retval = zfcp_erp_port_strategy_open_port(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 break;
1946
1947 case ZFCP_ERP_STEP_PORT_OPENING:
1948 /* D_ID might have changed during open */
1949 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
1950 ZFCP_STATUS_PORT_DID_DID),
Christof Schmitt553448f2008-06-10 18:20:58 +02001951 &port->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 retval = ZFCP_ERP_SUCCEEDED;
Christof Schmitt553448f2008-06-10 18:20:58 +02001953 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 break;
1956
1957 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02001958 /* unknown erp step */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 retval = ZFCP_ERP_FAILED;
1960 }
1961
1962 return retval;
1963}
1964
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965static int
1966zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
1967{
1968 int retval;
1969 struct zfcp_port *port = erp_action->port;
1970
1971 switch (erp_action->step) {
1972
1973 case ZFCP_ERP_STEP_UNINITIALIZED:
1974 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
1975 case ZFCP_ERP_STEP_PORT_CLOSING:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 retval = zfcp_erp_port_strategy_open_port(erp_action);
1977 break;
1978
1979 case ZFCP_ERP_STEP_PORT_OPENING:
Christof Schmitt553448f2008-06-10 18:20:58 +02001980 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 retval = ZFCP_ERP_SUCCEEDED;
Christof Schmitt553448f2008-06-10 18:20:58 +02001982 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 /* this is needed anyway (dont care for retval of wakeup) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
1986 break;
1987
1988 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02001989 /* unknown erp step */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 retval = ZFCP_ERP_FAILED;
1991 }
1992
1993 return retval;
1994}
1995
1996/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001997 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 *
1999 * purpose: makes the erp thread continue with reopen (physical) port
2000 * actions which have been paused until the name server port
2001 * is opened (or failed)
2002 *
2003 * returns: 0 (a kind of void retval, its not used)
2004 */
2005static int
2006zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2007 *ns_erp_action)
2008{
2009 int retval = 0;
2010 unsigned long flags;
2011 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2012 struct zfcp_erp_action *erp_action, *tmp;
2013
2014 read_lock_irqsave(&adapter->erp_lock, flags);
2015 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2016 list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 if (atomic_test_mask(
2019 ZFCP_STATUS_COMMON_ERP_FAILED,
2020 &adapter->nameserver_port->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +02002021 zfcp_erp_port_failed(erp_action->port, 27,
2022 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 zfcp_erp_action_ready(erp_action);
2024 }
2025 }
2026 read_unlock_irqrestore(&adapter->erp_lock, flags);
2027
2028 return retval;
2029}
2030
2031/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002032 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002034 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 *
2036 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2037 * ZFCP_ERP_FAILED - action finished unsuccessfully
2038 */
2039static int
2040zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2041{
2042 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 retval = zfcp_fsf_close_physical_port(erp_action);
2045 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 retval = ZFCP_ERP_NOMEM;
2047 goto out;
2048 }
2049 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2050 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 /* could not send 'open', fail */
2052 retval = ZFCP_ERP_FAILED;
2053 goto out;
2054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 retval = ZFCP_ERP_CONTINUES;
2056 out:
2057 return retval;
2058}
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060static int
2061zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2062{
2063 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2066 ZFCP_STATUS_COMMON_CLOSING |
2067 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2068 ZFCP_STATUS_PORT_DID_DID |
2069 ZFCP_STATUS_PORT_PHYS_CLOSING |
2070 ZFCP_STATUS_PORT_INVALID_WWPN,
2071 &port->status);
2072 return retval;
2073}
2074
2075/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002076 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002078 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 *
2080 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2081 * ZFCP_ERP_FAILED - action finished unsuccessfully
2082 */
2083static int
2084zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2085{
2086 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 retval = zfcp_fsf_close_port(erp_action);
2089 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 retval = ZFCP_ERP_NOMEM;
2091 goto out;
2092 }
2093 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2094 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* could not send 'close', fail */
2096 retval = ZFCP_ERP_FAILED;
2097 goto out;
2098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 retval = ZFCP_ERP_CONTINUES;
2100 out:
2101 return retval;
2102}
2103
2104/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002105 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002107 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 *
2109 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2110 * ZFCP_ERP_FAILED - action finished unsuccessfully
2111 */
2112static int
2113zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2114{
2115 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 retval = zfcp_fsf_open_port(erp_action);
2118 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 retval = ZFCP_ERP_NOMEM;
2120 goto out;
2121 }
2122 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2123 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /* could not send 'open', fail */
2125 retval = ZFCP_ERP_FAILED;
2126 goto out;
2127 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 retval = ZFCP_ERP_CONTINUES;
2129 out:
2130 return retval;
2131}
2132
2133/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002134 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002136 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 *
2138 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2139 * ZFCP_ERP_FAILED - action finished unsuccessfully
2140 */
2141static int
2142zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2143{
2144 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Christof Schmitt24073b42008-06-10 18:20:54 +02002146 retval = zfcp_fc_ns_gid_pn_request(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 retval = ZFCP_ERP_NOMEM;
2149 goto out;
2150 }
2151 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2152 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 /* could not send nameserver request, fail */
2154 retval = ZFCP_ERP_FAILED;
2155 goto out;
2156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 retval = ZFCP_ERP_CONTINUES;
2158 out:
2159 return retval;
2160}
2161
2162/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002163 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 *
2165 * purpose: this routine executes the 'Reopen Unit' action
2166 * currently no retries
2167 *
2168 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2169 * ZFCP_ERP_SUCCEEDED - action finished successfully
2170 * ZFCP_ERP_FAILED - action finished unsuccessfully
2171 */
2172static int
2173zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2174{
2175 int retval = ZFCP_ERP_FAILED;
2176 struct zfcp_unit *unit = erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178 switch (erp_action->step) {
2179
2180 /*
2181 * FIXME:
2182 * the ULP spec. begs for waiting for oustanding commands
2183 */
2184 case ZFCP_ERP_STEP_UNINITIALIZED:
2185 zfcp_erp_unit_strategy_clearstati(unit);
2186 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 retval = zfcp_erp_unit_strategy_close(erp_action);
2188 break;
2189 }
2190 /* else it's already closed, fall through */
2191 case ZFCP_ERP_STEP_UNIT_CLOSING:
Christof Schmitt553448f2008-06-10 18:20:58 +02002192 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 retval = ZFCP_ERP_FAILED;
Christof Schmitt553448f2008-06-10 18:20:58 +02002194 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2196 retval = ZFCP_ERP_EXIT;
Christof Schmitt553448f2008-06-10 18:20:58 +02002197 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 retval =
2199 zfcp_erp_unit_strategy_open(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 break;
2201
2202 case ZFCP_ERP_STEP_UNIT_OPENING:
Christof Schmitt553448f2008-06-10 18:20:58 +02002203 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 retval = ZFCP_ERP_SUCCEEDED;
Christof Schmitt553448f2008-06-10 18:20:58 +02002205 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 break;
2208 }
2209
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 return retval;
2211}
2212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213static int
2214zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2215{
2216 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
2218 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2219 ZFCP_STATUS_COMMON_CLOSING |
2220 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2221 ZFCP_STATUS_UNIT_SHARED |
2222 ZFCP_STATUS_UNIT_READONLY,
2223 &unit->status);
2224
2225 return retval;
2226}
2227
2228/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002229 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002231 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 *
2233 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2234 * ZFCP_ERP_FAILED - action finished unsuccessfully
2235 */
2236static int
2237zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2238{
2239 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 retval = zfcp_fsf_close_unit(erp_action);
2242 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 retval = ZFCP_ERP_NOMEM;
2244 goto out;
2245 }
2246 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2247 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 /* could not send 'close', fail */
2249 retval = ZFCP_ERP_FAILED;
2250 goto out;
2251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 retval = ZFCP_ERP_CONTINUES;
2253
2254 out:
2255 return retval;
2256}
2257
2258/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002259 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002261 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 *
2263 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2264 * ZFCP_ERP_FAILED - action finished unsuccessfully
2265 */
2266static int
2267zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2268{
2269 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 retval = zfcp_fsf_open_unit(erp_action);
2272 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 retval = ZFCP_ERP_NOMEM;
2274 goto out;
2275 }
2276 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2277 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 /* could not send 'open', fail */
2279 retval = ZFCP_ERP_FAILED;
2280 goto out;
2281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 retval = ZFCP_ERP_CONTINUES;
2283 out:
2284 return retval;
2285}
2286
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002287void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288{
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002289 BUG_ON(!fsf_req->erp_action);
2290 fsf_req->timer.function = zfcp_erp_timeout_handler;
2291 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2292 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2293 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002297 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 *
2299 * purpose: enqueue the specified error recovery action, if needed
2300 *
2301 * returns:
2302 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002303static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
2304 struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +02002305 struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306{
Martin Peschke9467a9b2008-03-27 14:22:03 +01002307 int retval = 1, need = want;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 struct zfcp_erp_action *erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 u32 status = 0;
2310
2311 /*
2312 * We need some rules here which check whether we really need
2313 * this action or whether we should just drop it.
2314 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2315 * 'Reopen Unit' request for an associated unit since we can't
2316 * satisfy this request now. A 'Reopen Port' action will trigger
2317 * 'Reopen Unit' actions when it completes.
2318 * Thus, there are only actions in the queue which can immediately be
2319 * executed. This makes the processing of the action queue more
2320 * efficient.
2321 */
2322
2323 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2324 &adapter->status))
2325 return -EIO;
2326
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 /* check whether we really need this */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002328 switch (want) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2330 if (atomic_test_mask
2331 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 goto out;
2333 }
2334 if (!atomic_test_mask
2335 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2336 atomic_test_mask
2337 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2338 goto out;
2339 }
2340 if (!atomic_test_mask
Martin Peschke9467a9b2008-03-27 14:22:03 +01002341 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
2342 need = ZFCP_ERP_ACTION_REOPEN_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 /* fall through !!! */
2344
2345 case ZFCP_ERP_ACTION_REOPEN_PORT:
2346 if (atomic_test_mask
2347 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 goto out;
2349 }
2350 /* fall through !!! */
2351
2352 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Andreas Herrmann3734d242005-09-13 21:47:11 +02002353 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
Christof Schmitt553448f2008-06-10 18:20:58 +02002354 &port->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 if (!atomic_test_mask
2357 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2358 atomic_test_mask
2359 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2360 goto out;
2361 }
2362 if (!atomic_test_mask
Martin Peschke9467a9b2008-03-27 14:22:03 +01002363 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
2364 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 /* fall through !!! */
2366
2367 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2368 if (atomic_test_mask
2369 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 goto out;
2371 }
2372 break;
2373
2374 default:
Christof Schmitt553448f2008-06-10 18:20:58 +02002375 /* unknown erp action */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 goto out;
2377 }
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 /* mark adapter to have some error recovery pending */
2380 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2381
2382 /* setup error recovery action */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002383 switch (need) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
2385 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2386 zfcp_unit_get(unit);
2387 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2388 erp_action = &unit->erp_action;
2389 if (!atomic_test_mask
2390 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
2391 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2392 break;
2393
2394 case ZFCP_ERP_ACTION_REOPEN_PORT:
2395 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2396 zfcp_port_get(port);
2397 zfcp_erp_action_dismiss_port(port);
2398 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
2399 erp_action = &port->erp_action;
2400 if (!atomic_test_mask
2401 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
2402 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2403 break;
2404
2405 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2406 zfcp_adapter_get(adapter);
2407 zfcp_erp_action_dismiss_adapter(adapter);
2408 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
2409 erp_action = &adapter->erp_action;
2410 if (!atomic_test_mask
2411 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
2412 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2413 break;
2414 }
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
2417 erp_action->adapter = adapter;
2418 erp_action->port = port;
2419 erp_action->unit = unit;
Martin Peschke9467a9b2008-03-27 14:22:03 +01002420 erp_action->action = need;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 erp_action->status = status;
2422
2423 ++adapter->erp_total_count;
2424
2425 /* finally put it into 'ready' queue and kick erp thread */
Martin Peschke86e8dfc2007-11-15 13:57:17 +01002426 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02002428 zfcp_rec_dbf_event_thread(1, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 retval = 0;
2430 out:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002431 zfcp_rec_dbf_event_trigger(id, ref, want, need, erp_action,
Martin Peschke9467a9b2008-03-27 14:22:03 +01002432 adapter, port, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 return retval;
2434}
2435
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436static int
2437zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
2438{
2439 int retval = 0;
2440 struct zfcp_adapter *adapter = erp_action->adapter;
2441
2442 --adapter->erp_total_count;
2443 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
2444 --adapter->erp_low_mem_count;
2445 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
2446 }
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 list_del(&erp_action->list);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002449 zfcp_rec_dbf_event_action(144, erp_action);
2450
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 switch (erp_action->action) {
2452 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2453 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2454 &erp_action->unit->status);
2455 break;
2456 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2457 case ZFCP_ERP_ACTION_REOPEN_PORT:
2458 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2459 &erp_action->port->status);
2460 break;
2461 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2462 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2463 &erp_action->adapter->status);
2464 break;
2465 default:
2466 /* bug */
2467 break;
2468 }
2469 return retval;
2470}
2471
2472/**
2473 * zfcp_erp_action_cleanup
2474 *
Adrian Bunk575c9682006-01-15 02:00:17 +01002475 * Register unit with scsi stack if appropriate and fix reference counts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 * Note: Temporary units are not registered with scsi stack.
2477 */
2478static void
2479zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
2480 struct zfcp_port *port, struct zfcp_unit *unit,
2481 int result)
2482{
2483 switch (action) {
2484 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2485 if ((result == ZFCP_ERP_SUCCEEDED)
2486 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
2487 &unit->status))
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002488 && !unit->device
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01002489 && port->rport) {
2490 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
2491 &unit->status);
Christof Schmitt5f852be2007-05-08 11:16:52 +02002492 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
2493 &unit->status) == 0)
2494 zfcp_erp_schedule_work(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01002495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 zfcp_unit_put(unit);
2497 break;
2498 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2499 case ZFCP_ERP_ACTION_REOPEN_PORT:
Andreas Herrmann338151e2006-05-22 18:25:56 +02002500 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
2501 &port->status)) {
2502 zfcp_port_put(port);
2503 break;
2504 }
2505
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002506 if ((result == ZFCP_ERP_SUCCEEDED)
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002507 && !port->rport) {
2508 struct fc_rport_identifiers ids;
2509 ids.node_name = port->wwnn;
2510 ids.port_name = port->wwpn;
2511 ids.port_id = port->d_id;
2512 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
2513 port->rport =
2514 fc_remote_port_add(adapter->scsi_host, 0, &ids);
2515 if (!port->rport)
Christof Schmitt553448f2008-06-10 18:20:58 +02002516 dev_err(&adapter->ccw_device->dev,
2517 "Failed registration of rport "
2518 "0x%016Lx.\n", port->wwpn);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002519 else {
Christof Schmitt5f852be2007-05-08 11:16:52 +02002520 scsi_target_unblock(&port->rport->dev);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002521 port->rport->maxframe_size = port->maxframe_size;
2522 port->rport->supported_classes =
2523 port->supported_classes;
2524 }
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002525 }
Andreas Herrmann338151e2006-05-22 18:25:56 +02002526 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
2527 fc_remote_port_delete(port->rport);
2528 port->rport = NULL;
2529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 zfcp_port_put(port);
2531 break;
2532 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Andreas Herrmann338151e2006-05-22 18:25:56 +02002533 if (result != ZFCP_ERP_SUCCEEDED) {
Andreas Herrmann338151e2006-05-22 18:25:56 +02002534 list_for_each_entry(port, &adapter->port_list_head, list)
2535 if (port->rport &&
2536 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2537 &port->status)) {
2538 fc_remote_port_delete(port->rport);
2539 port->rport = NULL;
2540 }
2541 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 zfcp_adapter_put(adapter);
2543 break;
2544 default:
2545 break;
2546 }
2547}
2548
2549
Andreas Herrmann81654282006-09-18 22:30:36 +02002550static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 struct zfcp_port *port;
2553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
2555 zfcp_erp_action_dismiss(&adapter->erp_action);
2556 else
2557 list_for_each_entry(port, &adapter->port_list_head, list)
2558 zfcp_erp_action_dismiss_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559}
2560
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02002561static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
2566 zfcp_erp_action_dismiss(&port->erp_action);
2567 else
2568 list_for_each_entry(unit, &port->unit_list_head, list)
2569 zfcp_erp_action_dismiss_unit(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02002572static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
2575 zfcp_erp_action_dismiss(&unit->erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
Heiko Carstens364c8552007-10-12 16:11:35 +02002578static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002581 zfcp_rec_dbf_event_action(145, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
Heiko Carstens364c8552007-10-12 16:11:35 +02002584static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002587 zfcp_rec_dbf_event_action(146, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
Martin Peschke1f6f7122008-04-18 12:51:55 +02002590void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002591{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002592 unsigned long flags;
2593
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002594 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01002595 zfcp_erp_modify_port_status(port, id, ref,
2596 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002597 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01002598 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002599}
2600
Martin Peschke1f6f7122008-04-18 12:51:55 +02002601void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002602{
Martin Peschke698ec0162008-03-27 14:22:02 +01002603 zfcp_erp_modify_unit_status(unit, id, ref,
2604 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01002605 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002606}
2607
Martin Peschke1f6f7122008-04-18 12:51:55 +02002608void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 unsigned long flags;
2611
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01002613 zfcp_erp_modify_port_status(port, id, ref,
2614 ZFCP_STATUS_COMMON_ERP_FAILED |
2615 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2617}
2618
Martin Peschke1f6f7122008-04-18 12:51:55 +02002619void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620{
Martin Peschke698ec0162008-03-27 14:22:02 +01002621 zfcp_erp_modify_unit_status(unit, id, ref,
2622 ZFCP_STATUS_COMMON_ERP_FAILED |
2623 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624}
2625
Martin Peschke9467a9b2008-03-27 14:22:03 +01002626void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02002627 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
2629 struct zfcp_port *port;
2630 unsigned long flags;
2631
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002632 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2633 return;
2634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 read_lock_irqsave(&zfcp_data.config_lock, flags);
6f71d9b2005-04-10 23:04:28 -05002636 if (adapter->nameserver_port)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002637 zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 list_for_each_entry(port, &adapter->port_list_head, list)
2639 if (port != adapter->nameserver_port)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002640 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2642}
2643
Martin Peschke1f6f7122008-04-18 12:51:55 +02002644void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 struct zfcp_unit *unit;
2647
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002649 &port->status) &&
2650 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 &port->status)) {
2652 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
2653 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002654 zfcp_erp_unit_access_changed(unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 return;
2656 }
2657
Christof Schmitt553448f2008-06-10 18:20:58 +02002658 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659}
2660
Martin Peschke1f6f7122008-04-18 12:51:55 +02002661void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002663 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
2664 &unit->status) &&
2665 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
2666 &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return;
2668
Christof Schmitt553448f2008-06-10 18:20:58 +02002669 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}