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