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