2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
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)
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.
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.
22 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
26 static int zfcp_erp_adisc(struct zfcp_port *);
27 static void zfcp_erp_adisc_handler(unsigned long);
29 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int, u8,
31 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int, u8,
33 static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int, u8, u64);
34 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int, u8, u64);
36 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int, u8,
38 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int, u8, u64);
40 static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
41 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
42 static void zfcp_erp_port_block(struct zfcp_port *, int);
43 static void zfcp_erp_port_unblock(struct zfcp_port *);
44 static void zfcp_erp_unit_block(struct zfcp_unit *, int);
45 static void zfcp_erp_unit_unblock(struct zfcp_unit *);
47 static int zfcp_erp_thread(void *);
49 static int zfcp_erp_strategy(struct zfcp_erp_action *);
51 static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
52 static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
53 static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
54 static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
55 static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
56 static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
57 static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
59 struct zfcp_unit *, int);
60 static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
61 static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
63 struct zfcp_unit *, int);
64 static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
65 static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
67 static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
68 static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
69 static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
70 static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
71 static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
72 static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
73 static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
74 static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
75 static int zfcp_erp_adapter_strategy_open_fsf_statusread(
76 struct zfcp_erp_action *);
78 static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
79 static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
81 static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
82 static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
83 static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
84 static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
85 static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
86 static int zfcp_erp_port_strategy_open_nameserver_wakeup(
87 struct zfcp_erp_action *);
88 static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
89 static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
90 static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
92 static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
93 static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
94 static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
95 static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
97 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
98 static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
99 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
100 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
102 static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
103 struct zfcp_port *, struct zfcp_unit *,
105 static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
106 static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
107 struct zfcp_port *, struct zfcp_unit *,
110 static void zfcp_erp_action_ready(struct zfcp_erp_action *);
111 static int zfcp_erp_action_exists(struct zfcp_erp_action *);
113 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
114 static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
116 static void zfcp_erp_memwait_handler(unsigned long);
119 * zfcp_close_qdio - close qdio queues for an adapter
121 static void zfcp_close_qdio(struct zfcp_adapter *adapter)
123 struct zfcp_qdio_queue *req_queue;
126 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
129 /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
130 req_queue = &adapter->request_queue;
131 write_lock_irq(&req_queue->queue_lock);
132 atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
133 write_unlock_irq(&req_queue->queue_lock);
135 debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
136 while (qdio_shutdown(adapter->ccw_device,
137 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
139 debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
141 /* cleanup used outbound sbals */
142 count = atomic_read(&req_queue->free_count);
143 if (count < QDIO_MAX_BUFFERS_PER_Q) {
144 first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
145 count = QDIO_MAX_BUFFERS_PER_Q - count;
146 zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
148 req_queue->free_index = 0;
149 atomic_set(&req_queue->free_count, 0);
150 req_queue->distance_from_int = 0;
151 adapter->response_queue.free_index = 0;
152 atomic_set(&adapter->response_queue.free_count, 0);
156 * zfcp_close_fsf - stop FSF operations for an adapter
158 * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
159 * requests waiting for completion; especially this returns SCSI commands
162 static void zfcp_close_fsf(struct zfcp_adapter *adapter)
164 /* close queues to ensure that buffers are not accessed by adapter */
165 zfcp_close_qdio(adapter);
166 zfcp_fsf_req_dismiss_all(adapter);
167 /* reset FSF request sequence number */
168 adapter->fsf_req_seq_no = 0;
169 /* all ports and units are closed */
170 zfcp_erp_modify_adapter_status(adapter, 24, 0,
171 ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
175 * zfcp_fsf_request_timeout_handler - called if a request timed out
176 * @data: pointer to adapter for handler function
178 * This function needs to be called if requests (ELS, Generic Service,
179 * or SCSI commands) exceed a certain time limit. The assumption is
180 * that after the time limit the adapter get stuck. So we trigger a reopen of
183 static void zfcp_fsf_request_timeout_handler(unsigned long data)
185 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
186 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62, 0);
189 void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
191 fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
192 fsf_req->timer.data = (unsigned long) fsf_req->adapter;
193 fsf_req->timer.expires = jiffies + timeout;
194 add_timer(&fsf_req->timer);
200 * purpose: called if an adapter failed,
201 * initiates adapter recovery which is done
204 * returns: 0 - initiated action successfully
205 * <0 - failed to initiate action
207 static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter,
208 int clear_mask, u8 id, u64 ref)
212 debug_text_event(adapter->erp_dbf, 5, "a_ro");
213 ZFCP_LOG_DEBUG("reopen adapter %s\n",
214 zfcp_get_busid_by_adapter(adapter));
216 zfcp_erp_adapter_block(adapter, clear_mask);
218 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
219 ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
220 zfcp_get_busid_by_adapter(adapter));
221 debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
222 /* ensure propagation of failed status to new devices */
223 zfcp_erp_adapter_failed(adapter, 13, 0);
227 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
228 adapter, NULL, NULL, id, ref);
237 * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
238 * used to ensure the correct locking
240 * returns: 0 - initiated action successfully
241 * <0 - failed to initiate action
243 int zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask,
249 read_lock_irqsave(&zfcp_data.config_lock, flags);
250 write_lock(&adapter->erp_lock);
251 retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask, id, ref);
252 write_unlock(&adapter->erp_lock);
253 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
258 int zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask,
263 retval = zfcp_erp_adapter_reopen(adapter,
264 ZFCP_STATUS_COMMON_RUNNING |
265 ZFCP_STATUS_COMMON_ERP_FAILED |
266 clear_mask, id, ref);
271 int zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask, u8 id,
276 retval = zfcp_erp_port_reopen(port,
277 ZFCP_STATUS_COMMON_RUNNING |
278 ZFCP_STATUS_COMMON_ERP_FAILED |
279 clear_mask, id, ref);
284 int zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask, u8 id,
289 retval = zfcp_erp_unit_reopen(unit,
290 ZFCP_STATUS_COMMON_RUNNING |
291 ZFCP_STATUS_COMMON_ERP_FAILED |
292 clear_mask, id, ref);
299 * zfcp_erp_adisc - send ADISC ELS command
300 * @port: port structure
303 zfcp_erp_adisc(struct zfcp_port *port)
305 struct zfcp_adapter *adapter = port->adapter;
306 struct zfcp_send_els *send_els;
307 struct zfcp_ls_adisc *adisc;
308 void *address = NULL;
311 send_els = kzalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
312 if (send_els == NULL)
315 send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
316 if (send_els->req == NULL)
318 sg_init_table(send_els->req, 1);
320 send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
321 if (send_els->resp == NULL)
323 sg_init_table(send_els->resp, 1);
325 address = (void *) get_zeroed_page(GFP_ATOMIC);
329 zfcp_address_to_sg(address, send_els->req, sizeof(struct zfcp_ls_adisc));
330 address += PAGE_SIZE >> 1;
331 zfcp_address_to_sg(address, send_els->resp, sizeof(struct zfcp_ls_adisc_acc));
332 send_els->req_count = send_els->resp_count = 1;
334 send_els->adapter = adapter;
335 send_els->port = port;
336 send_els->d_id = port->d_id;
337 send_els->handler = zfcp_erp_adisc_handler;
338 send_els->handler_data = (unsigned long) send_els;
340 adisc = zfcp_sg_to_address(send_els->req);
341 send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
343 /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
344 without FC-AL-2 capability, so we don't set it */
345 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
346 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
347 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
348 ZFCP_LOG_INFO("ADISC request from s_id 0x%06x to d_id 0x%06x "
349 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
350 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
351 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
352 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
355 retval = zfcp_fsf_send_els(send_els);
357 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
358 "0x%06x on adapter %s\n", send_els->d_id,
359 zfcp_get_busid_by_adapter(adapter));
369 __free_pages(sg_page(send_els->req), 0);
370 if (send_els != NULL) {
371 kfree(send_els->req);
372 kfree(send_els->resp);
381 * zfcp_erp_adisc_handler - handler for ADISC ELS command
382 * @data: pointer to struct zfcp_send_els
384 * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
387 zfcp_erp_adisc_handler(unsigned long data)
389 struct zfcp_send_els *send_els;
390 struct zfcp_port *port;
391 struct zfcp_adapter *adapter;
393 struct zfcp_ls_adisc_acc *adisc;
395 send_els = (struct zfcp_send_els *) data;
396 adapter = send_els->adapter;
397 port = send_els->port;
398 d_id = send_els->d_id;
400 /* request rejected or timed out */
401 if (send_els->status != 0) {
402 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
403 "force physical port reopen "
404 "(adapter %s, port d_id=0x%06x)\n",
405 zfcp_get_busid_by_adapter(adapter), d_id);
406 debug_text_event(adapter->erp_dbf, 3, "forcreop");
407 if (zfcp_erp_port_forced_reopen(port, 0, 63, 0))
408 ZFCP_LOG_NORMAL("failed reopen of port "
409 "(adapter %s, wwpn=0x%016Lx)\n",
410 zfcp_get_busid_by_port(port),
415 adisc = zfcp_sg_to_address(send_els->resp);
417 ZFCP_LOG_INFO("ADISC response from d_id 0x%06x to s_id "
418 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
419 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
420 d_id, fc_host_port_id(adapter->scsi_host),
421 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
422 adisc->hard_nport_id, adisc->nport_id);
424 /* set wwnn for port */
426 port->wwnn = adisc->wwnn;
428 if (port->wwpn != adisc->wwpn) {
429 ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
430 "port (adapter %s, wwpn=0x%016Lx, "
431 "adisc_resp_wwpn=0x%016Lx)\n",
432 zfcp_get_busid_by_port(port),
433 port->wwpn, (wwn_t) adisc->wwpn);
434 if (zfcp_erp_port_reopen(port, 0, 64, 0))
435 ZFCP_LOG_NORMAL("failed reopen of port "
436 "(adapter %s, wwpn=0x%016Lx)\n",
437 zfcp_get_busid_by_port(port),
443 __free_pages(sg_page(send_els->req), 0);
444 kfree(send_els->req);
445 kfree(send_els->resp);
451 * zfcp_test_link - lightweight link test procedure
452 * @port: port to be tested
454 * Test status of a link to a remote port using the ELS command ADISC.
457 zfcp_test_link(struct zfcp_port *port)
462 retval = zfcp_erp_adisc(port);
463 if (retval != 0 && retval != -EBUSY) {
465 ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
466 "on adapter %s\n ", port->wwpn,
467 zfcp_get_busid_by_port(port));
468 retval = zfcp_erp_port_forced_reopen(port, 0, 65, 0);
470 ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
471 "on adapter %s failed\n", port->wwpn,
472 zfcp_get_busid_by_port(port));
484 * purpose: called if a port failed to be opened normally
485 * initiates Forced Reopen recovery which is done
488 * returns: 0 - initiated action successfully
489 * <0 - failed to initiate action
491 static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port,
492 int clear_mask, u8 id, u64 ref)
495 struct zfcp_adapter *adapter = port->adapter;
497 debug_text_event(adapter->erp_dbf, 5, "pf_ro");
498 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
500 ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
501 port->wwpn, zfcp_get_busid_by_port(port));
503 zfcp_erp_port_block(port, clear_mask);
505 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
506 ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
507 "on adapter %s\n", port->wwpn,
508 zfcp_get_busid_by_port(port));
509 debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
510 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
515 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
516 port->adapter, port, NULL, id, ref);
525 * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
526 * used to ensure the correct locking
528 * returns: 0 - initiated action successfully
529 * <0 - failed to initiate action
531 int zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask, u8 id,
536 struct zfcp_adapter *adapter;
538 adapter = port->adapter;
539 read_lock_irqsave(&zfcp_data.config_lock, flags);
540 write_lock(&adapter->erp_lock);
541 retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask, id,
543 write_unlock(&adapter->erp_lock);
544 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
552 * purpose: called if a port is to be opened
553 * initiates Reopen recovery which is done
556 * returns: 0 - initiated action successfully
557 * <0 - failed to initiate action
559 static int zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask,
563 struct zfcp_adapter *adapter = port->adapter;
565 debug_text_event(adapter->erp_dbf, 5, "p_ro");
566 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
568 ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
569 port->wwpn, zfcp_get_busid_by_port(port));
571 zfcp_erp_port_block(port, clear_mask);
573 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
574 ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
575 "on adapter %s\n", port->wwpn,
576 zfcp_get_busid_by_port(port));
577 debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
578 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
579 /* ensure propagation of failed status to new devices */
580 zfcp_erp_port_failed(port, 14, 0);
585 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
586 port->adapter, port, NULL, id, ref);
593 * zfcp_erp_port_reopen - initiate reopen of a remote port
594 * @port: port to be reopened
595 * @clear_mask: specifies flags in port status to be cleared
596 * Return: 0 on success, < 0 on error
598 * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
599 * correct locking. An error recovery task is initiated to do the reopen.
600 * To wait for the completion of the reopen zfcp_erp_wait should be used.
602 int zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask, u8 id, u64 ref)
606 struct zfcp_adapter *adapter = port->adapter;
608 read_lock_irqsave(&zfcp_data.config_lock, flags);
609 write_lock(&adapter->erp_lock);
610 retval = zfcp_erp_port_reopen_internal(port, clear_mask, id, ref);
611 write_unlock(&adapter->erp_lock);
612 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
620 * purpose: called if a unit is to be opened
621 * initiates Reopen recovery which is done
624 * returns: 0 - initiated action successfully
625 * <0 - failed to initiate action
627 static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask,
631 struct zfcp_adapter *adapter = unit->port->adapter;
633 debug_text_event(adapter->erp_dbf, 5, "u_ro");
634 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
635 ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
636 "on adapter %s\n", unit->fcp_lun,
637 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
639 zfcp_erp_unit_block(unit, clear_mask);
641 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
642 ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
643 "on port 0x%016Lx on adapter %s\n",
644 unit->fcp_lun, unit->port->wwpn,
645 zfcp_get_busid_by_unit(unit));
646 debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
647 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
653 retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
654 adapter, unit->port, unit, id, ref);
660 * zfcp_erp_unit_reopen - initiate reopen of a unit
661 * @unit: unit to be reopened
662 * @clear_mask: specifies flags in unit status to be cleared
663 * Return: 0 on success, < 0 on error
665 * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
666 * locking. An error recovery task is initiated to do the reopen.
667 * To wait for the completion of the reopen zfcp_erp_wait should be used.
669 int zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask, u8 id, u64 ref)
673 struct zfcp_adapter *adapter;
674 struct zfcp_port *port;
677 adapter = port->adapter;
679 read_lock_irqsave(&zfcp_data.config_lock, flags);
680 write_lock(&adapter->erp_lock);
681 retval = zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
682 write_unlock(&adapter->erp_lock);
683 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
689 * zfcp_erp_adapter_block - mark adapter as blocked, block scsi requests
691 static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
693 debug_text_event(adapter->erp_dbf, 6, "a_bl");
694 zfcp_erp_modify_adapter_status(adapter, 15, 0,
695 ZFCP_STATUS_COMMON_UNBLOCKED |
696 clear_mask, ZFCP_CLEAR);
699 /* FIXME: isn't really atomic */
701 * returns the mask which has not been set so far, i.e.
702 * 0 if no bit has been changed, !0 if some bit has been changed
704 static int atomic_test_and_set_mask(unsigned long mask, atomic_t *v)
706 int changed_bits = (atomic_read(v) /*XOR*/^ mask) & mask;
707 atomic_set_mask(mask, v);
711 /* FIXME: isn't really atomic */
713 * returns the mask which has not been cleared so far, i.e.
714 * 0 if no bit has been changed, !0 if some bit has been changed
716 static int atomic_test_and_clear_mask(unsigned long mask, atomic_t *v)
718 int changed_bits = atomic_read(v) & mask;
719 atomic_clear_mask(mask, v);
724 * zfcp_erp_adapter_unblock - mark adapter as unblocked, allow scsi requests
726 static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
728 debug_text_event(adapter->erp_dbf, 6, "a_ubl");
729 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
731 zfcp_rec_dbf_event_adapter(16, 0, adapter);
737 * purpose: disable I/O,
738 * return any open requests and clean them up,
739 * aim: no pending and incoming I/O
744 zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
746 struct zfcp_adapter *adapter = port->adapter;
748 debug_text_event(adapter->erp_dbf, 6, "p_bl");
749 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
750 zfcp_erp_modify_port_status(port, 17, 0,
751 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
758 * purpose: enable I/O
763 zfcp_erp_port_unblock(struct zfcp_port *port)
765 struct zfcp_adapter *adapter = port->adapter;
767 debug_text_event(adapter->erp_dbf, 6, "p_ubl");
768 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
769 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
771 zfcp_rec_dbf_event_port(18, 0, port);
777 * purpose: disable I/O,
778 * return any open requests and clean them up,
779 * aim: no pending and incoming I/O
784 zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
786 struct zfcp_adapter *adapter = unit->port->adapter;
788 debug_text_event(adapter->erp_dbf, 6, "u_bl");
789 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
790 zfcp_erp_modify_unit_status(unit, 19, 0,
791 ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
798 * purpose: enable I/O
803 zfcp_erp_unit_unblock(struct zfcp_unit *unit)
805 struct zfcp_adapter *adapter = unit->port->adapter;
807 debug_text_event(adapter->erp_dbf, 6, "u_ubl");
808 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
809 if (atomic_test_and_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
811 zfcp_rec_dbf_event_unit(20, 0, unit);
815 zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
817 struct zfcp_adapter *adapter = erp_action->adapter;
819 debug_text_event(adapter->erp_dbf, 4, "a_ar");
820 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
822 zfcp_erp_action_to_ready(erp_action);
823 up(&adapter->erp_ready_sem);
824 zfcp_rec_dbf_event_thread(2, adapter, 0);
832 * returns: <0 erp_action not found in any list
833 * ZFCP_ERP_ACTION_READY erp_action is in ready list
834 * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
836 * locks: erp_lock must be held
839 zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
841 int retval = -EINVAL;
842 struct list_head *entry;
843 struct zfcp_erp_action *entry_erp_action;
844 struct zfcp_adapter *adapter = erp_action->adapter;
846 /* search in running list */
847 list_for_each(entry, &adapter->erp_running_head) {
849 list_entry(entry, struct zfcp_erp_action, list);
850 if (entry_erp_action == erp_action) {
851 retval = ZFCP_ERP_ACTION_RUNNING;
855 /* search in ready list */
856 list_for_each(entry, &adapter->erp_ready_head) {
858 list_entry(entry, struct zfcp_erp_action, list);
859 if (entry_erp_action == erp_action) {
860 retval = ZFCP_ERP_ACTION_READY;
870 * purpose: checks current status of action (timed out, dismissed, ...)
871 * and does appropriate preparations (dismiss fsf request, ...)
873 * locks: called under erp_lock (disabled interrupts)
876 zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
878 struct zfcp_adapter *adapter = erp_action->adapter;
880 if (erp_action->fsf_req) {
881 /* take lock to ensure that request is not deleted meanwhile */
882 spin_lock(&adapter->req_list_lock);
883 if (zfcp_reqlist_find_safe(adapter, erp_action->fsf_req) &&
884 erp_action->fsf_req->erp_action == erp_action) {
885 /* fsf_req still exists */
886 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
887 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
888 sizeof (unsigned long));
889 /* dismiss fsf_req of timed out/dismissed erp_action */
890 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
891 ZFCP_STATUS_ERP_TIMEDOUT)) {
892 debug_text_event(adapter->erp_dbf, 3,
894 erp_action->fsf_req->status |=
895 ZFCP_STATUS_FSFREQ_DISMISSED;
897 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
898 ZFCP_LOG_NORMAL("error: erp step timed out "
899 "(action=%d, fsf_req=%p)\n ",
901 erp_action->fsf_req);
904 * If fsf_req is neither dismissed nor completed
905 * then keep it running asynchronously and don't mess
906 * with the association of erp_action and fsf_req.
908 if (erp_action->fsf_req->status &
909 (ZFCP_STATUS_FSFREQ_COMPLETED |
910 ZFCP_STATUS_FSFREQ_DISMISSED)) {
911 /* forget about association between fsf_req
913 erp_action->fsf_req = NULL;
916 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
918 * even if this fsf_req has gone, forget about
919 * association between erp_action and fsf_req
921 erp_action->fsf_req = NULL;
923 spin_unlock(&adapter->req_list_lock);
925 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
929 * zfcp_erp_async_handler_nolock - complete erp_action
931 * Used for normal completion, time-out, dismissal and failure after
932 * low memory condition.
934 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
935 unsigned long set_mask)
937 struct zfcp_adapter *adapter = erp_action->adapter;
939 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
940 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
941 debug_event(adapter->erp_dbf, 2, &erp_action->action,
943 erp_action->status |= set_mask;
944 zfcp_erp_action_ready(erp_action);
946 /* action is ready or gone - nothing to do */
947 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
948 debug_event(adapter->erp_dbf, 3, &erp_action->action,
954 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
956 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
957 unsigned long set_mask)
959 struct zfcp_adapter *adapter = erp_action->adapter;
962 write_lock_irqsave(&adapter->erp_lock, flags);
963 zfcp_erp_async_handler_nolock(erp_action, set_mask);
964 write_unlock_irqrestore(&adapter->erp_lock, flags);
968 * purpose: is called for erp_action which was slept waiting for
969 * memory becoming avaliable,
970 * will trigger that this action will be continued
973 zfcp_erp_memwait_handler(unsigned long data)
975 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
976 struct zfcp_adapter *adapter = erp_action->adapter;
978 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
979 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
981 zfcp_erp_async_handler(erp_action, 0);
985 * purpose: is called if an asynchronous erp step timed out,
986 * action gets an appropriate flag and will be processed
989 static void zfcp_erp_timeout_handler(unsigned long data)
991 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
992 struct zfcp_adapter *adapter = erp_action->adapter;
994 debug_text_event(adapter->erp_dbf, 2, "a_th");
995 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
997 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1001 * zfcp_erp_action_dismiss - dismiss an erp_action
1003 * adapter->erp_lock must be held
1005 * Dismissal of an erp_action is usually required if an erp_action of
1006 * higher priority is generated.
1008 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1010 struct zfcp_adapter *adapter = erp_action->adapter;
1012 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1013 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1015 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
1016 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
1017 zfcp_erp_action_ready(erp_action);
1021 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1025 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1027 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1029 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1031 zfcp_get_busid_by_adapter(adapter));
1032 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1034 wait_event(adapter->erp_thread_wqh,
1035 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1037 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1040 return (retval < 0);
1050 * context: process (i.e. proc-fs or rmmod/insmod)
1052 * note: The caller of this routine ensures that the specified
1053 * adapter has been shut down and that this operation
1054 * has been completed. Thus, there are no pending erp_actions
1055 * which would need to be handled here.
1058 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1062 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1063 up(&adapter->erp_ready_sem);
1064 zfcp_rec_dbf_event_thread(2, adapter, 1);
1066 wait_event(adapter->erp_thread_wqh,
1067 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1070 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1073 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1079 * purpose: is run as a kernel thread,
1080 * goes through list of error recovery actions of associated adapter
1081 * and delegates single action to execution
1086 zfcp_erp_thread(void *data)
1088 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1089 struct list_head *next;
1090 struct zfcp_erp_action *erp_action;
1091 unsigned long flags;
1093 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1094 /* Block all signals */
1095 siginitsetinv(¤t->blocked, 0);
1096 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1097 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1098 wake_up(&adapter->erp_thread_wqh);
1100 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1101 &adapter->status)) {
1103 write_lock_irqsave(&adapter->erp_lock, flags);
1104 next = adapter->erp_ready_head.next;
1105 write_unlock_irqrestore(&adapter->erp_lock, flags);
1107 if (next != &adapter->erp_ready_head) {
1109 list_entry(next, struct zfcp_erp_action, list);
1111 * process action (incl. [re]moving it
1112 * from 'ready' queue)
1114 zfcp_erp_strategy(erp_action);
1118 * sleep as long as there is nothing to do, i.e.
1119 * no action in 'ready' queue to be processed and
1120 * thread is not to be killed
1122 zfcp_rec_dbf_event_thread(4, adapter, 1);
1123 down_interruptible(&adapter->erp_ready_sem);
1124 zfcp_rec_dbf_event_thread(5, adapter, 1);
1125 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1128 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1129 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1130 wake_up(&adapter->erp_thread_wqh);
1138 * purpose: drives single error recovery action and schedules higher and
1139 * subordinate actions, if necessary
1141 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1142 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1143 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1144 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1145 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1148 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1151 struct zfcp_adapter *adapter = erp_action->adapter;
1152 struct zfcp_port *port = erp_action->port;
1153 struct zfcp_unit *unit = erp_action->unit;
1154 int action = erp_action->action;
1155 u32 status = erp_action->status;
1156 unsigned long flags;
1158 /* serialise dismissing, timing out, moving, enqueueing */
1159 read_lock_irqsave(&zfcp_data.config_lock, flags);
1160 write_lock(&adapter->erp_lock);
1162 /* dequeue dismissed action and leave, if required */
1163 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1164 if (retval == ZFCP_ERP_DISMISSED) {
1165 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1170 * move action to 'running' queue before processing it
1171 * (to avoid a race condition regarding moving the
1172 * action to the 'running' queue and back)
1174 zfcp_erp_action_to_running(erp_action);
1177 * try to process action as far as possible,
1178 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1179 * afterwards the lock is required again for the following reasons:
1180 * - dequeueing of finished action and enqueueing of
1181 * follow-up actions must be atomic so that any other
1182 * reopen-routine does not believe there is nothing to do
1183 * and that it is safe to enqueue something else,
1184 * - we want to force any control thread which is dismissing
1185 * actions to finish this before we decide about
1186 * necessary steps to be taken here further
1188 write_unlock(&adapter->erp_lock);
1189 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1190 retval = zfcp_erp_strategy_do_action(erp_action);
1191 read_lock_irqsave(&zfcp_data.config_lock, flags);
1192 write_lock(&adapter->erp_lock);
1195 * check for dismissed status again to avoid follow-up actions,
1196 * failing of targets and so on for dismissed actions,
1197 * we go through down() here because there has been an up()
1199 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1200 retval = ZFCP_ERP_CONTINUES;
1203 case ZFCP_ERP_NOMEM:
1204 /* no memory to continue immediately, let it sleep */
1205 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1206 ++adapter->erp_low_mem_count;
1207 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1209 /* This condition is true if there is no memory available
1210 for any erp_action on this adapter. This implies that there
1211 are no elements in the memory pool(s) left for erp_actions.
1212 This might happen if an erp_action that used a memory pool
1213 element was timed out.
1215 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1216 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1217 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1218 "restarting I/O on adapter %s "
1219 "to free mempool\n",
1220 zfcp_get_busid_by_adapter(adapter));
1221 zfcp_erp_adapter_reopen_internal(adapter, 0, 66, 0);
1223 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1224 retval = zfcp_erp_strategy_memwait(erp_action);
1227 case ZFCP_ERP_CONTINUES:
1228 /* leave since this action runs asynchronously */
1229 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1230 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1231 --adapter->erp_low_mem_count;
1232 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1236 /* ok, finished action (whatever its result is) */
1238 /* check for unrecoverable targets */
1239 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1241 /* action must be dequeued (here to allow for further ones) */
1242 zfcp_erp_action_dequeue(erp_action);
1245 * put this target through the erp mill again if someone has
1246 * requested to change the status of a target being online
1247 * to offline or the other way around
1248 * (old retval is preserved if nothing has to be done here)
1250 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1251 port, unit, retval);
1254 * leave if target is in permanent error state or if
1255 * action is repeated in order to process state change
1257 if (retval == ZFCP_ERP_EXIT) {
1258 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1262 /* trigger follow up actions */
1263 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1266 write_unlock(&adapter->erp_lock);
1267 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1269 if (retval != ZFCP_ERP_CONTINUES)
1270 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1273 * a few tasks remain when the erp queues are empty
1274 * (don't do that if the last action evaluated was dismissed
1275 * since this clearly indicates that there is more to come) :
1276 * - close the name server port if it is open yet
1277 * (enqueues another [probably] final action)
1278 * - otherwise, wake up whoever wants to be woken when we are
1281 if (retval != ZFCP_ERP_DISMISSED)
1282 zfcp_erp_strategy_check_queues(adapter);
1284 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1294 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1295 * retval - otherwise
1298 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1300 struct zfcp_adapter *adapter = erp_action->adapter;
1302 zfcp_erp_strategy_check_fsfreq(erp_action);
1304 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1305 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1306 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1307 zfcp_erp_action_dequeue(erp_action);
1308 retval = ZFCP_ERP_DISMISSED;
1310 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1316 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1318 int retval = ZFCP_ERP_FAILED;
1319 struct zfcp_adapter *adapter = erp_action->adapter;
1322 * try to execute/continue action as far as possible,
1323 * note: no lock in subsequent strategy routines
1324 * (this allows these routine to call schedule, e.g.
1325 * kmalloc with such flags or qdio_initialize & friends)
1326 * Note: in case of timeout, the separate strategies will fail
1327 * anyhow. No need for a special action. Even worse, a nameserver
1328 * failure would not wake up waiting ports without the call.
1330 switch (erp_action->action) {
1332 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1333 retval = zfcp_erp_adapter_strategy(erp_action);
1336 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1337 retval = zfcp_erp_port_forced_strategy(erp_action);
1340 case ZFCP_ERP_ACTION_REOPEN_PORT:
1341 retval = zfcp_erp_port_strategy(erp_action);
1344 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1345 retval = zfcp_erp_unit_strategy(erp_action);
1349 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1350 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1352 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1353 "adapter %s (action=%d)\n",
1354 zfcp_get_busid_by_adapter(erp_action->adapter),
1355 erp_action->action);
1364 * purpose: triggers retry of this action after a certain amount of time
1365 * by means of timer provided by erp_action
1367 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1370 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1372 int retval = ZFCP_ERP_CONTINUES;
1373 struct zfcp_adapter *adapter = erp_action->adapter;
1375 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1376 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1377 init_timer(&erp_action->timer);
1378 erp_action->timer.function = zfcp_erp_memwait_handler;
1379 erp_action->timer.data = (unsigned long) erp_action;
1380 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1381 add_timer(&erp_action->timer);
1387 * function: zfcp_erp_adapter_failed
1389 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1393 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, u64 ref)
1395 zfcp_erp_modify_adapter_status(adapter, id, ref,
1396 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1397 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1398 zfcp_get_busid_by_adapter(adapter));
1399 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1403 * function: zfcp_erp_port_failed
1405 * purpose: sets the port and all underlying devices to ERP_FAILED
1409 zfcp_erp_port_failed(struct zfcp_port *port, u8 id, u64 ref)
1411 zfcp_erp_modify_port_status(port, id, ref,
1412 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1414 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1415 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1416 "port d_id=0x%06x)\n",
1417 zfcp_get_busid_by_port(port), port->d_id);
1419 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1420 zfcp_get_busid_by_port(port), port->wwpn);
1422 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1423 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1427 * function: zfcp_erp_unit_failed
1429 * purpose: sets the unit to ERP_FAILED
1433 zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, u64 ref)
1435 zfcp_erp_modify_unit_status(unit, id, ref,
1436 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1438 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1439 " on adapter %s\n", unit->fcp_lun,
1440 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1441 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1442 debug_event(unit->port->adapter->erp_dbf, 2,
1443 &unit->fcp_lun, sizeof (fcp_lun_t));
1447 * function: zfcp_erp_strategy_check_target
1449 * purpose: increments the erp action count on the device currently in
1450 * recovery if the action failed or resets the count in case of
1451 * success. If a maximum count is exceeded the device is marked
1453 * The 'blocked' state of a target which has been recovered
1454 * successfully is reset.
1456 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1457 * ZFCP_ERP_SUCCEEDED - action finished successfully
1458 * ZFCP_ERP_EXIT - action failed and will not continue
1461 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1463 struct zfcp_adapter *adapter = erp_action->adapter;
1464 struct zfcp_port *port = erp_action->port;
1465 struct zfcp_unit *unit = erp_action->unit;
1467 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1468 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1469 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1471 switch (erp_action->action) {
1473 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1474 result = zfcp_erp_strategy_check_unit(unit, result);
1477 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1478 case ZFCP_ERP_ACTION_REOPEN_PORT:
1479 result = zfcp_erp_strategy_check_port(port, result);
1482 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1483 result = zfcp_erp_strategy_check_adapter(adapter, result);
1491 zfcp_erp_strategy_statechange(int action,
1493 struct zfcp_adapter *adapter,
1494 struct zfcp_port *port,
1495 struct zfcp_unit *unit, int retval)
1497 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1498 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1502 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1503 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1505 zfcp_erp_adapter_reopen_internal(adapter,
1506 ZFCP_STATUS_COMMON_ERP_FAILED,
1508 retval = ZFCP_ERP_EXIT;
1512 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1513 case ZFCP_ERP_ACTION_REOPEN_PORT:
1514 if (zfcp_erp_strategy_statechange_detected(&port->status,
1516 zfcp_erp_port_reopen_internal(port,
1517 ZFCP_STATUS_COMMON_ERP_FAILED,
1519 retval = ZFCP_ERP_EXIT;
1523 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1524 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1526 zfcp_erp_unit_reopen_internal(unit,
1527 ZFCP_STATUS_COMMON_ERP_FAILED,
1529 retval = ZFCP_ERP_EXIT;
1538 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1541 /* take it online */
1542 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1543 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1544 /* take it offline */
1545 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1546 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1550 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1552 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1553 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1554 sizeof (fcp_lun_t));
1557 case ZFCP_ERP_SUCCEEDED :
1558 atomic_set(&unit->erp_counter, 0);
1559 zfcp_erp_unit_unblock(unit);
1561 case ZFCP_ERP_FAILED :
1562 atomic_inc(&unit->erp_counter);
1563 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1564 zfcp_erp_unit_failed(unit, 21, 0);
1566 case ZFCP_ERP_EXIT :
1571 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1572 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1573 result = ZFCP_ERP_EXIT;
1580 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1582 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1583 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1586 case ZFCP_ERP_SUCCEEDED :
1587 atomic_set(&port->erp_counter, 0);
1588 zfcp_erp_port_unblock(port);
1590 case ZFCP_ERP_FAILED :
1591 atomic_inc(&port->erp_counter);
1592 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1593 zfcp_erp_port_failed(port, 22, 0);
1595 case ZFCP_ERP_EXIT :
1600 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1601 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1602 result = ZFCP_ERP_EXIT;
1609 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1611 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1614 case ZFCP_ERP_SUCCEEDED :
1615 atomic_set(&adapter->erp_counter, 0);
1616 zfcp_erp_adapter_unblock(adapter);
1618 case ZFCP_ERP_FAILED :
1619 atomic_inc(&adapter->erp_counter);
1620 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1621 zfcp_erp_adapter_failed(adapter, 23, 0);
1623 case ZFCP_ERP_EXIT :
1628 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1629 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1630 result = ZFCP_ERP_EXIT;
1636 struct zfcp_erp_add_work {
1637 struct zfcp_unit *unit;
1638 struct work_struct work;
1642 * zfcp_erp_scsi_scan
1643 * @data: pointer to a struct zfcp_erp_add_work
1645 * Registers a logical unit with the SCSI stack.
1647 static void zfcp_erp_scsi_scan(struct work_struct *work)
1649 struct zfcp_erp_add_work *p =
1650 container_of(work, struct zfcp_erp_add_work, work);
1651 struct zfcp_unit *unit = p->unit;
1652 struct fc_rport *rport = unit->port->rport;
1653 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1655 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1656 zfcp_unit_put(unit);
1661 * zfcp_erp_schedule_work
1662 * @unit: pointer to unit which should be registered with SCSI stack
1664 * Schedules work which registers a unit with the SCSI stack
1667 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1669 struct zfcp_erp_add_work *p;
1671 p = kzalloc(sizeof(*p), GFP_KERNEL);
1673 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1674 "the FCP-LUN 0x%Lx connected to "
1675 "the port with WWPN 0x%Lx connected to "
1676 "the adapter %s with the SCSI stack.\n",
1679 zfcp_get_busid_by_unit(unit));
1683 zfcp_unit_get(unit);
1684 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1685 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1687 schedule_work(&p->work);
1693 * purpose: remaining things in good cases,
1694 * escalation in bad cases
1699 zfcp_erp_strategy_followup_actions(int action,
1700 struct zfcp_adapter *adapter,
1701 struct zfcp_port *port,
1702 struct zfcp_unit *unit, int status)
1704 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1705 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1707 /* initiate follow-up actions depending on success of finished action */
1710 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1711 if (status == ZFCP_ERP_SUCCEEDED)
1712 zfcp_erp_port_reopen_all_internal(adapter, 0, 70, 0);
1714 zfcp_erp_adapter_reopen_internal(adapter, 0, 71, 0);
1717 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1718 if (status == ZFCP_ERP_SUCCEEDED)
1719 zfcp_erp_port_reopen_internal(port, 0, 72, 0);
1721 zfcp_erp_adapter_reopen_internal(adapter, 0, 73, 0);
1724 case ZFCP_ERP_ACTION_REOPEN_PORT:
1725 if (status == ZFCP_ERP_SUCCEEDED)
1726 zfcp_erp_unit_reopen_all_internal(port, 0, 74, 0);
1728 zfcp_erp_port_forced_reopen_internal(port, 0, 75, 0);
1731 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1732 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1733 if (status != ZFCP_ERP_SUCCEEDED)
1734 zfcp_erp_port_reopen_internal(unit->port, 0, 76, 0);
1742 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1744 unsigned long flags;
1746 read_lock_irqsave(&zfcp_data.config_lock, flags);
1747 read_lock(&adapter->erp_lock);
1748 if (list_empty(&adapter->erp_ready_head) &&
1749 list_empty(&adapter->erp_running_head)) {
1750 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1751 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1753 wake_up(&adapter->erp_done_wqh);
1755 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1756 read_unlock(&adapter->erp_lock);
1757 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1763 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1764 * @adapter: adapter for which to wait for completion of its error recovery
1768 zfcp_erp_wait(struct zfcp_adapter *adapter)
1772 wait_event(adapter->erp_done_wqh,
1773 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1779 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1780 u64 ref, u32 mask, int set_or_clear)
1782 struct zfcp_port *port;
1783 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1785 if (set_or_clear == ZFCP_SET) {
1786 changed = atomic_test_and_set_mask(mask, &adapter->status);
1787 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1789 changed = atomic_test_and_clear_mask(mask, &adapter->status);
1790 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1791 atomic_set(&adapter->erp_counter, 0);
1792 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1795 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1796 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1798 /* Deal with all underlying devices, only pass common_mask */
1800 list_for_each_entry(port, &adapter->port_list_head, list)
1801 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1806 * function: zfcp_erp_modify_port_status
1808 * purpose: sets the port and all underlying devices to ERP_FAILED
1811 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, u64 ref,
1812 u32 mask, int set_or_clear)
1814 struct zfcp_unit *unit;
1815 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1817 if (set_or_clear == ZFCP_SET) {
1818 changed = atomic_test_and_set_mask(mask, &port->status);
1819 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1821 changed = atomic_test_and_clear_mask(mask, &port->status);
1822 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1823 atomic_set(&port->erp_counter, 0);
1824 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1827 zfcp_rec_dbf_event_port(id, ref, port);
1828 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1829 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1831 /* Modify status of all underlying devices, only pass common mask */
1833 list_for_each_entry(unit, &port->unit_list_head, list)
1834 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1839 * function: zfcp_erp_modify_unit_status
1841 * purpose: sets the unit to ERP_FAILED
1844 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, u64 ref,
1845 u32 mask, int set_or_clear)
1849 if (set_or_clear == ZFCP_SET) {
1850 changed = atomic_test_and_set_mask(mask, &unit->status);
1851 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1853 changed = atomic_test_and_clear_mask(mask, &unit->status);
1854 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1855 atomic_set(&unit->erp_counter, 0);
1857 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1860 zfcp_rec_dbf_event_unit(id, ref, unit);
1861 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1862 sizeof (fcp_lun_t));
1863 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1869 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1870 * used to ensure the correct locking
1872 * returns: 0 - initiated action successfully
1873 * <0 - failed to initiate action
1875 int zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask,
1879 unsigned long flags;
1881 read_lock_irqsave(&zfcp_data.config_lock, flags);
1882 write_lock(&adapter->erp_lock);
1883 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask, id,
1885 write_unlock(&adapter->erp_lock);
1886 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1891 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter,
1892 int clear_mask, u8 id, u64 ref)
1895 struct zfcp_port *port;
1897 list_for_each_entry(port, &adapter->port_list_head, list)
1898 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1899 zfcp_erp_port_reopen_internal(port, clear_mask, id,
1912 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port,
1913 int clear_mask, u8 id, u64 ref)
1916 struct zfcp_unit *unit;
1918 list_for_each_entry(unit, &port->unit_list_head, list)
1919 zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
1927 * purpose: this routine executes the 'Reopen Adapter' action
1928 * (the entire action is processed synchronously, since
1929 * there are no actions which might be run concurrently
1932 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1933 * ZFCP_ERP_FAILED - action finished unsuccessfully
1936 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1939 struct zfcp_adapter *adapter = erp_action->adapter;
1941 retval = zfcp_erp_adapter_strategy_close(erp_action);
1942 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1943 retval = ZFCP_ERP_EXIT;
1945 retval = zfcp_erp_adapter_strategy_open(erp_action);
1947 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1948 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1949 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1951 if (retval == ZFCP_ERP_FAILED) {
1952 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1953 "to recover itself\n",
1954 zfcp_get_busid_by_adapter(adapter));
1955 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
1966 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1967 * ZFCP_ERP_FAILED - action finished unsuccessfully
1970 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1974 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1975 &erp_action->adapter->status);
1976 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1977 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1978 &erp_action->adapter->status);
1988 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1989 * ZFCP_ERP_FAILED - action finished unsuccessfully
1992 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1996 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1997 &erp_action->adapter->status);
1998 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
1999 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2000 &erp_action->adapter->status);
2006 * function: zfcp_register_adapter
2008 * purpose: allocate the irq associated with this devno and register
2009 * the FSF adapter with the SCSI stack
2014 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2016 int retval = ZFCP_ERP_SUCCEEDED;
2021 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2022 if (retval != ZFCP_ERP_SUCCEEDED)
2025 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2026 if (retval != ZFCP_ERP_SUCCEEDED)
2027 goto failed_openfcp;
2029 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2033 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2034 &erp_action->adapter->status);
2037 zfcp_close_fsf(erp_action->adapter);
2039 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2040 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
2041 ZFCP_STATUS_ADAPTER_XPORT_OK,
2042 &erp_action->adapter->status);
2048 * function: zfcp_qdio_init
2050 * purpose: setup QDIO operation for specified adapter
2052 * returns: 0 - successful setup
2056 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2060 volatile struct qdio_buffer_element *sbale;
2061 struct zfcp_adapter *adapter = erp_action->adapter;
2063 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2064 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2066 zfcp_get_busid_by_adapter(adapter));
2070 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2071 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2073 zfcp_get_busid_by_adapter(adapter));
2074 goto failed_qdio_establish;
2076 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2078 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2079 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2081 zfcp_get_busid_by_adapter(adapter));
2082 goto failed_qdio_activate;
2084 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2087 * put buffers into response queue,
2089 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2090 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2092 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2096 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2097 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2098 zfcp_get_busid_by_adapter(adapter),
2099 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2101 retval = do_QDIO(adapter->ccw_device,
2102 QDIO_FLAG_SYNC_INPUT,
2103 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2106 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2108 goto failed_do_qdio;
2110 adapter->response_queue.free_index = 0;
2111 atomic_set(&adapter->response_queue.free_count, 0);
2112 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2113 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2115 /* set index of first avalable SBALS / number of available SBALS */
2116 adapter->request_queue.free_index = 0;
2117 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2118 adapter->request_queue.distance_from_int = 0;
2120 /* initialize waitqueue used to wait for free SBALs in requests queue */
2121 init_waitqueue_head(&adapter->request_wq);
2123 /* ok, we did it - skip all cleanups for different failures */
2124 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2125 retval = ZFCP_ERP_SUCCEEDED;
2131 failed_qdio_activate:
2132 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2133 while (qdio_shutdown(adapter->ccw_device,
2134 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2136 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2138 failed_qdio_establish:
2140 retval = ZFCP_ERP_FAILED;
2148 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2152 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2153 if (retval == ZFCP_ERP_FAILED)
2154 return ZFCP_ERP_FAILED;
2156 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2157 if (retval == ZFCP_ERP_FAILED)
2158 return ZFCP_ERP_FAILED;
2160 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2164 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2166 int retval = ZFCP_ERP_SUCCEEDED;
2168 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2169 struct zfcp_adapter *adapter = erp_action->adapter;
2171 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2173 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2174 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2176 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2177 write_lock_irq(&adapter->erp_lock);
2178 zfcp_erp_action_to_running(erp_action);
2179 write_unlock_irq(&adapter->erp_lock);
2180 if (zfcp_fsf_exchange_config_data(erp_action)) {
2181 retval = ZFCP_ERP_FAILED;
2182 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2183 ZFCP_LOG_INFO("error: initiation of exchange of "
2184 "configuration data failed for "
2186 zfcp_get_busid_by_adapter(adapter));
2189 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2190 ZFCP_LOG_DEBUG("Xchange underway\n");
2194 * Both the normal completion handler as well as the timeout
2195 * handler will do an 'up' when the 'exchange config data'
2196 * request completes or times out. Thus, the signal to go on
2197 * won't be lost utilizing this semaphore.
2198 * Furthermore, this 'adapter_reopen' action is
2199 * guaranteed to be the only action being there (highest action
2200 * which prevents other actions from being created).
2201 * Resulting from that, the wake signal recognized here
2202 * _must_ be the one belonging to the 'exchange config
2205 zfcp_rec_dbf_event_thread(6, adapter, 1);
2206 down(&adapter->erp_ready_sem);
2207 zfcp_rec_dbf_event_thread(7, adapter, 1);
2208 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2209 ZFCP_LOG_INFO("error: exchange of configuration data "
2210 "for adapter %s timed out\n",
2211 zfcp_get_busid_by_adapter(adapter));
2215 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2219 ZFCP_LOG_DEBUG("host connection still initialising... "
2220 "waiting and retrying...\n");
2221 /* sleep a little bit before retry */
2226 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2229 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2230 &adapter->status)) {
2231 ZFCP_LOG_INFO("error: exchange of configuration data for "
2232 "adapter %s failed\n",
2233 zfcp_get_busid_by_adapter(adapter));
2234 retval = ZFCP_ERP_FAILED;
2241 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2244 struct zfcp_adapter *adapter;
2246 adapter = erp_action->adapter;
2247 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2249 write_lock_irq(&adapter->erp_lock);
2250 zfcp_erp_action_to_running(erp_action);
2251 write_unlock_irq(&adapter->erp_lock);
2253 ret = zfcp_fsf_exchange_port_data(erp_action);
2254 if (ret == -EOPNOTSUPP) {
2255 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2256 return ZFCP_ERP_SUCCEEDED;
2258 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2259 return ZFCP_ERP_FAILED;
2261 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2263 ret = ZFCP_ERP_SUCCEEDED;
2264 zfcp_rec_dbf_event_thread(8, adapter, 1);
2265 down(&adapter->erp_ready_sem);
2266 zfcp_rec_dbf_event_thread(9, adapter, 1);
2267 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2268 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2269 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2270 ret = ZFCP_ERP_FAILED;
2273 /* don't treat as error for the sake of compatibility */
2274 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2275 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2276 "%s\n", zfcp_get_busid_by_adapter(adapter));
2282 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2285 int retval = ZFCP_ERP_SUCCEEDED;
2287 struct zfcp_adapter *adapter = erp_action->adapter;
2290 adapter->status_read_failed = 0;
2291 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2292 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2294 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2295 "notification failed on adapter %s\n",
2296 zfcp_get_busid_by_adapter(adapter));
2297 retval = ZFCP_ERP_FAILED;
2309 * purpose: this routine executes the 'Reopen Physical Port' action
2311 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2312 * ZFCP_ERP_SUCCEEDED - action finished successfully
2313 * ZFCP_ERP_FAILED - action finished unsuccessfully
2316 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2318 int retval = ZFCP_ERP_FAILED;
2319 struct zfcp_port *port = erp_action->port;
2320 struct zfcp_adapter *adapter = erp_action->adapter;
2322 switch (erp_action->step) {
2326 * the ULP spec. begs for waiting for oustanding commands
2328 case ZFCP_ERP_STEP_UNINITIALIZED:
2329 zfcp_erp_port_strategy_clearstati(port);
2331 * it would be sufficient to test only the normal open flag
2332 * since the phys. open flag cannot be set if the normal
2333 * open flag is unset - however, this is for readabilty ...
2335 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2336 ZFCP_STATUS_COMMON_OPEN),
2338 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2339 "close physical\n", port->wwpn);
2341 zfcp_erp_port_forced_strategy_close(erp_action);
2343 retval = ZFCP_ERP_FAILED;
2346 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2347 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2349 ZFCP_LOG_DEBUG("close physical failed for port "
2350 "0x%016Lx\n", port->wwpn);
2351 retval = ZFCP_ERP_FAILED;
2353 retval = ZFCP_ERP_SUCCEEDED;
2357 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2358 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2359 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2360 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2368 * purpose: this routine executes the 'Reopen Port' action
2370 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2371 * ZFCP_ERP_SUCCEEDED - action finished successfully
2372 * ZFCP_ERP_FAILED - action finished unsuccessfully
2375 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2377 int retval = ZFCP_ERP_FAILED;
2378 struct zfcp_port *port = erp_action->port;
2379 struct zfcp_adapter *adapter = erp_action->adapter;
2381 switch (erp_action->step) {
2385 * the ULP spec. begs for waiting for oustanding commands
2387 case ZFCP_ERP_STEP_UNINITIALIZED:
2388 zfcp_erp_port_strategy_clearstati(port);
2389 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2390 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2391 "close\n", port->wwpn);
2392 retval = zfcp_erp_port_strategy_close(erp_action);
2394 } /* else it's already closed, open it */
2397 case ZFCP_ERP_STEP_PORT_CLOSING:
2398 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2399 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2401 retval = ZFCP_ERP_FAILED;
2403 } /* else it's closed now, open it */
2406 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2407 retval = ZFCP_ERP_EXIT;
2409 retval = zfcp_erp_port_strategy_open(erp_action);
2412 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2413 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2414 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2415 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2421 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2425 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2426 &erp_action->port->status))
2427 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2429 retval = zfcp_erp_port_strategy_open_common(erp_action);
2435 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2438 struct zfcp_adapter *adapter = erp_action->adapter;
2439 struct zfcp_port *port = erp_action->port;
2441 switch (erp_action->step) {
2443 case ZFCP_ERP_STEP_UNINITIALIZED:
2444 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2445 case ZFCP_ERP_STEP_PORT_CLOSING:
2446 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2447 if (port->wwpn != adapter->peer_wwpn) {
2448 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2449 "on adapter %s.\nPeer WWPN "
2450 "0x%016Lx does not match\n",
2452 zfcp_get_busid_by_adapter(adapter),
2453 adapter->peer_wwpn);
2454 zfcp_erp_port_failed(port, 25, 0);
2455 retval = ZFCP_ERP_FAILED;
2458 port->d_id = adapter->peer_d_id;
2459 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2460 retval = zfcp_erp_port_strategy_open_port(erp_action);
2463 if (!(adapter->nameserver_port)) {
2464 retval = zfcp_nameserver_enqueue(adapter);
2466 ZFCP_LOG_NORMAL("error: nameserver port "
2467 "unavailable for adapter %s\n",
2468 zfcp_get_busid_by_adapter(adapter));
2469 retval = ZFCP_ERP_FAILED;
2473 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2474 &adapter->nameserver_port->status)) {
2475 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2476 "nameserver port\n");
2477 /* nameserver port may live again */
2478 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2479 &adapter->nameserver_port->status);
2480 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0,
2481 77, (u64)erp_action) >= 0) {
2483 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2484 retval = ZFCP_ERP_CONTINUES;
2486 retval = ZFCP_ERP_FAILED;
2489 /* else nameserver port is already open, fall through */
2490 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2491 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2492 &adapter->nameserver_port->status)) {
2493 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2494 retval = ZFCP_ERP_FAILED;
2496 ZFCP_LOG_DEBUG("nameserver port is open -> "
2497 "nameserver look-up for port 0x%016Lx\n",
2499 retval = zfcp_erp_port_strategy_open_common_lookup
2504 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2505 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2506 if (atomic_test_mask
2507 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2508 ZFCP_LOG_DEBUG("nameserver look-up failed "
2509 "for port 0x%016Lx "
2510 "(misconfigured WWPN?)\n",
2512 zfcp_erp_port_failed(port, 26, 0);
2513 retval = ZFCP_ERP_EXIT;
2515 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2516 "port 0x%016Lx\n", port->wwpn);
2517 retval = ZFCP_ERP_FAILED;
2520 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2521 "trying open\n", port->wwpn, port->d_id);
2522 retval = zfcp_erp_port_strategy_open_port(erp_action);
2526 case ZFCP_ERP_STEP_PORT_OPENING:
2527 /* D_ID might have changed during open */
2528 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2529 ZFCP_STATUS_PORT_DID_DID),
2531 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2532 retval = ZFCP_ERP_SUCCEEDED;
2534 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2536 retval = ZFCP_ERP_FAILED;
2541 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2543 retval = ZFCP_ERP_FAILED;
2550 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2553 struct zfcp_port *port = erp_action->port;
2555 switch (erp_action->step) {
2557 case ZFCP_ERP_STEP_UNINITIALIZED:
2558 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2559 case ZFCP_ERP_STEP_PORT_CLOSING:
2560 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2561 port->wwpn, port->d_id);
2562 retval = zfcp_erp_port_strategy_open_port(erp_action);
2565 case ZFCP_ERP_STEP_PORT_OPENING:
2566 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2567 ZFCP_LOG_DEBUG("WKA port is open\n");
2568 retval = ZFCP_ERP_SUCCEEDED;
2570 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2571 retval = ZFCP_ERP_FAILED;
2573 /* this is needed anyway (dont care for retval of wakeup) */
2574 ZFCP_LOG_DEBUG("continue other open port operations\n");
2575 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2579 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2581 retval = ZFCP_ERP_FAILED;
2590 * purpose: makes the erp thread continue with reopen (physical) port
2591 * actions which have been paused until the name server port
2592 * is opened (or failed)
2594 * returns: 0 (a kind of void retval, its not used)
2597 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2601 unsigned long flags;
2602 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2603 struct zfcp_erp_action *erp_action, *tmp;
2605 read_lock_irqsave(&adapter->erp_lock, flags);
2606 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2608 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2609 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2611 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2612 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2613 debug_event(adapter->erp_dbf, 3,
2614 &erp_action->port->wwpn, sizeof (wwn_t));
2615 if (atomic_test_mask(
2616 ZFCP_STATUS_COMMON_ERP_FAILED,
2617 &adapter->nameserver_port->status))
2618 zfcp_erp_port_failed(erp_action->port, 27, 0);
2619 zfcp_erp_action_ready(erp_action);
2622 read_unlock_irqrestore(&adapter->erp_lock, flags);
2632 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2633 * ZFCP_ERP_FAILED - action finished unsuccessfully
2636 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2639 struct zfcp_adapter *adapter = erp_action->adapter;
2640 struct zfcp_port *port = erp_action->port;
2642 retval = zfcp_fsf_close_physical_port(erp_action);
2643 if (retval == -ENOMEM) {
2644 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2645 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2646 retval = ZFCP_ERP_NOMEM;
2649 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2651 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2652 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2653 /* could not send 'open', fail */
2654 retval = ZFCP_ERP_FAILED;
2657 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2658 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2659 retval = ZFCP_ERP_CONTINUES;
2665 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2668 struct zfcp_adapter *adapter = port->adapter;
2670 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2671 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2673 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2674 ZFCP_STATUS_COMMON_CLOSING |
2675 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2676 ZFCP_STATUS_PORT_DID_DID |
2677 ZFCP_STATUS_PORT_PHYS_CLOSING |
2678 ZFCP_STATUS_PORT_INVALID_WWPN,
2688 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2689 * ZFCP_ERP_FAILED - action finished unsuccessfully
2692 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2695 struct zfcp_adapter *adapter = erp_action->adapter;
2696 struct zfcp_port *port = erp_action->port;
2698 retval = zfcp_fsf_close_port(erp_action);
2699 if (retval == -ENOMEM) {
2700 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2701 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2702 retval = ZFCP_ERP_NOMEM;
2705 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2707 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2708 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2709 /* could not send 'close', fail */
2710 retval = ZFCP_ERP_FAILED;
2713 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2714 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2715 retval = ZFCP_ERP_CONTINUES;
2725 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2726 * ZFCP_ERP_FAILED - action finished unsuccessfully
2729 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2732 struct zfcp_adapter *adapter = erp_action->adapter;
2733 struct zfcp_port *port = erp_action->port;
2735 retval = zfcp_fsf_open_port(erp_action);
2736 if (retval == -ENOMEM) {
2737 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2738 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2739 retval = ZFCP_ERP_NOMEM;
2742 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2744 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2745 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2746 /* could not send 'open', fail */
2747 retval = ZFCP_ERP_FAILED;
2750 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2751 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2752 retval = ZFCP_ERP_CONTINUES;
2762 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2763 * ZFCP_ERP_FAILED - action finished unsuccessfully
2766 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2769 struct zfcp_adapter *adapter = erp_action->adapter;
2770 struct zfcp_port *port = erp_action->port;
2772 retval = zfcp_ns_gid_pn_request(erp_action);
2773 if (retval == -ENOMEM) {
2774 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2775 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2776 retval = ZFCP_ERP_NOMEM;
2779 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2781 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2782 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2783 /* could not send nameserver request, fail */
2784 retval = ZFCP_ERP_FAILED;
2787 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2788 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2789 retval = ZFCP_ERP_CONTINUES;
2797 * purpose: this routine executes the 'Reopen Unit' action
2798 * currently no retries
2800 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2801 * ZFCP_ERP_SUCCEEDED - action finished successfully
2802 * ZFCP_ERP_FAILED - action finished unsuccessfully
2805 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2807 int retval = ZFCP_ERP_FAILED;
2808 struct zfcp_unit *unit = erp_action->unit;
2809 struct zfcp_adapter *adapter = erp_action->adapter;
2811 switch (erp_action->step) {
2815 * the ULP spec. begs for waiting for oustanding commands
2817 case ZFCP_ERP_STEP_UNINITIALIZED:
2818 zfcp_erp_unit_strategy_clearstati(unit);
2819 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2820 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2821 "trying close\n", unit->fcp_lun);
2822 retval = zfcp_erp_unit_strategy_close(erp_action);
2825 /* else it's already closed, fall through */
2826 case ZFCP_ERP_STEP_UNIT_CLOSING:
2827 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2828 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2830 retval = ZFCP_ERP_FAILED;
2832 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2833 retval = ZFCP_ERP_EXIT;
2835 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2836 "trying open\n", unit->fcp_lun);
2838 zfcp_erp_unit_strategy_open(erp_action);
2843 case ZFCP_ERP_STEP_UNIT_OPENING:
2844 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2845 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2847 retval = ZFCP_ERP_SUCCEEDED;
2849 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2851 retval = ZFCP_ERP_FAILED;
2856 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2857 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2858 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2859 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2864 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2867 struct zfcp_adapter *adapter = unit->port->adapter;
2869 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2870 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2872 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2873 ZFCP_STATUS_COMMON_CLOSING |
2874 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2875 ZFCP_STATUS_UNIT_SHARED |
2876 ZFCP_STATUS_UNIT_READONLY,
2887 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2888 * ZFCP_ERP_FAILED - action finished unsuccessfully
2891 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2894 struct zfcp_adapter *adapter = erp_action->adapter;
2895 struct zfcp_unit *unit = erp_action->unit;
2897 retval = zfcp_fsf_close_unit(erp_action);
2898 if (retval == -ENOMEM) {
2899 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2900 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2901 sizeof (fcp_lun_t));
2902 retval = ZFCP_ERP_NOMEM;
2905 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2907 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2908 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2909 sizeof (fcp_lun_t));
2910 /* could not send 'close', fail */
2911 retval = ZFCP_ERP_FAILED;
2914 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2915 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2916 retval = ZFCP_ERP_CONTINUES;
2927 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2928 * ZFCP_ERP_FAILED - action finished unsuccessfully
2931 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2934 struct zfcp_adapter *adapter = erp_action->adapter;
2935 struct zfcp_unit *unit = erp_action->unit;
2937 retval = zfcp_fsf_open_unit(erp_action);
2938 if (retval == -ENOMEM) {
2939 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2940 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2941 sizeof (fcp_lun_t));
2942 retval = ZFCP_ERP_NOMEM;
2945 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2947 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2948 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2949 sizeof (fcp_lun_t));
2950 /* could not send 'open', fail */
2951 retval = ZFCP_ERP_FAILED;
2954 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2955 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2956 retval = ZFCP_ERP_CONTINUES;
2961 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2963 BUG_ON(!fsf_req->erp_action);
2964 fsf_req->timer.function = zfcp_erp_timeout_handler;
2965 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2966 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2967 add_timer(&fsf_req->timer);
2973 * purpose: enqueue the specified error recovery action, if needed
2977 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
2978 struct zfcp_port *port,
2979 struct zfcp_unit *unit, u8 id, u64 ref)
2981 int retval = 1, need = want;
2982 struct zfcp_erp_action *erp_action = NULL;
2986 * We need some rules here which check whether we really need
2987 * this action or whether we should just drop it.
2988 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2989 * 'Reopen Unit' request for an associated unit since we can't
2990 * satisfy this request now. A 'Reopen Port' action will trigger
2991 * 'Reopen Unit' actions when it completes.
2992 * Thus, there are only actions in the queue which can immediately be
2993 * executed. This makes the processing of the action queue more
2997 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3001 debug_event(adapter->erp_dbf, 4, &want, sizeof (int));
3002 /* check whether we really need this */
3004 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3005 if (atomic_test_mask
3006 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3007 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3008 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3010 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3011 sizeof (fcp_lun_t));
3014 if (!atomic_test_mask
3015 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3017 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3020 if (!atomic_test_mask
3021 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
3022 need = ZFCP_ERP_ACTION_REOPEN_PORT;
3023 /* fall through !!! */
3025 case ZFCP_ERP_ACTION_REOPEN_PORT:
3026 if (atomic_test_mask
3027 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3028 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3029 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3033 /* fall through !!! */
3035 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3036 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3038 if (port->erp_action.action !=
3039 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3040 ZFCP_LOG_INFO("dropped erp action %i (port "
3041 "0x%016Lx, action in use: %i)\n",
3043 port->erp_action.action);
3044 debug_text_event(adapter->erp_dbf, 4,
3047 debug_text_event(adapter->erp_dbf, 4,
3049 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3053 if (!atomic_test_mask
3054 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3056 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3059 if (!atomic_test_mask
3060 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
3061 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3062 /* fall through !!! */
3064 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3065 if (atomic_test_mask
3066 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3067 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3073 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3074 debug_event(adapter->erp_dbf, 1, &want, sizeof (int));
3075 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3076 "on adapter %s (action=%d)\n",
3077 zfcp_get_busid_by_adapter(adapter), want);
3081 /* check whether we need something stronger first */
3083 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3084 debug_event(adapter->erp_dbf, 4, &need,
3086 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3087 "erp action %d on adapter %s\n",
3088 need, want, zfcp_get_busid_by_adapter(adapter));
3091 /* mark adapter to have some error recovery pending */
3092 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3094 /* setup error recovery action */
3097 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3098 zfcp_unit_get(unit);
3099 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3100 erp_action = &unit->erp_action;
3101 if (!atomic_test_mask
3102 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3103 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3106 case ZFCP_ERP_ACTION_REOPEN_PORT:
3107 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3108 zfcp_port_get(port);
3109 zfcp_erp_action_dismiss_port(port);
3110 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3111 erp_action = &port->erp_action;
3112 if (!atomic_test_mask
3113 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3114 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3117 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3118 zfcp_adapter_get(adapter);
3119 zfcp_erp_action_dismiss_adapter(adapter);
3120 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3121 erp_action = &adapter->erp_action;
3122 if (!atomic_test_mask
3123 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3124 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3128 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3130 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3131 erp_action->adapter = adapter;
3132 erp_action->port = port;
3133 erp_action->unit = unit;
3134 erp_action->action = need;
3135 erp_action->status = status;
3137 ++adapter->erp_total_count;
3139 /* finally put it into 'ready' queue and kick erp thread */
3140 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
3141 up(&adapter->erp_ready_sem);
3142 zfcp_rec_dbf_event_thread(1, adapter, 0);
3145 zfcp_rec_dbf_event_trigger(id, ref, want, need, (u64)erp_action,
3146 adapter, port, unit);
3151 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3154 struct zfcp_adapter *adapter = erp_action->adapter;
3156 --adapter->erp_total_count;
3157 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3158 --adapter->erp_low_mem_count;
3159 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3162 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3163 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3164 list_del(&erp_action->list);
3165 switch (erp_action->action) {
3166 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3167 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3168 &erp_action->unit->status);
3170 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3171 case ZFCP_ERP_ACTION_REOPEN_PORT:
3172 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3173 &erp_action->port->status);
3175 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3176 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3177 &erp_action->adapter->status);
3187 * zfcp_erp_action_cleanup
3189 * Register unit with scsi stack if appropriate and fix reference counts.
3190 * Note: Temporary units are not registered with scsi stack.
3193 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3194 struct zfcp_port *port, struct zfcp_unit *unit,
3198 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3199 if ((result == ZFCP_ERP_SUCCEEDED)
3200 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3204 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3206 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3207 &unit->status) == 0)
3208 zfcp_erp_schedule_work(unit);
3210 zfcp_unit_put(unit);
3212 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3213 case ZFCP_ERP_ACTION_REOPEN_PORT:
3214 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3216 zfcp_port_put(port);
3220 if ((result == ZFCP_ERP_SUCCEEDED)
3222 struct fc_rport_identifiers ids;
3223 ids.node_name = port->wwnn;
3224 ids.port_name = port->wwpn;
3225 ids.port_id = port->d_id;
3226 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3228 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3230 ZFCP_LOG_NORMAL("failed registration of rport"
3231 "(adapter %s, wwpn=0x%016Lx)\n",
3232 zfcp_get_busid_by_port(port),
3235 scsi_target_unblock(&port->rport->dev);
3236 port->rport->maxframe_size = port->maxframe_size;
3237 port->rport->supported_classes =
3238 port->supported_classes;
3241 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3242 fc_remote_port_delete(port->rport);
3245 zfcp_port_put(port);
3247 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3248 if (result != ZFCP_ERP_SUCCEEDED) {
3249 list_for_each_entry(port, &adapter->port_list_head, list)
3251 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3253 fc_remote_port_delete(port->rport);
3257 zfcp_adapter_put(adapter);
3265 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3267 struct zfcp_port *port;
3269 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3270 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3271 zfcp_erp_action_dismiss(&adapter->erp_action);
3273 list_for_each_entry(port, &adapter->port_list_head, list)
3274 zfcp_erp_action_dismiss_port(port);
3277 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3279 struct zfcp_unit *unit;
3280 struct zfcp_adapter *adapter = port->adapter;
3282 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3283 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3284 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3285 zfcp_erp_action_dismiss(&port->erp_action);
3287 list_for_each_entry(unit, &port->unit_list_head, list)
3288 zfcp_erp_action_dismiss_unit(unit);
3291 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3293 struct zfcp_adapter *adapter = unit->port->adapter;
3295 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3296 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3297 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3298 zfcp_erp_action_dismiss(&unit->erp_action);
3301 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3303 struct zfcp_adapter *adapter = erp_action->adapter;
3305 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3306 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3307 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3310 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3312 struct zfcp_adapter *adapter = erp_action->adapter;
3314 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3315 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3316 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3319 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, u64 ref)
3321 struct zfcp_adapter *adapter = port->adapter;
3322 unsigned long flags;
3324 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3325 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3326 read_lock_irqsave(&zfcp_data.config_lock, flags);
3327 zfcp_erp_modify_port_status(port, id, ref,
3328 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3329 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3330 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3333 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, u64 ref)
3335 struct zfcp_adapter *adapter = unit->port->adapter;
3337 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3338 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3339 zfcp_erp_modify_unit_status(unit, id, ref,
3340 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3341 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3344 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, u64 ref)
3346 struct zfcp_adapter *adapter = port->adapter;
3347 unsigned long flags;
3349 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3350 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3351 read_lock_irqsave(&zfcp_data.config_lock, flags);
3352 zfcp_erp_modify_port_status(port, id, ref,
3353 ZFCP_STATUS_COMMON_ERP_FAILED |
3354 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3355 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3358 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, u64 ref)
3360 struct zfcp_adapter *adapter = unit->port->adapter;
3362 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3363 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3364 zfcp_erp_modify_unit_status(unit, id, ref,
3365 ZFCP_STATUS_COMMON_ERP_FAILED |
3366 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3369 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
3372 struct zfcp_port *port;
3373 unsigned long flags;
3375 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3378 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3379 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3381 read_lock_irqsave(&zfcp_data.config_lock, flags);
3382 if (adapter->nameserver_port)
3383 zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
3384 list_for_each_entry(port, &adapter->port_list_head, list)
3385 if (port != adapter->nameserver_port)
3386 zfcp_erp_port_access_changed(port, id, ref);
3387 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3390 void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, u64 ref)
3392 struct zfcp_adapter *adapter = port->adapter;
3393 struct zfcp_unit *unit;
3395 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3396 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3398 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3400 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3402 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3403 list_for_each_entry(unit, &port->unit_list_head, list)
3404 zfcp_erp_unit_access_changed(unit, id, ref);
3408 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3409 "(due to ACT update)\n",
3410 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3411 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3412 ZFCP_LOG_NORMAL("failed reopen of port"
3413 "(adapter %s, wwpn=0x%016Lx)\n",
3414 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3417 void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, u64 ref)
3419 struct zfcp_adapter *adapter = unit->port->adapter;
3421 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3422 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3424 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3426 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3430 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3431 " on adapter %s (due to ACT update)\n",
3432 unit->fcp_lun, unit->port->wwpn,
3433 zfcp_get_busid_by_adapter(adapter));
3434 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3435 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3436 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3437 zfcp_get_busid_by_adapter(adapter),
3438 unit->port->wwpn, unit->fcp_lun);
3441 #undef ZFCP_LOG_AREA