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 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 11 | #define ZFCP_MAX_ERPS 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 13 | enum zfcp_erp_act_flags { |
| 14 | ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000, |
| 15 | ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000, |
| 16 | ZFCP_STATUS_ERP_DISMISSING = 0x00100000, |
| 17 | ZFCP_STATUS_ERP_DISMISSED = 0x00200000, |
| 18 | ZFCP_STATUS_ERP_LOWMEM = 0x00400000, |
| 19 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 21 | enum zfcp_erp_steps { |
| 22 | ZFCP_ERP_STEP_UNINITIALIZED = 0x0000, |
| 23 | ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001, |
| 24 | ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010, |
| 25 | ZFCP_ERP_STEP_PORT_CLOSING = 0x0100, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 26 | ZFCP_ERP_STEP_NAMESERVER_LOOKUP = 0x0400, |
| 27 | ZFCP_ERP_STEP_PORT_OPENING = 0x0800, |
| 28 | ZFCP_ERP_STEP_UNIT_CLOSING = 0x1000, |
| 29 | ZFCP_ERP_STEP_UNIT_OPENING = 0x2000, |
| 30 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 32 | enum zfcp_erp_act_type { |
| 33 | ZFCP_ERP_ACTION_REOPEN_UNIT = 1, |
| 34 | ZFCP_ERP_ACTION_REOPEN_PORT = 2, |
| 35 | ZFCP_ERP_ACTION_REOPEN_PORT_FORCED = 3, |
| 36 | ZFCP_ERP_ACTION_REOPEN_ADAPTER = 4, |
| 37 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 39 | enum zfcp_erp_act_state { |
| 40 | ZFCP_ERP_ACTION_RUNNING = 1, |
| 41 | ZFCP_ERP_ACTION_READY = 2, |
| 42 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 44 | enum zfcp_erp_act_result { |
| 45 | ZFCP_ERP_SUCCEEDED = 0, |
| 46 | ZFCP_ERP_FAILED = 1, |
| 47 | ZFCP_ERP_CONTINUES = 2, |
| 48 | ZFCP_ERP_EXIT = 3, |
| 49 | ZFCP_ERP_DISMISSED = 4, |
| 50 | ZFCP_ERP_NOMEM = 5, |
| 51 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 53 | static void zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int mask) |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 54 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 55 | zfcp_erp_modify_adapter_status(adapter, 15, NULL, |
| 56 | ZFCP_STATUS_COMMON_UNBLOCKED | mask, |
| 57 | ZFCP_CLEAR); |
Andreas Herrmann | 2abbe86 | 2006-09-18 22:29:56 +0200 | [diff] [blame] | 58 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 60 | static int zfcp_erp_action_exists(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 62 | struct zfcp_erp_action *curr_act; |
| 63 | |
| 64 | list_for_each_entry(curr_act, &act->adapter->erp_running_head, list) |
| 65 | if (act == curr_act) |
| 66 | return ZFCP_ERP_ACTION_RUNNING; |
| 67 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 70 | static void zfcp_erp_action_ready(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 72 | struct zfcp_adapter *adapter = act->adapter; |
| 73 | |
| 74 | list_move(&act->list, &act->adapter->erp_ready_head); |
| 75 | zfcp_rec_dbf_event_action(146, act); |
| 76 | up(&adapter->erp_ready_sem); |
| 77 | zfcp_rec_dbf_event_thread(2, adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 80 | static void zfcp_erp_action_dismiss(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 82 | act->status |= ZFCP_STATUS_ERP_DISMISSED; |
| 83 | if (zfcp_erp_action_exists(act) == ZFCP_ERP_ACTION_RUNNING) |
| 84 | zfcp_erp_action_ready(act); |
| 85 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 87 | static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit) |
| 88 | { |
| 89 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 90 | zfcp_erp_action_dismiss(&unit->erp_action); |
| 91 | } |
| 92 | |
| 93 | static void zfcp_erp_action_dismiss_port(struct zfcp_port *port) |
| 94 | { |
| 95 | struct zfcp_unit *unit; |
| 96 | |
| 97 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 98 | zfcp_erp_action_dismiss(&port->erp_action); |
| 99 | else |
| 100 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 101 | zfcp_erp_action_dismiss_unit(unit); |
| 102 | } |
| 103 | |
| 104 | static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter) |
| 105 | { |
| 106 | struct zfcp_port *port; |
| 107 | |
| 108 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 109 | zfcp_erp_action_dismiss(&adapter->erp_action); |
| 110 | else |
| 111 | list_for_each_entry(port, &adapter->port_list_head, list) |
| 112 | zfcp_erp_action_dismiss_port(port); |
| 113 | } |
| 114 | |
| 115 | static int zfcp_erp_required_act(int want, struct zfcp_adapter *adapter, |
| 116 | struct zfcp_port *port, |
| 117 | struct zfcp_unit *unit) |
| 118 | { |
| 119 | int need = want; |
| 120 | int u_status, p_status, a_status; |
| 121 | |
| 122 | switch (want) { |
| 123 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 124 | u_status = atomic_read(&unit->status); |
| 125 | if (u_status & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 126 | return 0; |
| 127 | p_status = atomic_read(&port->status); |
| 128 | if (!(p_status & ZFCP_STATUS_COMMON_RUNNING) || |
| 129 | p_status & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 130 | return 0; |
| 131 | if (!(p_status & ZFCP_STATUS_COMMON_UNBLOCKED)) |
| 132 | need = ZFCP_ERP_ACTION_REOPEN_PORT; |
| 133 | /* fall through */ |
| 134 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 135 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 136 | p_status = atomic_read(&port->status); |
| 137 | if (p_status & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 138 | return 0; |
| 139 | a_status = atomic_read(&adapter->status); |
| 140 | if (!(a_status & ZFCP_STATUS_COMMON_RUNNING) || |
| 141 | a_status & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 142 | return 0; |
| 143 | if (!(a_status & ZFCP_STATUS_COMMON_UNBLOCKED)) |
| 144 | need = ZFCP_ERP_ACTION_REOPEN_ADAPTER; |
| 145 | /* fall through */ |
| 146 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 147 | a_status = atomic_read(&adapter->status); |
| 148 | if (a_status & ZFCP_STATUS_COMMON_ERP_INUSE) |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | return need; |
| 153 | } |
| 154 | |
| 155 | static struct zfcp_erp_action *zfcp_erp_setup_act(int need, |
| 156 | struct zfcp_adapter *adapter, |
| 157 | struct zfcp_port *port, |
| 158 | struct zfcp_unit *unit) |
| 159 | { |
| 160 | struct zfcp_erp_action *erp_action; |
| 161 | u32 status = 0; |
| 162 | |
| 163 | switch (need) { |
| 164 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 165 | zfcp_unit_get(unit); |
| 166 | atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status); |
| 167 | erp_action = &unit->erp_action; |
| 168 | if (!(atomic_read(&unit->status) & ZFCP_STATUS_COMMON_RUNNING)) |
| 169 | status = ZFCP_STATUS_ERP_CLOSE_ONLY; |
| 170 | break; |
| 171 | |
| 172 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 173 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 174 | zfcp_port_get(port); |
| 175 | zfcp_erp_action_dismiss_port(port); |
| 176 | atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status); |
| 177 | erp_action = &port->erp_action; |
| 178 | if (!(atomic_read(&port->status) & ZFCP_STATUS_COMMON_RUNNING)) |
| 179 | status = ZFCP_STATUS_ERP_CLOSE_ONLY; |
| 180 | break; |
| 181 | |
| 182 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 183 | zfcp_adapter_get(adapter); |
| 184 | zfcp_erp_action_dismiss_adapter(adapter); |
| 185 | atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status); |
| 186 | erp_action = &adapter->erp_action; |
| 187 | if (!(atomic_read(&adapter->status) & |
| 188 | ZFCP_STATUS_COMMON_RUNNING)) |
| 189 | status = ZFCP_STATUS_ERP_CLOSE_ONLY; |
| 190 | break; |
| 191 | |
| 192 | default: |
| 193 | return NULL; |
| 194 | } |
| 195 | |
| 196 | memset(erp_action, 0, sizeof(struct zfcp_erp_action)); |
| 197 | erp_action->adapter = adapter; |
| 198 | erp_action->port = port; |
| 199 | erp_action->unit = unit; |
| 200 | erp_action->action = need; |
| 201 | erp_action->status = status; |
| 202 | |
| 203 | return erp_action; |
| 204 | } |
| 205 | |
| 206 | static int zfcp_erp_action_enqueue(int want, struct zfcp_adapter *adapter, |
| 207 | struct zfcp_port *port, |
| 208 | struct zfcp_unit *unit, u8 id, void *ref) |
| 209 | { |
| 210 | int retval = 1, need; |
| 211 | struct zfcp_erp_action *act = NULL; |
| 212 | |
| 213 | if (!(atomic_read(&adapter->status) & |
| 214 | ZFCP_STATUS_ADAPTER_ERP_THREAD_UP)) |
| 215 | return -EIO; |
| 216 | |
| 217 | need = zfcp_erp_required_act(want, adapter, port, unit); |
| 218 | if (!need) |
| 219 | goto out; |
| 220 | |
| 221 | atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status); |
| 222 | act = zfcp_erp_setup_act(need, adapter, port, unit); |
| 223 | if (!act) |
| 224 | goto out; |
| 225 | ++adapter->erp_total_count; |
| 226 | list_add_tail(&act->list, &adapter->erp_ready_head); |
| 227 | up(&adapter->erp_ready_sem); |
| 228 | zfcp_rec_dbf_event_thread(1, adapter); |
| 229 | retval = 0; |
| 230 | out: |
| 231 | zfcp_rec_dbf_event_trigger(id, ref, want, need, act, |
| 232 | adapter, port, unit); |
| 233 | return retval; |
| 234 | } |
| 235 | |
| 236 | static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, |
| 237 | int clear_mask, u8 id, void *ref) |
| 238 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | zfcp_erp_adapter_block(adapter, clear_mask); |
| 240 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 241 | /* ensure propagation of failed status to new devices */ |
| 242 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 243 | zfcp_erp_adapter_failed(adapter, 13, NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 244 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 246 | return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, |
| 247 | adapter, NULL, NULL, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /** |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 251 | * zfcp_erp_adapter_reopen - Reopen adapter. |
| 252 | * @adapter: Adapter to reopen. |
| 253 | * @clear: Status flags to clear. |
| 254 | * @id: Id for debug trace event. |
| 255 | * @ref: Reference for debug trace event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 257 | void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear, |
| 258 | u8 id, void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 260 | unsigned long flags; |
| 261 | |
| 262 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 263 | write_lock(&adapter->erp_lock); |
| 264 | _zfcp_erp_adapter_reopen(adapter, clear, id, ref); |
| 265 | write_unlock(&adapter->erp_lock); |
| 266 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * zfcp_erp_adapter_shutdown - Shutdown adapter. |
| 271 | * @adapter: Adapter to shut down. |
| 272 | * @clear: Status flags to clear. |
| 273 | * @id: Id for debug trace event. |
| 274 | * @ref: Reference for debug trace event. |
| 275 | */ |
| 276 | void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear, |
| 277 | u8 id, void *ref) |
| 278 | { |
| 279 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 280 | zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * zfcp_erp_port_shutdown - Shutdown port |
| 285 | * @port: Port to shut down. |
| 286 | * @clear: Status flags to clear. |
| 287 | * @id: Id for debug trace event. |
| 288 | * @ref: Reference for debug trace event. |
| 289 | */ |
| 290 | void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, u8 id, void *ref) |
| 291 | { |
| 292 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 293 | zfcp_erp_port_reopen(port, clear | flags, id, ref); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * zfcp_erp_unit_shutdown - Shutdown unit |
| 298 | * @unit: Unit to shut down. |
| 299 | * @clear: Status flags to clear. |
| 300 | * @id: Id for debug trace event. |
| 301 | * @ref: Reference for debug trace event. |
| 302 | */ |
| 303 | void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, u8 id, void *ref) |
| 304 | { |
| 305 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 306 | zfcp_erp_unit_reopen(unit, clear | flags, id, ref); |
| 307 | } |
| 308 | |
| 309 | static void zfcp_erp_port_block(struct zfcp_port *port, int clear) |
| 310 | { |
| 311 | zfcp_erp_modify_port_status(port, 17, NULL, |
| 312 | ZFCP_STATUS_COMMON_UNBLOCKED | clear, |
| 313 | ZFCP_CLEAR); |
| 314 | } |
| 315 | |
| 316 | static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port, |
| 317 | int clear, u8 id, void *ref) |
| 318 | { |
| 319 | zfcp_erp_port_block(port, clear); |
| 320 | |
| 321 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 322 | return; |
| 323 | |
| 324 | zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED, |
| 325 | port->adapter, port, NULL, id, ref); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * zfcp_erp_port_forced_reopen - Forced close of port and open again |
| 330 | * @port: Port to force close and to reopen. |
| 331 | * @id: Id for debug trace event. |
| 332 | * @ref: Reference for debug trace event. |
| 333 | */ |
| 334 | void zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear, u8 id, |
| 335 | void *ref) |
| 336 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | unsigned long flags; |
| 338 | struct zfcp_adapter *adapter = port->adapter; |
| 339 | |
| 340 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 341 | write_lock(&adapter->erp_lock); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 342 | _zfcp_erp_port_forced_reopen(port, clear, id, ref); |
| 343 | write_unlock(&adapter->erp_lock); |
| 344 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 345 | } |
| 346 | |
| 347 | static int _zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, |
| 348 | void *ref) |
| 349 | { |
| 350 | zfcp_erp_port_block(port, clear); |
| 351 | |
| 352 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 353 | /* ensure propagation of failed status to new devices */ |
| 354 | zfcp_erp_port_failed(port, 14, NULL); |
| 355 | return -EIO; |
| 356 | } |
| 357 | |
| 358 | return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT, |
| 359 | port->adapter, port, NULL, id, ref); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * zfcp_erp_port_reopen - trigger remote port recovery |
| 364 | * @port: port to recover |
| 365 | * @clear_mask: flags in port status to be cleared |
| 366 | * |
| 367 | * Returns 0 if recovery has been triggered, < 0 if not. |
| 368 | */ |
| 369 | int zfcp_erp_port_reopen(struct zfcp_port *port, int clear, u8 id, void *ref) |
| 370 | { |
| 371 | unsigned long flags; |
| 372 | int retval; |
| 373 | struct zfcp_adapter *adapter = port->adapter; |
| 374 | |
| 375 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 376 | write_lock(&adapter->erp_lock); |
| 377 | retval = _zfcp_erp_port_reopen(port, clear, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | write_unlock(&adapter->erp_lock); |
| 379 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 380 | |
| 381 | return retval; |
| 382 | } |
| 383 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 384 | static void zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 386 | zfcp_erp_modify_unit_status(unit, 19, NULL, |
| 387 | ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask, |
| 388 | ZFCP_CLEAR); |
| 389 | } |
| 390 | |
| 391 | static void _zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, |
| 392 | void *ref) |
| 393 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | struct zfcp_adapter *adapter = unit->port->adapter; |
| 395 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 396 | zfcp_erp_unit_block(unit, clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 398 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 399 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 401 | zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT, |
| 402 | adapter, unit->port, unit, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /** |
| 406 | * zfcp_erp_unit_reopen - initiate reopen of a unit |
| 407 | * @unit: unit to be reopened |
| 408 | * @clear_mask: specifies flags in unit status to be cleared |
| 409 | * Return: 0 on success, < 0 on error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 411 | void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, u8 id, void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | unsigned long flags; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 414 | struct zfcp_port *port = unit->port; |
| 415 | struct zfcp_adapter *adapter = port->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 418 | write_lock(&adapter->erp_lock); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 419 | _zfcp_erp_unit_reopen(unit, clear, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | write_unlock(&adapter->erp_lock); |
| 421 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 424 | static int status_change_set(unsigned long mask, atomic_t *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 426 | return (atomic_read(status) ^ mask) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 429 | static int status_change_clear(unsigned long mask, atomic_t *status) |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 430 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 431 | return atomic_read(status) & mask; |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 434 | static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 436 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 437 | zfcp_rec_dbf_event_adapter(16, NULL, adapter); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 438 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 441 | static void zfcp_erp_port_unblock(struct zfcp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 443 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 444 | zfcp_rec_dbf_event_port(18, NULL, port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 445 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 448 | static void zfcp_erp_unit_unblock(struct zfcp_unit *unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 450 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status)) |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 451 | zfcp_rec_dbf_event_unit(20, NULL, unit); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 452 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 455 | 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] | 456 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 457 | list_move(&erp_action->list, &erp_action->adapter->erp_running_head); |
| 458 | zfcp_rec_dbf_event_action(145, erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 461 | static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 463 | struct zfcp_adapter *adapter = act->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 465 | if (!act->fsf_req) |
| 466 | return; |
| 467 | |
| 468 | spin_lock(&adapter->req_list_lock); |
| 469 | if (zfcp_reqlist_find_safe(adapter, act->fsf_req) && |
| 470 | act->fsf_req->erp_action == act) { |
| 471 | if (act->status & (ZFCP_STATUS_ERP_DISMISSED | |
| 472 | ZFCP_STATUS_ERP_TIMEDOUT)) { |
| 473 | act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
| 474 | zfcp_rec_dbf_event_action(142, act); |
Martin Petermann | 7ea633f | 2008-11-04 16:35:11 +0100 | [diff] [blame] | 475 | act->fsf_req->erp_action = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 477 | if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) |
| 478 | zfcp_rec_dbf_event_action(143, act); |
| 479 | if (act->fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED | |
| 480 | ZFCP_STATUS_FSFREQ_DISMISSED)) |
| 481 | act->fsf_req = NULL; |
| 482 | } else |
| 483 | act->fsf_req = NULL; |
| 484 | spin_unlock(&adapter->req_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 487 | /** |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 488 | * zfcp_erp_notify - Trigger ERP action. |
| 489 | * @erp_action: ERP action to continue. |
| 490 | * @set_mask: ERP action status flags to set. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 492 | void zfcp_erp_notify(struct zfcp_erp_action *erp_action, unsigned long set_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
| 494 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 495 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | write_lock_irqsave(&adapter->erp_lock, flags); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 498 | if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) { |
| 499 | erp_action->status |= set_mask; |
| 500 | zfcp_erp_action_ready(erp_action); |
| 501 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | write_unlock_irqrestore(&adapter->erp_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 505 | /** |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 506 | * zfcp_erp_timeout_handler - Trigger ERP action from timed out ERP request |
| 507 | * @data: ERP action (from timer data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 509 | void zfcp_erp_timeout_handler(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 511 | struct zfcp_erp_action *act = (struct zfcp_erp_action *) data; |
| 512 | zfcp_erp_notify(act, ZFCP_STATUS_ERP_TIMEDOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 515 | static void zfcp_erp_memwait_handler(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 517 | zfcp_erp_notify((struct zfcp_erp_action *)data, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 520 | static void zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | init_timer(&erp_action->timer); |
| 523 | erp_action->timer.function = zfcp_erp_memwait_handler; |
| 524 | erp_action->timer.data = (unsigned long) erp_action; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 525 | erp_action->timer.expires = jiffies + HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | add_timer(&erp_action->timer); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void _zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, |
| 530 | int clear, u8 id, void *ref) |
| 531 | { |
| 532 | struct zfcp_port *port; |
| 533 | |
| 534 | list_for_each_entry(port, &adapter->port_list_head, list) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 535 | _zfcp_erp_port_reopen(port, clear, id, ref); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void _zfcp_erp_unit_reopen_all(struct zfcp_port *port, int clear, u8 id, |
| 539 | void *ref) |
| 540 | { |
| 541 | struct zfcp_unit *unit; |
| 542 | |
| 543 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 544 | _zfcp_erp_unit_reopen(unit, clear, id, ref); |
| 545 | } |
| 546 | |
| 547 | static void zfcp_erp_strategy_followup_actions(struct zfcp_erp_action *act) |
| 548 | { |
| 549 | struct zfcp_adapter *adapter = act->adapter; |
| 550 | struct zfcp_port *port = act->port; |
| 551 | struct zfcp_unit *unit = act->unit; |
| 552 | u32 status = act->status; |
| 553 | |
| 554 | /* initiate follow-up actions depending on success of finished action */ |
| 555 | switch (act->action) { |
| 556 | |
| 557 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 558 | if (status == ZFCP_ERP_SUCCEEDED) |
| 559 | _zfcp_erp_port_reopen_all(adapter, 0, 70, NULL); |
| 560 | else |
| 561 | _zfcp_erp_adapter_reopen(adapter, 0, 71, NULL); |
| 562 | break; |
| 563 | |
| 564 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 565 | if (status == ZFCP_ERP_SUCCEEDED) |
| 566 | _zfcp_erp_port_reopen(port, 0, 72, NULL); |
| 567 | else |
| 568 | _zfcp_erp_adapter_reopen(adapter, 0, 73, NULL); |
| 569 | break; |
| 570 | |
| 571 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 572 | if (status == ZFCP_ERP_SUCCEEDED) |
| 573 | _zfcp_erp_unit_reopen_all(port, 0, 74, NULL); |
| 574 | else |
| 575 | _zfcp_erp_port_forced_reopen(port, 0, 75, NULL); |
| 576 | break; |
| 577 | |
| 578 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 579 | if (status != ZFCP_ERP_SUCCEEDED) |
| 580 | _zfcp_erp_port_reopen(unit->port, 0, 76, NULL); |
| 581 | break; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | static void zfcp_erp_wakeup(struct zfcp_adapter *adapter) |
| 586 | { |
| 587 | unsigned long flags; |
| 588 | |
| 589 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 590 | read_lock(&adapter->erp_lock); |
| 591 | if (list_empty(&adapter->erp_ready_head) && |
| 592 | list_empty(&adapter->erp_running_head)) { |
| 593 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, |
| 594 | &adapter->status); |
| 595 | wake_up(&adapter->erp_done_wqh); |
| 596 | } |
| 597 | read_unlock(&adapter->erp_lock); |
| 598 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 599 | } |
| 600 | |
| 601 | static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act) |
| 602 | { |
| 603 | if (zfcp_qdio_open(act->adapter)) |
| 604 | return ZFCP_ERP_FAILED; |
| 605 | init_waitqueue_head(&act->adapter->request_wq); |
| 606 | atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status); |
| 607 | return ZFCP_ERP_SUCCEEDED; |
| 608 | } |
| 609 | |
| 610 | static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter) |
| 611 | { |
| 612 | struct zfcp_port *port; |
| 613 | port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0, |
| 614 | adapter->peer_d_id); |
| 615 | if (IS_ERR(port)) /* error or port already attached */ |
| 616 | return; |
| 617 | _zfcp_erp_port_reopen(port, 0, 150, NULL); |
| 618 | } |
| 619 | |
| 620 | static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action) |
| 621 | { |
| 622 | int retries; |
| 623 | int sleep = 1; |
| 624 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 625 | |
| 626 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status); |
| 627 | |
| 628 | for (retries = 7; retries; retries--) { |
| 629 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 630 | &adapter->status); |
| 631 | write_lock_irq(&adapter->erp_lock); |
| 632 | zfcp_erp_action_to_running(erp_action); |
| 633 | write_unlock_irq(&adapter->erp_lock); |
| 634 | if (zfcp_fsf_exchange_config_data(erp_action)) { |
| 635 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 636 | &adapter->status); |
| 637 | return ZFCP_ERP_FAILED; |
| 638 | } |
| 639 | |
| 640 | zfcp_rec_dbf_event_thread_lock(6, adapter); |
| 641 | down(&adapter->erp_ready_sem); |
| 642 | zfcp_rec_dbf_event_thread_lock(7, adapter); |
| 643 | if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) |
| 644 | break; |
| 645 | |
| 646 | if (!(atomic_read(&adapter->status) & |
| 647 | ZFCP_STATUS_ADAPTER_HOST_CON_INIT)) |
| 648 | break; |
| 649 | |
| 650 | ssleep(sleep); |
| 651 | sleep *= 2; |
| 652 | } |
| 653 | |
| 654 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 655 | &adapter->status); |
| 656 | |
| 657 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK)) |
| 658 | return ZFCP_ERP_FAILED; |
| 659 | |
| 660 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) |
| 661 | zfcp_erp_enqueue_ptp_port(adapter); |
| 662 | |
| 663 | return ZFCP_ERP_SUCCEEDED; |
| 664 | } |
| 665 | |
| 666 | static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act) |
| 667 | { |
| 668 | int ret; |
| 669 | struct zfcp_adapter *adapter = act->adapter; |
| 670 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 671 | write_lock_irq(&adapter->erp_lock); |
| 672 | zfcp_erp_action_to_running(act); |
| 673 | write_unlock_irq(&adapter->erp_lock); |
| 674 | |
| 675 | ret = zfcp_fsf_exchange_port_data(act); |
| 676 | if (ret == -EOPNOTSUPP) |
| 677 | return ZFCP_ERP_SUCCEEDED; |
| 678 | if (ret) |
| 679 | return ZFCP_ERP_FAILED; |
| 680 | |
| 681 | zfcp_rec_dbf_event_thread_lock(8, adapter); |
| 682 | down(&adapter->erp_ready_sem); |
| 683 | zfcp_rec_dbf_event_thread_lock(9, adapter); |
| 684 | if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) |
| 685 | return ZFCP_ERP_FAILED; |
| 686 | |
| 687 | return ZFCP_ERP_SUCCEEDED; |
| 688 | } |
| 689 | |
| 690 | static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act) |
| 691 | { |
| 692 | if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED) |
| 693 | return ZFCP_ERP_FAILED; |
| 694 | |
| 695 | if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED) |
| 696 | return ZFCP_ERP_FAILED; |
| 697 | |
| 698 | atomic_set(&act->adapter->stat_miss, 16); |
| 699 | if (zfcp_status_read_refill(act->adapter)) |
| 700 | return ZFCP_ERP_FAILED; |
| 701 | |
| 702 | return ZFCP_ERP_SUCCEEDED; |
| 703 | } |
| 704 | |
| 705 | static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *act, |
| 706 | int close) |
| 707 | { |
| 708 | int retval = ZFCP_ERP_SUCCEEDED; |
| 709 | struct zfcp_adapter *adapter = act->adapter; |
| 710 | |
| 711 | if (close) |
| 712 | goto close_only; |
| 713 | |
| 714 | retval = zfcp_erp_adapter_strategy_open_qdio(act); |
| 715 | if (retval != ZFCP_ERP_SUCCEEDED) |
| 716 | goto failed_qdio; |
| 717 | |
| 718 | retval = zfcp_erp_adapter_strategy_open_fsf(act); |
| 719 | if (retval != ZFCP_ERP_SUCCEEDED) |
| 720 | goto failed_openfcp; |
| 721 | |
| 722 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &act->adapter->status); |
| 723 | schedule_work(&act->adapter->scan_work); |
| 724 | |
| 725 | return ZFCP_ERP_SUCCEEDED; |
| 726 | |
| 727 | close_only: |
| 728 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, |
| 729 | &act->adapter->status); |
| 730 | |
| 731 | failed_openfcp: |
| 732 | /* close queues to ensure that buffers are not accessed by adapter */ |
| 733 | zfcp_qdio_close(adapter); |
| 734 | zfcp_fsf_req_dismiss_all(adapter); |
| 735 | adapter->fsf_req_seq_no = 0; |
| 736 | /* all ports and units are closed */ |
| 737 | zfcp_erp_modify_adapter_status(adapter, 24, NULL, |
| 738 | ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR); |
| 739 | failed_qdio: |
| 740 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK | |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 741 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 742 | &act->adapter->status); |
| 743 | return retval; |
| 744 | } |
| 745 | |
| 746 | static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act) |
| 747 | { |
| 748 | int retval; |
| 749 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 750 | zfcp_erp_adapter_strategy_generic(act, 1); /* close */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 751 | if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
| 752 | return ZFCP_ERP_EXIT; |
| 753 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 754 | retval = zfcp_erp_adapter_strategy_generic(act, 0); /* open */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 755 | |
| 756 | if (retval == ZFCP_ERP_FAILED) |
| 757 | ssleep(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | return retval; |
| 760 | } |
| 761 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 762 | static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 764 | int retval; |
| 765 | |
| 766 | retval = zfcp_fsf_close_physical_port(act); |
| 767 | if (retval == -ENOMEM) |
| 768 | return ZFCP_ERP_NOMEM; |
| 769 | act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING; |
| 770 | if (retval) |
| 771 | return ZFCP_ERP_FAILED; |
| 772 | |
| 773 | return ZFCP_ERP_CONTINUES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 776 | static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 778 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 779 | ZFCP_STATUS_PORT_PHYS_CLOSING | |
| 780 | ZFCP_STATUS_PORT_INVALID_WWPN, |
| 781 | &port->status); |
| 782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 784 | static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action) |
| 785 | { |
| 786 | struct zfcp_port *port = erp_action->port; |
| 787 | int status = atomic_read(&port->status); |
| 788 | |
| 789 | switch (erp_action->step) { |
| 790 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 791 | zfcp_erp_port_strategy_clearstati(port); |
| 792 | if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) && |
| 793 | (status & ZFCP_STATUS_COMMON_OPEN)) |
| 794 | return zfcp_erp_port_forced_strategy_close(erp_action); |
| 795 | else |
| 796 | return ZFCP_ERP_FAILED; |
| 797 | |
| 798 | case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: |
| 799 | if (status & ZFCP_STATUS_PORT_PHYS_OPEN) |
| 800 | return ZFCP_ERP_SUCCEEDED; |
| 801 | } |
| 802 | return ZFCP_ERP_FAILED; |
| 803 | } |
| 804 | |
| 805 | static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action) |
| 806 | { |
| 807 | int retval; |
| 808 | |
| 809 | retval = zfcp_fsf_close_port(erp_action); |
| 810 | if (retval == -ENOMEM) |
| 811 | return ZFCP_ERP_NOMEM; |
| 812 | erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING; |
| 813 | if (retval) |
| 814 | return ZFCP_ERP_FAILED; |
| 815 | return ZFCP_ERP_CONTINUES; |
| 816 | } |
| 817 | |
| 818 | static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action) |
| 819 | { |
| 820 | int retval; |
| 821 | |
| 822 | retval = zfcp_fsf_open_port(erp_action); |
| 823 | if (retval == -ENOMEM) |
| 824 | return ZFCP_ERP_NOMEM; |
| 825 | erp_action->step = ZFCP_ERP_STEP_PORT_OPENING; |
| 826 | if (retval) |
| 827 | return ZFCP_ERP_FAILED; |
| 828 | return ZFCP_ERP_CONTINUES; |
| 829 | } |
| 830 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 831 | static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act) |
| 832 | { |
| 833 | struct zfcp_adapter *adapter = act->adapter; |
| 834 | struct zfcp_port *port = act->port; |
| 835 | |
| 836 | if (port->wwpn != adapter->peer_wwpn) { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 837 | zfcp_erp_port_failed(port, 25, NULL); |
| 838 | return ZFCP_ERP_FAILED; |
| 839 | } |
| 840 | port->d_id = adapter->peer_d_id; |
| 841 | atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status); |
| 842 | return zfcp_erp_port_strategy_open_port(act); |
| 843 | } |
| 844 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 845 | void zfcp_erp_port_strategy_open_lookup(struct work_struct *work) |
| 846 | { |
| 847 | int retval; |
| 848 | struct zfcp_port *port = container_of(work, struct zfcp_port, |
| 849 | gid_pn_work); |
| 850 | |
| 851 | retval = zfcp_fc_ns_gid_pn(&port->erp_action); |
| 852 | if (retval == -ENOMEM) |
| 853 | zfcp_erp_notify(&port->erp_action, ZFCP_ERP_NOMEM); |
| 854 | port->erp_action.step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP; |
| 855 | if (retval) |
| 856 | zfcp_erp_notify(&port->erp_action, ZFCP_ERP_FAILED); |
| 857 | |
| 858 | } |
| 859 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 860 | static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act) |
| 861 | { |
| 862 | struct zfcp_adapter *adapter = act->adapter; |
| 863 | struct zfcp_port *port = act->port; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 864 | int p_status = atomic_read(&port->status); |
| 865 | |
| 866 | switch (act->step) { |
| 867 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 868 | case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: |
| 869 | case ZFCP_ERP_STEP_PORT_CLOSING: |
| 870 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) |
| 871 | return zfcp_erp_open_ptp_port(act); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 872 | if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) { |
Swen Schillig | b7f15f3 | 2008-10-01 12:42:22 +0200 | [diff] [blame] | 873 | queue_work(zfcp_data.work_queue, &port->gid_pn_work); |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 874 | return ZFCP_ERP_CONTINUES; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 875 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 876 | case ZFCP_ERP_STEP_NAMESERVER_LOOKUP: |
| 877 | if (!(p_status & ZFCP_STATUS_PORT_DID_DID)) { |
| 878 | if (p_status & (ZFCP_STATUS_PORT_INVALID_WWPN)) { |
| 879 | zfcp_erp_port_failed(port, 26, NULL); |
| 880 | return ZFCP_ERP_EXIT; |
| 881 | } |
| 882 | return ZFCP_ERP_FAILED; |
| 883 | } |
| 884 | return zfcp_erp_port_strategy_open_port(act); |
| 885 | |
| 886 | case ZFCP_ERP_STEP_PORT_OPENING: |
| 887 | /* D_ID might have changed during open */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 888 | if (p_status & ZFCP_STATUS_COMMON_OPEN) { |
| 889 | if (p_status & ZFCP_STATUS_PORT_DID_DID) |
| 890 | return ZFCP_ERP_SUCCEEDED; |
| 891 | else { |
| 892 | act->step = ZFCP_ERP_STEP_PORT_CLOSING; |
| 893 | return ZFCP_ERP_CONTINUES; |
| 894 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 895 | /* fall through otherwise */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 896 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 897 | } |
| 898 | return ZFCP_ERP_FAILED; |
| 899 | } |
| 900 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 901 | static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action) |
| 902 | { |
| 903 | struct zfcp_port *port = erp_action->port; |
| 904 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 905 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) |
| 906 | goto close_init_done; |
| 907 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 908 | switch (erp_action->step) { |
| 909 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 910 | zfcp_erp_port_strategy_clearstati(port); |
| 911 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN) |
| 912 | return zfcp_erp_port_strategy_close(erp_action); |
| 913 | break; |
| 914 | |
| 915 | case ZFCP_ERP_STEP_PORT_CLOSING: |
| 916 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN) |
| 917 | return ZFCP_ERP_FAILED; |
| 918 | break; |
| 919 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 920 | |
| 921 | close_init_done: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 922 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
| 923 | return ZFCP_ERP_EXIT; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 924 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 925 | return zfcp_erp_port_strategy_open_common(erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 928 | static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 930 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 931 | ZFCP_STATUS_UNIT_SHARED | |
| 932 | ZFCP_STATUS_UNIT_READONLY, |
| 933 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 936 | static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action) |
| 937 | { |
| 938 | int retval = zfcp_fsf_close_unit(erp_action); |
| 939 | if (retval == -ENOMEM) |
| 940 | return ZFCP_ERP_NOMEM; |
| 941 | erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING; |
| 942 | if (retval) |
| 943 | return ZFCP_ERP_FAILED; |
| 944 | return ZFCP_ERP_CONTINUES; |
| 945 | } |
| 946 | |
| 947 | static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action) |
| 948 | { |
| 949 | int retval = zfcp_fsf_open_unit(erp_action); |
| 950 | if (retval == -ENOMEM) |
| 951 | return ZFCP_ERP_NOMEM; |
| 952 | erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING; |
| 953 | if (retval) |
| 954 | return ZFCP_ERP_FAILED; |
| 955 | return ZFCP_ERP_CONTINUES; |
| 956 | } |
| 957 | |
| 958 | static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action) |
| 959 | { |
| 960 | struct zfcp_unit *unit = erp_action->unit; |
| 961 | |
| 962 | switch (erp_action->step) { |
| 963 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 964 | zfcp_erp_unit_strategy_clearstati(unit); |
| 965 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 966 | return zfcp_erp_unit_strategy_close(erp_action); |
| 967 | /* already closed, fall through */ |
| 968 | case ZFCP_ERP_STEP_UNIT_CLOSING: |
| 969 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 970 | return ZFCP_ERP_FAILED; |
| 971 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
| 972 | return ZFCP_ERP_EXIT; |
| 973 | return zfcp_erp_unit_strategy_open(erp_action); |
| 974 | |
| 975 | case ZFCP_ERP_STEP_UNIT_OPENING: |
| 976 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 977 | return ZFCP_ERP_SUCCEEDED; |
| 978 | } |
| 979 | return ZFCP_ERP_FAILED; |
| 980 | } |
| 981 | |
| 982 | static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result) |
| 983 | { |
| 984 | switch (result) { |
| 985 | case ZFCP_ERP_SUCCEEDED : |
| 986 | atomic_set(&unit->erp_counter, 0); |
| 987 | zfcp_erp_unit_unblock(unit); |
| 988 | break; |
| 989 | case ZFCP_ERP_FAILED : |
| 990 | atomic_inc(&unit->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 991 | if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) { |
| 992 | dev_err(&unit->port->adapter->ccw_device->dev, |
| 993 | "ERP failed for unit 0x%016Lx on " |
| 994 | "port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 995 | (unsigned long long)unit->fcp_lun, |
| 996 | (unsigned long long)unit->port->wwpn); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 997 | zfcp_erp_unit_failed(unit, 21, NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 998 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1003 | zfcp_erp_unit_block(unit, 0); |
| 1004 | result = ZFCP_ERP_EXIT; |
| 1005 | } |
| 1006 | return result; |
| 1007 | } |
| 1008 | |
| 1009 | static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result) |
| 1010 | { |
| 1011 | switch (result) { |
| 1012 | case ZFCP_ERP_SUCCEEDED : |
| 1013 | atomic_set(&port->erp_counter, 0); |
| 1014 | zfcp_erp_port_unblock(port); |
| 1015 | break; |
| 1016 | |
| 1017 | case ZFCP_ERP_FAILED : |
| 1018 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) { |
| 1019 | zfcp_erp_port_block(port, 0); |
| 1020 | result = ZFCP_ERP_EXIT; |
| 1021 | } |
| 1022 | atomic_inc(&port->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1023 | if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) { |
| 1024 | dev_err(&port->adapter->ccw_device->dev, |
| 1025 | "ERP failed for remote port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 1026 | (unsigned long long)port->wwpn); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1027 | zfcp_erp_port_failed(port, 22, NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1028 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1029 | break; |
| 1030 | } |
| 1031 | |
| 1032 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1033 | zfcp_erp_port_block(port, 0); |
| 1034 | result = ZFCP_ERP_EXIT; |
| 1035 | } |
| 1036 | return result; |
| 1037 | } |
| 1038 | |
| 1039 | static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, |
| 1040 | int result) |
| 1041 | { |
| 1042 | switch (result) { |
| 1043 | case ZFCP_ERP_SUCCEEDED : |
| 1044 | atomic_set(&adapter->erp_counter, 0); |
| 1045 | zfcp_erp_adapter_unblock(adapter); |
| 1046 | break; |
| 1047 | |
| 1048 | case ZFCP_ERP_FAILED : |
| 1049 | atomic_inc(&adapter->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1050 | if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) { |
| 1051 | dev_err(&adapter->ccw_device->dev, |
| 1052 | "ERP cannot recover an error " |
| 1053 | "on the FCP device\n"); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1054 | zfcp_erp_adapter_failed(adapter, 23, NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1055 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1056 | break; |
| 1057 | } |
| 1058 | |
| 1059 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1060 | zfcp_erp_adapter_block(adapter, 0); |
| 1061 | result = ZFCP_ERP_EXIT; |
| 1062 | } |
| 1063 | return result; |
| 1064 | } |
| 1065 | |
| 1066 | static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, |
| 1067 | int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | { |
| 1069 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1070 | struct zfcp_port *port = erp_action->port; |
| 1071 | struct zfcp_unit *unit = erp_action->unit; |
| 1072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | switch (erp_action->action) { |
| 1074 | |
| 1075 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1076 | result = zfcp_erp_strategy_check_unit(unit, result); |
| 1077 | break; |
| 1078 | |
| 1079 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1080 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1081 | result = zfcp_erp_strategy_check_port(port, result); |
| 1082 | break; |
| 1083 | |
| 1084 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1085 | result = zfcp_erp_strategy_check_adapter(adapter, result); |
| 1086 | break; |
| 1087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | return result; |
| 1089 | } |
| 1090 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1091 | static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1093 | int status = atomic_read(target_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1095 | if ((status & ZFCP_STATUS_COMMON_RUNNING) && |
| 1096 | (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) |
| 1097 | return 1; /* take it online */ |
| 1098 | |
| 1099 | if (!(status & ZFCP_STATUS_COMMON_RUNNING) && |
| 1100 | !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) |
| 1101 | return 1; /* take it offline */ |
| 1102 | |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
| 1106 | static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret) |
| 1107 | { |
| 1108 | int action = act->action; |
| 1109 | struct zfcp_adapter *adapter = act->adapter; |
| 1110 | struct zfcp_port *port = act->port; |
| 1111 | struct zfcp_unit *unit = act->unit; |
| 1112 | u32 erp_status = act->status; |
| 1113 | |
| 1114 | switch (action) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1116 | if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) { |
| 1117 | _zfcp_erp_adapter_reopen(adapter, |
| 1118 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 1119 | 67, NULL); |
| 1120 | return ZFCP_ERP_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | } |
| 1122 | break; |
| 1123 | |
| 1124 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1125 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1126 | if (zfcp_erp_strat_change_det(&port->status, erp_status)) { |
| 1127 | _zfcp_erp_port_reopen(port, |
| 1128 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 1129 | 68, NULL); |
| 1130 | return ZFCP_ERP_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | } |
| 1132 | break; |
| 1133 | |
| 1134 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1135 | if (zfcp_erp_strat_change_det(&unit->status, erp_status)) { |
| 1136 | _zfcp_erp_unit_reopen(unit, |
| 1137 | ZFCP_STATUS_COMMON_ERP_FAILED, |
| 1138 | 69, NULL); |
| 1139 | return ZFCP_ERP_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | break; |
| 1142 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1143 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1146 | static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1148 | struct zfcp_adapter *adapter = erp_action->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1150 | adapter->erp_total_count--; |
| 1151 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { |
| 1152 | adapter->erp_low_mem_count--; |
| 1153 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1156 | list_del(&erp_action->list); |
| 1157 | zfcp_rec_dbf_event_action(144, erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1159 | switch (erp_action->action) { |
| 1160 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1161 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1162 | &erp_action->unit->status); |
| 1163 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1165 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1166 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1167 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1168 | &erp_action->port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1170 | |
| 1171 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1172 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1173 | &erp_action->adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | break; |
| 1175 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1178 | struct zfcp_erp_add_work { |
| 1179 | struct zfcp_unit *unit; |
| 1180 | struct work_struct work; |
| 1181 | }; |
| 1182 | |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1183 | static void zfcp_erp_scsi_scan(struct work_struct *work) |
| 1184 | { |
| 1185 | struct zfcp_erp_add_work *p = |
| 1186 | container_of(work, struct zfcp_erp_add_work, work); |
| 1187 | struct zfcp_unit *unit = p->unit; |
| 1188 | struct fc_rport *rport = unit->port->rport; |
| 1189 | scsi_scan_target(&rport->dev, 0, rport->scsi_target_id, |
Christof Schmitt | 0406289 | 2008-10-01 12:42:20 +0200 | [diff] [blame] | 1190 | scsilun_to_int((struct scsi_lun *)&unit->fcp_lun), 0); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1191 | atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1192 | zfcp_unit_put(unit); |
Swen Schillig | 091694a | 2008-10-01 12:42:25 +0200 | [diff] [blame] | 1193 | wake_up(&unit->port->adapter->erp_done_wqh); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1194 | kfree(p); |
| 1195 | } |
| 1196 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1197 | static void zfcp_erp_schedule_work(struct zfcp_unit *unit) |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1198 | { |
| 1199 | struct zfcp_erp_add_work *p; |
| 1200 | |
Swen Schillig | 0d66132 | 2007-07-18 10:55:08 +0200 | [diff] [blame] | 1201 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1202 | if (!p) { |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 1203 | dev_err(&unit->port->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1204 | "Registering unit 0x%016Lx on port 0x%016Lx failed\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 1205 | (unsigned long long)unit->fcp_lun, |
| 1206 | (unsigned long long)unit->port->wwpn); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1207 | return; |
| 1208 | } |
| 1209 | |
| 1210 | zfcp_unit_get(unit); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1211 | atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status); |
| 1212 | INIT_WORK(&p->work, zfcp_erp_scsi_scan); |
| 1213 | p->unit = unit; |
Swen Schillig | b7f15f3 | 2008-10-01 12:42:22 +0200 | [diff] [blame] | 1214 | queue_work(zfcp_data.work_queue, &p->work); |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1215 | } |
| 1216 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1217 | static void zfcp_erp_rport_register(struct zfcp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1219 | struct fc_rport_identifiers ids; |
| 1220 | ids.node_name = port->wwnn; |
| 1221 | ids.port_name = port->wwpn; |
| 1222 | ids.port_id = port->d_id; |
| 1223 | ids.roles = FC_RPORT_ROLE_FCP_TARGET; |
| 1224 | port->rport = fc_remote_port_add(port->adapter->scsi_host, 0, &ids); |
| 1225 | if (!port->rport) { |
| 1226 | dev_err(&port->adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1227 | "Registering port 0x%016Lx failed\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 1228 | (unsigned long long)port->wwpn); |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 1229 | return; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | scsi_target_unblock(&port->rport->dev); |
| 1233 | port->rport->maxframe_size = port->maxframe_size; |
| 1234 | port->rport->supported_classes = port->supported_classes; |
Swen Schillig | cc8c282 | 2008-06-10 18:21:00 +0200 | [diff] [blame] | 1235 | } |
| 1236 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1237 | static void zfcp_erp_rports_del(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1239 | struct zfcp_port *port; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1240 | list_for_each_entry(port, &adapter->port_list_head, list) { |
Swen Schillig | e4e9ba5 | 2008-10-01 12:42:23 +0200 | [diff] [blame] | 1241 | if (!port->rport) |
| 1242 | continue; |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1243 | fc_remote_port_delete(port->rport); |
| 1244 | port->rport = NULL; |
| 1245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1248 | static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result) |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1249 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1250 | struct zfcp_adapter *adapter = act->adapter; |
| 1251 | struct zfcp_port *port = act->port; |
| 1252 | struct zfcp_unit *unit = act->unit; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1253 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1254 | switch (act->action) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1256 | if ((result == ZFCP_ERP_SUCCEEDED) && |
| 1257 | !unit->device && port->rport) { |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 1258 | atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED, |
| 1259 | &unit->status); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1260 | if (!(atomic_read(&unit->status) & |
| 1261 | ZFCP_STATUS_UNIT_SCSI_WORK_PENDING)) |
Christof Schmitt | 5f852be | 2007-05-08 11:16:52 +0200 | [diff] [blame] | 1262 | zfcp_erp_schedule_work(unit); |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 1263 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | zfcp_unit_put(unit); |
| 1265 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1268 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1269 | if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN) { |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 1270 | zfcp_port_put(port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1271 | return; |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 1272 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1273 | if ((result == ZFCP_ERP_SUCCEEDED) && !port->rport) |
| 1274 | zfcp_erp_rport_register(port); |
Andreas Herrmann | 338151e | 2006-05-22 18:25:56 +0200 | [diff] [blame] | 1275 | if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) { |
| 1276 | fc_remote_port_delete(port->rport); |
| 1277 | port->rport = NULL; |
| 1278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | zfcp_port_put(port); |
| 1280 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1283 | if (result != ZFCP_ERP_SUCCEEDED) |
| 1284 | zfcp_erp_rports_del(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | zfcp_adapter_put(adapter); |
| 1286 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1290 | static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action) |
| 1291 | { |
| 1292 | switch (erp_action->action) { |
| 1293 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1294 | return zfcp_erp_adapter_strategy(erp_action); |
| 1295 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1296 | return zfcp_erp_port_forced_strategy(erp_action); |
| 1297 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1298 | return zfcp_erp_port_strategy(erp_action); |
| 1299 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1300 | return zfcp_erp_unit_strategy(erp_action); |
| 1301 | } |
| 1302 | return ZFCP_ERP_FAILED; |
| 1303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1305 | static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action) |
| 1306 | { |
| 1307 | int retval; |
| 1308 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1309 | unsigned long flags; |
| 1310 | |
| 1311 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1312 | write_lock(&adapter->erp_lock); |
| 1313 | |
| 1314 | zfcp_erp_strategy_check_fsfreq(erp_action); |
| 1315 | |
| 1316 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) { |
| 1317 | zfcp_erp_action_dequeue(erp_action); |
| 1318 | retval = ZFCP_ERP_DISMISSED; |
| 1319 | goto unlock; |
| 1320 | } |
| 1321 | |
| 1322 | zfcp_erp_action_to_running(erp_action); |
| 1323 | |
| 1324 | /* no lock to allow for blocking operations */ |
| 1325 | write_unlock(&adapter->erp_lock); |
| 1326 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1327 | retval = zfcp_erp_strategy_do_action(erp_action); |
| 1328 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1329 | write_lock(&adapter->erp_lock); |
| 1330 | |
| 1331 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) |
| 1332 | retval = ZFCP_ERP_CONTINUES; |
| 1333 | |
| 1334 | switch (retval) { |
| 1335 | case ZFCP_ERP_NOMEM: |
| 1336 | if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) { |
| 1337 | ++adapter->erp_low_mem_count; |
| 1338 | erp_action->status |= ZFCP_STATUS_ERP_LOWMEM; |
| 1339 | } |
| 1340 | if (adapter->erp_total_count == adapter->erp_low_mem_count) |
| 1341 | _zfcp_erp_adapter_reopen(adapter, 0, 66, NULL); |
| 1342 | else { |
| 1343 | zfcp_erp_strategy_memwait(erp_action); |
| 1344 | retval = ZFCP_ERP_CONTINUES; |
| 1345 | } |
| 1346 | goto unlock; |
| 1347 | |
| 1348 | case ZFCP_ERP_CONTINUES: |
| 1349 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { |
| 1350 | --adapter->erp_low_mem_count; |
| 1351 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; |
| 1352 | } |
| 1353 | goto unlock; |
| 1354 | } |
| 1355 | |
| 1356 | retval = zfcp_erp_strategy_check_target(erp_action, retval); |
| 1357 | zfcp_erp_action_dequeue(erp_action); |
| 1358 | retval = zfcp_erp_strategy_statechange(erp_action, retval); |
| 1359 | if (retval == ZFCP_ERP_EXIT) |
| 1360 | goto unlock; |
| 1361 | zfcp_erp_strategy_followup_actions(erp_action); |
| 1362 | |
| 1363 | unlock: |
| 1364 | write_unlock(&adapter->erp_lock); |
| 1365 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1366 | |
| 1367 | if (retval != ZFCP_ERP_CONTINUES) |
| 1368 | zfcp_erp_action_cleanup(erp_action, retval); |
| 1369 | |
| 1370 | return retval; |
| 1371 | } |
| 1372 | |
| 1373 | static int zfcp_erp_thread(void *data) |
| 1374 | { |
| 1375 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; |
| 1376 | struct list_head *next; |
| 1377 | struct zfcp_erp_action *act; |
| 1378 | unsigned long flags; |
| 1379 | |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 1380 | daemonize("zfcperp%s", dev_name(&adapter->ccw_device->dev)); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1381 | /* Block all signals */ |
| 1382 | siginitsetinv(¤t->blocked, 0); |
| 1383 | atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status); |
| 1384 | wake_up(&adapter->erp_thread_wqh); |
| 1385 | |
| 1386 | while (!(atomic_read(&adapter->status) & |
| 1387 | ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL)) { |
| 1388 | write_lock_irqsave(&adapter->erp_lock, flags); |
| 1389 | next = adapter->erp_ready_head.next; |
| 1390 | write_unlock_irqrestore(&adapter->erp_lock, flags); |
| 1391 | |
| 1392 | if (next != &adapter->erp_ready_head) { |
| 1393 | act = list_entry(next, struct zfcp_erp_action, list); |
| 1394 | |
| 1395 | /* there is more to come after dismission, no notify */ |
| 1396 | if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED) |
| 1397 | zfcp_erp_wakeup(adapter); |
| 1398 | } |
| 1399 | |
Swen Schillig | 9fb3cd8 | 2008-10-01 12:42:24 +0200 | [diff] [blame] | 1400 | zfcp_rec_dbf_event_thread_lock(4, adapter); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1401 | down_interruptible(&adapter->erp_ready_sem); |
Swen Schillig | 9fb3cd8 | 2008-10-01 12:42:24 +0200 | [diff] [blame] | 1402 | zfcp_rec_dbf_event_thread_lock(5, adapter); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status); |
| 1406 | wake_up(&adapter->erp_thread_wqh); |
| 1407 | |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | /** |
| 1412 | * zfcp_erp_thread_setup - Start ERP thread for adapter |
| 1413 | * @adapter: Adapter to start the ERP thread for |
| 1414 | * |
| 1415 | * Returns 0 on success or error code from kernel_thread() |
| 1416 | */ |
| 1417 | int zfcp_erp_thread_setup(struct zfcp_adapter *adapter) |
| 1418 | { |
| 1419 | int retval; |
| 1420 | |
| 1421 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status); |
| 1422 | retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD); |
| 1423 | if (retval < 0) { |
| 1424 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1425 | "Creating an ERP thread for the FCP device failed.\n"); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1426 | return retval; |
| 1427 | } |
| 1428 | wait_event(adapter->erp_thread_wqh, |
| 1429 | atomic_read(&adapter->status) & |
| 1430 | ZFCP_STATUS_ADAPTER_ERP_THREAD_UP); |
| 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * zfcp_erp_thread_kill - Stop ERP thread. |
| 1436 | * @adapter: Adapter where the ERP thread should be stopped. |
| 1437 | * |
| 1438 | * The caller of this routine ensures that the specified adapter has |
| 1439 | * been shut down and that this operation has been completed. Thus, |
| 1440 | * there are no pending erp_actions which would need to be handled |
| 1441 | * here. |
| 1442 | */ |
| 1443 | void zfcp_erp_thread_kill(struct zfcp_adapter *adapter) |
| 1444 | { |
| 1445 | atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status); |
| 1446 | up(&adapter->erp_ready_sem); |
Swen Schillig | 41bfcf9 | 2008-10-01 12:42:26 +0200 | [diff] [blame] | 1447 | zfcp_rec_dbf_event_thread_lock(3, adapter); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1448 | |
| 1449 | wait_event(adapter->erp_thread_wqh, |
| 1450 | !(atomic_read(&adapter->status) & |
| 1451 | ZFCP_STATUS_ADAPTER_ERP_THREAD_UP)); |
| 1452 | |
| 1453 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, |
| 1454 | &adapter->status); |
| 1455 | } |
| 1456 | |
| 1457 | /** |
| 1458 | * zfcp_erp_adapter_failed - Set adapter status to failed. |
| 1459 | * @adapter: Failed adapter. |
| 1460 | * @id: Event id for debug trace. |
| 1461 | * @ref: Reference for debug trace. |
| 1462 | */ |
| 1463 | void zfcp_erp_adapter_failed(struct zfcp_adapter *adapter, u8 id, void *ref) |
| 1464 | { |
| 1465 | zfcp_erp_modify_adapter_status(adapter, id, ref, |
| 1466 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /** |
| 1470 | * zfcp_erp_port_failed - Set port status to failed. |
| 1471 | * @port: Failed port. |
| 1472 | * @id: Event id for debug trace. |
| 1473 | * @ref: Reference for debug trace. |
| 1474 | */ |
| 1475 | void zfcp_erp_port_failed(struct zfcp_port *port, u8 id, void *ref) |
| 1476 | { |
| 1477 | zfcp_erp_modify_port_status(port, id, ref, |
| 1478 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /** |
| 1482 | * zfcp_erp_unit_failed - Set unit status to failed. |
| 1483 | * @unit: Failed unit. |
| 1484 | * @id: Event id for debug trace. |
| 1485 | * @ref: Reference for debug trace. |
| 1486 | */ |
| 1487 | void zfcp_erp_unit_failed(struct zfcp_unit *unit, u8 id, void *ref) |
| 1488 | { |
| 1489 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1490 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /** |
| 1494 | * zfcp_erp_wait - wait for completion of error recovery on an adapter |
| 1495 | * @adapter: adapter for which to wait for completion of its error recovery |
| 1496 | */ |
| 1497 | void zfcp_erp_wait(struct zfcp_adapter *adapter) |
| 1498 | { |
| 1499 | wait_event(adapter->erp_done_wqh, |
| 1500 | !(atomic_read(&adapter->status) & |
| 1501 | ZFCP_STATUS_ADAPTER_ERP_PENDING)); |
| 1502 | } |
| 1503 | |
| 1504 | /** |
| 1505 | * zfcp_erp_modify_adapter_status - change adapter status bits |
| 1506 | * @adapter: adapter to change the status |
| 1507 | * @id: id for the debug trace |
| 1508 | * @ref: reference for the debug trace |
| 1509 | * @mask: status bits to change |
| 1510 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1511 | * |
| 1512 | * Changes in common status bits are propagated to attached ports and units. |
| 1513 | */ |
| 1514 | void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, u8 id, |
| 1515 | void *ref, u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | struct zfcp_port *port; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1518 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1520 | if (set_or_clear == ZFCP_SET) { |
| 1521 | if (status_change_set(mask, &adapter->status)) |
| 1522 | zfcp_rec_dbf_event_adapter(id, ref, adapter); |
| 1523 | atomic_set_mask(mask, &adapter->status); |
| 1524 | } else { |
| 1525 | if (status_change_clear(mask, &adapter->status)) |
| 1526 | zfcp_rec_dbf_event_adapter(id, ref, adapter); |
| 1527 | atomic_clear_mask(mask, &adapter->status); |
| 1528 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 1529 | atomic_set(&adapter->erp_counter, 0); |
| 1530 | } |
| 1531 | |
| 1532 | if (common_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | list_for_each_entry(port, &adapter->port_list_head, list) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1534 | zfcp_erp_modify_port_status(port, id, ref, common_mask, |
| 1535 | set_or_clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1538 | /** |
| 1539 | * zfcp_erp_modify_port_status - change port status bits |
| 1540 | * @port: port to change the status bits |
| 1541 | * @id: id for the debug trace |
| 1542 | * @ref: reference for the debug trace |
| 1543 | * @mask: status bits to change |
| 1544 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1545 | * |
| 1546 | * Changes in common status bits are propagated to attached units. |
| 1547 | */ |
| 1548 | void zfcp_erp_modify_port_status(struct zfcp_port *port, u8 id, void *ref, |
| 1549 | u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | struct zfcp_unit *unit; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1552 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1554 | if (set_or_clear == ZFCP_SET) { |
| 1555 | if (status_change_set(mask, &port->status)) |
| 1556 | zfcp_rec_dbf_event_port(id, ref, port); |
| 1557 | atomic_set_mask(mask, &port->status); |
| 1558 | } else { |
| 1559 | if (status_change_clear(mask, &port->status)) |
| 1560 | zfcp_rec_dbf_event_port(id, ref, port); |
| 1561 | atomic_clear_mask(mask, &port->status); |
| 1562 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 1563 | atomic_set(&port->erp_counter, 0); |
| 1564 | } |
| 1565 | |
| 1566 | if (common_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | list_for_each_entry(unit, &port->unit_list_head, list) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1568 | zfcp_erp_modify_unit_status(unit, id, ref, common_mask, |
| 1569 | set_or_clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1572 | /** |
| 1573 | * zfcp_erp_modify_unit_status - change unit status bits |
| 1574 | * @unit: unit to change the status bits |
| 1575 | * @id: id for the debug trace |
| 1576 | * @ref: reference for the debug trace |
| 1577 | * @mask: status bits to change |
| 1578 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1579 | */ |
| 1580 | void zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u8 id, void *ref, |
| 1581 | u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1583 | if (set_or_clear == ZFCP_SET) { |
| 1584 | if (status_change_set(mask, &unit->status)) |
| 1585 | zfcp_rec_dbf_event_unit(id, ref, unit); |
| 1586 | atomic_set_mask(mask, &unit->status); |
| 1587 | } else { |
| 1588 | if (status_change_clear(mask, &unit->status)) |
| 1589 | zfcp_rec_dbf_event_unit(id, ref, unit); |
| 1590 | atomic_clear_mask(mask, &unit->status); |
| 1591 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1592 | atomic_set(&unit->erp_counter, 0); |
| 1593 | } |
| 1594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1597 | /** |
| 1598 | * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP |
| 1599 | * @port: The "boxed" port. |
| 1600 | * @id: The debug trace id. |
| 1601 | * @id: Reference for the debug trace. |
| 1602 | */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1603 | void zfcp_erp_port_boxed(struct zfcp_port *port, u8 id, void *ref) |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1604 | { |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1605 | unsigned long flags; |
| 1606 | |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1607 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1608 | zfcp_erp_modify_port_status(port, id, ref, |
| 1609 | ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1610 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1611 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1614 | /** |
| 1615 | * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP |
| 1616 | * @port: The "boxed" unit. |
| 1617 | * @id: The debug trace id. |
| 1618 | * @id: Reference for the debug trace. |
| 1619 | */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1620 | void zfcp_erp_unit_boxed(struct zfcp_unit *unit, u8 id, void *ref) |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1621 | { |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1622 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1623 | ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1624 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1625 | } |
| 1626 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1627 | /** |
| 1628 | * zfcp_erp_port_access_denied - Adapter denied access to port. |
| 1629 | * @port: port where access has been denied |
| 1630 | * @id: id for debug trace |
| 1631 | * @ref: reference for debug trace |
| 1632 | * |
| 1633 | * Since the adapter has denied access, stop using the port and the |
| 1634 | * attached units. |
| 1635 | */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1636 | 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] | 1637 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | unsigned long flags; |
| 1639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1641 | zfcp_erp_modify_port_status(port, id, ref, |
| 1642 | ZFCP_STATUS_COMMON_ERP_FAILED | |
| 1643 | ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1645 | } |
| 1646 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1647 | /** |
| 1648 | * zfcp_erp_unit_access_denied - Adapter denied access to unit. |
| 1649 | * @unit: unit where access has been denied |
| 1650 | * @id: id for debug trace |
| 1651 | * @ref: reference for debug trace |
| 1652 | * |
| 1653 | * Since the adapter has denied access, stop using the unit. |
| 1654 | */ |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1655 | 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] | 1656 | { |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1657 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1658 | ZFCP_STATUS_COMMON_ERP_FAILED | |
| 1659 | ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | } |
| 1661 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1662 | static void zfcp_erp_unit_access_changed(struct zfcp_unit *unit, u8 id, |
| 1663 | void *ref) |
| 1664 | { |
| 1665 | int status = atomic_read(&unit->status); |
| 1666 | if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1667 | ZFCP_STATUS_COMMON_ACCESS_BOXED))) |
| 1668 | return; |
| 1669 | |
| 1670 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
| 1671 | } |
| 1672 | |
| 1673 | static void zfcp_erp_port_access_changed(struct zfcp_port *port, u8 id, |
| 1674 | void *ref) |
| 1675 | { |
| 1676 | struct zfcp_unit *unit; |
| 1677 | int status = atomic_read(&port->status); |
| 1678 | |
| 1679 | if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1680 | ZFCP_STATUS_COMMON_ACCESS_BOXED))) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1681 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 1682 | zfcp_erp_unit_access_changed(unit, id, ref); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1683 | return; |
| 1684 | } |
| 1685 | |
| 1686 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
| 1687 | } |
| 1688 | |
| 1689 | /** |
| 1690 | * zfcp_erp_adapter_access_changed - Process change in adapter ACT |
| 1691 | * @adapter: Adapter where the Access Control Table (ACT) changed |
| 1692 | * @id: Id for debug trace |
| 1693 | * @ref: Reference for debug trace |
| 1694 | */ |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1695 | void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, u8 id, |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1696 | void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | { |
| 1698 | struct zfcp_port *port; |
| 1699 | unsigned long flags; |
| 1700 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1701 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 1702 | return; |
| 1703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | list_for_each_entry(port, &adapter->port_list_head, list) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1706 | zfcp_erp_port_access_changed(port, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1708 | } |