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