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