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