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;
896 zfcp_rec_dbf_event_action(142, erp_action);
898 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
899 zfcp_rec_dbf_event_action(143, erp_action);
900 ZFCP_LOG_NORMAL("error: erp step timed out "
901 "(action=%d, fsf_req=%p)\n ",
903 erp_action->fsf_req);
906 * If fsf_req is neither dismissed nor completed
907 * then keep it running asynchronously and don't mess
908 * with the association of erp_action and fsf_req.
910 if (erp_action->fsf_req->status &
911 (ZFCP_STATUS_FSFREQ_COMPLETED |
912 ZFCP_STATUS_FSFREQ_DISMISSED)) {
913 /* forget about association between fsf_req
915 erp_action->fsf_req = NULL;
918 debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
920 * even if this fsf_req has gone, forget about
921 * association between erp_action and fsf_req
923 erp_action->fsf_req = NULL;
925 spin_unlock(&adapter->req_list_lock);
927 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
931 * zfcp_erp_async_handler_nolock - complete erp_action
933 * Used for normal completion, time-out, dismissal and failure after
934 * low memory condition.
936 static void zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
937 unsigned long set_mask)
939 struct zfcp_adapter *adapter = erp_action->adapter;
941 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
942 debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
943 debug_event(adapter->erp_dbf, 2, &erp_action->action,
945 erp_action->status |= set_mask;
946 zfcp_erp_action_ready(erp_action);
948 /* action is ready or gone - nothing to do */
949 debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
950 debug_event(adapter->erp_dbf, 3, &erp_action->action,
956 * zfcp_erp_async_handler - wrapper for erp_async_handler_nolock w/ locking
958 void zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
959 unsigned long set_mask)
961 struct zfcp_adapter *adapter = erp_action->adapter;
964 write_lock_irqsave(&adapter->erp_lock, flags);
965 zfcp_erp_async_handler_nolock(erp_action, set_mask);
966 write_unlock_irqrestore(&adapter->erp_lock, flags);
970 * purpose: is called for erp_action which was slept waiting for
971 * memory becoming avaliable,
972 * will trigger that this action will be continued
975 zfcp_erp_memwait_handler(unsigned long data)
977 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
978 struct zfcp_adapter *adapter = erp_action->adapter;
980 debug_text_event(adapter->erp_dbf, 2, "a_mwh");
981 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
983 zfcp_erp_async_handler(erp_action, 0);
987 * purpose: is called if an asynchronous erp step timed out,
988 * action gets an appropriate flag and will be processed
991 static void zfcp_erp_timeout_handler(unsigned long data)
993 struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
994 struct zfcp_adapter *adapter = erp_action->adapter;
996 debug_text_event(adapter->erp_dbf, 2, "a_th");
997 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
999 zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
1003 * zfcp_erp_action_dismiss - dismiss an erp_action
1005 * adapter->erp_lock must be held
1007 * Dismissal of an erp_action is usually required if an erp_action of
1008 * higher priority is generated.
1010 static void zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
1012 struct zfcp_adapter *adapter = erp_action->adapter;
1014 debug_text_event(adapter->erp_dbf, 2, "a_adis");
1015 debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
1017 erp_action->status |= ZFCP_STATUS_ERP_DISMISSED;
1018 if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING)
1019 zfcp_erp_action_ready(erp_action);
1023 zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
1027 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1029 retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
1031 ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
1033 zfcp_get_busid_by_adapter(adapter));
1034 debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
1036 wait_event(adapter->erp_thread_wqh,
1037 atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1039 debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
1042 return (retval < 0);
1052 * context: process (i.e. proc-fs or rmmod/insmod)
1054 * note: The caller of this routine ensures that the specified
1055 * adapter has been shut down and that this operation
1056 * has been completed. Thus, there are no pending erp_actions
1057 * which would need to be handled here.
1060 zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
1064 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
1065 up(&adapter->erp_ready_sem);
1066 zfcp_rec_dbf_event_thread(2, adapter, 1);
1068 wait_event(adapter->erp_thread_wqh,
1069 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
1072 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1075 debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
1081 * purpose: is run as a kernel thread,
1082 * goes through list of error recovery actions of associated adapter
1083 * and delegates single action to execution
1088 zfcp_erp_thread(void *data)
1090 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
1091 struct list_head *next;
1092 struct zfcp_erp_action *erp_action;
1093 unsigned long flags;
1095 daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
1096 /* Block all signals */
1097 siginitsetinv(¤t->blocked, 0);
1098 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1099 debug_text_event(adapter->erp_dbf, 5, "a_th_run");
1100 wake_up(&adapter->erp_thread_wqh);
1102 while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
1103 &adapter->status)) {
1105 write_lock_irqsave(&adapter->erp_lock, flags);
1106 next = adapter->erp_ready_head.next;
1107 write_unlock_irqrestore(&adapter->erp_lock, flags);
1109 if (next != &adapter->erp_ready_head) {
1111 list_entry(next, struct zfcp_erp_action, list);
1113 * process action (incl. [re]moving it
1114 * from 'ready' queue)
1116 zfcp_erp_strategy(erp_action);
1120 * sleep as long as there is nothing to do, i.e.
1121 * no action in 'ready' queue to be processed and
1122 * thread is not to be killed
1124 zfcp_rec_dbf_event_thread(4, adapter, 1);
1125 down_interruptible(&adapter->erp_ready_sem);
1126 zfcp_rec_dbf_event_thread(5, adapter, 1);
1127 debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
1130 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
1131 debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
1132 wake_up(&adapter->erp_thread_wqh);
1140 * purpose: drives single error recovery action and schedules higher and
1141 * subordinate actions, if necessary
1143 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
1144 * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
1145 * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
1146 * ZFCP_ERP_EXIT - action finished (dequeued), offline
1147 * ZFCP_ERP_DISMISSED - action canceled (dequeued)
1150 zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
1153 struct zfcp_adapter *adapter = erp_action->adapter;
1154 struct zfcp_port *port = erp_action->port;
1155 struct zfcp_unit *unit = erp_action->unit;
1156 int action = erp_action->action;
1157 u32 status = erp_action->status;
1158 unsigned long flags;
1160 /* serialise dismissing, timing out, moving, enqueueing */
1161 read_lock_irqsave(&zfcp_data.config_lock, flags);
1162 write_lock(&adapter->erp_lock);
1164 /* dequeue dismissed action and leave, if required */
1165 retval = zfcp_erp_strategy_check_action(erp_action, retval);
1166 if (retval == ZFCP_ERP_DISMISSED) {
1167 debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
1172 * move action to 'running' queue before processing it
1173 * (to avoid a race condition regarding moving the
1174 * action to the 'running' queue and back)
1176 zfcp_erp_action_to_running(erp_action);
1179 * try to process action as far as possible,
1180 * no lock to allow for blocking operations (kmalloc, qdio, ...),
1181 * afterwards the lock is required again for the following reasons:
1182 * - dequeueing of finished action and enqueueing of
1183 * follow-up actions must be atomic so that any other
1184 * reopen-routine does not believe there is nothing to do
1185 * and that it is safe to enqueue something else,
1186 * - we want to force any control thread which is dismissing
1187 * actions to finish this before we decide about
1188 * necessary steps to be taken here further
1190 write_unlock(&adapter->erp_lock);
1191 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1192 retval = zfcp_erp_strategy_do_action(erp_action);
1193 read_lock_irqsave(&zfcp_data.config_lock, flags);
1194 write_lock(&adapter->erp_lock);
1197 * check for dismissed status again to avoid follow-up actions,
1198 * failing of targets and so on for dismissed actions,
1199 * we go through down() here because there has been an up()
1201 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
1202 retval = ZFCP_ERP_CONTINUES;
1205 case ZFCP_ERP_NOMEM:
1206 /* no memory to continue immediately, let it sleep */
1207 if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
1208 ++adapter->erp_low_mem_count;
1209 erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
1211 /* This condition is true if there is no memory available
1212 for any erp_action on this adapter. This implies that there
1213 are no elements in the memory pool(s) left for erp_actions.
1214 This might happen if an erp_action that used a memory pool
1215 element was timed out.
1217 if (adapter->erp_total_count == adapter->erp_low_mem_count) {
1218 debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
1219 ZFCP_LOG_NORMAL("error: no mempool elements available, "
1220 "restarting I/O on adapter %s "
1221 "to free mempool\n",
1222 zfcp_get_busid_by_adapter(adapter));
1223 zfcp_erp_adapter_reopen_internal(adapter, 0, 66, 0);
1225 debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
1226 retval = zfcp_erp_strategy_memwait(erp_action);
1229 case ZFCP_ERP_CONTINUES:
1230 /* leave since this action runs asynchronously */
1231 debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
1232 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
1233 --adapter->erp_low_mem_count;
1234 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
1238 /* ok, finished action (whatever its result is) */
1240 /* check for unrecoverable targets */
1241 retval = zfcp_erp_strategy_check_target(erp_action, retval);
1243 /* action must be dequeued (here to allow for further ones) */
1244 zfcp_erp_action_dequeue(erp_action);
1247 * put this target through the erp mill again if someone has
1248 * requested to change the status of a target being online
1249 * to offline or the other way around
1250 * (old retval is preserved if nothing has to be done here)
1252 retval = zfcp_erp_strategy_statechange(action, status, adapter,
1253 port, unit, retval);
1256 * leave if target is in permanent error state or if
1257 * action is repeated in order to process state change
1259 if (retval == ZFCP_ERP_EXIT) {
1260 debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
1264 /* trigger follow up actions */
1265 zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
1268 write_unlock(&adapter->erp_lock);
1269 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1271 if (retval != ZFCP_ERP_CONTINUES)
1272 zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
1275 * a few tasks remain when the erp queues are empty
1276 * (don't do that if the last action evaluated was dismissed
1277 * since this clearly indicates that there is more to come) :
1278 * - close the name server port if it is open yet
1279 * (enqueues another [probably] final action)
1280 * - otherwise, wake up whoever wants to be woken when we are
1283 if (retval != ZFCP_ERP_DISMISSED)
1284 zfcp_erp_strategy_check_queues(adapter);
1286 debug_text_event(adapter->erp_dbf, 6, "a_st_done");
1296 * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
1297 * retval - otherwise
1300 zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
1302 struct zfcp_adapter *adapter = erp_action->adapter;
1304 zfcp_erp_strategy_check_fsfreq(erp_action);
1306 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1307 if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
1308 debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
1309 zfcp_erp_action_dequeue(erp_action);
1310 retval = ZFCP_ERP_DISMISSED;
1312 debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
1318 zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
1320 int retval = ZFCP_ERP_FAILED;
1321 struct zfcp_adapter *adapter = erp_action->adapter;
1324 * try to execute/continue action as far as possible,
1325 * note: no lock in subsequent strategy routines
1326 * (this allows these routine to call schedule, e.g.
1327 * kmalloc with such flags or qdio_initialize & friends)
1328 * Note: in case of timeout, the separate strategies will fail
1329 * anyhow. No need for a special action. Even worse, a nameserver
1330 * failure would not wake up waiting ports without the call.
1332 switch (erp_action->action) {
1334 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1335 retval = zfcp_erp_adapter_strategy(erp_action);
1338 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1339 retval = zfcp_erp_port_forced_strategy(erp_action);
1342 case ZFCP_ERP_ACTION_REOPEN_PORT:
1343 retval = zfcp_erp_port_strategy(erp_action);
1346 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1347 retval = zfcp_erp_unit_strategy(erp_action);
1351 debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
1352 debug_event(adapter->erp_dbf, 1, &erp_action->action,
1354 ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
1355 "adapter %s (action=%d)\n",
1356 zfcp_get_busid_by_adapter(erp_action->adapter),
1357 erp_action->action);
1366 * purpose: triggers retry of this action after a certain amount of time
1367 * by means of timer provided by erp_action
1369 * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
1372 zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
1374 int retval = ZFCP_ERP_CONTINUES;
1375 struct zfcp_adapter *adapter = erp_action->adapter;
1377 debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
1378 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
1379 init_timer(&erp_action->timer);
1380 erp_action->timer.function = zfcp_erp_memwait_handler;
1381 erp_action->timer.data = (unsigned long) erp_action;
1382 erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
1383 add_timer(&erp_action->timer);
1389 * function: zfcp_erp_adapter_failed
1391 * purpose: sets the adapter and all underlying devices to ERP_FAILED
1395 zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, u64 ref)
1397 zfcp_erp_modify_adapter_status(adapter, id, ref,
1398 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1399 ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
1400 zfcp_get_busid_by_adapter(adapter));
1401 debug_text_event(adapter->erp_dbf, 2, "a_afail");
1405 * function: zfcp_erp_port_failed
1407 * purpose: sets the port and all underlying devices to ERP_FAILED
1411 zfcp_erp_port_failed(struct zfcp_port *port, u8 id, u64 ref)
1413 zfcp_erp_modify_port_status(port, id, ref,
1414 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1416 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1417 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1418 "port d_id=0x%06x)\n",
1419 zfcp_get_busid_by_port(port), port->d_id);
1421 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
1422 zfcp_get_busid_by_port(port), port->wwpn);
1424 debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
1425 debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
1429 * function: zfcp_erp_unit_failed
1431 * purpose: sets the unit to ERP_FAILED
1435 zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, u64 ref)
1437 zfcp_erp_modify_unit_status(unit, id, ref,
1438 ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
1440 ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
1441 " on adapter %s\n", unit->fcp_lun,
1442 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
1443 debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
1444 debug_event(unit->port->adapter->erp_dbf, 2,
1445 &unit->fcp_lun, sizeof (fcp_lun_t));
1449 * function: zfcp_erp_strategy_check_target
1451 * purpose: increments the erp action count on the device currently in
1452 * recovery if the action failed or resets the count in case of
1453 * success. If a maximum count is exceeded the device is marked
1455 * The 'blocked' state of a target which has been recovered
1456 * successfully is reset.
1458 * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
1459 * ZFCP_ERP_SUCCEEDED - action finished successfully
1460 * ZFCP_ERP_EXIT - action failed and will not continue
1463 zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
1465 struct zfcp_adapter *adapter = erp_action->adapter;
1466 struct zfcp_port *port = erp_action->port;
1467 struct zfcp_unit *unit = erp_action->unit;
1469 debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
1470 debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
1471 debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
1473 switch (erp_action->action) {
1475 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1476 result = zfcp_erp_strategy_check_unit(unit, result);
1479 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1480 case ZFCP_ERP_ACTION_REOPEN_PORT:
1481 result = zfcp_erp_strategy_check_port(port, result);
1484 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1485 result = zfcp_erp_strategy_check_adapter(adapter, result);
1493 zfcp_erp_strategy_statechange(int action,
1495 struct zfcp_adapter *adapter,
1496 struct zfcp_port *port,
1497 struct zfcp_unit *unit, int retval)
1499 debug_text_event(adapter->erp_dbf, 3, "a_stsc");
1500 debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
1504 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1505 if (zfcp_erp_strategy_statechange_detected(&adapter->status,
1507 zfcp_erp_adapter_reopen_internal(adapter,
1508 ZFCP_STATUS_COMMON_ERP_FAILED,
1510 retval = ZFCP_ERP_EXIT;
1514 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1515 case ZFCP_ERP_ACTION_REOPEN_PORT:
1516 if (zfcp_erp_strategy_statechange_detected(&port->status,
1518 zfcp_erp_port_reopen_internal(port,
1519 ZFCP_STATUS_COMMON_ERP_FAILED,
1521 retval = ZFCP_ERP_EXIT;
1525 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1526 if (zfcp_erp_strategy_statechange_detected(&unit->status,
1528 zfcp_erp_unit_reopen_internal(unit,
1529 ZFCP_STATUS_COMMON_ERP_FAILED,
1531 retval = ZFCP_ERP_EXIT;
1540 zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
1543 /* take it online */
1544 (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1545 (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
1546 /* take it offline */
1547 (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
1548 !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
1552 zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
1554 debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
1555 debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
1556 sizeof (fcp_lun_t));
1559 case ZFCP_ERP_SUCCEEDED :
1560 atomic_set(&unit->erp_counter, 0);
1561 zfcp_erp_unit_unblock(unit);
1563 case ZFCP_ERP_FAILED :
1564 atomic_inc(&unit->erp_counter);
1565 if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
1566 zfcp_erp_unit_failed(unit, 21, 0);
1568 case ZFCP_ERP_EXIT :
1573 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
1574 zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
1575 result = ZFCP_ERP_EXIT;
1582 zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
1584 debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
1585 debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
1588 case ZFCP_ERP_SUCCEEDED :
1589 atomic_set(&port->erp_counter, 0);
1590 zfcp_erp_port_unblock(port);
1592 case ZFCP_ERP_FAILED :
1593 atomic_inc(&port->erp_counter);
1594 if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
1595 zfcp_erp_port_failed(port, 22, 0);
1597 case ZFCP_ERP_EXIT :
1602 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
1603 zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
1604 result = ZFCP_ERP_EXIT;
1611 zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1613 debug_text_event(adapter->erp_dbf, 5, "a_stct");
1616 case ZFCP_ERP_SUCCEEDED :
1617 atomic_set(&adapter->erp_counter, 0);
1618 zfcp_erp_adapter_unblock(adapter);
1620 case ZFCP_ERP_FAILED :
1621 atomic_inc(&adapter->erp_counter);
1622 if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
1623 zfcp_erp_adapter_failed(adapter, 23, 0);
1625 case ZFCP_ERP_EXIT :
1630 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
1631 zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
1632 result = ZFCP_ERP_EXIT;
1638 struct zfcp_erp_add_work {
1639 struct zfcp_unit *unit;
1640 struct work_struct work;
1644 * zfcp_erp_scsi_scan
1645 * @data: pointer to a struct zfcp_erp_add_work
1647 * Registers a logical unit with the SCSI stack.
1649 static void zfcp_erp_scsi_scan(struct work_struct *work)
1651 struct zfcp_erp_add_work *p =
1652 container_of(work, struct zfcp_erp_add_work, work);
1653 struct zfcp_unit *unit = p->unit;
1654 struct fc_rport *rport = unit->port->rport;
1655 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1657 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1658 zfcp_unit_put(unit);
1663 * zfcp_erp_schedule_work
1664 * @unit: pointer to unit which should be registered with SCSI stack
1666 * Schedules work which registers a unit with the SCSI stack
1669 zfcp_erp_schedule_work(struct zfcp_unit *unit)
1671 struct zfcp_erp_add_work *p;
1673 p = kzalloc(sizeof(*p), GFP_KERNEL);
1675 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1676 "the FCP-LUN 0x%Lx connected to "
1677 "the port with WWPN 0x%Lx connected to "
1678 "the adapter %s with the SCSI stack.\n",
1681 zfcp_get_busid_by_unit(unit));
1685 zfcp_unit_get(unit);
1686 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1687 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1689 schedule_work(&p->work);
1695 * purpose: remaining things in good cases,
1696 * escalation in bad cases
1701 zfcp_erp_strategy_followup_actions(int action,
1702 struct zfcp_adapter *adapter,
1703 struct zfcp_port *port,
1704 struct zfcp_unit *unit, int status)
1706 debug_text_event(adapter->erp_dbf, 5, "a_stfol");
1707 debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
1709 /* initiate follow-up actions depending on success of finished action */
1712 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
1713 if (status == ZFCP_ERP_SUCCEEDED)
1714 zfcp_erp_port_reopen_all_internal(adapter, 0, 70, 0);
1716 zfcp_erp_adapter_reopen_internal(adapter, 0, 71, 0);
1719 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
1720 if (status == ZFCP_ERP_SUCCEEDED)
1721 zfcp_erp_port_reopen_internal(port, 0, 72, 0);
1723 zfcp_erp_adapter_reopen_internal(adapter, 0, 73, 0);
1726 case ZFCP_ERP_ACTION_REOPEN_PORT:
1727 if (status == ZFCP_ERP_SUCCEEDED)
1728 zfcp_erp_unit_reopen_all_internal(port, 0, 74, 0);
1730 zfcp_erp_port_forced_reopen_internal(port, 0, 75, 0);
1733 case ZFCP_ERP_ACTION_REOPEN_UNIT:
1734 /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
1735 if (status != ZFCP_ERP_SUCCEEDED)
1736 zfcp_erp_port_reopen_internal(unit->port, 0, 76, 0);
1744 zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
1746 unsigned long flags;
1748 read_lock_irqsave(&zfcp_data.config_lock, flags);
1749 read_lock(&adapter->erp_lock);
1750 if (list_empty(&adapter->erp_ready_head) &&
1751 list_empty(&adapter->erp_running_head)) {
1752 debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
1753 atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1755 wake_up(&adapter->erp_done_wqh);
1757 debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
1758 read_unlock(&adapter->erp_lock);
1759 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1765 * zfcp_erp_wait - wait for completion of error recovery on an adapter
1766 * @adapter: adapter for which to wait for completion of its error recovery
1770 zfcp_erp_wait(struct zfcp_adapter *adapter)
1774 wait_event(adapter->erp_done_wqh,
1775 !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
1781 void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id,
1782 u64 ref, u32 mask, int set_or_clear)
1784 struct zfcp_port *port;
1785 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1787 if (set_or_clear == ZFCP_SET) {
1788 changed = atomic_test_and_set_mask(mask, &adapter->status);
1789 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
1791 changed = atomic_test_and_clear_mask(mask, &adapter->status);
1792 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1793 atomic_set(&adapter->erp_counter, 0);
1794 debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
1797 zfcp_rec_dbf_event_adapter(id, ref, adapter);
1798 debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
1800 /* Deal with all underlying devices, only pass common_mask */
1802 list_for_each_entry(port, &adapter->port_list_head, list)
1803 zfcp_erp_modify_port_status(port, id, ref, common_mask,
1808 * function: zfcp_erp_modify_port_status
1810 * purpose: sets the port and all underlying devices to ERP_FAILED
1813 void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, u64 ref,
1814 u32 mask, int set_or_clear)
1816 struct zfcp_unit *unit;
1817 u32 changed, common_mask = mask & ZFCP_COMMON_FLAGS;
1819 if (set_or_clear == ZFCP_SET) {
1820 changed = atomic_test_and_set_mask(mask, &port->status);
1821 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
1823 changed = atomic_test_and_clear_mask(mask, &port->status);
1824 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
1825 atomic_set(&port->erp_counter, 0);
1826 debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
1829 zfcp_rec_dbf_event_port(id, ref, port);
1830 debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
1831 debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1833 /* Modify status of all underlying devices, only pass common mask */
1835 list_for_each_entry(unit, &port->unit_list_head, list)
1836 zfcp_erp_modify_unit_status(unit, id, ref, common_mask,
1841 * function: zfcp_erp_modify_unit_status
1843 * purpose: sets the unit to ERP_FAILED
1846 void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, u64 ref,
1847 u32 mask, int set_or_clear)
1851 if (set_or_clear == ZFCP_SET) {
1852 changed = atomic_test_and_set_mask(mask, &unit->status);
1853 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
1855 changed = atomic_test_and_clear_mask(mask, &unit->status);
1856 if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
1857 atomic_set(&unit->erp_counter, 0);
1859 debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
1862 zfcp_rec_dbf_event_unit(id, ref, unit);
1863 debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
1864 sizeof (fcp_lun_t));
1865 debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
1871 * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
1872 * used to ensure the correct locking
1874 * returns: 0 - initiated action successfully
1875 * <0 - failed to initiate action
1877 int zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask,
1881 unsigned long flags;
1883 read_lock_irqsave(&zfcp_data.config_lock, flags);
1884 write_lock(&adapter->erp_lock);
1885 retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask, id,
1887 write_unlock(&adapter->erp_lock);
1888 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
1893 static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter,
1894 int clear_mask, u8 id, u64 ref)
1897 struct zfcp_port *port;
1899 list_for_each_entry(port, &adapter->port_list_head, list)
1900 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1901 zfcp_erp_port_reopen_internal(port, clear_mask, id,
1914 static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port,
1915 int clear_mask, u8 id, u64 ref)
1918 struct zfcp_unit *unit;
1920 list_for_each_entry(unit, &port->unit_list_head, list)
1921 zfcp_erp_unit_reopen_internal(unit, clear_mask, id, ref);
1929 * purpose: this routine executes the 'Reopen Adapter' action
1930 * (the entire action is processed synchronously, since
1931 * there are no actions which might be run concurrently
1934 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1935 * ZFCP_ERP_FAILED - action finished unsuccessfully
1938 zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
1941 struct zfcp_adapter *adapter = erp_action->adapter;
1943 retval = zfcp_erp_adapter_strategy_close(erp_action);
1944 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
1945 retval = ZFCP_ERP_EXIT;
1947 retval = zfcp_erp_adapter_strategy_open(erp_action);
1949 debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
1950 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
1951 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
1953 if (retval == ZFCP_ERP_FAILED) {
1954 ZFCP_LOG_INFO("Waiting to allow the adapter %s "
1955 "to recover itself\n",
1956 zfcp_get_busid_by_adapter(adapter));
1957 ssleep(ZFCP_TYPE2_RECOVERY_TIME);
1968 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1969 * ZFCP_ERP_FAILED - action finished unsuccessfully
1972 zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
1976 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
1977 &erp_action->adapter->status);
1978 retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
1979 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
1980 &erp_action->adapter->status);
1990 * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
1991 * ZFCP_ERP_FAILED - action finished unsuccessfully
1994 zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
1998 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
1999 &erp_action->adapter->status);
2000 retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
2001 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
2002 &erp_action->adapter->status);
2008 * function: zfcp_register_adapter
2010 * purpose: allocate the irq associated with this devno and register
2011 * the FSF adapter with the SCSI stack
2016 zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
2018 int retval = ZFCP_ERP_SUCCEEDED;
2023 retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
2024 if (retval != ZFCP_ERP_SUCCEEDED)
2027 retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
2028 if (retval != ZFCP_ERP_SUCCEEDED)
2029 goto failed_openfcp;
2031 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
2035 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2036 &erp_action->adapter->status);
2039 zfcp_close_fsf(erp_action->adapter);
2041 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2042 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
2043 ZFCP_STATUS_ADAPTER_XPORT_OK,
2044 &erp_action->adapter->status);
2050 * function: zfcp_qdio_init
2052 * purpose: setup QDIO operation for specified adapter
2054 * returns: 0 - successful setup
2058 zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
2062 volatile struct qdio_buffer_element *sbale;
2063 struct zfcp_adapter *adapter = erp_action->adapter;
2065 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
2066 ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
2068 zfcp_get_busid_by_adapter(adapter));
2072 if (qdio_establish(&adapter->qdio_init_data) != 0) {
2073 ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
2075 zfcp_get_busid_by_adapter(adapter));
2076 goto failed_qdio_establish;
2078 debug_text_event(adapter->erp_dbf, 3, "qdio_est");
2080 if (qdio_activate(adapter->ccw_device, 0) != 0) {
2081 ZFCP_LOG_INFO("error: activation of QDIO queues failed "
2083 zfcp_get_busid_by_adapter(adapter));
2084 goto failed_qdio_activate;
2086 debug_text_event(adapter->erp_dbf, 3, "qdio_act");
2089 * put buffers into response queue,
2091 for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
2092 sbale = &(adapter->response_queue.buffer[i]->element[0]);
2094 sbale->flags = SBAL_FLAGS_LAST_ENTRY;
2098 ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
2099 "queue_no=%i, index_in_queue=%i, count=%i)\n",
2100 zfcp_get_busid_by_adapter(adapter),
2101 QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
2103 retval = do_QDIO(adapter->ccw_device,
2104 QDIO_FLAG_SYNC_INPUT,
2105 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
2108 ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
2110 goto failed_do_qdio;
2112 adapter->response_queue.free_index = 0;
2113 atomic_set(&adapter->response_queue.free_count, 0);
2114 ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
2115 "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
2117 /* set index of first avalable SBALS / number of available SBALS */
2118 adapter->request_queue.free_index = 0;
2119 atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
2120 adapter->request_queue.distance_from_int = 0;
2122 /* initialize waitqueue used to wait for free SBALs in requests queue */
2123 init_waitqueue_head(&adapter->request_wq);
2125 /* ok, we did it - skip all cleanups for different failures */
2126 atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
2127 retval = ZFCP_ERP_SUCCEEDED;
2133 failed_qdio_activate:
2134 debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
2135 while (qdio_shutdown(adapter->ccw_device,
2136 QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
2138 debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
2140 failed_qdio_establish:
2142 retval = ZFCP_ERP_FAILED;
2150 zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
2154 retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
2155 if (retval == ZFCP_ERP_FAILED)
2156 return ZFCP_ERP_FAILED;
2158 retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
2159 if (retval == ZFCP_ERP_FAILED)
2160 return ZFCP_ERP_FAILED;
2162 return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
2166 zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
2168 int retval = ZFCP_ERP_SUCCEEDED;
2170 int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
2171 struct zfcp_adapter *adapter = erp_action->adapter;
2173 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2175 for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
2176 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2178 ZFCP_LOG_DEBUG("Doing exchange config data\n");
2179 write_lock_irq(&adapter->erp_lock);
2180 zfcp_erp_action_to_running(erp_action);
2181 write_unlock_irq(&adapter->erp_lock);
2182 if (zfcp_fsf_exchange_config_data(erp_action)) {
2183 retval = ZFCP_ERP_FAILED;
2184 debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
2185 ZFCP_LOG_INFO("error: initiation of exchange of "
2186 "configuration data failed for "
2188 zfcp_get_busid_by_adapter(adapter));
2191 debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
2192 ZFCP_LOG_DEBUG("Xchange underway\n");
2196 * Both the normal completion handler as well as the timeout
2197 * handler will do an 'up' when the 'exchange config data'
2198 * request completes or times out. Thus, the signal to go on
2199 * won't be lost utilizing this semaphore.
2200 * Furthermore, this 'adapter_reopen' action is
2201 * guaranteed to be the only action being there (highest action
2202 * which prevents other actions from being created).
2203 * Resulting from that, the wake signal recognized here
2204 * _must_ be the one belonging to the 'exchange config
2207 zfcp_rec_dbf_event_thread(6, adapter, 1);
2208 down(&adapter->erp_ready_sem);
2209 zfcp_rec_dbf_event_thread(7, adapter, 1);
2210 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2211 ZFCP_LOG_INFO("error: exchange of configuration data "
2212 "for adapter %s timed out\n",
2213 zfcp_get_busid_by_adapter(adapter));
2217 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2221 ZFCP_LOG_DEBUG("host connection still initialising... "
2222 "waiting and retrying...\n");
2223 /* sleep a little bit before retry */
2228 atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
2231 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2232 &adapter->status)) {
2233 ZFCP_LOG_INFO("error: exchange of configuration data for "
2234 "adapter %s failed\n",
2235 zfcp_get_busid_by_adapter(adapter));
2236 retval = ZFCP_ERP_FAILED;
2243 zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
2246 struct zfcp_adapter *adapter;
2248 adapter = erp_action->adapter;
2249 atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2251 write_lock_irq(&adapter->erp_lock);
2252 zfcp_erp_action_to_running(erp_action);
2253 write_unlock_irq(&adapter->erp_lock);
2255 ret = zfcp_fsf_exchange_port_data(erp_action);
2256 if (ret == -EOPNOTSUPP) {
2257 debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
2258 return ZFCP_ERP_SUCCEEDED;
2260 debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
2261 return ZFCP_ERP_FAILED;
2263 debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
2265 ret = ZFCP_ERP_SUCCEEDED;
2266 zfcp_rec_dbf_event_thread(8, adapter, 1);
2267 down(&adapter->erp_ready_sem);
2268 zfcp_rec_dbf_event_thread(9, adapter, 1);
2269 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
2270 ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
2271 "%s)\n", zfcp_get_busid_by_adapter(adapter));
2272 ret = ZFCP_ERP_FAILED;
2275 /* don't treat as error for the sake of compatibility */
2276 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
2277 ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
2278 "%s\n", zfcp_get_busid_by_adapter(adapter));
2284 zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
2287 int retval = ZFCP_ERP_SUCCEEDED;
2289 struct zfcp_adapter *adapter = erp_action->adapter;
2292 adapter->status_read_failed = 0;
2293 for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
2294 temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
2296 ZFCP_LOG_INFO("error: set-up of unsolicited status "
2297 "notification failed on adapter %s\n",
2298 zfcp_get_busid_by_adapter(adapter));
2299 retval = ZFCP_ERP_FAILED;
2311 * purpose: this routine executes the 'Reopen Physical Port' action
2313 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2314 * ZFCP_ERP_SUCCEEDED - action finished successfully
2315 * ZFCP_ERP_FAILED - action finished unsuccessfully
2318 zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
2320 int retval = ZFCP_ERP_FAILED;
2321 struct zfcp_port *port = erp_action->port;
2322 struct zfcp_adapter *adapter = erp_action->adapter;
2324 switch (erp_action->step) {
2328 * the ULP spec. begs for waiting for oustanding commands
2330 case ZFCP_ERP_STEP_UNINITIALIZED:
2331 zfcp_erp_port_strategy_clearstati(port);
2333 * it would be sufficient to test only the normal open flag
2334 * since the phys. open flag cannot be set if the normal
2335 * open flag is unset - however, this is for readabilty ...
2337 if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
2338 ZFCP_STATUS_COMMON_OPEN),
2340 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2341 "close physical\n", port->wwpn);
2343 zfcp_erp_port_forced_strategy_close(erp_action);
2345 retval = ZFCP_ERP_FAILED;
2348 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2349 if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
2351 ZFCP_LOG_DEBUG("close physical failed for port "
2352 "0x%016Lx\n", port->wwpn);
2353 retval = ZFCP_ERP_FAILED;
2355 retval = ZFCP_ERP_SUCCEEDED;
2359 debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
2360 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2361 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2362 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2370 * purpose: this routine executes the 'Reopen Port' action
2372 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2373 * ZFCP_ERP_SUCCEEDED - action finished successfully
2374 * ZFCP_ERP_FAILED - action finished unsuccessfully
2377 zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
2379 int retval = ZFCP_ERP_FAILED;
2380 struct zfcp_port *port = erp_action->port;
2381 struct zfcp_adapter *adapter = erp_action->adapter;
2383 switch (erp_action->step) {
2387 * the ULP spec. begs for waiting for oustanding commands
2389 case ZFCP_ERP_STEP_UNINITIALIZED:
2390 zfcp_erp_port_strategy_clearstati(port);
2391 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2392 ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
2393 "close\n", port->wwpn);
2394 retval = zfcp_erp_port_strategy_close(erp_action);
2396 } /* else it's already closed, open it */
2399 case ZFCP_ERP_STEP_PORT_CLOSING:
2400 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2401 ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
2403 retval = ZFCP_ERP_FAILED;
2405 } /* else it's closed now, open it */
2408 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2409 retval = ZFCP_ERP_EXIT;
2411 retval = zfcp_erp_port_strategy_open(erp_action);
2414 debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
2415 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
2416 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2417 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2423 zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
2427 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
2428 &erp_action->port->status))
2429 retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
2431 retval = zfcp_erp_port_strategy_open_common(erp_action);
2437 zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2440 struct zfcp_adapter *adapter = erp_action->adapter;
2441 struct zfcp_port *port = erp_action->port;
2443 switch (erp_action->step) {
2445 case ZFCP_ERP_STEP_UNINITIALIZED:
2446 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2447 case ZFCP_ERP_STEP_PORT_CLOSING:
2448 if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
2449 if (port->wwpn != adapter->peer_wwpn) {
2450 ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
2451 "on adapter %s.\nPeer WWPN "
2452 "0x%016Lx does not match\n",
2454 zfcp_get_busid_by_adapter(adapter),
2455 adapter->peer_wwpn);
2456 zfcp_erp_port_failed(port, 25, 0);
2457 retval = ZFCP_ERP_FAILED;
2460 port->d_id = adapter->peer_d_id;
2461 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
2462 retval = zfcp_erp_port_strategy_open_port(erp_action);
2465 if (!(adapter->nameserver_port)) {
2466 retval = zfcp_nameserver_enqueue(adapter);
2468 ZFCP_LOG_NORMAL("error: nameserver port "
2469 "unavailable for adapter %s\n",
2470 zfcp_get_busid_by_adapter(adapter));
2471 retval = ZFCP_ERP_FAILED;
2475 if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
2476 &adapter->nameserver_port->status)) {
2477 ZFCP_LOG_DEBUG("nameserver port is not open -> open "
2478 "nameserver port\n");
2479 /* nameserver port may live again */
2480 atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
2481 &adapter->nameserver_port->status);
2482 if (zfcp_erp_port_reopen(adapter->nameserver_port, 0,
2483 77, (u64)erp_action) >= 0) {
2485 ZFCP_ERP_STEP_NAMESERVER_OPEN;
2486 retval = ZFCP_ERP_CONTINUES;
2488 retval = ZFCP_ERP_FAILED;
2491 /* else nameserver port is already open, fall through */
2492 case ZFCP_ERP_STEP_NAMESERVER_OPEN:
2493 if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
2494 &adapter->nameserver_port->status)) {
2495 ZFCP_LOG_DEBUG("open failed for nameserver port\n");
2496 retval = ZFCP_ERP_FAILED;
2498 ZFCP_LOG_DEBUG("nameserver port is open -> "
2499 "nameserver look-up for port 0x%016Lx\n",
2501 retval = zfcp_erp_port_strategy_open_common_lookup
2506 case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
2507 if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
2508 if (atomic_test_mask
2509 (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
2510 ZFCP_LOG_DEBUG("nameserver look-up failed "
2511 "for port 0x%016Lx "
2512 "(misconfigured WWPN?)\n",
2514 zfcp_erp_port_failed(port, 26, 0);
2515 retval = ZFCP_ERP_EXIT;
2517 ZFCP_LOG_DEBUG("nameserver look-up failed for "
2518 "port 0x%016Lx\n", port->wwpn);
2519 retval = ZFCP_ERP_FAILED;
2522 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2523 "trying open\n", port->wwpn, port->d_id);
2524 retval = zfcp_erp_port_strategy_open_port(erp_action);
2528 case ZFCP_ERP_STEP_PORT_OPENING:
2529 /* D_ID might have changed during open */
2530 if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
2531 ZFCP_STATUS_PORT_DID_DID),
2533 ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
2534 retval = ZFCP_ERP_SUCCEEDED;
2536 ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
2538 retval = ZFCP_ERP_FAILED;
2543 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2545 retval = ZFCP_ERP_FAILED;
2552 zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2555 struct zfcp_port *port = erp_action->port;
2557 switch (erp_action->step) {
2559 case ZFCP_ERP_STEP_UNINITIALIZED:
2560 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2561 case ZFCP_ERP_STEP_PORT_CLOSING:
2562 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2563 port->wwpn, port->d_id);
2564 retval = zfcp_erp_port_strategy_open_port(erp_action);
2567 case ZFCP_ERP_STEP_PORT_OPENING:
2568 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
2569 ZFCP_LOG_DEBUG("WKA port is open\n");
2570 retval = ZFCP_ERP_SUCCEEDED;
2572 ZFCP_LOG_DEBUG("open failed for WKA port\n");
2573 retval = ZFCP_ERP_FAILED;
2575 /* this is needed anyway (dont care for retval of wakeup) */
2576 ZFCP_LOG_DEBUG("continue other open port operations\n");
2577 zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
2581 ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
2583 retval = ZFCP_ERP_FAILED;
2592 * purpose: makes the erp thread continue with reopen (physical) port
2593 * actions which have been paused until the name server port
2594 * is opened (or failed)
2596 * returns: 0 (a kind of void retval, its not used)
2599 zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
2603 unsigned long flags;
2604 struct zfcp_adapter *adapter = ns_erp_action->adapter;
2605 struct zfcp_erp_action *erp_action, *tmp;
2607 read_lock_irqsave(&adapter->erp_lock, flags);
2608 list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
2610 debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
2611 debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
2613 if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
2614 debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
2615 debug_event(adapter->erp_dbf, 3,
2616 &erp_action->port->wwpn, sizeof (wwn_t));
2617 if (atomic_test_mask(
2618 ZFCP_STATUS_COMMON_ERP_FAILED,
2619 &adapter->nameserver_port->status))
2620 zfcp_erp_port_failed(erp_action->port, 27, 0);
2621 zfcp_erp_action_ready(erp_action);
2624 read_unlock_irqrestore(&adapter->erp_lock, flags);
2634 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2635 * ZFCP_ERP_FAILED - action finished unsuccessfully
2638 zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
2641 struct zfcp_adapter *adapter = erp_action->adapter;
2642 struct zfcp_port *port = erp_action->port;
2644 retval = zfcp_fsf_close_physical_port(erp_action);
2645 if (retval == -ENOMEM) {
2646 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
2647 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2648 retval = ZFCP_ERP_NOMEM;
2651 erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
2653 debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
2654 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2655 /* could not send 'open', fail */
2656 retval = ZFCP_ERP_FAILED;
2659 debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
2660 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2661 retval = ZFCP_ERP_CONTINUES;
2667 zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
2670 struct zfcp_adapter *adapter = port->adapter;
2672 debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
2673 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2675 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2676 ZFCP_STATUS_COMMON_CLOSING |
2677 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2678 ZFCP_STATUS_PORT_DID_DID |
2679 ZFCP_STATUS_PORT_PHYS_CLOSING |
2680 ZFCP_STATUS_PORT_INVALID_WWPN,
2690 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2691 * ZFCP_ERP_FAILED - action finished unsuccessfully
2694 zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
2697 struct zfcp_adapter *adapter = erp_action->adapter;
2698 struct zfcp_port *port = erp_action->port;
2700 retval = zfcp_fsf_close_port(erp_action);
2701 if (retval == -ENOMEM) {
2702 debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
2703 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2704 retval = ZFCP_ERP_NOMEM;
2707 erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
2709 debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
2710 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2711 /* could not send 'close', fail */
2712 retval = ZFCP_ERP_FAILED;
2715 debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
2716 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2717 retval = ZFCP_ERP_CONTINUES;
2727 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2728 * ZFCP_ERP_FAILED - action finished unsuccessfully
2731 zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
2734 struct zfcp_adapter *adapter = erp_action->adapter;
2735 struct zfcp_port *port = erp_action->port;
2737 retval = zfcp_fsf_open_port(erp_action);
2738 if (retval == -ENOMEM) {
2739 debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
2740 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2741 retval = ZFCP_ERP_NOMEM;
2744 erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
2746 debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
2747 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2748 /* could not send 'open', fail */
2749 retval = ZFCP_ERP_FAILED;
2752 debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
2753 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2754 retval = ZFCP_ERP_CONTINUES;
2764 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2765 * ZFCP_ERP_FAILED - action finished unsuccessfully
2768 zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
2771 struct zfcp_adapter *adapter = erp_action->adapter;
2772 struct zfcp_port *port = erp_action->port;
2774 retval = zfcp_ns_gid_pn_request(erp_action);
2775 if (retval == -ENOMEM) {
2776 debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
2777 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2778 retval = ZFCP_ERP_NOMEM;
2781 erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
2783 debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
2784 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
2785 /* could not send nameserver request, fail */
2786 retval = ZFCP_ERP_FAILED;
2789 debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
2790 debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
2791 retval = ZFCP_ERP_CONTINUES;
2799 * purpose: this routine executes the 'Reopen Unit' action
2800 * currently no retries
2802 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2803 * ZFCP_ERP_SUCCEEDED - action finished successfully
2804 * ZFCP_ERP_FAILED - action finished unsuccessfully
2807 zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
2809 int retval = ZFCP_ERP_FAILED;
2810 struct zfcp_unit *unit = erp_action->unit;
2811 struct zfcp_adapter *adapter = erp_action->adapter;
2813 switch (erp_action->step) {
2817 * the ULP spec. begs for waiting for oustanding commands
2819 case ZFCP_ERP_STEP_UNINITIALIZED:
2820 zfcp_erp_unit_strategy_clearstati(unit);
2821 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2822 ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
2823 "trying close\n", unit->fcp_lun);
2824 retval = zfcp_erp_unit_strategy_close(erp_action);
2827 /* else it's already closed, fall through */
2828 case ZFCP_ERP_STEP_UNIT_CLOSING:
2829 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2830 ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
2832 retval = ZFCP_ERP_FAILED;
2834 if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
2835 retval = ZFCP_ERP_EXIT;
2837 ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
2838 "trying open\n", unit->fcp_lun);
2840 zfcp_erp_unit_strategy_open(erp_action);
2845 case ZFCP_ERP_STEP_UNIT_OPENING:
2846 if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
2847 ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
2849 retval = ZFCP_ERP_SUCCEEDED;
2851 ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
2853 retval = ZFCP_ERP_FAILED;
2858 debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
2859 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
2860 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
2861 debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
2866 zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
2869 struct zfcp_adapter *adapter = unit->port->adapter;
2871 debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
2872 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
2874 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
2875 ZFCP_STATUS_COMMON_CLOSING |
2876 ZFCP_STATUS_COMMON_ACCESS_DENIED |
2877 ZFCP_STATUS_UNIT_SHARED |
2878 ZFCP_STATUS_UNIT_READONLY,
2889 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2890 * ZFCP_ERP_FAILED - action finished unsuccessfully
2893 zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
2896 struct zfcp_adapter *adapter = erp_action->adapter;
2897 struct zfcp_unit *unit = erp_action->unit;
2899 retval = zfcp_fsf_close_unit(erp_action);
2900 if (retval == -ENOMEM) {
2901 debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
2902 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2903 sizeof (fcp_lun_t));
2904 retval = ZFCP_ERP_NOMEM;
2907 erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
2909 debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
2910 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2911 sizeof (fcp_lun_t));
2912 /* could not send 'close', fail */
2913 retval = ZFCP_ERP_FAILED;
2916 debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
2917 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2918 retval = ZFCP_ERP_CONTINUES;
2929 * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
2930 * ZFCP_ERP_FAILED - action finished unsuccessfully
2933 zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
2936 struct zfcp_adapter *adapter = erp_action->adapter;
2937 struct zfcp_unit *unit = erp_action->unit;
2939 retval = zfcp_fsf_open_unit(erp_action);
2940 if (retval == -ENOMEM) {
2941 debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
2942 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2943 sizeof (fcp_lun_t));
2944 retval = ZFCP_ERP_NOMEM;
2947 erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
2949 debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
2950 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
2951 sizeof (fcp_lun_t));
2952 /* could not send 'open', fail */
2953 retval = ZFCP_ERP_FAILED;
2956 debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
2957 debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
2958 retval = ZFCP_ERP_CONTINUES;
2963 void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
2965 BUG_ON(!fsf_req->erp_action);
2966 fsf_req->timer.function = zfcp_erp_timeout_handler;
2967 fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
2968 fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
2969 add_timer(&fsf_req->timer);
2975 * purpose: enqueue the specified error recovery action, if needed
2979 static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter,
2980 struct zfcp_port *port,
2981 struct zfcp_unit *unit, u8 id, u64 ref)
2983 int retval = 1, need = want;
2984 struct zfcp_erp_action *erp_action = NULL;
2988 * We need some rules here which check whether we really need
2989 * this action or whether we should just drop it.
2990 * E.g. if there is a unfinished 'Reopen Port' request then we drop a
2991 * 'Reopen Unit' request for an associated unit since we can't
2992 * satisfy this request now. A 'Reopen Port' action will trigger
2993 * 'Reopen Unit' actions when it completes.
2994 * Thus, there are only actions in the queue which can immediately be
2995 * executed. This makes the processing of the action queue more
2999 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
3003 debug_event(adapter->erp_dbf, 4, &want, sizeof (int));
3004 /* check whether we really need this */
3006 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3007 if (atomic_test_mask
3008 (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
3009 debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
3010 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3012 debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
3013 sizeof (fcp_lun_t));
3016 if (!atomic_test_mask
3017 (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
3019 (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
3022 if (!atomic_test_mask
3023 (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status))
3024 need = ZFCP_ERP_ACTION_REOPEN_PORT;
3025 /* fall through !!! */
3027 case ZFCP_ERP_ACTION_REOPEN_PORT:
3028 if (atomic_test_mask
3029 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
3030 debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
3031 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3035 /* fall through !!! */
3037 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3038 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3040 if (port->erp_action.action !=
3041 ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
3042 ZFCP_LOG_INFO("dropped erp action %i (port "
3043 "0x%016Lx, action in use: %i)\n",
3045 port->erp_action.action);
3046 debug_text_event(adapter->erp_dbf, 4,
3049 debug_text_event(adapter->erp_dbf, 4,
3051 debug_event(adapter->erp_dbf, 4, &port->wwpn,
3055 if (!atomic_test_mask
3056 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
3058 (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
3061 if (!atomic_test_mask
3062 (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status))
3063 need = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
3064 /* fall through !!! */
3066 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3067 if (atomic_test_mask
3068 (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
3069 debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
3075 debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
3076 debug_event(adapter->erp_dbf, 1, &want, sizeof (int));
3077 ZFCP_LOG_NORMAL("bug: unknown erp action requested "
3078 "on adapter %s (action=%d)\n",
3079 zfcp_get_busid_by_adapter(adapter), want);
3083 /* check whether we need something stronger first */
3085 debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
3086 debug_event(adapter->erp_dbf, 4, &need,
3088 ZFCP_LOG_DEBUG("stronger erp action %d needed before "
3089 "erp action %d on adapter %s\n",
3090 need, want, zfcp_get_busid_by_adapter(adapter));
3093 /* mark adapter to have some error recovery pending */
3094 atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
3096 /* setup error recovery action */
3099 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3100 zfcp_unit_get(unit);
3101 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
3102 erp_action = &unit->erp_action;
3103 if (!atomic_test_mask
3104 (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
3105 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3108 case ZFCP_ERP_ACTION_REOPEN_PORT:
3109 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3110 zfcp_port_get(port);
3111 zfcp_erp_action_dismiss_port(port);
3112 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
3113 erp_action = &port->erp_action;
3114 if (!atomic_test_mask
3115 (ZFCP_STATUS_COMMON_RUNNING, &port->status))
3116 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3119 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3120 zfcp_adapter_get(adapter);
3121 zfcp_erp_action_dismiss_adapter(adapter);
3122 atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
3123 erp_action = &adapter->erp_action;
3124 if (!atomic_test_mask
3125 (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
3126 status = ZFCP_STATUS_ERP_CLOSE_ONLY;
3130 debug_text_event(adapter->erp_dbf, 4, "a_actenq");
3132 memset(erp_action, 0, sizeof (struct zfcp_erp_action));
3133 erp_action->adapter = adapter;
3134 erp_action->port = port;
3135 erp_action->unit = unit;
3136 erp_action->action = need;
3137 erp_action->status = status;
3139 ++adapter->erp_total_count;
3141 /* finally put it into 'ready' queue and kick erp thread */
3142 list_add_tail(&erp_action->list, &adapter->erp_ready_head);
3143 up(&adapter->erp_ready_sem);
3144 zfcp_rec_dbf_event_thread(1, adapter, 0);
3147 zfcp_rec_dbf_event_trigger(id, ref, want, need, (u64)erp_action,
3148 adapter, port, unit);
3153 zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
3156 struct zfcp_adapter *adapter = erp_action->adapter;
3158 --adapter->erp_total_count;
3159 if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
3160 --adapter->erp_low_mem_count;
3161 erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
3164 debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
3165 debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
3166 list_del(&erp_action->list);
3167 zfcp_rec_dbf_event_action(144, erp_action);
3169 switch (erp_action->action) {
3170 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3171 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3172 &erp_action->unit->status);
3174 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3175 case ZFCP_ERP_ACTION_REOPEN_PORT:
3176 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3177 &erp_action->port->status);
3179 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3180 atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
3181 &erp_action->adapter->status);
3191 * zfcp_erp_action_cleanup
3193 * Register unit with scsi stack if appropriate and fix reference counts.
3194 * Note: Temporary units are not registered with scsi stack.
3197 zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3198 struct zfcp_port *port, struct zfcp_unit *unit,
3202 case ZFCP_ERP_ACTION_REOPEN_UNIT:
3203 if ((result == ZFCP_ERP_SUCCEEDED)
3204 && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
3208 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3210 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3211 &unit->status) == 0)
3212 zfcp_erp_schedule_work(unit);
3214 zfcp_unit_put(unit);
3216 case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
3217 case ZFCP_ERP_ACTION_REOPEN_PORT:
3218 if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
3220 zfcp_port_put(port);
3224 if ((result == ZFCP_ERP_SUCCEEDED)
3226 struct fc_rport_identifiers ids;
3227 ids.node_name = port->wwnn;
3228 ids.port_name = port->wwpn;
3229 ids.port_id = port->d_id;
3230 ids.roles = FC_RPORT_ROLE_FCP_TARGET;
3232 fc_remote_port_add(adapter->scsi_host, 0, &ids);
3234 ZFCP_LOG_NORMAL("failed registration of rport"
3235 "(adapter %s, wwpn=0x%016Lx)\n",
3236 zfcp_get_busid_by_port(port),
3239 scsi_target_unblock(&port->rport->dev);
3240 port->rport->maxframe_size = port->maxframe_size;
3241 port->rport->supported_classes =
3242 port->supported_classes;
3245 if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
3246 fc_remote_port_delete(port->rport);
3249 zfcp_port_put(port);
3251 case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
3252 if (result != ZFCP_ERP_SUCCEEDED) {
3253 list_for_each_entry(port, &adapter->port_list_head, list)
3255 !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
3257 fc_remote_port_delete(port->rport);
3261 zfcp_adapter_put(adapter);
3269 static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
3271 struct zfcp_port *port;
3273 debug_text_event(adapter->erp_dbf, 5, "a_actab");
3274 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
3275 zfcp_erp_action_dismiss(&adapter->erp_action);
3277 list_for_each_entry(port, &adapter->port_list_head, list)
3278 zfcp_erp_action_dismiss_port(port);
3281 static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
3283 struct zfcp_unit *unit;
3284 struct zfcp_adapter *adapter = port->adapter;
3286 debug_text_event(adapter->erp_dbf, 5, "p_actab");
3287 debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
3288 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
3289 zfcp_erp_action_dismiss(&port->erp_action);
3291 list_for_each_entry(unit, &port->unit_list_head, list)
3292 zfcp_erp_action_dismiss_unit(unit);
3295 static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
3297 struct zfcp_adapter *adapter = unit->port->adapter;
3299 debug_text_event(adapter->erp_dbf, 5, "u_actab");
3300 debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
3301 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
3302 zfcp_erp_action_dismiss(&unit->erp_action);
3305 static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
3307 struct zfcp_adapter *adapter = erp_action->adapter;
3309 debug_text_event(adapter->erp_dbf, 6, "a_toru");
3310 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3311 list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
3312 zfcp_rec_dbf_event_action(145, erp_action);
3315 static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
3317 struct zfcp_adapter *adapter = erp_action->adapter;
3319 debug_text_event(adapter->erp_dbf, 6, "a_tore");
3320 debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
3321 list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
3322 zfcp_rec_dbf_event_action(146, erp_action);
3325 void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, u64 ref)
3327 struct zfcp_adapter *adapter = port->adapter;
3328 unsigned long flags;
3330 debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
3331 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3332 read_lock_irqsave(&zfcp_data.config_lock, flags);
3333 zfcp_erp_modify_port_status(port, id, ref,
3334 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3335 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3336 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3339 void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, u64 ref)
3341 struct zfcp_adapter *adapter = unit->port->adapter;
3343 debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
3344 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3345 zfcp_erp_modify_unit_status(unit, id, ref,
3346 ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET);
3347 zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref);
3350 void zfcp_erp_port_access_denied(struct zfcp_port *port, u8 id, u64 ref)
3352 struct zfcp_adapter *adapter = port->adapter;
3353 unsigned long flags;
3355 debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
3356 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3357 read_lock_irqsave(&zfcp_data.config_lock, flags);
3358 zfcp_erp_modify_port_status(port, id, ref,
3359 ZFCP_STATUS_COMMON_ERP_FAILED |
3360 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3361 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3364 void zfcp_erp_unit_access_denied(struct zfcp_unit *unit, u8 id, u64 ref)
3366 struct zfcp_adapter *adapter = unit->port->adapter;
3368 debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
3369 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3370 zfcp_erp_modify_unit_status(unit, id, ref,
3371 ZFCP_STATUS_COMMON_ERP_FAILED |
3372 ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET);
3375 void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id,
3378 struct zfcp_port *port;
3379 unsigned long flags;
3381 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
3384 debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
3385 debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
3387 read_lock_irqsave(&zfcp_data.config_lock, flags);
3388 if (adapter->nameserver_port)
3389 zfcp_erp_port_access_changed(adapter->nameserver_port, id, ref);
3390 list_for_each_entry(port, &adapter->port_list_head, list)
3391 if (port != adapter->nameserver_port)
3392 zfcp_erp_port_access_changed(port, id, ref);
3393 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
3396 void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, u64 ref)
3398 struct zfcp_adapter *adapter = port->adapter;
3399 struct zfcp_unit *unit;
3401 debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
3402 debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
3404 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3406 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3408 if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
3409 list_for_each_entry(unit, &port->unit_list_head, list)
3410 zfcp_erp_unit_access_changed(unit, id, ref);
3414 ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
3415 "(due to ACT update)\n",
3416 port->wwpn, zfcp_get_busid_by_adapter(adapter));
3417 if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3418 ZFCP_LOG_NORMAL("failed reopen of port"
3419 "(adapter %s, wwpn=0x%016Lx)\n",
3420 zfcp_get_busid_by_adapter(adapter), port->wwpn);
3423 void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, u64 ref)
3425 struct zfcp_adapter *adapter = unit->port->adapter;
3427 debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
3428 debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
3430 if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
3432 !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
3436 ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
3437 " on adapter %s (due to ACT update)\n",
3438 unit->fcp_lun, unit->port->wwpn,
3439 zfcp_get_busid_by_adapter(adapter));
3440 if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref))
3441 ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
3442 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3443 zfcp_get_busid_by_adapter(adapter),
3444 unit->port->wwpn, unit->fcp_lun);
3447 #undef ZFCP_LOG_AREA