blob: 4a6d08363d4b98dc7c5414defe462a2be12ccf07 [file] [log] [blame]
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001/*
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02002 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andreas Herrmann4a9d2d82006-05-22 18:14:08 +02005 * (C) Copyright IBM Corp. 2002, 2006
Swen Schillig41fa2ad2007-09-07 09:15:31 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
22#define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "zfcp_ext.h"
25
Martin Peschke9467a9b2008-03-27 14:22:03 +010026static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020027 void *);
Martin Peschke9467a9b2008-03-27 14:22:03 +010028static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020029 void *);
30static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int, u8, void *);
31static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int, u8, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Martin Peschke9467a9b2008-03-27 14:22:03 +010033static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int, u8,
Martin Peschke1f6f7122008-04-18 12:51:55 +020034 void *);
35static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int, u8,
36 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
39static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
40static void zfcp_erp_port_block(struct zfcp_port *, int);
41static void zfcp_erp_port_unblock(struct zfcp_port *);
42static void zfcp_erp_unit_block(struct zfcp_unit *, int);
43static void zfcp_erp_unit_unblock(struct zfcp_unit *);
44
45static int zfcp_erp_thread(void *);
46
47static int zfcp_erp_strategy(struct zfcp_erp_action *);
48
49static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
50static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
51static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
52static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
53static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
54static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
55static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
56 struct zfcp_port *,
57 struct zfcp_unit *, int);
Heiko Carstens364c8552007-10-12 16:11:35 +020058static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
60 struct zfcp_port *,
61 struct zfcp_unit *, int);
62static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
63static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
64
65static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
66static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
67static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
69static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
70static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
71static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020072static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static int zfcp_erp_adapter_strategy_open_fsf_statusread(
74 struct zfcp_erp_action *);
75
76static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
77static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
78
79static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
80static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
81static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
82static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
83static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
84static int zfcp_erp_port_strategy_open_nameserver_wakeup(
85 struct zfcp_erp_action *);
86static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
87static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
88static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
89
90static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
91static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
92static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
93static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
94
Andreas Herrmann81654282006-09-18 22:30:36 +020095static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020096static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
97static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
98static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100101 struct zfcp_port *, struct zfcp_unit *,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200102 u8 id, void *ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
104static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
105 struct zfcp_port *, struct zfcp_unit *,
106 int);
107
108static void zfcp_erp_action_ready(struct zfcp_erp_action *);
109static int zfcp_erp_action_exists(struct zfcp_erp_action *);
110
Heiko Carstens364c8552007-10-12 16:11:35 +0200111static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
112static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static void zfcp_erp_memwait_handler(unsigned long);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200115
116/**
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200117 * zfcp_close_fsf - stop FSF operations for an adapter
118 *
119 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
120 * requests waiting for completion; especially this returns SCSI commands
121 * with error state).
122 */
123static void zfcp_close_fsf(struct zfcp_adapter *adapter)
124{
125 /* close queues to ensure that buffers are not accessed by adapter */
Swen Schillig00bab912008-06-10 18:20:57 +0200126 zfcp_qdio_close(adapter);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200127 zfcp_fsf_req_dismiss_all(adapter);
128 /* reset FSF request sequence number */
129 adapter->fsf_req_seq_no = 0;
130 /* all ports and units are closed */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200131 zfcp_erp_modify_adapter_status(adapter, 24, NULL,
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200132 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/**
136 * zfcp_fsf_request_timeout_handler - called if a request timed out
137 * @data: pointer to adapter for handler function
138 *
139 * This function needs to be called if requests (ELS, Generic Service,
140 * or SCSI commands) exceed a certain time limit. The assumption is
141 * that after the time limit the adapter get stuck. So we trigger a reopen of
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200142 * the adapter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200144static void zfcp_fsf_request_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200146 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Martin Peschke1f6f7122008-04-18 12:51:55 +0200147 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
148 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200151void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200153 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
154 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
Christof Schmitt9e3738f2007-03-28 14:20:40 +0200155 fsf_req->timer.expires = jiffies + timeout;
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200156 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
159/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200160 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 *
162 * purpose: called if an adapter failed,
163 * initiates adapter recovery which is done
164 * asynchronously
165 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200166 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 * <0 - failed to initiate action
168 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100169static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200170 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 int retval;
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 ZFCP_LOG_DEBUG("reopen adapter %s\n",
175 zfcp_get_busid_by_adapter(adapter));
176
177 zfcp_erp_adapter_block(adapter, clear_mask);
178
179 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
180 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
181 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /* ensure propagation of failed status to new devices */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200183 zfcp_erp_adapter_failed(adapter, 13, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 retval = -EIO;
185 goto out;
186 }
187 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100188 adapter, NULL, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 out:
191 return retval;
192}
193
194/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200195 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 *
197 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
198 * used to ensure the correct locking
199 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200200 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 * <0 - failed to initiate action
202 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100203int zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200204 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 int retval;
207 unsigned long flags;
208
209 read_lock_irqsave(&zfcp_data.config_lock, flags);
210 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100211 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 write_unlock(&adapter->erp_lock);
213 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
214
215 return retval;
216}
217
Martin Peschke9467a9b2008-03-27 14:22:03 +0100218int zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200219 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 int retval;
222
223 retval = zfcp_erp_adapter_reopen(adapter,
224 ZFCP_STATUS_COMMON_RUNNING |
225 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100226 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 return retval;
229}
230
Martin Peschke9467a9b2008-03-27 14:22:03 +0100231int zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200232 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
234 int retval;
235
236 retval = zfcp_erp_port_reopen(port,
237 ZFCP_STATUS_COMMON_RUNNING |
238 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100239 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 return retval;
242}
243
Martin Peschke9467a9b2008-03-27 14:22:03 +0100244int zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200245 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 int retval;
248
249 retval = zfcp_erp_unit_reopen(unit,
250 ZFCP_STATUS_COMMON_RUNNING |
251 ZFCP_STATUS_COMMON_ERP_FAILED |
Martin Peschke9467a9b2008-03-27 14:22:03 +0100252 clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 return retval;
255}
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200258 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 *
260 * purpose: called if a port failed to be opened normally
261 * initiates Forced Reopen recovery which is done
262 * asynchronously
263 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200264 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 * <0 - failed to initiate action
266 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100267static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200268 int clear_mask, u8 id,
269 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
274 port->wwpn, zfcp_get_busid_by_port(port));
275
276 zfcp_erp_port_block(port, clear_mask);
277
278 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
279 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
280 "on adapter %s\n", port->wwpn,
281 zfcp_get_busid_by_port(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 retval = -EIO;
283 goto out;
284 }
285
286 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100287 port->adapter, port, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 out:
290 return retval;
291}
292
293/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200294 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 *
296 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
297 * used to ensure the correct locking
298 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200299 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 * <0 - failed to initiate action
301 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100302int zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200303 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
305 int retval;
306 unsigned long flags;
307 struct zfcp_adapter *adapter;
308
309 adapter = port->adapter;
310 read_lock_irqsave(&zfcp_data.config_lock, flags);
311 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100312 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask, id,
313 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 write_unlock(&adapter->erp_lock);
315 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
316
317 return retval;
318}
319
320/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200321 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 *
323 * purpose: called if a port is to be opened
324 * initiates Reopen recovery which is done
325 * asynchronously
326 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200327 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * <0 - failed to initiate action
329 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100330static int zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200331 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
333 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
336 port->wwpn, zfcp_get_busid_by_port(port));
337
338 zfcp_erp_port_block(port, clear_mask);
339
340 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
341 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
342 "on adapter %s\n", port->wwpn,
343 zfcp_get_busid_by_port(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* ensure propagation of failed status to new devices */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200345 zfcp_erp_port_failed(port, 14, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 retval = -EIO;
347 goto out;
348 }
349
350 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100351 port->adapter, port, NULL, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 out:
354 return retval;
355}
356
357/**
358 * zfcp_erp_port_reopen - initiate reopen of a remote port
359 * @port: port to be reopened
360 * @clear_mask: specifies flags in port status to be cleared
361 * Return: 0 on success, < 0 on error
362 *
363 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
364 * correct locking. An error recovery task is initiated to do the reopen.
365 * To wait for the completion of the reopen zfcp_erp_wait should be used.
366 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200367int zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask, u8 id,
368 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
370 int retval;
371 unsigned long flags;
372 struct zfcp_adapter *adapter = port->adapter;
373
374 read_lock_irqsave(&zfcp_data.config_lock, flags);
375 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100376 retval = zfcp_erp_port_reopen_internal(port, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 write_unlock(&adapter->erp_lock);
378 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
379
380 return retval;
381}
382
383/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200384 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 *
386 * purpose: called if a unit is to be opened
387 * initiates Reopen recovery which is done
388 * asynchronously
389 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200390 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 * <0 - failed to initiate action
392 */
Martin Peschke9467a9b2008-03-27 14:22:03 +0100393static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +0200394 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 int retval;
397 struct zfcp_adapter *adapter = unit->port->adapter;
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
400 "on adapter %s\n", unit->fcp_lun,
401 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
402
403 zfcp_erp_unit_block(unit, clear_mask);
404
405 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
406 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
407 "on port 0x%016Lx on adapter %s\n",
408 unit->fcp_lun, unit->port->wwpn,
409 zfcp_get_busid_by_unit(unit));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 retval = -EIO;
411 goto out;
412 }
413
414 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
Martin Peschke9467a9b2008-03-27 14:22:03 +0100415 adapter, unit->port, unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 out:
417 return retval;
418}
419
420/**
421 * zfcp_erp_unit_reopen - initiate reopen of a unit
422 * @unit: unit to be reopened
423 * @clear_mask: specifies flags in unit status to be cleared
424 * Return: 0 on success, < 0 on error
425 *
426 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
427 * locking. An error recovery task is initiated to do the reopen.
428 * To wait for the completion of the reopen zfcp_erp_wait should be used.
429 */
Martin Peschke1f6f7122008-04-18 12:51:55 +0200430int zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask, u8 id,
431 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 int retval;
434 unsigned long flags;
435 struct zfcp_adapter *adapter;
436 struct zfcp_port *port;
437
438 port = unit->port;
439 adapter = port->adapter;
440
441 read_lock_irqsave(&zfcp_data.config_lock, flags);
442 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +0100443 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 write_unlock(&adapter->erp_lock);
445 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
446
447 return retval;
448}
449
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200450/**
451 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200453static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200455 zfcp_erp_modify_adapter_status(adapter, 15, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 ZFCP_STATUS_COMMON_UNBLOCKED |
457 clear_mask, ZFCP_CLEAR);
458}
459
Martin Peschke698ec0162008-03-27 14:22:02 +0100460/* FIXME: isn't really atomic */
461/*
462 * returns the mask which has not been set so far, i.e.
463 * 0 if no bit has been changed, !0 if some bit has been changed
464 */
465static int atomic_test_and_set_mask(unsigned long mask, atomic_t *v)
466{
467 int changed_bits = (atomic_read(v) /*XOR*/^ mask) & mask;
468 atomic_set_mask(mask, v);
469 return changed_bits;
470}
471
472/* FIXME: isn't really atomic */
473/*
474 * returns the mask which has not been cleared so far, i.e.
475 * 0 if no bit has been changed, !0 if some bit has been changed
476 */
477static int atomic_test_and_clear_mask(unsigned long mask, atomic_t *v)
478{
479 int changed_bits = atomic_read(v) & mask;
480 atomic_clear_mask(mask, v);
481 return changed_bits;
482}
483
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200484/**
485 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200487static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
Martin Peschke698ec0162008-03-27 14:22:02 +0100489 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
490 &adapter->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200491 zfcp_rec_dbf_event_adapter(16, NULL, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492}
493
494/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200495 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 *
497 * purpose: disable I/O,
498 * return any open requests and clean them up,
499 * aim: no pending and incoming I/O
500 *
501 * returns:
502 */
503static void
504zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
505{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200506 zfcp_erp_modify_port_status(port, 17, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
508 ZFCP_CLEAR);
509}
510
511/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200512 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 *
514 * purpose: enable I/O
515 *
516 * returns:
517 */
518static void
519zfcp_erp_port_unblock(struct zfcp_port *port)
520{
Martin Peschke698ec0162008-03-27 14:22:02 +0100521 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
522 &port->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200523 zfcp_rec_dbf_event_port(18, NULL, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
526/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200527 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 *
529 * purpose: disable I/O,
530 * return any open requests and clean them up,
531 * aim: no pending and incoming I/O
532 *
533 * returns:
534 */
535static void
536zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
537{
Martin Peschke1f6f7122008-04-18 12:51:55 +0200538 zfcp_erp_modify_unit_status(unit, 19, NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
540 ZFCP_CLEAR);
541}
542
543/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200544 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 *
546 * purpose: enable I/O
547 *
548 * returns:
549 */
550static void
551zfcp_erp_unit_unblock(struct zfcp_unit *unit)
552{
Martin Peschke698ec0162008-03-27 14:22:02 +0100553 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
554 &unit->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +0200555 zfcp_rec_dbf_event_unit(20, NULL, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558static void
559zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
560{
561 struct zfcp_adapter *adapter = erp_action->adapter;
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 zfcp_erp_action_to_ready(erp_action);
564 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200565 zfcp_rec_dbf_event_thread(2, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200569 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 *
571 * purpose:
572 *
573 * returns: <0 erp_action not found in any list
574 * ZFCP_ERP_ACTION_READY erp_action is in ready list
575 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
576 *
577 * locks: erp_lock must be held
578 */
579static int
580zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
581{
582 int retval = -EINVAL;
583 struct list_head *entry;
584 struct zfcp_erp_action *entry_erp_action;
585 struct zfcp_adapter *adapter = erp_action->adapter;
586
587 /* search in running list */
588 list_for_each(entry, &adapter->erp_running_head) {
589 entry_erp_action =
590 list_entry(entry, struct zfcp_erp_action, list);
591 if (entry_erp_action == erp_action) {
592 retval = ZFCP_ERP_ACTION_RUNNING;
593 goto out;
594 }
595 }
596 /* search in ready list */
597 list_for_each(entry, &adapter->erp_ready_head) {
598 entry_erp_action =
599 list_entry(entry, struct zfcp_erp_action, list);
600 if (entry_erp_action == erp_action) {
601 retval = ZFCP_ERP_ACTION_READY;
602 goto out;
603 }
604 }
605
606 out:
607 return retval;
608}
609
610/*
611 * purpose: checks current status of action (timed out, dismissed, ...)
612 * and does appropriate preparations (dismiss fsf request, ...)
613 *
614 * locks: called under erp_lock (disabled interrupts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
Swen Schilligca880cf2007-02-09 10:00:14 +0100616static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
618{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 struct zfcp_adapter *adapter = erp_action->adapter;
620
621 if (erp_action->fsf_req) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200622 /* take lock to ensure that request is not deleted meanwhile */
623 spin_lock(&adapter->req_list_lock);
Heiko Carstensd1ad09d2007-12-20 12:30:22 +0100624 if (zfcp_reqlist_find_safe(adapter, erp_action->fsf_req) &&
625 erp_action->fsf_req->erp_action == erp_action) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 /* fsf_req still exists */
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200627 /* dismiss fsf_req of timed out/dismissed erp_action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
629 ZFCP_STATUS_ERP_TIMEDOUT)) {
Swen Schilligca880cf2007-02-09 10:00:14 +0100630 erp_action->fsf_req->status |=
631 ZFCP_STATUS_FSFREQ_DISMISSED;
Martin Peschke6f4f3652008-03-27 14:22:04 +0100632 zfcp_rec_dbf_event_action(142, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
634 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
Martin Peschke6f4f3652008-03-27 14:22:04 +0100635 zfcp_rec_dbf_event_action(143, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ZFCP_LOG_NORMAL("error: erp step timed out "
637 "(action=%d, fsf_req=%p)\n ",
638 erp_action->action,
639 erp_action->fsf_req);
640 }
641 /*
642 * If fsf_req is neither dismissed nor completed
643 * then keep it running asynchronously and don't mess
644 * with the association of erp_action and fsf_req.
645 */
Swen Schilligca880cf2007-02-09 10:00:14 +0100646 if (erp_action->fsf_req->status &
647 (ZFCP_STATUS_FSFREQ_COMPLETED |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 ZFCP_STATUS_FSFREQ_DISMISSED)) {
649 /* forget about association between fsf_req
650 and erp_action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 erp_action->fsf_req = NULL;
652 }
653 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 /*
655 * even if this fsf_req has gone, forget about
656 * association between erp_action and fsf_req
657 */
658 erp_action->fsf_req = NULL;
659 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200660 spin_unlock(&adapter->req_list_lock);
Martin Peschke507e4962008-03-27 14:22:05 +0100661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200664/**
665 * zfcp_erp_async_handler_nolock - complete erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200667 * Used for normal completion, time-out, dismissal and failure after
668 * low memory condition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200670static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
671 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 erp_action->status |= set_mask;
675 zfcp_erp_action_ready(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 } else {
677 /* action is ready or gone - nothing to do */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679}
680
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200681/**
682 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200684void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
685 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
687 struct zfcp_adapter *adapter = erp_action->adapter;
688 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 write_lock_irqsave(&adapter->erp_lock, flags);
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200691 zfcp_erp_async_handler_nolock(erp_action, set_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
694
695/*
696 * purpose: is called for erp_action which was slept waiting for
697 * memory becoming avaliable,
698 * will trigger that this action will be continued
699 */
700static void
701zfcp_erp_memwait_handler(unsigned long data)
702{
703 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705 zfcp_erp_async_handler(erp_action, 0);
706}
707
708/*
709 * purpose: is called if an asynchronous erp step timed out,
710 * action gets an appropriate flag and will be processed
711 * accordingly
712 */
Heiko Carstens364c8552007-10-12 16:11:35 +0200713static void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
715 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
718}
719
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200720/**
721 * zfcp_erp_action_dismiss - dismiss an erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200723 * adapter->erp_lock must be held
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200724 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200725 * Dismissal of an erp_action is usually required if an erp_action of
726 * higher priority is generated.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200728static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Martin Peschked0076f72007-11-15 13:57:08 +0100730 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
731 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
732 zfcp_erp_action_ready(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733}
734
735int
736zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
737{
738 int retval = 0;
739
740 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
743 if (retval < 0) {
744 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
745 "adapter %s\n",
746 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 } else {
748 wait_event(adapter->erp_thread_wqh,
749 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
750 &adapter->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752
753 return (retval < 0);
754}
755
756/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200757 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200759 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 *
761 * returns:
762 *
763 * context: process (i.e. proc-fs or rmmod/insmod)
764 *
765 * note: The caller of this routine ensures that the specified
766 * adapter has been shut down and that this operation
767 * has been completed. Thus, there are no pending erp_actions
768 * which would need to be handled here.
769 */
770int
771zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
772{
773 int retval = 0;
774
775 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
776 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200777 zfcp_rec_dbf_event_thread_lock(2, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 wait_event(adapter->erp_thread_wqh,
780 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
781 &adapter->status));
782
783 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
784 &adapter->status);
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 return retval;
787}
788
789/*
790 * purpose: is run as a kernel thread,
791 * goes through list of error recovery actions of associated adapter
792 * and delegates single action to execution
793 *
794 * returns: 0
795 */
796static int
797zfcp_erp_thread(void *data)
798{
799 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
800 struct list_head *next;
801 struct zfcp_erp_action *erp_action;
802 unsigned long flags;
803
804 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
805 /* Block all signals */
806 siginitsetinv(&current->blocked, 0);
807 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 wake_up(&adapter->erp_thread_wqh);
809
810 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
811 &adapter->status)) {
812
813 write_lock_irqsave(&adapter->erp_lock, flags);
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100814 next = adapter->erp_ready_head.next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 write_unlock_irqrestore(&adapter->erp_lock, flags);
816
817 if (next != &adapter->erp_ready_head) {
818 erp_action =
819 list_entry(next, struct zfcp_erp_action, list);
820 /*
821 * process action (incl. [re]moving it
822 * from 'ready' queue)
823 */
824 zfcp_erp_strategy(erp_action);
825 }
826
827 /*
828 * sleep as long as there is nothing to do, i.e.
829 * no action in 'ready' queue to be processed and
830 * thread is not to be killed
831 */
Christof Schmittaa0fec62008-05-19 12:17:47 +0200832 zfcp_rec_dbf_event_thread_lock(4, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 down_interruptible(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +0200834 zfcp_rec_dbf_event_thread_lock(5, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 wake_up(&adapter->erp_thread_wqh);
839
840 return 0;
841}
842
843/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200844 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 *
846 * purpose: drives single error recovery action and schedules higher and
847 * subordinate actions, if necessary
848 *
849 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
850 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
851 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
852 * ZFCP_ERP_EXIT - action finished (dequeued), offline
853 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
854 */
855static int
856zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
857{
858 int retval = 0;
859 struct zfcp_adapter *adapter = erp_action->adapter;
860 struct zfcp_port *port = erp_action->port;
861 struct zfcp_unit *unit = erp_action->unit;
862 int action = erp_action->action;
863 u32 status = erp_action->status;
864 unsigned long flags;
865
866 /* serialise dismissing, timing out, moving, enqueueing */
867 read_lock_irqsave(&zfcp_data.config_lock, flags);
868 write_lock(&adapter->erp_lock);
869
870 /* dequeue dismissed action and leave, if required */
871 retval = zfcp_erp_strategy_check_action(erp_action, retval);
872 if (retval == ZFCP_ERP_DISMISSED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 goto unlock;
874 }
875
876 /*
877 * move action to 'running' queue before processing it
878 * (to avoid a race condition regarding moving the
879 * action to the 'running' queue and back)
880 */
881 zfcp_erp_action_to_running(erp_action);
882
883 /*
884 * try to process action as far as possible,
885 * no lock to allow for blocking operations (kmalloc, qdio, ...),
886 * afterwards the lock is required again for the following reasons:
887 * - dequeueing of finished action and enqueueing of
888 * follow-up actions must be atomic so that any other
889 * reopen-routine does not believe there is nothing to do
890 * and that it is safe to enqueue something else,
891 * - we want to force any control thread which is dismissing
892 * actions to finish this before we decide about
893 * necessary steps to be taken here further
894 */
895 write_unlock(&adapter->erp_lock);
896 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
897 retval = zfcp_erp_strategy_do_action(erp_action);
898 read_lock_irqsave(&zfcp_data.config_lock, flags);
899 write_lock(&adapter->erp_lock);
900
901 /*
902 * check for dismissed status again to avoid follow-up actions,
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100903 * failing of targets and so on for dismissed actions,
904 * we go through down() here because there has been an up()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 */
Martin Peschke86e8dfc2007-11-15 13:57:17 +0100906 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
907 retval = ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 switch (retval) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 case ZFCP_ERP_NOMEM:
911 /* no memory to continue immediately, let it sleep */
912 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
913 ++adapter->erp_low_mem_count;
914 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
915 }
916 /* This condition is true if there is no memory available
917 for any erp_action on this adapter. This implies that there
918 are no elements in the memory pool(s) left for erp_actions.
919 This might happen if an erp_action that used a memory pool
920 element was timed out.
921 */
922 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 ZFCP_LOG_NORMAL("error: no mempool elements available, "
924 "restarting I/O on adapter %s "
925 "to free mempool\n",
926 zfcp_get_busid_by_adapter(adapter));
Martin Peschke1f6f7122008-04-18 12:51:55 +0200927 zfcp_erp_adapter_reopen_internal(adapter, 0, 66, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 retval = zfcp_erp_strategy_memwait(erp_action);
930 }
931 goto unlock;
932 case ZFCP_ERP_CONTINUES:
933 /* leave since this action runs asynchronously */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
935 --adapter->erp_low_mem_count;
936 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
937 }
938 goto unlock;
939 }
940 /* ok, finished action (whatever its result is) */
941
942 /* check for unrecoverable targets */
943 retval = zfcp_erp_strategy_check_target(erp_action, retval);
944
945 /* action must be dequeued (here to allow for further ones) */
946 zfcp_erp_action_dequeue(erp_action);
947
948 /*
949 * put this target through the erp mill again if someone has
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200950 * requested to change the status of a target being online
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 * to offline or the other way around
952 * (old retval is preserved if nothing has to be done here)
953 */
954 retval = zfcp_erp_strategy_statechange(action, status, adapter,
955 port, unit, retval);
956
957 /*
958 * leave if target is in permanent error state or if
959 * action is repeated in order to process state change
960 */
961 if (retval == ZFCP_ERP_EXIT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 goto unlock;
963 }
964
965 /* trigger follow up actions */
966 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
967
968 unlock:
969 write_unlock(&adapter->erp_lock);
970 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (retval != ZFCP_ERP_CONTINUES)
973 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
974
975 /*
976 * a few tasks remain when the erp queues are empty
977 * (don't do that if the last action evaluated was dismissed
978 * since this clearly indicates that there is more to come) :
979 * - close the name server port if it is open yet
980 * (enqueues another [probably] final action)
981 * - otherwise, wake up whoever wants to be woken when we are
982 * done with erp
983 */
984 if (retval != ZFCP_ERP_DISMISSED)
985 zfcp_erp_strategy_check_queues(adapter);
986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return retval;
988}
989
990/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200991 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +0200993 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 *
995 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
996 * retval - otherwise
997 */
998static int
999zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1000{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 zfcp_erp_strategy_check_fsfreq(erp_action);
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 zfcp_erp_action_dequeue(erp_action);
1005 retval = ZFCP_ERP_DISMISSED;
Martin Peschke507e4962008-03-27 14:22:05 +01001006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 return retval;
1009}
1010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011static int
1012zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1013{
1014 int retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /*
1017 * try to execute/continue action as far as possible,
1018 * note: no lock in subsequent strategy routines
1019 * (this allows these routine to call schedule, e.g.
1020 * kmalloc with such flags or qdio_initialize & friends)
Joe Perches5d67d162008-01-26 14:11:20 +01001021 * Note: in case of timeout, the separate strategies will fail
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 * anyhow. No need for a special action. Even worse, a nameserver
1023 * failure would not wake up waiting ports without the call.
1024 */
1025 switch (erp_action->action) {
1026
1027 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1028 retval = zfcp_erp_adapter_strategy(erp_action);
1029 break;
1030
1031 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1032 retval = zfcp_erp_port_forced_strategy(erp_action);
1033 break;
1034
1035 case ZFCP_ERP_ACTION_REOPEN_PORT:
1036 retval = zfcp_erp_port_strategy(erp_action);
1037 break;
1038
1039 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1040 retval = zfcp_erp_unit_strategy(erp_action);
1041 break;
1042
1043 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1045 "adapter %s (action=%d)\n",
1046 zfcp_get_busid_by_adapter(erp_action->adapter),
1047 erp_action->action);
1048 }
1049
1050 return retval;
1051}
1052
1053/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001054 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 *
1056 * purpose: triggers retry of this action after a certain amount of time
1057 * by means of timer provided by erp_action
1058 *
1059 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1060 */
1061static int
1062zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1063{
1064 int retval = ZFCP_ERP_CONTINUES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 init_timer(&erp_action->timer);
1067 erp_action->timer.function = zfcp_erp_memwait_handler;
1068 erp_action->timer.data = (unsigned long) erp_action;
1069 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1070 add_timer(&erp_action->timer);
1071
1072 return retval;
1073}
1074
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001075/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 * function: zfcp_erp_adapter_failed
1077 *
1078 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1079 *
1080 */
1081void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001082zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Martin Peschke698ec0162008-03-27 14:22:02 +01001084 zfcp_erp_modify_adapter_status(adapter, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1086 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1087 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088}
1089
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001090/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 * function: zfcp_erp_port_failed
1092 *
1093 * purpose: sets the port and all underlying devices to ERP_FAILED
1094 *
1095 */
1096void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001097zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098{
Martin Peschke698ec0162008-03-27 14:22:02 +01001099 zfcp_erp_modify_port_status(port, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1101
1102 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1103 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
Christof Schmitt1d589ed2007-05-08 11:14:41 +02001104 "port d_id=0x%06x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 zfcp_get_busid_by_port(port), port->d_id);
1106 else
1107 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1108 zfcp_get_busid_by_port(port), port->wwpn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109}
1110
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001111/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 * function: zfcp_erp_unit_failed
1113 *
1114 * purpose: sets the unit to ERP_FAILED
1115 *
1116 */
1117void
Martin Peschke1f6f7122008-04-18 12:51:55 +02001118zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
Martin Peschke698ec0162008-03-27 14:22:02 +01001120 zfcp_erp_modify_unit_status(unit, id, ref,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1122
1123 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1124 " on adapter %s\n", unit->fcp_lun,
1125 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
1128/*
1129 * function: zfcp_erp_strategy_check_target
1130 *
1131 * purpose: increments the erp action count on the device currently in
1132 * recovery if the action failed or resets the count in case of
1133 * success. If a maximum count is exceeded the device is marked
1134 * as ERP_FAILED.
1135 * The 'blocked' state of a target which has been recovered
1136 * successfully is reset.
1137 *
1138 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001139 * ZFCP_ERP_SUCCEEDED - action finished successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 * ZFCP_ERP_EXIT - action failed and will not continue
1141 */
1142static int
1143zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1144{
1145 struct zfcp_adapter *adapter = erp_action->adapter;
1146 struct zfcp_port *port = erp_action->port;
1147 struct zfcp_unit *unit = erp_action->unit;
1148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 switch (erp_action->action) {
1150
1151 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1152 result = zfcp_erp_strategy_check_unit(unit, result);
1153 break;
1154
1155 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1156 case ZFCP_ERP_ACTION_REOPEN_PORT:
1157 result = zfcp_erp_strategy_check_port(port, result);
1158 break;
1159
1160 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1161 result = zfcp_erp_strategy_check_adapter(adapter, result);
1162 break;
1163 }
1164
1165 return result;
1166}
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168static int
1169zfcp_erp_strategy_statechange(int action,
1170 u32 status,
1171 struct zfcp_adapter *adapter,
1172 struct zfcp_port *port,
1173 struct zfcp_unit *unit, int retval)
1174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 switch (action) {
1176
1177 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1178 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1179 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001180 zfcp_erp_adapter_reopen_internal(adapter,
1181 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001182 67, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 retval = ZFCP_ERP_EXIT;
1184 }
1185 break;
1186
1187 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1188 case ZFCP_ERP_ACTION_REOPEN_PORT:
1189 if (zfcp_erp_strategy_statechange_detected(&port->status,
1190 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001191 zfcp_erp_port_reopen_internal(port,
1192 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001193 68, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 retval = ZFCP_ERP_EXIT;
1195 }
1196 break;
1197
1198 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1199 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1200 status)) {
Martin Peschke9467a9b2008-03-27 14:22:03 +01001201 zfcp_erp_unit_reopen_internal(unit,
1202 ZFCP_STATUS_COMMON_ERP_FAILED,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001203 69, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 retval = ZFCP_ERP_EXIT;
1205 }
1206 break;
1207 }
1208
1209 return retval;
1210}
1211
Heiko Carstens364c8552007-10-12 16:11:35 +02001212static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1214{
1215 return
1216 /* take it online */
1217 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1218 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1219 /* take it offline */
1220 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1221 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1222}
1223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224static int
1225zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1226{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 switch (result) {
1228 case ZFCP_ERP_SUCCEEDED :
1229 atomic_set(&unit->erp_counter, 0);
1230 zfcp_erp_unit_unblock(unit);
1231 break;
1232 case ZFCP_ERP_FAILED :
1233 atomic_inc(&unit->erp_counter);
1234 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001235 zfcp_erp_unit_failed(unit, 21, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 break;
1237 case ZFCP_ERP_EXIT :
1238 /* nothing */
1239 break;
1240 }
1241
1242 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1243 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1244 result = ZFCP_ERP_EXIT;
1245 }
1246
1247 return result;
1248}
1249
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250static int
1251zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1252{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 switch (result) {
1254 case ZFCP_ERP_SUCCEEDED :
1255 atomic_set(&port->erp_counter, 0);
1256 zfcp_erp_port_unblock(port);
1257 break;
1258 case ZFCP_ERP_FAILED :
1259 atomic_inc(&port->erp_counter);
1260 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001261 zfcp_erp_port_failed(port, 22, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 break;
1263 case ZFCP_ERP_EXIT :
1264 /* nothing */
1265 break;
1266 }
1267
1268 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1269 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1270 result = ZFCP_ERP_EXIT;
1271 }
1272
1273 return result;
1274}
1275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276static int
1277zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1278{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 switch (result) {
1280 case ZFCP_ERP_SUCCEEDED :
1281 atomic_set(&adapter->erp_counter, 0);
1282 zfcp_erp_adapter_unblock(adapter);
1283 break;
1284 case ZFCP_ERP_FAILED :
1285 atomic_inc(&adapter->erp_counter);
1286 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001287 zfcp_erp_adapter_failed(adapter, 23, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 break;
1289 case ZFCP_ERP_EXIT :
1290 /* nothing */
1291 break;
1292 }
1293
1294 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1295 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1296 result = ZFCP_ERP_EXIT;
1297 }
1298
1299 return result;
1300}
1301
Christof Schmitt5f852be2007-05-08 11:16:52 +02001302struct zfcp_erp_add_work {
1303 struct zfcp_unit *unit;
1304 struct work_struct work;
1305};
1306
1307/**
1308 * zfcp_erp_scsi_scan
1309 * @data: pointer to a struct zfcp_erp_add_work
1310 *
1311 * Registers a logical unit with the SCSI stack.
1312 */
1313static void zfcp_erp_scsi_scan(struct work_struct *work)
1314{
1315 struct zfcp_erp_add_work *p =
1316 container_of(work, struct zfcp_erp_add_work, work);
1317 struct zfcp_unit *unit = p->unit;
1318 struct fc_rport *rport = unit->port->rport;
1319 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1320 unit->scsi_lun, 0);
1321 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001322 zfcp_unit_put(unit);
1323 kfree(p);
1324}
1325
1326/**
1327 * zfcp_erp_schedule_work
1328 * @unit: pointer to unit which should be registered with SCSI stack
1329 *
1330 * Schedules work which registers a unit with the SCSI stack
1331 */
1332static void
1333zfcp_erp_schedule_work(struct zfcp_unit *unit)
1334{
1335 struct zfcp_erp_add_work *p;
1336
Swen Schillig0d661322007-07-18 10:55:08 +02001337 p = kzalloc(sizeof(*p), GFP_KERNEL);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001338 if (!p) {
1339 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1340 "the FCP-LUN 0x%Lx connected to "
1341 "the port with WWPN 0x%Lx connected to "
1342 "the adapter %s with the SCSI stack.\n",
1343 unit->fcp_lun,
1344 unit->port->wwpn,
1345 zfcp_get_busid_by_unit(unit));
1346 return;
1347 }
1348
1349 zfcp_unit_get(unit);
Christof Schmitt5f852be2007-05-08 11:16:52 +02001350 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1351 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1352 p->unit = unit;
1353 schedule_work(&p->work);
1354}
1355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001357 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 *
1359 * purpose: remaining things in good cases,
1360 * escalation in bad cases
1361 *
1362 * returns:
1363 */
1364static int
1365zfcp_erp_strategy_followup_actions(int action,
1366 struct zfcp_adapter *adapter,
1367 struct zfcp_port *port,
1368 struct zfcp_unit *unit, int status)
1369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 /* initiate follow-up actions depending on success of finished action */
1371 switch (action) {
1372
1373 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1374 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001375 zfcp_erp_port_reopen_all_internal(adapter, 0, 70, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001377 zfcp_erp_adapter_reopen_internal(adapter, 0, 71, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 break;
1379
1380 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1381 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001382 zfcp_erp_port_reopen_internal(port, 0, 72, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001384 zfcp_erp_adapter_reopen_internal(adapter, 0, 73, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 break;
1386
1387 case ZFCP_ERP_ACTION_REOPEN_PORT:
1388 if (status == ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001389 zfcp_erp_unit_reopen_all_internal(port, 0, 74, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 else
Martin Peschke1f6f7122008-04-18 12:51:55 +02001391 zfcp_erp_port_forced_reopen_internal(port, 0, 75, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 break;
1393
1394 case ZFCP_ERP_ACTION_REOPEN_UNIT:
Heiko Carstenscc16ceb2007-08-28 09:30:42 +02001395 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1396 if (status != ZFCP_ERP_SUCCEEDED)
Martin Peschke1f6f7122008-04-18 12:51:55 +02001397 zfcp_erp_port_reopen_internal(unit->port, 0, 76, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 break;
1399 }
1400
1401 return 0;
1402}
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404static int
1405zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1406{
1407 unsigned long flags;
1408
1409 read_lock_irqsave(&zfcp_data.config_lock, flags);
1410 read_lock(&adapter->erp_lock);
1411 if (list_empty(&adapter->erp_ready_head) &&
1412 list_empty(&adapter->erp_running_head)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1414 &adapter->status);
1415 wake_up(&adapter->erp_done_wqh);
Martin Peschke507e4962008-03-27 14:22:05 +01001416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 read_unlock(&adapter->erp_lock);
1418 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1419
1420 return 0;
1421}
1422
1423/**
1424 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1425 * @adapter: adapter for which to wait for completion of its error recovery
1426 * Return: 0
1427 */
1428int
1429zfcp_erp_wait(struct zfcp_adapter *adapter)
1430{
1431 int retval = 0;
1432
1433 wait_event(adapter->erp_done_wqh,
1434 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1435 &adapter->status));
1436
1437 return retval;
1438}
1439
Martin Peschke698ec0162008-03-27 14:22:02 +01001440void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001441 void *ref, u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
1443 struct zfcp_port *port;
Martin Peschke698ec0162008-03-27 14:22:02 +01001444 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001447 changed = atomic_test_and_set_mask(mask, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001449 changed = atomic_test_and_clear_mask(mask, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1451 atomic_set(&adapter->erp_counter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001453 if (changed)
1454 zfcp_rec_dbf_event_adapter(id, ref, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
1456 /* Deal with all underlying devices, only pass common_mask */
1457 if (common_mask)
1458 list_for_each_entry(port, &adapter->port_list_head, list)
Martin Peschke698ec0162008-03-27 14:22:02 +01001459 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1460 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461}
1462
1463/*
1464 * function: zfcp_erp_modify_port_status
1465 *
1466 * purpose: sets the port and all underlying devices to ERP_FAILED
1467 *
1468 */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001469void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +01001470 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471{
1472 struct zfcp_unit *unit;
Martin Peschke698ec0162008-03-27 14:22:02 +01001473 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001476 changed = atomic_test_and_set_mask(mask, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001478 changed = atomic_test_and_clear_mask(mask, &port->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1480 atomic_set(&port->erp_counter, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001482 if (changed)
1483 zfcp_rec_dbf_event_port(id, ref, port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 /* Modify status of all underlying devices, only pass common mask */
1486 if (common_mask)
1487 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke698ec0162008-03-27 14:22:02 +01001488 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1489 set_or_clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490}
1491
1492/*
1493 * function: zfcp_erp_modify_unit_status
1494 *
1495 * purpose: sets the unit to ERP_FAILED
1496 *
1497 */
Martin Peschke1f6f7122008-04-18 12:51:55 +02001498void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref,
Martin Peschke698ec0162008-03-27 14:22:02 +01001499 u32 mask, int set_or_clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500{
Martin Peschke698ec0162008-03-27 14:22:02 +01001501 u32 changed;
1502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 if (set_or_clear == ZFCP_SET) {
Martin Peschke698ec0162008-03-27 14:22:02 +01001504 changed = atomic_test_and_set_mask(mask, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 } else {
Martin Peschke698ec0162008-03-27 14:22:02 +01001506 changed = atomic_test_and_clear_mask(mask, &unit->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1508 atomic_set(&unit->erp_counter, 0);
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
Martin Peschke698ec0162008-03-27 14:22:02 +01001511 if (changed)
1512 zfcp_rec_dbf_event_unit(id, ref, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
1515/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001516 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 *
1518 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1519 * used to ensure the correct locking
1520 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001521 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 * <0 - failed to initiate action
1523 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001524int zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001525 u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
1527 int retval;
1528 unsigned long flags;
1529
1530 read_lock_irqsave(&zfcp_data.config_lock, flags);
1531 write_lock(&adapter->erp_lock);
Martin Peschke9467a9b2008-03-27 14:22:03 +01001532 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask, id,
1533 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 write_unlock(&adapter->erp_lock);
1535 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1536
1537 return retval;
1538}
1539
Martin Peschke9467a9b2008-03-27 14:22:03 +01001540static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001541 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
1543 int retval = 0;
1544 struct zfcp_port *port;
1545
1546 list_for_each_entry(port, &adapter->port_list_head, list)
1547 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
Martin Peschke9467a9b2008-03-27 14:22:03 +01001548 zfcp_erp_port_reopen_internal(port, clear_mask, id,
1549 ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 return retval;
1552}
1553
1554/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001555 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001557 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 *
1559 * returns: FIXME
1560 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01001561static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +02001562 int clear_mask, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
1564 int retval = 0;
1565 struct zfcp_unit *unit;
1566
1567 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke9467a9b2008-03-27 14:22:03 +01001568 zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 return retval;
1571}
1572
1573/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001574 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 *
1576 * purpose: this routine executes the 'Reopen Adapter' action
1577 * (the entire action is processed synchronously, since
1578 * there are no actions which might be run concurrently
1579 * per definition)
1580 *
1581 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1582 * ZFCP_ERP_FAILED - action finished unsuccessfully
1583 */
1584static int
1585zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1586{
1587 int retval;
1588 struct zfcp_adapter *adapter = erp_action->adapter;
1589
1590 retval = zfcp_erp_adapter_strategy_close(erp_action);
1591 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1592 retval = ZFCP_ERP_EXIT;
1593 else
1594 retval = zfcp_erp_adapter_strategy_open(erp_action);
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 if (retval == ZFCP_ERP_FAILED) {
1597 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1598 "to recover itself\n",
1599 zfcp_get_busid_by_adapter(adapter));
Christof Schmitt18edcdb2007-11-05 12:37:45 +01001600 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 }
1602
1603 return retval;
1604}
1605
1606/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001607 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001609 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 *
1611 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1612 * ZFCP_ERP_FAILED - action finished unsuccessfully
1613 */
1614static int
1615zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1616{
1617 int retval;
1618
1619 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1620 &erp_action->adapter->status);
1621 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1622 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1623 &erp_action->adapter->status);
1624
1625 return retval;
1626}
1627
1628/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001629 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001631 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 *
1633 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1634 * ZFCP_ERP_FAILED - action finished unsuccessfully
1635 */
1636static int
1637zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1638{
1639 int retval;
1640
1641 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1642 &erp_action->adapter->status);
1643 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1644 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1645 &erp_action->adapter->status);
1646
1647 return retval;
1648}
1649
1650/*
1651 * function: zfcp_register_adapter
1652 *
1653 * purpose: allocate the irq associated with this devno and register
1654 * the FSF adapter with the SCSI stack
1655 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001656 * returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 */
1658static int
1659zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1660{
1661 int retval = ZFCP_ERP_SUCCEEDED;
1662
1663 if (close)
1664 goto close_only;
1665
1666 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1667 if (retval != ZFCP_ERP_SUCCEEDED)
1668 goto failed_qdio;
1669
1670 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1671 if (retval != ZFCP_ERP_SUCCEEDED)
1672 goto failed_openfcp;
1673
1674 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1675 goto out;
1676
1677 close_only:
1678 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1679 &erp_action->adapter->status);
1680
1681 failed_openfcp:
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001682 zfcp_close_fsf(erp_action->adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 failed_qdio:
Volker Sameskec7f6b3a2007-05-29 15:29:49 +02001684 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
1685 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
1686 ZFCP_STATUS_ADAPTER_XPORT_OK,
1687 &erp_action->adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 out:
1689 return retval;
1690}
1691
1692/*
1693 * function: zfcp_qdio_init
1694 *
1695 * purpose: setup QDIO operation for specified adapter
1696 *
1697 * returns: 0 - successful setup
1698 * !0 - failed setup
1699 */
Heiko Carstens364c8552007-10-12 16:11:35 +02001700static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1702{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 struct zfcp_adapter *adapter = erp_action->adapter;
1704
Swen Schillig00bab912008-06-10 18:20:57 +02001705 if (zfcp_qdio_open(adapter))
1706 return ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
1708 /* initialize waitqueue used to wait for free SBALs in requests queue */
1709 init_waitqueue_head(&adapter->request_wq);
1710
1711 /* ok, we did it - skip all cleanups for different failures */
1712 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
Swen Schillig00bab912008-06-10 18:20:57 +02001713 return ZFCP_ERP_SUCCEEDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717static int
1718zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
1719{
Andreas Herrmann2448c452005-12-01 02:50:36 +01001720 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Andreas Herrmann2448c452005-12-01 02:50:36 +01001722 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
1723 if (retval == ZFCP_ERP_FAILED)
1724 return ZFCP_ERP_FAILED;
1725
1726 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
1727 if (retval == ZFCP_ERP_FAILED)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001728 return ZFCP_ERP_FAILED;
1729
1730 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731}
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733static int
1734zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
1735{
1736 int retval = ZFCP_ERP_SUCCEEDED;
1737 int retries;
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001738 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 struct zfcp_adapter *adapter = erp_action->adapter;
1740
1741 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001743 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1745 &adapter->status);
1746 ZFCP_LOG_DEBUG("Doing exchange config data\n");
Heiko Carstens9f09c542006-07-03 17:32:20 -07001747 write_lock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07001749 write_unlock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 if (zfcp_fsf_exchange_config_data(erp_action)) {
1751 retval = ZFCP_ERP_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 ZFCP_LOG_INFO("error: initiation of exchange of "
1753 "configuration data failed for "
1754 "adapter %s\n",
1755 zfcp_get_busid_by_adapter(adapter));
1756 break;
1757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 ZFCP_LOG_DEBUG("Xchange underway\n");
1759
1760 /*
1761 * Why this works:
1762 * Both the normal completion handler as well as the timeout
1763 * handler will do an 'up' when the 'exchange config data'
1764 * request completes or times out. Thus, the signal to go on
1765 * won't be lost utilizing this semaphore.
1766 * Furthermore, this 'adapter_reopen' action is
1767 * guaranteed to be the only action being there (highest action
1768 * which prevents other actions from being created).
1769 * Resulting from that, the wake signal recognized here
1770 * _must_ be the one belonging to the 'exchange config
1771 * data' request.
1772 */
Christof Schmittaa0fec62008-05-19 12:17:47 +02001773 zfcp_rec_dbf_event_thread_lock(6, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 down(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02001775 zfcp_rec_dbf_event_thread_lock(7, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1777 ZFCP_LOG_INFO("error: exchange of configuration data "
1778 "for adapter %s timed out\n",
1779 zfcp_get_busid_by_adapter(adapter));
1780 break;
1781 }
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001782
1783 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1784 &adapter->status))
1785 break;
1786
1787 ZFCP_LOG_DEBUG("host connection still initialising... "
1788 "waiting and retrying...\n");
1789 /* sleep a little bit before retry */
Christof Schmitt18edcdb2007-11-05 12:37:45 +01001790 ssleep(sleep);
Andreas Herrmann22753fa2005-06-13 13:15:15 +02001791 sleep *= 2;
1792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Volker Sameskec7f6b3a2007-05-29 15:29:49 +02001794 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
1795 &adapter->status);
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
1798 &adapter->status)) {
1799 ZFCP_LOG_INFO("error: exchange of configuration data for "
1800 "adapter %s failed\n",
1801 zfcp_get_busid_by_adapter(adapter));
1802 retval = ZFCP_ERP_FAILED;
1803 }
1804
1805 return retval;
1806}
1807
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001808static int
1809zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
1810{
Andreas Herrmann2448c452005-12-01 02:50:36 +01001811 int ret;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001812 struct zfcp_adapter *adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001813
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001814 adapter = erp_action->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001815 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
1816
Heiko Carstens9f09c542006-07-03 17:32:20 -07001817 write_lock_irq(&adapter->erp_lock);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001818 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07001819 write_unlock_irq(&adapter->erp_lock);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001820
Swen Schillig52ef11a2007-08-28 09:31:09 +02001821 ret = zfcp_fsf_exchange_port_data(erp_action);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001822 if (ret == -EOPNOTSUPP) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001823 return ZFCP_ERP_SUCCEEDED;
1824 } else if (ret) {
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001825 return ZFCP_ERP_FAILED;
1826 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001827
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001828 ret = ZFCP_ERP_SUCCEEDED;
Christof Schmittaa0fec62008-05-19 12:17:47 +02001829 zfcp_rec_dbf_event_thread_lock(8, adapter);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001830 down(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02001831 zfcp_rec_dbf_event_thread_lock(9, adapter);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001832 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
1833 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
1834 "%s)\n", zfcp_get_busid_by_adapter(adapter));
1835 ret = ZFCP_ERP_FAILED;
1836 }
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02001837
1838 /* don't treat as error for the sake of compatibility */
1839 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
1840 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001841 "%s\n", zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001842
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01001843 return ret;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02001844}
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846static int
1847zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
1848 *erp_action)
1849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 struct zfcp_adapter *adapter = erp_action->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Swen Schilligd26ab062008-05-19 12:17:37 +02001852 atomic_set(&adapter->stat_miss, 16);
1853 return zfcp_status_read_refill(adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854}
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001857 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 *
1859 * purpose: this routine executes the 'Reopen Physical Port' action
1860 *
1861 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1862 * ZFCP_ERP_SUCCEEDED - action finished successfully
1863 * ZFCP_ERP_FAILED - action finished unsuccessfully
1864 */
1865static int
1866zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
1867{
1868 int retval = ZFCP_ERP_FAILED;
1869 struct zfcp_port *port = erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 switch (erp_action->step) {
1872
1873 /*
1874 * FIXME:
1875 * the ULP spec. begs for waiting for oustanding commands
1876 */
1877 case ZFCP_ERP_STEP_UNINITIALIZED:
1878 zfcp_erp_port_strategy_clearstati(port);
1879 /*
1880 * it would be sufficient to test only the normal open flag
1881 * since the phys. open flag cannot be set if the normal
1882 * open flag is unset - however, this is for readabilty ...
1883 */
1884 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
1885 ZFCP_STATUS_COMMON_OPEN),
1886 &port->status)) {
1887 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
1888 "close physical\n", port->wwpn);
1889 retval =
1890 zfcp_erp_port_forced_strategy_close(erp_action);
1891 } else
1892 retval = ZFCP_ERP_FAILED;
1893 break;
1894
1895 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
1896 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
1897 &port->status)) {
1898 ZFCP_LOG_DEBUG("close physical failed for port "
1899 "0x%016Lx\n", port->wwpn);
1900 retval = ZFCP_ERP_FAILED;
1901 } else
1902 retval = ZFCP_ERP_SUCCEEDED;
1903 break;
1904 }
1905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 return retval;
1907}
1908
1909/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02001910 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 *
1912 * purpose: this routine executes the 'Reopen Port' action
1913 *
1914 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1915 * ZFCP_ERP_SUCCEEDED - action finished successfully
1916 * ZFCP_ERP_FAILED - action finished unsuccessfully
1917 */
1918static int
1919zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
1920{
1921 int retval = ZFCP_ERP_FAILED;
1922 struct zfcp_port *port = erp_action->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
1924 switch (erp_action->step) {
1925
1926 /*
1927 * FIXME:
1928 * the ULP spec. begs for waiting for oustanding commands
1929 */
1930 case ZFCP_ERP_STEP_UNINITIALIZED:
1931 zfcp_erp_port_strategy_clearstati(port);
1932 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
1933 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
1934 "close\n", port->wwpn);
1935 retval = zfcp_erp_port_strategy_close(erp_action);
1936 goto out;
1937 } /* else it's already closed, open it */
1938 break;
1939
1940 case ZFCP_ERP_STEP_PORT_CLOSING:
1941 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
1942 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
1943 port->wwpn);
1944 retval = ZFCP_ERP_FAILED;
1945 goto out;
1946 } /* else it's closed now, open it */
1947 break;
1948 }
1949 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1950 retval = ZFCP_ERP_EXIT;
1951 else
1952 retval = zfcp_erp_port_strategy_open(erp_action);
1953
1954 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 return retval;
1956}
1957
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958static int
1959zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
1960{
1961 int retval;
1962
1963 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
1964 &erp_action->port->status))
1965 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
1966 else
1967 retval = zfcp_erp_port_strategy_open_common(erp_action);
1968
1969 return retval;
1970}
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972static int
1973zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
1974{
1975 int retval = 0;
1976 struct zfcp_adapter *adapter = erp_action->adapter;
1977 struct zfcp_port *port = erp_action->port;
1978
1979 switch (erp_action->step) {
1980
1981 case ZFCP_ERP_STEP_UNINITIALIZED:
1982 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
1983 case ZFCP_ERP_STEP_PORT_CLOSING:
Andreas Herrmannad757cd2006-01-13 02:26:11 +01001984 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
6f71d9b2005-04-10 23:04:28 -05001985 if (port->wwpn != adapter->peer_wwpn) {
1986 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
1987 "on adapter %s.\nPeer WWPN "
1988 "0x%016Lx does not match\n",
1989 port->wwpn,
1990 zfcp_get_busid_by_adapter(adapter),
1991 adapter->peer_wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02001992 zfcp_erp_port_failed(port, 25, NULL);
6f71d9b2005-04-10 23:04:28 -05001993 retval = ZFCP_ERP_FAILED;
1994 break;
1995 }
1996 port->d_id = adapter->peer_d_id;
1997 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1998 retval = zfcp_erp_port_strategy_open_port(erp_action);
1999 break;
2000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 if (!(adapter->nameserver_port)) {
2002 retval = zfcp_nameserver_enqueue(adapter);
2003 if (retval != 0) {
2004 ZFCP_LOG_NORMAL("error: nameserver port "
2005 "unavailable for adapter %s\n",
2006 zfcp_get_busid_by_adapter(adapter));
2007 retval = ZFCP_ERP_FAILED;
2008 break;
2009 }
2010 }
2011 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2012 &adapter->nameserver_port->status)) {
2013 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2014 "nameserver port\n");
2015 /* nameserver port may live again */
2016 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2017 &adapter->nameserver_port->status);
Martin Peschke9467a9b2008-03-27 14:22:03 +01002018 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0,
Martin Peschke1f6f7122008-04-18 12:51:55 +02002019 77, erp_action) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 erp_action->step =
2021 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2022 retval = ZFCP_ERP_CONTINUES;
2023 } else
2024 retval = ZFCP_ERP_FAILED;
2025 break;
2026 }
2027 /* else nameserver port is already open, fall through */
2028 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2029 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2030 &adapter->nameserver_port->status)) {
2031 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2032 retval = ZFCP_ERP_FAILED;
2033 } else {
2034 ZFCP_LOG_DEBUG("nameserver port is open -> "
2035 "nameserver look-up for port 0x%016Lx\n",
2036 port->wwpn);
2037 retval = zfcp_erp_port_strategy_open_common_lookup
2038 (erp_action);
2039 }
2040 break;
2041
2042 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2043 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2044 if (atomic_test_mask
2045 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2046 ZFCP_LOG_DEBUG("nameserver look-up failed "
2047 "for port 0x%016Lx "
2048 "(misconfigured WWPN?)\n",
2049 port->wwpn);
Martin Peschke1f6f7122008-04-18 12:51:55 +02002050 zfcp_erp_port_failed(port, 26, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 retval = ZFCP_ERP_EXIT;
2052 } else {
2053 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2054 "port 0x%016Lx\n", port->wwpn);
2055 retval = ZFCP_ERP_FAILED;
2056 }
2057 } else {
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002058 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 "trying open\n", port->wwpn, port->d_id);
2060 retval = zfcp_erp_port_strategy_open_port(erp_action);
2061 }
2062 break;
2063
2064 case ZFCP_ERP_STEP_PORT_OPENING:
2065 /* D_ID might have changed during open */
2066 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2067 ZFCP_STATUS_PORT_DID_DID),
2068 &port->status)) {
2069 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2070 retval = ZFCP_ERP_SUCCEEDED;
2071 } else {
2072 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2073 port->wwpn);
2074 retval = ZFCP_ERP_FAILED;
2075 }
2076 break;
2077
2078 default:
2079 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2080 erp_action->step);
2081 retval = ZFCP_ERP_FAILED;
2082 }
2083
2084 return retval;
2085}
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087static int
2088zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2089{
2090 int retval;
2091 struct zfcp_port *port = erp_action->port;
2092
2093 switch (erp_action->step) {
2094
2095 case ZFCP_ERP_STEP_UNINITIALIZED:
2096 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2097 case ZFCP_ERP_STEP_PORT_CLOSING:
Christof Schmitt1d589ed2007-05-08 11:14:41 +02002098 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 port->wwpn, port->d_id);
2100 retval = zfcp_erp_port_strategy_open_port(erp_action);
2101 break;
2102
2103 case ZFCP_ERP_STEP_PORT_OPENING:
2104 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2105 ZFCP_LOG_DEBUG("WKA port is open\n");
2106 retval = ZFCP_ERP_SUCCEEDED;
2107 } else {
2108 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2109 retval = ZFCP_ERP_FAILED;
2110 }
2111 /* this is needed anyway (dont care for retval of wakeup) */
2112 ZFCP_LOG_DEBUG("continue other open port operations\n");
2113 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2114 break;
2115
2116 default:
2117 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2118 erp_action->step);
2119 retval = ZFCP_ERP_FAILED;
2120 }
2121
2122 return retval;
2123}
2124
2125/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002126 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 *
2128 * purpose: makes the erp thread continue with reopen (physical) port
2129 * actions which have been paused until the name server port
2130 * is opened (or failed)
2131 *
2132 * returns: 0 (a kind of void retval, its not used)
2133 */
2134static int
2135zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2136 *ns_erp_action)
2137{
2138 int retval = 0;
2139 unsigned long flags;
2140 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2141 struct zfcp_erp_action *erp_action, *tmp;
2142
2143 read_lock_irqsave(&adapter->erp_lock, flags);
2144 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2145 list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 if (atomic_test_mask(
2148 ZFCP_STATUS_COMMON_ERP_FAILED,
2149 &adapter->nameserver_port->status))
Martin Peschke1f6f7122008-04-18 12:51:55 +02002150 zfcp_erp_port_failed(erp_action->port, 27,
2151 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 zfcp_erp_action_ready(erp_action);
2153 }
2154 }
2155 read_unlock_irqrestore(&adapter->erp_lock, flags);
2156
2157 return retval;
2158}
2159
2160/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002161 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002163 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 *
2165 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2166 * ZFCP_ERP_FAILED - action finished unsuccessfully
2167 */
2168static int
2169zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2170{
2171 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 retval = zfcp_fsf_close_physical_port(erp_action);
2174 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 retval = ZFCP_ERP_NOMEM;
2176 goto out;
2177 }
2178 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2179 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 /* could not send 'open', fail */
2181 retval = ZFCP_ERP_FAILED;
2182 goto out;
2183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 retval = ZFCP_ERP_CONTINUES;
2185 out:
2186 return retval;
2187}
2188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189static int
2190zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2191{
2192 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
2194 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2195 ZFCP_STATUS_COMMON_CLOSING |
2196 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2197 ZFCP_STATUS_PORT_DID_DID |
2198 ZFCP_STATUS_PORT_PHYS_CLOSING |
2199 ZFCP_STATUS_PORT_INVALID_WWPN,
2200 &port->status);
2201 return retval;
2202}
2203
2204/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002205 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002207 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 *
2209 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2210 * ZFCP_ERP_FAILED - action finished unsuccessfully
2211 */
2212static int
2213zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2214{
2215 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 retval = zfcp_fsf_close_port(erp_action);
2218 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 retval = ZFCP_ERP_NOMEM;
2220 goto out;
2221 }
2222 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2223 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 /* could not send 'close', fail */
2225 retval = ZFCP_ERP_FAILED;
2226 goto out;
2227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 retval = ZFCP_ERP_CONTINUES;
2229 out:
2230 return retval;
2231}
2232
2233/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002234 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002236 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 *
2238 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2239 * ZFCP_ERP_FAILED - action finished unsuccessfully
2240 */
2241static int
2242zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2243{
2244 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 retval = zfcp_fsf_open_port(erp_action);
2247 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 retval = ZFCP_ERP_NOMEM;
2249 goto out;
2250 }
2251 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2252 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /* could not send 'open', fail */
2254 retval = ZFCP_ERP_FAILED;
2255 goto out;
2256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 retval = ZFCP_ERP_CONTINUES;
2258 out:
2259 return retval;
2260}
2261
2262/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002263 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002265 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 *
2267 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2268 * ZFCP_ERP_FAILED - action finished unsuccessfully
2269 */
2270static int
2271zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2272{
2273 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Christof Schmitt24073b42008-06-10 18:20:54 +02002275 retval = zfcp_fc_ns_gid_pn_request(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 retval = ZFCP_ERP_NOMEM;
2278 goto out;
2279 }
2280 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2281 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 /* could not send nameserver request, fail */
2283 retval = ZFCP_ERP_FAILED;
2284 goto out;
2285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 retval = ZFCP_ERP_CONTINUES;
2287 out:
2288 return retval;
2289}
2290
2291/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002292 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 *
2294 * purpose: this routine executes the 'Reopen Unit' action
2295 * currently no retries
2296 *
2297 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2298 * ZFCP_ERP_SUCCEEDED - action finished successfully
2299 * ZFCP_ERP_FAILED - action finished unsuccessfully
2300 */
2301static int
2302zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2303{
2304 int retval = ZFCP_ERP_FAILED;
2305 struct zfcp_unit *unit = erp_action->unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
2307 switch (erp_action->step) {
2308
2309 /*
2310 * FIXME:
2311 * the ULP spec. begs for waiting for oustanding commands
2312 */
2313 case ZFCP_ERP_STEP_UNINITIALIZED:
2314 zfcp_erp_unit_strategy_clearstati(unit);
2315 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2316 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2317 "trying close\n", unit->fcp_lun);
2318 retval = zfcp_erp_unit_strategy_close(erp_action);
2319 break;
2320 }
2321 /* else it's already closed, fall through */
2322 case ZFCP_ERP_STEP_UNIT_CLOSING:
2323 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2324 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2325 unit->fcp_lun);
2326 retval = ZFCP_ERP_FAILED;
2327 } else {
2328 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2329 retval = ZFCP_ERP_EXIT;
2330 else {
2331 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2332 "trying open\n", unit->fcp_lun);
2333 retval =
2334 zfcp_erp_unit_strategy_open(erp_action);
2335 }
2336 }
2337 break;
2338
2339 case ZFCP_ERP_STEP_UNIT_OPENING:
2340 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2341 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2342 unit->fcp_lun);
2343 retval = ZFCP_ERP_SUCCEEDED;
2344 } else {
2345 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2346 unit->fcp_lun);
2347 retval = ZFCP_ERP_FAILED;
2348 }
2349 break;
2350 }
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 return retval;
2353}
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355static int
2356zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2357{
2358 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359
2360 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2361 ZFCP_STATUS_COMMON_CLOSING |
2362 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2363 ZFCP_STATUS_UNIT_SHARED |
2364 ZFCP_STATUS_UNIT_READONLY,
2365 &unit->status);
2366
2367 return retval;
2368}
2369
2370/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002371 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002373 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 *
2375 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2376 * ZFCP_ERP_FAILED - action finished unsuccessfully
2377 */
2378static int
2379zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2380{
2381 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 retval = zfcp_fsf_close_unit(erp_action);
2384 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 retval = ZFCP_ERP_NOMEM;
2386 goto out;
2387 }
2388 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2389 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 /* could not send 'close', fail */
2391 retval = ZFCP_ERP_FAILED;
2392 goto out;
2393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 retval = ZFCP_ERP_CONTINUES;
2395
2396 out:
2397 return retval;
2398}
2399
2400/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002401 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 *
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002403 * purpose:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 *
2405 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2406 * ZFCP_ERP_FAILED - action finished unsuccessfully
2407 */
2408static int
2409zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2410{
2411 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 retval = zfcp_fsf_open_unit(erp_action);
2414 if (retval == -ENOMEM) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 retval = ZFCP_ERP_NOMEM;
2416 goto out;
2417 }
2418 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2419 if (retval != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 /* could not send 'open', fail */
2421 retval = ZFCP_ERP_FAILED;
2422 goto out;
2423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 retval = ZFCP_ERP_CONTINUES;
2425 out:
2426 return retval;
2427}
2428
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002429void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430{
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002431 BUG_ON(!fsf_req->erp_action);
2432 fsf_req->timer.function = zfcp_erp_timeout_handler;
2433 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2434 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2435 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436}
2437
2438/*
Swen Schillig41fa2ad2007-09-07 09:15:31 +02002439 * function:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 *
2441 * purpose: enqueue the specified error recovery action, if needed
2442 *
2443 * returns:
2444 */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002445static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
2446 struct zfcp_port *port,
Martin Peschke1f6f7122008-04-18 12:51:55 +02002447 struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Martin Peschke9467a9b2008-03-27 14:22:03 +01002449 int retval = 1, need = want;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 struct zfcp_erp_action *erp_action = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 u32 status = 0;
2452
2453 /*
2454 * We need some rules here which check whether we really need
2455 * this action or whether we should just drop it.
2456 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2457 * 'Reopen Unit' request for an associated unit since we can't
2458 * satisfy this request now. A 'Reopen Port' action will trigger
2459 * 'Reopen Unit' actions when it completes.
2460 * Thus, there are only actions in the queue which can immediately be
2461 * executed. This makes the processing of the action queue more
2462 * efficient.
2463 */
2464
2465 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2466 &adapter->status))
2467 return -EIO;
2468
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 /* check whether we really need this */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002470 switch (want) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2472 if (atomic_test_mask
2473 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 goto out;
2475 }
2476 if (!atomic_test_mask
2477 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2478 atomic_test_mask
2479 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2480 goto out;
2481 }
2482 if (!atomic_test_mask
Martin Peschke9467a9b2008-03-27 14:22:03 +01002483 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
2484 need = ZFCP_ERP_ACTION_REOPEN_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 /* fall through !!! */
2486
2487 case ZFCP_ERP_ACTION_REOPEN_PORT:
2488 if (atomic_test_mask
2489 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 goto out;
2491 }
2492 /* fall through !!! */
2493
2494 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Andreas Herrmann3734d242005-09-13 21:47:11 +02002495 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2496 &port->status)) {
2497 if (port->erp_action.action !=
2498 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2499 ZFCP_LOG_INFO("dropped erp action %i (port "
2500 "0x%016Lx, action in use: %i)\n",
Martin Peschke9467a9b2008-03-27 14:22:03 +01002501 want, port->wwpn,
Andreas Herrmann3734d242005-09-13 21:47:11 +02002502 port->erp_action.action);
Martin Peschke507e4962008-03-27 14:22:05 +01002503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 goto out;
2505 }
2506 if (!atomic_test_mask
2507 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2508 atomic_test_mask
2509 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2510 goto out;
2511 }
2512 if (!atomic_test_mask
Martin Peschke9467a9b2008-03-27 14:22:03 +01002513 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
2514 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 /* fall through !!! */
2516
2517 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2518 if (atomic_test_mask
2519 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 goto out;
2521 }
2522 break;
2523
2524 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2526 "on adapter %s (action=%d)\n",
Martin Peschke9467a9b2008-03-27 14:22:03 +01002527 zfcp_get_busid_by_adapter(adapter), want);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 goto out;
2529 }
2530
2531 /* check whether we need something stronger first */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002532 if (need) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2534 "erp action %d on adapter %s\n",
Martin Peschke9467a9b2008-03-27 14:22:03 +01002535 need, want, zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 }
2537
2538 /* mark adapter to have some error recovery pending */
2539 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2540
2541 /* setup error recovery action */
Martin Peschke9467a9b2008-03-27 14:22:03 +01002542 switch (need) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
2544 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2545 zfcp_unit_get(unit);
2546 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2547 erp_action = &unit->erp_action;
2548 if (!atomic_test_mask
2549 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
2550 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2551 break;
2552
2553 case ZFCP_ERP_ACTION_REOPEN_PORT:
2554 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2555 zfcp_port_get(port);
2556 zfcp_erp_action_dismiss_port(port);
2557 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
2558 erp_action = &port->erp_action;
2559 if (!atomic_test_mask
2560 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
2561 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2562 break;
2563
2564 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2565 zfcp_adapter_get(adapter);
2566 zfcp_erp_action_dismiss_adapter(adapter);
2567 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
2568 erp_action = &adapter->erp_action;
2569 if (!atomic_test_mask
2570 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
2571 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
2572 break;
2573 }
2574
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
2576 erp_action->adapter = adapter;
2577 erp_action->port = port;
2578 erp_action->unit = unit;
Martin Peschke9467a9b2008-03-27 14:22:03 +01002579 erp_action->action = need;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 erp_action->status = status;
2581
2582 ++adapter->erp_total_count;
2583
2584 /* finally put it into 'ready' queue and kick erp thread */
Martin Peschke86e8dfc2007-11-15 13:57:17 +01002585 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 up(&adapter->erp_ready_sem);
Christof Schmittaa0fec62008-05-19 12:17:47 +02002587 zfcp_rec_dbf_event_thread(1, adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 retval = 0;
2589 out:
Martin Peschke1f6f7122008-04-18 12:51:55 +02002590 zfcp_rec_dbf_event_trigger(id, ref, want, need, erp_action,
Martin Peschke9467a9b2008-03-27 14:22:03 +01002591 adapter, port, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 return retval;
2593}
2594
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595static int
2596zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
2597{
2598 int retval = 0;
2599 struct zfcp_adapter *adapter = erp_action->adapter;
2600
2601 --adapter->erp_total_count;
2602 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
2603 --adapter->erp_low_mem_count;
2604 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
2605 }
2606
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 list_del(&erp_action->list);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002608 zfcp_rec_dbf_event_action(144, erp_action);
2609
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 switch (erp_action->action) {
2611 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2612 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2613 &erp_action->unit->status);
2614 break;
2615 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2616 case ZFCP_ERP_ACTION_REOPEN_PORT:
2617 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2618 &erp_action->port->status);
2619 break;
2620 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2621 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2622 &erp_action->adapter->status);
2623 break;
2624 default:
2625 /* bug */
2626 break;
2627 }
2628 return retval;
2629}
2630
2631/**
2632 * zfcp_erp_action_cleanup
2633 *
Adrian Bunk575c9682006-01-15 02:00:17 +01002634 * Register unit with scsi stack if appropriate and fix reference counts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 * Note: Temporary units are not registered with scsi stack.
2636 */
2637static void
2638zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
2639 struct zfcp_port *port, struct zfcp_unit *unit,
2640 int result)
2641{
2642 switch (action) {
2643 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2644 if ((result == ZFCP_ERP_SUCCEEDED)
2645 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
2646 &unit->status))
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002647 && !unit->device
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01002648 && port->rport) {
2649 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
2650 &unit->status);
Christof Schmitt5f852be2007-05-08 11:16:52 +02002651 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
2652 &unit->status) == 0)
2653 zfcp_erp_schedule_work(unit);
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01002654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 zfcp_unit_put(unit);
2656 break;
2657 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
2658 case ZFCP_ERP_ACTION_REOPEN_PORT:
Andreas Herrmann338151e2006-05-22 18:25:56 +02002659 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
2660 &port->status)) {
2661 zfcp_port_put(port);
2662 break;
2663 }
2664
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002665 if ((result == ZFCP_ERP_SUCCEEDED)
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002666 && !port->rport) {
2667 struct fc_rport_identifiers ids;
2668 ids.node_name = port->wwnn;
2669 ids.port_name = port->wwpn;
2670 ids.port_id = port->d_id;
2671 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
2672 port->rport =
2673 fc_remote_port_add(adapter->scsi_host, 0, &ids);
2674 if (!port->rport)
2675 ZFCP_LOG_NORMAL("failed registration of rport"
2676 "(adapter %s, wwpn=0x%016Lx)\n",
2677 zfcp_get_busid_by_port(port),
2678 port->wwpn);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002679 else {
Christof Schmitt5f852be2007-05-08 11:16:52 +02002680 scsi_target_unblock(&port->rport->dev);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02002681 port->rport->maxframe_size = port->maxframe_size;
2682 port->rport->supported_classes =
2683 port->supported_classes;
2684 }
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07002685 }
Andreas Herrmann338151e2006-05-22 18:25:56 +02002686 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
2687 fc_remote_port_delete(port->rport);
2688 port->rport = NULL;
2689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 zfcp_port_put(port);
2691 break;
2692 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Andreas Herrmann338151e2006-05-22 18:25:56 +02002693 if (result != ZFCP_ERP_SUCCEEDED) {
Andreas Herrmann338151e2006-05-22 18:25:56 +02002694 list_for_each_entry(port, &adapter->port_list_head, list)
2695 if (port->rport &&
2696 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2697 &port->status)) {
2698 fc_remote_port_delete(port->rport);
2699 port->rport = NULL;
2700 }
2701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 zfcp_adapter_put(adapter);
2703 break;
2704 default:
2705 break;
2706 }
2707}
2708
2709
Andreas Herrmann81654282006-09-18 22:30:36 +02002710static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 struct zfcp_port *port;
2713
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
2715 zfcp_erp_action_dismiss(&adapter->erp_action);
2716 else
2717 list_for_each_entry(port, &adapter->port_list_head, list)
2718 zfcp_erp_action_dismiss_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719}
2720
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02002721static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 struct zfcp_unit *unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
2726 zfcp_erp_action_dismiss(&port->erp_action);
2727 else
2728 list_for_each_entry(unit, &port->unit_list_head, list)
2729 zfcp_erp_action_dismiss_unit(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730}
2731
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02002732static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
2735 zfcp_erp_action_dismiss(&unit->erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736}
2737
Heiko Carstens364c8552007-10-12 16:11:35 +02002738static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002741 zfcp_rec_dbf_event_action(145, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742}
2743
Heiko Carstens364c8552007-10-12 16:11:35 +02002744static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
Martin Peschke6f4f3652008-03-27 14:22:04 +01002747 zfcp_rec_dbf_event_action(146, erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748}
2749
Martin Peschke1f6f7122008-04-18 12:51:55 +02002750void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002751{
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002752 unsigned long flags;
2753
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002754 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01002755 zfcp_erp_modify_port_status(port, id, ref,
2756 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002757 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
Martin Peschke9467a9b2008-03-27 14:22:03 +01002758 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002759}
2760
Martin Peschke1f6f7122008-04-18 12:51:55 +02002761void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref)
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002762{
Martin Peschke698ec0162008-03-27 14:22:02 +01002763 zfcp_erp_modify_unit_status(unit, id, ref,
2764 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
Martin Peschke9467a9b2008-03-27 14:22:03 +01002765 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002766}
2767
Martin Peschke1f6f7122008-04-18 12:51:55 +02002768void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 unsigned long flags;
2771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 read_lock_irqsave(&zfcp_data.config_lock, flags);
Martin Peschke698ec0162008-03-27 14:22:02 +01002773 zfcp_erp_modify_port_status(port, id, ref,
2774 ZFCP_STATUS_COMMON_ERP_FAILED |
2775 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2777}
2778
Martin Peschke1f6f7122008-04-18 12:51:55 +02002779void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780{
Martin Peschke698ec0162008-03-27 14:22:02 +01002781 zfcp_erp_modify_unit_status(unit, id, ref,
2782 ZFCP_STATUS_COMMON_ERP_FAILED |
2783 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784}
2785
Martin Peschke9467a9b2008-03-27 14:22:03 +01002786void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
Martin Peschke1f6f7122008-04-18 12:51:55 +02002787 void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788{
2789 struct zfcp_port *port;
2790 unsigned long flags;
2791
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002792 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2793 return;
2794
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 read_lock_irqsave(&zfcp_data.config_lock, flags);
6f71d9b2005-04-10 23:04:28 -05002796 if (adapter->nameserver_port)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002797 zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 list_for_each_entry(port, &adapter->port_list_head, list)
2799 if (port != adapter->nameserver_port)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002800 zfcp_erp_port_access_changed(port, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
2802}
2803
Martin Peschke1f6f7122008-04-18 12:51:55 +02002804void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805{
2806 struct zfcp_adapter *adapter = port->adapter;
2807 struct zfcp_unit *unit;
2808
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002810 &port->status) &&
2811 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 &port->status)) {
2813 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
2814 list_for_each_entry(unit, &port->unit_list_head, list)
Martin Peschke9467a9b2008-03-27 14:22:03 +01002815 zfcp_erp_unit_access_changed(unit, id, ref);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 return;
2817 }
2818
2819 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
2820 "(due to ACT update)\n",
2821 port->wwpn, zfcp_get_busid_by_adapter(adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +01002822 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 ZFCP_LOG_NORMAL("failed reopen of port"
2824 "(adapter %s, wwpn=0x%016Lx)\n",
2825 zfcp_get_busid_by_adapter(adapter), port->wwpn);
2826}
2827
Martin Peschke1f6f7122008-04-18 12:51:55 +02002828void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, void *ref)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829{
2830 struct zfcp_adapter *adapter = unit->port->adapter;
2831
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02002832 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
2833 &unit->status) &&
2834 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
2835 &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 return;
2837
2838 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
2839 " on adapter %s (due to ACT update)\n",
2840 unit->fcp_lun, unit->port->wwpn,
2841 zfcp_get_busid_by_adapter(adapter));
Martin Peschke9467a9b2008-03-27 14:22:03 +01002842 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
2844 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
2845 zfcp_get_busid_by_adapter(adapter),
2846 unit->port->wwpn, unit->fcp_lun);
2847}
2848
2849#undef ZFCP_LOG_AREA