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