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