blob: af42a0eadf03b7621164671d6390165ab6f4cf6a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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.
20 */
21
22#define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "zfcp_ext.h"
25
Andreas Herrmann64b29a132005-06-13 13:18:56 +020026static int zfcp_erp_adisc(struct zfcp_port *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static void zfcp_erp_adisc_handler(unsigned long);
28
29static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
30static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
31static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
32static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
33
34static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
35static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
36
37static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
38static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
39static void zfcp_erp_port_block(struct zfcp_port *, int);
40static void zfcp_erp_port_unblock(struct zfcp_port *);
41static void zfcp_erp_unit_block(struct zfcp_unit *, int);
42static void zfcp_erp_unit_unblock(struct zfcp_unit *);
43
44static int zfcp_erp_thread(void *);
45
46static int zfcp_erp_strategy(struct zfcp_erp_action *);
47
48static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
49static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
50static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
51static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
52static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
53static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
54static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
55 struct zfcp_port *,
56 struct zfcp_unit *, int);
57static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
58static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
59 struct zfcp_port *,
60 struct zfcp_unit *, int);
61static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
62static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
63
64static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
65static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
66static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
68static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
69static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
70static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020071static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static int zfcp_erp_adapter_strategy_open_fsf_statusread(
73 struct zfcp_erp_action *);
74
75static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
76static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
77
78static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
79static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
80static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
81static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
82static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
83static int zfcp_erp_port_strategy_open_nameserver_wakeup(
84 struct zfcp_erp_action *);
85static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
86static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
87static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
88
89static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
90static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
91static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
92static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
93
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +020094static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
95static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
96static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
99 struct zfcp_port *, struct zfcp_unit *);
100static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
101static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
102 struct zfcp_port *, struct zfcp_unit *,
103 int);
104
105static void zfcp_erp_action_ready(struct zfcp_erp_action *);
106static int zfcp_erp_action_exists(struct zfcp_erp_action *);
107
108static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
109static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
110
111static void zfcp_erp_memwait_handler(unsigned long);
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200112
113/**
114 * zfcp_close_qdio - close qdio queues for an adapter
115 */
116static void zfcp_close_qdio(struct zfcp_adapter *adapter)
117{
118 struct zfcp_qdio_queue *req_queue;
119 int first, count;
120
121 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
122 return;
123
124 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
125 req_queue = &adapter->request_queue;
126 write_lock_irq(&req_queue->queue_lock);
127 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
128 write_unlock_irq(&req_queue->queue_lock);
129
130 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
131 while (qdio_shutdown(adapter->ccw_device,
132 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
133 msleep(1000);
134 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
135
136 /* cleanup used outbound sbals */
137 count = atomic_read(&req_queue->free_count);
138 if (count < QDIO_MAX_BUFFERS_PER_Q) {
139 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
140 count = QDIO_MAX_BUFFERS_PER_Q - count;
141 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
142 }
143 req_queue->free_index = 0;
144 atomic_set(&req_queue->free_count, 0);
145 req_queue->distance_from_int = 0;
146 adapter->response_queue.free_index = 0;
147 atomic_set(&adapter->response_queue.free_count, 0);
148}
149
150/**
151 * zfcp_close_fsf - stop FSF operations for an adapter
152 *
153 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
154 * requests waiting for completion; especially this returns SCSI commands
155 * with error state).
156 */
157static void zfcp_close_fsf(struct zfcp_adapter *adapter)
158{
159 /* close queues to ensure that buffers are not accessed by adapter */
160 zfcp_close_qdio(adapter);
161 zfcp_fsf_req_dismiss_all(adapter);
162 /* reset FSF request sequence number */
163 adapter->fsf_req_seq_no = 0;
164 /* all ports and units are closed */
165 zfcp_erp_modify_adapter_status(adapter,
166 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
167}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169/**
170 * zfcp_fsf_request_timeout_handler - called if a request timed out
171 * @data: pointer to adapter for handler function
172 *
173 * This function needs to be called if requests (ELS, Generic Service,
174 * or SCSI commands) exceed a certain time limit. The assumption is
175 * that after the time limit the adapter get stuck. So we trigger a reopen of
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200176 * the adapter.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200178static void zfcp_fsf_request_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200180 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 zfcp_erp_adapter_reopen(adapter, 0);
182}
183
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200184void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200186 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
187 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
188 fsf_req->timer.expires = timeout;
189 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190}
191
192/*
193 * function:
194 *
195 * purpose: called if an adapter failed,
196 * initiates adapter recovery which is done
197 * asynchronously
198 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200199 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 * <0 - failed to initiate action
201 */
202int
203zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
204{
205 int retval;
206
207 debug_text_event(adapter->erp_dbf, 5, "a_ro");
208 ZFCP_LOG_DEBUG("reopen adapter %s\n",
209 zfcp_get_busid_by_adapter(adapter));
210
211 zfcp_erp_adapter_block(adapter, clear_mask);
212
213 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
214 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
215 zfcp_get_busid_by_adapter(adapter));
216 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
217 /* ensure propagation of failed status to new devices */
218 zfcp_erp_adapter_failed(adapter);
219 retval = -EIO;
220 goto out;
221 }
222 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
223 adapter, NULL, NULL);
224
225 out:
226 return retval;
227}
228
229/*
230 * function:
231 *
232 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
233 * used to ensure the correct locking
234 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200235 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 * <0 - failed to initiate action
237 */
238int
239zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
240{
241 int retval;
242 unsigned long flags;
243
244 read_lock_irqsave(&zfcp_data.config_lock, flags);
245 write_lock(&adapter->erp_lock);
246 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
247 write_unlock(&adapter->erp_lock);
248 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
249
250 return retval;
251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253int
254zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
255{
256 int retval;
257
258 retval = zfcp_erp_adapter_reopen(adapter,
259 ZFCP_STATUS_COMMON_RUNNING |
260 ZFCP_STATUS_COMMON_ERP_FAILED |
261 clear_mask);
262
263 return retval;
264}
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266int
267zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
268{
269 int retval;
270
271 retval = zfcp_erp_port_reopen(port,
272 ZFCP_STATUS_COMMON_RUNNING |
273 ZFCP_STATUS_COMMON_ERP_FAILED |
274 clear_mask);
275
276 return retval;
277}
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279int
280zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
281{
282 int retval;
283
284 retval = zfcp_erp_unit_reopen(unit,
285 ZFCP_STATUS_COMMON_RUNNING |
286 ZFCP_STATUS_COMMON_ERP_FAILED |
287 clear_mask);
288
289 return retval;
290}
291
292
293/**
294 * zfcp_erp_adisc - send ADISC ELS command
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200295 * @port: port structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 */
297int
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200298zfcp_erp_adisc(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200300 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 struct zfcp_send_els *send_els;
302 struct zfcp_ls_adisc *adisc;
303 void *address = NULL;
304 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Andreas Herrmannec4081c2006-05-22 18:17:30 +0200306 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 if (send_els == NULL)
308 goto nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Andreas Herrmannec4081c2006-05-22 18:17:30 +0200310 send_els->req = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (send_els->req == NULL)
312 goto nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Andreas Herrmannec4081c2006-05-22 18:17:30 +0200314 send_els->resp = kzalloc(sizeof(struct scatterlist), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (send_els->resp == NULL)
316 goto nomem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318 address = (void *) get_zeroed_page(GFP_ATOMIC);
319 if (address == NULL)
320 goto nomem;
321
322 zfcp_address_to_sg(address, send_els->req);
323 address += PAGE_SIZE >> 1;
324 zfcp_address_to_sg(address, send_els->resp);
325 send_els->req_count = send_els->resp_count = 1;
326
327 send_els->adapter = adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200328 send_els->port = port;
329 send_els->d_id = port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 send_els->handler = zfcp_erp_adisc_handler;
331 send_els->handler_data = (unsigned long) send_els;
332
333 adisc = zfcp_sg_to_address(send_els->req);
334 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
335
336 send_els->req->length = sizeof(struct zfcp_ls_adisc);
337 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
338
339 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
340 without FC-AL-2 capability, so we don't set it */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200341 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
342 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
343 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
345 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
346 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200347 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
349 adisc->nport_id);
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 retval = zfcp_fsf_send_els(send_els);
352 if (retval != 0) {
353 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200354 "0x%08x on adapter %s\n", send_els->d_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 zfcp_get_busid_by_adapter(adapter));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 goto freemem;
357 }
358
359 goto out;
360
361 nomem:
362 retval = -ENOMEM;
363 freemem:
364 if (address != NULL)
365 __free_pages(send_els->req->page, 0);
366 if (send_els != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 kfree(send_els->req);
368 kfree(send_els->resp);
369 kfree(send_els);
370 }
371 out:
372 return retval;
373}
374
375
376/**
377 * zfcp_erp_adisc_handler - handler for ADISC ELS command
378 * @data: pointer to struct zfcp_send_els
379 *
380 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
381 */
382void
383zfcp_erp_adisc_handler(unsigned long data)
384{
385 struct zfcp_send_els *send_els;
386 struct zfcp_port *port;
387 struct zfcp_adapter *adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200388 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 struct zfcp_ls_adisc_acc *adisc;
390
391 send_els = (struct zfcp_send_els *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200393 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 d_id = send_els->d_id;
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 /* request rejected or timed out */
397 if (send_els->status != 0) {
398 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
399 "force physical port reopen "
400 "(adapter %s, port d_id=0x%08x)\n",
401 zfcp_get_busid_by_adapter(adapter), d_id);
402 debug_text_event(adapter->erp_dbf, 3, "forcreop");
403 if (zfcp_erp_port_forced_reopen(port, 0))
404 ZFCP_LOG_NORMAL("failed reopen of port "
405 "(adapter %s, wwpn=0x%016Lx)\n",
406 zfcp_get_busid_by_port(port),
407 port->wwpn);
408 goto out;
409 }
410
411 adisc = zfcp_sg_to_address(send_els->resp);
412
413 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
414 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
415 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200416 d_id, fc_host_port_id(adapter->scsi_host),
417 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
418 adisc->hard_nport_id, adisc->nport_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 /* set wwnn for port */
421 if (port->wwnn == 0)
422 port->wwnn = adisc->wwnn;
423
424 if (port->wwpn != adisc->wwpn) {
425 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
426 "port (adapter %s, wwpn=0x%016Lx, "
427 "adisc_resp_wwpn=0x%016Lx)\n",
428 zfcp_get_busid_by_port(port),
429 port->wwpn, (wwn_t) adisc->wwpn);
430 if (zfcp_erp_port_reopen(port, 0))
431 ZFCP_LOG_NORMAL("failed reopen of port "
432 "(adapter %s, wwpn=0x%016Lx)\n",
433 zfcp_get_busid_by_port(port),
434 port->wwpn);
435 }
436
437 out:
438 zfcp_port_put(port);
439 __free_pages(send_els->req->page, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 kfree(send_els->req);
441 kfree(send_els->resp);
442 kfree(send_els);
443}
444
445
446/**
447 * zfcp_test_link - lightweight link test procedure
448 * @port: port to be tested
449 *
450 * Test status of a link to a remote port using the ELS command ADISC.
451 */
452int
453zfcp_test_link(struct zfcp_port *port)
454{
455 int retval;
456
457 zfcp_port_get(port);
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200458 retval = zfcp_erp_adisc(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (retval != 0) {
460 zfcp_port_put(port);
461 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
462 "on adapter %s\n ", port->wwpn,
463 zfcp_get_busid_by_port(port));
464 retval = zfcp_erp_port_forced_reopen(port, 0);
465 if (retval != 0) {
466 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
467 "on adapter %s failed\n", port->wwpn,
468 zfcp_get_busid_by_port(port));
469 retval = -EPERM;
470 }
471 }
472
473 return retval;
474}
475
476
477/*
478 * function:
479 *
480 * purpose: called if a port failed to be opened normally
481 * initiates Forced Reopen recovery which is done
482 * asynchronously
483 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200484 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 * <0 - failed to initiate action
486 */
487static int
488zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
489{
490 int retval;
491 struct zfcp_adapter *adapter = port->adapter;
492
493 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
494 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
495
496 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
497 port->wwpn, zfcp_get_busid_by_port(port));
498
499 zfcp_erp_port_block(port, clear_mask);
500
501 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
502 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
503 "on adapter %s\n", port->wwpn,
504 zfcp_get_busid_by_port(port));
505 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
506 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
507 retval = -EIO;
508 goto out;
509 }
510
511 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
512 port->adapter, port, NULL);
513
514 out:
515 return retval;
516}
517
518/*
519 * function:
520 *
521 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
522 * used to ensure the correct locking
523 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200524 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * <0 - failed to initiate action
526 */
527int
528zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
529{
530 int retval;
531 unsigned long flags;
532 struct zfcp_adapter *adapter;
533
534 adapter = port->adapter;
535 read_lock_irqsave(&zfcp_data.config_lock, flags);
536 write_lock(&adapter->erp_lock);
537 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
538 write_unlock(&adapter->erp_lock);
539 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
540
541 return retval;
542}
543
544/*
545 * function:
546 *
547 * purpose: called if a port is to be opened
548 * initiates Reopen recovery which is done
549 * asynchronously
550 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200551 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 * <0 - failed to initiate action
553 */
554static int
555zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
556{
557 int retval;
558 struct zfcp_adapter *adapter = port->adapter;
559
560 debug_text_event(adapter->erp_dbf, 5, "p_ro");
561 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
562
563 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
564 port->wwpn, zfcp_get_busid_by_port(port));
565
566 zfcp_erp_port_block(port, clear_mask);
567
568 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
569 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
570 "on adapter %s\n", port->wwpn,
571 zfcp_get_busid_by_port(port));
572 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
573 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
574 /* ensure propagation of failed status to new devices */
575 zfcp_erp_port_failed(port);
576 retval = -EIO;
577 goto out;
578 }
579
580 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
581 port->adapter, port, NULL);
582
583 out:
584 return retval;
585}
586
587/**
588 * zfcp_erp_port_reopen - initiate reopen of a remote port
589 * @port: port to be reopened
590 * @clear_mask: specifies flags in port status to be cleared
591 * Return: 0 on success, < 0 on error
592 *
593 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
594 * correct locking. An error recovery task is initiated to do the reopen.
595 * To wait for the completion of the reopen zfcp_erp_wait should be used.
596 */
597int
598zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
599{
600 int retval;
601 unsigned long flags;
602 struct zfcp_adapter *adapter = port->adapter;
603
604 read_lock_irqsave(&zfcp_data.config_lock, flags);
605 write_lock(&adapter->erp_lock);
606 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
607 write_unlock(&adapter->erp_lock);
608 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
609
610 return retval;
611}
612
613/*
614 * function:
615 *
616 * purpose: called if a unit is to be opened
617 * initiates Reopen recovery which is done
618 * asynchronously
619 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200620 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 * <0 - failed to initiate action
622 */
623static int
624zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
625{
626 int retval;
627 struct zfcp_adapter *adapter = unit->port->adapter;
628
629 debug_text_event(adapter->erp_dbf, 5, "u_ro");
630 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
631 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
632 "on adapter %s\n", unit->fcp_lun,
633 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
634
635 zfcp_erp_unit_block(unit, clear_mask);
636
637 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
638 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
639 "on port 0x%016Lx on adapter %s\n",
640 unit->fcp_lun, unit->port->wwpn,
641 zfcp_get_busid_by_unit(unit));
642 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
643 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
644 sizeof (fcp_lun_t));
645 retval = -EIO;
646 goto out;
647 }
648
649 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
650 unit->port->adapter, unit->port, unit);
651 out:
652 return retval;
653}
654
655/**
656 * zfcp_erp_unit_reopen - initiate reopen of a unit
657 * @unit: unit to be reopened
658 * @clear_mask: specifies flags in unit status to be cleared
659 * Return: 0 on success, < 0 on error
660 *
661 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
662 * locking. An error recovery task is initiated to do the reopen.
663 * To wait for the completion of the reopen zfcp_erp_wait should be used.
664 */
665int
666zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
667{
668 int retval;
669 unsigned long flags;
670 struct zfcp_adapter *adapter;
671 struct zfcp_port *port;
672
673 port = unit->port;
674 adapter = port->adapter;
675
676 read_lock_irqsave(&zfcp_data.config_lock, flags);
677 write_lock(&adapter->erp_lock);
678 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
679 write_unlock(&adapter->erp_lock);
680 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
681
682 return retval;
683}
684
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200685/**
686 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200688static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
690 debug_text_event(adapter->erp_dbf, 6, "a_bl");
691 zfcp_erp_modify_adapter_status(adapter,
692 ZFCP_STATUS_COMMON_UNBLOCKED |
693 clear_mask, ZFCP_CLEAR);
694}
695
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200696/**
697 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200699static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
702 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
703}
704
705/*
706 * function:
707 *
708 * purpose: disable I/O,
709 * return any open requests and clean them up,
710 * aim: no pending and incoming I/O
711 *
712 * returns:
713 */
714static void
715zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
716{
717 struct zfcp_adapter *adapter = port->adapter;
718
719 debug_text_event(adapter->erp_dbf, 6, "p_bl");
720 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
721 zfcp_erp_modify_port_status(port,
722 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
723 ZFCP_CLEAR);
724}
725
726/*
727 * function:
728 *
729 * purpose: enable I/O
730 *
731 * returns:
732 */
733static void
734zfcp_erp_port_unblock(struct zfcp_port *port)
735{
736 struct zfcp_adapter *adapter = port->adapter;
737
738 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
739 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
740 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
741}
742
743/*
744 * function:
745 *
746 * purpose: disable I/O,
747 * return any open requests and clean them up,
748 * aim: no pending and incoming I/O
749 *
750 * returns:
751 */
752static void
753zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
754{
755 struct zfcp_adapter *adapter = unit->port->adapter;
756
757 debug_text_event(adapter->erp_dbf, 6, "u_bl");
758 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
759 zfcp_erp_modify_unit_status(unit,
760 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
761 ZFCP_CLEAR);
762}
763
764/*
765 * function:
766 *
767 * purpose: enable I/O
768 *
769 * returns:
770 */
771static void
772zfcp_erp_unit_unblock(struct zfcp_unit *unit)
773{
774 struct zfcp_adapter *adapter = unit->port->adapter;
775
776 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
777 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
778 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
779}
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781static void
782zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
783{
784 struct zfcp_adapter *adapter = erp_action->adapter;
785
786 debug_text_event(adapter->erp_dbf, 4, "a_ar");
787 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
788
789 zfcp_erp_action_to_ready(erp_action);
790 up(&adapter->erp_ready_sem);
791}
792
793/*
794 * function:
795 *
796 * purpose:
797 *
798 * returns: <0 erp_action not found in any list
799 * ZFCP_ERP_ACTION_READY erp_action is in ready list
800 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
801 *
802 * locks: erp_lock must be held
803 */
804static int
805zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
806{
807 int retval = -EINVAL;
808 struct list_head *entry;
809 struct zfcp_erp_action *entry_erp_action;
810 struct zfcp_adapter *adapter = erp_action->adapter;
811
812 /* search in running list */
813 list_for_each(entry, &adapter->erp_running_head) {
814 entry_erp_action =
815 list_entry(entry, struct zfcp_erp_action, list);
816 if (entry_erp_action == erp_action) {
817 retval = ZFCP_ERP_ACTION_RUNNING;
818 goto out;
819 }
820 }
821 /* search in ready list */
822 list_for_each(entry, &adapter->erp_ready_head) {
823 entry_erp_action =
824 list_entry(entry, struct zfcp_erp_action, list);
825 if (entry_erp_action == erp_action) {
826 retval = ZFCP_ERP_ACTION_READY;
827 goto out;
828 }
829 }
830
831 out:
832 return retval;
833}
834
835/*
836 * purpose: checks current status of action (timed out, dismissed, ...)
837 * and does appropriate preparations (dismiss fsf request, ...)
838 *
839 * locks: called under erp_lock (disabled interrupts)
840 *
841 * returns: 0
842 */
843static int
844zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
845{
846 int retval = 0;
Andreas Herrmann3734d242005-09-13 21:47:11 +0200847 struct zfcp_fsf_req *fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 struct zfcp_adapter *adapter = erp_action->adapter;
849
850 if (erp_action->fsf_req) {
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200851 /* take lock to ensure that request is not deleted meanwhile */
852 spin_lock(&adapter->req_list_lock);
853 if ((!zfcp_reqlist_ismember(adapter,
854 erp_action->fsf_req->req_id)) &&
855 (fsf_req->erp_action == erp_action)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* fsf_req still exists */
857 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
858 debug_event(adapter->erp_dbf, 3, &fsf_req,
859 sizeof (unsigned long));
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200860 /* dismiss fsf_req of timed out/dismissed erp_action */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
862 ZFCP_STATUS_ERP_TIMEDOUT)) {
863 debug_text_event(adapter->erp_dbf, 3,
864 "a_ca_disreq");
865 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
866 }
867 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
868 ZFCP_LOG_NORMAL("error: erp step timed out "
869 "(action=%d, fsf_req=%p)\n ",
870 erp_action->action,
871 erp_action->fsf_req);
872 }
873 /*
874 * If fsf_req is neither dismissed nor completed
875 * then keep it running asynchronously and don't mess
876 * with the association of erp_action and fsf_req.
877 */
878 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
879 ZFCP_STATUS_FSFREQ_DISMISSED)) {
880 /* forget about association between fsf_req
881 and erp_action */
882 fsf_req->erp_action = NULL;
883 erp_action->fsf_req = NULL;
884 }
885 } else {
886 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
887 /*
888 * even if this fsf_req has gone, forget about
889 * association between erp_action and fsf_req
890 */
891 erp_action->fsf_req = NULL;
892 }
Volker Sameskefea9d6c2006-08-02 11:05:16 +0200893 spin_unlock(&adapter->req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 } else
895 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
896
897 return retval;
898}
899
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200900/**
901 * zfcp_erp_async_handler_nolock - complete erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200903 * Used for normal completion, time-out, dismissal and failure after
904 * low memory condition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200906static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
907 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 struct zfcp_adapter *adapter = erp_action->adapter;
910
911 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
912 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
913 debug_event(adapter->erp_dbf, 2, &erp_action->action,
914 sizeof (int));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 erp_action->status |= set_mask;
916 zfcp_erp_action_ready(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 } else {
918 /* action is ready or gone - nothing to do */
919 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
920 debug_event(adapter->erp_dbf, 3, &erp_action->action,
921 sizeof (int));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923}
924
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200925/**
926 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200928void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
929 unsigned long set_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930{
931 struct zfcp_adapter *adapter = erp_action->adapter;
932 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 write_lock_irqsave(&adapter->erp_lock, flags);
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200935 zfcp_erp_async_handler_nolock(erp_action, set_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 write_unlock_irqrestore(&adapter->erp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939/*
940 * purpose: is called for erp_action which was slept waiting for
941 * memory becoming avaliable,
942 * will trigger that this action will be continued
943 */
944static void
945zfcp_erp_memwait_handler(unsigned long data)
946{
947 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
948 struct zfcp_adapter *adapter = erp_action->adapter;
949
950 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
951 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
952
953 zfcp_erp_async_handler(erp_action, 0);
954}
955
956/*
957 * purpose: is called if an asynchronous erp step timed out,
958 * action gets an appropriate flag and will be processed
959 * accordingly
960 */
Andreas Herrmann2abbe862006-09-18 22:29:56 +0200961void zfcp_erp_timeout_handler(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962{
963 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
964 struct zfcp_adapter *adapter = erp_action->adapter;
965
966 debug_text_event(adapter->erp_dbf, 2, "a_th");
967 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
968
969 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
970}
971
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200972/**
973 * zfcp_erp_action_dismiss - dismiss an erp_action
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 *
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200975 * adapter->erp_lock must be held
976 *
977 * Dismissal of an erp_action is usually required if an erp_action of
978 * higher priority is generated.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 */
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +0200980static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
982 struct zfcp_adapter *adapter = erp_action->adapter;
983
984 debug_text_event(adapter->erp_dbf, 2, "a_adis");
985 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
986
987 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988}
989
990int
991zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
992{
993 int retval = 0;
994
995 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
998 if (retval < 0) {
999 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1000 "adapter %s\n",
1001 zfcp_get_busid_by_adapter(adapter));
1002 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1003 } else {
1004 wait_event(adapter->erp_thread_wqh,
1005 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1006 &adapter->status));
1007 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1008 }
1009
1010 return (retval < 0);
1011}
1012
1013/*
1014 * function:
1015 *
1016 * purpose:
1017 *
1018 * returns:
1019 *
1020 * context: process (i.e. proc-fs or rmmod/insmod)
1021 *
1022 * note: The caller of this routine ensures that the specified
1023 * adapter has been shut down and that this operation
1024 * has been completed. Thus, there are no pending erp_actions
1025 * which would need to be handled here.
1026 */
1027int
1028zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1029{
1030 int retval = 0;
1031
1032 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1033 up(&adapter->erp_ready_sem);
1034
1035 wait_event(adapter->erp_thread_wqh,
1036 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1037 &adapter->status));
1038
1039 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1040 &adapter->status);
1041
1042 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1043
1044 return retval;
1045}
1046
1047/*
1048 * purpose: is run as a kernel thread,
1049 * goes through list of error recovery actions of associated adapter
1050 * and delegates single action to execution
1051 *
1052 * returns: 0
1053 */
1054static int
1055zfcp_erp_thread(void *data)
1056{
1057 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1058 struct list_head *next;
1059 struct zfcp_erp_action *erp_action;
1060 unsigned long flags;
1061
1062 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1063 /* Block all signals */
1064 siginitsetinv(&current->blocked, 0);
1065 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1066 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1067 wake_up(&adapter->erp_thread_wqh);
1068
1069 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1070 &adapter->status)) {
1071
1072 write_lock_irqsave(&adapter->erp_lock, flags);
1073 next = adapter->erp_ready_head.prev;
1074 write_unlock_irqrestore(&adapter->erp_lock, flags);
1075
1076 if (next != &adapter->erp_ready_head) {
1077 erp_action =
1078 list_entry(next, struct zfcp_erp_action, list);
1079 /*
1080 * process action (incl. [re]moving it
1081 * from 'ready' queue)
1082 */
1083 zfcp_erp_strategy(erp_action);
1084 }
1085
1086 /*
1087 * sleep as long as there is nothing to do, i.e.
1088 * no action in 'ready' queue to be processed and
1089 * thread is not to be killed
1090 */
1091 down_interruptible(&adapter->erp_ready_sem);
1092 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1093 }
1094
1095 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1096 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1097 wake_up(&adapter->erp_thread_wqh);
1098
1099 return 0;
1100}
1101
1102/*
1103 * function:
1104 *
1105 * purpose: drives single error recovery action and schedules higher and
1106 * subordinate actions, if necessary
1107 *
1108 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1109 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1110 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1111 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1112 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1113 */
1114static int
1115zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1116{
1117 int retval = 0;
1118 struct zfcp_adapter *adapter = erp_action->adapter;
1119 struct zfcp_port *port = erp_action->port;
1120 struct zfcp_unit *unit = erp_action->unit;
1121 int action = erp_action->action;
1122 u32 status = erp_action->status;
1123 unsigned long flags;
1124
1125 /* serialise dismissing, timing out, moving, enqueueing */
1126 read_lock_irqsave(&zfcp_data.config_lock, flags);
1127 write_lock(&adapter->erp_lock);
1128
1129 /* dequeue dismissed action and leave, if required */
1130 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1131 if (retval == ZFCP_ERP_DISMISSED) {
1132 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1133 goto unlock;
1134 }
1135
1136 /*
1137 * move action to 'running' queue before processing it
1138 * (to avoid a race condition regarding moving the
1139 * action to the 'running' queue and back)
1140 */
1141 zfcp_erp_action_to_running(erp_action);
1142
1143 /*
1144 * try to process action as far as possible,
1145 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1146 * afterwards the lock is required again for the following reasons:
1147 * - dequeueing of finished action and enqueueing of
1148 * follow-up actions must be atomic so that any other
1149 * reopen-routine does not believe there is nothing to do
1150 * and that it is safe to enqueue something else,
1151 * - we want to force any control thread which is dismissing
1152 * actions to finish this before we decide about
1153 * necessary steps to be taken here further
1154 */
1155 write_unlock(&adapter->erp_lock);
1156 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1157 retval = zfcp_erp_strategy_do_action(erp_action);
1158 read_lock_irqsave(&zfcp_data.config_lock, flags);
1159 write_lock(&adapter->erp_lock);
1160
1161 /*
1162 * check for dismissed status again to avoid follow-up actions,
1163 * failing of targets and so on for dismissed actions
1164 */
1165 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1166
1167 switch (retval) {
1168 case ZFCP_ERP_DISMISSED:
1169 /* leave since this action has ridden to its ancestors */
1170 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1171 goto unlock;
1172 case ZFCP_ERP_NOMEM:
1173 /* no memory to continue immediately, let it sleep */
1174 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1175 ++adapter->erp_low_mem_count;
1176 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1177 }
1178 /* This condition is true if there is no memory available
1179 for any erp_action on this adapter. This implies that there
1180 are no elements in the memory pool(s) left for erp_actions.
1181 This might happen if an erp_action that used a memory pool
1182 element was timed out.
1183 */
1184 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1185 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1186 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1187 "restarting I/O on adapter %s "
1188 "to free mempool\n",
1189 zfcp_get_busid_by_adapter(adapter));
1190 zfcp_erp_adapter_reopen_internal(adapter, 0);
1191 } else {
1192 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1193 retval = zfcp_erp_strategy_memwait(erp_action);
1194 }
1195 goto unlock;
1196 case ZFCP_ERP_CONTINUES:
1197 /* leave since this action runs asynchronously */
1198 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1199 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1200 --adapter->erp_low_mem_count;
1201 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1202 }
1203 goto unlock;
1204 }
1205 /* ok, finished action (whatever its result is) */
1206
1207 /* check for unrecoverable targets */
1208 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1209
1210 /* action must be dequeued (here to allow for further ones) */
1211 zfcp_erp_action_dequeue(erp_action);
1212
1213 /*
1214 * put this target through the erp mill again if someone has
1215 * requested to change the status of a target being online
1216 * to offline or the other way around
1217 * (old retval is preserved if nothing has to be done here)
1218 */
1219 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1220 port, unit, retval);
1221
1222 /*
1223 * leave if target is in permanent error state or if
1224 * action is repeated in order to process state change
1225 */
1226 if (retval == ZFCP_ERP_EXIT) {
1227 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1228 goto unlock;
1229 }
1230
1231 /* trigger follow up actions */
1232 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1233
1234 unlock:
1235 write_unlock(&adapter->erp_lock);
1236 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1237
1238 if (retval != ZFCP_ERP_CONTINUES)
1239 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1240
1241 /*
1242 * a few tasks remain when the erp queues are empty
1243 * (don't do that if the last action evaluated was dismissed
1244 * since this clearly indicates that there is more to come) :
1245 * - close the name server port if it is open yet
1246 * (enqueues another [probably] final action)
1247 * - otherwise, wake up whoever wants to be woken when we are
1248 * done with erp
1249 */
1250 if (retval != ZFCP_ERP_DISMISSED)
1251 zfcp_erp_strategy_check_queues(adapter);
1252
1253 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1254
1255 return retval;
1256}
1257
1258/*
1259 * function:
1260 *
1261 * purpose:
1262 *
1263 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1264 * retval - otherwise
1265 */
1266static int
1267zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1268{
1269 struct zfcp_adapter *adapter = erp_action->adapter;
1270
1271 zfcp_erp_strategy_check_fsfreq(erp_action);
1272
1273 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1274 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1275 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1276 zfcp_erp_action_dequeue(erp_action);
1277 retval = ZFCP_ERP_DISMISSED;
1278 } else
1279 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1280
1281 return retval;
1282}
1283
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284static int
1285zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1286{
1287 int retval = ZFCP_ERP_FAILED;
1288 struct zfcp_adapter *adapter = erp_action->adapter;
1289
1290 /*
1291 * try to execute/continue action as far as possible,
1292 * note: no lock in subsequent strategy routines
1293 * (this allows these routine to call schedule, e.g.
1294 * kmalloc with such flags or qdio_initialize & friends)
1295 * Note: in case of timeout, the seperate strategies will fail
1296 * anyhow. No need for a special action. Even worse, a nameserver
1297 * failure would not wake up waiting ports without the call.
1298 */
1299 switch (erp_action->action) {
1300
1301 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1302 retval = zfcp_erp_adapter_strategy(erp_action);
1303 break;
1304
1305 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1306 retval = zfcp_erp_port_forced_strategy(erp_action);
1307 break;
1308
1309 case ZFCP_ERP_ACTION_REOPEN_PORT:
1310 retval = zfcp_erp_port_strategy(erp_action);
1311 break;
1312
1313 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1314 retval = zfcp_erp_unit_strategy(erp_action);
1315 break;
1316
1317 default:
1318 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1319 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1320 sizeof (int));
1321 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1322 "adapter %s (action=%d)\n",
1323 zfcp_get_busid_by_adapter(erp_action->adapter),
1324 erp_action->action);
1325 }
1326
1327 return retval;
1328}
1329
1330/*
1331 * function:
1332 *
1333 * purpose: triggers retry of this action after a certain amount of time
1334 * by means of timer provided by erp_action
1335 *
1336 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1337 */
1338static int
1339zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1340{
1341 int retval = ZFCP_ERP_CONTINUES;
1342 struct zfcp_adapter *adapter = erp_action->adapter;
1343
1344 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1345 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1346 init_timer(&erp_action->timer);
1347 erp_action->timer.function = zfcp_erp_memwait_handler;
1348 erp_action->timer.data = (unsigned long) erp_action;
1349 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1350 add_timer(&erp_action->timer);
1351
1352 return retval;
1353}
1354
1355/*
1356 * function: zfcp_erp_adapter_failed
1357 *
1358 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1359 *
1360 */
1361void
1362zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1363{
1364 zfcp_erp_modify_adapter_status(adapter,
1365 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1366 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1367 zfcp_get_busid_by_adapter(adapter));
1368 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1369}
1370
1371/*
1372 * function: zfcp_erp_port_failed
1373 *
1374 * purpose: sets the port and all underlying devices to ERP_FAILED
1375 *
1376 */
1377void
1378zfcp_erp_port_failed(struct zfcp_port *port)
1379{
1380 zfcp_erp_modify_port_status(port,
1381 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1382
1383 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1384 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1385 "port d_id=0x%08x)\n",
1386 zfcp_get_busid_by_port(port), port->d_id);
1387 else
1388 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1389 zfcp_get_busid_by_port(port), port->wwpn);
1390
1391 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1392 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1393}
1394
1395/*
1396 * function: zfcp_erp_unit_failed
1397 *
1398 * purpose: sets the unit to ERP_FAILED
1399 *
1400 */
1401void
1402zfcp_erp_unit_failed(struct zfcp_unit *unit)
1403{
1404 zfcp_erp_modify_unit_status(unit,
1405 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1406
1407 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1408 " on adapter %s\n", unit->fcp_lun,
1409 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1410 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1411 debug_event(unit->port->adapter->erp_dbf, 2,
1412 &unit->fcp_lun, sizeof (fcp_lun_t));
1413}
1414
1415/*
1416 * function: zfcp_erp_strategy_check_target
1417 *
1418 * purpose: increments the erp action count on the device currently in
1419 * recovery if the action failed or resets the count in case of
1420 * success. If a maximum count is exceeded the device is marked
1421 * as ERP_FAILED.
1422 * The 'blocked' state of a target which has been recovered
1423 * successfully is reset.
1424 *
1425 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1426 * ZFCP_ERP_SUCCEEDED - action finished successfully
1427 * ZFCP_ERP_EXIT - action failed and will not continue
1428 */
1429static int
1430zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1431{
1432 struct zfcp_adapter *adapter = erp_action->adapter;
1433 struct zfcp_port *port = erp_action->port;
1434 struct zfcp_unit *unit = erp_action->unit;
1435
1436 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1437 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1438 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1439
1440 switch (erp_action->action) {
1441
1442 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1443 result = zfcp_erp_strategy_check_unit(unit, result);
1444 break;
1445
1446 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1447 case ZFCP_ERP_ACTION_REOPEN_PORT:
1448 result = zfcp_erp_strategy_check_port(port, result);
1449 break;
1450
1451 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1452 result = zfcp_erp_strategy_check_adapter(adapter, result);
1453 break;
1454 }
1455
1456 return result;
1457}
1458
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459static int
1460zfcp_erp_strategy_statechange(int action,
1461 u32 status,
1462 struct zfcp_adapter *adapter,
1463 struct zfcp_port *port,
1464 struct zfcp_unit *unit, int retval)
1465{
1466 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1467 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1468
1469 switch (action) {
1470
1471 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1472 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1473 status)) {
1474 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1475 retval = ZFCP_ERP_EXIT;
1476 }
1477 break;
1478
1479 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1480 case ZFCP_ERP_ACTION_REOPEN_PORT:
1481 if (zfcp_erp_strategy_statechange_detected(&port->status,
1482 status)) {
1483 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1484 retval = ZFCP_ERP_EXIT;
1485 }
1486 break;
1487
1488 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1489 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1490 status)) {
1491 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1492 retval = ZFCP_ERP_EXIT;
1493 }
1494 break;
1495 }
1496
1497 return retval;
1498}
1499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500static inline int
1501zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1502{
1503 return
1504 /* take it online */
1505 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1506 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1507 /* take it offline */
1508 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1509 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1510}
1511
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512static int
1513zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1514{
1515 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1516 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1517 sizeof (fcp_lun_t));
1518
1519 switch (result) {
1520 case ZFCP_ERP_SUCCEEDED :
1521 atomic_set(&unit->erp_counter, 0);
1522 zfcp_erp_unit_unblock(unit);
1523 break;
1524 case ZFCP_ERP_FAILED :
1525 atomic_inc(&unit->erp_counter);
1526 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1527 zfcp_erp_unit_failed(unit);
1528 break;
1529 case ZFCP_ERP_EXIT :
1530 /* nothing */
1531 break;
1532 }
1533
1534 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1535 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1536 result = ZFCP_ERP_EXIT;
1537 }
1538
1539 return result;
1540}
1541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542static int
1543zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1544{
1545 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1546 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1547
1548 switch (result) {
1549 case ZFCP_ERP_SUCCEEDED :
1550 atomic_set(&port->erp_counter, 0);
1551 zfcp_erp_port_unblock(port);
1552 break;
1553 case ZFCP_ERP_FAILED :
1554 atomic_inc(&port->erp_counter);
1555 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1556 zfcp_erp_port_failed(port);
1557 break;
1558 case ZFCP_ERP_EXIT :
1559 /* nothing */
1560 break;
1561 }
1562
1563 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1564 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1565 result = ZFCP_ERP_EXIT;
1566 }
1567
1568 return result;
1569}
1570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571static int
1572zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1573{
1574 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1575
1576 switch (result) {
1577 case ZFCP_ERP_SUCCEEDED :
1578 atomic_set(&adapter->erp_counter, 0);
1579 zfcp_erp_adapter_unblock(adapter);
1580 break;
1581 case ZFCP_ERP_FAILED :
1582 atomic_inc(&adapter->erp_counter);
1583 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1584 zfcp_erp_adapter_failed(adapter);
1585 break;
1586 case ZFCP_ERP_EXIT :
1587 /* nothing */
1588 break;
1589 }
1590
1591 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1592 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1593 result = ZFCP_ERP_EXIT;
1594 }
1595
1596 return result;
1597}
1598
1599/*
1600 * function:
1601 *
1602 * purpose: remaining things in good cases,
1603 * escalation in bad cases
1604 *
1605 * returns:
1606 */
1607static int
1608zfcp_erp_strategy_followup_actions(int action,
1609 struct zfcp_adapter *adapter,
1610 struct zfcp_port *port,
1611 struct zfcp_unit *unit, int status)
1612{
1613 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1614 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1615
1616 /* initiate follow-up actions depending on success of finished action */
1617 switch (action) {
1618
1619 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1620 if (status == ZFCP_ERP_SUCCEEDED)
1621 zfcp_erp_port_reopen_all_internal(adapter, 0);
1622 else
1623 zfcp_erp_adapter_reopen_internal(adapter, 0);
1624 break;
1625
1626 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1627 if (status == ZFCP_ERP_SUCCEEDED)
1628 zfcp_erp_port_reopen_internal(port, 0);
1629 else
1630 zfcp_erp_adapter_reopen_internal(adapter, 0);
1631 break;
1632
1633 case ZFCP_ERP_ACTION_REOPEN_PORT:
1634 if (status == ZFCP_ERP_SUCCEEDED)
1635 zfcp_erp_unit_reopen_all_internal(port, 0);
1636 else
1637 zfcp_erp_port_forced_reopen_internal(port, 0);
1638 break;
1639
1640 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1641 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1642 else
1643 zfcp_erp_port_reopen_internal(unit->port, 0);
1644 break;
1645 }
1646
1647 return 0;
1648}
1649
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650static int
1651zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1652{
1653 unsigned long flags;
1654
1655 read_lock_irqsave(&zfcp_data.config_lock, flags);
1656 read_lock(&adapter->erp_lock);
1657 if (list_empty(&adapter->erp_ready_head) &&
1658 list_empty(&adapter->erp_running_head)) {
1659 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1660 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1661 &adapter->status);
1662 wake_up(&adapter->erp_done_wqh);
1663 } else
1664 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1665 read_unlock(&adapter->erp_lock);
1666 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1667
1668 return 0;
1669}
1670
1671/**
1672 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1673 * @adapter: adapter for which to wait for completion of its error recovery
1674 * Return: 0
1675 */
1676int
1677zfcp_erp_wait(struct zfcp_adapter *adapter)
1678{
1679 int retval = 0;
1680
1681 wait_event(adapter->erp_done_wqh,
1682 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1683 &adapter->status));
1684
1685 return retval;
1686}
1687
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688void
1689zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1690 u32 mask, int set_or_clear)
1691{
1692 struct zfcp_port *port;
1693 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1694
1695 if (set_or_clear == ZFCP_SET) {
1696 atomic_set_mask(mask, &adapter->status);
1697 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1698 } else {
1699 atomic_clear_mask(mask, &adapter->status);
1700 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1701 atomic_set(&adapter->erp_counter, 0);
1702 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1703 }
1704 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1705
1706 /* Deal with all underlying devices, only pass common_mask */
1707 if (common_mask)
1708 list_for_each_entry(port, &adapter->port_list_head, list)
1709 zfcp_erp_modify_port_status(port, common_mask,
1710 set_or_clear);
1711}
1712
1713/*
1714 * function: zfcp_erp_modify_port_status
1715 *
1716 * purpose: sets the port and all underlying devices to ERP_FAILED
1717 *
1718 */
1719void
1720zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1721{
1722 struct zfcp_unit *unit;
1723 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1724
1725 if (set_or_clear == ZFCP_SET) {
1726 atomic_set_mask(mask, &port->status);
1727 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1728 } else {
1729 atomic_clear_mask(mask, &port->status);
1730 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1731 atomic_set(&port->erp_counter, 0);
1732 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1733 }
1734 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1735 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1736
1737 /* Modify status of all underlying devices, only pass common mask */
1738 if (common_mask)
1739 list_for_each_entry(unit, &port->unit_list_head, list)
1740 zfcp_erp_modify_unit_status(unit, common_mask,
1741 set_or_clear);
1742}
1743
1744/*
1745 * function: zfcp_erp_modify_unit_status
1746 *
1747 * purpose: sets the unit to ERP_FAILED
1748 *
1749 */
1750void
1751zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1752{
1753 if (set_or_clear == ZFCP_SET) {
1754 atomic_set_mask(mask, &unit->status);
1755 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1756 } else {
1757 atomic_clear_mask(mask, &unit->status);
1758 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1759 atomic_set(&unit->erp_counter, 0);
1760 }
1761 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1762 }
1763 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1764 sizeof (fcp_lun_t));
1765 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1766}
1767
1768/*
1769 * function:
1770 *
1771 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1772 * used to ensure the correct locking
1773 *
Andreas Mohrd6e05ed2006-06-26 18:35:02 +02001774 * returns: 0 - initiated action successfully
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * <0 - failed to initiate action
1776 */
1777int
1778zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1779{
1780 int retval;
1781 unsigned long flags;
1782
1783 read_lock_irqsave(&zfcp_data.config_lock, flags);
1784 write_lock(&adapter->erp_lock);
1785 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1786 write_unlock(&adapter->erp_lock);
1787 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1788
1789 return retval;
1790}
1791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792static int
1793zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1794{
1795 int retval = 0;
1796 struct zfcp_port *port;
1797
1798 list_for_each_entry(port, &adapter->port_list_head, list)
1799 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1800 zfcp_erp_port_reopen_internal(port, clear_mask);
1801
1802 return retval;
1803}
1804
1805/*
1806 * function:
1807 *
1808 * purpose:
1809 *
1810 * returns: FIXME
1811 */
1812static int
1813zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1814{
1815 int retval = 0;
1816 struct zfcp_unit *unit;
1817
1818 list_for_each_entry(unit, &port->unit_list_head, list)
1819 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1820
1821 return retval;
1822}
1823
1824/*
1825 * function:
1826 *
1827 * purpose: this routine executes the 'Reopen Adapter' action
1828 * (the entire action is processed synchronously, since
1829 * there are no actions which might be run concurrently
1830 * per definition)
1831 *
1832 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1833 * ZFCP_ERP_FAILED - action finished unsuccessfully
1834 */
1835static int
1836zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1837{
1838 int retval;
1839 struct zfcp_adapter *adapter = erp_action->adapter;
1840
1841 retval = zfcp_erp_adapter_strategy_close(erp_action);
1842 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1843 retval = ZFCP_ERP_EXIT;
1844 else
1845 retval = zfcp_erp_adapter_strategy_open(erp_action);
1846
1847 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1848 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1849 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1850
1851 if (retval == ZFCP_ERP_FAILED) {
1852 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1853 "to recover itself\n",
1854 zfcp_get_busid_by_adapter(adapter));
1855 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1856 }
1857
1858 return retval;
1859}
1860
1861/*
1862 * function:
1863 *
1864 * purpose:
1865 *
1866 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1867 * ZFCP_ERP_FAILED - action finished unsuccessfully
1868 */
1869static int
1870zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1871{
1872 int retval;
1873
1874 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1875 &erp_action->adapter->status);
1876 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1877 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1878 &erp_action->adapter->status);
1879
1880 return retval;
1881}
1882
1883/*
1884 * function:
1885 *
1886 * purpose:
1887 *
1888 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1889 * ZFCP_ERP_FAILED - action finished unsuccessfully
1890 */
1891static int
1892zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1893{
1894 int retval;
1895
1896 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1897 &erp_action->adapter->status);
1898 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1899 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
1900 &erp_action->adapter->status);
1901
1902 return retval;
1903}
1904
1905/*
1906 * function: zfcp_register_adapter
1907 *
1908 * purpose: allocate the irq associated with this devno and register
1909 * the FSF adapter with the SCSI stack
1910 *
1911 * returns:
1912 */
1913static int
1914zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
1915{
1916 int retval = ZFCP_ERP_SUCCEEDED;
1917
1918 if (close)
1919 goto close_only;
1920
1921 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
1922 if (retval != ZFCP_ERP_SUCCEEDED)
1923 goto failed_qdio;
1924
1925 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
1926 if (retval != ZFCP_ERP_SUCCEEDED)
1927 goto failed_openfcp;
1928
1929 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
1930 goto out;
1931
1932 close_only:
1933 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
1934 &erp_action->adapter->status);
1935
1936 failed_openfcp:
Andreas Herrmann2abbe862006-09-18 22:29:56 +02001937 zfcp_close_fsf(erp_action->adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 failed_qdio:
1939 out:
1940 return retval;
1941}
1942
1943/*
1944 * function: zfcp_qdio_init
1945 *
1946 * purpose: setup QDIO operation for specified adapter
1947 *
1948 * returns: 0 - successful setup
1949 * !0 - failed setup
1950 */
1951int
1952zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
1953{
1954 int retval;
1955 int i;
1956 volatile struct qdio_buffer_element *sbale;
1957 struct zfcp_adapter *adapter = erp_action->adapter;
1958
1959 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
1960 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
1961 "adapter %s\n",
1962 zfcp_get_busid_by_adapter(adapter));
1963 goto failed_sanity;
1964 }
1965
1966 if (qdio_establish(&adapter->qdio_init_data) != 0) {
1967 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
1968 "on adapter %s\n",
1969 zfcp_get_busid_by_adapter(adapter));
1970 goto failed_qdio_establish;
1971 }
1972 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
1973
1974 if (qdio_activate(adapter->ccw_device, 0) != 0) {
1975 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
1976 "on adapter %s\n",
1977 zfcp_get_busid_by_adapter(adapter));
1978 goto failed_qdio_activate;
1979 }
1980 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
1981
1982 /*
1983 * put buffers into response queue,
1984 */
1985 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
1986 sbale = &(adapter->response_queue.buffer[i]->element[0]);
1987 sbale->length = 0;
1988 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
1989 sbale->addr = 0;
1990 }
1991
1992 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
1993 "queue_no=%i, index_in_queue=%i, count=%i)\n",
1994 zfcp_get_busid_by_adapter(adapter),
1995 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
1996
1997 retval = do_QDIO(adapter->ccw_device,
1998 QDIO_FLAG_SYNC_INPUT,
1999 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2000
2001 if (retval) {
2002 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2003 retval);
2004 goto failed_do_qdio;
2005 } else {
2006 adapter->response_queue.free_index = 0;
2007 atomic_set(&adapter->response_queue.free_count, 0);
2008 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2009 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2010 }
2011 /* set index of first avalable SBALS / number of available SBALS */
2012 adapter->request_queue.free_index = 0;
2013 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2014 adapter->request_queue.distance_from_int = 0;
2015
2016 /* initialize waitqueue used to wait for free SBALs in requests queue */
2017 init_waitqueue_head(&adapter->request_wq);
2018
2019 /* ok, we did it - skip all cleanups for different failures */
2020 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2021 retval = ZFCP_ERP_SUCCEEDED;
2022 goto out;
2023
2024 failed_do_qdio:
2025 /* NOP */
2026
2027 failed_qdio_activate:
2028 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2029 while (qdio_shutdown(adapter->ccw_device,
2030 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2031 msleep(1000);
2032 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2033
2034 failed_qdio_establish:
2035 failed_sanity:
2036 retval = ZFCP_ERP_FAILED;
2037
2038 out:
2039 return retval;
2040}
2041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043static int
2044zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2045{
Andreas Herrmann2448c452005-12-01 02:50:36 +01002046 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Andreas Herrmann2448c452005-12-01 02:50:36 +01002048 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2049 if (retval == ZFCP_ERP_FAILED)
2050 return ZFCP_ERP_FAILED;
2051
2052 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2053 if (retval == ZFCP_ERP_FAILED)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002054 return ZFCP_ERP_FAILED;
2055
2056 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059static int
2060zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2061{
2062 int retval = ZFCP_ERP_SUCCEEDED;
2063 int retries;
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002064 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 struct zfcp_adapter *adapter = erp_action->adapter;
2066
2067 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002069 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2071 &adapter->status);
2072 ZFCP_LOG_DEBUG("Doing exchange config data\n");
Heiko Carstens9f09c542006-07-03 17:32:20 -07002073 write_lock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07002075 write_unlock_irq(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 if (zfcp_fsf_exchange_config_data(erp_action)) {
2077 retval = ZFCP_ERP_FAILED;
2078 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2079 ZFCP_LOG_INFO("error: initiation of exchange of "
2080 "configuration data failed for "
2081 "adapter %s\n",
2082 zfcp_get_busid_by_adapter(adapter));
2083 break;
2084 }
2085 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2086 ZFCP_LOG_DEBUG("Xchange underway\n");
2087
2088 /*
2089 * Why this works:
2090 * Both the normal completion handler as well as the timeout
2091 * handler will do an 'up' when the 'exchange config data'
2092 * request completes or times out. Thus, the signal to go on
2093 * won't be lost utilizing this semaphore.
2094 * Furthermore, this 'adapter_reopen' action is
2095 * guaranteed to be the only action being there (highest action
2096 * which prevents other actions from being created).
2097 * Resulting from that, the wake signal recognized here
2098 * _must_ be the one belonging to the 'exchange config
2099 * data' request.
2100 */
2101 down(&adapter->erp_ready_sem);
2102 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2103 ZFCP_LOG_INFO("error: exchange of configuration data "
2104 "for adapter %s timed out\n",
2105 zfcp_get_busid_by_adapter(adapter));
2106 break;
2107 }
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002108
2109 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2110 &adapter->status))
2111 break;
2112
2113 ZFCP_LOG_DEBUG("host connection still initialising... "
2114 "waiting and retrying...\n");
2115 /* sleep a little bit before retry */
2116 msleep(jiffies_to_msecs(sleep));
2117 sleep *= 2;
2118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2121 &adapter->status)) {
2122 ZFCP_LOG_INFO("error: exchange of configuration data for "
2123 "adapter %s failed\n",
2124 zfcp_get_busid_by_adapter(adapter));
2125 retval = ZFCP_ERP_FAILED;
2126 }
2127
2128 return retval;
2129}
2130
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002131static int
2132zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2133{
Andreas Herrmann2448c452005-12-01 02:50:36 +01002134 int ret;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002135 struct zfcp_adapter *adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002136
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002137 adapter = erp_action->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002138 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2139
Heiko Carstens9f09c542006-07-03 17:32:20 -07002140 write_lock_irq(&adapter->erp_lock);
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002141 zfcp_erp_action_to_running(erp_action);
Heiko Carstens9f09c542006-07-03 17:32:20 -07002142 write_unlock_irq(&adapter->erp_lock);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002143
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002144 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
2145 if (ret == -EOPNOTSUPP) {
2146 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2147 return ZFCP_ERP_SUCCEEDED;
2148 } else if (ret) {
2149 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2150 return ZFCP_ERP_FAILED;
2151 }
2152 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002153
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002154 ret = ZFCP_ERP_SUCCEEDED;
2155 down(&adapter->erp_ready_sem);
2156 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2157 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2158 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2159 ret = ZFCP_ERP_FAILED;
2160 }
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02002161
2162 /* don't treat as error for the sake of compatibility */
2163 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2164 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002165 "%s\n", zfcp_get_busid_by_adapter(adapter));
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002166
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002167 return ret;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002168}
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170static int
2171zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2172 *erp_action)
2173{
2174 int retval = ZFCP_ERP_SUCCEEDED;
2175 int temp_ret;
2176 struct zfcp_adapter *adapter = erp_action->adapter;
2177 int i;
2178
2179 adapter->status_read_failed = 0;
2180 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2181 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2182 if (temp_ret < 0) {
2183 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2184 "notification failed on adapter %s\n",
2185 zfcp_get_busid_by_adapter(adapter));
2186 retval = ZFCP_ERP_FAILED;
2187 i--;
2188 break;
2189 }
2190 }
2191
2192 return retval;
2193}
2194
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195/*
2196 * function:
2197 *
2198 * purpose: this routine executes the 'Reopen Physical Port' action
2199 *
2200 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2201 * ZFCP_ERP_SUCCEEDED - action finished successfully
2202 * ZFCP_ERP_FAILED - action finished unsuccessfully
2203 */
2204static int
2205zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2206{
2207 int retval = ZFCP_ERP_FAILED;
2208 struct zfcp_port *port = erp_action->port;
2209 struct zfcp_adapter *adapter = erp_action->adapter;
2210
2211 switch (erp_action->step) {
2212
2213 /*
2214 * FIXME:
2215 * the ULP spec. begs for waiting for oustanding commands
2216 */
2217 case ZFCP_ERP_STEP_UNINITIALIZED:
2218 zfcp_erp_port_strategy_clearstati(port);
2219 /*
2220 * it would be sufficient to test only the normal open flag
2221 * since the phys. open flag cannot be set if the normal
2222 * open flag is unset - however, this is for readabilty ...
2223 */
2224 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2225 ZFCP_STATUS_COMMON_OPEN),
2226 &port->status)) {
2227 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2228 "close physical\n", port->wwpn);
2229 retval =
2230 zfcp_erp_port_forced_strategy_close(erp_action);
2231 } else
2232 retval = ZFCP_ERP_FAILED;
2233 break;
2234
2235 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2236 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2237 &port->status)) {
2238 ZFCP_LOG_DEBUG("close physical failed for port "
2239 "0x%016Lx\n", port->wwpn);
2240 retval = ZFCP_ERP_FAILED;
2241 } else
2242 retval = ZFCP_ERP_SUCCEEDED;
2243 break;
2244 }
2245
2246 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2247 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2248 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2249 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2250
2251 return retval;
2252}
2253
2254/*
2255 * function:
2256 *
2257 * purpose: this routine executes the 'Reopen Port' action
2258 *
2259 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2260 * ZFCP_ERP_SUCCEEDED - action finished successfully
2261 * ZFCP_ERP_FAILED - action finished unsuccessfully
2262 */
2263static int
2264zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2265{
2266 int retval = ZFCP_ERP_FAILED;
2267 struct zfcp_port *port = erp_action->port;
2268 struct zfcp_adapter *adapter = erp_action->adapter;
2269
2270 switch (erp_action->step) {
2271
2272 /*
2273 * FIXME:
2274 * the ULP spec. begs for waiting for oustanding commands
2275 */
2276 case ZFCP_ERP_STEP_UNINITIALIZED:
2277 zfcp_erp_port_strategy_clearstati(port);
2278 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2279 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2280 "close\n", port->wwpn);
2281 retval = zfcp_erp_port_strategy_close(erp_action);
2282 goto out;
2283 } /* else it's already closed, open it */
2284 break;
2285
2286 case ZFCP_ERP_STEP_PORT_CLOSING:
2287 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2288 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2289 port->wwpn);
2290 retval = ZFCP_ERP_FAILED;
2291 goto out;
2292 } /* else it's closed now, open it */
2293 break;
2294 }
2295 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2296 retval = ZFCP_ERP_EXIT;
2297 else
2298 retval = zfcp_erp_port_strategy_open(erp_action);
2299
2300 out:
2301 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2302 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2303 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2304 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2305
2306 return retval;
2307}
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309static int
2310zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2311{
2312 int retval;
2313
2314 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2315 &erp_action->port->status))
2316 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2317 else
2318 retval = zfcp_erp_port_strategy_open_common(erp_action);
2319
2320 return retval;
2321}
2322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323static int
2324zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2325{
2326 int retval = 0;
2327 struct zfcp_adapter *adapter = erp_action->adapter;
2328 struct zfcp_port *port = erp_action->port;
2329
2330 switch (erp_action->step) {
2331
2332 case ZFCP_ERP_STEP_UNINITIALIZED:
2333 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2334 case ZFCP_ERP_STEP_PORT_CLOSING:
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002335 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
6f71d9b2005-04-10 23:04:28 -05002336 if (port->wwpn != adapter->peer_wwpn) {
2337 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2338 "on adapter %s.\nPeer WWPN "
2339 "0x%016Lx does not match\n",
2340 port->wwpn,
2341 zfcp_get_busid_by_adapter(adapter),
2342 adapter->peer_wwpn);
2343 zfcp_erp_port_failed(port);
2344 retval = ZFCP_ERP_FAILED;
2345 break;
2346 }
2347 port->d_id = adapter->peer_d_id;
2348 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2349 retval = zfcp_erp_port_strategy_open_port(erp_action);
2350 break;
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (!(adapter->nameserver_port)) {
2353 retval = zfcp_nameserver_enqueue(adapter);
2354 if (retval != 0) {
2355 ZFCP_LOG_NORMAL("error: nameserver port "
2356 "unavailable for adapter %s\n",
2357 zfcp_get_busid_by_adapter(adapter));
2358 retval = ZFCP_ERP_FAILED;
2359 break;
2360 }
2361 }
2362 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2363 &adapter->nameserver_port->status)) {
2364 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2365 "nameserver port\n");
2366 /* nameserver port may live again */
2367 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2368 &adapter->nameserver_port->status);
2369 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2370 >= 0) {
2371 erp_action->step =
2372 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2373 retval = ZFCP_ERP_CONTINUES;
2374 } else
2375 retval = ZFCP_ERP_FAILED;
2376 break;
2377 }
2378 /* else nameserver port is already open, fall through */
2379 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2380 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2381 &adapter->nameserver_port->status)) {
2382 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2383 retval = ZFCP_ERP_FAILED;
2384 } else {
2385 ZFCP_LOG_DEBUG("nameserver port is open -> "
2386 "nameserver look-up for port 0x%016Lx\n",
2387 port->wwpn);
2388 retval = zfcp_erp_port_strategy_open_common_lookup
2389 (erp_action);
2390 }
2391 break;
2392
2393 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2394 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2395 if (atomic_test_mask
2396 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2397 ZFCP_LOG_DEBUG("nameserver look-up failed "
2398 "for port 0x%016Lx "
2399 "(misconfigured WWPN?)\n",
2400 port->wwpn);
2401 zfcp_erp_port_failed(port);
2402 retval = ZFCP_ERP_EXIT;
2403 } else {
2404 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2405 "port 0x%016Lx\n", port->wwpn);
2406 retval = ZFCP_ERP_FAILED;
2407 }
2408 } else {
2409 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2410 "trying open\n", port->wwpn, port->d_id);
2411 retval = zfcp_erp_port_strategy_open_port(erp_action);
2412 }
2413 break;
2414
2415 case ZFCP_ERP_STEP_PORT_OPENING:
2416 /* D_ID might have changed during open */
2417 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2418 ZFCP_STATUS_PORT_DID_DID),
2419 &port->status)) {
2420 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2421 retval = ZFCP_ERP_SUCCEEDED;
2422 } else {
2423 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2424 port->wwpn);
2425 retval = ZFCP_ERP_FAILED;
2426 }
2427 break;
2428
2429 default:
2430 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2431 erp_action->step);
2432 retval = ZFCP_ERP_FAILED;
2433 }
2434
2435 return retval;
2436}
2437
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438static int
2439zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2440{
2441 int retval;
2442 struct zfcp_port *port = erp_action->port;
2443
2444 switch (erp_action->step) {
2445
2446 case ZFCP_ERP_STEP_UNINITIALIZED:
2447 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2448 case ZFCP_ERP_STEP_PORT_CLOSING:
2449 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2450 port->wwpn, port->d_id);
2451 retval = zfcp_erp_port_strategy_open_port(erp_action);
2452 break;
2453
2454 case ZFCP_ERP_STEP_PORT_OPENING:
2455 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2456 ZFCP_LOG_DEBUG("WKA port is open\n");
2457 retval = ZFCP_ERP_SUCCEEDED;
2458 } else {
2459 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2460 retval = ZFCP_ERP_FAILED;
2461 }
2462 /* this is needed anyway (dont care for retval of wakeup) */
2463 ZFCP_LOG_DEBUG("continue other open port operations\n");
2464 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2465 break;
2466
2467 default:
2468 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2469 erp_action->step);
2470 retval = ZFCP_ERP_FAILED;
2471 }
2472
2473 return retval;
2474}
2475
2476/*
2477 * function:
2478 *
2479 * purpose: makes the erp thread continue with reopen (physical) port
2480 * actions which have been paused until the name server port
2481 * is opened (or failed)
2482 *
2483 * returns: 0 (a kind of void retval, its not used)
2484 */
2485static int
2486zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2487 *ns_erp_action)
2488{
2489 int retval = 0;
2490 unsigned long flags;
2491 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2492 struct zfcp_erp_action *erp_action, *tmp;
2493
2494 read_lock_irqsave(&adapter->erp_lock, flags);
2495 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2496 list) {
2497 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2498 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2499 sizeof (wwn_t));
2500 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2501 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2502 debug_event(adapter->erp_dbf, 3,
2503 &erp_action->port->wwpn, sizeof (wwn_t));
2504 if (atomic_test_mask(
2505 ZFCP_STATUS_COMMON_ERP_FAILED,
2506 &adapter->nameserver_port->status))
2507 zfcp_erp_port_failed(erp_action->port);
2508 zfcp_erp_action_ready(erp_action);
2509 }
2510 }
2511 read_unlock_irqrestore(&adapter->erp_lock, flags);
2512
2513 return retval;
2514}
2515
2516/*
2517 * function:
2518 *
2519 * purpose:
2520 *
2521 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2522 * ZFCP_ERP_FAILED - action finished unsuccessfully
2523 */
2524static int
2525zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2526{
2527 int retval;
2528 struct zfcp_adapter *adapter = erp_action->adapter;
2529 struct zfcp_port *port = erp_action->port;
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 retval = zfcp_fsf_close_physical_port(erp_action);
2532 if (retval == -ENOMEM) {
2533 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2534 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2535 retval = ZFCP_ERP_NOMEM;
2536 goto out;
2537 }
2538 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2539 if (retval != 0) {
2540 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2541 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2542 /* could not send 'open', fail */
2543 retval = ZFCP_ERP_FAILED;
2544 goto out;
2545 }
2546 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2547 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2548 retval = ZFCP_ERP_CONTINUES;
2549 out:
2550 return retval;
2551}
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553static int
2554zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2555{
2556 int retval = 0;
2557 struct zfcp_adapter *adapter = port->adapter;
2558
2559 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2560 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2561
2562 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2563 ZFCP_STATUS_COMMON_CLOSING |
2564 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2565 ZFCP_STATUS_PORT_DID_DID |
2566 ZFCP_STATUS_PORT_PHYS_CLOSING |
2567 ZFCP_STATUS_PORT_INVALID_WWPN,
2568 &port->status);
2569 return retval;
2570}
2571
2572/*
2573 * function:
2574 *
2575 * purpose:
2576 *
2577 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2578 * ZFCP_ERP_FAILED - action finished unsuccessfully
2579 */
2580static int
2581zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2582{
2583 int retval;
2584 struct zfcp_adapter *adapter = erp_action->adapter;
2585 struct zfcp_port *port = erp_action->port;
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 retval = zfcp_fsf_close_port(erp_action);
2588 if (retval == -ENOMEM) {
2589 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2590 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2591 retval = ZFCP_ERP_NOMEM;
2592 goto out;
2593 }
2594 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2595 if (retval != 0) {
2596 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2597 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2598 /* could not send 'close', fail */
2599 retval = ZFCP_ERP_FAILED;
2600 goto out;
2601 }
2602 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2603 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2604 retval = ZFCP_ERP_CONTINUES;
2605 out:
2606 return retval;
2607}
2608
2609/*
2610 * function:
2611 *
2612 * purpose:
2613 *
2614 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2615 * ZFCP_ERP_FAILED - action finished unsuccessfully
2616 */
2617static int
2618zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2619{
2620 int retval;
2621 struct zfcp_adapter *adapter = erp_action->adapter;
2622 struct zfcp_port *port = erp_action->port;
2623
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 retval = zfcp_fsf_open_port(erp_action);
2625 if (retval == -ENOMEM) {
2626 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2627 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2628 retval = ZFCP_ERP_NOMEM;
2629 goto out;
2630 }
2631 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2632 if (retval != 0) {
2633 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2634 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2635 /* could not send 'open', fail */
2636 retval = ZFCP_ERP_FAILED;
2637 goto out;
2638 }
2639 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2640 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2641 retval = ZFCP_ERP_CONTINUES;
2642 out:
2643 return retval;
2644}
2645
2646/*
2647 * function:
2648 *
2649 * purpose:
2650 *
2651 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2652 * ZFCP_ERP_FAILED - action finished unsuccessfully
2653 */
2654static int
2655zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2656{
2657 int retval;
2658 struct zfcp_adapter *adapter = erp_action->adapter;
2659 struct zfcp_port *port = erp_action->port;
2660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 retval = zfcp_ns_gid_pn_request(erp_action);
2662 if (retval == -ENOMEM) {
2663 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2664 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2665 retval = ZFCP_ERP_NOMEM;
2666 goto out;
2667 }
2668 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2669 if (retval != 0) {
2670 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2671 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2672 /* could not send nameserver request, fail */
2673 retval = ZFCP_ERP_FAILED;
2674 goto out;
2675 }
2676 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2677 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2678 retval = ZFCP_ERP_CONTINUES;
2679 out:
2680 return retval;
2681}
2682
2683/*
2684 * function:
2685 *
2686 * purpose: this routine executes the 'Reopen Unit' action
2687 * currently no retries
2688 *
2689 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2690 * ZFCP_ERP_SUCCEEDED - action finished successfully
2691 * ZFCP_ERP_FAILED - action finished unsuccessfully
2692 */
2693static int
2694zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2695{
2696 int retval = ZFCP_ERP_FAILED;
2697 struct zfcp_unit *unit = erp_action->unit;
2698 struct zfcp_adapter *adapter = erp_action->adapter;
2699
2700 switch (erp_action->step) {
2701
2702 /*
2703 * FIXME:
2704 * the ULP spec. begs for waiting for oustanding commands
2705 */
2706 case ZFCP_ERP_STEP_UNINITIALIZED:
2707 zfcp_erp_unit_strategy_clearstati(unit);
2708 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2709 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2710 "trying close\n", unit->fcp_lun);
2711 retval = zfcp_erp_unit_strategy_close(erp_action);
2712 break;
2713 }
2714 /* else it's already closed, fall through */
2715 case ZFCP_ERP_STEP_UNIT_CLOSING:
2716 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2717 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2718 unit->fcp_lun);
2719 retval = ZFCP_ERP_FAILED;
2720 } else {
2721 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2722 retval = ZFCP_ERP_EXIT;
2723 else {
2724 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2725 "trying open\n", unit->fcp_lun);
2726 retval =
2727 zfcp_erp_unit_strategy_open(erp_action);
2728 }
2729 }
2730 break;
2731
2732 case ZFCP_ERP_STEP_UNIT_OPENING:
2733 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2734 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2735 unit->fcp_lun);
2736 retval = ZFCP_ERP_SUCCEEDED;
2737 } else {
2738 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2739 unit->fcp_lun);
2740 retval = ZFCP_ERP_FAILED;
2741 }
2742 break;
2743 }
2744
2745 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2746 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2747 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2748 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2749 return retval;
2750}
2751
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752static int
2753zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2754{
2755 int retval = 0;
2756 struct zfcp_adapter *adapter = unit->port->adapter;
2757
2758 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2759 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2760
2761 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2762 ZFCP_STATUS_COMMON_CLOSING |
2763 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2764 ZFCP_STATUS_UNIT_SHARED |
2765 ZFCP_STATUS_UNIT_READONLY,
2766 &unit->status);
2767
2768 return retval;
2769}
2770
2771/*
2772 * function:
2773 *
2774 * purpose:
2775 *
2776 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2777 * ZFCP_ERP_FAILED - action finished unsuccessfully
2778 */
2779static int
2780zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2781{
2782 int retval;
2783 struct zfcp_adapter *adapter = erp_action->adapter;
2784 struct zfcp_unit *unit = erp_action->unit;
2785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 retval = zfcp_fsf_close_unit(erp_action);
2787 if (retval == -ENOMEM) {
2788 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2789 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2790 sizeof (fcp_lun_t));
2791 retval = ZFCP_ERP_NOMEM;
2792 goto out;
2793 }
2794 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2795 if (retval != 0) {
2796 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2797 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2798 sizeof (fcp_lun_t));
2799 /* could not send 'close', fail */
2800 retval = ZFCP_ERP_FAILED;
2801 goto out;
2802 }
2803 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2804 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2805 retval = ZFCP_ERP_CONTINUES;
2806
2807 out:
2808 return retval;
2809}
2810
2811/*
2812 * function:
2813 *
2814 * purpose:
2815 *
2816 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2817 * ZFCP_ERP_FAILED - action finished unsuccessfully
2818 */
2819static int
2820zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2821{
2822 int retval;
2823 struct zfcp_adapter *adapter = erp_action->adapter;
2824 struct zfcp_unit *unit = erp_action->unit;
2825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 retval = zfcp_fsf_open_unit(erp_action);
2827 if (retval == -ENOMEM) {
2828 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2829 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2830 sizeof (fcp_lun_t));
2831 retval = ZFCP_ERP_NOMEM;
2832 goto out;
2833 }
2834 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2835 if (retval != 0) {
2836 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2837 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2838 sizeof (fcp_lun_t));
2839 /* could not send 'open', fail */
2840 retval = ZFCP_ERP_FAILED;
2841 goto out;
2842 }
2843 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2844 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2845 retval = ZFCP_ERP_CONTINUES;
2846 out:
2847 return retval;
2848}
2849
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002850void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851{
Andreas Herrmann2abbe862006-09-18 22:29:56 +02002852 BUG_ON(!fsf_req->erp_action);
2853 fsf_req->timer.function = zfcp_erp_timeout_handler;
2854 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2855 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2856 add_timer(&fsf_req->timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857}
2858
2859/*
2860 * function:
2861 *
2862 * purpose: enqueue the specified error recovery action, if needed
2863 *
2864 * returns:
2865 */
2866static int
2867zfcp_erp_action_enqueue(int action,
2868 struct zfcp_adapter *adapter,
2869 struct zfcp_port *port, struct zfcp_unit *unit)
2870{
2871 int retval = 1;
2872 struct zfcp_erp_action *erp_action = NULL;
2873 int stronger_action = 0;
2874 u32 status = 0;
2875
2876 /*
2877 * We need some rules here which check whether we really need
2878 * this action or whether we should just drop it.
2879 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2880 * 'Reopen Unit' request for an associated unit since we can't
2881 * satisfy this request now. A 'Reopen Port' action will trigger
2882 * 'Reopen Unit' actions when it completes.
2883 * Thus, there are only actions in the queue which can immediately be
2884 * executed. This makes the processing of the action queue more
2885 * efficient.
2886 */
2887
2888 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
2889 &adapter->status))
2890 return -EIO;
2891
2892 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
2893 /* check whether we really need this */
2894 switch (action) {
2895 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2896 if (atomic_test_mask
2897 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
2898 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
2899 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2900 sizeof (wwn_t));
2901 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
2902 sizeof (fcp_lun_t));
2903 goto out;
2904 }
2905 if (!atomic_test_mask
2906 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
2907 atomic_test_mask
2908 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
2909 goto out;
2910 }
2911 if (!atomic_test_mask
2912 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
2913 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
2914 unit = NULL;
2915 }
2916 /* fall through !!! */
2917
2918 case ZFCP_ERP_ACTION_REOPEN_PORT:
2919 if (atomic_test_mask
2920 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
2921 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
2922 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2923 sizeof (wwn_t));
2924 goto out;
2925 }
2926 /* fall through !!! */
2927
2928 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Andreas Herrmann3734d242005-09-13 21:47:11 +02002929 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
2930 &port->status)) {
2931 if (port->erp_action.action !=
2932 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
2933 ZFCP_LOG_INFO("dropped erp action %i (port "
2934 "0x%016Lx, action in use: %i)\n",
2935 action, port->wwpn,
2936 port->erp_action.action);
2937 debug_text_event(adapter->erp_dbf, 4,
2938 "pf_actenq_drp");
2939 } else
2940 debug_text_event(adapter->erp_dbf, 4,
2941 "pf_actenq_drpcp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 debug_event(adapter->erp_dbf, 4, &port->wwpn,
2943 sizeof (wwn_t));
2944 goto out;
2945 }
2946 if (!atomic_test_mask
2947 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
2948 atomic_test_mask
2949 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
2950 goto out;
2951 }
2952 if (!atomic_test_mask
2953 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
2954 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
2955 port = NULL;
2956 }
2957 /* fall through !!! */
2958
2959 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
2960 if (atomic_test_mask
2961 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
2962 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
2963 goto out;
2964 }
2965 break;
2966
2967 default:
2968 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
2969 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
2970 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
2971 "on adapter %s (action=%d)\n",
2972 zfcp_get_busid_by_adapter(adapter), action);
2973 goto out;
2974 }
2975
2976 /* check whether we need something stronger first */
2977 if (stronger_action) {
2978 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
2979 debug_event(adapter->erp_dbf, 4, &stronger_action,
2980 sizeof (int));
2981 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
2982 "erp action %d on adapter %s\n",
2983 stronger_action, action,
2984 zfcp_get_busid_by_adapter(adapter));
2985 action = stronger_action;
2986 }
2987
2988 /* mark adapter to have some error recovery pending */
2989 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
2990
2991 /* setup error recovery action */
2992 switch (action) {
2993
2994 case ZFCP_ERP_ACTION_REOPEN_UNIT:
2995 zfcp_unit_get(unit);
2996 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
2997 erp_action = &unit->erp_action;
2998 if (!atomic_test_mask
2999 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3000 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3001 break;
3002
3003 case ZFCP_ERP_ACTION_REOPEN_PORT:
3004 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3005 zfcp_port_get(port);
3006 zfcp_erp_action_dismiss_port(port);
3007 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3008 erp_action = &port->erp_action;
3009 if (!atomic_test_mask
3010 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3011 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3012 break;
3013
3014 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3015 zfcp_adapter_get(adapter);
3016 zfcp_erp_action_dismiss_adapter(adapter);
3017 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3018 erp_action = &adapter->erp_action;
3019 if (!atomic_test_mask
3020 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3021 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3022 break;
3023 }
3024
3025 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3026
3027 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3028 erp_action->adapter = adapter;
3029 erp_action->port = port;
3030 erp_action->unit = unit;
3031 erp_action->action = action;
3032 erp_action->status = status;
3033
3034 ++adapter->erp_total_count;
3035
3036 /* finally put it into 'ready' queue and kick erp thread */
3037 list_add(&erp_action->list, &adapter->erp_ready_head);
3038 up(&adapter->erp_ready_sem);
3039 retval = 0;
3040 out:
3041 return retval;
3042}
3043
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044static int
3045zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3046{
3047 int retval = 0;
3048 struct zfcp_adapter *adapter = erp_action->adapter;
3049
3050 --adapter->erp_total_count;
3051 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3052 --adapter->erp_low_mem_count;
3053 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3054 }
3055
3056 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3057 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3058 list_del(&erp_action->list);
3059 switch (erp_action->action) {
3060 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3061 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3062 &erp_action->unit->status);
3063 break;
3064 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3065 case ZFCP_ERP_ACTION_REOPEN_PORT:
3066 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3067 &erp_action->port->status);
3068 break;
3069 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3070 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3071 &erp_action->adapter->status);
3072 break;
3073 default:
3074 /* bug */
3075 break;
3076 }
3077 return retval;
3078}
3079
3080/**
3081 * zfcp_erp_action_cleanup
3082 *
Adrian Bunk575c9682006-01-15 02:00:17 +01003083 * Register unit with scsi stack if appropriate and fix reference counts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 * Note: Temporary units are not registered with scsi stack.
3085 */
3086static void
3087zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3088 struct zfcp_port *port, struct zfcp_unit *unit,
3089 int result)
3090{
3091 switch (action) {
3092 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3093 if ((result == ZFCP_ERP_SUCCEEDED)
3094 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3095 &unit->status))
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003096 && !unit->device
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01003097 && port->rport) {
3098 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3099 &unit->status);
3100 scsi_scan_target(&port->rport->dev, 0,
3101 port->rport->scsi_target_id,
3102 unit->scsi_lun, 0);
3103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 zfcp_unit_put(unit);
3105 break;
3106 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3107 case ZFCP_ERP_ACTION_REOPEN_PORT:
Andreas Herrmann338151e2006-05-22 18:25:56 +02003108 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3109 &port->status)) {
3110 zfcp_port_put(port);
3111 break;
3112 }
3113
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003114 if ((result == ZFCP_ERP_SUCCEEDED)
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003115 && !port->rport) {
3116 struct fc_rport_identifiers ids;
3117 ids.node_name = port->wwnn;
3118 ids.port_name = port->wwpn;
3119 ids.port_id = port->d_id;
3120 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3121 port->rport =
3122 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3123 if (!port->rport)
3124 ZFCP_LOG_NORMAL("failed registration of rport"
3125 "(adapter %s, wwpn=0x%016Lx)\n",
3126 zfcp_get_busid_by_port(port),
3127 port->wwpn);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02003128 else {
Andreas Herrmann61c41822006-02-11 01:43:55 +01003129 scsi_flush_work(adapter->scsi_host);
Ralph Wuerthner75bfc282006-05-22 18:24:33 +02003130 port->rport->maxframe_size = port->maxframe_size;
3131 port->rport->supported_classes =
3132 port->supported_classes;
3133 }
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003134 }
Andreas Herrmann338151e2006-05-22 18:25:56 +02003135 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3136 fc_remote_port_delete(port->rport);
3137 port->rport = NULL;
3138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 zfcp_port_put(port);
3140 break;
3141 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
Andreas Herrmann338151e2006-05-22 18:25:56 +02003142 if (result != ZFCP_ERP_SUCCEEDED) {
3143 struct zfcp_port *port;
3144 list_for_each_entry(port, &adapter->port_list_head, list)
3145 if (port->rport &&
3146 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3147 &port->status)) {
3148 fc_remote_port_delete(port->rport);
3149 port->rport = NULL;
3150 }
3151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 zfcp_adapter_put(adapter);
3153 break;
3154 default:
3155 break;
3156 }
3157}
3158
3159
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02003160void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 struct zfcp_port *port;
3163
3164 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3165 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3166 zfcp_erp_action_dismiss(&adapter->erp_action);
3167 else
3168 list_for_each_entry(port, &adapter->port_list_head, list)
3169 zfcp_erp_action_dismiss_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170}
3171
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02003172static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 struct zfcp_unit *unit;
3175 struct zfcp_adapter *adapter = port->adapter;
3176
3177 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3178 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3179 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3180 zfcp_erp_action_dismiss(&port->erp_action);
3181 else
3182 list_for_each_entry(unit, &port->unit_list_head, list)
3183 zfcp_erp_action_dismiss_unit(unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184}
3185
Andreas Herrmannf6c0e7a2006-08-02 11:05:52 +02003186static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 struct zfcp_adapter *adapter = unit->port->adapter;
3189
3190 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3191 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3192 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3193 zfcp_erp_action_dismiss(&unit->erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194}
3195
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196static inline void
3197zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3198{
3199 struct zfcp_adapter *adapter = erp_action->adapter;
3200
3201 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3202 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3203 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3204}
3205
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206static inline void
3207zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3208{
3209 struct zfcp_adapter *adapter = erp_action->adapter;
3210
3211 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3212 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3213 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3214}
3215
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003216void
3217zfcp_erp_port_boxed(struct zfcp_port *port)
3218{
3219 struct zfcp_adapter *adapter = port->adapter;
3220 unsigned long flags;
3221
3222 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3223 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3224 read_lock_irqsave(&zfcp_data.config_lock, flags);
3225 zfcp_erp_modify_port_status(port,
3226 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3227 ZFCP_SET);
3228 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3229 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3230}
3231
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003232void
3233zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3234{
3235 struct zfcp_adapter *adapter = unit->port->adapter;
3236
3237 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3238 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3239 zfcp_erp_modify_unit_status(unit,
3240 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3241 ZFCP_SET);
3242 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3243}
3244
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245void
3246zfcp_erp_port_access_denied(struct zfcp_port *port)
3247{
3248 struct zfcp_adapter *adapter = port->adapter;
3249 unsigned long flags;
3250
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003251 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3253 read_lock_irqsave(&zfcp_data.config_lock, flags);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003254 zfcp_erp_modify_port_status(port,
3255 ZFCP_STATUS_COMMON_ERP_FAILED |
3256 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3257 ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3259}
3260
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261void
3262zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3263{
3264 struct zfcp_adapter *adapter = unit->port->adapter;
3265
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003266 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003268 zfcp_erp_modify_unit_status(unit,
3269 ZFCP_STATUS_COMMON_ERP_FAILED |
3270 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3271 ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272}
3273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274void
3275zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3276{
3277 struct zfcp_port *port;
3278 unsigned long flags;
3279
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003280 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3281 return;
3282
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003283 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
Andreas Herrmann06506d02006-05-22 18:18:19 +02003284 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 read_lock_irqsave(&zfcp_data.config_lock, flags);
6f71d9b2005-04-10 23:04:28 -05003287 if (adapter->nameserver_port)
3288 zfcp_erp_port_access_changed(adapter->nameserver_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 list_for_each_entry(port, &adapter->port_list_head, list)
3290 if (port != adapter->nameserver_port)
3291 zfcp_erp_port_access_changed(port);
3292 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3293}
3294
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295void
3296zfcp_erp_port_access_changed(struct zfcp_port *port)
3297{
3298 struct zfcp_adapter *adapter = port->adapter;
3299 struct zfcp_unit *unit;
3300
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003301 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3303
3304 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003305 &port->status) &&
3306 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 &port->status)) {
3308 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3309 list_for_each_entry(unit, &port->unit_list_head, list)
3310 zfcp_erp_unit_access_changed(unit);
3311 return;
3312 }
3313
3314 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3315 "(due to ACT update)\n",
3316 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3317 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3318 ZFCP_LOG_NORMAL("failed reopen of port"
3319 "(adapter %s, wwpn=0x%016Lx)\n",
3320 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3321}
3322
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323void
3324zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3325{
3326 struct zfcp_adapter *adapter = unit->port->adapter;
3327
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003328 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3330
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003331 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3332 &unit->status) &&
3333 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3334 &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 return;
3336
3337 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3338 " on adapter %s (due to ACT update)\n",
3339 unit->fcp_lun, unit->port->wwpn,
3340 zfcp_get_busid_by_adapter(adapter));
3341 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3342 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3343 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3344 zfcp_get_busid_by_adapter(adapter),
3345 unit->port->wwpn, unit->fcp_lun);
3346}
3347
3348#undef ZFCP_LOG_AREA