blob: e2dac3dc3fcddbf2d5c20bdd618e25bedf3f4595 [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 *);
67static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
68static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
69static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
70static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
71static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
72static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +020073static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static int zfcp_erp_adapter_strategy_open_fsf_statusread(
75 struct zfcp_erp_action *);
76
77static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
78static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
79
80static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
81static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
82static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
83static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
84static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
85static int zfcp_erp_port_strategy_open_nameserver_wakeup(
86 struct zfcp_erp_action *);
87static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
88static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
89static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
90
91static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
92static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
93static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
94static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
95
96static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
97static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
98static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
99static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
100
101static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
102 struct zfcp_port *, struct zfcp_unit *);
103static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
104static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
105 struct zfcp_port *, struct zfcp_unit *,
106 int);
107
108static void zfcp_erp_action_ready(struct zfcp_erp_action *);
109static int zfcp_erp_action_exists(struct zfcp_erp_action *);
110
111static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
112static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
113
114static void zfcp_erp_memwait_handler(unsigned long);
115static void zfcp_erp_timeout_handler(unsigned long);
116static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
117
118/**
119 * zfcp_fsf_request_timeout_handler - called if a request timed out
120 * @data: pointer to adapter for handler function
121 *
122 * This function needs to be called if requests (ELS, Generic Service,
123 * or SCSI commands) exceed a certain time limit. The assumption is
124 * that after the time limit the adapter get stuck. So we trigger a reopen of
125 * the adapter. This should not be used for error recovery, SCSI abort
126 * commands and SCSI requests from SCSI mid-layer.
127 */
128void
129zfcp_fsf_request_timeout_handler(unsigned long data)
130{
131 struct zfcp_adapter *adapter;
132
133 adapter = (struct zfcp_adapter *) data;
134
135 zfcp_erp_adapter_reopen(adapter, 0);
136}
137
138/*
139 * function: zfcp_fsf_scsi_er_timeout_handler
140 *
141 * purpose: This function needs to be called whenever a SCSI error recovery
142 * action (abort/reset) does not return.
143 * Re-opening the adapter means that the command can be returned
144 * by zfcp (it is guarranteed that it does not return via the
145 * adapter anymore). The buffer can then be used again.
146 *
147 * returns: sod all
148 */
149void
150zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
151{
152 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
153
154 ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
155 "Restarting all operations on the adapter %s\n",
156 zfcp_get_busid_by_adapter(adapter));
157 debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
158 zfcp_erp_adapter_reopen(adapter, 0);
159
160 return;
161}
162
163/*
164 * function:
165 *
166 * purpose: called if an adapter failed,
167 * initiates adapter recovery which is done
168 * asynchronously
169 *
170 * returns: 0 - initiated action succesfully
171 * <0 - failed to initiate action
172 */
173int
174zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
175{
176 int retval;
177
178 debug_text_event(adapter->erp_dbf, 5, "a_ro");
179 ZFCP_LOG_DEBUG("reopen adapter %s\n",
180 zfcp_get_busid_by_adapter(adapter));
181
182 zfcp_erp_adapter_block(adapter, clear_mask);
183
184 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
185 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
186 zfcp_get_busid_by_adapter(adapter));
187 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
188 /* ensure propagation of failed status to new devices */
189 zfcp_erp_adapter_failed(adapter);
190 retval = -EIO;
191 goto out;
192 }
193 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
194 adapter, NULL, NULL);
195
196 out:
197 return retval;
198}
199
200/*
201 * function:
202 *
203 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
204 * used to ensure the correct locking
205 *
206 * returns: 0 - initiated action succesfully
207 * <0 - failed to initiate action
208 */
209int
210zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
211{
212 int retval;
213 unsigned long flags;
214
215 read_lock_irqsave(&zfcp_data.config_lock, flags);
216 write_lock(&adapter->erp_lock);
217 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
218 write_unlock(&adapter->erp_lock);
219 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
220
221 return retval;
222}
223
224/*
225 * function:
226 *
227 * purpose:
228 *
229 * returns:
230 */
231int
232zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
233{
234 int retval;
235
236 retval = zfcp_erp_adapter_reopen(adapter,
237 ZFCP_STATUS_COMMON_RUNNING |
238 ZFCP_STATUS_COMMON_ERP_FAILED |
239 clear_mask);
240
241 return retval;
242}
243
244/*
245 * function:
246 *
247 * purpose:
248 *
249 * returns:
250 */
251int
252zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
253{
254 int retval;
255
256 retval = zfcp_erp_port_reopen(port,
257 ZFCP_STATUS_COMMON_RUNNING |
258 ZFCP_STATUS_COMMON_ERP_FAILED |
259 clear_mask);
260
261 return retval;
262}
263
264/*
265 * function:
266 *
267 * purpose:
268 *
269 * returns:
270 */
271int
272zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
273{
274 int retval;
275
276 retval = zfcp_erp_unit_reopen(unit,
277 ZFCP_STATUS_COMMON_RUNNING |
278 ZFCP_STATUS_COMMON_ERP_FAILED |
279 clear_mask);
280
281 return retval;
282}
283
284
285/**
286 * zfcp_erp_adisc - send ADISC ELS command
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200287 * @port: port structure
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 */
289int
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200290zfcp_erp_adisc(struct zfcp_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200292 struct zfcp_adapter *adapter = port->adapter;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct zfcp_send_els *send_els;
294 struct zfcp_ls_adisc *adisc;
295 void *address = NULL;
296 int retval = 0;
297 struct timer_list *timer;
298
299 send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
300 if (send_els == NULL)
301 goto nomem;
302 memset(send_els, 0, sizeof(*send_els));
303
304 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
305 if (send_els->req == NULL)
306 goto nomem;
307 memset(send_els->req, 0, sizeof(*send_els->req));
308
309 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
310 if (send_els->resp == NULL)
311 goto nomem;
312 memset(send_els->resp, 0, sizeof(*send_els->resp));
313
314 address = (void *) get_zeroed_page(GFP_ATOMIC);
315 if (address == NULL)
316 goto nomem;
317
318 zfcp_address_to_sg(address, send_els->req);
319 address += PAGE_SIZE >> 1;
320 zfcp_address_to_sg(address, send_els->resp);
321 send_els->req_count = send_els->resp_count = 1;
322
323 send_els->adapter = adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200324 send_els->port = port;
325 send_els->d_id = port->d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 send_els->handler = zfcp_erp_adisc_handler;
327 send_els->handler_data = (unsigned long) send_els;
328
329 adisc = zfcp_sg_to_address(send_els->req);
330 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
331
332 send_els->req->length = sizeof(struct zfcp_ls_adisc);
333 send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
334
335 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
336 without FC-AL-2 capability, so we don't set it */
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200337 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
338 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
339 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
341 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
342 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200343 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
345 adisc->nport_id);
346
347 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
348 if (!timer)
349 goto nomem;
350
351 init_timer(timer);
352 timer->function = zfcp_fsf_request_timeout_handler;
353 timer->data = (unsigned long) adapter;
354 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
355 send_els->timer = timer;
356
357 retval = zfcp_fsf_send_els(send_els);
358 if (retval != 0) {
359 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200360 "0x%08x on adapter %s\n", send_els->d_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 zfcp_get_busid_by_adapter(adapter));
362 del_timer(send_els->timer);
363 goto freemem;
364 }
365
366 goto out;
367
368 nomem:
369 retval = -ENOMEM;
370 freemem:
371 if (address != NULL)
372 __free_pages(send_els->req->page, 0);
373 if (send_els != NULL) {
374 kfree(send_els->timer);
375 kfree(send_els->req);
376 kfree(send_els->resp);
377 kfree(send_els);
378 }
379 out:
380 return retval;
381}
382
383
384/**
385 * zfcp_erp_adisc_handler - handler for ADISC ELS command
386 * @data: pointer to struct zfcp_send_els
387 *
388 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
389 */
390void
391zfcp_erp_adisc_handler(unsigned long data)
392{
393 struct zfcp_send_els *send_els;
394 struct zfcp_port *port;
395 struct zfcp_adapter *adapter;
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200396 u32 d_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 struct zfcp_ls_adisc_acc *adisc;
398
399 send_els = (struct zfcp_send_els *) data;
400
401 del_timer(send_els->timer);
402
403 adapter = send_els->adapter;
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200404 port = send_els->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 d_id = send_els->d_id;
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /* request rejected or timed out */
408 if (send_els->status != 0) {
409 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
410 "force physical port reopen "
411 "(adapter %s, port d_id=0x%08x)\n",
412 zfcp_get_busid_by_adapter(adapter), d_id);
413 debug_text_event(adapter->erp_dbf, 3, "forcreop");
414 if (zfcp_erp_port_forced_reopen(port, 0))
415 ZFCP_LOG_NORMAL("failed reopen of port "
416 "(adapter %s, wwpn=0x%016Lx)\n",
417 zfcp_get_busid_by_port(port),
418 port->wwpn);
419 goto out;
420 }
421
422 adisc = zfcp_sg_to_address(send_els->resp);
423
424 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
425 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
426 "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
Andreas Herrmann13e1e1f2005-09-19 16:56:17 +0200427 d_id, fc_host_port_id(adapter->scsi_host),
428 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
429 adisc->hard_nport_id, adisc->nport_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* set wwnn for port */
432 if (port->wwnn == 0)
433 port->wwnn = adisc->wwnn;
434
435 if (port->wwpn != adisc->wwpn) {
436 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
437 "port (adapter %s, wwpn=0x%016Lx, "
438 "adisc_resp_wwpn=0x%016Lx)\n",
439 zfcp_get_busid_by_port(port),
440 port->wwpn, (wwn_t) adisc->wwpn);
441 if (zfcp_erp_port_reopen(port, 0))
442 ZFCP_LOG_NORMAL("failed reopen of port "
443 "(adapter %s, wwpn=0x%016Lx)\n",
444 zfcp_get_busid_by_port(port),
445 port->wwpn);
446 }
447
448 out:
449 zfcp_port_put(port);
450 __free_pages(send_els->req->page, 0);
451 kfree(send_els->timer);
452 kfree(send_els->req);
453 kfree(send_els->resp);
454 kfree(send_els);
455}
456
457
458/**
459 * zfcp_test_link - lightweight link test procedure
460 * @port: port to be tested
461 *
462 * Test status of a link to a remote port using the ELS command ADISC.
463 */
464int
465zfcp_test_link(struct zfcp_port *port)
466{
467 int retval;
468
469 zfcp_port_get(port);
Andreas Herrmann64b29a132005-06-13 13:18:56 +0200470 retval = zfcp_erp_adisc(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (retval != 0) {
472 zfcp_port_put(port);
473 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
474 "on adapter %s\n ", port->wwpn,
475 zfcp_get_busid_by_port(port));
476 retval = zfcp_erp_port_forced_reopen(port, 0);
477 if (retval != 0) {
478 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
479 "on adapter %s failed\n", port->wwpn,
480 zfcp_get_busid_by_port(port));
481 retval = -EPERM;
482 }
483 }
484
485 return retval;
486}
487
488
489/*
490 * function:
491 *
492 * purpose: called if a port failed to be opened normally
493 * initiates Forced Reopen recovery which is done
494 * asynchronously
495 *
496 * returns: 0 - initiated action succesfully
497 * <0 - failed to initiate action
498 */
499static int
500zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
501{
502 int retval;
503 struct zfcp_adapter *adapter = port->adapter;
504
505 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
506 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
507
508 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
509 port->wwpn, zfcp_get_busid_by_port(port));
510
511 zfcp_erp_port_block(port, clear_mask);
512
513 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
514 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
515 "on adapter %s\n", port->wwpn,
516 zfcp_get_busid_by_port(port));
517 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
518 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
519 retval = -EIO;
520 goto out;
521 }
522
523 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
524 port->adapter, port, NULL);
525
526 out:
527 return retval;
528}
529
530/*
531 * function:
532 *
533 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
534 * used to ensure the correct locking
535 *
536 * returns: 0 - initiated action succesfully
537 * <0 - failed to initiate action
538 */
539int
540zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
541{
542 int retval;
543 unsigned long flags;
544 struct zfcp_adapter *adapter;
545
546 adapter = port->adapter;
547 read_lock_irqsave(&zfcp_data.config_lock, flags);
548 write_lock(&adapter->erp_lock);
549 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
550 write_unlock(&adapter->erp_lock);
551 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
552
553 return retval;
554}
555
556/*
557 * function:
558 *
559 * purpose: called if a port is to be opened
560 * initiates Reopen recovery which is done
561 * asynchronously
562 *
563 * returns: 0 - initiated action succesfully
564 * <0 - failed to initiate action
565 */
566static int
567zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
568{
569 int retval;
570 struct zfcp_adapter *adapter = port->adapter;
571
572 debug_text_event(adapter->erp_dbf, 5, "p_ro");
573 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
574
575 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
576 port->wwpn, zfcp_get_busid_by_port(port));
577
578 zfcp_erp_port_block(port, clear_mask);
579
580 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
581 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
582 "on adapter %s\n", port->wwpn,
583 zfcp_get_busid_by_port(port));
584 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
585 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
586 /* ensure propagation of failed status to new devices */
587 zfcp_erp_port_failed(port);
588 retval = -EIO;
589 goto out;
590 }
591
592 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
593 port->adapter, port, NULL);
594
595 out:
596 return retval;
597}
598
599/**
600 * zfcp_erp_port_reopen - initiate reopen of a remote port
601 * @port: port to be reopened
602 * @clear_mask: specifies flags in port status to be cleared
603 * Return: 0 on success, < 0 on error
604 *
605 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
606 * correct locking. An error recovery task is initiated to do the reopen.
607 * To wait for the completion of the reopen zfcp_erp_wait should be used.
608 */
609int
610zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
611{
612 int retval;
613 unsigned long flags;
614 struct zfcp_adapter *adapter = port->adapter;
615
616 read_lock_irqsave(&zfcp_data.config_lock, flags);
617 write_lock(&adapter->erp_lock);
618 retval = zfcp_erp_port_reopen_internal(port, clear_mask);
619 write_unlock(&adapter->erp_lock);
620 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
621
622 return retval;
623}
624
625/*
626 * function:
627 *
628 * purpose: called if a unit is to be opened
629 * initiates Reopen recovery which is done
630 * asynchronously
631 *
632 * returns: 0 - initiated action succesfully
633 * <0 - failed to initiate action
634 */
635static int
636zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
637{
638 int retval;
639 struct zfcp_adapter *adapter = unit->port->adapter;
640
641 debug_text_event(adapter->erp_dbf, 5, "u_ro");
642 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
643 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
644 "on adapter %s\n", unit->fcp_lun,
645 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
646
647 zfcp_erp_unit_block(unit, clear_mask);
648
649 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
650 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
651 "on port 0x%016Lx on adapter %s\n",
652 unit->fcp_lun, unit->port->wwpn,
653 zfcp_get_busid_by_unit(unit));
654 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
655 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
656 sizeof (fcp_lun_t));
657 retval = -EIO;
658 goto out;
659 }
660
661 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
662 unit->port->adapter, unit->port, unit);
663 out:
664 return retval;
665}
666
667/**
668 * zfcp_erp_unit_reopen - initiate reopen of a unit
669 * @unit: unit to be reopened
670 * @clear_mask: specifies flags in unit status to be cleared
671 * Return: 0 on success, < 0 on error
672 *
673 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
674 * locking. An error recovery task is initiated to do the reopen.
675 * To wait for the completion of the reopen zfcp_erp_wait should be used.
676 */
677int
678zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
679{
680 int retval;
681 unsigned long flags;
682 struct zfcp_adapter *adapter;
683 struct zfcp_port *port;
684
685 port = unit->port;
686 adapter = port->adapter;
687
688 read_lock_irqsave(&zfcp_data.config_lock, flags);
689 write_lock(&adapter->erp_lock);
690 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
691 write_unlock(&adapter->erp_lock);
692 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
693
694 return retval;
695}
696
697/*
698 * function:
699 *
700 * purpose: disable I/O,
701 * return any open requests and clean them up,
702 * aim: no pending and incoming I/O
703 *
704 * returns:
705 */
706static void
707zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
708{
709 debug_text_event(adapter->erp_dbf, 6, "a_bl");
710 zfcp_erp_modify_adapter_status(adapter,
711 ZFCP_STATUS_COMMON_UNBLOCKED |
712 clear_mask, ZFCP_CLEAR);
713}
714
715/*
716 * function:
717 *
718 * purpose: enable I/O
719 *
720 * returns:
721 */
722static void
723zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
724{
725 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
726 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
727}
728
729/*
730 * function:
731 *
732 * purpose: disable I/O,
733 * return any open requests and clean them up,
734 * aim: no pending and incoming I/O
735 *
736 * returns:
737 */
738static void
739zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
740{
741 struct zfcp_adapter *adapter = port->adapter;
742
743 debug_text_event(adapter->erp_dbf, 6, "p_bl");
744 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
745 zfcp_erp_modify_port_status(port,
746 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
747 ZFCP_CLEAR);
748}
749
750/*
751 * function:
752 *
753 * purpose: enable I/O
754 *
755 * returns:
756 */
757static void
758zfcp_erp_port_unblock(struct zfcp_port *port)
759{
760 struct zfcp_adapter *adapter = port->adapter;
761
762 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
763 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
764 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
765}
766
767/*
768 * function:
769 *
770 * purpose: disable I/O,
771 * return any open requests and clean them up,
772 * aim: no pending and incoming I/O
773 *
774 * returns:
775 */
776static void
777zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
778{
779 struct zfcp_adapter *adapter = unit->port->adapter;
780
781 debug_text_event(adapter->erp_dbf, 6, "u_bl");
782 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
783 zfcp_erp_modify_unit_status(unit,
784 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
785 ZFCP_CLEAR);
786}
787
788/*
789 * function:
790 *
791 * purpose: enable I/O
792 *
793 * returns:
794 */
795static void
796zfcp_erp_unit_unblock(struct zfcp_unit *unit)
797{
798 struct zfcp_adapter *adapter = unit->port->adapter;
799
800 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
801 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
802 atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
803}
804
805/*
806 * function:
807 *
808 * purpose:
809 *
810 * returns:
811 */
812static void
813zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
814{
815 struct zfcp_adapter *adapter = erp_action->adapter;
816
817 debug_text_event(adapter->erp_dbf, 4, "a_ar");
818 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
819
820 zfcp_erp_action_to_ready(erp_action);
821 up(&adapter->erp_ready_sem);
822}
823
824/*
825 * function:
826 *
827 * purpose:
828 *
829 * returns: <0 erp_action not found in any list
830 * ZFCP_ERP_ACTION_READY erp_action is in ready list
831 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
832 *
833 * locks: erp_lock must be held
834 */
835static int
836zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
837{
838 int retval = -EINVAL;
839 struct list_head *entry;
840 struct zfcp_erp_action *entry_erp_action;
841 struct zfcp_adapter *adapter = erp_action->adapter;
842
843 /* search in running list */
844 list_for_each(entry, &adapter->erp_running_head) {
845 entry_erp_action =
846 list_entry(entry, struct zfcp_erp_action, list);
847 if (entry_erp_action == erp_action) {
848 retval = ZFCP_ERP_ACTION_RUNNING;
849 goto out;
850 }
851 }
852 /* search in ready list */
853 list_for_each(entry, &adapter->erp_ready_head) {
854 entry_erp_action =
855 list_entry(entry, struct zfcp_erp_action, list);
856 if (entry_erp_action == erp_action) {
857 retval = ZFCP_ERP_ACTION_READY;
858 goto out;
859 }
860 }
861
862 out:
863 return retval;
864}
865
866/*
867 * purpose: checks current status of action (timed out, dismissed, ...)
868 * and does appropriate preparations (dismiss fsf request, ...)
869 *
870 * locks: called under erp_lock (disabled interrupts)
871 *
872 * returns: 0
873 */
874static int
875zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
876{
877 int retval = 0;
Andreas Herrmann3734d242005-09-13 21:47:11 +0200878 struct zfcp_fsf_req *fsf_req = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 struct zfcp_adapter *adapter = erp_action->adapter;
880
881 if (erp_action->fsf_req) {
882 /* take lock to ensure that request is not being deleted meanwhile */
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200883 spin_lock(&adapter->fsf_req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /* check whether fsf req does still exist */
885 list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
886 if (fsf_req == erp_action->fsf_req)
887 break;
Andreas Herrmann3734d242005-09-13 21:47:11 +0200888 if (fsf_req && (fsf_req->erp_action == erp_action)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 /* fsf_req still exists */
890 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
891 debug_event(adapter->erp_dbf, 3, &fsf_req,
892 sizeof (unsigned long));
893 /* dismiss fsf_req of timed out or dismissed erp_action */
894 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
895 ZFCP_STATUS_ERP_TIMEDOUT)) {
896 debug_text_event(adapter->erp_dbf, 3,
897 "a_ca_disreq");
898 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
899 }
900 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
901 ZFCP_LOG_NORMAL("error: erp step timed out "
902 "(action=%d, fsf_req=%p)\n ",
903 erp_action->action,
904 erp_action->fsf_req);
905 }
906 /*
907 * If fsf_req is neither dismissed nor completed
908 * then keep it running asynchronously and don't mess
909 * with the association of erp_action and fsf_req.
910 */
911 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
912 ZFCP_STATUS_FSFREQ_DISMISSED)) {
913 /* forget about association between fsf_req
914 and erp_action */
915 fsf_req->erp_action = NULL;
916 erp_action->fsf_req = NULL;
917 }
918 } else {
919 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
920 /*
921 * even if this fsf_req has gone, forget about
922 * association between erp_action and fsf_req
923 */
924 erp_action->fsf_req = NULL;
925 }
Andreas Herrmann1db2c9c2005-06-13 13:20:35 +0200926 spin_unlock(&adapter->fsf_req_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 } else
928 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
929
930 return retval;
931}
932
933/*
934 * purpose: generic handler for asynchronous events related to erp_action events
935 * (normal completion, time-out, dismissing, retry after
936 * low memory condition)
937 *
938 * note: deletion of timer is not required (e.g. in case of a time-out),
939 * but a second try does no harm,
940 * we leave it in here to allow for greater simplification
941 *
942 * returns: 0 - there was an action to handle
943 * !0 - otherwise
944 */
945static int
946zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
947 unsigned long set_mask)
948{
949 int retval;
950 struct zfcp_adapter *adapter = erp_action->adapter;
951
952 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
953 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
954 debug_event(adapter->erp_dbf, 2, &erp_action->action,
955 sizeof (int));
956 if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
957 del_timer(&erp_action->timer);
958 erp_action->status |= set_mask;
959 zfcp_erp_action_ready(erp_action);
960 retval = 0;
961 } else {
962 /* action is ready or gone - nothing to do */
963 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
964 debug_event(adapter->erp_dbf, 3, &erp_action->action,
965 sizeof (int));
966 retval = 1;
967 }
968
969 return retval;
970}
971
972/*
973 * purpose: generic handler for asynchronous events related to erp_action
974 * events (normal completion, time-out, dismissing, retry after
975 * low memory condition)
976 *
977 * note: deletion of timer is not required (e.g. in case of a time-out),
978 * but a second try does no harm,
979 * we leave it in here to allow for greater simplification
980 *
981 * returns: 0 - there was an action to handle
982 * !0 - otherwise
983 */
984int
985zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
986 unsigned long set_mask)
987{
988 struct zfcp_adapter *adapter = erp_action->adapter;
989 unsigned long flags;
990 int retval;
991
992 write_lock_irqsave(&adapter->erp_lock, flags);
993 retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
994 write_unlock_irqrestore(&adapter->erp_lock, flags);
995
996 return retval;
997}
998
999/*
1000 * purpose: is called for erp_action which was slept waiting for
1001 * memory becoming avaliable,
1002 * will trigger that this action will be continued
1003 */
1004static void
1005zfcp_erp_memwait_handler(unsigned long data)
1006{
1007 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1008 struct zfcp_adapter *adapter = erp_action->adapter;
1009
1010 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
1011 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1012
1013 zfcp_erp_async_handler(erp_action, 0);
1014}
1015
1016/*
1017 * purpose: is called if an asynchronous erp step timed out,
1018 * action gets an appropriate flag and will be processed
1019 * accordingly
1020 */
1021static void
1022zfcp_erp_timeout_handler(unsigned long data)
1023{
1024 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
1025 struct zfcp_adapter *adapter = erp_action->adapter;
1026
1027 debug_text_event(adapter->erp_dbf, 2, "a_th");
1028 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1029
1030 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1031}
1032
1033/*
1034 * purpose: is called for an erp_action which needs to be ended
1035 * though not being done,
1036 * this is usually required if an higher is generated,
1037 * action gets an appropriate flag and will be processed
1038 * accordingly
1039 *
1040 * locks: erp_lock held (thus we need to call another handler variant)
1041 */
1042static int
1043zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1044{
1045 struct zfcp_adapter *adapter = erp_action->adapter;
1046
1047 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1048 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1049
1050 zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
1051
1052 return 0;
1053}
1054
1055int
1056zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1057{
1058 int retval = 0;
1059
1060 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1063 if (retval < 0) {
1064 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1065 "adapter %s\n",
1066 zfcp_get_busid_by_adapter(adapter));
1067 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1068 } else {
1069 wait_event(adapter->erp_thread_wqh,
1070 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1071 &adapter->status));
1072 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1073 }
1074
1075 return (retval < 0);
1076}
1077
1078/*
1079 * function:
1080 *
1081 * purpose:
1082 *
1083 * returns:
1084 *
1085 * context: process (i.e. proc-fs or rmmod/insmod)
1086 *
1087 * note: The caller of this routine ensures that the specified
1088 * adapter has been shut down and that this operation
1089 * has been completed. Thus, there are no pending erp_actions
1090 * which would need to be handled here.
1091 */
1092int
1093zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1094{
1095 int retval = 0;
1096
1097 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1098 up(&adapter->erp_ready_sem);
1099
1100 wait_event(adapter->erp_thread_wqh,
1101 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1102 &adapter->status));
1103
1104 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1105 &adapter->status);
1106
1107 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1108
1109 return retval;
1110}
1111
1112/*
1113 * purpose: is run as a kernel thread,
1114 * goes through list of error recovery actions of associated adapter
1115 * and delegates single action to execution
1116 *
1117 * returns: 0
1118 */
1119static int
1120zfcp_erp_thread(void *data)
1121{
1122 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1123 struct list_head *next;
1124 struct zfcp_erp_action *erp_action;
1125 unsigned long flags;
1126
1127 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1128 /* Block all signals */
1129 siginitsetinv(&current->blocked, 0);
1130 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1131 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1132 wake_up(&adapter->erp_thread_wqh);
1133
1134 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1135 &adapter->status)) {
1136
1137 write_lock_irqsave(&adapter->erp_lock, flags);
1138 next = adapter->erp_ready_head.prev;
1139 write_unlock_irqrestore(&adapter->erp_lock, flags);
1140
1141 if (next != &adapter->erp_ready_head) {
1142 erp_action =
1143 list_entry(next, struct zfcp_erp_action, list);
1144 /*
1145 * process action (incl. [re]moving it
1146 * from 'ready' queue)
1147 */
1148 zfcp_erp_strategy(erp_action);
1149 }
1150
1151 /*
1152 * sleep as long as there is nothing to do, i.e.
1153 * no action in 'ready' queue to be processed and
1154 * thread is not to be killed
1155 */
1156 down_interruptible(&adapter->erp_ready_sem);
1157 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1158 }
1159
1160 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1161 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1162 wake_up(&adapter->erp_thread_wqh);
1163
1164 return 0;
1165}
1166
1167/*
1168 * function:
1169 *
1170 * purpose: drives single error recovery action and schedules higher and
1171 * subordinate actions, if necessary
1172 *
1173 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1174 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1175 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1176 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1177 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1178 */
1179static int
1180zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1181{
1182 int retval = 0;
1183 struct zfcp_adapter *adapter = erp_action->adapter;
1184 struct zfcp_port *port = erp_action->port;
1185 struct zfcp_unit *unit = erp_action->unit;
1186 int action = erp_action->action;
1187 u32 status = erp_action->status;
1188 unsigned long flags;
1189
1190 /* serialise dismissing, timing out, moving, enqueueing */
1191 read_lock_irqsave(&zfcp_data.config_lock, flags);
1192 write_lock(&adapter->erp_lock);
1193
1194 /* dequeue dismissed action and leave, if required */
1195 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1196 if (retval == ZFCP_ERP_DISMISSED) {
1197 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1198 goto unlock;
1199 }
1200
1201 /*
1202 * move action to 'running' queue before processing it
1203 * (to avoid a race condition regarding moving the
1204 * action to the 'running' queue and back)
1205 */
1206 zfcp_erp_action_to_running(erp_action);
1207
1208 /*
1209 * try to process action as far as possible,
1210 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1211 * afterwards the lock is required again for the following reasons:
1212 * - dequeueing of finished action and enqueueing of
1213 * follow-up actions must be atomic so that any other
1214 * reopen-routine does not believe there is nothing to do
1215 * and that it is safe to enqueue something else,
1216 * - we want to force any control thread which is dismissing
1217 * actions to finish this before we decide about
1218 * necessary steps to be taken here further
1219 */
1220 write_unlock(&adapter->erp_lock);
1221 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1222 retval = zfcp_erp_strategy_do_action(erp_action);
1223 read_lock_irqsave(&zfcp_data.config_lock, flags);
1224 write_lock(&adapter->erp_lock);
1225
1226 /*
1227 * check for dismissed status again to avoid follow-up actions,
1228 * failing of targets and so on for dismissed actions
1229 */
1230 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1231
1232 switch (retval) {
1233 case ZFCP_ERP_DISMISSED:
1234 /* leave since this action has ridden to its ancestors */
1235 debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
1236 goto unlock;
1237 case ZFCP_ERP_NOMEM:
1238 /* no memory to continue immediately, let it sleep */
1239 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1240 ++adapter->erp_low_mem_count;
1241 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1242 }
1243 /* This condition is true if there is no memory available
1244 for any erp_action on this adapter. This implies that there
1245 are no elements in the memory pool(s) left for erp_actions.
1246 This might happen if an erp_action that used a memory pool
1247 element was timed out.
1248 */
1249 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1250 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1251 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1252 "restarting I/O on adapter %s "
1253 "to free mempool\n",
1254 zfcp_get_busid_by_adapter(adapter));
1255 zfcp_erp_adapter_reopen_internal(adapter, 0);
1256 } else {
1257 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1258 retval = zfcp_erp_strategy_memwait(erp_action);
1259 }
1260 goto unlock;
1261 case ZFCP_ERP_CONTINUES:
1262 /* leave since this action runs asynchronously */
1263 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1264 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1265 --adapter->erp_low_mem_count;
1266 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1267 }
1268 goto unlock;
1269 }
1270 /* ok, finished action (whatever its result is) */
1271
1272 /* check for unrecoverable targets */
1273 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1274
1275 /* action must be dequeued (here to allow for further ones) */
1276 zfcp_erp_action_dequeue(erp_action);
1277
1278 /*
1279 * put this target through the erp mill again if someone has
1280 * requested to change the status of a target being online
1281 * to offline or the other way around
1282 * (old retval is preserved if nothing has to be done here)
1283 */
1284 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1285 port, unit, retval);
1286
1287 /*
1288 * leave if target is in permanent error state or if
1289 * action is repeated in order to process state change
1290 */
1291 if (retval == ZFCP_ERP_EXIT) {
1292 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1293 goto unlock;
1294 }
1295
1296 /* trigger follow up actions */
1297 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1298
1299 unlock:
1300 write_unlock(&adapter->erp_lock);
1301 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1302
1303 if (retval != ZFCP_ERP_CONTINUES)
1304 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1305
1306 /*
1307 * a few tasks remain when the erp queues are empty
1308 * (don't do that if the last action evaluated was dismissed
1309 * since this clearly indicates that there is more to come) :
1310 * - close the name server port if it is open yet
1311 * (enqueues another [probably] final action)
1312 * - otherwise, wake up whoever wants to be woken when we are
1313 * done with erp
1314 */
1315 if (retval != ZFCP_ERP_DISMISSED)
1316 zfcp_erp_strategy_check_queues(adapter);
1317
1318 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1319
1320 return retval;
1321}
1322
1323/*
1324 * function:
1325 *
1326 * purpose:
1327 *
1328 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1329 * retval - otherwise
1330 */
1331static int
1332zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1333{
1334 struct zfcp_adapter *adapter = erp_action->adapter;
1335
1336 zfcp_erp_strategy_check_fsfreq(erp_action);
1337
1338 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1339 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1340 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1341 zfcp_erp_action_dequeue(erp_action);
1342 retval = ZFCP_ERP_DISMISSED;
1343 } else
1344 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1345
1346 return retval;
1347}
1348
1349/*
1350 * function:
1351 *
1352 * purpose:
1353 *
1354 * returns:
1355 */
1356static int
1357zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1358{
1359 int retval = ZFCP_ERP_FAILED;
1360 struct zfcp_adapter *adapter = erp_action->adapter;
1361
1362 /*
1363 * try to execute/continue action as far as possible,
1364 * note: no lock in subsequent strategy routines
1365 * (this allows these routine to call schedule, e.g.
1366 * kmalloc with such flags or qdio_initialize & friends)
1367 * Note: in case of timeout, the seperate strategies will fail
1368 * anyhow. No need for a special action. Even worse, a nameserver
1369 * failure would not wake up waiting ports without the call.
1370 */
1371 switch (erp_action->action) {
1372
1373 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1374 retval = zfcp_erp_adapter_strategy(erp_action);
1375 break;
1376
1377 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1378 retval = zfcp_erp_port_forced_strategy(erp_action);
1379 break;
1380
1381 case ZFCP_ERP_ACTION_REOPEN_PORT:
1382 retval = zfcp_erp_port_strategy(erp_action);
1383 break;
1384
1385 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1386 retval = zfcp_erp_unit_strategy(erp_action);
1387 break;
1388
1389 default:
1390 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1391 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1392 sizeof (int));
1393 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1394 "adapter %s (action=%d)\n",
1395 zfcp_get_busid_by_adapter(erp_action->adapter),
1396 erp_action->action);
1397 }
1398
1399 return retval;
1400}
1401
1402/*
1403 * function:
1404 *
1405 * purpose: triggers retry of this action after a certain amount of time
1406 * by means of timer provided by erp_action
1407 *
1408 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1409 */
1410static int
1411zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1412{
1413 int retval = ZFCP_ERP_CONTINUES;
1414 struct zfcp_adapter *adapter = erp_action->adapter;
1415
1416 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1417 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1418 init_timer(&erp_action->timer);
1419 erp_action->timer.function = zfcp_erp_memwait_handler;
1420 erp_action->timer.data = (unsigned long) erp_action;
1421 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1422 add_timer(&erp_action->timer);
1423
1424 return retval;
1425}
1426
1427/*
1428 * function: zfcp_erp_adapter_failed
1429 *
1430 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1431 *
1432 */
1433void
1434zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
1435{
1436 zfcp_erp_modify_adapter_status(adapter,
1437 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1438 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1439 zfcp_get_busid_by_adapter(adapter));
1440 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1441}
1442
1443/*
1444 * function: zfcp_erp_port_failed
1445 *
1446 * purpose: sets the port and all underlying devices to ERP_FAILED
1447 *
1448 */
1449void
1450zfcp_erp_port_failed(struct zfcp_port *port)
1451{
1452 zfcp_erp_modify_port_status(port,
1453 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1454
1455 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1456 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1457 "port d_id=0x%08x)\n",
1458 zfcp_get_busid_by_port(port), port->d_id);
1459 else
1460 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1461 zfcp_get_busid_by_port(port), port->wwpn);
1462
1463 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1464 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1465}
1466
1467/*
1468 * function: zfcp_erp_unit_failed
1469 *
1470 * purpose: sets the unit to ERP_FAILED
1471 *
1472 */
1473void
1474zfcp_erp_unit_failed(struct zfcp_unit *unit)
1475{
1476 zfcp_erp_modify_unit_status(unit,
1477 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1478
1479 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1480 " on adapter %s\n", unit->fcp_lun,
1481 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1482 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1483 debug_event(unit->port->adapter->erp_dbf, 2,
1484 &unit->fcp_lun, sizeof (fcp_lun_t));
1485}
1486
1487/*
1488 * function: zfcp_erp_strategy_check_target
1489 *
1490 * purpose: increments the erp action count on the device currently in
1491 * recovery if the action failed or resets the count in case of
1492 * success. If a maximum count is exceeded the device is marked
1493 * as ERP_FAILED.
1494 * The 'blocked' state of a target which has been recovered
1495 * successfully is reset.
1496 *
1497 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1498 * ZFCP_ERP_SUCCEEDED - action finished successfully
1499 * ZFCP_ERP_EXIT - action failed and will not continue
1500 */
1501static int
1502zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1503{
1504 struct zfcp_adapter *adapter = erp_action->adapter;
1505 struct zfcp_port *port = erp_action->port;
1506 struct zfcp_unit *unit = erp_action->unit;
1507
1508 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1509 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1510 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1511
1512 switch (erp_action->action) {
1513
1514 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1515 result = zfcp_erp_strategy_check_unit(unit, result);
1516 break;
1517
1518 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1519 case ZFCP_ERP_ACTION_REOPEN_PORT:
1520 result = zfcp_erp_strategy_check_port(port, result);
1521 break;
1522
1523 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1524 result = zfcp_erp_strategy_check_adapter(adapter, result);
1525 break;
1526 }
1527
1528 return result;
1529}
1530
1531/*
1532 * function:
1533 *
1534 * purpose:
1535 *
1536 * returns:
1537 */
1538static int
1539zfcp_erp_strategy_statechange(int action,
1540 u32 status,
1541 struct zfcp_adapter *adapter,
1542 struct zfcp_port *port,
1543 struct zfcp_unit *unit, int retval)
1544{
1545 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1546 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1547
1548 switch (action) {
1549
1550 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1551 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1552 status)) {
1553 zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
1554 retval = ZFCP_ERP_EXIT;
1555 }
1556 break;
1557
1558 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1559 case ZFCP_ERP_ACTION_REOPEN_PORT:
1560 if (zfcp_erp_strategy_statechange_detected(&port->status,
1561 status)) {
1562 zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
1563 retval = ZFCP_ERP_EXIT;
1564 }
1565 break;
1566
1567 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1568 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1569 status)) {
1570 zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
1571 retval = ZFCP_ERP_EXIT;
1572 }
1573 break;
1574 }
1575
1576 return retval;
1577}
1578
1579/*
1580 * function:
1581 *
1582 * purpose:
1583 *
1584 * returns:
1585 */
1586static inline int
1587zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1588{
1589 return
1590 /* take it online */
1591 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1592 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1593 /* take it offline */
1594 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1595 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1596}
1597
1598/*
1599 * function:
1600 *
1601 * purpose:
1602 *
1603 * returns:
1604 */
1605static int
1606zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1607{
1608 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1609 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1610 sizeof (fcp_lun_t));
1611
1612 switch (result) {
1613 case ZFCP_ERP_SUCCEEDED :
1614 atomic_set(&unit->erp_counter, 0);
1615 zfcp_erp_unit_unblock(unit);
1616 break;
1617 case ZFCP_ERP_FAILED :
1618 atomic_inc(&unit->erp_counter);
1619 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1620 zfcp_erp_unit_failed(unit);
1621 break;
1622 case ZFCP_ERP_EXIT :
1623 /* nothing */
1624 break;
1625 }
1626
1627 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1628 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1629 result = ZFCP_ERP_EXIT;
1630 }
1631
1632 return result;
1633}
1634
1635/*
1636 * function:
1637 *
1638 * purpose:
1639 *
1640 * returns:
1641 */
1642static int
1643zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1644{
1645 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1646 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1647
1648 switch (result) {
1649 case ZFCP_ERP_SUCCEEDED :
1650 atomic_set(&port->erp_counter, 0);
1651 zfcp_erp_port_unblock(port);
1652 break;
1653 case ZFCP_ERP_FAILED :
1654 atomic_inc(&port->erp_counter);
1655 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1656 zfcp_erp_port_failed(port);
1657 break;
1658 case ZFCP_ERP_EXIT :
1659 /* nothing */
1660 break;
1661 }
1662
1663 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1664 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1665 result = ZFCP_ERP_EXIT;
1666 }
1667
1668 return result;
1669}
1670
1671/*
1672 * function:
1673 *
1674 * purpose:
1675 *
1676 * returns:
1677 */
1678static int
1679zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1680{
1681 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1682
1683 switch (result) {
1684 case ZFCP_ERP_SUCCEEDED :
1685 atomic_set(&adapter->erp_counter, 0);
1686 zfcp_erp_adapter_unblock(adapter);
1687 break;
1688 case ZFCP_ERP_FAILED :
1689 atomic_inc(&adapter->erp_counter);
1690 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1691 zfcp_erp_adapter_failed(adapter);
1692 break;
1693 case ZFCP_ERP_EXIT :
1694 /* nothing */
1695 break;
1696 }
1697
1698 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1699 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1700 result = ZFCP_ERP_EXIT;
1701 }
1702
1703 return result;
1704}
1705
1706/*
1707 * function:
1708 *
1709 * purpose: remaining things in good cases,
1710 * escalation in bad cases
1711 *
1712 * returns:
1713 */
1714static int
1715zfcp_erp_strategy_followup_actions(int action,
1716 struct zfcp_adapter *adapter,
1717 struct zfcp_port *port,
1718 struct zfcp_unit *unit, int status)
1719{
1720 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1721 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1722
1723 /* initiate follow-up actions depending on success of finished action */
1724 switch (action) {
1725
1726 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1727 if (status == ZFCP_ERP_SUCCEEDED)
1728 zfcp_erp_port_reopen_all_internal(adapter, 0);
1729 else
1730 zfcp_erp_adapter_reopen_internal(adapter, 0);
1731 break;
1732
1733 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1734 if (status == ZFCP_ERP_SUCCEEDED)
1735 zfcp_erp_port_reopen_internal(port, 0);
1736 else
1737 zfcp_erp_adapter_reopen_internal(adapter, 0);
1738 break;
1739
1740 case ZFCP_ERP_ACTION_REOPEN_PORT:
1741 if (status == ZFCP_ERP_SUCCEEDED)
1742 zfcp_erp_unit_reopen_all_internal(port, 0);
1743 else
1744 zfcp_erp_port_forced_reopen_internal(port, 0);
1745 break;
1746
1747 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1748 if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
1749 else
1750 zfcp_erp_port_reopen_internal(unit->port, 0);
1751 break;
1752 }
1753
1754 return 0;
1755}
1756
1757/*
1758 * function:
1759 *
1760 * purpose:
1761 *
1762 * returns:
1763 */
1764static int
1765zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1766{
1767 unsigned long flags;
1768
1769 read_lock_irqsave(&zfcp_data.config_lock, flags);
1770 read_lock(&adapter->erp_lock);
1771 if (list_empty(&adapter->erp_ready_head) &&
1772 list_empty(&adapter->erp_running_head)) {
1773 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1774 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1775 &adapter->status);
1776 wake_up(&adapter->erp_done_wqh);
1777 } else
1778 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1779 read_unlock(&adapter->erp_lock);
1780 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1781
1782 return 0;
1783}
1784
1785/**
1786 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1787 * @adapter: adapter for which to wait for completion of its error recovery
1788 * Return: 0
1789 */
1790int
1791zfcp_erp_wait(struct zfcp_adapter *adapter)
1792{
1793 int retval = 0;
1794
1795 wait_event(adapter->erp_done_wqh,
1796 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1797 &adapter->status));
1798
1799 return retval;
1800}
1801
1802/*
1803 * function: zfcp_erp_modify_adapter_status
1804 *
1805 * purpose:
1806 *
1807 */
1808void
1809zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
1810 u32 mask, int set_or_clear)
1811{
1812 struct zfcp_port *port;
1813 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1814
1815 if (set_or_clear == ZFCP_SET) {
1816 atomic_set_mask(mask, &adapter->status);
1817 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1818 } else {
1819 atomic_clear_mask(mask, &adapter->status);
1820 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1821 atomic_set(&adapter->erp_counter, 0);
1822 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1823 }
1824 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1825
1826 /* Deal with all underlying devices, only pass common_mask */
1827 if (common_mask)
1828 list_for_each_entry(port, &adapter->port_list_head, list)
1829 zfcp_erp_modify_port_status(port, common_mask,
1830 set_or_clear);
1831}
1832
1833/*
1834 * function: zfcp_erp_modify_port_status
1835 *
1836 * purpose: sets the port and all underlying devices to ERP_FAILED
1837 *
1838 */
1839void
1840zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
1841{
1842 struct zfcp_unit *unit;
1843 u32 common_mask = mask & ZFCP_COMMON_FLAGS;
1844
1845 if (set_or_clear == ZFCP_SET) {
1846 atomic_set_mask(mask, &port->status);
1847 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1848 } else {
1849 atomic_clear_mask(mask, &port->status);
1850 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1851 atomic_set(&port->erp_counter, 0);
1852 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1853 }
1854 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1855 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1856
1857 /* Modify status of all underlying devices, only pass common mask */
1858 if (common_mask)
1859 list_for_each_entry(unit, &port->unit_list_head, list)
1860 zfcp_erp_modify_unit_status(unit, common_mask,
1861 set_or_clear);
1862}
1863
1864/*
1865 * function: zfcp_erp_modify_unit_status
1866 *
1867 * purpose: sets the unit to ERP_FAILED
1868 *
1869 */
1870void
1871zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
1872{
1873 if (set_or_clear == ZFCP_SET) {
1874 atomic_set_mask(mask, &unit->status);
1875 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1876 } else {
1877 atomic_clear_mask(mask, &unit->status);
1878 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1879 atomic_set(&unit->erp_counter, 0);
1880 }
1881 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1882 }
1883 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1884 sizeof (fcp_lun_t));
1885 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1886}
1887
1888/*
1889 * function:
1890 *
1891 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1892 * used to ensure the correct locking
1893 *
1894 * returns: 0 - initiated action succesfully
1895 * <0 - failed to initiate action
1896 */
1897int
1898zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
1899{
1900 int retval;
1901 unsigned long flags;
1902
1903 read_lock_irqsave(&zfcp_data.config_lock, flags);
1904 write_lock(&adapter->erp_lock);
1905 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
1906 write_unlock(&adapter->erp_lock);
1907 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1908
1909 return retval;
1910}
1911
1912/*
1913 * function:
1914 *
1915 * purpose:
1916 *
1917 * returns: FIXME
1918 */
1919static int
1920zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
1921{
1922 int retval = 0;
1923 struct zfcp_port *port;
1924
1925 list_for_each_entry(port, &adapter->port_list_head, list)
1926 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1927 zfcp_erp_port_reopen_internal(port, clear_mask);
1928
1929 return retval;
1930}
1931
1932/*
1933 * function:
1934 *
1935 * purpose:
1936 *
1937 * returns: FIXME
1938 */
1939static int
1940zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
1941{
1942 int retval = 0;
1943 struct zfcp_unit *unit;
1944
1945 list_for_each_entry(unit, &port->unit_list_head, list)
1946 zfcp_erp_unit_reopen_internal(unit, clear_mask);
1947
1948 return retval;
1949}
1950
1951/*
1952 * function:
1953 *
1954 * purpose: this routine executes the 'Reopen Adapter' action
1955 * (the entire action is processed synchronously, since
1956 * there are no actions which might be run concurrently
1957 * per definition)
1958 *
1959 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1960 * ZFCP_ERP_FAILED - action finished unsuccessfully
1961 */
1962static int
1963zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1964{
1965 int retval;
1966 struct zfcp_adapter *adapter = erp_action->adapter;
1967
1968 retval = zfcp_erp_adapter_strategy_close(erp_action);
1969 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1970 retval = ZFCP_ERP_EXIT;
1971 else
1972 retval = zfcp_erp_adapter_strategy_open(erp_action);
1973
1974 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1975 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1976 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1977
1978 if (retval == ZFCP_ERP_FAILED) {
1979 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1980 "to recover itself\n",
1981 zfcp_get_busid_by_adapter(adapter));
1982 msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
1983 }
1984
1985 return retval;
1986}
1987
1988/*
1989 * function:
1990 *
1991 * purpose:
1992 *
1993 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1994 * ZFCP_ERP_FAILED - action finished unsuccessfully
1995 */
1996static int
1997zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1998{
1999 int retval;
2000
2001 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
2002 &erp_action->adapter->status);
2003 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
2004 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
2005 &erp_action->adapter->status);
2006
2007 return retval;
2008}
2009
2010/*
2011 * function:
2012 *
2013 * purpose:
2014 *
2015 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
2016 * ZFCP_ERP_FAILED - action finished unsuccessfully
2017 */
2018static int
2019zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
2020{
2021 int retval;
2022
2023 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
2024 &erp_action->adapter->status);
2025 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2026 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2027 &erp_action->adapter->status);
2028
2029 return retval;
2030}
2031
2032/*
2033 * function: zfcp_register_adapter
2034 *
2035 * purpose: allocate the irq associated with this devno and register
2036 * the FSF adapter with the SCSI stack
2037 *
2038 * returns:
2039 */
2040static int
2041zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2042{
2043 int retval = ZFCP_ERP_SUCCEEDED;
2044
2045 if (close)
2046 goto close_only;
2047
2048 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2049 if (retval != ZFCP_ERP_SUCCEEDED)
2050 goto failed_qdio;
2051
2052 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2053 if (retval != ZFCP_ERP_SUCCEEDED)
2054 goto failed_openfcp;
2055
2056 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2057 goto out;
2058
2059 close_only:
2060 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2061 &erp_action->adapter->status);
2062
2063 failed_openfcp:
2064 zfcp_erp_adapter_strategy_close_qdio(erp_action);
2065 zfcp_erp_adapter_strategy_close_fsf(erp_action);
2066 failed_qdio:
2067 out:
2068 return retval;
2069}
2070
2071/*
2072 * function: zfcp_qdio_init
2073 *
2074 * purpose: setup QDIO operation for specified adapter
2075 *
2076 * returns: 0 - successful setup
2077 * !0 - failed setup
2078 */
2079int
2080zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2081{
2082 int retval;
2083 int i;
2084 volatile struct qdio_buffer_element *sbale;
2085 struct zfcp_adapter *adapter = erp_action->adapter;
2086
2087 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2088 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2089 "adapter %s\n",
2090 zfcp_get_busid_by_adapter(adapter));
2091 goto failed_sanity;
2092 }
2093
2094 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2095 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2096 "on adapter %s\n",
2097 zfcp_get_busid_by_adapter(adapter));
2098 goto failed_qdio_establish;
2099 }
2100 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2101
2102 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2103 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2104 "on adapter %s\n",
2105 zfcp_get_busid_by_adapter(adapter));
2106 goto failed_qdio_activate;
2107 }
2108 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2109
2110 /*
2111 * put buffers into response queue,
2112 */
2113 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2114 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2115 sbale->length = 0;
2116 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2117 sbale->addr = 0;
2118 }
2119
2120 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2121 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2122 zfcp_get_busid_by_adapter(adapter),
2123 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2124
2125 retval = do_QDIO(adapter->ccw_device,
2126 QDIO_FLAG_SYNC_INPUT,
2127 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2128
2129 if (retval) {
2130 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2131 retval);
2132 goto failed_do_qdio;
2133 } else {
2134 adapter->response_queue.free_index = 0;
2135 atomic_set(&adapter->response_queue.free_count, 0);
2136 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2137 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2138 }
2139 /* set index of first avalable SBALS / number of available SBALS */
2140 adapter->request_queue.free_index = 0;
2141 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2142 adapter->request_queue.distance_from_int = 0;
2143
2144 /* initialize waitqueue used to wait for free SBALs in requests queue */
2145 init_waitqueue_head(&adapter->request_wq);
2146
2147 /* ok, we did it - skip all cleanups for different failures */
2148 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2149 retval = ZFCP_ERP_SUCCEEDED;
2150 goto out;
2151
2152 failed_do_qdio:
2153 /* NOP */
2154
2155 failed_qdio_activate:
2156 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2157 while (qdio_shutdown(adapter->ccw_device,
2158 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2159 msleep(1000);
2160 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2161
2162 failed_qdio_establish:
2163 failed_sanity:
2164 retval = ZFCP_ERP_FAILED;
2165
2166 out:
2167 return retval;
2168}
2169
2170/*
2171 * function: zfcp_qdio_cleanup
2172 *
2173 * purpose: cleans up QDIO operation for the specified adapter
2174 *
2175 * returns: 0 - successful cleanup
2176 * !0 - failed cleanup
2177 */
2178int
2179zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
2180{
2181 int retval = ZFCP_ERP_SUCCEEDED;
2182 int first_used;
2183 int used_count;
2184 struct zfcp_adapter *adapter = erp_action->adapter;
2185
2186 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2187 ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
2188 "queues on adapter %s\n",
2189 zfcp_get_busid_by_adapter(adapter));
2190 retval = ZFCP_ERP_FAILED;
2191 goto out;
2192 }
2193
2194 /*
2195 * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
2196 * do_QDIO won't be called while qdio_shutdown is in progress.
2197 */
2198
2199 write_lock_irq(&adapter->request_queue.queue_lock);
2200 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2201 write_unlock_irq(&adapter->request_queue.queue_lock);
2202
2203 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
2204 while (qdio_shutdown(adapter->ccw_device,
2205 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2206 msleep(1000);
2207 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
2208
2209 /*
2210 * First we had to stop QDIO operation.
2211 * Now it is safe to take the following actions.
2212 */
2213
2214 /* Cleanup only necessary when there are unacknowledged buffers */
2215 if (atomic_read(&adapter->request_queue.free_count)
2216 < QDIO_MAX_BUFFERS_PER_Q) {
2217 first_used = (adapter->request_queue.free_index +
2218 atomic_read(&adapter->request_queue.free_count))
2219 % QDIO_MAX_BUFFERS_PER_Q;
2220 used_count = QDIO_MAX_BUFFERS_PER_Q -
2221 atomic_read(&adapter->request_queue.free_count);
2222 zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
2223 first_used, used_count);
2224 }
2225 adapter->response_queue.free_index = 0;
2226 atomic_set(&adapter->response_queue.free_count, 0);
2227 adapter->request_queue.free_index = 0;
2228 atomic_set(&adapter->request_queue.free_count, 0);
2229 adapter->request_queue.distance_from_int = 0;
2230 out:
2231 return retval;
2232}
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234static int
2235zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2236{
Andreas Herrmann2448c452005-12-01 02:50:36 +01002237 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Andreas Herrmann2448c452005-12-01 02:50:36 +01002239 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2240 if (retval == ZFCP_ERP_FAILED)
2241 return ZFCP_ERP_FAILED;
2242
2243 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2244 if (retval == ZFCP_ERP_FAILED)
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002245 return ZFCP_ERP_FAILED;
2246
2247 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248}
2249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250static int
2251zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2252{
2253 int retval = ZFCP_ERP_SUCCEEDED;
2254 int retries;
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002255 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 struct zfcp_adapter *adapter = erp_action->adapter;
2257
2258 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002260 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2262 &adapter->status);
2263 ZFCP_LOG_DEBUG("Doing exchange config data\n");
Andreas Herrmann3734d242005-09-13 21:47:11 +02002264 write_lock(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 zfcp_erp_action_to_running(erp_action);
Andreas Herrmann3734d242005-09-13 21:47:11 +02002266 write_unlock(&adapter->erp_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 zfcp_erp_timeout_init(erp_action);
2268 if (zfcp_fsf_exchange_config_data(erp_action)) {
2269 retval = ZFCP_ERP_FAILED;
2270 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2271 ZFCP_LOG_INFO("error: initiation of exchange of "
2272 "configuration data failed for "
2273 "adapter %s\n",
2274 zfcp_get_busid_by_adapter(adapter));
2275 break;
2276 }
2277 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2278 ZFCP_LOG_DEBUG("Xchange underway\n");
2279
2280 /*
2281 * Why this works:
2282 * Both the normal completion handler as well as the timeout
2283 * handler will do an 'up' when the 'exchange config data'
2284 * request completes or times out. Thus, the signal to go on
2285 * won't be lost utilizing this semaphore.
2286 * Furthermore, this 'adapter_reopen' action is
2287 * guaranteed to be the only action being there (highest action
2288 * which prevents other actions from being created).
2289 * Resulting from that, the wake signal recognized here
2290 * _must_ be the one belonging to the 'exchange config
2291 * data' request.
2292 */
2293 down(&adapter->erp_ready_sem);
2294 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2295 ZFCP_LOG_INFO("error: exchange of configuration data "
2296 "for adapter %s timed out\n",
2297 zfcp_get_busid_by_adapter(adapter));
2298 break;
2299 }
Andreas Herrmann22753fa2005-06-13 13:15:15 +02002300
2301 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2302 &adapter->status))
2303 break;
2304
2305 ZFCP_LOG_DEBUG("host connection still initialising... "
2306 "waiting and retrying...\n");
2307 /* sleep a little bit before retry */
2308 msleep(jiffies_to_msecs(sleep));
2309 sleep *= 2;
2310 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2313 &adapter->status)) {
2314 ZFCP_LOG_INFO("error: exchange of configuration data for "
2315 "adapter %s failed\n",
2316 zfcp_get_busid_by_adapter(adapter));
2317 retval = ZFCP_ERP_FAILED;
2318 }
2319
2320 return retval;
2321}
2322
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002323static int
2324zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2325{
Andreas Herrmann2448c452005-12-01 02:50:36 +01002326 int ret;
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002327 struct zfcp_adapter *adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002328
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002329 adapter = erp_action->adapter;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002330 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2331
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002332 write_lock(&adapter->erp_lock);
2333 zfcp_erp_action_to_running(erp_action);
2334 write_unlock(&adapter->erp_lock);
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002335
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002336 zfcp_erp_timeout_init(erp_action);
2337 ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
2338 if (ret == -EOPNOTSUPP) {
2339 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2340 return ZFCP_ERP_SUCCEEDED;
2341 } else if (ret) {
2342 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2343 return ZFCP_ERP_FAILED;
2344 }
2345 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002346
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002347 ret = ZFCP_ERP_SUCCEEDED;
2348 down(&adapter->erp_ready_sem);
2349 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2350 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2351 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2352 ret = ZFCP_ERP_FAILED;
2353 }
2354 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status)) {
2355 ZFCP_LOG_INFO("error: exchange port data failed (adapter "
2356 "%s\n", zfcp_get_busid_by_adapter(adapter));
2357 ret = ZFCP_ERP_FAILED;
2358 }
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002359
Andreas Herrmann2f8f3ed2006-02-11 01:41:50 +01002360 return ret;
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02002361}
2362
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363/*
2364 * function:
2365 *
2366 * purpose:
2367 *
2368 * returns:
2369 */
2370static int
2371zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2372 *erp_action)
2373{
2374 int retval = ZFCP_ERP_SUCCEEDED;
2375 int temp_ret;
2376 struct zfcp_adapter *adapter = erp_action->adapter;
2377 int i;
2378
2379 adapter->status_read_failed = 0;
2380 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2381 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2382 if (temp_ret < 0) {
2383 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2384 "notification failed on adapter %s\n",
2385 zfcp_get_busid_by_adapter(adapter));
2386 retval = ZFCP_ERP_FAILED;
2387 i--;
2388 break;
2389 }
2390 }
2391
2392 return retval;
2393}
2394
2395/*
2396 * function: zfcp_fsf_cleanup
2397 *
2398 * purpose: cleanup FSF operation for specified adapter
2399 *
2400 * returns: 0 - FSF operation successfully cleaned up
2401 * !0 - failed to cleanup FSF operation for this adapter
2402 */
2403static int
2404zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
2405{
2406 int retval = ZFCP_ERP_SUCCEEDED;
2407 struct zfcp_adapter *adapter = erp_action->adapter;
2408
2409 /*
2410 * wake waiting initiators of requests,
2411 * return SCSI commands (with error status),
2412 * clean up all requests (synchronously)
2413 */
2414 zfcp_fsf_req_dismiss_all(adapter);
2415 /* reset FSF request sequence number */
2416 adapter->fsf_req_seq_no = 0;
2417 /* all ports and units are closed */
2418 zfcp_erp_modify_adapter_status(adapter,
2419 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
2420
2421 return retval;
2422}
2423
2424/*
2425 * function:
2426 *
2427 * purpose: this routine executes the 'Reopen Physical Port' action
2428 *
2429 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2430 * ZFCP_ERP_SUCCEEDED - action finished successfully
2431 * ZFCP_ERP_FAILED - action finished unsuccessfully
2432 */
2433static int
2434zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2435{
2436 int retval = ZFCP_ERP_FAILED;
2437 struct zfcp_port *port = erp_action->port;
2438 struct zfcp_adapter *adapter = erp_action->adapter;
2439
2440 switch (erp_action->step) {
2441
2442 /*
2443 * FIXME:
2444 * the ULP spec. begs for waiting for oustanding commands
2445 */
2446 case ZFCP_ERP_STEP_UNINITIALIZED:
2447 zfcp_erp_port_strategy_clearstati(port);
2448 /*
2449 * it would be sufficient to test only the normal open flag
2450 * since the phys. open flag cannot be set if the normal
2451 * open flag is unset - however, this is for readabilty ...
2452 */
2453 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2454 ZFCP_STATUS_COMMON_OPEN),
2455 &port->status)) {
2456 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2457 "close physical\n", port->wwpn);
2458 retval =
2459 zfcp_erp_port_forced_strategy_close(erp_action);
2460 } else
2461 retval = ZFCP_ERP_FAILED;
2462 break;
2463
2464 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2465 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2466 &port->status)) {
2467 ZFCP_LOG_DEBUG("close physical failed for port "
2468 "0x%016Lx\n", port->wwpn);
2469 retval = ZFCP_ERP_FAILED;
2470 } else
2471 retval = ZFCP_ERP_SUCCEEDED;
2472 break;
2473 }
2474
2475 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2476 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2477 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2478 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2479
2480 return retval;
2481}
2482
2483/*
2484 * function:
2485 *
2486 * purpose: this routine executes the 'Reopen Port' action
2487 *
2488 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2489 * ZFCP_ERP_SUCCEEDED - action finished successfully
2490 * ZFCP_ERP_FAILED - action finished unsuccessfully
2491 */
2492static int
2493zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2494{
2495 int retval = ZFCP_ERP_FAILED;
2496 struct zfcp_port *port = erp_action->port;
2497 struct zfcp_adapter *adapter = erp_action->adapter;
2498
2499 switch (erp_action->step) {
2500
2501 /*
2502 * FIXME:
2503 * the ULP spec. begs for waiting for oustanding commands
2504 */
2505 case ZFCP_ERP_STEP_UNINITIALIZED:
2506 zfcp_erp_port_strategy_clearstati(port);
2507 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2508 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2509 "close\n", port->wwpn);
2510 retval = zfcp_erp_port_strategy_close(erp_action);
2511 goto out;
2512 } /* else it's already closed, open it */
2513 break;
2514
2515 case ZFCP_ERP_STEP_PORT_CLOSING:
2516 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2517 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2518 port->wwpn);
2519 retval = ZFCP_ERP_FAILED;
2520 goto out;
2521 } /* else it's closed now, open it */
2522 break;
2523 }
2524 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2525 retval = ZFCP_ERP_EXIT;
2526 else
2527 retval = zfcp_erp_port_strategy_open(erp_action);
2528
2529 out:
2530 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2531 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2532 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2533 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2534
2535 return retval;
2536}
2537
2538/*
2539 * function:
2540 *
2541 * purpose:
2542 *
2543 * returns:
2544 */
2545static int
2546zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2547{
2548 int retval;
2549
2550 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2551 &erp_action->port->status))
2552 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2553 else
2554 retval = zfcp_erp_port_strategy_open_common(erp_action);
2555
2556 return retval;
2557}
2558
2559/*
2560 * function:
2561 *
2562 * purpose:
2563 *
2564 * returns:
2565 *
2566 * FIXME(design): currently only prepared for fabric (nameserver!)
2567 */
2568static int
2569zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2570{
2571 int retval = 0;
2572 struct zfcp_adapter *adapter = erp_action->adapter;
2573 struct zfcp_port *port = erp_action->port;
2574
2575 switch (erp_action->step) {
2576
2577 case ZFCP_ERP_STEP_UNINITIALIZED:
2578 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2579 case ZFCP_ERP_STEP_PORT_CLOSING:
Andreas Herrmannad757cd2006-01-13 02:26:11 +01002580 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
6f71d9b2005-04-10 23:04:28 -05002581 if (port->wwpn != adapter->peer_wwpn) {
2582 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2583 "on adapter %s.\nPeer WWPN "
2584 "0x%016Lx does not match\n",
2585 port->wwpn,
2586 zfcp_get_busid_by_adapter(adapter),
2587 adapter->peer_wwpn);
2588 zfcp_erp_port_failed(port);
2589 retval = ZFCP_ERP_FAILED;
2590 break;
2591 }
2592 port->d_id = adapter->peer_d_id;
2593 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2594 retval = zfcp_erp_port_strategy_open_port(erp_action);
2595 break;
2596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 if (!(adapter->nameserver_port)) {
2598 retval = zfcp_nameserver_enqueue(adapter);
2599 if (retval != 0) {
2600 ZFCP_LOG_NORMAL("error: nameserver port "
2601 "unavailable for adapter %s\n",
2602 zfcp_get_busid_by_adapter(adapter));
2603 retval = ZFCP_ERP_FAILED;
2604 break;
2605 }
2606 }
2607 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2608 &adapter->nameserver_port->status)) {
2609 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2610 "nameserver port\n");
2611 /* nameserver port may live again */
2612 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2613 &adapter->nameserver_port->status);
2614 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
2615 >= 0) {
2616 erp_action->step =
2617 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2618 retval = ZFCP_ERP_CONTINUES;
2619 } else
2620 retval = ZFCP_ERP_FAILED;
2621 break;
2622 }
2623 /* else nameserver port is already open, fall through */
2624 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2625 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2626 &adapter->nameserver_port->status)) {
2627 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2628 retval = ZFCP_ERP_FAILED;
2629 } else {
2630 ZFCP_LOG_DEBUG("nameserver port is open -> "
2631 "nameserver look-up for port 0x%016Lx\n",
2632 port->wwpn);
2633 retval = zfcp_erp_port_strategy_open_common_lookup
2634 (erp_action);
2635 }
2636 break;
2637
2638 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2639 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2640 if (atomic_test_mask
2641 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2642 ZFCP_LOG_DEBUG("nameserver look-up failed "
2643 "for port 0x%016Lx "
2644 "(misconfigured WWPN?)\n",
2645 port->wwpn);
2646 zfcp_erp_port_failed(port);
2647 retval = ZFCP_ERP_EXIT;
2648 } else {
2649 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2650 "port 0x%016Lx\n", port->wwpn);
2651 retval = ZFCP_ERP_FAILED;
2652 }
2653 } else {
2654 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
2655 "trying open\n", port->wwpn, port->d_id);
2656 retval = zfcp_erp_port_strategy_open_port(erp_action);
2657 }
2658 break;
2659
2660 case ZFCP_ERP_STEP_PORT_OPENING:
2661 /* D_ID might have changed during open */
2662 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2663 ZFCP_STATUS_PORT_DID_DID),
2664 &port->status)) {
2665 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2666 retval = ZFCP_ERP_SUCCEEDED;
2667 } else {
2668 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2669 port->wwpn);
2670 retval = ZFCP_ERP_FAILED;
2671 }
2672 break;
2673
2674 default:
2675 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2676 erp_action->step);
2677 retval = ZFCP_ERP_FAILED;
2678 }
2679
2680 return retval;
2681}
2682
2683/*
2684 * function:
2685 *
2686 * purpose:
2687 *
2688 * returns:
2689 */
2690static int
2691zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2692{
2693 int retval;
2694 struct zfcp_port *port = erp_action->port;
2695
2696 switch (erp_action->step) {
2697
2698 case ZFCP_ERP_STEP_UNINITIALIZED:
2699 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2700 case ZFCP_ERP_STEP_PORT_CLOSING:
2701 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
2702 port->wwpn, port->d_id);
2703 retval = zfcp_erp_port_strategy_open_port(erp_action);
2704 break;
2705
2706 case ZFCP_ERP_STEP_PORT_OPENING:
2707 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2708 ZFCP_LOG_DEBUG("WKA port is open\n");
2709 retval = ZFCP_ERP_SUCCEEDED;
2710 } else {
2711 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2712 retval = ZFCP_ERP_FAILED;
2713 }
2714 /* this is needed anyway (dont care for retval of wakeup) */
2715 ZFCP_LOG_DEBUG("continue other open port operations\n");
2716 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2717 break;
2718
2719 default:
2720 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2721 erp_action->step);
2722 retval = ZFCP_ERP_FAILED;
2723 }
2724
2725 return retval;
2726}
2727
2728/*
2729 * function:
2730 *
2731 * purpose: makes the erp thread continue with reopen (physical) port
2732 * actions which have been paused until the name server port
2733 * is opened (or failed)
2734 *
2735 * returns: 0 (a kind of void retval, its not used)
2736 */
2737static int
2738zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2739 *ns_erp_action)
2740{
2741 int retval = 0;
2742 unsigned long flags;
2743 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2744 struct zfcp_erp_action *erp_action, *tmp;
2745
2746 read_lock_irqsave(&adapter->erp_lock, flags);
2747 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2748 list) {
2749 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2750 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2751 sizeof (wwn_t));
2752 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2753 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2754 debug_event(adapter->erp_dbf, 3,
2755 &erp_action->port->wwpn, sizeof (wwn_t));
2756 if (atomic_test_mask(
2757 ZFCP_STATUS_COMMON_ERP_FAILED,
2758 &adapter->nameserver_port->status))
2759 zfcp_erp_port_failed(erp_action->port);
2760 zfcp_erp_action_ready(erp_action);
2761 }
2762 }
2763 read_unlock_irqrestore(&adapter->erp_lock, flags);
2764
2765 return retval;
2766}
2767
2768/*
2769 * function:
2770 *
2771 * purpose:
2772 *
2773 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2774 * ZFCP_ERP_FAILED - action finished unsuccessfully
2775 */
2776static int
2777zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2778{
2779 int retval;
2780 struct zfcp_adapter *adapter = erp_action->adapter;
2781 struct zfcp_port *port = erp_action->port;
2782
2783 zfcp_erp_timeout_init(erp_action);
2784 retval = zfcp_fsf_close_physical_port(erp_action);
2785 if (retval == -ENOMEM) {
2786 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2787 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2788 retval = ZFCP_ERP_NOMEM;
2789 goto out;
2790 }
2791 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2792 if (retval != 0) {
2793 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2794 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2795 /* could not send 'open', fail */
2796 retval = ZFCP_ERP_FAILED;
2797 goto out;
2798 }
2799 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2800 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2801 retval = ZFCP_ERP_CONTINUES;
2802 out:
2803 return retval;
2804}
2805
2806/*
2807 * function:
2808 *
2809 * purpose:
2810 *
2811 * returns:
2812 */
2813static int
2814zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2815{
2816 int retval = 0;
2817 struct zfcp_adapter *adapter = port->adapter;
2818
2819 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2820 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2821
2822 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2823 ZFCP_STATUS_COMMON_CLOSING |
2824 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2825 ZFCP_STATUS_PORT_DID_DID |
2826 ZFCP_STATUS_PORT_PHYS_CLOSING |
2827 ZFCP_STATUS_PORT_INVALID_WWPN,
2828 &port->status);
2829 return retval;
2830}
2831
2832/*
2833 * function:
2834 *
2835 * purpose:
2836 *
2837 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2838 * ZFCP_ERP_FAILED - action finished unsuccessfully
2839 */
2840static int
2841zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2842{
2843 int retval;
2844 struct zfcp_adapter *adapter = erp_action->adapter;
2845 struct zfcp_port *port = erp_action->port;
2846
2847 zfcp_erp_timeout_init(erp_action);
2848 retval = zfcp_fsf_close_port(erp_action);
2849 if (retval == -ENOMEM) {
2850 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2851 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2852 retval = ZFCP_ERP_NOMEM;
2853 goto out;
2854 }
2855 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2856 if (retval != 0) {
2857 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2858 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2859 /* could not send 'close', fail */
2860 retval = ZFCP_ERP_FAILED;
2861 goto out;
2862 }
2863 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2864 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2865 retval = ZFCP_ERP_CONTINUES;
2866 out:
2867 return retval;
2868}
2869
2870/*
2871 * function:
2872 *
2873 * purpose:
2874 *
2875 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2876 * ZFCP_ERP_FAILED - action finished unsuccessfully
2877 */
2878static int
2879zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2880{
2881 int retval;
2882 struct zfcp_adapter *adapter = erp_action->adapter;
2883 struct zfcp_port *port = erp_action->port;
2884
2885 zfcp_erp_timeout_init(erp_action);
2886 retval = zfcp_fsf_open_port(erp_action);
2887 if (retval == -ENOMEM) {
2888 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2889 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2890 retval = ZFCP_ERP_NOMEM;
2891 goto out;
2892 }
2893 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2894 if (retval != 0) {
2895 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2896 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2897 /* could not send 'open', fail */
2898 retval = ZFCP_ERP_FAILED;
2899 goto out;
2900 }
2901 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2902 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2903 retval = ZFCP_ERP_CONTINUES;
2904 out:
2905 return retval;
2906}
2907
2908/*
2909 * function:
2910 *
2911 * purpose:
2912 *
2913 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2914 * ZFCP_ERP_FAILED - action finished unsuccessfully
2915 */
2916static int
2917zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2918{
2919 int retval;
2920 struct zfcp_adapter *adapter = erp_action->adapter;
2921 struct zfcp_port *port = erp_action->port;
2922
2923 zfcp_erp_timeout_init(erp_action);
2924 retval = zfcp_ns_gid_pn_request(erp_action);
2925 if (retval == -ENOMEM) {
2926 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2927 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2928 retval = ZFCP_ERP_NOMEM;
2929 goto out;
2930 }
2931 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2932 if (retval != 0) {
2933 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2934 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2935 /* could not send nameserver request, fail */
2936 retval = ZFCP_ERP_FAILED;
2937 goto out;
2938 }
2939 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2940 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2941 retval = ZFCP_ERP_CONTINUES;
2942 out:
2943 return retval;
2944}
2945
2946/*
2947 * function:
2948 *
2949 * purpose: this routine executes the 'Reopen Unit' action
2950 * currently no retries
2951 *
2952 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2953 * ZFCP_ERP_SUCCEEDED - action finished successfully
2954 * ZFCP_ERP_FAILED - action finished unsuccessfully
2955 */
2956static int
2957zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2958{
2959 int retval = ZFCP_ERP_FAILED;
2960 struct zfcp_unit *unit = erp_action->unit;
2961 struct zfcp_adapter *adapter = erp_action->adapter;
2962
2963 switch (erp_action->step) {
2964
2965 /*
2966 * FIXME:
2967 * the ULP spec. begs for waiting for oustanding commands
2968 */
2969 case ZFCP_ERP_STEP_UNINITIALIZED:
2970 zfcp_erp_unit_strategy_clearstati(unit);
2971 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2972 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2973 "trying close\n", unit->fcp_lun);
2974 retval = zfcp_erp_unit_strategy_close(erp_action);
2975 break;
2976 }
2977 /* else it's already closed, fall through */
2978 case ZFCP_ERP_STEP_UNIT_CLOSING:
2979 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2980 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2981 unit->fcp_lun);
2982 retval = ZFCP_ERP_FAILED;
2983 } else {
2984 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2985 retval = ZFCP_ERP_EXIT;
2986 else {
2987 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2988 "trying open\n", unit->fcp_lun);
2989 retval =
2990 zfcp_erp_unit_strategy_open(erp_action);
2991 }
2992 }
2993 break;
2994
2995 case ZFCP_ERP_STEP_UNIT_OPENING:
2996 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2997 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2998 unit->fcp_lun);
2999 retval = ZFCP_ERP_SUCCEEDED;
3000 } else {
3001 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
3002 unit->fcp_lun);
3003 retval = ZFCP_ERP_FAILED;
3004 }
3005 break;
3006 }
3007
3008 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
3009 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
3010 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
3011 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
3012 return retval;
3013}
3014
3015/*
3016 * function:
3017 *
3018 * purpose:
3019 *
3020 * returns:
3021 */
3022static int
3023zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
3024{
3025 int retval = 0;
3026 struct zfcp_adapter *adapter = unit->port->adapter;
3027
3028 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
3029 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3030
3031 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
3032 ZFCP_STATUS_COMMON_CLOSING |
3033 ZFCP_STATUS_COMMON_ACCESS_DENIED |
3034 ZFCP_STATUS_UNIT_SHARED |
3035 ZFCP_STATUS_UNIT_READONLY,
3036 &unit->status);
3037
3038 return retval;
3039}
3040
3041/*
3042 * function:
3043 *
3044 * purpose:
3045 *
3046 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3047 * ZFCP_ERP_FAILED - action finished unsuccessfully
3048 */
3049static int
3050zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
3051{
3052 int retval;
3053 struct zfcp_adapter *adapter = erp_action->adapter;
3054 struct zfcp_unit *unit = erp_action->unit;
3055
3056 zfcp_erp_timeout_init(erp_action);
3057 retval = zfcp_fsf_close_unit(erp_action);
3058 if (retval == -ENOMEM) {
3059 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
3060 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3061 sizeof (fcp_lun_t));
3062 retval = ZFCP_ERP_NOMEM;
3063 goto out;
3064 }
3065 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
3066 if (retval != 0) {
3067 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
3068 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3069 sizeof (fcp_lun_t));
3070 /* could not send 'close', fail */
3071 retval = ZFCP_ERP_FAILED;
3072 goto out;
3073 }
3074 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
3075 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3076 retval = ZFCP_ERP_CONTINUES;
3077
3078 out:
3079 return retval;
3080}
3081
3082/*
3083 * function:
3084 *
3085 * purpose:
3086 *
3087 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
3088 * ZFCP_ERP_FAILED - action finished unsuccessfully
3089 */
3090static int
3091zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
3092{
3093 int retval;
3094 struct zfcp_adapter *adapter = erp_action->adapter;
3095 struct zfcp_unit *unit = erp_action->unit;
3096
3097 zfcp_erp_timeout_init(erp_action);
3098 retval = zfcp_fsf_open_unit(erp_action);
3099 if (retval == -ENOMEM) {
3100 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
3101 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3102 sizeof (fcp_lun_t));
3103 retval = ZFCP_ERP_NOMEM;
3104 goto out;
3105 }
3106 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
3107 if (retval != 0) {
3108 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
3109 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
3110 sizeof (fcp_lun_t));
3111 /* could not send 'open', fail */
3112 retval = ZFCP_ERP_FAILED;
3113 goto out;
3114 }
3115 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
3116 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
3117 retval = ZFCP_ERP_CONTINUES;
3118 out:
3119 return retval;
3120}
3121
3122/*
3123 * function:
3124 *
3125 * purpose:
3126 *
3127 * returns:
3128 */
3129static inline void
3130zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
3131{
3132 init_timer(&erp_action->timer);
3133 erp_action->timer.function = zfcp_erp_timeout_handler;
3134 erp_action->timer.data = (unsigned long) erp_action;
3135 /* jiffies will be added in zfcp_fsf_req_send */
3136 erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
3137}
3138
3139/*
3140 * function:
3141 *
3142 * purpose: enqueue the specified error recovery action, if needed
3143 *
3144 * returns:
3145 */
3146static int
3147zfcp_erp_action_enqueue(int action,
3148 struct zfcp_adapter *adapter,
3149 struct zfcp_port *port, struct zfcp_unit *unit)
3150{
3151 int retval = 1;
3152 struct zfcp_erp_action *erp_action = NULL;
3153 int stronger_action = 0;
3154 u32 status = 0;
3155
3156 /*
3157 * We need some rules here which check whether we really need
3158 * this action or whether we should just drop it.
3159 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
3160 * 'Reopen Unit' request for an associated unit since we can't
3161 * satisfy this request now. A 'Reopen Port' action will trigger
3162 * 'Reopen Unit' actions when it completes.
3163 * Thus, there are only actions in the queue which can immediately be
3164 * executed. This makes the processing of the action queue more
3165 * efficient.
3166 */
3167
3168 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3169 &adapter->status))
3170 return -EIO;
3171
3172 debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
3173 /* check whether we really need this */
3174 switch (action) {
3175 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3176 if (atomic_test_mask
3177 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3178 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3179 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3180 sizeof (wwn_t));
3181 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3182 sizeof (fcp_lun_t));
3183 goto out;
3184 }
3185 if (!atomic_test_mask
3186 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3187 atomic_test_mask
3188 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3189 goto out;
3190 }
3191 if (!atomic_test_mask
3192 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
3193 stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
3194 unit = NULL;
3195 }
3196 /* fall through !!! */
3197
3198 case ZFCP_ERP_ACTION_REOPEN_PORT:
3199 if (atomic_test_mask
3200 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3201 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3202 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3203 sizeof (wwn_t));
3204 goto out;
3205 }
3206 /* fall through !!! */
3207
3208 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
Andreas Herrmann3734d242005-09-13 21:47:11 +02003209 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3210 &port->status)) {
3211 if (port->erp_action.action !=
3212 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3213 ZFCP_LOG_INFO("dropped erp action %i (port "
3214 "0x%016Lx, action in use: %i)\n",
3215 action, port->wwpn,
3216 port->erp_action.action);
3217 debug_text_event(adapter->erp_dbf, 4,
3218 "pf_actenq_drp");
3219 } else
3220 debug_text_event(adapter->erp_dbf, 4,
3221 "pf_actenq_drpcp");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3223 sizeof (wwn_t));
3224 goto out;
3225 }
3226 if (!atomic_test_mask
3227 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3228 atomic_test_mask
3229 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3230 goto out;
3231 }
3232 if (!atomic_test_mask
3233 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
3234 stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3235 port = NULL;
3236 }
3237 /* fall through !!! */
3238
3239 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3240 if (atomic_test_mask
3241 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3242 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3243 goto out;
3244 }
3245 break;
3246
3247 default:
3248 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3249 debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
3250 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3251 "on adapter %s (action=%d)\n",
3252 zfcp_get_busid_by_adapter(adapter), action);
3253 goto out;
3254 }
3255
3256 /* check whether we need something stronger first */
3257 if (stronger_action) {
3258 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3259 debug_event(adapter->erp_dbf, 4, &stronger_action,
3260 sizeof (int));
3261 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3262 "erp action %d on adapter %s\n",
3263 stronger_action, action,
3264 zfcp_get_busid_by_adapter(adapter));
3265 action = stronger_action;
3266 }
3267
3268 /* mark adapter to have some error recovery pending */
3269 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3270
3271 /* setup error recovery action */
3272 switch (action) {
3273
3274 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3275 zfcp_unit_get(unit);
3276 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3277 erp_action = &unit->erp_action;
3278 if (!atomic_test_mask
3279 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3280 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3281 break;
3282
3283 case ZFCP_ERP_ACTION_REOPEN_PORT:
3284 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3285 zfcp_port_get(port);
3286 zfcp_erp_action_dismiss_port(port);
3287 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3288 erp_action = &port->erp_action;
3289 if (!atomic_test_mask
3290 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3291 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3292 break;
3293
3294 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3295 zfcp_adapter_get(adapter);
3296 zfcp_erp_action_dismiss_adapter(adapter);
3297 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3298 erp_action = &adapter->erp_action;
3299 if (!atomic_test_mask
3300 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3301 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3302 break;
3303 }
3304
3305 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3306
3307 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3308 erp_action->adapter = adapter;
3309 erp_action->port = port;
3310 erp_action->unit = unit;
3311 erp_action->action = action;
3312 erp_action->status = status;
3313
3314 ++adapter->erp_total_count;
3315
3316 /* finally put it into 'ready' queue and kick erp thread */
3317 list_add(&erp_action->list, &adapter->erp_ready_head);
3318 up(&adapter->erp_ready_sem);
3319 retval = 0;
3320 out:
3321 return retval;
3322}
3323
3324/*
3325 * function:
3326 *
3327 * purpose:
3328 *
3329 * returns:
3330 */
3331static int
3332zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3333{
3334 int retval = 0;
3335 struct zfcp_adapter *adapter = erp_action->adapter;
3336
3337 --adapter->erp_total_count;
3338 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3339 --adapter->erp_low_mem_count;
3340 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3341 }
3342
3343 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3344 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3345 list_del(&erp_action->list);
3346 switch (erp_action->action) {
3347 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3348 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3349 &erp_action->unit->status);
3350 break;
3351 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3352 case ZFCP_ERP_ACTION_REOPEN_PORT:
3353 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3354 &erp_action->port->status);
3355 break;
3356 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3357 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3358 &erp_action->adapter->status);
3359 break;
3360 default:
3361 /* bug */
3362 break;
3363 }
3364 return retval;
3365}
3366
3367/**
3368 * zfcp_erp_action_cleanup
3369 *
Adrian Bunk575c9682006-01-15 02:00:17 +01003370 * Register unit with scsi stack if appropriate and fix reference counts.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 * Note: Temporary units are not registered with scsi stack.
3372 */
3373static void
3374zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3375 struct zfcp_port *port, struct zfcp_unit *unit,
3376 int result)
3377{
3378 switch (action) {
3379 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3380 if ((result == ZFCP_ERP_SUCCEEDED)
3381 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3382 &unit->status))
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003383 && !unit->device
Andreas Herrmannad58f7d2006-03-10 00:56:16 +01003384 && port->rport) {
3385 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3386 &unit->status);
3387 scsi_scan_target(&port->rport->dev, 0,
3388 port->rport->scsi_target_id,
3389 unit->scsi_lun, 0);
3390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 zfcp_unit_put(unit);
3392 break;
3393 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3394 case ZFCP_ERP_ACTION_REOPEN_PORT:
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003395 if ((result == ZFCP_ERP_SUCCEEDED)
3396 && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3397 &port->status)
3398 && !port->rport) {
3399 struct fc_rport_identifiers ids;
3400 ids.node_name = port->wwnn;
3401 ids.port_name = port->wwpn;
3402 ids.port_id = port->d_id;
3403 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3404 port->rport =
3405 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3406 if (!port->rport)
3407 ZFCP_LOG_NORMAL("failed registration of rport"
3408 "(adapter %s, wwpn=0x%016Lx)\n",
3409 zfcp_get_busid_by_port(port),
3410 port->wwpn);
Andreas Herrmann61c41822006-02-11 01:43:55 +01003411 else
3412 scsi_flush_work(adapter->scsi_host);
Andreas Herrmann3859f6a2005-08-27 11:07:54 -07003413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 zfcp_port_put(port);
3415 break;
3416 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3417 zfcp_adapter_put(adapter);
3418 break;
3419 default:
3420 break;
3421 }
3422}
3423
3424
3425/*
3426 * function:
3427 *
3428 * purpose:
3429 *
3430 * returns: FIXME
3431 */
3432static int
3433zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3434{
3435 int retval = 0;
3436 struct zfcp_port *port;
3437
3438 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3439 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3440 zfcp_erp_action_dismiss(&adapter->erp_action);
3441 else
3442 list_for_each_entry(port, &adapter->port_list_head, list)
3443 zfcp_erp_action_dismiss_port(port);
3444
3445 return retval;
3446}
3447
3448/*
3449 * function:
3450 *
3451 * purpose:
3452 *
3453 * returns: FIXME
3454 */
3455static int
3456zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3457{
3458 int retval = 0;
3459 struct zfcp_unit *unit;
3460 struct zfcp_adapter *adapter = port->adapter;
3461
3462 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3463 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3464 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3465 zfcp_erp_action_dismiss(&port->erp_action);
3466 else
3467 list_for_each_entry(unit, &port->unit_list_head, list)
3468 zfcp_erp_action_dismiss_unit(unit);
3469
3470 return retval;
3471}
3472
3473/*
3474 * function:
3475 *
3476 * purpose:
3477 *
3478 * returns: FIXME
3479 */
3480static int
3481zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3482{
3483 int retval = 0;
3484 struct zfcp_adapter *adapter = unit->port->adapter;
3485
3486 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3487 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3488 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3489 zfcp_erp_action_dismiss(&unit->erp_action);
3490
3491 return retval;
3492}
3493
3494/*
3495 * function:
3496 *
3497 * purpose: moves erp_action to 'erp running list'
3498 *
3499 * returns:
3500 */
3501static inline void
3502zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3503{
3504 struct zfcp_adapter *adapter = erp_action->adapter;
3505
3506 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3507 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3508 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3509}
3510
3511/*
3512 * function:
3513 *
3514 * purpose: moves erp_action to 'erp ready list'
3515 *
3516 * returns:
3517 */
3518static inline void
3519zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3520{
3521 struct zfcp_adapter *adapter = erp_action->adapter;
3522
3523 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3524 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3525 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3526}
3527
3528/*
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003529 * function: zfcp_erp_port_boxed
3530 *
3531 * purpose:
3532 */
3533void
3534zfcp_erp_port_boxed(struct zfcp_port *port)
3535{
3536 struct zfcp_adapter *adapter = port->adapter;
3537 unsigned long flags;
3538
3539 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3540 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3541 read_lock_irqsave(&zfcp_data.config_lock, flags);
3542 zfcp_erp_modify_port_status(port,
3543 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3544 ZFCP_SET);
3545 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3546 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
3547}
3548
3549/*
3550 * function: zfcp_erp_unit_boxed
3551 *
3552 * purpose:
3553 */
3554void
3555zfcp_erp_unit_boxed(struct zfcp_unit *unit)
3556{
3557 struct zfcp_adapter *adapter = unit->port->adapter;
3558
3559 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3560 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3561 zfcp_erp_modify_unit_status(unit,
3562 ZFCP_STATUS_COMMON_ACCESS_BOXED,
3563 ZFCP_SET);
3564 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
3565}
3566
3567/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 * function: zfcp_erp_port_access_denied
3569 *
3570 * purpose:
3571 */
3572void
3573zfcp_erp_port_access_denied(struct zfcp_port *port)
3574{
3575 struct zfcp_adapter *adapter = port->adapter;
3576 unsigned long flags;
3577
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003578 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3580 read_lock_irqsave(&zfcp_data.config_lock, flags);
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003581 zfcp_erp_modify_port_status(port,
3582 ZFCP_STATUS_COMMON_ERP_FAILED |
3583 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3584 ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3586}
3587
3588/*
3589 * function: zfcp_erp_unit_access_denied
3590 *
3591 * purpose:
3592 */
3593void
3594zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
3595{
3596 struct zfcp_adapter *adapter = unit->port->adapter;
3597
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003598 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003600 zfcp_erp_modify_unit_status(unit,
3601 ZFCP_STATUS_COMMON_ERP_FAILED |
3602 ZFCP_STATUS_COMMON_ACCESS_DENIED,
3603 ZFCP_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604}
3605
3606/*
3607 * function: zfcp_erp_adapter_access_changed
3608 *
3609 * purpose:
3610 */
3611void
3612zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
3613{
3614 struct zfcp_port *port;
3615 unsigned long flags;
3616
Maxim Shchetyninaef4a982005-09-13 21:51:16 +02003617 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3618 return;
3619
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003620 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
3622
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 read_lock_irqsave(&zfcp_data.config_lock, flags);
6f71d9b2005-04-10 23:04:28 -05003624 if (adapter->nameserver_port)
3625 zfcp_erp_port_access_changed(adapter->nameserver_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 list_for_each_entry(port, &adapter->port_list_head, list)
3627 if (port != adapter->nameserver_port)
3628 zfcp_erp_port_access_changed(port);
3629 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3630}
3631
3632/*
3633 * function: zfcp_erp_port_access_changed
3634 *
3635 * purpose:
3636 */
3637void
3638zfcp_erp_port_access_changed(struct zfcp_port *port)
3639{
3640 struct zfcp_adapter *adapter = port->adapter;
3641 struct zfcp_unit *unit;
3642
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003643 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3645
3646 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003647 &port->status) &&
3648 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 &port->status)) {
3650 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3651 list_for_each_entry(unit, &port->unit_list_head, list)
3652 zfcp_erp_unit_access_changed(unit);
3653 return;
3654 }
3655
3656 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3657 "(due to ACT update)\n",
3658 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3659 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3660 ZFCP_LOG_NORMAL("failed reopen of port"
3661 "(adapter %s, wwpn=0x%016Lx)\n",
3662 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3663}
3664
3665/*
3666 * function: zfcp_erp_unit_access_changed
3667 *
3668 * purpose:
3669 */
3670void
3671zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
3672{
3673 struct zfcp_adapter *adapter = unit->port->adapter;
3674
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003675 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3677
Andreas Herrmannd736a27b2005-06-13 13:23:57 +02003678 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3679 &unit->status) &&
3680 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3681 &unit->status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 return;
3683
3684 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3685 " on adapter %s (due to ACT update)\n",
3686 unit->fcp_lun, unit->port->wwpn,
3687 zfcp_get_busid_by_adapter(adapter));
3688 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
3689 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3690 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3691 zfcp_get_busid_by_adapter(adapter),
3692 unit->port->wwpn, unit->fcp_lun);
3693}
3694
3695#undef ZFCP_LOG_AREA