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