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