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