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