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