Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 1 | /* |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 2 | * zfcp device driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Christof Schmitt | 553448f | 2008-06-10 18:20:58 +0200 | [diff] [blame] | 4 | * Error Recovery Procedures (ERP). |
Swen Schillig | 41fa2ad | 2007-09-07 09:15:31 +0200 | [diff] [blame] | 5 | * |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 6 | * Copyright IBM Corporation 2002, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Christof Schmitt | ecf39d4 | 2008-12-25 13:39:53 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "zfcp" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 12 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "zfcp_ext.h" |
| 14 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 15 | #define ZFCP_MAX_ERPS 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 17 | enum zfcp_erp_act_flags { |
| 18 | ZFCP_STATUS_ERP_TIMEDOUT = 0x10000000, |
| 19 | ZFCP_STATUS_ERP_CLOSE_ONLY = 0x01000000, |
| 20 | ZFCP_STATUS_ERP_DISMISSING = 0x00100000, |
| 21 | ZFCP_STATUS_ERP_DISMISSED = 0x00200000, |
| 22 | ZFCP_STATUS_ERP_LOWMEM = 0x00400000, |
| 23 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 25 | enum zfcp_erp_steps { |
| 26 | ZFCP_ERP_STEP_UNINITIALIZED = 0x0000, |
| 27 | ZFCP_ERP_STEP_FSF_XCONFIG = 0x0001, |
| 28 | ZFCP_ERP_STEP_PHYS_PORT_CLOSING = 0x0010, |
| 29 | ZFCP_ERP_STEP_PORT_CLOSING = 0x0100, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 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 | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 78 | zfcp_dbf_rec_action("erardy1", act); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 79 | wake_up(&adapter->erp_ready_wq); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 80 | zfcp_dbf_rec_thread("erardy2", adapter->dbf); |
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 | |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 216 | if (!adapter->erp_thread) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 217 | return -EIO; |
| 218 | |
| 219 | need = zfcp_erp_required_act(want, adapter, port, unit); |
| 220 | if (!need) |
| 221 | goto out; |
| 222 | |
| 223 | atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status); |
| 224 | act = zfcp_erp_setup_act(need, adapter, port, unit); |
| 225 | if (!act) |
| 226 | goto out; |
| 227 | ++adapter->erp_total_count; |
| 228 | list_add_tail(&act->list, &adapter->erp_ready_head); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 229 | wake_up(&adapter->erp_ready_wq); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 230 | zfcp_dbf_rec_thread("eracte1", adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 231 | retval = 0; |
| 232 | out: |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 233 | zfcp_dbf_rec_trigger(id, ref, want, need, act, adapter, port, unit); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 234 | return retval; |
| 235 | } |
| 236 | |
| 237 | static int _zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 238 | int clear_mask, char *id, void *ref) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 239 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | zfcp_erp_adapter_block(adapter, clear_mask); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 241 | zfcp_scsi_schedule_rports_block(adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 243 | /* ensure propagation of failed status to new devices */ |
| 244 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 245 | zfcp_erp_adapter_failed(adapter, "erareo1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 246 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 248 | return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER, |
| 249 | adapter, NULL, NULL, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 253 | * zfcp_erp_adapter_reopen - Reopen adapter. |
| 254 | * @adapter: Adapter to reopen. |
| 255 | * @clear: Status flags to clear. |
| 256 | * @id: Id for debug trace event. |
| 257 | * @ref: Reference for debug trace event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 259 | void zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 260 | char *id, void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 262 | unsigned long flags; |
| 263 | |
| 264 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 265 | write_lock(&adapter->erp_lock); |
| 266 | _zfcp_erp_adapter_reopen(adapter, clear, id, ref); |
| 267 | write_unlock(&adapter->erp_lock); |
| 268 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * zfcp_erp_adapter_shutdown - Shutdown adapter. |
| 273 | * @adapter: Adapter to shut down. |
| 274 | * @clear: Status flags to clear. |
| 275 | * @id: Id for debug trace event. |
| 276 | * @ref: Reference for debug trace event. |
| 277 | */ |
| 278 | void zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 279 | char *id, void *ref) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 280 | { |
| 281 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 282 | zfcp_erp_adapter_reopen(adapter, clear | flags, id, ref); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * zfcp_erp_port_shutdown - Shutdown port |
| 287 | * @port: Port to shut down. |
| 288 | * @clear: Status flags to clear. |
| 289 | * @id: Id for debug trace event. |
| 290 | * @ref: Reference for debug trace event. |
| 291 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 292 | void zfcp_erp_port_shutdown(struct zfcp_port *port, int clear, char *id, |
| 293 | void *ref) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 294 | { |
| 295 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 296 | zfcp_erp_port_reopen(port, clear | flags, id, ref); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * zfcp_erp_unit_shutdown - Shutdown unit |
| 301 | * @unit: Unit to shut down. |
| 302 | * @clear: Status flags to clear. |
| 303 | * @id: Id for debug trace event. |
| 304 | * @ref: Reference for debug trace event. |
| 305 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 306 | void zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear, char *id, |
| 307 | void *ref) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 308 | { |
| 309 | int flags = ZFCP_STATUS_COMMON_RUNNING | ZFCP_STATUS_COMMON_ERP_FAILED; |
| 310 | zfcp_erp_unit_reopen(unit, clear | flags, id, ref); |
| 311 | } |
| 312 | |
| 313 | static void zfcp_erp_port_block(struct zfcp_port *port, int clear) |
| 314 | { |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 315 | zfcp_erp_modify_port_status(port, "erpblk1", NULL, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 316 | ZFCP_STATUS_COMMON_UNBLOCKED | clear, |
| 317 | ZFCP_CLEAR); |
| 318 | } |
| 319 | |
| 320 | static void _zfcp_erp_port_forced_reopen(struct zfcp_port *port, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 321 | int clear, char *id, void *ref) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 322 | { |
| 323 | zfcp_erp_port_block(port, clear); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 324 | zfcp_scsi_schedule_rport_block(port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 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); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 356 | zfcp_scsi_schedule_rport_block(port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 357 | |
| 358 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 359 | /* ensure propagation of failed status to new devices */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 360 | zfcp_erp_port_failed(port, "erpreo1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 361 | return -EIO; |
| 362 | } |
| 363 | |
| 364 | return zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT, |
| 365 | port->adapter, port, NULL, id, ref); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * zfcp_erp_port_reopen - trigger remote port recovery |
| 370 | * @port: port to recover |
| 371 | * @clear_mask: flags in port status to be cleared |
| 372 | * |
| 373 | * Returns 0 if recovery has been triggered, < 0 if not. |
| 374 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 375 | 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] | 376 | { |
| 377 | unsigned long flags; |
| 378 | int retval; |
| 379 | struct zfcp_adapter *adapter = port->adapter; |
| 380 | |
| 381 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 382 | write_lock(&adapter->erp_lock); |
| 383 | retval = _zfcp_erp_port_reopen(port, clear, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | write_unlock(&adapter->erp_lock); |
| 385 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 386 | |
| 387 | return retval; |
| 388 | } |
| 389 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 390 | 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] | 391 | { |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 392 | zfcp_erp_modify_unit_status(unit, "erublk1", NULL, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 393 | ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask, |
| 394 | ZFCP_CLEAR); |
| 395 | } |
| 396 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 397 | 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] | 398 | void *ref) |
| 399 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | struct zfcp_adapter *adapter = unit->port->adapter; |
| 401 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 402 | zfcp_erp_unit_block(unit, clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 404 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 405 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 407 | zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT, |
| 408 | adapter, unit->port, unit, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | /** |
| 412 | * zfcp_erp_unit_reopen - initiate reopen of a unit |
| 413 | * @unit: unit to be reopened |
| 414 | * @clear_mask: specifies flags in unit status to be cleared |
| 415 | * Return: 0 on success, < 0 on error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 417 | void zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear, char *id, |
| 418 | void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | unsigned long flags; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 421 | struct zfcp_port *port = unit->port; |
| 422 | struct zfcp_adapter *adapter = port->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 425 | write_lock(&adapter->erp_lock); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 426 | _zfcp_erp_unit_reopen(unit, clear, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | write_unlock(&adapter->erp_lock); |
| 428 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 431 | static int status_change_set(unsigned long mask, atomic_t *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 433 | return (atomic_read(status) ^ mask) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 436 | static int status_change_clear(unsigned long mask, atomic_t *status) |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 437 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 438 | return atomic_read(status) & mask; |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 439 | } |
| 440 | |
Andreas Herrmann | f6c0e7a | 2006-08-02 11:05:52 +0200 | [diff] [blame] | 441 | static void zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 443 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 444 | zfcp_dbf_rec_adapter("eraubl1", NULL, adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 445 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 448 | static void zfcp_erp_port_unblock(struct zfcp_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 450 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 451 | zfcp_dbf_rec_port("erpubl1", NULL, port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 452 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 455 | static void zfcp_erp_unit_unblock(struct zfcp_unit *unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 457 | if (status_change_set(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 458 | zfcp_dbf_rec_unit("eruubl1", NULL, unit); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 459 | atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 462 | static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 464 | list_move(&erp_action->list, &erp_action->adapter->erp_running_head); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 465 | zfcp_dbf_rec_action("erator1", erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 468 | static void zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *act) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 470 | struct zfcp_adapter *adapter = act->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 472 | if (!act->fsf_req) |
| 473 | return; |
| 474 | |
| 475 | spin_lock(&adapter->req_list_lock); |
| 476 | if (zfcp_reqlist_find_safe(adapter, act->fsf_req) && |
| 477 | act->fsf_req->erp_action == act) { |
| 478 | if (act->status & (ZFCP_STATUS_ERP_DISMISSED | |
| 479 | ZFCP_STATUS_ERP_TIMEDOUT)) { |
| 480 | act->fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 481 | zfcp_dbf_rec_action("erscf_1", act); |
Martin Petermann | 7ea633f | 2008-11-04 16:35:11 +0100 | [diff] [blame] | 482 | act->fsf_req->erp_action = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 484 | if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 485 | zfcp_dbf_rec_action("erscf_2", act); |
Swen Schillig | 058b864 | 2009-08-18 15:43:14 +0200 | [diff] [blame] | 486 | if (act->fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 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 | |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 553 | static void zfcp_erp_strategy_followup_failed(struct zfcp_erp_action *act) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 554 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 555 | switch (act->action) { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 556 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 557 | _zfcp_erp_adapter_reopen(act->adapter, 0, "ersff_1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 558 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 559 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 560 | _zfcp_erp_port_forced_reopen(act->port, 0, "ersff_2", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 561 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 562 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 563 | _zfcp_erp_port_reopen(act->port, 0, "ersff_3", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 564 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 565 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 566 | _zfcp_erp_unit_reopen(act->unit, 0, "ersff_4", NULL); |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | static void zfcp_erp_strategy_followup_success(struct zfcp_erp_action *act) |
| 572 | { |
| 573 | switch (act->action) { |
| 574 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 575 | _zfcp_erp_port_reopen_all(act->adapter, 0, "ersfs_1", NULL); |
| 576 | break; |
| 577 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 578 | _zfcp_erp_port_reopen(act->port, 0, "ersfs_2", NULL); |
| 579 | break; |
| 580 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 581 | _zfcp_erp_unit_reopen_all(act->port, 0, "ersfs_3", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 582 | break; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | static void zfcp_erp_wakeup(struct zfcp_adapter *adapter) |
| 587 | { |
| 588 | unsigned long flags; |
| 589 | |
| 590 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 591 | read_lock(&adapter->erp_lock); |
| 592 | if (list_empty(&adapter->erp_ready_head) && |
| 593 | list_empty(&adapter->erp_running_head)) { |
| 594 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, |
| 595 | &adapter->status); |
| 596 | wake_up(&adapter->erp_done_wqh); |
| 597 | } |
| 598 | read_unlock(&adapter->erp_lock); |
| 599 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 600 | } |
| 601 | |
| 602 | static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *act) |
| 603 | { |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 604 | struct zfcp_qdio *qdio = act->adapter->qdio; |
| 605 | |
| 606 | if (zfcp_qdio_open(qdio)) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 607 | return ZFCP_ERP_FAILED; |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 608 | init_waitqueue_head(&qdio->req_q_wq); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 609 | atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &act->adapter->status); |
| 610 | return ZFCP_ERP_SUCCEEDED; |
| 611 | } |
| 612 | |
| 613 | static void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter) |
| 614 | { |
| 615 | struct zfcp_port *port; |
| 616 | port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0, |
| 617 | adapter->peer_d_id); |
| 618 | if (IS_ERR(port)) /* error or port already attached */ |
| 619 | return; |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 620 | _zfcp_erp_port_reopen(port, 0, "ereptp1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action) |
| 624 | { |
| 625 | int retries; |
| 626 | int sleep = 1; |
| 627 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 628 | |
| 629 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status); |
| 630 | |
| 631 | for (retries = 7; retries; retries--) { |
| 632 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 633 | &adapter->status); |
| 634 | write_lock_irq(&adapter->erp_lock); |
| 635 | zfcp_erp_action_to_running(erp_action); |
| 636 | write_unlock_irq(&adapter->erp_lock); |
| 637 | if (zfcp_fsf_exchange_config_data(erp_action)) { |
| 638 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 639 | &adapter->status); |
| 640 | return ZFCP_ERP_FAILED; |
| 641 | } |
| 642 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 643 | zfcp_dbf_rec_thread_lock("erasfx1", adapter->dbf); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 644 | wait_event(adapter->erp_ready_wq, |
| 645 | !list_empty(&adapter->erp_ready_head)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 646 | zfcp_dbf_rec_thread_lock("erasfx2", adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 647 | if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) |
| 648 | break; |
| 649 | |
| 650 | if (!(atomic_read(&adapter->status) & |
| 651 | ZFCP_STATUS_ADAPTER_HOST_CON_INIT)) |
| 652 | break; |
| 653 | |
| 654 | ssleep(sleep); |
| 655 | sleep *= 2; |
| 656 | } |
| 657 | |
| 658 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
| 659 | &adapter->status); |
| 660 | |
| 661 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK)) |
| 662 | return ZFCP_ERP_FAILED; |
| 663 | |
| 664 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) |
| 665 | zfcp_erp_enqueue_ptp_port(adapter); |
| 666 | |
| 667 | return ZFCP_ERP_SUCCEEDED; |
| 668 | } |
| 669 | |
| 670 | static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act) |
| 671 | { |
| 672 | int ret; |
| 673 | struct zfcp_adapter *adapter = act->adapter; |
| 674 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 675 | write_lock_irq(&adapter->erp_lock); |
| 676 | zfcp_erp_action_to_running(act); |
| 677 | write_unlock_irq(&adapter->erp_lock); |
| 678 | |
| 679 | ret = zfcp_fsf_exchange_port_data(act); |
| 680 | if (ret == -EOPNOTSUPP) |
| 681 | return ZFCP_ERP_SUCCEEDED; |
| 682 | if (ret) |
| 683 | return ZFCP_ERP_FAILED; |
| 684 | |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 685 | zfcp_dbf_rec_thread_lock("erasox1", adapter->dbf); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 686 | wait_event(adapter->erp_ready_wq, |
| 687 | !list_empty(&adapter->erp_ready_head)); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 688 | zfcp_dbf_rec_thread_lock("erasox2", adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 689 | if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) |
| 690 | return ZFCP_ERP_FAILED; |
| 691 | |
| 692 | return ZFCP_ERP_SUCCEEDED; |
| 693 | } |
| 694 | |
| 695 | static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act) |
| 696 | { |
| 697 | if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED) |
| 698 | return ZFCP_ERP_FAILED; |
| 699 | |
| 700 | if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED) |
| 701 | return ZFCP_ERP_FAILED; |
| 702 | |
| 703 | atomic_set(&act->adapter->stat_miss, 16); |
| 704 | if (zfcp_status_read_refill(act->adapter)) |
| 705 | return ZFCP_ERP_FAILED; |
| 706 | |
| 707 | return ZFCP_ERP_SUCCEEDED; |
| 708 | } |
| 709 | |
Swen Schillig | cf13c08 | 2009-03-02 13:09:03 +0100 | [diff] [blame] | 710 | static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 711 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 712 | struct zfcp_adapter *adapter = act->adapter; |
| 713 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 714 | /* close queues to ensure that buffers are not accessed by adapter */ |
Swen Schillig | 564e1c8 | 2009-08-18 15:43:19 +0200 | [diff] [blame] | 715 | zfcp_qdio_close(adapter->qdio); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 716 | zfcp_fsf_req_dismiss_all(adapter); |
| 717 | adapter->fsf_req_seq_no = 0; |
Christof Schmitt | 55c770f | 2009-08-18 15:43:12 +0200 | [diff] [blame] | 718 | zfcp_fc_wka_ports_force_offline(adapter->gs); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 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: |
Christof Schmitt | ddb3e0c | 2009-07-13 15:06:08 +0200 | [diff] [blame] | 800 | if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN)) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 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 | |
| 845 | static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act) |
| 846 | { |
| 847 | struct zfcp_adapter *adapter = act->adapter; |
| 848 | struct zfcp_port *port = act->port; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 849 | int p_status = atomic_read(&port->status); |
| 850 | |
| 851 | switch (act->step) { |
| 852 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 853 | case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: |
| 854 | case ZFCP_ERP_STEP_PORT_CLOSING: |
| 855 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) |
| 856 | return zfcp_erp_open_ptp_port(act); |
Christof Schmitt | b98478d | 2008-12-19 16:56:59 +0100 | [diff] [blame] | 857 | if (!port->d_id) { |
Swen Schillig | 947a9ac | 2009-03-02 13:09:10 +0100 | [diff] [blame] | 858 | zfcp_port_get(port); |
Swen Schillig | 4544683 | 2009-08-18 15:43:17 +0200 | [diff] [blame] | 859 | if (!queue_work(adapter->work_queue, |
Swen Schillig | 947a9ac | 2009-03-02 13:09:10 +0100 | [diff] [blame] | 860 | &port->gid_pn_work)) |
| 861 | zfcp_port_put(port); |
Christof Schmitt | 799b76d | 2009-08-18 15:43:20 +0200 | [diff] [blame] | 862 | return ZFCP_ERP_EXIT; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 863 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 864 | return zfcp_erp_port_strategy_open_port(act); |
| 865 | |
| 866 | case ZFCP_ERP_STEP_PORT_OPENING: |
| 867 | /* D_ID might have changed during open */ |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 868 | if (p_status & ZFCP_STATUS_COMMON_OPEN) { |
Christof Schmitt | b98478d | 2008-12-19 16:56:59 +0100 | [diff] [blame] | 869 | if (port->d_id) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 870 | return ZFCP_ERP_SUCCEEDED; |
| 871 | else { |
| 872 | act->step = ZFCP_ERP_STEP_PORT_CLOSING; |
| 873 | return ZFCP_ERP_CONTINUES; |
| 874 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 875 | } |
Swen Schillig | ea460a8 | 2009-05-15 13:18:20 +0200 | [diff] [blame] | 876 | if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) { |
| 877 | port->d_id = 0; |
| 878 | _zfcp_erp_port_reopen(port, 0, "erpsoc1", NULL); |
| 879 | return ZFCP_ERP_EXIT; |
| 880 | } |
| 881 | /* fall through otherwise */ |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 882 | } |
| 883 | return ZFCP_ERP_FAILED; |
| 884 | } |
| 885 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 886 | static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action) |
| 887 | { |
| 888 | struct zfcp_port *port = erp_action->port; |
| 889 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 890 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) |
| 891 | goto close_init_done; |
| 892 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 893 | switch (erp_action->step) { |
| 894 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 895 | zfcp_erp_port_strategy_clearstati(port); |
| 896 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN) |
| 897 | return zfcp_erp_port_strategy_close(erp_action); |
| 898 | break; |
| 899 | |
| 900 | case ZFCP_ERP_STEP_PORT_CLOSING: |
| 901 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_OPEN) |
| 902 | return ZFCP_ERP_FAILED; |
| 903 | break; |
| 904 | } |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 905 | |
| 906 | close_init_done: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 907 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
| 908 | return ZFCP_ERP_EXIT; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 909 | |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 910 | return zfcp_erp_port_strategy_open_common(erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 913 | static void zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
Swen Schillig | 44cc76f | 2008-10-01 12:42:16 +0200 | [diff] [blame] | 915 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 916 | ZFCP_STATUS_UNIT_SHARED | |
| 917 | ZFCP_STATUS_UNIT_READONLY, |
| 918 | &unit->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 921 | static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action) |
| 922 | { |
| 923 | int retval = zfcp_fsf_close_unit(erp_action); |
| 924 | if (retval == -ENOMEM) |
| 925 | return ZFCP_ERP_NOMEM; |
| 926 | erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING; |
| 927 | if (retval) |
| 928 | return ZFCP_ERP_FAILED; |
| 929 | return ZFCP_ERP_CONTINUES; |
| 930 | } |
| 931 | |
| 932 | static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action) |
| 933 | { |
| 934 | int retval = zfcp_fsf_open_unit(erp_action); |
| 935 | if (retval == -ENOMEM) |
| 936 | return ZFCP_ERP_NOMEM; |
| 937 | erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING; |
| 938 | if (retval) |
| 939 | return ZFCP_ERP_FAILED; |
| 940 | return ZFCP_ERP_CONTINUES; |
| 941 | } |
| 942 | |
| 943 | static int zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action) |
| 944 | { |
| 945 | struct zfcp_unit *unit = erp_action->unit; |
| 946 | |
| 947 | switch (erp_action->step) { |
| 948 | case ZFCP_ERP_STEP_UNINITIALIZED: |
| 949 | zfcp_erp_unit_strategy_clearstati(unit); |
| 950 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 951 | return zfcp_erp_unit_strategy_close(erp_action); |
| 952 | /* already closed, fall through */ |
| 953 | case ZFCP_ERP_STEP_UNIT_CLOSING: |
| 954 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 955 | return ZFCP_ERP_FAILED; |
| 956 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
| 957 | return ZFCP_ERP_EXIT; |
| 958 | return zfcp_erp_unit_strategy_open(erp_action); |
| 959 | |
| 960 | case ZFCP_ERP_STEP_UNIT_OPENING: |
| 961 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_OPEN) |
| 962 | return ZFCP_ERP_SUCCEEDED; |
| 963 | } |
| 964 | return ZFCP_ERP_FAILED; |
| 965 | } |
| 966 | |
| 967 | static int zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result) |
| 968 | { |
| 969 | switch (result) { |
| 970 | case ZFCP_ERP_SUCCEEDED : |
| 971 | atomic_set(&unit->erp_counter, 0); |
| 972 | zfcp_erp_unit_unblock(unit); |
| 973 | break; |
| 974 | case ZFCP_ERP_FAILED : |
| 975 | atomic_inc(&unit->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 976 | if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS) { |
| 977 | dev_err(&unit->port->adapter->ccw_device->dev, |
| 978 | "ERP failed for unit 0x%016Lx on " |
| 979 | "port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 980 | (unsigned long long)unit->fcp_lun, |
| 981 | (unsigned long long)unit->port->wwpn); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 982 | zfcp_erp_unit_failed(unit, "erusck1", NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 983 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 984 | break; |
| 985 | } |
| 986 | |
| 987 | if (atomic_read(&unit->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 988 | zfcp_erp_unit_block(unit, 0); |
| 989 | result = ZFCP_ERP_EXIT; |
| 990 | } |
| 991 | return result; |
| 992 | } |
| 993 | |
| 994 | static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result) |
| 995 | { |
| 996 | switch (result) { |
| 997 | case ZFCP_ERP_SUCCEEDED : |
| 998 | atomic_set(&port->erp_counter, 0); |
| 999 | zfcp_erp_port_unblock(port); |
| 1000 | break; |
| 1001 | |
| 1002 | case ZFCP_ERP_FAILED : |
| 1003 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) { |
| 1004 | zfcp_erp_port_block(port, 0); |
| 1005 | result = ZFCP_ERP_EXIT; |
| 1006 | } |
| 1007 | atomic_inc(&port->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1008 | if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) { |
| 1009 | dev_err(&port->adapter->ccw_device->dev, |
| 1010 | "ERP failed for remote port 0x%016Lx\n", |
Swen Schillig | 7ba58c9 | 2008-10-01 12:42:18 +0200 | [diff] [blame] | 1011 | (unsigned long long)port->wwpn); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1012 | zfcp_erp_port_failed(port, "erpsck1", NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1013 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1014 | break; |
| 1015 | } |
| 1016 | |
| 1017 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1018 | zfcp_erp_port_block(port, 0); |
| 1019 | result = ZFCP_ERP_EXIT; |
| 1020 | } |
| 1021 | return result; |
| 1022 | } |
| 1023 | |
| 1024 | static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, |
| 1025 | int result) |
| 1026 | { |
| 1027 | switch (result) { |
| 1028 | case ZFCP_ERP_SUCCEEDED : |
| 1029 | atomic_set(&adapter->erp_counter, 0); |
| 1030 | zfcp_erp_adapter_unblock(adapter); |
| 1031 | break; |
| 1032 | |
| 1033 | case ZFCP_ERP_FAILED : |
| 1034 | atomic_inc(&adapter->erp_counter); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1035 | if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) { |
| 1036 | dev_err(&adapter->ccw_device->dev, |
| 1037 | "ERP cannot recover an error " |
| 1038 | "on the FCP device\n"); |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1039 | zfcp_erp_adapter_failed(adapter, "erasck1", NULL); |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1040 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1041 | break; |
| 1042 | } |
| 1043 | |
| 1044 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1045 | zfcp_erp_adapter_block(adapter, 0); |
| 1046 | result = ZFCP_ERP_EXIT; |
| 1047 | } |
| 1048 | return result; |
| 1049 | } |
| 1050 | |
| 1051 | static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, |
| 1052 | int result) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | { |
| 1054 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1055 | struct zfcp_port *port = erp_action->port; |
| 1056 | struct zfcp_unit *unit = erp_action->unit; |
| 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | switch (erp_action->action) { |
| 1059 | |
| 1060 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1061 | result = zfcp_erp_strategy_check_unit(unit, result); |
| 1062 | break; |
| 1063 | |
| 1064 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1065 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1066 | result = zfcp_erp_strategy_check_port(port, result); |
| 1067 | break; |
| 1068 | |
| 1069 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1070 | result = zfcp_erp_strategy_check_adapter(adapter, result); |
| 1071 | break; |
| 1072 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | return result; |
| 1074 | } |
| 1075 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1076 | 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] | 1077 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1078 | int status = atomic_read(target_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1080 | if ((status & ZFCP_STATUS_COMMON_RUNNING) && |
| 1081 | (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) |
| 1082 | return 1; /* take it online */ |
| 1083 | |
| 1084 | if (!(status & ZFCP_STATUS_COMMON_RUNNING) && |
| 1085 | !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) |
| 1086 | return 1; /* take it offline */ |
| 1087 | |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret) |
| 1092 | { |
| 1093 | int action = act->action; |
| 1094 | struct zfcp_adapter *adapter = act->adapter; |
| 1095 | struct zfcp_port *port = act->port; |
| 1096 | struct zfcp_unit *unit = act->unit; |
| 1097 | u32 erp_status = act->status; |
| 1098 | |
| 1099 | switch (action) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1101 | if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) { |
| 1102 | _zfcp_erp_adapter_reopen(adapter, |
| 1103 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1104 | "ersscg1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1105 | return ZFCP_ERP_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | |
| 1109 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1110 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1111 | if (zfcp_erp_strat_change_det(&port->status, erp_status)) { |
| 1112 | _zfcp_erp_port_reopen(port, |
| 1113 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1114 | "ersscg2", 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_UNIT: |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1120 | if (zfcp_erp_strat_change_det(&unit->status, erp_status)) { |
| 1121 | _zfcp_erp_unit_reopen(unit, |
| 1122 | ZFCP_STATUS_COMMON_ERP_FAILED, |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1123 | "ersscg3", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1124 | return ZFCP_ERP_EXIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | } |
| 1126 | break; |
| 1127 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1128 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1131 | static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1133 | struct zfcp_adapter *adapter = erp_action->adapter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1135 | adapter->erp_total_count--; |
| 1136 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { |
| 1137 | adapter->erp_low_mem_count--; |
| 1138 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; |
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 | list_del(&erp_action->list); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1142 | zfcp_dbf_rec_action("eractd1", erp_action); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1144 | switch (erp_action->action) { |
| 1145 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1146 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1147 | &erp_action->unit->status); |
| 1148 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1150 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1151 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1152 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1153 | &erp_action->port->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1155 | |
| 1156 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1157 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
| 1158 | &erp_action->adapter->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | break; |
| 1160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1163 | 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] | 1164 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1165 | struct zfcp_adapter *adapter = act->adapter; |
| 1166 | struct zfcp_port *port = act->port; |
| 1167 | struct zfcp_unit *unit = act->unit; |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1168 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1169 | switch (act->action) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 1171 | if ((result == ZFCP_ERP_SUCCEEDED) && !unit->device) { |
Swen Schillig | 92d5193 | 2009-04-17 15:08:04 +0200 | [diff] [blame] | 1172 | zfcp_unit_get(unit); |
| 1173 | if (scsi_queue_work(unit->port->adapter->scsi_host, |
| 1174 | &unit->scsi_work) <= 0) |
| 1175 | zfcp_unit_put(unit); |
Andreas Herrmann | ad58f7d | 2006-03-10 00:56:16 +0100 | [diff] [blame] | 1176 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | zfcp_unit_put(unit); |
| 1178 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1181 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 1182 | if (result == ZFCP_ERP_SUCCEEDED) |
| 1183 | zfcp_scsi_schedule_rport_register(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | zfcp_port_put(port); |
| 1185 | break; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 1188 | if (result == ZFCP_ERP_SUCCEEDED) { |
Christof Schmitt | bd43a42b7 | 2008-12-25 13:38:50 +0100 | [diff] [blame] | 1189 | register_service_level(&adapter->service_level); |
Swen Schillig | fca55b6 | 2008-11-26 18:07:40 +0100 | [diff] [blame] | 1190 | schedule_work(&adapter->scan_work); |
Christof Schmitt | a2fa0ae | 2009-03-02 13:09:08 +0100 | [diff] [blame] | 1191 | } else |
| 1192 | unregister_service_level(&adapter->service_level); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | zfcp_adapter_put(adapter); |
| 1194 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1198 | static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action) |
| 1199 | { |
| 1200 | switch (erp_action->action) { |
| 1201 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
| 1202 | return zfcp_erp_adapter_strategy(erp_action); |
| 1203 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
| 1204 | return zfcp_erp_port_forced_strategy(erp_action); |
| 1205 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
| 1206 | return zfcp_erp_port_strategy(erp_action); |
| 1207 | case ZFCP_ERP_ACTION_REOPEN_UNIT: |
| 1208 | return zfcp_erp_unit_strategy(erp_action); |
| 1209 | } |
| 1210 | return ZFCP_ERP_FAILED; |
| 1211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1213 | static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action) |
| 1214 | { |
| 1215 | int retval; |
| 1216 | struct zfcp_adapter *adapter = erp_action->adapter; |
| 1217 | unsigned long flags; |
| 1218 | |
| 1219 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1220 | write_lock(&adapter->erp_lock); |
| 1221 | |
| 1222 | zfcp_erp_strategy_check_fsfreq(erp_action); |
| 1223 | |
| 1224 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) { |
| 1225 | zfcp_erp_action_dequeue(erp_action); |
| 1226 | retval = ZFCP_ERP_DISMISSED; |
| 1227 | goto unlock; |
| 1228 | } |
| 1229 | |
| 1230 | zfcp_erp_action_to_running(erp_action); |
| 1231 | |
| 1232 | /* no lock to allow for blocking operations */ |
| 1233 | write_unlock(&adapter->erp_lock); |
| 1234 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1235 | retval = zfcp_erp_strategy_do_action(erp_action); |
| 1236 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
| 1237 | write_lock(&adapter->erp_lock); |
| 1238 | |
| 1239 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) |
| 1240 | retval = ZFCP_ERP_CONTINUES; |
| 1241 | |
| 1242 | switch (retval) { |
| 1243 | case ZFCP_ERP_NOMEM: |
| 1244 | if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) { |
| 1245 | ++adapter->erp_low_mem_count; |
| 1246 | erp_action->status |= ZFCP_STATUS_ERP_LOWMEM; |
| 1247 | } |
| 1248 | if (adapter->erp_total_count == adapter->erp_low_mem_count) |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1249 | _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1", NULL); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1250 | else { |
| 1251 | zfcp_erp_strategy_memwait(erp_action); |
| 1252 | retval = ZFCP_ERP_CONTINUES; |
| 1253 | } |
| 1254 | goto unlock; |
| 1255 | |
| 1256 | case ZFCP_ERP_CONTINUES: |
| 1257 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { |
| 1258 | --adapter->erp_low_mem_count; |
| 1259 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; |
| 1260 | } |
| 1261 | goto unlock; |
| 1262 | } |
| 1263 | |
| 1264 | retval = zfcp_erp_strategy_check_target(erp_action, retval); |
| 1265 | zfcp_erp_action_dequeue(erp_action); |
| 1266 | retval = zfcp_erp_strategy_statechange(erp_action, retval); |
| 1267 | if (retval == ZFCP_ERP_EXIT) |
| 1268 | goto unlock; |
Christof Schmitt | 85600f7 | 2009-07-13 15:06:09 +0200 | [diff] [blame] | 1269 | if (retval == ZFCP_ERP_SUCCEEDED) |
| 1270 | zfcp_erp_strategy_followup_success(erp_action); |
| 1271 | if (retval == ZFCP_ERP_FAILED) |
| 1272 | zfcp_erp_strategy_followup_failed(erp_action); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1273 | |
| 1274 | unlock: |
| 1275 | write_unlock(&adapter->erp_lock); |
| 1276 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1277 | |
| 1278 | if (retval != ZFCP_ERP_CONTINUES) |
| 1279 | zfcp_erp_action_cleanup(erp_action, retval); |
| 1280 | |
| 1281 | return retval; |
| 1282 | } |
| 1283 | |
| 1284 | static int zfcp_erp_thread(void *data) |
| 1285 | { |
| 1286 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; |
| 1287 | struct list_head *next; |
| 1288 | struct zfcp_erp_action *act; |
| 1289 | unsigned long flags; |
| 1290 | |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1291 | for (;;) { |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1292 | zfcp_dbf_rec_thread_lock("erthrd1", adapter->dbf); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1293 | wait_event_interruptible(adapter->erp_ready_wq, |
| 1294 | !list_empty(&adapter->erp_ready_head) || |
| 1295 | kthread_should_stop()); |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1296 | zfcp_dbf_rec_thread_lock("erthrd2", adapter->dbf); |
Swen Schillig | 94ab4b3 | 2009-04-17 15:08:06 +0200 | [diff] [blame] | 1297 | |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1298 | if (kthread_should_stop()) |
| 1299 | break; |
| 1300 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1301 | write_lock_irqsave(&adapter->erp_lock, flags); |
| 1302 | next = adapter->erp_ready_head.next; |
| 1303 | write_unlock_irqrestore(&adapter->erp_lock, flags); |
| 1304 | |
| 1305 | if (next != &adapter->erp_ready_head) { |
| 1306 | act = list_entry(next, struct zfcp_erp_action, list); |
| 1307 | |
| 1308 | /* there is more to come after dismission, no notify */ |
| 1309 | if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED) |
| 1310 | zfcp_erp_wakeup(adapter); |
| 1311 | } |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1314 | return 0; |
| 1315 | } |
| 1316 | |
| 1317 | /** |
| 1318 | * zfcp_erp_thread_setup - Start ERP thread for adapter |
| 1319 | * @adapter: Adapter to start the ERP thread for |
| 1320 | * |
| 1321 | * Returns 0 on success or error code from kernel_thread() |
| 1322 | */ |
| 1323 | int zfcp_erp_thread_setup(struct zfcp_adapter *adapter) |
| 1324 | { |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1325 | struct task_struct *thread; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1326 | |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1327 | thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s", |
| 1328 | dev_name(&adapter->ccw_device->dev)); |
| 1329 | if (IS_ERR(thread)) { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1330 | dev_err(&adapter->ccw_device->dev, |
Christof Schmitt | ff3b24f | 2008-10-01 12:42:15 +0200 | [diff] [blame] | 1331 | "Creating an ERP thread for the FCP device failed.\n"); |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1332 | return PTR_ERR(thread); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1333 | } |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1334 | |
| 1335 | adapter->erp_thread = thread; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1336 | return 0; |
| 1337 | } |
| 1338 | |
| 1339 | /** |
| 1340 | * zfcp_erp_thread_kill - Stop ERP thread. |
| 1341 | * @adapter: Adapter where the ERP thread should be stopped. |
| 1342 | * |
| 1343 | * The caller of this routine ensures that the specified adapter has |
| 1344 | * been shut down and that this operation has been completed. Thus, |
| 1345 | * there are no pending erp_actions which would need to be handled |
| 1346 | * here. |
| 1347 | */ |
| 1348 | void zfcp_erp_thread_kill(struct zfcp_adapter *adapter) |
| 1349 | { |
Christof Schmitt | 347c6a9 | 2009-08-18 15:43:25 +0200 | [diff] [blame^] | 1350 | kthread_stop(adapter->erp_thread); |
| 1351 | adapter->erp_thread = NULL; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * zfcp_erp_adapter_failed - Set adapter status to failed. |
| 1356 | * @adapter: Failed adapter. |
| 1357 | * @id: Event id for debug trace. |
| 1358 | * @ref: Reference for debug trace. |
| 1359 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1360 | 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] | 1361 | { |
| 1362 | zfcp_erp_modify_adapter_status(adapter, id, ref, |
| 1363 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * zfcp_erp_port_failed - Set port status to failed. |
| 1368 | * @port: Failed port. |
| 1369 | * @id: Event id for debug trace. |
| 1370 | * @ref: Reference for debug trace. |
| 1371 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1372 | 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] | 1373 | { |
| 1374 | zfcp_erp_modify_port_status(port, id, ref, |
| 1375 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | /** |
| 1379 | * zfcp_erp_unit_failed - Set unit status to failed. |
| 1380 | * @unit: Failed unit. |
| 1381 | * @id: Event id for debug trace. |
| 1382 | * @ref: Reference for debug trace. |
| 1383 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1384 | 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] | 1385 | { |
| 1386 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1387 | ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /** |
| 1391 | * zfcp_erp_wait - wait for completion of error recovery on an adapter |
| 1392 | * @adapter: adapter for which to wait for completion of its error recovery |
| 1393 | */ |
| 1394 | void zfcp_erp_wait(struct zfcp_adapter *adapter) |
| 1395 | { |
| 1396 | wait_event(adapter->erp_done_wqh, |
| 1397 | !(atomic_read(&adapter->status) & |
| 1398 | ZFCP_STATUS_ADAPTER_ERP_PENDING)); |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * zfcp_erp_modify_adapter_status - change adapter status bits |
| 1403 | * @adapter: adapter to change the status |
| 1404 | * @id: id for the debug trace |
| 1405 | * @ref: reference for the debug trace |
| 1406 | * @mask: status bits to change |
| 1407 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1408 | * |
| 1409 | * Changes in common status bits are propagated to attached ports and units. |
| 1410 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1411 | void zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter, char *id, |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1412 | void *ref, u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | struct zfcp_port *port; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1415 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1417 | if (set_or_clear == ZFCP_SET) { |
| 1418 | if (status_change_set(mask, &adapter->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1419 | zfcp_dbf_rec_adapter(id, ref, adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1420 | atomic_set_mask(mask, &adapter->status); |
| 1421 | } else { |
| 1422 | if (status_change_clear(mask, &adapter->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1423 | zfcp_dbf_rec_adapter(id, ref, adapter->dbf); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1424 | atomic_clear_mask(mask, &adapter->status); |
| 1425 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 1426 | atomic_set(&adapter->erp_counter, 0); |
| 1427 | } |
| 1428 | |
| 1429 | if (common_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | list_for_each_entry(port, &adapter->port_list_head, list) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1431 | zfcp_erp_modify_port_status(port, id, ref, common_mask, |
| 1432 | set_or_clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1435 | /** |
| 1436 | * zfcp_erp_modify_port_status - change port status bits |
| 1437 | * @port: port to change the status bits |
| 1438 | * @id: id for the debug trace |
| 1439 | * @ref: reference for the debug trace |
| 1440 | * @mask: status bits to change |
| 1441 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1442 | * |
| 1443 | * Changes in common status bits are propagated to attached units. |
| 1444 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1445 | 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] | 1446 | u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | struct zfcp_unit *unit; |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1449 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1451 | if (set_or_clear == ZFCP_SET) { |
| 1452 | if (status_change_set(mask, &port->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1453 | zfcp_dbf_rec_port(id, ref, port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1454 | atomic_set_mask(mask, &port->status); |
| 1455 | } else { |
| 1456 | if (status_change_clear(mask, &port->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1457 | zfcp_dbf_rec_port(id, ref, port); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1458 | atomic_clear_mask(mask, &port->status); |
| 1459 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) |
| 1460 | atomic_set(&port->erp_counter, 0); |
| 1461 | } |
| 1462 | |
| 1463 | if (common_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | list_for_each_entry(unit, &port->unit_list_head, list) |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1465 | zfcp_erp_modify_unit_status(unit, id, ref, common_mask, |
| 1466 | set_or_clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1469 | /** |
| 1470 | * zfcp_erp_modify_unit_status - change unit status bits |
| 1471 | * @unit: unit to change the status bits |
| 1472 | * @id: id for the debug trace |
| 1473 | * @ref: reference for the debug trace |
| 1474 | * @mask: status bits to change |
| 1475 | * @set_or_clear: ZFCP_SET or ZFCP_CLEAR |
| 1476 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1477 | 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] | 1478 | u32 mask, int set_or_clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | { |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1480 | if (set_or_clear == ZFCP_SET) { |
| 1481 | if (status_change_set(mask, &unit->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1482 | zfcp_dbf_rec_unit(id, ref, unit); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1483 | atomic_set_mask(mask, &unit->status); |
| 1484 | } else { |
| 1485 | if (status_change_clear(mask, &unit->status)) |
Swen Schillig | 5771710 | 2009-08-18 15:43:21 +0200 | [diff] [blame] | 1486 | zfcp_dbf_rec_unit(id, ref, unit); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1487 | atomic_clear_mask(mask, &unit->status); |
| 1488 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) { |
| 1489 | atomic_set(&unit->erp_counter, 0); |
| 1490 | } |
| 1491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1494 | /** |
| 1495 | * zfcp_erp_port_boxed - Mark port as "boxed" and start ERP |
| 1496 | * @port: The "boxed" port. |
| 1497 | * @id: The debug trace id. |
| 1498 | * @id: Reference for the debug trace. |
| 1499 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1500 | 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] | 1501 | { |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1502 | unsigned long flags; |
| 1503 | |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1504 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1505 | zfcp_erp_modify_port_status(port, id, ref, |
| 1506 | ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1507 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1508 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1511 | /** |
| 1512 | * zfcp_erp_unit_boxed - Mark unit as "boxed" and start ERP |
| 1513 | * @port: The "boxed" unit. |
| 1514 | * @id: The debug trace id. |
| 1515 | * @id: Reference for the debug trace. |
| 1516 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1517 | 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] | 1518 | { |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1519 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1520 | ZFCP_STATUS_COMMON_ACCESS_BOXED, ZFCP_SET); |
Martin Peschke | 9467a9b | 2008-03-27 14:22:03 +0100 | [diff] [blame] | 1521 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
Andreas Herrmann | d736a27b | 2005-06-13 13:23:57 +0200 | [diff] [blame] | 1522 | } |
| 1523 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1524 | /** |
| 1525 | * zfcp_erp_port_access_denied - Adapter denied access to port. |
| 1526 | * @port: port where access has been denied |
| 1527 | * @id: id for debug trace |
| 1528 | * @ref: reference for debug trace |
| 1529 | * |
| 1530 | * Since the adapter has denied access, stop using the port and the |
| 1531 | * attached units. |
| 1532 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1533 | 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] | 1534 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | unsigned long flags; |
| 1536 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1538 | zfcp_erp_modify_port_status(port, id, ref, |
| 1539 | ZFCP_STATUS_COMMON_ERP_FAILED | |
| 1540 | ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1542 | } |
| 1543 | |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1544 | /** |
| 1545 | * zfcp_erp_unit_access_denied - Adapter denied access to unit. |
| 1546 | * @unit: unit where access has been denied |
| 1547 | * @id: id for debug trace |
| 1548 | * @ref: reference for debug trace |
| 1549 | * |
| 1550 | * Since the adapter has denied access, stop using the unit. |
| 1551 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1552 | 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] | 1553 | { |
Martin Peschke | 698ec016 | 2008-03-27 14:22:02 +0100 | [diff] [blame] | 1554 | zfcp_erp_modify_unit_status(unit, id, ref, |
| 1555 | ZFCP_STATUS_COMMON_ERP_FAILED | |
| 1556 | ZFCP_STATUS_COMMON_ACCESS_DENIED, ZFCP_SET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1559 | 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] | 1560 | void *ref) |
| 1561 | { |
| 1562 | int status = atomic_read(&unit->status); |
| 1563 | if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1564 | ZFCP_STATUS_COMMON_ACCESS_BOXED))) |
| 1565 | return; |
| 1566 | |
| 1567 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
| 1568 | } |
| 1569 | |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1570 | 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] | 1571 | void *ref) |
| 1572 | { |
| 1573 | struct zfcp_unit *unit; |
| 1574 | int status = atomic_read(&port->status); |
| 1575 | |
| 1576 | if (!(status & (ZFCP_STATUS_COMMON_ACCESS_DENIED | |
| 1577 | ZFCP_STATUS_COMMON_ACCESS_BOXED))) { |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1578 | list_for_each_entry(unit, &port->unit_list_head, list) |
| 1579 | zfcp_erp_unit_access_changed(unit, id, ref); |
Christof Schmitt | 287ac01 | 2008-07-02 10:56:40 +0200 | [diff] [blame] | 1580 | return; |
| 1581 | } |
| 1582 | |
| 1583 | zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, id, ref); |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * zfcp_erp_adapter_access_changed - Process change in adapter ACT |
| 1588 | * @adapter: Adapter where the Access Control Table (ACT) changed |
| 1589 | * @id: Id for debug trace |
| 1590 | * @ref: Reference for debug trace |
| 1591 | */ |
Swen Schillig | 5ffd51a | 2009-03-02 13:09:04 +0100 | [diff] [blame] | 1592 | void zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter, char *id, |
Martin Peschke | 1f6f712 | 2008-04-18 12:51:55 +0200 | [diff] [blame] | 1593 | void *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | { |
| 1595 | struct zfcp_port *port; |
| 1596 | unsigned long flags; |
| 1597 | |
Maxim Shchetynin | aef4a98 | 2005-09-13 21:51:16 +0200 | [diff] [blame] | 1598 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) |
| 1599 | return; |
| 1600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | read_lock_irqsave(&zfcp_data.config_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | list_for_each_entry(port, &adapter->port_list_head, list) |
Swen Schillig | 5ab944f | 2008-10-01 12:42:17 +0200 | [diff] [blame] | 1603 | zfcp_erp_port_access_changed(port, id, ref); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); |
| 1605 | } |