Commit | Line | Data |
---|---|---|
41fa2ada | 1 | /* |
553448f6 | 2 | * zfcp device driver |
1da177e4 | 3 | * |
553448f6 | 4 | * Error Recovery Procedures (ERP). |
41fa2ada | 5 | * |
a53c8fab | 6 | * Copyright IBM Corp. 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 void zfcp_erp_enqueue_ptp_port(struct zfcp_adapter *adapter) |
648 | { | |
649 | struct zfcp_port *port; | |
650 | port = zfcp_port_enqueue(adapter, adapter->peer_wwpn, 0, | |
651 | adapter->peer_d_id); | |
652 | if (IS_ERR(port)) /* error or port already attached */ | |
653 | return; | |
ea4a3a6a | 654 | _zfcp_erp_port_reopen(port, 0, "ereptp1"); |
287ac01a | 655 | } |
1da177e4 | 656 | |
287ac01a CS |
657 | static int zfcp_erp_adapter_strat_fsf_xconf(struct zfcp_erp_action *erp_action) |
658 | { | |
659 | int retries; | |
660 | int sleep = 1; | |
661 | struct zfcp_adapter *adapter = erp_action->adapter; | |
1da177e4 | 662 | |
287ac01a CS |
663 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status); |
664 | ||
665 | for (retries = 7; retries; retries--) { | |
666 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, | |
667 | &adapter->status); | |
668 | write_lock_irq(&adapter->erp_lock); | |
669 | zfcp_erp_action_to_running(erp_action); | |
670 | write_unlock_irq(&adapter->erp_lock); | |
671 | if (zfcp_fsf_exchange_config_data(erp_action)) { | |
672 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, | |
673 | &adapter->status); | |
674 | return ZFCP_ERP_FAILED; | |
1da177e4 | 675 | } |
1da177e4 | 676 | |
347c6a96 CS |
677 | wait_event(adapter->erp_ready_wq, |
678 | !list_empty(&adapter->erp_ready_head)); | |
287ac01a CS |
679 | if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) |
680 | break; | |
1da177e4 | 681 | |
287ac01a CS |
682 | if (!(atomic_read(&adapter->status) & |
683 | ZFCP_STATUS_ADAPTER_HOST_CON_INIT)) | |
684 | break; | |
1da177e4 | 685 | |
287ac01a CS |
686 | ssleep(sleep); |
687 | sleep *= 2; | |
1da177e4 LT |
688 | } |
689 | ||
287ac01a CS |
690 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, |
691 | &adapter->status); | |
1da177e4 | 692 | |
287ac01a CS |
693 | if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_XCONFIG_OK)) |
694 | return ZFCP_ERP_FAILED; | |
41fa2ada | 695 | |
287ac01a CS |
696 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) |
697 | zfcp_erp_enqueue_ptp_port(adapter); | |
1da177e4 | 698 | |
287ac01a | 699 | return ZFCP_ERP_SUCCEEDED; |
1da177e4 LT |
700 | } |
701 | ||
287ac01a | 702 | static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *act) |
1da177e4 | 703 | { |
287ac01a CS |
704 | int ret; |
705 | struct zfcp_adapter *adapter = act->adapter; | |
1da177e4 | 706 | |
287ac01a CS |
707 | write_lock_irq(&adapter->erp_lock); |
708 | zfcp_erp_action_to_running(act); | |
709 | write_unlock_irq(&adapter->erp_lock); | |
710 | ||
711 | ret = zfcp_fsf_exchange_port_data(act); | |
712 | if (ret == -EOPNOTSUPP) | |
713 | return ZFCP_ERP_SUCCEEDED; | |
714 | if (ret) | |
715 | return ZFCP_ERP_FAILED; | |
716 | ||
ae0904f6 | 717 | zfcp_dbf_rec_run("erasox1", act); |
347c6a96 CS |
718 | wait_event(adapter->erp_ready_wq, |
719 | !list_empty(&adapter->erp_ready_head)); | |
ae0904f6 | 720 | zfcp_dbf_rec_run("erasox2", act); |
287ac01a CS |
721 | if (act->status & ZFCP_STATUS_ERP_TIMEDOUT) |
722 | return ZFCP_ERP_FAILED; | |
723 | ||
724 | return ZFCP_ERP_SUCCEEDED; | |
1da177e4 LT |
725 | } |
726 | ||
287ac01a | 727 | static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *act) |
1da177e4 | 728 | { |
287ac01a CS |
729 | if (zfcp_erp_adapter_strat_fsf_xconf(act) == ZFCP_ERP_FAILED) |
730 | return ZFCP_ERP_FAILED; | |
1da177e4 | 731 | |
287ac01a CS |
732 | if (zfcp_erp_adapter_strategy_open_fsf_xport(act) == ZFCP_ERP_FAILED) |
733 | return ZFCP_ERP_FAILED; | |
1da177e4 | 734 | |
c7b279ae | 735 | if (mempool_resize(act->adapter->pool.sr_data, |
8d88cf3f CS |
736 | act->adapter->stat_read_buf_num, GFP_KERNEL)) |
737 | return ZFCP_ERP_FAILED; | |
738 | ||
739 | if (mempool_resize(act->adapter->pool.status_read_req, | |
740 | act->adapter->stat_read_buf_num, GFP_KERNEL)) | |
741 | return ZFCP_ERP_FAILED; | |
742 | ||
64deb6ef | 743 | atomic_set(&act->adapter->stat_miss, act->adapter->stat_read_buf_num); |
287ac01a CS |
744 | if (zfcp_status_read_refill(act->adapter)) |
745 | return ZFCP_ERP_FAILED; | |
1da177e4 | 746 | |
287ac01a CS |
747 | return ZFCP_ERP_SUCCEEDED; |
748 | } | |
1da177e4 | 749 | |
cf13c082 | 750 | static void zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *act) |
287ac01a | 751 | { |
287ac01a | 752 | struct zfcp_adapter *adapter = act->adapter; |
1da177e4 | 753 | |
287ac01a | 754 | /* close queues to ensure that buffers are not accessed by adapter */ |
564e1c86 | 755 | zfcp_qdio_close(adapter->qdio); |
287ac01a CS |
756 | zfcp_fsf_req_dismiss_all(adapter); |
757 | adapter->fsf_req_seq_no = 0; | |
55c770fa | 758 | zfcp_fc_wka_ports_force_offline(adapter->gs); |
b62a8d9b | 759 | /* all ports and LUNs are closed */ |
edaed859 | 760 | zfcp_erp_clear_adapter_status(adapter, ZFCP_STATUS_COMMON_OPEN); |
cf13c082 | 761 | |
287ac01a | 762 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK | |
cf13c082 | 763 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status); |
1da177e4 LT |
764 | } |
765 | ||
cf13c082 | 766 | static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *act) |
1da177e4 | 767 | { |
cf13c082 | 768 | struct zfcp_adapter *adapter = act->adapter; |
1da177e4 | 769 | |
3d63d3b4 | 770 | if (zfcp_qdio_open(adapter->qdio)) { |
cf13c082 SS |
771 | atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK | |
772 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, | |
773 | &adapter->status); | |
774 | return ZFCP_ERP_FAILED; | |
775 | } | |
287ac01a | 776 | |
cf13c082 SS |
777 | if (zfcp_erp_adapter_strategy_open_fsf(act)) { |
778 | zfcp_erp_adapter_strategy_close(act); | |
779 | return ZFCP_ERP_FAILED; | |
780 | } | |
781 | ||
782 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &adapter->status); | |
783 | ||
784 | return ZFCP_ERP_SUCCEEDED; | |
785 | } | |
287ac01a | 786 | |
cf13c082 SS |
787 | static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *act) |
788 | { | |
789 | struct zfcp_adapter *adapter = act->adapter; | |
790 | ||
791 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_OPEN) { | |
792 | zfcp_erp_adapter_strategy_close(act); | |
793 | if (act->status & ZFCP_STATUS_ERP_CLOSE_ONLY) | |
794 | return ZFCP_ERP_EXIT; | |
795 | } | |
796 | ||
797 | if (zfcp_erp_adapter_strategy_open(act)) { | |
287ac01a | 798 | ssleep(8); |
cf13c082 SS |
799 | return ZFCP_ERP_FAILED; |
800 | } | |
1da177e4 | 801 | |
cf13c082 | 802 | return ZFCP_ERP_SUCCEEDED; |
1da177e4 LT |
803 | } |
804 | ||
287ac01a | 805 | static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act) |
1da177e4 | 806 | { |
287ac01a CS |
807 | int retval; |
808 | ||
809 | retval = zfcp_fsf_close_physical_port(act); | |
810 | if (retval == -ENOMEM) | |
811 | return ZFCP_ERP_NOMEM; | |
812 | act->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING; | |
813 | if (retval) | |
814 | return ZFCP_ERP_FAILED; | |
815 | ||
816 | return ZFCP_ERP_CONTINUES; | |
1da177e4 LT |
817 | } |
818 | ||
287ac01a | 819 | static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port) |
1da177e4 | 820 | { |
a5b11dda | 821 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status); |
287ac01a | 822 | } |
1da177e4 | 823 | |
287ac01a CS |
824 | static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action) |
825 | { | |
826 | struct zfcp_port *port = erp_action->port; | |
827 | int status = atomic_read(&port->status); | |
828 | ||
829 | switch (erp_action->step) { | |
830 | case ZFCP_ERP_STEP_UNINITIALIZED: | |
831 | zfcp_erp_port_strategy_clearstati(port); | |
832 | if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) && | |
833 | (status & ZFCP_STATUS_COMMON_OPEN)) | |
834 | return zfcp_erp_port_forced_strategy_close(erp_action); | |
835 | else | |
836 | return ZFCP_ERP_FAILED; | |
837 | ||
838 | case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: | |
ddb3e0c1 | 839 | if (!(status & ZFCP_STATUS_PORT_PHYS_OPEN)) |
287ac01a CS |
840 | return ZFCP_ERP_SUCCEEDED; |
841 | } | |
842 | return ZFCP_ERP_FAILED; | |
1da177e4 LT |
843 | } |
844 | ||
287ac01a | 845 | static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action) |
1da177e4 | 846 | { |
287ac01a | 847 | int retval; |
1da177e4 | 848 | |
287ac01a CS |
849 | retval = zfcp_fsf_close_port(erp_action); |
850 | if (retval == -ENOMEM) | |
851 | return ZFCP_ERP_NOMEM; | |
852 | erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING; | |
853 | if (retval) | |
854 | return ZFCP_ERP_FAILED; | |
855 | return ZFCP_ERP_CONTINUES; | |
1da177e4 LT |
856 | } |
857 | ||
287ac01a | 858 | static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action) |
1da177e4 | 859 | { |
287ac01a | 860 | int retval; |
1da177e4 | 861 | |
287ac01a CS |
862 | retval = zfcp_fsf_open_port(erp_action); |
863 | if (retval == -ENOMEM) | |
864 | return ZFCP_ERP_NOMEM; | |
865 | erp_action->step = ZFCP_ERP_STEP_PORT_OPENING; | |
866 | if (retval) | |
867 | return ZFCP_ERP_FAILED; | |
868 | return ZFCP_ERP_CONTINUES; | |
869 | } | |
1da177e4 | 870 | |
287ac01a | 871 | static int zfcp_erp_open_ptp_port(struct zfcp_erp_action *act) |
1da177e4 | 872 | { |
287ac01a CS |
873 | struct zfcp_adapter *adapter = act->adapter; |
874 | struct zfcp_port *port = act->port; | |
1da177e4 | 875 | |
287ac01a | 876 | if (port->wwpn != adapter->peer_wwpn) { |
edaed859 | 877 | zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ERP_FAILED); |
287ac01a CS |
878 | return ZFCP_ERP_FAILED; |
879 | } | |
880 | port->d_id = adapter->peer_d_id; | |
287ac01a CS |
881 | return zfcp_erp_port_strategy_open_port(act); |
882 | } | |
883 | ||
884 | static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *act) | |
885 | { | |
886 | struct zfcp_adapter *adapter = act->adapter; | |
887 | struct zfcp_port *port = act->port; | |
287ac01a CS |
888 | int p_status = atomic_read(&port->status); |
889 | ||
890 | switch (act->step) { | |
891 | case ZFCP_ERP_STEP_UNINITIALIZED: | |
892 | case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: | |
893 | case ZFCP_ERP_STEP_PORT_CLOSING: | |
894 | if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) | |
895 | return zfcp_erp_open_ptp_port(act); | |
b98478d7 | 896 | if (!port->d_id) { |
934aeb58 | 897 | zfcp_fc_trigger_did_lookup(port); |
799b76d0 | 898 | return ZFCP_ERP_EXIT; |
287ac01a | 899 | } |
287ac01a CS |
900 | return zfcp_erp_port_strategy_open_port(act); |
901 | ||
902 | case ZFCP_ERP_STEP_PORT_OPENING: | |
903 | /* D_ID might have changed during open */ | |
5ab944f9 | 904 | if (p_status & ZFCP_STATUS_COMMON_OPEN) { |
934aeb58 CS |
905 | if (!port->d_id) { |
906 | zfcp_fc_trigger_did_lookup(port); | |
907 | return ZFCP_ERP_EXIT; | |
5ab944f9 | 908 | } |
934aeb58 | 909 | return ZFCP_ERP_SUCCEEDED; |
5ab944f9 | 910 | } |
ea460a81 SS |
911 | if (port->d_id && !(p_status & ZFCP_STATUS_COMMON_NOESC)) { |
912 | port->d_id = 0; | |
f7bd7c36 | 913 | return ZFCP_ERP_FAILED; |
ea460a81 SS |
914 | } |
915 | /* fall through otherwise */ | |
287ac01a CS |
916 | } |
917 | return ZFCP_ERP_FAILED; | |
918 | } | |
919 | ||
287ac01a CS |
920 | static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action) |
921 | { | |
922 | struct zfcp_port *port = erp_action->port; | |
934aeb58 | 923 | int p_status = atomic_read(&port->status); |
287ac01a | 924 | |
934aeb58 CS |
925 | if ((p_status & ZFCP_STATUS_COMMON_NOESC) && |
926 | !(p_status & ZFCP_STATUS_COMMON_OPEN)) | |
5ab944f9 SS |
927 | goto close_init_done; |
928 | ||
287ac01a CS |
929 | switch (erp_action->step) { |
930 | case ZFCP_ERP_STEP_UNINITIALIZED: | |
931 | zfcp_erp_port_strategy_clearstati(port); | |
934aeb58 | 932 | if (p_status & ZFCP_STATUS_COMMON_OPEN) |
287ac01a | 933 | return zfcp_erp_port_strategy_close(erp_action); |
1da177e4 LT |
934 | break; |
935 | ||
287ac01a | 936 | case ZFCP_ERP_STEP_PORT_CLOSING: |
934aeb58 | 937 | if (p_status & ZFCP_STATUS_COMMON_OPEN) |
287ac01a | 938 | return ZFCP_ERP_FAILED; |
1da177e4 LT |
939 | break; |
940 | } | |
5ab944f9 SS |
941 | |
942 | close_init_done: | |
287ac01a CS |
943 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) |
944 | return ZFCP_ERP_EXIT; | |
1da177e4 | 945 | |
5ab944f9 | 946 | return zfcp_erp_port_strategy_open_common(erp_action); |
287ac01a CS |
947 | } |
948 | ||
b62a8d9b | 949 | static void zfcp_erp_lun_strategy_clearstati(struct scsi_device *sdev) |
287ac01a | 950 | { |
b62a8d9b CS |
951 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
952 | ||
44cc76f2 | 953 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
b62a8d9b CS |
954 | ZFCP_STATUS_LUN_SHARED | ZFCP_STATUS_LUN_READONLY, |
955 | &zfcp_sdev->status); | |
287ac01a CS |
956 | } |
957 | ||
b62a8d9b | 958 | static int zfcp_erp_lun_strategy_close(struct zfcp_erp_action *erp_action) |
287ac01a | 959 | { |
b62a8d9b | 960 | int retval = zfcp_fsf_close_lun(erp_action); |
287ac01a CS |
961 | if (retval == -ENOMEM) |
962 | return ZFCP_ERP_NOMEM; | |
b62a8d9b | 963 | erp_action->step = ZFCP_ERP_STEP_LUN_CLOSING; |
287ac01a CS |
964 | if (retval) |
965 | return ZFCP_ERP_FAILED; | |
966 | return ZFCP_ERP_CONTINUES; | |
967 | } | |
968 | ||
b62a8d9b | 969 | static int zfcp_erp_lun_strategy_open(struct zfcp_erp_action *erp_action) |
287ac01a | 970 | { |
b62a8d9b | 971 | int retval = zfcp_fsf_open_lun(erp_action); |
287ac01a CS |
972 | if (retval == -ENOMEM) |
973 | return ZFCP_ERP_NOMEM; | |
b62a8d9b | 974 | erp_action->step = ZFCP_ERP_STEP_LUN_OPENING; |
287ac01a CS |
975 | if (retval) |
976 | return ZFCP_ERP_FAILED; | |
977 | return ZFCP_ERP_CONTINUES; | |
1da177e4 LT |
978 | } |
979 | ||
b62a8d9b | 980 | static int zfcp_erp_lun_strategy(struct zfcp_erp_action *erp_action) |
1da177e4 | 981 | { |
b62a8d9b CS |
982 | struct scsi_device *sdev = erp_action->sdev; |
983 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); | |
287ac01a CS |
984 | |
985 | switch (erp_action->step) { | |
986 | case ZFCP_ERP_STEP_UNINITIALIZED: | |
b62a8d9b CS |
987 | zfcp_erp_lun_strategy_clearstati(sdev); |
988 | if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN) | |
989 | return zfcp_erp_lun_strategy_close(erp_action); | |
287ac01a | 990 | /* already closed, fall through */ |
b62a8d9b CS |
991 | case ZFCP_ERP_STEP_LUN_CLOSING: |
992 | if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN) | |
287ac01a CS |
993 | return ZFCP_ERP_FAILED; |
994 | if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY) | |
995 | return ZFCP_ERP_EXIT; | |
b62a8d9b | 996 | return zfcp_erp_lun_strategy_open(erp_action); |
287ac01a | 997 | |
b62a8d9b CS |
998 | case ZFCP_ERP_STEP_LUN_OPENING: |
999 | if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_OPEN) | |
287ac01a CS |
1000 | return ZFCP_ERP_SUCCEEDED; |
1001 | } | |
1002 | return ZFCP_ERP_FAILED; | |
1da177e4 LT |
1003 | } |
1004 | ||
b62a8d9b | 1005 | static int zfcp_erp_strategy_check_lun(struct scsi_device *sdev, int result) |
1da177e4 | 1006 | { |
b62a8d9b CS |
1007 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
1008 | ||
1da177e4 LT |
1009 | switch (result) { |
1010 | case ZFCP_ERP_SUCCEEDED : | |
b62a8d9b CS |
1011 | atomic_set(&zfcp_sdev->erp_counter, 0); |
1012 | zfcp_erp_lun_unblock(sdev); | |
1da177e4 LT |
1013 | break; |
1014 | case ZFCP_ERP_FAILED : | |
b62a8d9b CS |
1015 | atomic_inc(&zfcp_sdev->erp_counter); |
1016 | if (atomic_read(&zfcp_sdev->erp_counter) > ZFCP_MAX_ERPS) { | |
1017 | dev_err(&zfcp_sdev->port->adapter->ccw_device->dev, | |
1018 | "ERP failed for LUN 0x%016Lx on " | |
ff3b24fa | 1019 | "port 0x%016Lx\n", |
b62a8d9b CS |
1020 | (unsigned long long)zfcp_scsi_dev_lun(sdev), |
1021 | (unsigned long long)zfcp_sdev->port->wwpn); | |
edaed859 SS |
1022 | zfcp_erp_set_lun_status(sdev, |
1023 | ZFCP_STATUS_COMMON_ERP_FAILED); | |
ff3b24fa | 1024 | } |
1da177e4 | 1025 | break; |
1da177e4 LT |
1026 | } |
1027 | ||
b62a8d9b CS |
1028 | if (atomic_read(&zfcp_sdev->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
1029 | zfcp_erp_lun_block(sdev, 0); | |
1da177e4 LT |
1030 | result = ZFCP_ERP_EXIT; |
1031 | } | |
1da177e4 LT |
1032 | return result; |
1033 | } | |
1034 | ||
287ac01a | 1035 | static int zfcp_erp_strategy_check_port(struct zfcp_port *port, int result) |
1da177e4 | 1036 | { |
1da177e4 LT |
1037 | switch (result) { |
1038 | case ZFCP_ERP_SUCCEEDED : | |
1039 | atomic_set(&port->erp_counter, 0); | |
1040 | zfcp_erp_port_unblock(port); | |
1041 | break; | |
287ac01a | 1042 | |
1da177e4 | 1043 | case ZFCP_ERP_FAILED : |
287ac01a | 1044 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_NOESC) { |
cc8c2829 SS |
1045 | zfcp_erp_port_block(port, 0); |
1046 | result = ZFCP_ERP_EXIT; | |
1047 | } | |
1da177e4 | 1048 | atomic_inc(&port->erp_counter); |
ff3b24fa CS |
1049 | if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS) { |
1050 | dev_err(&port->adapter->ccw_device->dev, | |
1051 | "ERP failed for remote port 0x%016Lx\n", | |
7ba58c9c | 1052 | (unsigned long long)port->wwpn); |
edaed859 SS |
1053 | zfcp_erp_set_port_status(port, |
1054 | ZFCP_STATUS_COMMON_ERP_FAILED); | |
ff3b24fa | 1055 | } |
1da177e4 | 1056 | break; |
1da177e4 LT |
1057 | } |
1058 | ||
287ac01a CS |
1059 | if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
1060 | zfcp_erp_port_block(port, 0); | |
1da177e4 LT |
1061 | result = ZFCP_ERP_EXIT; |
1062 | } | |
1da177e4 LT |
1063 | return result; |
1064 | } | |
1065 | ||
287ac01a CS |
1066 | static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, |
1067 | int result) | |
1da177e4 | 1068 | { |
1da177e4 LT |
1069 | switch (result) { |
1070 | case ZFCP_ERP_SUCCEEDED : | |
1071 | atomic_set(&adapter->erp_counter, 0); | |
1072 | zfcp_erp_adapter_unblock(adapter); | |
1073 | break; | |
287ac01a | 1074 | |
1da177e4 LT |
1075 | case ZFCP_ERP_FAILED : |
1076 | atomic_inc(&adapter->erp_counter); | |
ff3b24fa CS |
1077 | if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS) { |
1078 | dev_err(&adapter->ccw_device->dev, | |
1079 | "ERP cannot recover an error " | |
1080 | "on the FCP device\n"); | |
edaed859 SS |
1081 | zfcp_erp_set_adapter_status(adapter, |
1082 | ZFCP_STATUS_COMMON_ERP_FAILED); | |
ff3b24fa | 1083 | } |
1da177e4 | 1084 | break; |
1da177e4 LT |
1085 | } |
1086 | ||
287ac01a CS |
1087 | if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED) { |
1088 | zfcp_erp_adapter_block(adapter, 0); | |
1da177e4 LT |
1089 | result = ZFCP_ERP_EXIT; |
1090 | } | |
1da177e4 LT |
1091 | return result; |
1092 | } | |
1093 | ||
287ac01a CS |
1094 | static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, |
1095 | int result) | |
5f852be9 | 1096 | { |
287ac01a CS |
1097 | struct zfcp_adapter *adapter = erp_action->adapter; |
1098 | struct zfcp_port *port = erp_action->port; | |
b62a8d9b | 1099 | struct scsi_device *sdev = erp_action->sdev; |
287ac01a CS |
1100 | |
1101 | switch (erp_action->action) { | |
1102 | ||
b62a8d9b CS |
1103 | case ZFCP_ERP_ACTION_REOPEN_LUN: |
1104 | result = zfcp_erp_strategy_check_lun(sdev, result); | |
287ac01a CS |
1105 | break; |
1106 | ||
1107 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: | |
1108 | case ZFCP_ERP_ACTION_REOPEN_PORT: | |
1109 | result = zfcp_erp_strategy_check_port(port, result); | |
1110 | break; | |
1111 | ||
1112 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: | |
1113 | result = zfcp_erp_strategy_check_adapter(adapter, result); | |
1114 | break; | |
1115 | } | |
1116 | return result; | |
5f852be9 CS |
1117 | } |
1118 | ||
287ac01a | 1119 | static int zfcp_erp_strat_change_det(atomic_t *target_status, u32 erp_status) |
5f852be9 | 1120 | { |
287ac01a | 1121 | int status = atomic_read(target_status); |
5f852be9 | 1122 | |
287ac01a CS |
1123 | if ((status & ZFCP_STATUS_COMMON_RUNNING) && |
1124 | (erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) | |
1125 | return 1; /* take it online */ | |
5f852be9 | 1126 | |
287ac01a CS |
1127 | if (!(status & ZFCP_STATUS_COMMON_RUNNING) && |
1128 | !(erp_status & ZFCP_STATUS_ERP_CLOSE_ONLY)) | |
1129 | return 1; /* take it offline */ | |
1130 | ||
1131 | return 0; | |
5f852be9 CS |
1132 | } |
1133 | ||
287ac01a | 1134 | static int zfcp_erp_strategy_statechange(struct zfcp_erp_action *act, int ret) |
1da177e4 | 1135 | { |
287ac01a CS |
1136 | int action = act->action; |
1137 | struct zfcp_adapter *adapter = act->adapter; | |
1138 | struct zfcp_port *port = act->port; | |
b62a8d9b CS |
1139 | struct scsi_device *sdev = act->sdev; |
1140 | struct zfcp_scsi_dev *zfcp_sdev; | |
287ac01a | 1141 | u32 erp_status = act->status; |
1da177e4 | 1142 | |
287ac01a | 1143 | switch (action) { |
1da177e4 | 1144 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
287ac01a CS |
1145 | if (zfcp_erp_strat_change_det(&adapter->status, erp_status)) { |
1146 | _zfcp_erp_adapter_reopen(adapter, | |
1147 | ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 1148 | "ersscg1"); |
287ac01a CS |
1149 | return ZFCP_ERP_EXIT; |
1150 | } | |
1da177e4 LT |
1151 | break; |
1152 | ||
1153 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: | |
1da177e4 | 1154 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
287ac01a CS |
1155 | if (zfcp_erp_strat_change_det(&port->status, erp_status)) { |
1156 | _zfcp_erp_port_reopen(port, | |
1157 | ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 1158 | "ersscg2"); |
287ac01a CS |
1159 | return ZFCP_ERP_EXIT; |
1160 | } | |
1da177e4 LT |
1161 | break; |
1162 | ||
b62a8d9b CS |
1163 | case ZFCP_ERP_ACTION_REOPEN_LUN: |
1164 | zfcp_sdev = sdev_to_zfcp(sdev); | |
1165 | if (zfcp_erp_strat_change_det(&zfcp_sdev->status, erp_status)) { | |
1166 | _zfcp_erp_lun_reopen(sdev, | |
1167 | ZFCP_STATUS_COMMON_ERP_FAILED, | |
ea4a3a6a | 1168 | "ersscg3", 0); |
287ac01a CS |
1169 | return ZFCP_ERP_EXIT; |
1170 | } | |
1da177e4 LT |
1171 | break; |
1172 | } | |
287ac01a | 1173 | return ret; |
1da177e4 LT |
1174 | } |
1175 | ||
287ac01a | 1176 | static void zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action) |
1da177e4 | 1177 | { |
287ac01a | 1178 | struct zfcp_adapter *adapter = erp_action->adapter; |
b62a8d9b | 1179 | struct zfcp_scsi_dev *zfcp_sdev; |
1da177e4 | 1180 | |
287ac01a CS |
1181 | adapter->erp_total_count--; |
1182 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { | |
1183 | adapter->erp_low_mem_count--; | |
1184 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; | |
507e4969 | 1185 | } |
1da177e4 | 1186 | |
287ac01a | 1187 | list_del(&erp_action->list); |
ae0904f6 | 1188 | zfcp_dbf_rec_run("eractd1", erp_action); |
1da177e4 | 1189 | |
287ac01a | 1190 | switch (erp_action->action) { |
b62a8d9b CS |
1191 | case ZFCP_ERP_ACTION_REOPEN_LUN: |
1192 | zfcp_sdev = sdev_to_zfcp(erp_action->sdev); | |
287ac01a | 1193 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, |
b62a8d9b | 1194 | &zfcp_sdev->status); |
287ac01a | 1195 | break; |
1da177e4 | 1196 | |
287ac01a CS |
1197 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: |
1198 | case ZFCP_ERP_ACTION_REOPEN_PORT: | |
1199 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, | |
1200 | &erp_action->port->status); | |
1201 | break; | |
1da177e4 | 1202 | |
287ac01a CS |
1203 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: |
1204 | atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE, | |
1205 | &erp_action->adapter->status); | |
1206 | break; | |
1207 | } | |
1da177e4 LT |
1208 | } |
1209 | ||
287ac01a | 1210 | static void zfcp_erp_action_cleanup(struct zfcp_erp_action *act, int result) |
1da177e4 | 1211 | { |
287ac01a CS |
1212 | struct zfcp_adapter *adapter = act->adapter; |
1213 | struct zfcp_port *port = act->port; | |
b62a8d9b | 1214 | struct scsi_device *sdev = act->sdev; |
1da177e4 | 1215 | |
287ac01a | 1216 | switch (act->action) { |
b62a8d9b | 1217 | case ZFCP_ERP_ACTION_REOPEN_LUN: |
fdbd1c5e | 1218 | if (!(act->status & ZFCP_STATUS_ERP_NO_REF)) |
b62a8d9b | 1219 | scsi_device_put(sdev); |
287ac01a | 1220 | break; |
1da177e4 | 1221 | |
287ac01a | 1222 | case ZFCP_ERP_ACTION_REOPEN_PORT: |
a2fa0aed CS |
1223 | if (result == ZFCP_ERP_SUCCEEDED) |
1224 | zfcp_scsi_schedule_rport_register(port); | |
5767620c CS |
1225 | /* fall through */ |
1226 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: | |
615f59e0 | 1227 | put_device(&port->dev); |
287ac01a CS |
1228 | break; |
1229 | ||
1230 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: | |
a2fa0aed | 1231 | if (result == ZFCP_ERP_SUCCEEDED) { |
bd43a42b | 1232 | register_service_level(&adapter->service_level); |
9eae07ef | 1233 | queue_work(adapter->work_queue, &adapter->scan_work); |
038d9446 | 1234 | queue_work(adapter->work_queue, &adapter->ns_up_work); |
a2fa0aed CS |
1235 | } else |
1236 | unregister_service_level(&adapter->service_level); | |
038d9446 | 1237 | |
f3450c7b | 1238 | kref_put(&adapter->ref, zfcp_adapter_release); |
287ac01a CS |
1239 | break; |
1240 | } | |
1da177e4 LT |
1241 | } |
1242 | ||
287ac01a | 1243 | static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action) |
1da177e4 | 1244 | { |
287ac01a CS |
1245 | switch (erp_action->action) { |
1246 | case ZFCP_ERP_ACTION_REOPEN_ADAPTER: | |
1247 | return zfcp_erp_adapter_strategy(erp_action); | |
1248 | case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: | |
1249 | return zfcp_erp_port_forced_strategy(erp_action); | |
1250 | case ZFCP_ERP_ACTION_REOPEN_PORT: | |
1251 | return zfcp_erp_port_strategy(erp_action); | |
b62a8d9b CS |
1252 | case ZFCP_ERP_ACTION_REOPEN_LUN: |
1253 | return zfcp_erp_lun_strategy(erp_action); | |
287ac01a CS |
1254 | } |
1255 | return ZFCP_ERP_FAILED; | |
1da177e4 LT |
1256 | } |
1257 | ||
287ac01a | 1258 | static int zfcp_erp_strategy(struct zfcp_erp_action *erp_action) |
1da177e4 LT |
1259 | { |
1260 | int retval; | |
287ac01a | 1261 | unsigned long flags; |
ecf0c772 | 1262 | struct zfcp_adapter *adapter = erp_action->adapter; |
1da177e4 | 1263 | |
f3450c7b | 1264 | kref_get(&adapter->ref); |
1da177e4 | 1265 | |
f3450c7b | 1266 | write_lock_irqsave(&adapter->erp_lock, flags); |
287ac01a | 1267 | zfcp_erp_strategy_check_fsfreq(erp_action); |
1da177e4 | 1268 | |
287ac01a CS |
1269 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) { |
1270 | zfcp_erp_action_dequeue(erp_action); | |
1271 | retval = ZFCP_ERP_DISMISSED; | |
1272 | goto unlock; | |
22753fa5 | 1273 | } |
1da177e4 | 1274 | |
9c785d94 CS |
1275 | if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) { |
1276 | retval = ZFCP_ERP_FAILED; | |
1277 | goto check_target; | |
1278 | } | |
1279 | ||
2f8f3ed5 | 1280 | zfcp_erp_action_to_running(erp_action); |
1da177e4 | 1281 | |
287ac01a | 1282 | /* no lock to allow for blocking operations */ |
ecf0c772 | 1283 | write_unlock_irqrestore(&adapter->erp_lock, flags); |
287ac01a | 1284 | retval = zfcp_erp_strategy_do_action(erp_action); |
ecf0c772 | 1285 | write_lock_irqsave(&adapter->erp_lock, flags); |
1da177e4 | 1286 | |
287ac01a CS |
1287 | if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) |
1288 | retval = ZFCP_ERP_CONTINUES; | |
cc8c2829 | 1289 | |
287ac01a CS |
1290 | switch (retval) { |
1291 | case ZFCP_ERP_NOMEM: | |
1292 | if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) { | |
1293 | ++adapter->erp_low_mem_count; | |
1294 | erp_action->status |= ZFCP_STATUS_ERP_LOWMEM; | |
1da177e4 | 1295 | } |
287ac01a | 1296 | if (adapter->erp_total_count == adapter->erp_low_mem_count) |
ea4a3a6a | 1297 | _zfcp_erp_adapter_reopen(adapter, 0, "erstgy1"); |
287ac01a CS |
1298 | else { |
1299 | zfcp_erp_strategy_memwait(erp_action); | |
1300 | retval = ZFCP_ERP_CONTINUES; | |
1da177e4 | 1301 | } |
287ac01a | 1302 | goto unlock; |
1da177e4 | 1303 | |
287ac01a CS |
1304 | case ZFCP_ERP_CONTINUES: |
1305 | if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) { | |
1306 | --adapter->erp_low_mem_count; | |
1307 | erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM; | |
1da177e4 | 1308 | } |
287ac01a | 1309 | goto unlock; |
1da177e4 LT |
1310 | } |
1311 | ||
9c785d94 | 1312 | check_target: |
287ac01a CS |
1313 | retval = zfcp_erp_strategy_check_target(erp_action, retval); |
1314 | zfcp_erp_action_dequeue(erp_action); | |
1315 | retval = zfcp_erp_strategy_statechange(erp_action, retval); | |
1316 | if (retval == ZFCP_ERP_EXIT) | |
1317 | goto unlock; | |
85600f7f CS |
1318 | if (retval == ZFCP_ERP_SUCCEEDED) |
1319 | zfcp_erp_strategy_followup_success(erp_action); | |
1320 | if (retval == ZFCP_ERP_FAILED) | |
1321 | zfcp_erp_strategy_followup_failed(erp_action); | |
1da177e4 | 1322 | |
287ac01a | 1323 | unlock: |
ecf0c772 | 1324 | write_unlock_irqrestore(&adapter->erp_lock, flags); |
1da177e4 | 1325 | |
287ac01a CS |
1326 | if (retval != ZFCP_ERP_CONTINUES) |
1327 | zfcp_erp_action_cleanup(erp_action, retval); | |
1da177e4 | 1328 | |
f3450c7b | 1329 | kref_put(&adapter->ref, zfcp_adapter_release); |
1da177e4 LT |
1330 | return retval; |
1331 | } | |
1332 | ||
287ac01a | 1333 | static int zfcp_erp_thread(void *data) |
1da177e4 | 1334 | { |
287ac01a CS |
1335 | struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; |
1336 | struct list_head *next; | |
1337 | struct zfcp_erp_action *act; | |
1338 | unsigned long flags; | |
94ab4b38 | 1339 | |
347c6a96 | 1340 | for (;;) { |
347c6a96 CS |
1341 | wait_event_interruptible(adapter->erp_ready_wq, |
1342 | !list_empty(&adapter->erp_ready_head) || | |
1343 | kthread_should_stop()); | |
94ab4b38 | 1344 | |
347c6a96 CS |
1345 | if (kthread_should_stop()) |
1346 | break; | |
1347 | ||
287ac01a CS |
1348 | write_lock_irqsave(&adapter->erp_lock, flags); |
1349 | next = adapter->erp_ready_head.next; | |
1350 | write_unlock_irqrestore(&adapter->erp_lock, flags); | |
1da177e4 | 1351 | |
287ac01a CS |
1352 | if (next != &adapter->erp_ready_head) { |
1353 | act = list_entry(next, struct zfcp_erp_action, list); | |
1da177e4 | 1354 | |
287ac01a CS |
1355 | /* there is more to come after dismission, no notify */ |
1356 | if (zfcp_erp_strategy(act) != ZFCP_ERP_DISMISSED) | |
1357 | zfcp_erp_wakeup(adapter); | |
1da177e4 | 1358 | } |
1da177e4 LT |
1359 | } |
1360 | ||
287ac01a CS |
1361 | return 0; |
1362 | } | |
1da177e4 | 1363 | |
287ac01a CS |
1364 | /** |
1365 | * zfcp_erp_thread_setup - Start ERP thread for adapter | |
1366 | * @adapter: Adapter to start the ERP thread for | |
1367 | * | |
1368 | * Returns 0 on success or error code from kernel_thread() | |
1369 | */ | |
1370 | int zfcp_erp_thread_setup(struct zfcp_adapter *adapter) | |
1371 | { | |
347c6a96 | 1372 | struct task_struct *thread; |
1da177e4 | 1373 | |
347c6a96 CS |
1374 | thread = kthread_run(zfcp_erp_thread, adapter, "zfcperp%s", |
1375 | dev_name(&adapter->ccw_device->dev)); | |
1376 | if (IS_ERR(thread)) { | |
287ac01a | 1377 | dev_err(&adapter->ccw_device->dev, |
ff3b24fa | 1378 | "Creating an ERP thread for the FCP device failed.\n"); |
347c6a96 | 1379 | return PTR_ERR(thread); |
1da177e4 | 1380 | } |
347c6a96 CS |
1381 | |
1382 | adapter->erp_thread = thread; | |
287ac01a CS |
1383 | return 0; |
1384 | } | |
1da177e4 | 1385 | |
287ac01a CS |
1386 | /** |
1387 | * zfcp_erp_thread_kill - Stop ERP thread. | |
1388 | * @adapter: Adapter where the ERP thread should be stopped. | |
1389 | * | |
1390 | * The caller of this routine ensures that the specified adapter has | |
1391 | * been shut down and that this operation has been completed. Thus, | |
1392 | * there are no pending erp_actions which would need to be handled | |
1393 | * here. | |
1394 | */ | |
1395 | void zfcp_erp_thread_kill(struct zfcp_adapter *adapter) | |
1396 | { | |
347c6a96 CS |
1397 | kthread_stop(adapter->erp_thread); |
1398 | adapter->erp_thread = NULL; | |
143bb6bf CS |
1399 | WARN_ON(!list_empty(&adapter->erp_ready_head)); |
1400 | WARN_ON(!list_empty(&adapter->erp_running_head)); | |
1da177e4 LT |
1401 | } |
1402 | ||
287ac01a | 1403 | /** |
edaed859 SS |
1404 | * zfcp_erp_wait - wait for completion of error recovery on an adapter |
1405 | * @adapter: adapter for which to wait for completion of its error recovery | |
287ac01a | 1406 | */ |
edaed859 | 1407 | void zfcp_erp_wait(struct zfcp_adapter *adapter) |
1da177e4 | 1408 | { |
edaed859 SS |
1409 | wait_event(adapter->erp_done_wqh, |
1410 | !(atomic_read(&adapter->status) & | |
1411 | ZFCP_STATUS_ADAPTER_ERP_PENDING)); | |
287ac01a | 1412 | } |
1da177e4 | 1413 | |
287ac01a | 1414 | /** |
edaed859 SS |
1415 | * zfcp_erp_set_adapter_status - set adapter status bits |
1416 | * @adapter: adapter to change the status | |
1417 | * @mask: status bits to change | |
1418 | * | |
1419 | * Changes in common status bits are propagated to attached ports and LUNs. | |
287ac01a | 1420 | */ |
edaed859 | 1421 | void zfcp_erp_set_adapter_status(struct zfcp_adapter *adapter, u32 mask) |
287ac01a | 1422 | { |
edaed859 SS |
1423 | struct zfcp_port *port; |
1424 | struct scsi_device *sdev; | |
1425 | unsigned long flags; | |
1426 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; | |
1da177e4 | 1427 | |
edaed859 | 1428 | atomic_set_mask(mask, &adapter->status); |
1da177e4 | 1429 | |
edaed859 SS |
1430 | if (!common_mask) |
1431 | return; | |
1432 | ||
1433 | read_lock_irqsave(&adapter->port_list_lock, flags); | |
1434 | list_for_each_entry(port, &adapter->port_list, list) | |
1435 | atomic_set_mask(common_mask, &port->status); | |
1436 | read_unlock_irqrestore(&adapter->port_list_lock, flags); | |
1437 | ||
1438 | shost_for_each_device(sdev, adapter->scsi_host) | |
1439 | atomic_set_mask(common_mask, &sdev_to_zfcp(sdev)->status); | |
287ac01a | 1440 | } |
1da177e4 | 1441 | |
287ac01a | 1442 | /** |
edaed859 | 1443 | * zfcp_erp_clear_adapter_status - clear adapter status bits |
287ac01a | 1444 | * @adapter: adapter to change the status |
287ac01a | 1445 | * @mask: status bits to change |
287ac01a | 1446 | * |
b62a8d9b | 1447 | * Changes in common status bits are propagated to attached ports and LUNs. |
287ac01a | 1448 | */ |
edaed859 | 1449 | void zfcp_erp_clear_adapter_status(struct zfcp_adapter *adapter, u32 mask) |
1da177e4 | 1450 | { |
1da177e4 | 1451 | struct zfcp_port *port; |
edaed859 | 1452 | struct scsi_device *sdev; |
ecf0c772 | 1453 | unsigned long flags; |
287ac01a | 1454 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
edaed859 | 1455 | u32 clear_counter = mask & ZFCP_STATUS_COMMON_ERP_FAILED; |
1da177e4 | 1456 | |
edaed859 SS |
1457 | atomic_clear_mask(mask, &adapter->status); |
1458 | ||
1459 | if (!common_mask) | |
1460 | return; | |
1461 | ||
1462 | if (clear_counter) | |
1463 | atomic_set(&adapter->erp_counter, 0); | |
1464 | ||
1465 | read_lock_irqsave(&adapter->port_list_lock, flags); | |
1466 | list_for_each_entry(port, &adapter->port_list, list) { | |
1467 | atomic_clear_mask(common_mask, &port->status); | |
1468 | if (clear_counter) | |
1469 | atomic_set(&port->erp_counter, 0); | |
287ac01a | 1470 | } |
edaed859 | 1471 | read_unlock_irqrestore(&adapter->port_list_lock, flags); |
287ac01a | 1472 | |
edaed859 SS |
1473 | shost_for_each_device(sdev, adapter->scsi_host) { |
1474 | atomic_clear_mask(common_mask, &sdev_to_zfcp(sdev)->status); | |
1475 | if (clear_counter) | |
1476 | atomic_set(&sdev_to_zfcp(sdev)->erp_counter, 0); | |
ecf0c772 | 1477 | } |
1da177e4 LT |
1478 | } |
1479 | ||
287ac01a | 1480 | /** |
edaed859 SS |
1481 | * zfcp_erp_set_port_status - set port status bits |
1482 | * @port: port to change the status | |
287ac01a | 1483 | * @mask: status bits to change |
287ac01a | 1484 | * |
b62a8d9b | 1485 | * Changes in common status bits are propagated to attached LUNs. |
287ac01a | 1486 | */ |
edaed859 | 1487 | void zfcp_erp_set_port_status(struct zfcp_port *port, u32 mask) |
1da177e4 | 1488 | { |
b62a8d9b | 1489 | struct scsi_device *sdev; |
287ac01a | 1490 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; |
1da177e4 | 1491 | |
edaed859 | 1492 | atomic_set_mask(mask, &port->status); |
1da177e4 | 1493 | |
edaed859 SS |
1494 | if (!common_mask) |
1495 | return; | |
1496 | ||
1497 | shost_for_each_device(sdev, port->adapter->scsi_host) | |
1498 | if (sdev_to_zfcp(sdev)->port == port) | |
1499 | atomic_set_mask(common_mask, | |
1500 | &sdev_to_zfcp(sdev)->status); | |
1da177e4 LT |
1501 | } |
1502 | ||
287ac01a | 1503 | /** |
edaed859 SS |
1504 | * zfcp_erp_clear_port_status - clear port status bits |
1505 | * @port: adapter to change the status | |
287ac01a | 1506 | * @mask: status bits to change |
edaed859 SS |
1507 | * |
1508 | * Changes in common status bits are propagated to attached LUNs. | |
287ac01a | 1509 | */ |
edaed859 | 1510 | void zfcp_erp_clear_port_status(struct zfcp_port *port, u32 mask) |
1da177e4 | 1511 | { |
edaed859 SS |
1512 | struct scsi_device *sdev; |
1513 | u32 common_mask = mask & ZFCP_COMMON_FLAGS; | |
1514 | u32 clear_counter = mask & ZFCP_STATUS_COMMON_ERP_FAILED; | |
1515 | ||
1516 | atomic_clear_mask(mask, &port->status); | |
1517 | ||
1518 | if (!common_mask) | |
1519 | return; | |
b62a8d9b | 1520 | |
edaed859 SS |
1521 | if (clear_counter) |
1522 | atomic_set(&port->erp_counter, 0); | |
1523 | ||
1524 | shost_for_each_device(sdev, port->adapter->scsi_host) | |
1525 | if (sdev_to_zfcp(sdev)->port == port) { | |
1526 | atomic_clear_mask(common_mask, | |
1527 | &sdev_to_zfcp(sdev)->status); | |
1528 | if (clear_counter) | |
1529 | atomic_set(&sdev_to_zfcp(sdev)->erp_counter, 0); | |
287ac01a | 1530 | } |
1da177e4 LT |
1531 | } |
1532 | ||
287ac01a | 1533 | /** |
edaed859 SS |
1534 | * zfcp_erp_set_lun_status - set lun status bits |
1535 | * @sdev: SCSI device / lun to set the status bits | |
1536 | * @mask: status bits to change | |
287ac01a | 1537 | */ |
edaed859 | 1538 | void zfcp_erp_set_lun_status(struct scsi_device *sdev, u32 mask) |
d736a27b | 1539 | { |
edaed859 SS |
1540 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
1541 | ||
1542 | atomic_set_mask(mask, &zfcp_sdev->status); | |
d736a27b AH |
1543 | } |
1544 | ||
287ac01a | 1545 | /** |
edaed859 SS |
1546 | * zfcp_erp_clear_lun_status - clear lun status bits |
1547 | * @sdev: SCSi device / lun to clear the status bits | |
1548 | * @mask: status bits to change | |
287ac01a | 1549 | */ |
edaed859 | 1550 | void zfcp_erp_clear_lun_status(struct scsi_device *sdev, u32 mask) |
d736a27b | 1551 | { |
edaed859 SS |
1552 | struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); |
1553 | ||
1554 | atomic_clear_mask(mask, &zfcp_sdev->status); | |
1555 | ||
1556 | if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) | |
1557 | atomic_set(&zfcp_sdev->erp_counter, 0); | |
d736a27b | 1558 | } |
edaed859 | 1559 |