]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * | |
3 | * linux/drivers/s390/scsi/zfcp_fsf.c | |
4 | * | |
5 | * FCP adapter driver for IBM eServer zSeries | |
6 | * | |
7 | * (C) Copyright IBM Corp. 2002, 2004 | |
8 | * | |
9 | * Author(s): Martin Peschke <mpeschke@de.ibm.com> | |
10 | * Raimund Schroeder <raimund.schroeder@de.ibm.com> | |
11 | * Aron Zeh | |
12 | * Wolfgang Taphorn | |
13 | * Stefan Bader <stefan.bader@de.ibm.com> | |
14 | * Heiko Carstens <heiko.carstens@de.ibm.com> | |
15 | * Andreas Herrmann <aherrman@de.ibm.com> | |
16 | * Volker Sameske <sameske@de.ibm.com> | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | * the Free Software Foundation; either version 2, or (at your option) | |
21 | * any later version. | |
22 | * | |
23 | * This program is distributed in the hope that it will be useful, | |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
27 | * | |
28 | * You should have received a copy of the GNU General Public License | |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
31 | */ | |
32 | ||
33 | #define ZFCP_FSF_C_REVISION "$Revision: 1.92 $" | |
34 | ||
35 | #include "zfcp_ext.h" | |
36 | ||
37 | static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *); | |
38 | static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *); | |
39 | static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *); | |
40 | static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *); | |
41 | static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *); | |
42 | static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *); | |
43 | static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *); | |
44 | static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *); | |
45 | static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *); | |
46 | static int zfcp_fsf_send_fcp_command_task_management_handler( | |
47 | struct zfcp_fsf_req *); | |
48 | static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *); | |
49 | static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *); | |
50 | static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *); | |
51 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *); | |
52 | static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *); | |
53 | static inline int zfcp_fsf_req_sbal_check( | |
54 | unsigned long *, struct zfcp_qdio_queue *, int); | |
55 | static inline int zfcp_use_one_sbal( | |
56 | struct scatterlist *, int, struct scatterlist *, int); | |
57 | static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int); | |
58 | static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *); | |
59 | static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *); | |
60 | static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *); | |
61 | static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *); | |
aef4a983 MS |
62 | static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *, |
63 | struct fsf_link_down_info *); | |
1da177e4 LT |
64 | static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *); |
65 | static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *); | |
1da177e4 LT |
66 | |
67 | /* association between FSF command and FSF QTCB type */ | |
68 | static u32 fsf_qtcb_type[] = { | |
69 | [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND, | |
70 | [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND, | |
71 | [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND, | |
72 | [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND, | |
73 | [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND, | |
74 | [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND, | |
75 | [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND, | |
76 | [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND, | |
77 | [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND, | |
78 | [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND, | |
79 | [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND, | |
80 | [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND, | |
81 | [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND | |
82 | }; | |
83 | ||
84 | static const char zfcp_act_subtable_type[5][8] = { | |
85 | "unknown", "OS", "WWPN", "DID", "LUN" | |
86 | }; | |
87 | ||
88 | /****************************************************************/ | |
89 | /*************** FSF related Functions *************************/ | |
90 | /****************************************************************/ | |
91 | ||
92 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF | |
93 | ||
94 | /* | |
95 | * function: zfcp_fsf_req_alloc | |
96 | * | |
97 | * purpose: Obtains an fsf_req and potentially a qtcb (for all but | |
98 | * unsolicited requests) via helper functions | |
99 | * Does some initial fsf request set-up. | |
100 | * | |
101 | * returns: pointer to allocated fsf_req if successfull | |
102 | * NULL otherwise | |
103 | * | |
104 | * locks: none | |
105 | * | |
106 | */ | |
107 | static struct zfcp_fsf_req * | |
108 | zfcp_fsf_req_alloc(mempool_t *pool, int req_flags) | |
109 | { | |
110 | size_t size; | |
111 | void *ptr; | |
112 | struct zfcp_fsf_req *fsf_req = NULL; | |
113 | ||
114 | if (req_flags & ZFCP_REQ_NO_QTCB) | |
115 | size = sizeof(struct zfcp_fsf_req); | |
116 | else | |
117 | size = sizeof(struct zfcp_fsf_req_pool_element); | |
118 | ||
119 | if (likely(pool != NULL)) | |
120 | ptr = mempool_alloc(pool, GFP_ATOMIC); | |
121 | else | |
122 | ptr = kmalloc(size, GFP_ATOMIC); | |
123 | ||
124 | if (unlikely(NULL == ptr)) | |
125 | goto out; | |
126 | ||
127 | memset(ptr, 0, size); | |
128 | ||
129 | if (req_flags & ZFCP_REQ_NO_QTCB) { | |
130 | fsf_req = (struct zfcp_fsf_req *) ptr; | |
131 | } else { | |
132 | fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req; | |
133 | fsf_req->qtcb = | |
134 | &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb; | |
135 | } | |
136 | ||
137 | fsf_req->pool = pool; | |
138 | ||
139 | out: | |
140 | return fsf_req; | |
141 | } | |
142 | ||
143 | /* | |
144 | * function: zfcp_fsf_req_free | |
145 | * | |
146 | * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or | |
147 | * returns it into the pool via helper functions. | |
148 | * | |
149 | * returns: sod all | |
150 | * | |
151 | * locks: none | |
152 | */ | |
1db2c9c0 | 153 | void |
1da177e4 LT |
154 | zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req) |
155 | { | |
156 | if (likely(fsf_req->pool != NULL)) | |
157 | mempool_free(fsf_req, fsf_req->pool); | |
1db2c9c0 AH |
158 | else |
159 | kfree(fsf_req); | |
1da177e4 LT |
160 | } |
161 | ||
162 | /* | |
163 | * function: | |
164 | * | |
165 | * purpose: | |
166 | * | |
167 | * returns: | |
168 | * | |
169 | * note: qdio queues shall be down (no ongoing inbound processing) | |
170 | */ | |
171 | int | |
172 | zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) | |
173 | { | |
1da177e4 | 174 | struct zfcp_fsf_req *fsf_req, *tmp; |
1db2c9c0 AH |
175 | unsigned long flags; |
176 | LIST_HEAD(remove_queue); | |
1da177e4 | 177 | |
1db2c9c0 AH |
178 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
179 | list_splice_init(&adapter->fsf_req_list_head, &remove_queue); | |
180 | atomic_set(&adapter->fsf_reqs_active, 0); | |
181 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); | |
1da177e4 | 182 | |
1db2c9c0 AH |
183 | list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) { |
184 | list_del(&fsf_req->list); | |
185 | zfcp_fsf_req_dismiss(fsf_req); | |
1da177e4 LT |
186 | } |
187 | ||
1db2c9c0 | 188 | return 0; |
1da177e4 LT |
189 | } |
190 | ||
191 | /* | |
192 | * function: | |
193 | * | |
194 | * purpose: | |
195 | * | |
196 | * returns: | |
197 | */ | |
198 | static void | |
199 | zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req) | |
200 | { | |
201 | fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; | |
202 | zfcp_fsf_req_complete(fsf_req); | |
203 | } | |
204 | ||
205 | /* | |
206 | * function: zfcp_fsf_req_complete | |
207 | * | |
208 | * purpose: Updates active counts and timers for openfcp-reqs | |
209 | * May cleanup request after req_eval returns | |
210 | * | |
211 | * returns: 0 - success | |
212 | * !0 - failure | |
213 | * | |
214 | * context: | |
215 | */ | |
216 | int | |
217 | zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req) | |
218 | { | |
219 | int retval = 0; | |
220 | int cleanup; | |
1da177e4 LT |
221 | |
222 | if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) { | |
223 | ZFCP_LOG_DEBUG("Status read response received\n"); | |
224 | /* | |
225 | * Note: all cleanup handling is done in the callchain of | |
226 | * the function call-chain below. | |
227 | */ | |
228 | zfcp_fsf_status_read_handler(fsf_req); | |
229 | goto out; | |
230 | } else | |
231 | zfcp_fsf_protstatus_eval(fsf_req); | |
232 | ||
233 | /* | |
234 | * fsf_req may be deleted due to waking up functions, so | |
235 | * cleanup is saved here and used later | |
236 | */ | |
237 | if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP)) | |
238 | cleanup = 1; | |
239 | else | |
240 | cleanup = 0; | |
241 | ||
242 | fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED; | |
243 | ||
244 | /* cleanup request if requested by initiator */ | |
245 | if (likely(cleanup)) { | |
246 | ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req); | |
247 | /* | |
248 | * lock must not be held here since it will be | |
249 | * grabed by the called routine, too | |
250 | */ | |
1db2c9c0 | 251 | zfcp_fsf_req_free(fsf_req); |
1da177e4 LT |
252 | } else { |
253 | /* notify initiator waiting for the requests completion */ | |
254 | ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req); | |
255 | /* | |
256 | * FIXME: Race! We must not access fsf_req here as it might have been | |
257 | * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED | |
258 | * flag. It's an improbable case. But, we have the same paranoia for | |
259 | * the cleanup flag already. | |
260 | * Might better be handled using complete()? | |
261 | * (setting the flag and doing wakeup ought to be atomic | |
262 | * with regard to checking the flag as long as waitqueue is | |
263 | * part of the to be released structure) | |
264 | */ | |
265 | wake_up(&fsf_req->completion_wq); | |
266 | } | |
267 | ||
268 | out: | |
269 | return retval; | |
270 | } | |
271 | ||
272 | /* | |
273 | * function: zfcp_fsf_protstatus_eval | |
274 | * | |
275 | * purpose: evaluates the QTCB of the finished FSF request | |
276 | * and initiates appropriate actions | |
277 | * (usually calling FSF command specific handlers) | |
278 | * | |
279 | * returns: | |
280 | * | |
281 | * context: | |
282 | * | |
283 | * locks: | |
284 | */ | |
285 | static int | |
286 | zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req) | |
287 | { | |
288 | int retval = 0; | |
289 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
8a36e453 MS |
290 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
291 | union fsf_prot_status_qual *prot_status_qual = | |
292 | &qtcb->prefix.prot_status_qual; | |
1da177e4 | 293 | |
8a36e453 | 294 | zfcp_hba_dbf_event_fsf_response(fsf_req); |
1da177e4 LT |
295 | |
296 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { | |
297 | ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n", | |
298 | (unsigned long) fsf_req); | |
299 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | | |
300 | ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */ | |
1da177e4 LT |
301 | goto skip_protstatus; |
302 | } | |
303 | ||
304 | /* log additional information provided by FSF (if any) */ | |
8a36e453 | 305 | if (unlikely(qtcb->header.log_length)) { |
1da177e4 | 306 | /* do not trust them ;-) */ |
8a36e453 | 307 | if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) { |
1da177e4 LT |
308 | ZFCP_LOG_NORMAL |
309 | ("bug: ULP (FSF logging) log data starts " | |
310 | "beyond end of packet header. Ignored. " | |
311 | "(start=%i, size=%li)\n", | |
8a36e453 | 312 | qtcb->header.log_start, |
1da177e4 LT |
313 | sizeof(struct fsf_qtcb)); |
314 | goto forget_log; | |
315 | } | |
8a36e453 | 316 | if ((size_t) (qtcb->header.log_start + qtcb->header.log_length) |
1da177e4 LT |
317 | > sizeof(struct fsf_qtcb)) { |
318 | ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends " | |
319 | "beyond end of packet header. Ignored. " | |
320 | "(start=%i, length=%i, size=%li)\n", | |
8a36e453 MS |
321 | qtcb->header.log_start, |
322 | qtcb->header.log_length, | |
1da177e4 LT |
323 | sizeof(struct fsf_qtcb)); |
324 | goto forget_log; | |
325 | } | |
326 | ZFCP_LOG_TRACE("ULP log data: \n"); | |
327 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, | |
8a36e453 MS |
328 | (char *) qtcb + qtcb->header.log_start, |
329 | qtcb->header.log_length); | |
1da177e4 LT |
330 | } |
331 | forget_log: | |
332 | ||
333 | /* evaluate FSF Protocol Status */ | |
8a36e453 | 334 | switch (qtcb->prefix.prot_status) { |
1da177e4 LT |
335 | |
336 | case FSF_PROT_GOOD: | |
1da177e4 | 337 | case FSF_PROT_FSF_STATUS_PRESENTED: |
1da177e4 LT |
338 | break; |
339 | ||
340 | case FSF_PROT_QTCB_VERSION_ERROR: | |
1da177e4 LT |
341 | ZFCP_LOG_NORMAL("error: The adapter %s contains " |
342 | "microcode of version 0x%x, the device driver " | |
343 | "only supports 0x%x. Aborting.\n", | |
344 | zfcp_get_busid_by_adapter(adapter), | |
8a36e453 MS |
345 | prot_status_qual->version_error.fsf_version, |
346 | ZFCP_QTCB_VERSION); | |
1da177e4 | 347 | zfcp_erp_adapter_shutdown(adapter, 0); |
1da177e4 LT |
348 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
349 | break; | |
350 | ||
351 | case FSF_PROT_SEQ_NUMB_ERROR: | |
1da177e4 LT |
352 | ZFCP_LOG_NORMAL("bug: Sequence number mismatch between " |
353 | "driver (0x%x) and adapter %s (0x%x). " | |
354 | "Restarting all operations on this adapter.\n", | |
8a36e453 | 355 | qtcb->prefix.req_seq_no, |
1da177e4 | 356 | zfcp_get_busid_by_adapter(adapter), |
8a36e453 | 357 | prot_status_qual->sequence_error.exp_req_seq_no); |
1da177e4 | 358 | zfcp_erp_adapter_reopen(adapter, 0); |
1da177e4 LT |
359 | fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; |
360 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
361 | break; | |
362 | ||
363 | case FSF_PROT_UNSUPP_QTCB_TYPE: | |
1da177e4 LT |
364 | ZFCP_LOG_NORMAL("error: Packet header type used by the " |
365 | "device driver is incompatible with " | |
366 | "that used on adapter %s. " | |
367 | "Stopping all operations on this adapter.\n", | |
368 | zfcp_get_busid_by_adapter(adapter)); | |
1da177e4 | 369 | zfcp_erp_adapter_shutdown(adapter, 0); |
1da177e4 LT |
370 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
371 | break; | |
372 | ||
373 | case FSF_PROT_HOST_CONNECTION_INITIALIZING: | |
1da177e4 LT |
374 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
375 | atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT, | |
376 | &(adapter->status)); | |
1da177e4 LT |
377 | break; |
378 | ||
379 | case FSF_PROT_DUPLICATE_REQUEST_ID: | |
1da177e4 LT |
380 | ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx " |
381 | "to the adapter %s is ambiguous. " | |
aef4a983 MS |
382 | "Stopping all operations on this adapter.\n", |
383 | *(unsigned long long*) | |
384 | (&qtcb->bottom.support.req_handle), | |
1da177e4 | 385 | zfcp_get_busid_by_adapter(adapter)); |
1da177e4 | 386 | zfcp_erp_adapter_shutdown(adapter, 0); |
1da177e4 LT |
387 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
388 | break; | |
389 | ||
390 | case FSF_PROT_LINK_DOWN: | |
aef4a983 MS |
391 | zfcp_fsf_link_down_info_eval(adapter, |
392 | &prot_status_qual->link_down_info); | |
1da177e4 LT |
393 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
394 | break; | |
395 | ||
396 | case FSF_PROT_REEST_QUEUE: | |
8a36e453 | 397 | ZFCP_LOG_NORMAL("The local link to adapter with " |
1da177e4 LT |
398 | "%s was re-plugged. " |
399 | "Re-starting operations on this adapter.\n", | |
400 | zfcp_get_busid_by_adapter(adapter)); | |
401 | /* All ports should be marked as ready to run again */ | |
402 | zfcp_erp_modify_adapter_status(adapter, | |
403 | ZFCP_STATUS_COMMON_RUNNING, | |
404 | ZFCP_SET); | |
405 | zfcp_erp_adapter_reopen(adapter, | |
406 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
407 | | ZFCP_STATUS_COMMON_ERP_FAILED); | |
1da177e4 LT |
408 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
409 | break; | |
410 | ||
411 | case FSF_PROT_ERROR_STATE: | |
1da177e4 LT |
412 | ZFCP_LOG_NORMAL("error: The adapter %s " |
413 | "has entered the error state. " | |
414 | "Restarting all operations on this " | |
415 | "adapter.\n", | |
416 | zfcp_get_busid_by_adapter(adapter)); | |
1da177e4 | 417 | zfcp_erp_adapter_reopen(adapter, 0); |
1da177e4 LT |
418 | fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY; |
419 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
420 | break; | |
421 | ||
422 | default: | |
423 | ZFCP_LOG_NORMAL("bug: Transfer protocol status information " | |
424 | "provided by the adapter %s " | |
425 | "is not compatible with the device driver. " | |
426 | "Stopping all operations on this adapter. " | |
427 | "(debug info 0x%x).\n", | |
428 | zfcp_get_busid_by_adapter(adapter), | |
8a36e453 | 429 | qtcb->prefix.prot_status); |
1da177e4 LT |
430 | zfcp_erp_adapter_shutdown(adapter, 0); |
431 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
432 | } | |
433 | ||
434 | skip_protstatus: | |
435 | /* | |
436 | * always call specific handlers to give them a chance to do | |
437 | * something meaningful even in error cases | |
438 | */ | |
439 | zfcp_fsf_fsfstatus_eval(fsf_req); | |
440 | return retval; | |
441 | } | |
442 | ||
443 | /* | |
444 | * function: zfcp_fsf_fsfstatus_eval | |
445 | * | |
446 | * purpose: evaluates FSF status of completed FSF request | |
447 | * and acts accordingly | |
448 | * | |
449 | * returns: | |
450 | */ | |
451 | static int | |
452 | zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req) | |
453 | { | |
454 | int retval = 0; | |
455 | ||
456 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { | |
457 | goto skip_fsfstatus; | |
458 | } | |
459 | ||
460 | /* evaluate FSF Status */ | |
461 | switch (fsf_req->qtcb->header.fsf_status) { | |
462 | case FSF_UNKNOWN_COMMAND: | |
1da177e4 LT |
463 | ZFCP_LOG_NORMAL("bug: Command issued by the device driver is " |
464 | "not known by the adapter %s " | |
465 | "Stopping all operations on this adapter. " | |
466 | "(debug info 0x%x).\n", | |
467 | zfcp_get_busid_by_adapter(fsf_req->adapter), | |
468 | fsf_req->qtcb->header.fsf_command); | |
1da177e4 | 469 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0); |
1da177e4 LT |
470 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
471 | break; | |
472 | ||
473 | case FSF_FCP_RSP_AVAILABLE: | |
1da177e4 LT |
474 | ZFCP_LOG_DEBUG("FCP Sense data will be presented to the " |
475 | "SCSI stack.\n"); | |
1da177e4 LT |
476 | break; |
477 | ||
478 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
479 | zfcp_fsf_fsfstatus_qual_eval(fsf_req); |
480 | break; | |
1da177e4 LT |
481 | } |
482 | ||
483 | skip_fsfstatus: | |
484 | /* | |
485 | * always call specific handlers to give them a chance to do | |
486 | * something meaningful even in error cases | |
487 | */ | |
488 | zfcp_fsf_req_dispatch(fsf_req); | |
489 | ||
490 | return retval; | |
491 | } | |
492 | ||
493 | /* | |
494 | * function: zfcp_fsf_fsfstatus_qual_eval | |
495 | * | |
496 | * purpose: evaluates FSF status-qualifier of completed FSF request | |
497 | * and acts accordingly | |
498 | * | |
499 | * returns: | |
500 | */ | |
501 | static int | |
502 | zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req) | |
503 | { | |
504 | int retval = 0; | |
505 | ||
506 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { | |
507 | case FSF_SQ_FCP_RSP_AVAILABLE: | |
1da177e4 LT |
508 | break; |
509 | case FSF_SQ_RETRY_IF_POSSIBLE: | |
1da177e4 | 510 | /* The SCSI-stack may now issue retries or escalate */ |
1da177e4 LT |
511 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
512 | break; | |
513 | case FSF_SQ_COMMAND_ABORTED: | |
1da177e4 | 514 | /* Carry the aborted state on to upper layer */ |
1da177e4 LT |
515 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED; |
516 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
517 | break; | |
518 | case FSF_SQ_NO_RECOM: | |
1da177e4 LT |
519 | ZFCP_LOG_NORMAL("bug: No recommendation could be given for a" |
520 | "problem on the adapter %s " | |
521 | "Stopping all operations on this adapter. ", | |
522 | zfcp_get_busid_by_adapter(fsf_req->adapter)); | |
523 | zfcp_erp_adapter_shutdown(fsf_req->adapter, 0); | |
1da177e4 LT |
524 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
525 | break; | |
526 | case FSF_SQ_ULP_PROGRAMMING_ERROR: | |
1da177e4 LT |
527 | ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer " |
528 | "(adapter %s)\n", | |
529 | zfcp_get_busid_by_adapter(fsf_req->adapter)); | |
1da177e4 LT |
530 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
531 | break; | |
532 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
533 | case FSF_SQ_NO_RETRY_POSSIBLE: | |
534 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
535 | /* dealt with in the respective functions */ | |
536 | break; | |
537 | default: | |
538 | ZFCP_LOG_NORMAL("bug: Additional status info could " | |
539 | "not be interpreted properly.\n"); | |
540 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, | |
541 | (char *) &fsf_req->qtcb->header.fsf_status_qual, | |
542 | sizeof (union fsf_status_qual)); | |
1da177e4 LT |
543 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
544 | break; | |
545 | } | |
546 | ||
547 | return retval; | |
548 | } | |
549 | ||
aef4a983 MS |
550 | /** |
551 | * zfcp_fsf_link_down_info_eval - evaluate link down information block | |
552 | */ | |
553 | static void | |
554 | zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter, | |
555 | struct fsf_link_down_info *link_down) | |
556 | { | |
557 | switch (link_down->error_code) { | |
558 | case FSF_PSQ_LINK_NO_LIGHT: | |
559 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
560 | "(no light detected)\n", | |
561 | zfcp_get_busid_by_adapter(adapter)); | |
562 | break; | |
563 | case FSF_PSQ_LINK_WRAP_PLUG: | |
564 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
565 | "(wrap plug detected)\n", | |
566 | zfcp_get_busid_by_adapter(adapter)); | |
567 | break; | |
568 | case FSF_PSQ_LINK_NO_FCP: | |
569 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
570 | "(adjacent node on link does not support FCP)\n", | |
571 | zfcp_get_busid_by_adapter(adapter)); | |
572 | break; | |
573 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: | |
574 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
575 | "(firmware update in progress)\n", | |
576 | zfcp_get_busid_by_adapter(adapter)); | |
577 | break; | |
578 | case FSF_PSQ_LINK_INVALID_WWPN: | |
579 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
580 | "(duplicate or invalid WWPN detected)\n", | |
581 | zfcp_get_busid_by_adapter(adapter)); | |
582 | break; | |
583 | case FSF_PSQ_LINK_NO_NPIV_SUPPORT: | |
584 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
585 | "(no support for NPIV by Fabric)\n", | |
586 | zfcp_get_busid_by_adapter(adapter)); | |
587 | break; | |
588 | case FSF_PSQ_LINK_NO_FCP_RESOURCES: | |
589 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
590 | "(out of resource in FCP daughtercard)\n", | |
591 | zfcp_get_busid_by_adapter(adapter)); | |
592 | break; | |
593 | case FSF_PSQ_LINK_NO_FABRIC_RESOURCES: | |
594 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
595 | "(out of resource in Fabric)\n", | |
596 | zfcp_get_busid_by_adapter(adapter)); | |
597 | break; | |
598 | case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE: | |
599 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
600 | "(unable to Fabric login)\n", | |
601 | zfcp_get_busid_by_adapter(adapter)); | |
602 | break; | |
603 | case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED: | |
604 | ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n", | |
605 | zfcp_get_busid_by_adapter(adapter)); | |
606 | break; | |
607 | case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED: | |
608 | ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n", | |
609 | zfcp_get_busid_by_adapter(adapter)); | |
610 | break; | |
611 | case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT: | |
612 | ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n", | |
613 | zfcp_get_busid_by_adapter(adapter)); | |
614 | break; | |
615 | default: | |
616 | ZFCP_LOG_NORMAL("The local link to adapter %s is down " | |
617 | "(warning: unknown reason code %d)\n", | |
618 | zfcp_get_busid_by_adapter(adapter), | |
619 | link_down->error_code); | |
620 | } | |
621 | ||
622 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) | |
623 | ZFCP_LOG_DEBUG("Debug information to link down: " | |
624 | "primary_status=0x%02x " | |
625 | "ioerr_code=0x%02x " | |
626 | "action_code=0x%02x " | |
627 | "reason_code=0x%02x " | |
628 | "explanation_code=0x%02x " | |
629 | "vendor_specific_code=0x%02x\n", | |
630 | link_down->primary_status, | |
631 | link_down->ioerr_code, | |
632 | link_down->action_code, | |
633 | link_down->reason_code, | |
634 | link_down->explanation_code, | |
635 | link_down->vendor_specific_code); | |
636 | ||
637 | if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, | |
638 | &adapter->status)) { | |
639 | atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, | |
640 | &adapter->status); | |
641 | switch (link_down->error_code) { | |
642 | case FSF_PSQ_LINK_NO_LIGHT: | |
643 | case FSF_PSQ_LINK_WRAP_PLUG: | |
644 | case FSF_PSQ_LINK_NO_FCP: | |
645 | case FSF_PSQ_LINK_FIRMWARE_UPDATE: | |
646 | zfcp_erp_adapter_reopen(adapter, 0); | |
647 | break; | |
648 | default: | |
649 | zfcp_erp_adapter_failed(adapter); | |
650 | } | |
651 | } | |
652 | } | |
653 | ||
1da177e4 LT |
654 | /* |
655 | * function: zfcp_fsf_req_dispatch | |
656 | * | |
657 | * purpose: calls the appropriate command specific handler | |
658 | * | |
659 | * returns: | |
660 | */ | |
661 | static int | |
662 | zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req) | |
663 | { | |
664 | struct zfcp_erp_action *erp_action = fsf_req->erp_action; | |
665 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
666 | int retval = 0; | |
667 | ||
1da177e4 LT |
668 | |
669 | switch (fsf_req->fsf_command) { | |
670 | ||
671 | case FSF_QTCB_FCP_CMND: | |
1da177e4 LT |
672 | zfcp_fsf_send_fcp_command_handler(fsf_req); |
673 | break; | |
674 | ||
675 | case FSF_QTCB_ABORT_FCP_CMND: | |
1da177e4 LT |
676 | zfcp_fsf_abort_fcp_command_handler(fsf_req); |
677 | break; | |
678 | ||
679 | case FSF_QTCB_SEND_GENERIC: | |
1da177e4 LT |
680 | zfcp_fsf_send_ct_handler(fsf_req); |
681 | break; | |
682 | ||
683 | case FSF_QTCB_OPEN_PORT_WITH_DID: | |
1da177e4 LT |
684 | zfcp_fsf_open_port_handler(fsf_req); |
685 | break; | |
686 | ||
687 | case FSF_QTCB_OPEN_LUN: | |
1da177e4 LT |
688 | zfcp_fsf_open_unit_handler(fsf_req); |
689 | break; | |
690 | ||
691 | case FSF_QTCB_CLOSE_LUN: | |
1da177e4 LT |
692 | zfcp_fsf_close_unit_handler(fsf_req); |
693 | break; | |
694 | ||
695 | case FSF_QTCB_CLOSE_PORT: | |
1da177e4 LT |
696 | zfcp_fsf_close_port_handler(fsf_req); |
697 | break; | |
698 | ||
699 | case FSF_QTCB_CLOSE_PHYSICAL_PORT: | |
1da177e4 LT |
700 | zfcp_fsf_close_physical_port_handler(fsf_req); |
701 | break; | |
702 | ||
703 | case FSF_QTCB_EXCHANGE_CONFIG_DATA: | |
1da177e4 LT |
704 | zfcp_fsf_exchange_config_data_handler(fsf_req); |
705 | break; | |
706 | ||
707 | case FSF_QTCB_EXCHANGE_PORT_DATA: | |
1da177e4 LT |
708 | zfcp_fsf_exchange_port_data_handler(fsf_req); |
709 | break; | |
710 | ||
711 | case FSF_QTCB_SEND_ELS: | |
1da177e4 LT |
712 | zfcp_fsf_send_els_handler(fsf_req); |
713 | break; | |
714 | ||
715 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | |
1da177e4 LT |
716 | zfcp_fsf_control_file_handler(fsf_req); |
717 | break; | |
718 | ||
719 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | |
1da177e4 LT |
720 | zfcp_fsf_control_file_handler(fsf_req); |
721 | break; | |
722 | ||
723 | default: | |
1da177e4 LT |
724 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
725 | ZFCP_LOG_NORMAL("bug: Command issued by the device driver is " | |
726 | "not supported by the adapter %s\n", | |
8a36e453 | 727 | zfcp_get_busid_by_adapter(adapter)); |
1da177e4 LT |
728 | if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command) |
729 | ZFCP_LOG_NORMAL | |
730 | ("bug: Command issued by the device driver differs " | |
731 | "from the command returned by the adapter %s " | |
732 | "(debug info 0x%x, 0x%x).\n", | |
8a36e453 | 733 | zfcp_get_busid_by_adapter(adapter), |
1da177e4 LT |
734 | fsf_req->fsf_command, |
735 | fsf_req->qtcb->header.fsf_command); | |
736 | } | |
737 | ||
738 | if (!erp_action) | |
739 | return retval; | |
740 | ||
1da177e4 LT |
741 | zfcp_erp_async_handler(erp_action, 0); |
742 | ||
743 | return retval; | |
744 | } | |
745 | ||
746 | /* | |
747 | * function: zfcp_fsf_status_read | |
748 | * | |
749 | * purpose: initiates a Status Read command at the specified adapter | |
750 | * | |
751 | * returns: | |
752 | */ | |
753 | int | |
754 | zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags) | |
755 | { | |
756 | struct zfcp_fsf_req *fsf_req; | |
757 | struct fsf_status_read_buffer *status_buffer; | |
758 | unsigned long lock_flags; | |
759 | volatile struct qdio_buffer_element *sbale; | |
760 | int retval = 0; | |
761 | ||
762 | /* setup new FSF request */ | |
763 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS, | |
764 | req_flags | ZFCP_REQ_NO_QTCB, | |
765 | adapter->pool.fsf_req_status_read, | |
766 | &lock_flags, &fsf_req); | |
767 | if (retval < 0) { | |
768 | ZFCP_LOG_INFO("error: Could not create unsolicited status " | |
769 | "buffer for adapter %s.\n", | |
770 | zfcp_get_busid_by_adapter(adapter)); | |
771 | goto failed_req_create; | |
772 | } | |
773 | ||
774 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
775 | sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS; | |
776 | sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY; | |
777 | fsf_req->sbale_curr = 2; | |
778 | ||
779 | status_buffer = | |
780 | mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC); | |
781 | if (!status_buffer) { | |
782 | ZFCP_LOG_NORMAL("bug: could not get some buffer\n"); | |
783 | goto failed_buf; | |
784 | } | |
785 | memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer)); | |
059c97d0 | 786 | fsf_req->data = (unsigned long) status_buffer; |
1da177e4 LT |
787 | |
788 | /* insert pointer to respective buffer */ | |
789 | sbale = zfcp_qdio_sbale_curr(fsf_req); | |
790 | sbale->addr = (void *) status_buffer; | |
791 | sbale->length = sizeof(struct fsf_status_read_buffer); | |
792 | ||
793 | /* start QDIO request for this FSF request */ | |
794 | retval = zfcp_fsf_req_send(fsf_req, NULL); | |
795 | if (retval) { | |
796 | ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status " | |
797 | "environment.\n"); | |
798 | goto failed_req_send; | |
799 | } | |
800 | ||
801 | ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n", | |
802 | zfcp_get_busid_by_adapter(adapter)); | |
803 | goto out; | |
804 | ||
805 | failed_req_send: | |
806 | mempool_free(status_buffer, adapter->pool.data_status_read); | |
807 | ||
808 | failed_buf: | |
809 | zfcp_fsf_req_free(fsf_req); | |
810 | failed_req_create: | |
8a36e453 | 811 | zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL); |
1da177e4 LT |
812 | out: |
813 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
814 | return retval; | |
815 | } | |
816 | ||
817 | static int | |
818 | zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req) | |
819 | { | |
820 | struct fsf_status_read_buffer *status_buffer; | |
821 | struct zfcp_adapter *adapter; | |
822 | struct zfcp_port *port; | |
823 | unsigned long flags; | |
824 | ||
059c97d0 | 825 | status_buffer = (struct fsf_status_read_buffer *) fsf_req->data; |
1da177e4 LT |
826 | adapter = fsf_req->adapter; |
827 | ||
828 | read_lock_irqsave(&zfcp_data.config_lock, flags); | |
829 | list_for_each_entry(port, &adapter->port_list_head, list) | |
830 | if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK)) | |
831 | break; | |
832 | read_unlock_irqrestore(&zfcp_data.config_lock, flags); | |
833 | ||
834 | if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) { | |
835 | ZFCP_LOG_NORMAL("bug: Reopen port indication received for" | |
836 | "nonexisting port with d_id 0x%08x on " | |
837 | "adapter %s. Ignored.\n", | |
838 | status_buffer->d_id & ZFCP_DID_MASK, | |
839 | zfcp_get_busid_by_adapter(adapter)); | |
840 | goto out; | |
841 | } | |
842 | ||
843 | switch (status_buffer->status_subtype) { | |
844 | ||
845 | case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT: | |
1da177e4 LT |
846 | debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:"); |
847 | zfcp_erp_port_reopen(port, 0); | |
848 | break; | |
849 | ||
850 | case FSF_STATUS_READ_SUB_ERROR_PORT: | |
1da177e4 LT |
851 | debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:"); |
852 | zfcp_erp_port_shutdown(port, 0); | |
853 | break; | |
854 | ||
855 | default: | |
856 | debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:"); | |
857 | debug_exception(adapter->erp_dbf, 0, | |
858 | &status_buffer->status_subtype, sizeof (u32)); | |
859 | ZFCP_LOG_NORMAL("bug: Undefined status subtype received " | |
860 | "for a reopen indication on port with " | |
861 | "d_id 0x%08x on the adapter %s. " | |
862 | "Ignored. (debug info 0x%x)\n", | |
863 | status_buffer->d_id, | |
864 | zfcp_get_busid_by_adapter(adapter), | |
865 | status_buffer->status_subtype); | |
866 | } | |
867 | out: | |
868 | return 0; | |
869 | } | |
870 | ||
871 | /* | |
872 | * function: zfcp_fsf_status_read_handler | |
873 | * | |
874 | * purpose: is called for finished Open Port command | |
875 | * | |
876 | * returns: | |
877 | */ | |
878 | static int | |
879 | zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req) | |
880 | { | |
881 | int retval = 0; | |
882 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
883 | struct fsf_status_read_buffer *status_buffer = | |
059c97d0 | 884 | (struct fsf_status_read_buffer *) fsf_req->data; |
1da177e4 LT |
885 | |
886 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) { | |
8a36e453 | 887 | zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer); |
1da177e4 | 888 | mempool_free(status_buffer, adapter->pool.data_status_read); |
1db2c9c0 | 889 | zfcp_fsf_req_free(fsf_req); |
1da177e4 LT |
890 | goto out; |
891 | } | |
892 | ||
8a36e453 MS |
893 | zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer); |
894 | ||
1da177e4 LT |
895 | switch (status_buffer->status_type) { |
896 | ||
897 | case FSF_STATUS_READ_PORT_CLOSED: | |
1da177e4 LT |
898 | zfcp_fsf_status_read_port_closed(fsf_req); |
899 | break; | |
900 | ||
901 | case FSF_STATUS_READ_INCOMING_ELS: | |
1da177e4 LT |
902 | zfcp_fsf_incoming_els(fsf_req); |
903 | break; | |
904 | ||
905 | case FSF_STATUS_READ_SENSE_DATA_AVAIL: | |
1da177e4 LT |
906 | ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n", |
907 | zfcp_get_busid_by_adapter(adapter)); | |
1da177e4 LT |
908 | break; |
909 | ||
910 | case FSF_STATUS_READ_BIT_ERROR_THRESHOLD: | |
1da177e4 LT |
911 | ZFCP_LOG_NORMAL("Bit error threshold data received:\n"); |
912 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, | |
913 | (char *) status_buffer, | |
914 | sizeof (struct fsf_status_read_buffer)); | |
915 | break; | |
916 | ||
917 | case FSF_STATUS_READ_LINK_DOWN: | |
aef4a983 MS |
918 | switch (status_buffer->status_subtype) { |
919 | case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK: | |
920 | ZFCP_LOG_INFO("Physical link to adapter %s is down\n", | |
921 | zfcp_get_busid_by_adapter(adapter)); | |
922 | break; | |
923 | case FSF_STATUS_READ_SUB_FDISC_FAILED: | |
924 | ZFCP_LOG_INFO("Local link to adapter %s is down " | |
925 | "due to failed FDISC login\n", | |
1da177e4 | 926 | zfcp_get_busid_by_adapter(adapter)); |
aef4a983 MS |
927 | break; |
928 | case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE: | |
929 | ZFCP_LOG_INFO("Local link to adapter %s is down " | |
930 | "due to firmware update on adapter\n", | |
931 | zfcp_get_busid_by_adapter(adapter)); | |
932 | break; | |
933 | default: | |
934 | ZFCP_LOG_INFO("Local link to adapter %s is down " | |
935 | "due to unknown reason\n", | |
936 | zfcp_get_busid_by_adapter(adapter)); | |
937 | }; | |
938 | zfcp_fsf_link_down_info_eval(adapter, | |
939 | (struct fsf_link_down_info *) &status_buffer->payload); | |
1da177e4 LT |
940 | break; |
941 | ||
942 | case FSF_STATUS_READ_LINK_UP: | |
aef4a983 | 943 | ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. " |
1da177e4 LT |
944 | "Restarting operations on this adapter\n", |
945 | zfcp_get_busid_by_adapter(adapter)); | |
946 | /* All ports should be marked as ready to run again */ | |
947 | zfcp_erp_modify_adapter_status(adapter, | |
948 | ZFCP_STATUS_COMMON_RUNNING, | |
949 | ZFCP_SET); | |
950 | zfcp_erp_adapter_reopen(adapter, | |
951 | ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED | |
952 | | ZFCP_STATUS_COMMON_ERP_FAILED); | |
953 | break; | |
954 | ||
955 | case FSF_STATUS_READ_CFDC_UPDATED: | |
8a36e453 | 956 | ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n", |
1da177e4 LT |
957 | zfcp_get_busid_by_adapter(adapter)); |
958 | zfcp_erp_adapter_access_changed(adapter); | |
959 | break; | |
960 | ||
961 | case FSF_STATUS_READ_CFDC_HARDENED: | |
1da177e4 LT |
962 | switch (status_buffer->status_subtype) { |
963 | case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE: | |
8a36e453 | 964 | ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n", |
1da177e4 LT |
965 | zfcp_get_busid_by_adapter(adapter)); |
966 | break; | |
967 | case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2: | |
8a36e453 | 968 | ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied " |
1da177e4 LT |
969 | "to the secondary SE\n", |
970 | zfcp_get_busid_by_adapter(adapter)); | |
971 | break; | |
972 | default: | |
8a36e453 | 973 | ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n", |
1da177e4 LT |
974 | zfcp_get_busid_by_adapter(adapter)); |
975 | } | |
976 | break; | |
977 | ||
aef4a983 MS |
978 | case FSF_STATUS_READ_FEATURE_UPDATE_ALERT: |
979 | debug_text_event(adapter->erp_dbf, 2, "unsol_features:"); | |
980 | ZFCP_LOG_INFO("List of supported features on adapter %s has " | |
981 | "been changed from 0x%08X to 0x%08X\n", | |
982 | zfcp_get_busid_by_adapter(adapter), | |
983 | *(u32*) (status_buffer->payload + 4), | |
984 | *(u32*) (status_buffer->payload)); | |
985 | adapter->adapter_features = *(u32*) status_buffer->payload; | |
986 | break; | |
987 | ||
1da177e4 | 988 | default: |
8a36e453 | 989 | ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown " |
1da177e4 LT |
990 | "type was received (debug info 0x%x)\n", |
991 | status_buffer->status_type); | |
992 | ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n", | |
993 | status_buffer); | |
994 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
995 | (char *) status_buffer, | |
996 | sizeof (struct fsf_status_read_buffer)); | |
997 | break; | |
998 | } | |
999 | mempool_free(status_buffer, adapter->pool.data_status_read); | |
1db2c9c0 | 1000 | zfcp_fsf_req_free(fsf_req); |
1da177e4 LT |
1001 | /* |
1002 | * recycle buffer and start new request repeat until outbound | |
1003 | * queue is empty or adapter shutdown is requested | |
1004 | */ | |
1005 | /* | |
1006 | * FIXME(qdio): | |
1007 | * we may wait in the req_create for 5s during shutdown, so | |
1008 | * qdio_cleanup will have to wait at least that long before returning | |
1009 | * with failure to allow us a proper cleanup under all circumstances | |
1010 | */ | |
1011 | /* | |
1012 | * FIXME: | |
1013 | * allocation failure possible? (Is this code needed?) | |
1014 | */ | |
1015 | retval = zfcp_fsf_status_read(adapter, 0); | |
1016 | if (retval < 0) { | |
1017 | ZFCP_LOG_INFO("Failed to create unsolicited status read " | |
1018 | "request for the adapter %s.\n", | |
1019 | zfcp_get_busid_by_adapter(adapter)); | |
1020 | /* temporary fix to avoid status read buffer shortage */ | |
1021 | adapter->status_read_failed++; | |
1022 | if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed) | |
1023 | < ZFCP_STATUS_READ_FAILED_THRESHOLD) { | |
1024 | ZFCP_LOG_INFO("restart adapter %s due to status read " | |
1025 | "buffer shortage\n", | |
1026 | zfcp_get_busid_by_adapter(adapter)); | |
1027 | zfcp_erp_adapter_reopen(adapter, 0); | |
1028 | } | |
1029 | } | |
1030 | out: | |
1031 | return retval; | |
1032 | } | |
1033 | ||
1034 | /* | |
1035 | * function: zfcp_fsf_abort_fcp_command | |
1036 | * | |
1037 | * purpose: tells FSF to abort a running SCSI command | |
1038 | * | |
1039 | * returns: address of initiated FSF request | |
1040 | * NULL - request could not be initiated | |
1041 | * | |
1042 | * FIXME(design): should be watched by a timeout !!! | |
1043 | * FIXME(design) shouldn't this be modified to return an int | |
1044 | * also...don't know how though | |
1045 | */ | |
1046 | struct zfcp_fsf_req * | |
1047 | zfcp_fsf_abort_fcp_command(unsigned long old_req_id, | |
1048 | struct zfcp_adapter *adapter, | |
1049 | struct zfcp_unit *unit, int req_flags) | |
1050 | { | |
1051 | volatile struct qdio_buffer_element *sbale; | |
1052 | unsigned long lock_flags; | |
1053 | struct zfcp_fsf_req *fsf_req = NULL; | |
1054 | int retval = 0; | |
1055 | ||
1056 | /* setup new FSF request */ | |
1057 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND, | |
1058 | req_flags, adapter->pool.fsf_req_abort, | |
1059 | &lock_flags, &fsf_req); | |
1060 | if (retval < 0) { | |
1061 | ZFCP_LOG_INFO("error: Failed to create an abort command " | |
1062 | "request for lun 0x%016Lx on port 0x%016Lx " | |
1063 | "on adapter %s.\n", | |
1064 | unit->fcp_lun, | |
1065 | unit->port->wwpn, | |
1066 | zfcp_get_busid_by_adapter(adapter)); | |
1067 | goto out; | |
1068 | } | |
1069 | ||
1070 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
1071 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1072 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1073 | ||
059c97d0 | 1074 | fsf_req->data = (unsigned long) unit; |
1da177e4 LT |
1075 | |
1076 | /* set handles of unit and its parent port in QTCB */ | |
1077 | fsf_req->qtcb->header.lun_handle = unit->handle; | |
1078 | fsf_req->qtcb->header.port_handle = unit->port->handle; | |
1079 | ||
1080 | /* set handle of request which should be aborted */ | |
1081 | fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id; | |
1082 | ||
1083 | /* start QDIO request for this FSF request */ | |
1084 | ||
1085 | zfcp_fsf_start_scsi_er_timer(adapter); | |
1086 | retval = zfcp_fsf_req_send(fsf_req, NULL); | |
1087 | if (retval) { | |
1088 | del_timer(&adapter->scsi_er_timer); | |
1089 | ZFCP_LOG_INFO("error: Failed to send abort command request " | |
1090 | "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n", | |
1091 | zfcp_get_busid_by_adapter(adapter), | |
1092 | unit->port->wwpn, unit->fcp_lun); | |
1093 | zfcp_fsf_req_free(fsf_req); | |
1094 | fsf_req = NULL; | |
1095 | goto out; | |
1096 | } | |
1097 | ||
1098 | ZFCP_LOG_DEBUG("Abort FCP Command request initiated " | |
1099 | "(adapter%s, port d_id=0x%08x, " | |
1100 | "unit x%016Lx, old_req_id=0x%lx)\n", | |
1101 | zfcp_get_busid_by_adapter(adapter), | |
1102 | unit->port->d_id, | |
1103 | unit->fcp_lun, old_req_id); | |
1104 | out: | |
1105 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
1106 | return fsf_req; | |
1107 | } | |
1108 | ||
1109 | /* | |
1110 | * function: zfcp_fsf_abort_fcp_command_handler | |
1111 | * | |
1112 | * purpose: is called for finished Abort FCP Command request | |
1113 | * | |
1114 | * returns: | |
1115 | */ | |
1116 | static int | |
1117 | zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req) | |
1118 | { | |
1119 | int retval = -EINVAL; | |
059c97d0 | 1120 | struct zfcp_unit *unit; |
1da177e4 LT |
1121 | unsigned char status_qual = |
1122 | new_fsf_req->qtcb->header.fsf_status_qual.word[0]; | |
1123 | ||
1124 | del_timer(&new_fsf_req->adapter->scsi_er_timer); | |
1125 | ||
1126 | if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
1127 | /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */ | |
1128 | goto skip_fsfstatus; | |
1129 | } | |
1130 | ||
059c97d0 AH |
1131 | unit = (struct zfcp_unit *) new_fsf_req->data; |
1132 | ||
1da177e4 LT |
1133 | /* evaluate FSF status in QTCB */ |
1134 | switch (new_fsf_req->qtcb->header.fsf_status) { | |
1135 | ||
1136 | case FSF_PORT_HANDLE_NOT_VALID: | |
1137 | if (status_qual >> 4 != status_qual % 0xf) { | |
1da177e4 LT |
1138 | debug_text_event(new_fsf_req->adapter->erp_dbf, 3, |
1139 | "fsf_s_phand_nv0"); | |
1140 | /* | |
1141 | * In this case a command that was sent prior to a port | |
1142 | * reopen was aborted (handles are different). This is | |
1143 | * fine. | |
1144 | */ | |
1145 | } else { | |
1da177e4 LT |
1146 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for " |
1147 | "port 0x%016Lx on adapter %s invalid. " | |
1148 | "This may happen occasionally.\n", | |
1149 | unit->port->handle, | |
1150 | unit->port->wwpn, | |
1151 | zfcp_get_busid_by_unit(unit)); | |
1152 | ZFCP_LOG_INFO("status qualifier:\n"); | |
1153 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, | |
1154 | (char *) &new_fsf_req->qtcb->header. | |
1155 | fsf_status_qual, | |
1156 | sizeof (union fsf_status_qual)); | |
1157 | /* Let's hope this sorts out the mess */ | |
1158 | debug_text_event(new_fsf_req->adapter->erp_dbf, 1, | |
1159 | "fsf_s_phand_nv1"); | |
1160 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); | |
1161 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1162 | } | |
1163 | break; | |
1164 | ||
1165 | case FSF_LUN_HANDLE_NOT_VALID: | |
1166 | if (status_qual >> 4 != status_qual % 0xf) { | |
1167 | /* 2 */ | |
1da177e4 LT |
1168 | debug_text_event(new_fsf_req->adapter->erp_dbf, 3, |
1169 | "fsf_s_lhand_nv0"); | |
1170 | /* | |
1171 | * In this case a command that was sent prior to a unit | |
1172 | * reopen was aborted (handles are different). | |
1173 | * This is fine. | |
1174 | */ | |
1175 | } else { | |
1da177e4 LT |
1176 | ZFCP_LOG_INFO |
1177 | ("Warning: Temporary LUN identifier 0x%x of LUN " | |
1178 | "0x%016Lx on port 0x%016Lx on adapter %s is " | |
1179 | "invalid. This may happen in rare cases. " | |
1180 | "Trying to re-establish link.\n", | |
1181 | unit->handle, | |
1182 | unit->fcp_lun, | |
1183 | unit->port->wwpn, | |
1184 | zfcp_get_busid_by_unit(unit)); | |
1185 | ZFCP_LOG_DEBUG("Status qualifier data:\n"); | |
1186 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
1187 | (char *) &new_fsf_req->qtcb->header. | |
1188 | fsf_status_qual, | |
1189 | sizeof (union fsf_status_qual)); | |
1190 | /* Let's hope this sorts out the mess */ | |
1191 | debug_text_event(new_fsf_req->adapter->erp_dbf, 1, | |
1192 | "fsf_s_lhand_nv1"); | |
1193 | zfcp_erp_port_reopen(unit->port, 0); | |
1194 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1195 | } | |
1196 | break; | |
1197 | ||
1198 | case FSF_FCP_COMMAND_DOES_NOT_EXIST: | |
1da177e4 LT |
1199 | retval = 0; |
1200 | debug_text_event(new_fsf_req->adapter->erp_dbf, 3, | |
1201 | "fsf_s_no_exist"); | |
1202 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED; | |
1203 | break; | |
1204 | ||
1205 | case FSF_PORT_BOXED: | |
1da177e4 LT |
1206 | ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to " |
1207 | "be reopened\n", unit->port->wwpn, | |
1208 | zfcp_get_busid_by_unit(unit)); | |
1209 | debug_text_event(new_fsf_req->adapter->erp_dbf, 2, | |
1210 | "fsf_s_pboxed"); | |
d736a27b | 1211 | zfcp_erp_port_boxed(unit->port); |
1da177e4 LT |
1212 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1213 | | ZFCP_STATUS_FSFREQ_RETRY; | |
1214 | break; | |
1215 | ||
1216 | case FSF_LUN_BOXED: | |
1da177e4 LT |
1217 | ZFCP_LOG_INFO( |
1218 | "unit 0x%016Lx on port 0x%016Lx on adapter %s needs " | |
1219 | "to be reopened\n", | |
1220 | unit->fcp_lun, unit->port->wwpn, | |
1221 | zfcp_get_busid_by_unit(unit)); | |
1222 | debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed"); | |
d736a27b | 1223 | zfcp_erp_unit_boxed(unit); |
1da177e4 LT |
1224 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1225 | | ZFCP_STATUS_FSFREQ_RETRY; | |
1226 | break; | |
1227 | ||
1228 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
1229 | switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
1230 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
1231 | debug_text_event(new_fsf_req->adapter->erp_dbf, 1, |
1232 | "fsf_sq_ltest"); | |
65a8d4e1 | 1233 | zfcp_test_link(unit->port); |
1da177e4 LT |
1234 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1235 | break; | |
1236 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
1237 | /* SCSI stack will escalate */ |
1238 | debug_text_event(new_fsf_req->adapter->erp_dbf, 1, | |
1239 | "fsf_sq_ulp"); | |
1240 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1241 | break; | |
1242 | default: | |
1243 | ZFCP_LOG_NORMAL | |
1244 | ("bug: Wrong status qualifier 0x%x arrived.\n", | |
1245 | new_fsf_req->qtcb->header.fsf_status_qual.word[0]); | |
1246 | debug_text_event(new_fsf_req->adapter->erp_dbf, 0, | |
1247 | "fsf_sq_inval:"); | |
1248 | debug_exception(new_fsf_req->adapter->erp_dbf, 0, | |
1249 | &new_fsf_req->qtcb->header. | |
1250 | fsf_status_qual.word[0], sizeof (u32)); | |
1251 | break; | |
1252 | } | |
1253 | break; | |
1254 | ||
1255 | case FSF_GOOD: | |
1da177e4 LT |
1256 | retval = 0; |
1257 | new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED; | |
1258 | break; | |
1259 | ||
1260 | default: | |
1261 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
1262 | "(debug info 0x%x)\n", | |
1263 | new_fsf_req->qtcb->header.fsf_status); | |
1264 | debug_text_event(new_fsf_req->adapter->erp_dbf, 0, | |
1265 | "fsf_s_inval:"); | |
1266 | debug_exception(new_fsf_req->adapter->erp_dbf, 0, | |
1267 | &new_fsf_req->qtcb->header.fsf_status, | |
1268 | sizeof (u32)); | |
1269 | break; | |
1270 | } | |
1271 | skip_fsfstatus: | |
1272 | return retval; | |
1273 | } | |
1274 | ||
1275 | /** | |
1276 | * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into | |
1277 | * one SBALE | |
1278 | * Two scatter-gather lists are passed, one for the reqeust and one for the | |
1279 | * response. | |
1280 | */ | |
1281 | static inline int | |
1282 | zfcp_use_one_sbal(struct scatterlist *req, int req_count, | |
1283 | struct scatterlist *resp, int resp_count) | |
1284 | { | |
1285 | return ((req_count == 1) && | |
1286 | (resp_count == 1) && | |
1287 | (((unsigned long) zfcp_sg_to_address(&req[0]) & | |
1288 | PAGE_MASK) == | |
1289 | ((unsigned long) (zfcp_sg_to_address(&req[0]) + | |
1290 | req[0].length - 1) & PAGE_MASK)) && | |
1291 | (((unsigned long) zfcp_sg_to_address(&resp[0]) & | |
1292 | PAGE_MASK) == | |
1293 | ((unsigned long) (zfcp_sg_to_address(&resp[0]) + | |
1294 | resp[0].length - 1) & PAGE_MASK))); | |
1295 | } | |
1296 | ||
1297 | /** | |
1298 | * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS) | |
1299 | * @ct: pointer to struct zfcp_send_ct which conatins all needed data for | |
1300 | * the request | |
1301 | * @pool: pointer to memory pool, if non-null this pool is used to allocate | |
1302 | * a struct zfcp_fsf_req | |
1303 | * @erp_action: pointer to erp_action, if non-null the Generic Service request | |
1304 | * is sent within error recovery | |
1305 | */ | |
1306 | int | |
1307 | zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool, | |
1308 | struct zfcp_erp_action *erp_action) | |
1309 | { | |
1310 | volatile struct qdio_buffer_element *sbale; | |
1311 | struct zfcp_port *port; | |
1312 | struct zfcp_adapter *adapter; | |
1313 | struct zfcp_fsf_req *fsf_req; | |
1314 | unsigned long lock_flags; | |
1315 | int bytes; | |
1316 | int ret = 0; | |
1317 | ||
1318 | port = ct->port; | |
1319 | adapter = port->adapter; | |
1320 | ||
1321 | ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC, | |
1322 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
1323 | pool, &lock_flags, &fsf_req); | |
1324 | if (ret < 0) { | |
1325 | ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for " | |
1326 | "adapter: %s\n", | |
1327 | zfcp_get_busid_by_adapter(adapter)); | |
1328 | goto failed_req; | |
1329 | } | |
1330 | ||
1331 | if (erp_action != NULL) { | |
1332 | erp_action->fsf_req = fsf_req; | |
1333 | fsf_req->erp_action = erp_action; | |
1334 | } | |
1335 | ||
1336 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
1337 | if (zfcp_use_one_sbal(ct->req, ct->req_count, | |
1338 | ct->resp, ct->resp_count)){ | |
1339 | /* both request buffer and response buffer | |
1340 | fit into one sbale each */ | |
1341 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; | |
1342 | sbale[2].addr = zfcp_sg_to_address(&ct->req[0]); | |
1343 | sbale[2].length = ct->req[0].length; | |
1344 | sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]); | |
1345 | sbale[3].length = ct->resp[0].length; | |
1346 | sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY; | |
aef4a983 | 1347 | } else if (adapter->adapter_features & |
1da177e4 LT |
1348 | FSF_FEATURE_ELS_CT_CHAINED_SBALS) { |
1349 | /* try to use chained SBALs */ | |
1350 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, | |
1351 | SBAL_FLAGS0_TYPE_WRITE_READ, | |
1352 | ct->req, ct->req_count, | |
1353 | ZFCP_MAX_SBALS_PER_CT_REQ); | |
1354 | if (bytes <= 0) { | |
1355 | ZFCP_LOG_INFO("error: creation of CT request failed " | |
1356 | "on adapter %s\n", | |
1357 | zfcp_get_busid_by_adapter(adapter)); | |
1358 | if (bytes == 0) | |
1359 | ret = -ENOMEM; | |
1360 | else | |
1361 | ret = bytes; | |
1362 | ||
1363 | goto failed_send; | |
1364 | } | |
1365 | fsf_req->qtcb->bottom.support.req_buf_length = bytes; | |
1366 | fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; | |
1367 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, | |
1368 | SBAL_FLAGS0_TYPE_WRITE_READ, | |
1369 | ct->resp, ct->resp_count, | |
1370 | ZFCP_MAX_SBALS_PER_CT_REQ); | |
1371 | if (bytes <= 0) { | |
1372 | ZFCP_LOG_INFO("error: creation of CT request failed " | |
1373 | "on adapter %s\n", | |
1374 | zfcp_get_busid_by_adapter(adapter)); | |
1375 | if (bytes == 0) | |
1376 | ret = -ENOMEM; | |
1377 | else | |
1378 | ret = bytes; | |
1379 | ||
1380 | goto failed_send; | |
1381 | } | |
1382 | fsf_req->qtcb->bottom.support.resp_buf_length = bytes; | |
1383 | } else { | |
1384 | /* reject send generic request */ | |
1385 | ZFCP_LOG_INFO( | |
1386 | "error: microcode does not support chained SBALs," | |
1387 | "CT request too big (adapter %s)\n", | |
1388 | zfcp_get_busid_by_adapter(adapter)); | |
1389 | ret = -EOPNOTSUPP; | |
1390 | goto failed_send; | |
1391 | } | |
1392 | ||
1393 | /* settings in QTCB */ | |
1394 | fsf_req->qtcb->header.port_handle = port->handle; | |
1395 | fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class; | |
1396 | fsf_req->qtcb->bottom.support.timeout = ct->timeout; | |
059c97d0 | 1397 | fsf_req->data = (unsigned long) ct; |
1da177e4 | 1398 | |
8a36e453 MS |
1399 | zfcp_san_dbf_event_ct_request(fsf_req); |
1400 | ||
1da177e4 LT |
1401 | /* start QDIO request for this FSF request */ |
1402 | ret = zfcp_fsf_req_send(fsf_req, ct->timer); | |
1403 | if (ret) { | |
1404 | ZFCP_LOG_DEBUG("error: initiation of CT request failed " | |
1405 | "(adapter %s, port 0x%016Lx)\n", | |
1406 | zfcp_get_busid_by_adapter(adapter), port->wwpn); | |
1407 | goto failed_send; | |
1408 | } | |
1409 | ||
1410 | ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n", | |
1411 | zfcp_get_busid_by_adapter(adapter), port->wwpn); | |
1412 | goto out; | |
1413 | ||
1414 | failed_send: | |
1415 | zfcp_fsf_req_free(fsf_req); | |
1416 | if (erp_action != NULL) { | |
1417 | erp_action->fsf_req = NULL; | |
1418 | } | |
1419 | failed_req: | |
1420 | out: | |
1421 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, | |
1422 | lock_flags); | |
1423 | return ret; | |
1424 | } | |
1425 | ||
1426 | /** | |
1427 | * zfcp_fsf_send_ct_handler - handler for Generic Service requests | |
1428 | * @fsf_req: pointer to struct zfcp_fsf_req | |
1429 | * | |
059c97d0 AH |
1430 | * Data specific for the Generic Service request is passed using |
1431 | * fsf_req->data. There we find the pointer to struct zfcp_send_ct. | |
1432 | * Usually a specific handler for the CT request is called which is | |
1433 | * found in this structure. | |
1da177e4 LT |
1434 | */ |
1435 | static int | |
1436 | zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req) | |
1437 | { | |
1438 | struct zfcp_port *port; | |
1439 | struct zfcp_adapter *adapter; | |
1440 | struct zfcp_send_ct *send_ct; | |
1441 | struct fsf_qtcb_header *header; | |
1442 | struct fsf_qtcb_bottom_support *bottom; | |
1443 | int retval = -EINVAL; | |
1444 | u16 subtable, rule, counter; | |
1445 | ||
1446 | adapter = fsf_req->adapter; | |
059c97d0 | 1447 | send_ct = (struct zfcp_send_ct *) fsf_req->data; |
1da177e4 LT |
1448 | port = send_ct->port; |
1449 | header = &fsf_req->qtcb->header; | |
1450 | bottom = &fsf_req->qtcb->bottom.support; | |
1451 | ||
1452 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
1453 | goto skip_fsfstatus; | |
1454 | ||
1455 | /* evaluate FSF status in QTCB */ | |
1456 | switch (header->fsf_status) { | |
1457 | ||
1458 | case FSF_GOOD: | |
8a36e453 | 1459 | zfcp_san_dbf_event_ct_response(fsf_req); |
1da177e4 LT |
1460 | retval = 0; |
1461 | break; | |
1462 | ||
1463 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | |
1da177e4 LT |
1464 | if (adapter->fc_service_class <= 3) { |
1465 | ZFCP_LOG_INFO("error: adapter %s does not support fc " | |
1466 | "class %d.\n", | |
1467 | zfcp_get_busid_by_port(port), | |
1468 | adapter->fc_service_class); | |
1469 | } else { | |
1470 | ZFCP_LOG_INFO("bug: The fibre channel class at the " | |
1471 | "adapter %s is invalid. " | |
1472 | "(debug info %d)\n", | |
1473 | zfcp_get_busid_by_port(port), | |
1474 | adapter->fc_service_class); | |
1475 | } | |
1476 | /* stop operation for this adapter */ | |
1477 | debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup"); | |
1478 | zfcp_erp_adapter_shutdown(adapter, 0); | |
1479 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1480 | break; | |
1481 | ||
1482 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
1483 | switch (header->fsf_status_qual.word[0]){ |
1484 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
1485 | /* reopening link to port */ |
1486 | debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest"); | |
1487 | zfcp_test_link(port); | |
1488 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1489 | break; | |
1490 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
1491 | /* ERP strategy will escalate */ |
1492 | debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp"); | |
1493 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1494 | break; | |
1495 | default: | |
1496 | ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x " | |
1497 | "arrived.\n", | |
1498 | header->fsf_status_qual.word[0]); | |
1499 | break; | |
1500 | } | |
1501 | break; | |
1502 | ||
1503 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
1504 | ZFCP_LOG_NORMAL("access denied, cannot send generic service " |
1505 | "command (adapter %s, port d_id=0x%08x)\n", | |
1506 | zfcp_get_busid_by_port(port), port->d_id); | |
1507 | for (counter = 0; counter < 2; counter++) { | |
1508 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
1509 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
1510 | switch (subtable) { | |
1511 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
1512 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
1513 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
1514 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
1515 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
1516 | zfcp_act_subtable_type[subtable], rule); | |
1517 | break; | |
1518 | } | |
1519 | } | |
1520 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_access"); | |
1521 | zfcp_erp_port_access_denied(port); | |
1522 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1523 | break; | |
1524 | ||
1525 | case FSF_GENERIC_COMMAND_REJECTED: | |
1da177e4 LT |
1526 | ZFCP_LOG_INFO("generic service command rejected " |
1527 | "(adapter %s, port d_id=0x%08x)\n", | |
1528 | zfcp_get_busid_by_port(port), port->d_id); | |
1529 | ZFCP_LOG_INFO("status qualifier:\n"); | |
1530 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, | |
1531 | (char *) &header->fsf_status_qual, | |
1532 | sizeof (union fsf_status_qual)); | |
1533 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej"); | |
1534 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1535 | break; | |
1536 | ||
1537 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
1538 | ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port " |
1539 | "0x%016Lx on adapter %s invalid. This may " | |
1540 | "happen occasionally.\n", port->handle, | |
1541 | port->wwpn, zfcp_get_busid_by_port(port)); | |
1542 | ZFCP_LOG_INFO("status qualifier:\n"); | |
1543 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, | |
1544 | (char *) &header->fsf_status_qual, | |
1545 | sizeof (union fsf_status_qual)); | |
1546 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv"); | |
1547 | zfcp_erp_adapter_reopen(adapter, 0); | |
1548 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1549 | break; | |
1550 | ||
1551 | case FSF_PORT_BOXED: | |
1da177e4 LT |
1552 | ZFCP_LOG_INFO("port needs to be reopened " |
1553 | "(adapter %s, port d_id=0x%08x)\n", | |
1554 | zfcp_get_busid_by_port(port), port->d_id); | |
1555 | debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed"); | |
d736a27b | 1556 | zfcp_erp_port_boxed(port); |
1da177e4 LT |
1557 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
1558 | | ZFCP_STATUS_FSFREQ_RETRY; | |
1559 | break; | |
1560 | ||
1561 | /* following states should never occure, all cases avoided | |
1562 | in zfcp_fsf_send_ct - but who knows ... */ | |
1563 | case FSF_PAYLOAD_SIZE_MISMATCH: | |
1da177e4 LT |
1564 | ZFCP_LOG_INFO("payload size mismatch (adapter: %s, " |
1565 | "req_buf_length=%d, resp_buf_length=%d)\n", | |
1566 | zfcp_get_busid_by_adapter(adapter), | |
1567 | bottom->req_buf_length, bottom->resp_buf_length); | |
1568 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1569 | break; | |
1570 | case FSF_REQUEST_SIZE_TOO_LARGE: | |
1da177e4 LT |
1571 | ZFCP_LOG_INFO("request size too large (adapter: %s, " |
1572 | "req_buf_length=%d)\n", | |
1573 | zfcp_get_busid_by_adapter(adapter), | |
1574 | bottom->req_buf_length); | |
1575 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1576 | break; | |
1577 | case FSF_RESPONSE_SIZE_TOO_LARGE: | |
1da177e4 LT |
1578 | ZFCP_LOG_INFO("response size too large (adapter: %s, " |
1579 | "resp_buf_length=%d)\n", | |
1580 | zfcp_get_busid_by_adapter(adapter), | |
1581 | bottom->resp_buf_length); | |
1582 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1583 | break; | |
1584 | case FSF_SBAL_MISMATCH: | |
1da177e4 LT |
1585 | ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, " |
1586 | "resp_buf_length=%d)\n", | |
1587 | zfcp_get_busid_by_adapter(adapter), | |
1588 | bottom->req_buf_length, bottom->resp_buf_length); | |
1589 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1590 | break; | |
1591 | ||
1592 | default: | |
1593 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
1594 | "(debug info 0x%x)\n", header->fsf_status); | |
1595 | debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:"); | |
1596 | debug_exception(adapter->erp_dbf, 0, | |
1597 | &header->fsf_status_qual.word[0], sizeof (u32)); | |
1598 | break; | |
1599 | } | |
1600 | ||
1601 | skip_fsfstatus: | |
1602 | send_ct->status = retval; | |
1603 | ||
1604 | if (send_ct->handler != NULL) | |
1605 | send_ct->handler(send_ct->handler_data); | |
1606 | ||
1607 | return retval; | |
1608 | } | |
1609 | ||
1610 | /** | |
1611 | * zfcp_fsf_send_els - initiate an ELS command (FC-FS) | |
1612 | * @els: pointer to struct zfcp_send_els which contains all needed data for | |
1613 | * the command. | |
1614 | */ | |
1615 | int | |
1616 | zfcp_fsf_send_els(struct zfcp_send_els *els) | |
1617 | { | |
1618 | volatile struct qdio_buffer_element *sbale; | |
1619 | struct zfcp_fsf_req *fsf_req; | |
13e1e1f0 | 1620 | u32 d_id; |
1da177e4 LT |
1621 | struct zfcp_adapter *adapter; |
1622 | unsigned long lock_flags; | |
1623 | int bytes; | |
1624 | int ret = 0; | |
1625 | ||
1626 | d_id = els->d_id; | |
1627 | adapter = els->adapter; | |
1628 | ||
1629 | ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS, | |
1630 | ZFCP_REQ_AUTO_CLEANUP, | |
1631 | NULL, &lock_flags, &fsf_req); | |
1632 | if (ret < 0) { | |
1633 | ZFCP_LOG_INFO("error: creation of ELS request failed " | |
1634 | "(adapter %s, port d_id: 0x%08x)\n", | |
1635 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1636 | goto failed_req; | |
1637 | } | |
1638 | ||
1639 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
1640 | if (zfcp_use_one_sbal(els->req, els->req_count, | |
1641 | els->resp, els->resp_count)){ | |
1642 | /* both request buffer and response buffer | |
1643 | fit into one sbale each */ | |
1644 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ; | |
1645 | sbale[2].addr = zfcp_sg_to_address(&els->req[0]); | |
1646 | sbale[2].length = els->req[0].length; | |
1647 | sbale[3].addr = zfcp_sg_to_address(&els->resp[0]); | |
1648 | sbale[3].length = els->resp[0].length; | |
1649 | sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY; | |
aef4a983 | 1650 | } else if (adapter->adapter_features & |
1da177e4 LT |
1651 | FSF_FEATURE_ELS_CT_CHAINED_SBALS) { |
1652 | /* try to use chained SBALs */ | |
1653 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, | |
1654 | SBAL_FLAGS0_TYPE_WRITE_READ, | |
1655 | els->req, els->req_count, | |
1656 | ZFCP_MAX_SBALS_PER_ELS_REQ); | |
1657 | if (bytes <= 0) { | |
1658 | ZFCP_LOG_INFO("error: creation of ELS request failed " | |
1659 | "(adapter %s, port d_id: 0x%08x)\n", | |
1660 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1661 | if (bytes == 0) { | |
1662 | ret = -ENOMEM; | |
1663 | } else { | |
1664 | ret = bytes; | |
1665 | } | |
1666 | goto failed_send; | |
1667 | } | |
1668 | fsf_req->qtcb->bottom.support.req_buf_length = bytes; | |
1669 | fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL; | |
1670 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, | |
1671 | SBAL_FLAGS0_TYPE_WRITE_READ, | |
1672 | els->resp, els->resp_count, | |
1673 | ZFCP_MAX_SBALS_PER_ELS_REQ); | |
1674 | if (bytes <= 0) { | |
1675 | ZFCP_LOG_INFO("error: creation of ELS request failed " | |
1676 | "(adapter %s, port d_id: 0x%08x)\n", | |
1677 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1678 | if (bytes == 0) { | |
1679 | ret = -ENOMEM; | |
1680 | } else { | |
1681 | ret = bytes; | |
1682 | } | |
1683 | goto failed_send; | |
1684 | } | |
1685 | fsf_req->qtcb->bottom.support.resp_buf_length = bytes; | |
1686 | } else { | |
1687 | /* reject request */ | |
1688 | ZFCP_LOG_INFO("error: microcode does not support chained SBALs" | |
1689 | ", ELS request too big (adapter %s, " | |
1690 | "port d_id: 0x%08x)\n", | |
1691 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1692 | ret = -EOPNOTSUPP; | |
1693 | goto failed_send; | |
1694 | } | |
1695 | ||
1696 | /* settings in QTCB */ | |
1697 | fsf_req->qtcb->bottom.support.d_id = d_id; | |
1698 | fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class; | |
1699 | fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT; | |
059c97d0 | 1700 | fsf_req->data = (unsigned long) els; |
1da177e4 LT |
1701 | |
1702 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
1703 | ||
8a36e453 MS |
1704 | zfcp_san_dbf_event_els_request(fsf_req); |
1705 | ||
1da177e4 LT |
1706 | /* start QDIO request for this FSF request */ |
1707 | ret = zfcp_fsf_req_send(fsf_req, els->timer); | |
1708 | if (ret) { | |
1709 | ZFCP_LOG_DEBUG("error: initiation of ELS request failed " | |
1710 | "(adapter %s, port d_id: 0x%08x)\n", | |
1711 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1712 | goto failed_send; | |
1713 | } | |
1714 | ||
1715 | ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: " | |
1716 | "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id); | |
1717 | goto out; | |
1718 | ||
1719 | failed_send: | |
1720 | zfcp_fsf_req_free(fsf_req); | |
1721 | ||
1722 | failed_req: | |
1723 | out: | |
1724 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, | |
1725 | lock_flags); | |
1726 | ||
1727 | return ret; | |
1728 | } | |
1729 | ||
1730 | /** | |
1731 | * zfcp_fsf_send_els_handler - handler for ELS commands | |
1732 | * @fsf_req: pointer to struct zfcp_fsf_req | |
1733 | * | |
059c97d0 AH |
1734 | * Data specific for the ELS command is passed using |
1735 | * fsf_req->data. There we find the pointer to struct zfcp_send_els. | |
1736 | * Usually a specific handler for the ELS command is called which is | |
1737 | * found in this structure. | |
1da177e4 LT |
1738 | */ |
1739 | static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req) | |
1740 | { | |
1741 | struct zfcp_adapter *adapter; | |
1da177e4 | 1742 | struct zfcp_port *port; |
13e1e1f0 | 1743 | u32 d_id; |
1da177e4 LT |
1744 | struct fsf_qtcb_header *header; |
1745 | struct fsf_qtcb_bottom_support *bottom; | |
1746 | struct zfcp_send_els *send_els; | |
1747 | int retval = -EINVAL; | |
1748 | u16 subtable, rule, counter; | |
1749 | ||
059c97d0 | 1750 | send_els = (struct zfcp_send_els *) fsf_req->data; |
1da177e4 | 1751 | adapter = send_els->adapter; |
64b29a13 | 1752 | port = send_els->port; |
1da177e4 LT |
1753 | d_id = send_els->d_id; |
1754 | header = &fsf_req->qtcb->header; | |
1755 | bottom = &fsf_req->qtcb->bottom.support; | |
1756 | ||
1757 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
1758 | goto skip_fsfstatus; | |
1759 | ||
1760 | switch (header->fsf_status) { | |
1761 | ||
1762 | case FSF_GOOD: | |
8a36e453 | 1763 | zfcp_san_dbf_event_els_response(fsf_req); |
1da177e4 LT |
1764 | retval = 0; |
1765 | break; | |
1766 | ||
1767 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | |
1da177e4 LT |
1768 | if (adapter->fc_service_class <= 3) { |
1769 | ZFCP_LOG_INFO("error: adapter %s does " | |
1770 | "not support fibrechannel class %d.\n", | |
1771 | zfcp_get_busid_by_adapter(adapter), | |
1772 | adapter->fc_service_class); | |
1773 | } else { | |
1774 | ZFCP_LOG_INFO("bug: The fibrechannel class at " | |
1775 | "adapter %s is invalid. " | |
1776 | "(debug info %d)\n", | |
1777 | zfcp_get_busid_by_adapter(adapter), | |
1778 | adapter->fc_service_class); | |
1779 | } | |
1780 | /* stop operation for this adapter */ | |
1781 | debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup"); | |
1782 | zfcp_erp_adapter_shutdown(adapter, 0); | |
1783 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1784 | break; | |
1785 | ||
1786 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
1787 | switch (header->fsf_status_qual.word[0]){ |
1788 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 | 1789 | debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest"); |
64b29a13 AH |
1790 | if (port && (send_els->ls_code != ZFCP_LS_ADISC)) |
1791 | zfcp_test_link(port); | |
1da177e4 LT |
1792 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1793 | break; | |
1794 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
1795 | debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp"); |
1796 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1797 | retval = | |
1798 | zfcp_handle_els_rjt(header->fsf_status_qual.word[1], | |
1799 | (struct zfcp_ls_rjt_par *) | |
1800 | &header->fsf_status_qual.word[2]); | |
1801 | break; | |
1802 | case FSF_SQ_RETRY_IF_POSSIBLE: | |
1da177e4 LT |
1803 | debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry"); |
1804 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1805 | break; | |
1806 | default: | |
1807 | ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n", | |
1808 | header->fsf_status_qual.word[0]); | |
1809 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, | |
1810 | (char*)header->fsf_status_qual.word, 16); | |
1811 | } | |
1812 | break; | |
1813 | ||
1814 | case FSF_ELS_COMMAND_REJECTED: | |
1da177e4 LT |
1815 | ZFCP_LOG_INFO("ELS has been rejected because command filter " |
1816 | "prohibited sending " | |
1817 | "(adapter: %s, port d_id: 0x%08x)\n", | |
1818 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1819 | ||
1820 | break; | |
1821 | ||
1822 | case FSF_PAYLOAD_SIZE_MISMATCH: | |
1da177e4 LT |
1823 | ZFCP_LOG_INFO( |
1824 | "ELS request size and ELS response size must be either " | |
1825 | "both 0, or both greater than 0 " | |
1826 | "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n", | |
1827 | zfcp_get_busid_by_adapter(adapter), | |
1828 | bottom->req_buf_length, | |
1829 | bottom->resp_buf_length); | |
1830 | break; | |
1831 | ||
1832 | case FSF_REQUEST_SIZE_TOO_LARGE: | |
1da177e4 LT |
1833 | ZFCP_LOG_INFO( |
1834 | "Length of the ELS request buffer, " | |
1835 | "specified in QTCB bottom, " | |
1836 | "exceeds the size of the buffers " | |
1837 | "that have been allocated for ELS request data " | |
1838 | "(adapter: %s, req_buf_length=%d)\n", | |
1839 | zfcp_get_busid_by_adapter(adapter), | |
1840 | bottom->req_buf_length); | |
1841 | break; | |
1842 | ||
1843 | case FSF_RESPONSE_SIZE_TOO_LARGE: | |
1da177e4 LT |
1844 | ZFCP_LOG_INFO( |
1845 | "Length of the ELS response buffer, " | |
1846 | "specified in QTCB bottom, " | |
1847 | "exceeds the size of the buffers " | |
1848 | "that have been allocated for ELS response data " | |
1849 | "(adapter: %s, resp_buf_length=%d)\n", | |
1850 | zfcp_get_busid_by_adapter(adapter), | |
1851 | bottom->resp_buf_length); | |
1852 | break; | |
1853 | ||
1854 | case FSF_SBAL_MISMATCH: | |
1855 | /* should never occure, avoided in zfcp_fsf_send_els */ | |
1da177e4 LT |
1856 | ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, " |
1857 | "resp_buf_length=%d)\n", | |
1858 | zfcp_get_busid_by_adapter(adapter), | |
1859 | bottom->req_buf_length, bottom->resp_buf_length); | |
1860 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1861 | break; | |
1862 | ||
1863 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
1864 | ZFCP_LOG_NORMAL("access denied, cannot send ELS command " |
1865 | "(adapter %s, port d_id=0x%08x)\n", | |
1866 | zfcp_get_busid_by_adapter(adapter), d_id); | |
1867 | for (counter = 0; counter < 2; counter++) { | |
1868 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
1869 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
1870 | switch (subtable) { | |
1871 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
1872 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
1873 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
1874 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
1875 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
1876 | zfcp_act_subtable_type[subtable], rule); | |
1877 | break; | |
1878 | } | |
1879 | } | |
1880 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_access"); | |
1da177e4 LT |
1881 | if (port != NULL) |
1882 | zfcp_erp_port_access_denied(port); | |
1da177e4 LT |
1883 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1884 | break; | |
1885 | ||
1886 | default: | |
1887 | ZFCP_LOG_NORMAL( | |
1888 | "bug: An unknown FSF Status was presented " | |
1889 | "(adapter: %s, fsf_status=0x%08x)\n", | |
1890 | zfcp_get_busid_by_adapter(adapter), | |
1891 | header->fsf_status); | |
1892 | debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval"); | |
1893 | debug_exception(adapter->erp_dbf, 0, | |
1894 | &header->fsf_status_qual.word[0], sizeof(u32)); | |
1895 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
1896 | break; | |
1897 | } | |
1898 | ||
1899 | skip_fsfstatus: | |
1900 | send_els->status = retval; | |
1901 | ||
1902 | if (send_els->handler != 0) | |
1903 | send_els->handler(send_els->handler_data); | |
1904 | ||
1905 | return retval; | |
1906 | } | |
1907 | ||
1908 | /* | |
1909 | * function: | |
1910 | * | |
1911 | * purpose: | |
1912 | * | |
1913 | * returns: address of initiated FSF request | |
1914 | * NULL - request could not be initiated | |
1915 | */ | |
1916 | int | |
1917 | zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action) | |
1918 | { | |
1919 | volatile struct qdio_buffer_element *sbale; | |
1920 | unsigned long lock_flags; | |
1921 | int retval = 0; | |
1922 | ||
1923 | /* setup new FSF request */ | |
1924 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
1925 | FSF_QTCB_EXCHANGE_CONFIG_DATA, | |
1926 | ZFCP_REQ_AUTO_CLEANUP, | |
1927 | erp_action->adapter->pool.fsf_req_erp, | |
1928 | &lock_flags, &(erp_action->fsf_req)); | |
1929 | if (retval < 0) { | |
1930 | ZFCP_LOG_INFO("error: Could not create exchange configuration " | |
1931 | "data request for adapter %s.\n", | |
1932 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
1933 | goto out; | |
1934 | } | |
1935 | ||
1936 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
1937 | erp_action->fsf_req->sbal_curr, 0); | |
1938 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
1939 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
1940 | ||
1941 | erp_action->fsf_req->erp_action = erp_action; | |
1942 | erp_action->fsf_req->qtcb->bottom.config.feature_selection = | |
aef4a983 MS |
1943 | FSF_FEATURE_CFDC | |
1944 | FSF_FEATURE_LUN_SHARING | | |
1945 | FSF_FEATURE_UPDATE_ALERT; | |
1da177e4 LT |
1946 | |
1947 | /* start QDIO request for this FSF request */ | |
1948 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
1949 | if (retval) { | |
1950 | ZFCP_LOG_INFO | |
1951 | ("error: Could not send exchange configuration data " | |
1952 | "command on the adapter %s\n", | |
1953 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
1954 | zfcp_fsf_req_free(erp_action->fsf_req); | |
1955 | erp_action->fsf_req = NULL; | |
1956 | goto out; | |
1957 | } | |
1958 | ||
1959 | ZFCP_LOG_DEBUG("exchange configuration data request initiated " | |
1960 | "(adapter %s)\n", | |
1961 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
1962 | ||
1963 | out: | |
1964 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
1965 | lock_flags); | |
1966 | return retval; | |
1967 | } | |
1968 | ||
1969 | /** | |
1970 | * zfcp_fsf_exchange_config_evaluate | |
1971 | * @fsf_req: fsf_req which belongs to xchg config data request | |
1972 | * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1) | |
1973 | * | |
1974 | * returns: -EIO on error, 0 otherwise | |
1975 | */ | |
1976 | static int | |
1977 | zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok) | |
1978 | { | |
1979 | struct fsf_qtcb_bottom_config *bottom; | |
1980 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
13e1e1f0 | 1981 | struct Scsi_Host *shost = adapter->scsi_host; |
1da177e4 LT |
1982 | |
1983 | bottom = &fsf_req->qtcb->bottom.config; | |
1984 | ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n", | |
1985 | bottom->low_qtcb_version, bottom->high_qtcb_version); | |
1986 | adapter->fsf_lic_version = bottom->lic_version; | |
aef4a983 MS |
1987 | adapter->adapter_features = bottom->adapter_features; |
1988 | adapter->connection_features = bottom->connection_features; | |
6f71d9bc JB |
1989 | adapter->peer_wwpn = 0; |
1990 | adapter->peer_wwnn = 0; | |
1991 | adapter->peer_d_id = 0; | |
1da177e4 LT |
1992 | |
1993 | if (xchg_ok) { | |
13e1e1f0 AH |
1994 | fc_host_node_name(shost) = bottom->nport_serv_param.wwnn; |
1995 | fc_host_port_name(shost) = bottom->nport_serv_param.wwpn; | |
1996 | fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK; | |
1997 | fc_host_speed(shost) = bottom->fc_link_speed; | |
1998 | fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3; | |
1da177e4 | 1999 | adapter->fc_topology = bottom->fc_topology; |
1da177e4 | 2000 | adapter->hydra_version = bottom->adapter_type; |
aef4a983 | 2001 | if (adapter->physical_wwpn == 0) |
13e1e1f0 | 2002 | adapter->physical_wwpn = fc_host_port_name(shost); |
aef4a983 | 2003 | if (adapter->physical_s_id == 0) |
13e1e1f0 | 2004 | adapter->physical_s_id = fc_host_port_id(shost); |
1da177e4 | 2005 | } else { |
13e1e1f0 AH |
2006 | fc_host_node_name(shost) = 0; |
2007 | fc_host_port_name(shost) = 0; | |
2008 | fc_host_port_id(shost) = 0; | |
2009 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
1da177e4 | 2010 | adapter->fc_topology = 0; |
1da177e4 LT |
2011 | adapter->hydra_version = 0; |
2012 | } | |
2013 | ||
6f71d9bc JB |
2014 | if (adapter->fc_topology == FSF_TOPO_P2P) { |
2015 | adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK; | |
2016 | adapter->peer_wwpn = bottom->plogi_payload.wwpn; | |
2017 | adapter->peer_wwnn = bottom->plogi_payload.wwnn; | |
2018 | } | |
2019 | ||
aef4a983 | 2020 | if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) { |
1da177e4 | 2021 | adapter->hardware_version = bottom->hardware_version; |
13e1e1f0 AH |
2022 | memcpy(fc_host_serial_number(shost), bottom->serial_number, |
2023 | min(FC_SERIAL_NUMBER_SIZE, 17)); | |
2024 | EBCASC(fc_host_serial_number(shost), | |
2025 | min(FC_SERIAL_NUMBER_SIZE, 17)); | |
1da177e4 LT |
2026 | } |
2027 | ||
6f71d9bc | 2028 | ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n" |
13e1e1f0 AH |
2029 | "WWNN 0x%016Lx, " |
2030 | "WWPN 0x%016Lx, " | |
2031 | "S_ID 0x%08x,\n" | |
2032 | "adapter version 0x%x, " | |
2033 | "LIC version 0x%x, " | |
2034 | "FC link speed %d Gb/s\n", | |
2035 | zfcp_get_busid_by_adapter(adapter), | |
2036 | (wwn_t) fc_host_node_name(shost), | |
2037 | (wwn_t) fc_host_port_name(shost), | |
2038 | fc_host_port_id(shost), | |
2039 | adapter->hydra_version, | |
2040 | adapter->fsf_lic_version, | |
2041 | fc_host_speed(shost)); | |
1da177e4 LT |
2042 | if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) { |
2043 | ZFCP_LOG_NORMAL("error: the adapter %s " | |
2044 | "only supports newer control block " | |
2045 | "versions in comparison to this device " | |
2046 | "driver (try updated device driver)\n", | |
2047 | zfcp_get_busid_by_adapter(adapter)); | |
2048 | debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver"); | |
2049 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2050 | return -EIO; | |
2051 | } | |
2052 | if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) { | |
2053 | ZFCP_LOG_NORMAL("error: the adapter %s " | |
2054 | "only supports older control block " | |
2055 | "versions than this device driver uses" | |
2056 | "(consider a microcode upgrade)\n", | |
2057 | zfcp_get_busid_by_adapter(adapter)); | |
2058 | debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver"); | |
2059 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2060 | return -EIO; | |
2061 | } | |
2062 | return 0; | |
2063 | } | |
2064 | ||
2065 | /* | |
2066 | * function: zfcp_fsf_exchange_config_data_handler | |
2067 | * | |
2068 | * purpose: is called for finished Exchange Configuration Data command | |
2069 | * | |
2070 | * returns: | |
2071 | */ | |
2072 | static int | |
2073 | zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req) | |
2074 | { | |
2075 | struct fsf_qtcb_bottom_config *bottom; | |
2076 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
aef4a983 | 2077 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
1da177e4 LT |
2078 | |
2079 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
2080 | return -EIO; | |
2081 | ||
aef4a983 | 2082 | switch (qtcb->header.fsf_status) { |
1da177e4 LT |
2083 | |
2084 | case FSF_GOOD: | |
1da177e4 LT |
2085 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1)) |
2086 | return -EIO; | |
2087 | ||
2088 | switch (adapter->fc_topology) { | |
2089 | case FSF_TOPO_P2P: | |
6f71d9bc JB |
2090 | ZFCP_LOG_NORMAL("Point-to-Point fibrechannel " |
2091 | "configuration detected at adapter %s\n" | |
2092 | "Peer WWNN 0x%016llx, " | |
2093 | "peer WWPN 0x%016llx, " | |
2094 | "peer d_id 0x%06x\n", | |
2095 | zfcp_get_busid_by_adapter(adapter), | |
2096 | adapter->peer_wwnn, | |
2097 | adapter->peer_wwpn, | |
2098 | adapter->peer_d_id); | |
1da177e4 LT |
2099 | debug_text_event(fsf_req->adapter->erp_dbf, 0, |
2100 | "top-p-to-p"); | |
6f71d9bc | 2101 | break; |
1da177e4 | 2102 | case FSF_TOPO_AL: |
1da177e4 LT |
2103 | ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel " |
2104 | "topology detected at adapter %s " | |
2105 | "unsupported, shutting down adapter\n", | |
2106 | zfcp_get_busid_by_adapter(adapter)); | |
2107 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
2108 | "top-al"); | |
2109 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2110 | return -EIO; | |
2111 | case FSF_TOPO_FABRIC: | |
aef4a983 | 2112 | ZFCP_LOG_NORMAL("Switched fabric fibrechannel " |
1da177e4 LT |
2113 | "network detected at adapter %s.\n", |
2114 | zfcp_get_busid_by_adapter(adapter)); | |
2115 | break; | |
2116 | default: | |
2117 | ZFCP_LOG_NORMAL("bug: The fibrechannel topology " | |
2118 | "reported by the exchange " | |
2119 | "configuration command for " | |
2120 | "the adapter %s is not " | |
2121 | "of a type known to the zfcp " | |
2122 | "driver, shutting down adapter\n", | |
2123 | zfcp_get_busid_by_adapter(adapter)); | |
6f71d9bc | 2124 | adapter->fc_topology = FSF_TOPO_ERROR; |
1da177e4 LT |
2125 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, |
2126 | "unknown-topo"); | |
2127 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2128 | return -EIO; | |
2129 | } | |
aef4a983 | 2130 | bottom = &qtcb->bottom.config; |
1da177e4 LT |
2131 | if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) { |
2132 | ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) " | |
2133 | "allowed by the adapter %s " | |
2134 | "is lower than the minimum " | |
2135 | "required by the driver (%ld bytes).\n", | |
2136 | bottom->max_qtcb_size, | |
2137 | zfcp_get_busid_by_adapter(adapter), | |
2138 | sizeof(struct fsf_qtcb)); | |
2139 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
2140 | "qtcb-size"); | |
2141 | debug_event(fsf_req->adapter->erp_dbf, 0, | |
2142 | &bottom->max_qtcb_size, sizeof (u32)); | |
2143 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2144 | return -EIO; | |
2145 | } | |
2146 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, | |
2147 | &adapter->status); | |
2148 | break; | |
2149 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | |
2150 | debug_text_event(adapter->erp_dbf, 0, "xchg-inco"); | |
2151 | ||
2152 | if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0)) | |
2153 | return -EIO; | |
2154 | ||
aef4a983 MS |
2155 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status); |
2156 | ||
2157 | zfcp_fsf_link_down_info_eval(adapter, | |
2158 | &qtcb->header.fsf_status_qual.link_down_info); | |
1da177e4 LT |
2159 | break; |
2160 | default: | |
2161 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng"); | |
2162 | debug_event(fsf_req->adapter->erp_dbf, 0, | |
2163 | &fsf_req->qtcb->header.fsf_status, sizeof (u32)); | |
2164 | zfcp_erp_adapter_shutdown(adapter, 0); | |
2165 | return -EIO; | |
2166 | } | |
2167 | return 0; | |
2168 | } | |
2169 | ||
2170 | /** | |
2171 | * zfcp_fsf_exchange_port_data - request information about local port | |
aef4a983 | 2172 | * @erp_action: ERP action for the adapter for which port data is requested |
1da177e4 LT |
2173 | * @adapter: for which port data is requested |
2174 | * @data: response to exchange port data request | |
2175 | */ | |
2176 | int | |
aef4a983 MS |
2177 | zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action, |
2178 | struct zfcp_adapter *adapter, | |
1da177e4 LT |
2179 | struct fsf_qtcb_bottom_port *data) |
2180 | { | |
2181 | volatile struct qdio_buffer_element *sbale; | |
2182 | int retval = 0; | |
2183 | unsigned long lock_flags; | |
2184 | struct zfcp_fsf_req *fsf_req; | |
2185 | struct timer_list *timer; | |
2186 | ||
aef4a983 | 2187 | if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) { |
1da177e4 LT |
2188 | ZFCP_LOG_INFO("error: exchange port data " |
2189 | "command not supported by adapter %s\n", | |
2190 | zfcp_get_busid_by_adapter(adapter)); | |
2191 | return -EOPNOTSUPP; | |
2192 | } | |
2193 | ||
1da177e4 LT |
2194 | /* setup new FSF request */ |
2195 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, | |
2448c459 AH |
2196 | erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0, |
2197 | 0, &lock_flags, &fsf_req); | |
1da177e4 LT |
2198 | if (retval < 0) { |
2199 | ZFCP_LOG_INFO("error: Out of resources. Could not create an " | |
2200 | "exchange port data request for" | |
2201 | "the adapter %s.\n", | |
2202 | zfcp_get_busid_by_adapter(adapter)); | |
2203 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, | |
2204 | lock_flags); | |
2448c459 | 2205 | return retval; |
aef4a983 MS |
2206 | } |
2207 | ||
2208 | if (data) | |
2448c459 | 2209 | fsf_req->data = (unsigned long) data; |
059c97d0 | 2210 | |
1da177e4 LT |
2211 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); |
2212 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
2213 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
2214 | ||
2448c459 AH |
2215 | if (erp_action) { |
2216 | erp_action->fsf_req = fsf_req; | |
2217 | fsf_req->erp_action = erp_action; | |
2218 | timer = &erp_action->timer; | |
2219 | } else { | |
2220 | timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC); | |
2221 | if (!timer) { | |
2222 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, | |
2223 | lock_flags); | |
2224 | zfcp_fsf_req_free(fsf_req); | |
2225 | return -ENOMEM; | |
2226 | } | |
2227 | init_timer(timer); | |
2228 | timer->function = zfcp_fsf_request_timeout_handler; | |
2229 | timer->data = (unsigned long) adapter; | |
2230 | timer->expires = ZFCP_FSF_REQUEST_TIMEOUT; | |
2231 | } | |
1da177e4 LT |
2232 | |
2233 | retval = zfcp_fsf_req_send(fsf_req, timer); | |
2234 | if (retval) { | |
2235 | ZFCP_LOG_INFO("error: Could not send an exchange port data " | |
2236 | "command on the adapter %s\n", | |
2237 | zfcp_get_busid_by_adapter(adapter)); | |
2238 | zfcp_fsf_req_free(fsf_req); | |
aef4a983 MS |
2239 | if (erp_action) |
2240 | erp_action->fsf_req = NULL; | |
2448c459 AH |
2241 | else |
2242 | kfree(timer); | |
1da177e4 LT |
2243 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, |
2244 | lock_flags); | |
2448c459 | 2245 | return retval; |
1da177e4 LT |
2246 | } |
2247 | ||
2448c459 | 2248 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); |
1da177e4 | 2249 | |
2448c459 AH |
2250 | if (!erp_action) { |
2251 | wait_event(fsf_req->completion_wq, | |
2252 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | |
2253 | del_timer_sync(timer); | |
2254 | zfcp_fsf_req_free(fsf_req); | |
2255 | kfree(timer); | |
2256 | } | |
1da177e4 LT |
2257 | return retval; |
2258 | } | |
2259 | ||
2260 | ||
2261 | /** | |
2262 | * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request | |
2263 | * @fsf_req: pointer to struct zfcp_fsf_req | |
2264 | */ | |
2265 | static void | |
2266 | zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req) | |
2267 | { | |
aef4a983 | 2268 | struct zfcp_adapter *adapter = fsf_req->adapter; |
13e1e1f0 | 2269 | struct Scsi_Host *shost = adapter->scsi_host; |
aef4a983 MS |
2270 | struct fsf_qtcb *qtcb = fsf_req->qtcb; |
2271 | struct fsf_qtcb_bottom_port *bottom, *data; | |
1da177e4 LT |
2272 | |
2273 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) | |
2274 | return; | |
2275 | ||
aef4a983 | 2276 | switch (qtcb->header.fsf_status) { |
1da177e4 | 2277 | case FSF_GOOD: |
aef4a983 MS |
2278 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); |
2279 | ||
2280 | bottom = &qtcb->bottom.port; | |
2281 | data = (struct fsf_qtcb_bottom_port*) fsf_req->data; | |
2282 | if (data) | |
2283 | memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port)); | |
2284 | if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) { | |
2285 | adapter->physical_wwpn = bottom->wwpn; | |
2286 | adapter->physical_s_id = bottom->fc_port_id; | |
2287 | } else { | |
13e1e1f0 AH |
2288 | adapter->physical_wwpn = fc_host_port_name(shost); |
2289 | adapter->physical_s_id = fc_host_port_id(shost); | |
aef4a983 | 2290 | } |
13e1e1f0 | 2291 | fc_host_maxframe_size(shost) = bottom->maximum_frame_size; |
aef4a983 MS |
2292 | break; |
2293 | ||
2294 | case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE: | |
2295 | atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status); | |
2296 | ||
2297 | zfcp_fsf_link_down_info_eval(adapter, | |
2298 | &qtcb->header.fsf_status_qual.link_down_info); | |
1da177e4 LT |
2299 | break; |
2300 | ||
2301 | default: | |
aef4a983 MS |
2302 | debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng"); |
2303 | debug_event(adapter->erp_dbf, 0, | |
1da177e4 LT |
2304 | &fsf_req->qtcb->header.fsf_status, sizeof(u32)); |
2305 | } | |
2306 | } | |
2307 | ||
2308 | ||
2309 | /* | |
2310 | * function: zfcp_fsf_open_port | |
2311 | * | |
2312 | * purpose: | |
2313 | * | |
2314 | * returns: address of initiated FSF request | |
2315 | * NULL - request could not be initiated | |
2316 | */ | |
2317 | int | |
2318 | zfcp_fsf_open_port(struct zfcp_erp_action *erp_action) | |
2319 | { | |
2320 | volatile struct qdio_buffer_element *sbale; | |
2321 | unsigned long lock_flags; | |
2322 | int retval = 0; | |
2323 | ||
2324 | /* setup new FSF request */ | |
2325 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
2326 | FSF_QTCB_OPEN_PORT_WITH_DID, | |
2327 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
2328 | erp_action->adapter->pool.fsf_req_erp, | |
2329 | &lock_flags, &(erp_action->fsf_req)); | |
2330 | if (retval < 0) { | |
2331 | ZFCP_LOG_INFO("error: Could not create open port request " | |
2332 | "for port 0x%016Lx on adapter %s.\n", | |
2333 | erp_action->port->wwpn, | |
2334 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
2335 | goto out; | |
2336 | } | |
2337 | ||
2338 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
2339 | erp_action->fsf_req->sbal_curr, 0); | |
2340 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
2341 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
2342 | ||
2343 | erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id; | |
2344 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status); | |
059c97d0 | 2345 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
1da177e4 LT |
2346 | erp_action->fsf_req->erp_action = erp_action; |
2347 | ||
2348 | /* start QDIO request for this FSF request */ | |
2349 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
2350 | if (retval) { | |
2351 | ZFCP_LOG_INFO("error: Could not send open port request for " | |
2352 | "port 0x%016Lx on adapter %s.\n", | |
2353 | erp_action->port->wwpn, | |
2354 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
2355 | zfcp_fsf_req_free(erp_action->fsf_req); | |
2356 | erp_action->fsf_req = NULL; | |
2357 | goto out; | |
2358 | } | |
2359 | ||
2360 | ZFCP_LOG_DEBUG("open port request initiated " | |
2361 | "(adapter %s, port 0x%016Lx)\n", | |
2362 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2363 | erp_action->port->wwpn); | |
2364 | out: | |
2365 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
2366 | lock_flags); | |
2367 | return retval; | |
2368 | } | |
2369 | ||
2370 | /* | |
2371 | * function: zfcp_fsf_open_port_handler | |
2372 | * | |
2373 | * purpose: is called for finished Open Port command | |
2374 | * | |
2375 | * returns: | |
2376 | */ | |
2377 | static int | |
2378 | zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req) | |
2379 | { | |
2380 | int retval = -EINVAL; | |
2381 | struct zfcp_port *port; | |
2382 | struct fsf_plogi *plogi; | |
2383 | struct fsf_qtcb_header *header; | |
2384 | u16 subtable, rule, counter; | |
2385 | ||
059c97d0 | 2386 | port = (struct zfcp_port *) fsf_req->data; |
1da177e4 LT |
2387 | header = &fsf_req->qtcb->header; |
2388 | ||
2389 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
2390 | /* don't change port status in our bookkeeping */ | |
2391 | goto skip_fsfstatus; | |
2392 | } | |
2393 | ||
2394 | /* evaluate FSF status in QTCB */ | |
2395 | switch (header->fsf_status) { | |
2396 | ||
2397 | case FSF_PORT_ALREADY_OPEN: | |
1da177e4 LT |
2398 | ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s " |
2399 | "is already open.\n", | |
2400 | port->wwpn, zfcp_get_busid_by_port(port)); | |
2401 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, | |
2402 | "fsf_s_popen"); | |
2403 | /* | |
2404 | * This is a bug, however operation should continue normally | |
2405 | * if it is simply ignored | |
2406 | */ | |
2407 | break; | |
2408 | ||
2409 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
2410 | ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx " |
2411 | "on adapter %s\n", | |
2412 | port->wwpn, zfcp_get_busid_by_port(port)); | |
2413 | for (counter = 0; counter < 2; counter++) { | |
2414 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
2415 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
2416 | switch (subtable) { | |
2417 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
2418 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
2419 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
2420 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
2421 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
2422 | zfcp_act_subtable_type[subtable], rule); | |
2423 | break; | |
2424 | } | |
2425 | } | |
2426 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); | |
2427 | zfcp_erp_port_access_denied(port); | |
2428 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2429 | break; | |
2430 | ||
2431 | case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED: | |
1da177e4 LT |
2432 | ZFCP_LOG_INFO("error: The FSF adapter is out of resources. " |
2433 | "The remote port 0x%016Lx on adapter %s " | |
2434 | "could not be opened. Disabling it.\n", | |
2435 | port->wwpn, zfcp_get_busid_by_port(port)); | |
2436 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
2437 | "fsf_s_max_ports"); | |
2438 | zfcp_erp_port_failed(port); | |
2439 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2440 | break; | |
2441 | ||
2442 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
2443 | switch (header->fsf_status_qual.word[0]) { |
2444 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
2445 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
2446 | "fsf_sq_ltest"); | |
2447 | /* ERP strategy will escalate */ | |
2448 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2449 | break; | |
2450 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
2451 | /* ERP strategy will escalate */ | |
2452 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
2453 | "fsf_sq_ulp"); | |
2454 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2455 | break; | |
2456 | case FSF_SQ_NO_RETRY_POSSIBLE: | |
1da177e4 LT |
2457 | ZFCP_LOG_NORMAL("The remote port 0x%016Lx on " |
2458 | "adapter %s could not be opened. " | |
2459 | "Disabling it.\n", | |
2460 | port->wwpn, | |
2461 | zfcp_get_busid_by_port(port)); | |
2462 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, | |
2463 | "fsf_sq_no_retry"); | |
2464 | zfcp_erp_port_failed(port); | |
2465 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2466 | break; | |
2467 | default: | |
2468 | ZFCP_LOG_NORMAL | |
2469 | ("bug: Wrong status qualifier 0x%x arrived.\n", | |
2470 | header->fsf_status_qual.word[0]); | |
2471 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
2472 | "fsf_sq_inval:"); | |
2473 | debug_exception( | |
2474 | fsf_req->adapter->erp_dbf, 0, | |
2475 | &header->fsf_status_qual.word[0], | |
2476 | sizeof (u32)); | |
2477 | break; | |
2478 | } | |
2479 | break; | |
2480 | ||
2481 | case FSF_GOOD: | |
1da177e4 LT |
2482 | /* save port handle assigned by FSF */ |
2483 | port->handle = header->port_handle; | |
2484 | ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s " | |
2485 | "was opened, it's port handle is 0x%x\n", | |
2486 | port->wwpn, zfcp_get_busid_by_port(port), | |
2487 | port->handle); | |
2488 | /* mark port as open */ | |
2489 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | | |
2490 | ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | |
d736a27b AH |
2491 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
2492 | ZFCP_STATUS_COMMON_ACCESS_BOXED, | |
2493 | &port->status); | |
1da177e4 LT |
2494 | retval = 0; |
2495 | /* check whether D_ID has changed during open */ | |
2496 | /* | |
2497 | * FIXME: This check is not airtight, as the FCP channel does | |
2498 | * not monitor closures of target port connections caused on | |
2499 | * the remote side. Thus, they might miss out on invalidating | |
2500 | * locally cached WWPNs (and other N_Port parameters) of gone | |
2501 | * target ports. So, our heroic attempt to make things safe | |
2502 | * could be undermined by 'open port' response data tagged with | |
2503 | * obsolete WWPNs. Another reason to monitor potential | |
2504 | * connection closures ourself at least (by interpreting | |
2505 | * incoming ELS' and unsolicited status). It just crosses my | |
2506 | * mind that one should be able to cross-check by means of | |
2507 | * another GID_PN straight after a port has been opened. | |
2508 | * Alternately, an ADISC/PDISC ELS should suffice, as well. | |
2509 | */ | |
2510 | plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els; | |
2511 | if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status)) | |
2512 | { | |
2513 | if (fsf_req->qtcb->bottom.support.els1_length < | |
2514 | ((((unsigned long) &plogi->serv_param.wwpn) - | |
2515 | ((unsigned long) plogi)) + sizeof (u64))) { | |
2516 | ZFCP_LOG_INFO( | |
2517 | "warning: insufficient length of " | |
2518 | "PLOGI payload (%i)\n", | |
2519 | fsf_req->qtcb->bottom.support.els1_length); | |
2520 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
2521 | "fsf_s_short_plogi:"); | |
2522 | /* skip sanity check and assume wwpn is ok */ | |
2523 | } else { | |
2524 | if (plogi->serv_param.wwpn != port->wwpn) { | |
2525 | ZFCP_LOG_INFO("warning: d_id of port " | |
2526 | "0x%016Lx changed during " | |
2527 | "open\n", port->wwpn); | |
2528 | debug_text_event( | |
2529 | fsf_req->adapter->erp_dbf, 0, | |
2530 | "fsf_s_did_change:"); | |
2531 | atomic_clear_mask( | |
2532 | ZFCP_STATUS_PORT_DID_DID, | |
2533 | &port->status); | |
2534 | } else | |
2535 | port->wwnn = plogi->serv_param.wwnn; | |
2536 | } | |
2537 | } | |
2538 | break; | |
2539 | ||
2540 | case FSF_UNKNOWN_OP_SUBTYPE: | |
2541 | /* should never occure, subtype not set in zfcp_fsf_open_port */ | |
1da177e4 LT |
2542 | ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, " |
2543 | "op_subtype=0x%x)\n", | |
2544 | zfcp_get_busid_by_port(port), | |
2545 | fsf_req->qtcb->bottom.support.operation_subtype); | |
2546 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2547 | break; | |
2548 | ||
2549 | default: | |
2550 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
2551 | "(debug info 0x%x)\n", | |
2552 | header->fsf_status); | |
2553 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); | |
2554 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
2555 | &header->fsf_status, sizeof (u32)); | |
2556 | break; | |
2557 | } | |
2558 | ||
2559 | skip_fsfstatus: | |
2560 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status); | |
2561 | return retval; | |
2562 | } | |
2563 | ||
2564 | /* | |
2565 | * function: zfcp_fsf_close_port | |
2566 | * | |
2567 | * purpose: submit FSF command "close port" | |
2568 | * | |
2569 | * returns: address of initiated FSF request | |
2570 | * NULL - request could not be initiated | |
2571 | */ | |
2572 | int | |
2573 | zfcp_fsf_close_port(struct zfcp_erp_action *erp_action) | |
2574 | { | |
2575 | volatile struct qdio_buffer_element *sbale; | |
2576 | unsigned long lock_flags; | |
2577 | int retval = 0; | |
2578 | ||
2579 | /* setup new FSF request */ | |
2580 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
2581 | FSF_QTCB_CLOSE_PORT, | |
2582 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
2583 | erp_action->adapter->pool.fsf_req_erp, | |
2584 | &lock_flags, &(erp_action->fsf_req)); | |
2585 | if (retval < 0) { | |
2586 | ZFCP_LOG_INFO("error: Could not create a close port request " | |
2587 | "for port 0x%016Lx on adapter %s.\n", | |
2588 | erp_action->port->wwpn, | |
2589 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
2590 | goto out; | |
2591 | } | |
2592 | ||
2593 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
2594 | erp_action->fsf_req->sbal_curr, 0); | |
2595 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
2596 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
2597 | ||
2598 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status); | |
059c97d0 | 2599 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
1da177e4 LT |
2600 | erp_action->fsf_req->erp_action = erp_action; |
2601 | erp_action->fsf_req->qtcb->header.port_handle = | |
2602 | erp_action->port->handle; | |
2603 | ||
2604 | /* start QDIO request for this FSF request */ | |
2605 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
2606 | if (retval) { | |
2607 | ZFCP_LOG_INFO("error: Could not send a close port request for " | |
2608 | "port 0x%016Lx on adapter %s.\n", | |
2609 | erp_action->port->wwpn, | |
2610 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
2611 | zfcp_fsf_req_free(erp_action->fsf_req); | |
2612 | erp_action->fsf_req = NULL; | |
2613 | goto out; | |
2614 | } | |
2615 | ||
2616 | ZFCP_LOG_TRACE("close port request initiated " | |
2617 | "(adapter %s, port 0x%016Lx)\n", | |
2618 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2619 | erp_action->port->wwpn); | |
2620 | out: | |
2621 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
2622 | lock_flags); | |
2623 | return retval; | |
2624 | } | |
2625 | ||
2626 | /* | |
2627 | * function: zfcp_fsf_close_port_handler | |
2628 | * | |
2629 | * purpose: is called for finished Close Port FSF command | |
2630 | * | |
2631 | * returns: | |
2632 | */ | |
2633 | static int | |
2634 | zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req) | |
2635 | { | |
2636 | int retval = -EINVAL; | |
2637 | struct zfcp_port *port; | |
2638 | ||
059c97d0 | 2639 | port = (struct zfcp_port *) fsf_req->data; |
1da177e4 LT |
2640 | |
2641 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
2642 | /* don't change port status in our bookkeeping */ | |
2643 | goto skip_fsfstatus; | |
2644 | } | |
2645 | ||
2646 | /* evaluate FSF status in QTCB */ | |
2647 | switch (fsf_req->qtcb->header.fsf_status) { | |
2648 | ||
2649 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
2650 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
2651 | "0x%016Lx on adapter %s invalid. This may happen " | |
2652 | "occasionally.\n", port->handle, | |
2653 | port->wwpn, zfcp_get_busid_by_port(port)); | |
2654 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
2655 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
2656 | (char *) &fsf_req->qtcb->header.fsf_status_qual, | |
2657 | sizeof (union fsf_status_qual)); | |
2658 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
2659 | "fsf_s_phand_nv"); | |
2660 | zfcp_erp_adapter_reopen(port->adapter, 0); | |
2661 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2662 | break; | |
2663 | ||
2664 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
2665 | /* Note: FSF has actually closed the port in this case. |
2666 | * The status code is just daft. Fingers crossed for a change | |
2667 | */ | |
2668 | retval = 0; | |
2669 | break; | |
2670 | ||
2671 | case FSF_GOOD: | |
1da177e4 LT |
2672 | ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, " |
2673 | "port handle 0x%x\n", port->wwpn, | |
2674 | zfcp_get_busid_by_port(port), port->handle); | |
2675 | zfcp_erp_modify_port_status(port, | |
2676 | ZFCP_STATUS_COMMON_OPEN, | |
2677 | ZFCP_CLEAR); | |
2678 | retval = 0; | |
2679 | break; | |
2680 | ||
2681 | default: | |
2682 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
2683 | "(debug info 0x%x)\n", | |
2684 | fsf_req->qtcb->header.fsf_status); | |
2685 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); | |
2686 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
2687 | &fsf_req->qtcb->header.fsf_status, | |
2688 | sizeof (u32)); | |
2689 | break; | |
2690 | } | |
2691 | ||
2692 | skip_fsfstatus: | |
2693 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status); | |
2694 | return retval; | |
2695 | } | |
2696 | ||
2697 | /* | |
2698 | * function: zfcp_fsf_close_physical_port | |
2699 | * | |
2700 | * purpose: submit FSF command "close physical port" | |
2701 | * | |
2702 | * returns: address of initiated FSF request | |
2703 | * NULL - request could not be initiated | |
2704 | */ | |
2705 | int | |
2706 | zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action) | |
2707 | { | |
2708 | int retval = 0; | |
2709 | unsigned long lock_flags; | |
2710 | volatile struct qdio_buffer_element *sbale; | |
2711 | ||
2712 | /* setup new FSF request */ | |
2713 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
2714 | FSF_QTCB_CLOSE_PHYSICAL_PORT, | |
2715 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
2716 | erp_action->adapter->pool.fsf_req_erp, | |
2717 | &lock_flags, &erp_action->fsf_req); | |
2718 | if (retval < 0) { | |
2719 | ZFCP_LOG_INFO("error: Could not create close physical port " | |
2720 | "request (adapter %s, port 0x%016Lx)\n", | |
2721 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2722 | erp_action->port->wwpn); | |
2723 | ||
2724 | goto out; | |
2725 | } | |
2726 | ||
2727 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
2728 | erp_action->fsf_req->sbal_curr, 0); | |
2729 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
2730 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
2731 | ||
2732 | /* mark port as being closed */ | |
2733 | atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, | |
2734 | &erp_action->port->status); | |
2735 | /* save a pointer to this port */ | |
059c97d0 | 2736 | erp_action->fsf_req->data = (unsigned long) erp_action->port; |
aef4a983 | 2737 | /* port to be closed */ |
1da177e4 LT |
2738 | erp_action->fsf_req->qtcb->header.port_handle = |
2739 | erp_action->port->handle; | |
2740 | erp_action->fsf_req->erp_action = erp_action; | |
2741 | ||
2742 | /* start QDIO request for this FSF request */ | |
2743 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
2744 | if (retval) { | |
2745 | ZFCP_LOG_INFO("error: Could not send close physical port " | |
2746 | "request (adapter %s, port 0x%016Lx)\n", | |
2747 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2748 | erp_action->port->wwpn); | |
2749 | zfcp_fsf_req_free(erp_action->fsf_req); | |
2750 | erp_action->fsf_req = NULL; | |
2751 | goto out; | |
2752 | } | |
2753 | ||
2754 | ZFCP_LOG_TRACE("close physical port request initiated " | |
2755 | "(adapter %s, port 0x%016Lx)\n", | |
2756 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2757 | erp_action->port->wwpn); | |
2758 | out: | |
2759 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
2760 | lock_flags); | |
2761 | return retval; | |
2762 | } | |
2763 | ||
2764 | /* | |
2765 | * function: zfcp_fsf_close_physical_port_handler | |
2766 | * | |
2767 | * purpose: is called for finished Close Physical Port FSF command | |
2768 | * | |
2769 | * returns: | |
2770 | */ | |
2771 | static int | |
2772 | zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req) | |
2773 | { | |
2774 | int retval = -EINVAL; | |
2775 | struct zfcp_port *port; | |
2776 | struct zfcp_unit *unit; | |
2777 | struct fsf_qtcb_header *header; | |
2778 | u16 subtable, rule, counter; | |
2779 | ||
059c97d0 | 2780 | port = (struct zfcp_port *) fsf_req->data; |
1da177e4 LT |
2781 | header = &fsf_req->qtcb->header; |
2782 | ||
2783 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
2784 | /* don't change port status in our bookkeeping */ | |
2785 | goto skip_fsfstatus; | |
2786 | } | |
2787 | ||
2788 | /* evaluate FSF status in QTCB */ | |
2789 | switch (header->fsf_status) { | |
2790 | ||
2791 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
2792 | ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid" |
2793 | "(adapter %s, port 0x%016Lx). " | |
2794 | "This may happen occasionally.\n", | |
2795 | port->handle, | |
2796 | zfcp_get_busid_by_port(port), | |
2797 | port->wwpn); | |
2798 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
2799 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
2800 | (char *) &header->fsf_status_qual, | |
2801 | sizeof (union fsf_status_qual)); | |
2802 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
2803 | "fsf_s_phand_nv"); | |
2804 | zfcp_erp_adapter_reopen(port->adapter, 0); | |
2805 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2806 | break; | |
2807 | ||
2808 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
2809 | ZFCP_LOG_NORMAL("Access denied, cannot close " |
2810 | "physical port 0x%016Lx on adapter %s\n", | |
2811 | port->wwpn, zfcp_get_busid_by_port(port)); | |
2812 | for (counter = 0; counter < 2; counter++) { | |
2813 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
2814 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
2815 | switch (subtable) { | |
2816 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
2817 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
2818 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
2819 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
2820 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
2821 | zfcp_act_subtable_type[subtable], rule); | |
2822 | break; | |
2823 | } | |
2824 | } | |
2825 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); | |
2826 | zfcp_erp_port_access_denied(port); | |
2827 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2828 | break; | |
2829 | ||
2830 | case FSF_PORT_BOXED: | |
1da177e4 LT |
2831 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter " |
2832 | "%s needs to be reopened but it was attempted " | |
2833 | "to close it physically.\n", | |
2834 | port->wwpn, | |
2835 | zfcp_get_busid_by_port(port)); | |
2836 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed"); | |
d736a27b | 2837 | zfcp_erp_port_boxed(port); |
1da177e4 LT |
2838 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
2839 | ZFCP_STATUS_FSFREQ_RETRY; | |
2840 | break; | |
2841 | ||
2842 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
2843 | switch (header->fsf_status_qual.word[0]) { |
2844 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
2845 | debug_text_event(fsf_req->adapter->erp_dbf, 1, |
2846 | "fsf_sq_ltest"); | |
2847 | /* This will now be escalated by ERP */ | |
2848 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2849 | break; | |
2850 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
2851 | /* ERP strategy will escalate */ |
2852 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
2853 | "fsf_sq_ulp"); | |
2854 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
2855 | break; | |
2856 | default: | |
2857 | ZFCP_LOG_NORMAL | |
2858 | ("bug: Wrong status qualifier 0x%x arrived.\n", | |
2859 | header->fsf_status_qual.word[0]); | |
2860 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
2861 | "fsf_sq_inval:"); | |
2862 | debug_exception( | |
2863 | fsf_req->adapter->erp_dbf, 0, | |
2864 | &header->fsf_status_qual.word[0], sizeof (u32)); | |
2865 | break; | |
2866 | } | |
2867 | break; | |
2868 | ||
2869 | case FSF_GOOD: | |
1da177e4 LT |
2870 | ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s " |
2871 | "physically closed, port handle 0x%x\n", | |
2872 | port->wwpn, | |
2873 | zfcp_get_busid_by_port(port), port->handle); | |
2874 | /* can't use generic zfcp_erp_modify_port_status because | |
2875 | * ZFCP_STATUS_COMMON_OPEN must not be reset for the port | |
2876 | */ | |
2877 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); | |
2878 | list_for_each_entry(unit, &port->unit_list_head, list) | |
2879 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | |
2880 | retval = 0; | |
2881 | break; | |
2882 | ||
2883 | default: | |
2884 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
2885 | "(debug info 0x%x)\n", | |
2886 | header->fsf_status); | |
2887 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); | |
2888 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
2889 | &header->fsf_status, sizeof (u32)); | |
2890 | break; | |
2891 | } | |
2892 | ||
2893 | skip_fsfstatus: | |
2894 | atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status); | |
2895 | return retval; | |
2896 | } | |
2897 | ||
2898 | /* | |
2899 | * function: zfcp_fsf_open_unit | |
2900 | * | |
2901 | * purpose: | |
2902 | * | |
2903 | * returns: | |
2904 | * | |
2905 | * assumptions: This routine does not check whether the associated | |
2906 | * remote port has already been opened. This should be | |
2907 | * done by calling routines. Otherwise some status | |
2908 | * may be presented by FSF | |
2909 | */ | |
2910 | int | |
2911 | zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action) | |
2912 | { | |
2913 | volatile struct qdio_buffer_element *sbale; | |
2914 | unsigned long lock_flags; | |
2915 | int retval = 0; | |
2916 | ||
2917 | /* setup new FSF request */ | |
2918 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
2919 | FSF_QTCB_OPEN_LUN, | |
2920 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
2921 | erp_action->adapter->pool.fsf_req_erp, | |
2922 | &lock_flags, &(erp_action->fsf_req)); | |
2923 | if (retval < 0) { | |
2924 | ZFCP_LOG_INFO("error: Could not create open unit request for " | |
2925 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", | |
2926 | erp_action->unit->fcp_lun, | |
2927 | erp_action->unit->port->wwpn, | |
2928 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
2929 | goto out; | |
2930 | } | |
2931 | ||
2932 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
2933 | erp_action->fsf_req->sbal_curr, 0); | |
2934 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
2935 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
2936 | ||
2937 | erp_action->fsf_req->qtcb->header.port_handle = | |
2938 | erp_action->port->handle; | |
2939 | erp_action->fsf_req->qtcb->bottom.support.fcp_lun = | |
2940 | erp_action->unit->fcp_lun; | |
aef4a983 | 2941 | if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE)) |
1da177e4 LT |
2942 | erp_action->fsf_req->qtcb->bottom.support.option = |
2943 | FSF_OPEN_LUN_SUPPRESS_BOXING; | |
2944 | atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status); | |
059c97d0 | 2945 | erp_action->fsf_req->data = (unsigned long) erp_action->unit; |
1da177e4 LT |
2946 | erp_action->fsf_req->erp_action = erp_action; |
2947 | ||
2948 | /* start QDIO request for this FSF request */ | |
2949 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
2950 | if (retval) { | |
2951 | ZFCP_LOG_INFO("error: Could not send an open unit request " | |
2952 | "on the adapter %s, port 0x%016Lx for " | |
2953 | "unit 0x%016Lx\n", | |
2954 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2955 | erp_action->port->wwpn, | |
2956 | erp_action->unit->fcp_lun); | |
2957 | zfcp_fsf_req_free(erp_action->fsf_req); | |
2958 | erp_action->fsf_req = NULL; | |
2959 | goto out; | |
2960 | } | |
2961 | ||
2962 | ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, " | |
2963 | "port 0x%016Lx, unit 0x%016Lx)\n", | |
2964 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
2965 | erp_action->port->wwpn, erp_action->unit->fcp_lun); | |
2966 | out: | |
2967 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
2968 | lock_flags); | |
2969 | return retval; | |
2970 | } | |
2971 | ||
2972 | /* | |
2973 | * function: zfcp_fsf_open_unit_handler | |
2974 | * | |
2975 | * purpose: is called for finished Open LUN command | |
2976 | * | |
2977 | * returns: | |
2978 | */ | |
2979 | static int | |
2980 | zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req) | |
2981 | { | |
2982 | int retval = -EINVAL; | |
2983 | struct zfcp_adapter *adapter; | |
2984 | struct zfcp_unit *unit; | |
2985 | struct fsf_qtcb_header *header; | |
2986 | struct fsf_qtcb_bottom_support *bottom; | |
2987 | struct fsf_queue_designator *queue_designator; | |
2988 | u16 subtable, rule, counter; | |
aef4a983 | 2989 | int exclusive, readwrite; |
1da177e4 | 2990 | |
059c97d0 | 2991 | unit = (struct zfcp_unit *) fsf_req->data; |
1da177e4 LT |
2992 | |
2993 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
2994 | /* don't change unit status in our bookkeeping */ | |
2995 | goto skip_fsfstatus; | |
2996 | } | |
2997 | ||
2998 | adapter = fsf_req->adapter; | |
2999 | header = &fsf_req->qtcb->header; | |
3000 | bottom = &fsf_req->qtcb->bottom.support; | |
3001 | queue_designator = &header->fsf_status_qual.fsf_queue_designator; | |
3002 | ||
1da177e4 LT |
3003 | atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | |
3004 | ZFCP_STATUS_UNIT_SHARED | | |
3005 | ZFCP_STATUS_UNIT_READONLY, | |
3006 | &unit->status); | |
3007 | ||
3008 | /* evaluate FSF status in QTCB */ | |
3009 | switch (header->fsf_status) { | |
3010 | ||
3011 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
3012 | ZFCP_LOG_INFO("Temporary port identifier 0x%x " |
3013 | "for port 0x%016Lx on adapter %s invalid " | |
3014 | "This may happen occasionally\n", | |
3015 | unit->port->handle, | |
3016 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); | |
3017 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
3018 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3019 | (char *) &header->fsf_status_qual, | |
3020 | sizeof (union fsf_status_qual)); | |
3021 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv"); | |
3022 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); | |
3023 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3024 | break; | |
3025 | ||
3026 | case FSF_LUN_ALREADY_OPEN: | |
1da177e4 LT |
3027 | ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on " |
3028 | "remote port 0x%016Lx on adapter %s twice.\n", | |
3029 | unit->fcp_lun, | |
3030 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); | |
3031 | debug_text_exception(adapter->erp_dbf, 0, | |
3032 | "fsf_s_uopen"); | |
3033 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3034 | break; | |
3035 | ||
3036 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
3037 | ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on " |
3038 | "remote port 0x%016Lx on adapter %s\n", | |
3039 | unit->fcp_lun, unit->port->wwpn, | |
3040 | zfcp_get_busid_by_unit(unit)); | |
3041 | for (counter = 0; counter < 2; counter++) { | |
3042 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
3043 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
3044 | switch (subtable) { | |
3045 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
3046 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
3047 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
3048 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
3049 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
3050 | zfcp_act_subtable_type[subtable], rule); | |
3051 | break; | |
3052 | } | |
3053 | } | |
3054 | debug_text_event(adapter->erp_dbf, 1, "fsf_s_access"); | |
3055 | zfcp_erp_unit_access_denied(unit); | |
3056 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); | |
3057 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); | |
3058 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3059 | break; | |
3060 | ||
3061 | case FSF_PORT_BOXED: | |
1da177e4 LT |
3062 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
3063 | "needs to be reopened\n", | |
3064 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); | |
3065 | debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed"); | |
d736a27b | 3066 | zfcp_erp_port_boxed(unit->port); |
1da177e4 LT |
3067 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
3068 | ZFCP_STATUS_FSFREQ_RETRY; | |
3069 | break; | |
3070 | ||
3071 | case FSF_LUN_SHARING_VIOLATION: | |
1da177e4 LT |
3072 | if (header->fsf_status_qual.word[0] != 0) { |
3073 | ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port " | |
3074 | "with WWPN 0x%Lx " | |
3075 | "connected to the adapter %s " | |
3076 | "is already in use in LPAR%d, CSS%d\n", | |
3077 | unit->fcp_lun, | |
3078 | unit->port->wwpn, | |
3079 | zfcp_get_busid_by_unit(unit), | |
3080 | queue_designator->hla, | |
3081 | queue_designator->cssid); | |
3082 | } else { | |
3083 | subtable = header->fsf_status_qual.halfword[4]; | |
3084 | rule = header->fsf_status_qual.halfword[5]; | |
3085 | switch (subtable) { | |
3086 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
3087 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
3088 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
3089 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
3090 | ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the " | |
3091 | "remote port with WWPN 0x%Lx " | |
3092 | "connected to the adapter %s " | |
3093 | "is denied (%s rule %d)\n", | |
3094 | unit->fcp_lun, | |
3095 | unit->port->wwpn, | |
3096 | zfcp_get_busid_by_unit(unit), | |
3097 | zfcp_act_subtable_type[subtable], | |
3098 | rule); | |
3099 | break; | |
3100 | } | |
3101 | } | |
3102 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
3103 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3104 | (char *) &header->fsf_status_qual, | |
3105 | sizeof (union fsf_status_qual)); | |
3106 | debug_text_event(adapter->erp_dbf, 2, | |
3107 | "fsf_s_l_sh_vio"); | |
3108 | zfcp_erp_unit_access_denied(unit); | |
3109 | atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status); | |
3110 | atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status); | |
3111 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3112 | break; | |
3113 | ||
3114 | case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED: | |
1da177e4 LT |
3115 | ZFCP_LOG_INFO("error: The adapter ran out of resources. " |
3116 | "There is no handle (temporary port identifier) " | |
3117 | "available for unit 0x%016Lx on port 0x%016Lx " | |
3118 | "on adapter %s\n", | |
3119 | unit->fcp_lun, | |
3120 | unit->port->wwpn, | |
3121 | zfcp_get_busid_by_unit(unit)); | |
3122 | debug_text_event(adapter->erp_dbf, 1, | |
3123 | "fsf_s_max_units"); | |
3124 | zfcp_erp_unit_failed(unit); | |
3125 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3126 | break; | |
3127 | ||
3128 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
3129 | switch (header->fsf_status_qual.word[0]) { |
3130 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
3131 | /* Re-establish link to port */ |
3132 | debug_text_event(adapter->erp_dbf, 1, | |
3133 | "fsf_sq_ltest"); | |
65a8d4e1 | 3134 | zfcp_test_link(unit->port); |
1da177e4 LT |
3135 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3136 | break; | |
3137 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
3138 | /* ERP strategy will escalate */ |
3139 | debug_text_event(adapter->erp_dbf, 1, | |
3140 | "fsf_sq_ulp"); | |
3141 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3142 | break; | |
3143 | default: | |
3144 | ZFCP_LOG_NORMAL | |
3145 | ("bug: Wrong status qualifier 0x%x arrived.\n", | |
3146 | header->fsf_status_qual.word[0]); | |
3147 | debug_text_event(adapter->erp_dbf, 0, | |
3148 | "fsf_sq_inval:"); | |
3149 | debug_exception(adapter->erp_dbf, 0, | |
3150 | &header->fsf_status_qual.word[0], | |
3151 | sizeof (u32)); | |
3152 | } | |
3153 | break; | |
3154 | ||
3155 | case FSF_INVALID_COMMAND_OPTION: | |
1da177e4 LT |
3156 | ZFCP_LOG_NORMAL( |
3157 | "Invalid option 0x%x has been specified " | |
3158 | "in QTCB bottom sent to the adapter %s\n", | |
3159 | bottom->option, | |
3160 | zfcp_get_busid_by_adapter(adapter)); | |
3161 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3162 | retval = -EINVAL; | |
3163 | break; | |
3164 | ||
3165 | case FSF_GOOD: | |
1da177e4 LT |
3166 | /* save LUN handle assigned by FSF */ |
3167 | unit->handle = header->lun_handle; | |
3168 | ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on " | |
3169 | "adapter %s opened, port handle 0x%x\n", | |
3170 | unit->fcp_lun, | |
3171 | unit->port->wwpn, | |
3172 | zfcp_get_busid_by_unit(unit), | |
3173 | unit->handle); | |
3174 | /* mark unit as open */ | |
3175 | atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | |
aef4a983 MS |
3176 | |
3177 | if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) && | |
3178 | (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) && | |
3179 | (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) { | |
3180 | exclusive = (bottom->lun_access_info & | |
3181 | FSF_UNIT_ACCESS_EXCLUSIVE); | |
3182 | readwrite = (bottom->lun_access_info & | |
3183 | FSF_UNIT_ACCESS_OUTBOUND_TRANSFER); | |
3184 | ||
1da177e4 LT |
3185 | if (!exclusive) |
3186 | atomic_set_mask(ZFCP_STATUS_UNIT_SHARED, | |
3187 | &unit->status); | |
3188 | ||
3189 | if (!readwrite) { | |
3190 | atomic_set_mask(ZFCP_STATUS_UNIT_READONLY, | |
3191 | &unit->status); | |
3192 | ZFCP_LOG_NORMAL("read-only access for unit " | |
3193 | "(adapter %s, wwpn=0x%016Lx, " | |
3194 | "fcp_lun=0x%016Lx)\n", | |
3195 | zfcp_get_busid_by_unit(unit), | |
3196 | unit->port->wwpn, | |
3197 | unit->fcp_lun); | |
3198 | } | |
3199 | ||
3200 | if (exclusive && !readwrite) { | |
3201 | ZFCP_LOG_NORMAL("exclusive access of read-only " | |
3202 | "unit not supported\n"); | |
3203 | zfcp_erp_unit_failed(unit); | |
3204 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3205 | zfcp_erp_unit_shutdown(unit, 0); | |
3206 | } else if (!exclusive && readwrite) { | |
3207 | ZFCP_LOG_NORMAL("shared access of read-write " | |
3208 | "unit not supported\n"); | |
3209 | zfcp_erp_unit_failed(unit); | |
3210 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3211 | zfcp_erp_unit_shutdown(unit, 0); | |
3212 | } | |
3213 | } | |
3214 | ||
3215 | retval = 0; | |
3216 | break; | |
3217 | ||
3218 | default: | |
3219 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
3220 | "(debug info 0x%x)\n", | |
3221 | header->fsf_status); | |
3222 | debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:"); | |
3223 | debug_exception(adapter->erp_dbf, 0, | |
3224 | &header->fsf_status, sizeof (u32)); | |
3225 | break; | |
3226 | } | |
3227 | ||
3228 | skip_fsfstatus: | |
3229 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status); | |
3230 | return retval; | |
3231 | } | |
3232 | ||
3233 | /* | |
3234 | * function: zfcp_fsf_close_unit | |
3235 | * | |
3236 | * purpose: | |
3237 | * | |
3238 | * returns: address of fsf_req - request successfully initiated | |
3239 | * NULL - | |
3240 | * | |
3241 | * assumptions: This routine does not check whether the associated | |
3242 | * remote port/lun has already been opened. This should be | |
3243 | * done by calling routines. Otherwise some status | |
3244 | * may be presented by FSF | |
3245 | */ | |
3246 | int | |
3247 | zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action) | |
3248 | { | |
3249 | volatile struct qdio_buffer_element *sbale; | |
3250 | unsigned long lock_flags; | |
3251 | int retval = 0; | |
3252 | ||
3253 | /* setup new FSF request */ | |
3254 | retval = zfcp_fsf_req_create(erp_action->adapter, | |
3255 | FSF_QTCB_CLOSE_LUN, | |
3256 | ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP, | |
3257 | erp_action->adapter->pool.fsf_req_erp, | |
3258 | &lock_flags, &(erp_action->fsf_req)); | |
3259 | if (retval < 0) { | |
3260 | ZFCP_LOG_INFO("error: Could not create close unit request for " | |
3261 | "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n", | |
3262 | erp_action->unit->fcp_lun, | |
3263 | erp_action->port->wwpn, | |
3264 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
3265 | goto out; | |
3266 | } | |
3267 | ||
3268 | sbale = zfcp_qdio_sbale_req(erp_action->fsf_req, | |
3269 | erp_action->fsf_req->sbal_curr, 0); | |
3270 | sbale[0].flags |= SBAL_FLAGS0_TYPE_READ; | |
3271 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
3272 | ||
3273 | erp_action->fsf_req->qtcb->header.port_handle = | |
3274 | erp_action->port->handle; | |
3275 | erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle; | |
3276 | atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status); | |
059c97d0 | 3277 | erp_action->fsf_req->data = (unsigned long) erp_action->unit; |
1da177e4 LT |
3278 | erp_action->fsf_req->erp_action = erp_action; |
3279 | ||
3280 | /* start QDIO request for this FSF request */ | |
3281 | retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer); | |
3282 | if (retval) { | |
3283 | ZFCP_LOG_INFO("error: Could not send a close unit request for " | |
3284 | "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n", | |
3285 | erp_action->unit->fcp_lun, | |
3286 | erp_action->port->wwpn, | |
3287 | zfcp_get_busid_by_adapter(erp_action->adapter)); | |
3288 | zfcp_fsf_req_free(erp_action->fsf_req); | |
3289 | erp_action->fsf_req = NULL; | |
3290 | goto out; | |
3291 | } | |
3292 | ||
3293 | ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, " | |
3294 | "port 0x%016Lx, unit 0x%016Lx)\n", | |
3295 | zfcp_get_busid_by_adapter(erp_action->adapter), | |
3296 | erp_action->port->wwpn, erp_action->unit->fcp_lun); | |
3297 | out: | |
3298 | write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock, | |
3299 | lock_flags); | |
3300 | return retval; | |
3301 | } | |
3302 | ||
3303 | /* | |
3304 | * function: zfcp_fsf_close_unit_handler | |
3305 | * | |
3306 | * purpose: is called for finished Close LUN FSF command | |
3307 | * | |
3308 | * returns: | |
3309 | */ | |
3310 | static int | |
3311 | zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req) | |
3312 | { | |
3313 | int retval = -EINVAL; | |
3314 | struct zfcp_unit *unit; | |
3315 | ||
059c97d0 | 3316 | unit = (struct zfcp_unit *) fsf_req->data; |
1da177e4 LT |
3317 | |
3318 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
3319 | /* don't change unit status in our bookkeeping */ | |
3320 | goto skip_fsfstatus; | |
3321 | } | |
3322 | ||
3323 | /* evaluate FSF status in QTCB */ | |
3324 | switch (fsf_req->qtcb->header.fsf_status) { | |
3325 | ||
3326 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
3327 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
3328 | "0x%016Lx on adapter %s invalid. This may " | |
3329 | "happen in rare circumstances\n", | |
3330 | unit->port->handle, | |
3331 | unit->port->wwpn, | |
3332 | zfcp_get_busid_by_unit(unit)); | |
3333 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
3334 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3335 | (char *) &fsf_req->qtcb->header.fsf_status_qual, | |
3336 | sizeof (union fsf_status_qual)); | |
3337 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3338 | "fsf_s_phand_nv"); | |
3339 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); | |
1da177e4 LT |
3340 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3341 | break; | |
3342 | ||
3343 | case FSF_LUN_HANDLE_NOT_VALID: | |
1da177e4 LT |
3344 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit " |
3345 | "0x%016Lx on port 0x%016Lx on adapter %s is " | |
3346 | "invalid. This may happen occasionally.\n", | |
3347 | unit->handle, | |
3348 | unit->fcp_lun, | |
3349 | unit->port->wwpn, | |
3350 | zfcp_get_busid_by_unit(unit)); | |
3351 | ZFCP_LOG_DEBUG("Status qualifier data:\n"); | |
3352 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3353 | (char *) &fsf_req->qtcb->header.fsf_status_qual, | |
3354 | sizeof (union fsf_status_qual)); | |
3355 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3356 | "fsf_s_lhand_nv"); | |
3357 | zfcp_erp_port_reopen(unit->port, 0); | |
1da177e4 LT |
3358 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3359 | break; | |
3360 | ||
3361 | case FSF_PORT_BOXED: | |
1da177e4 LT |
3362 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
3363 | "needs to be reopened\n", | |
3364 | unit->port->wwpn, | |
3365 | zfcp_get_busid_by_unit(unit)); | |
3366 | debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed"); | |
d736a27b | 3367 | zfcp_erp_port_boxed(unit->port); |
1da177e4 LT |
3368 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
3369 | ZFCP_STATUS_FSFREQ_RETRY; | |
3370 | break; | |
3371 | ||
3372 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
3373 | switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) { |
3374 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
3375 | /* re-establish link to port */ |
3376 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3377 | "fsf_sq_ltest"); | |
65a8d4e1 | 3378 | zfcp_test_link(unit->port); |
1da177e4 LT |
3379 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3380 | break; | |
3381 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
3382 | /* ERP strategy will escalate */ |
3383 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3384 | "fsf_sq_ulp"); | |
3385 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3386 | break; | |
3387 | default: | |
3388 | ZFCP_LOG_NORMAL | |
3389 | ("bug: Wrong status qualifier 0x%x arrived.\n", | |
3390 | fsf_req->qtcb->header.fsf_status_qual.word[0]); | |
3391 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
3392 | "fsf_sq_inval:"); | |
3393 | debug_exception( | |
3394 | fsf_req->adapter->erp_dbf, 0, | |
3395 | &fsf_req->qtcb->header.fsf_status_qual.word[0], | |
3396 | sizeof (u32)); | |
3397 | break; | |
3398 | } | |
3399 | break; | |
3400 | ||
3401 | case FSF_GOOD: | |
1da177e4 LT |
3402 | ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s " |
3403 | "closed, port handle 0x%x\n", | |
3404 | unit->fcp_lun, | |
3405 | unit->port->wwpn, | |
3406 | zfcp_get_busid_by_unit(unit), | |
3407 | unit->handle); | |
3408 | /* mark unit as closed */ | |
3409 | atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status); | |
3410 | retval = 0; | |
3411 | break; | |
3412 | ||
3413 | default: | |
3414 | ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented " | |
3415 | "(debug info 0x%x)\n", | |
3416 | fsf_req->qtcb->header.fsf_status); | |
3417 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); | |
3418 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
3419 | &fsf_req->qtcb->header.fsf_status, | |
3420 | sizeof (u32)); | |
3421 | break; | |
3422 | } | |
3423 | ||
3424 | skip_fsfstatus: | |
3425 | atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status); | |
3426 | return retval; | |
3427 | } | |
3428 | ||
3429 | /** | |
3430 | * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command) | |
3431 | * @adapter: adapter where scsi command is issued | |
3432 | * @unit: unit where command is sent to | |
3433 | * @scsi_cmnd: scsi command to be sent | |
3434 | * @timer: timer to be started when request is initiated | |
3435 | * @req_flags: flags for fsf_request | |
3436 | */ | |
3437 | int | |
3438 | zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter, | |
3439 | struct zfcp_unit *unit, | |
3440 | struct scsi_cmnd * scsi_cmnd, | |
3441 | struct timer_list *timer, int req_flags) | |
3442 | { | |
3443 | struct zfcp_fsf_req *fsf_req = NULL; | |
3444 | struct fcp_cmnd_iu *fcp_cmnd_iu; | |
3445 | unsigned int sbtype; | |
3446 | unsigned long lock_flags; | |
3447 | int real_bytes = 0; | |
3448 | int retval = 0; | |
3449 | int mask; | |
3450 | ||
3451 | /* setup new FSF request */ | |
3452 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, | |
3453 | adapter->pool.fsf_req_scsi, | |
3454 | &lock_flags, &fsf_req); | |
3455 | if (unlikely(retval < 0)) { | |
3456 | ZFCP_LOG_DEBUG("error: Could not create FCP command request " | |
3457 | "for unit 0x%016Lx on port 0x%016Lx on " | |
3458 | "adapter %s\n", | |
3459 | unit->fcp_lun, | |
3460 | unit->port->wwpn, | |
3461 | zfcp_get_busid_by_adapter(adapter)); | |
3462 | goto failed_req_create; | |
3463 | } | |
3464 | ||
059c97d0 AH |
3465 | zfcp_unit_get(unit); |
3466 | fsf_req->unit = unit; | |
1da177e4 | 3467 | |
059c97d0 AH |
3468 | /* associate FSF request with SCSI request (for look up on abort) */ |
3469 | scsi_cmnd->host_scribble = (char *) fsf_req; | |
3470 | ||
3471 | /* associate SCSI command with FSF request */ | |
3472 | fsf_req->data = (unsigned long) scsi_cmnd; | |
1da177e4 LT |
3473 | |
3474 | /* set handles of unit and its parent port in QTCB */ | |
3475 | fsf_req->qtcb->header.lun_handle = unit->handle; | |
3476 | fsf_req->qtcb->header.port_handle = unit->port->handle; | |
3477 | ||
3478 | /* FSF does not define the structure of the FCP_CMND IU */ | |
3479 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) | |
3480 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); | |
3481 | ||
3482 | /* | |
3483 | * set depending on data direction: | |
3484 | * data direction bits in SBALE (SB Type) | |
3485 | * data direction bits in QTCB | |
3486 | * data direction bits in FCP_CMND IU | |
3487 | */ | |
3488 | switch (scsi_cmnd->sc_data_direction) { | |
3489 | case DMA_NONE: | |
1da177e4 LT |
3490 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; |
3491 | /* | |
3492 | * FIXME(qdio): | |
3493 | * what is the correct type for commands | |
3494 | * without 'real' data buffers? | |
3495 | */ | |
3496 | sbtype = SBAL_FLAGS0_TYPE_READ; | |
3497 | break; | |
3498 | case DMA_FROM_DEVICE: | |
1da177e4 LT |
3499 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ; |
3500 | sbtype = SBAL_FLAGS0_TYPE_READ; | |
3501 | fcp_cmnd_iu->rddata = 1; | |
3502 | break; | |
3503 | case DMA_TO_DEVICE: | |
1da177e4 LT |
3504 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE; |
3505 | sbtype = SBAL_FLAGS0_TYPE_WRITE; | |
3506 | fcp_cmnd_iu->wddata = 1; | |
3507 | break; | |
3508 | case DMA_BIDIRECTIONAL: | |
1da177e4 LT |
3509 | default: |
3510 | /* | |
3511 | * dummy, catch this condition earlier | |
3512 | * in zfcp_scsi_queuecommand | |
3513 | */ | |
3514 | goto failed_scsi_cmnd; | |
3515 | } | |
3516 | ||
3517 | /* set FC service class in QTCB (3 per default) */ | |
3518 | fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class; | |
3519 | ||
3520 | /* set FCP_LUN in FCP_CMND IU in QTCB */ | |
3521 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | |
3522 | ||
3523 | mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED; | |
3524 | ||
3525 | /* set task attributes in FCP_CMND IU in QTCB */ | |
3526 | if (likely((scsi_cmnd->device->simple_tags) || | |
3527 | (atomic_test_mask(mask, &unit->status)))) | |
3528 | fcp_cmnd_iu->task_attribute = SIMPLE_Q; | |
3529 | else | |
3530 | fcp_cmnd_iu->task_attribute = UNTAGGED; | |
3531 | ||
3532 | /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */ | |
3533 | if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) { | |
3534 | fcp_cmnd_iu->add_fcp_cdb_length | |
3535 | = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2; | |
3536 | ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, " | |
3537 | "additional FCP_CDB length is 0x%x " | |
3538 | "(shifted right 2 bits)\n", | |
3539 | scsi_cmnd->cmd_len, | |
3540 | fcp_cmnd_iu->add_fcp_cdb_length); | |
3541 | } | |
3542 | /* | |
3543 | * copy SCSI CDB (including additional length, if any) to | |
3544 | * FCP_CDB in FCP_CMND IU in QTCB | |
3545 | */ | |
3546 | memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len); | |
3547 | ||
3548 | /* FCP CMND IU length in QTCB */ | |
3549 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = | |
3550 | sizeof (struct fcp_cmnd_iu) + | |
3551 | fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t); | |
3552 | ||
3553 | /* generate SBALEs from data buffer */ | |
3554 | real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd); | |
3555 | if (unlikely(real_bytes < 0)) { | |
3556 | if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) { | |
3557 | ZFCP_LOG_DEBUG( | |
3558 | "Data did not fit into available buffer(s), " | |
3559 | "waiting for more...\n"); | |
3560 | retval = -EIO; | |
3561 | } else { | |
3562 | ZFCP_LOG_NORMAL("error: No truncation implemented but " | |
3563 | "required. Shutting down unit " | |
3564 | "(adapter %s, port 0x%016Lx, " | |
3565 | "unit 0x%016Lx)\n", | |
3566 | zfcp_get_busid_by_unit(unit), | |
3567 | unit->port->wwpn, | |
3568 | unit->fcp_lun); | |
3569 | zfcp_erp_unit_shutdown(unit, 0); | |
3570 | retval = -EINVAL; | |
3571 | } | |
3572 | goto no_fit; | |
3573 | } | |
3574 | ||
3575 | /* set length of FCP data length in FCP_CMND IU in QTCB */ | |
3576 | zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes); | |
3577 | ||
3578 | ZFCP_LOG_DEBUG("Sending SCSI command:\n"); | |
3579 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3580 | (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len); | |
3581 | ||
3582 | /* | |
3583 | * start QDIO request for this FSF request | |
3584 | * covered by an SBALE) | |
3585 | */ | |
3586 | retval = zfcp_fsf_req_send(fsf_req, timer); | |
3587 | if (unlikely(retval < 0)) { | |
3588 | ZFCP_LOG_INFO("error: Could not send FCP command request " | |
3589 | "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n", | |
3590 | zfcp_get_busid_by_adapter(adapter), | |
3591 | unit->port->wwpn, | |
3592 | unit->fcp_lun); | |
3593 | goto send_failed; | |
3594 | } | |
3595 | ||
3596 | ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, " | |
3597 | "port 0x%016Lx, unit 0x%016Lx)\n", | |
3598 | zfcp_get_busid_by_adapter(adapter), | |
3599 | unit->port->wwpn, | |
3600 | unit->fcp_lun); | |
3601 | goto success; | |
3602 | ||
3603 | send_failed: | |
3604 | no_fit: | |
3605 | failed_scsi_cmnd: | |
059c97d0 | 3606 | zfcp_unit_put(unit); |
1da177e4 LT |
3607 | zfcp_fsf_req_free(fsf_req); |
3608 | fsf_req = NULL; | |
3609 | scsi_cmnd->host_scribble = NULL; | |
3610 | success: | |
3611 | failed_req_create: | |
3612 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
3613 | return retval; | |
3614 | } | |
3615 | ||
3616 | /* | |
3617 | * function: zfcp_fsf_send_fcp_command_task_management | |
3618 | * | |
3619 | * purpose: | |
3620 | * | |
3621 | * returns: | |
3622 | * | |
3623 | * FIXME(design): should be watched by a timeout!!! | |
3624 | * FIXME(design) shouldn't this be modified to return an int | |
3625 | * also...don't know how though | |
3626 | * | |
3627 | */ | |
3628 | struct zfcp_fsf_req * | |
3629 | zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter, | |
3630 | struct zfcp_unit *unit, | |
3631 | u8 tm_flags, int req_flags) | |
3632 | { | |
3633 | struct zfcp_fsf_req *fsf_req = NULL; | |
3634 | int retval = 0; | |
3635 | struct fcp_cmnd_iu *fcp_cmnd_iu; | |
3636 | unsigned long lock_flags; | |
3637 | volatile struct qdio_buffer_element *sbale; | |
3638 | ||
3639 | /* setup new FSF request */ | |
3640 | retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags, | |
3641 | adapter->pool.fsf_req_scsi, | |
3642 | &lock_flags, &fsf_req); | |
3643 | if (retval < 0) { | |
3644 | ZFCP_LOG_INFO("error: Could not create FCP command (task " | |
3645 | "management) request for adapter %s, port " | |
3646 | " 0x%016Lx, unit 0x%016Lx.\n", | |
3647 | zfcp_get_busid_by_adapter(adapter), | |
3648 | unit->port->wwpn, unit->fcp_lun); | |
3649 | goto out; | |
3650 | } | |
3651 | ||
3652 | /* | |
3653 | * Used to decide on proper handler in the return path, | |
3654 | * could be either zfcp_fsf_send_fcp_command_task_handler or | |
3655 | * zfcp_fsf_send_fcp_command_task_management_handler */ | |
3656 | ||
3657 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT; | |
3658 | ||
3659 | /* | |
3660 | * hold a pointer to the unit being target of this | |
3661 | * task management request | |
3662 | */ | |
059c97d0 | 3663 | fsf_req->data = (unsigned long) unit; |
1da177e4 LT |
3664 | |
3665 | /* set FSF related fields in QTCB */ | |
3666 | fsf_req->qtcb->header.lun_handle = unit->handle; | |
3667 | fsf_req->qtcb->header.port_handle = unit->port->handle; | |
3668 | fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND; | |
3669 | fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class; | |
3670 | fsf_req->qtcb->bottom.io.fcp_cmnd_length = | |
3671 | sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t); | |
3672 | ||
3673 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
3674 | sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE; | |
3675 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
3676 | ||
3677 | /* set FCP related fields in FCP_CMND IU in QTCB */ | |
3678 | fcp_cmnd_iu = (struct fcp_cmnd_iu *) | |
3679 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); | |
3680 | fcp_cmnd_iu->fcp_lun = unit->fcp_lun; | |
3681 | fcp_cmnd_iu->task_management_flags = tm_flags; | |
3682 | ||
3683 | /* start QDIO request for this FSF request */ | |
3684 | zfcp_fsf_start_scsi_er_timer(adapter); | |
3685 | retval = zfcp_fsf_req_send(fsf_req, NULL); | |
3686 | if (retval) { | |
3687 | del_timer(&adapter->scsi_er_timer); | |
3688 | ZFCP_LOG_INFO("error: Could not send an FCP-command (task " | |
3689 | "management) on adapter %s, port 0x%016Lx for " | |
3690 | "unit LUN 0x%016Lx\n", | |
3691 | zfcp_get_busid_by_adapter(adapter), | |
3692 | unit->port->wwpn, | |
3693 | unit->fcp_lun); | |
3694 | zfcp_fsf_req_free(fsf_req); | |
3695 | fsf_req = NULL; | |
3696 | goto out; | |
3697 | } | |
3698 | ||
3699 | ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated " | |
3700 | "(adapter %s, port 0x%016Lx, unit 0x%016Lx, " | |
3701 | "tm_flags=0x%x)\n", | |
3702 | zfcp_get_busid_by_adapter(adapter), | |
3703 | unit->port->wwpn, | |
3704 | unit->fcp_lun, | |
3705 | tm_flags); | |
3706 | out: | |
3707 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
3708 | return fsf_req; | |
3709 | } | |
3710 | ||
3711 | /* | |
3712 | * function: zfcp_fsf_send_fcp_command_handler | |
3713 | * | |
3714 | * purpose: is called for finished Send FCP Command | |
3715 | * | |
3716 | * returns: | |
3717 | */ | |
3718 | static int | |
3719 | zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req) | |
3720 | { | |
3721 | int retval = -EINVAL; | |
3722 | struct zfcp_unit *unit; | |
3723 | struct fsf_qtcb_header *header; | |
3724 | u16 subtable, rule, counter; | |
3725 | ||
3726 | header = &fsf_req->qtcb->header; | |
3727 | ||
3728 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)) | |
059c97d0 | 3729 | unit = (struct zfcp_unit *) fsf_req->data; |
1da177e4 | 3730 | else |
059c97d0 | 3731 | unit = fsf_req->unit; |
1da177e4 LT |
3732 | |
3733 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { | |
3734 | /* go directly to calls of special handlers */ | |
3735 | goto skip_fsfstatus; | |
3736 | } | |
3737 | ||
3738 | /* evaluate FSF status in QTCB */ | |
3739 | switch (header->fsf_status) { | |
3740 | ||
3741 | case FSF_PORT_HANDLE_NOT_VALID: | |
1da177e4 LT |
3742 | ZFCP_LOG_INFO("Temporary port identifier 0x%x for port " |
3743 | "0x%016Lx on adapter %s invalid\n", | |
3744 | unit->port->handle, | |
3745 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); | |
3746 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3747 | (char *) &header->fsf_status_qual, | |
3748 | sizeof (union fsf_status_qual)); | |
3749 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3750 | "fsf_s_phand_nv"); | |
3751 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); | |
3752 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3753 | break; | |
3754 | ||
3755 | case FSF_LUN_HANDLE_NOT_VALID: | |
1da177e4 LT |
3756 | ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit " |
3757 | "0x%016Lx on port 0x%016Lx on adapter %s is " | |
3758 | "invalid. This may happen occasionally.\n", | |
3759 | unit->handle, | |
3760 | unit->fcp_lun, | |
3761 | unit->port->wwpn, | |
3762 | zfcp_get_busid_by_unit(unit)); | |
3763 | ZFCP_LOG_NORMAL("Status qualifier data:\n"); | |
3764 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, | |
3765 | (char *) &header->fsf_status_qual, | |
3766 | sizeof (union fsf_status_qual)); | |
3767 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3768 | "fsf_s_uhand_nv"); | |
3769 | zfcp_erp_port_reopen(unit->port, 0); | |
3770 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3771 | break; | |
3772 | ||
3773 | case FSF_HANDLE_MISMATCH: | |
1da177e4 LT |
3774 | ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed " |
3775 | "unexpectedly. (adapter %s, port 0x%016Lx, " | |
3776 | "unit 0x%016Lx)\n", | |
3777 | unit->port->handle, | |
3778 | zfcp_get_busid_by_unit(unit), | |
3779 | unit->port->wwpn, | |
3780 | unit->fcp_lun); | |
3781 | ZFCP_LOG_NORMAL("status qualifier:\n"); | |
3782 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, | |
3783 | (char *) &header->fsf_status_qual, | |
3784 | sizeof (union fsf_status_qual)); | |
3785 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3786 | "fsf_s_hand_mis"); | |
3787 | zfcp_erp_adapter_reopen(unit->port->adapter, 0); | |
1da177e4 LT |
3788 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3789 | break; | |
3790 | ||
3791 | case FSF_SERVICE_CLASS_NOT_SUPPORTED: | |
1da177e4 LT |
3792 | if (fsf_req->adapter->fc_service_class <= 3) { |
3793 | ZFCP_LOG_NORMAL("error: The adapter %s does " | |
3794 | "not support fibrechannel class %d.\n", | |
3795 | zfcp_get_busid_by_unit(unit), | |
3796 | fsf_req->adapter->fc_service_class); | |
3797 | } else { | |
3798 | ZFCP_LOG_NORMAL("bug: The fibrechannel class at " | |
3799 | "adapter %s is invalid. " | |
3800 | "(debug info %d)\n", | |
3801 | zfcp_get_busid_by_unit(unit), | |
3802 | fsf_req->adapter->fc_service_class); | |
3803 | } | |
3804 | /* stop operation for this adapter */ | |
3805 | debug_text_exception(fsf_req->adapter->erp_dbf, 0, | |
3806 | "fsf_s_class_nsup"); | |
3807 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); | |
1da177e4 LT |
3808 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3809 | break; | |
3810 | ||
3811 | case FSF_FCPLUN_NOT_VALID: | |
1da177e4 LT |
3812 | ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on " |
3813 | "adapter %s does not have correct unit " | |
3814 | "handle 0x%x\n", | |
3815 | unit->fcp_lun, | |
3816 | unit->port->wwpn, | |
3817 | zfcp_get_busid_by_unit(unit), | |
3818 | unit->handle); | |
3819 | ZFCP_LOG_DEBUG("status qualifier:\n"); | |
3820 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
3821 | (char *) &header->fsf_status_qual, | |
3822 | sizeof (union fsf_status_qual)); | |
3823 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3824 | "fsf_s_fcp_lun_nv"); | |
3825 | zfcp_erp_port_reopen(unit->port, 0); | |
1da177e4 LT |
3826 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3827 | break; | |
3828 | ||
3829 | case FSF_ACCESS_DENIED: | |
1da177e4 LT |
3830 | ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to " |
3831 | "unit 0x%016Lx on port 0x%016Lx on " | |
3832 | "adapter %s\n", unit->fcp_lun, unit->port->wwpn, | |
3833 | zfcp_get_busid_by_unit(unit)); | |
3834 | for (counter = 0; counter < 2; counter++) { | |
3835 | subtable = header->fsf_status_qual.halfword[counter * 2]; | |
3836 | rule = header->fsf_status_qual.halfword[counter * 2 + 1]; | |
3837 | switch (subtable) { | |
3838 | case FSF_SQ_CFDC_SUBTABLE_OS: | |
3839 | case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN: | |
3840 | case FSF_SQ_CFDC_SUBTABLE_PORT_DID: | |
3841 | case FSF_SQ_CFDC_SUBTABLE_LUN: | |
3842 | ZFCP_LOG_INFO("Access denied (%s rule %d)\n", | |
3843 | zfcp_act_subtable_type[subtable], rule); | |
3844 | break; | |
3845 | } | |
3846 | } | |
3847 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access"); | |
3848 | zfcp_erp_unit_access_denied(unit); | |
3849 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
3850 | break; | |
3851 | ||
3852 | case FSF_DIRECTION_INDICATOR_NOT_VALID: | |
1da177e4 LT |
3853 | ZFCP_LOG_INFO("bug: Invalid data direction given for unit " |
3854 | "0x%016Lx on port 0x%016Lx on adapter %s " | |
3855 | "(debug info %d)\n", | |
3856 | unit->fcp_lun, | |
3857 | unit->port->wwpn, | |
3858 | zfcp_get_busid_by_unit(unit), | |
3859 | fsf_req->qtcb->bottom.io.data_direction); | |
3860 | /* stop operation for this adapter */ | |
3861 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
3862 | "fsf_s_dir_ind_nv"); | |
3863 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); | |
1da177e4 LT |
3864 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3865 | break; | |
3866 | ||
3867 | case FSF_CMND_LENGTH_NOT_VALID: | |
1da177e4 LT |
3868 | ZFCP_LOG_NORMAL |
3869 | ("bug: An invalid control-data-block length field " | |
3870 | "was found in a command for unit 0x%016Lx on port " | |
3871 | "0x%016Lx on adapter %s " "(debug info %d)\n", | |
3872 | unit->fcp_lun, unit->port->wwpn, | |
3873 | zfcp_get_busid_by_unit(unit), | |
3874 | fsf_req->qtcb->bottom.io.fcp_cmnd_length); | |
3875 | /* stop operation for this adapter */ | |
3876 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
3877 | "fsf_s_cmd_len_nv"); | |
3878 | zfcp_erp_adapter_shutdown(unit->port->adapter, 0); | |
1da177e4 LT |
3879 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
3880 | break; | |
3881 | ||
3882 | case FSF_PORT_BOXED: | |
1da177e4 LT |
3883 | ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s " |
3884 | "needs to be reopened\n", | |
3885 | unit->port->wwpn, zfcp_get_busid_by_unit(unit)); | |
3886 | debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed"); | |
d736a27b | 3887 | zfcp_erp_port_boxed(unit->port); |
1da177e4 LT |
3888 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR | |
3889 | ZFCP_STATUS_FSFREQ_RETRY; | |
3890 | break; | |
3891 | ||
3892 | case FSF_LUN_BOXED: | |
1da177e4 LT |
3893 | ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, " |
3894 | "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n", | |
3895 | zfcp_get_busid_by_unit(unit), | |
3896 | unit->port->wwpn, unit->fcp_lun); | |
3897 | debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed"); | |
d736a27b | 3898 | zfcp_erp_unit_boxed(unit); |
1da177e4 LT |
3899 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3900 | | ZFCP_STATUS_FSFREQ_RETRY; | |
3901 | break; | |
3902 | ||
3903 | case FSF_ADAPTER_STATUS_AVAILABLE: | |
1da177e4 LT |
3904 | switch (header->fsf_status_qual.word[0]) { |
3905 | case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: | |
1da177e4 LT |
3906 | /* re-establish link to port */ |
3907 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3908 | "fsf_sq_ltest"); | |
65a8d4e1 | 3909 | zfcp_test_link(unit->port); |
1da177e4 LT |
3910 | break; |
3911 | case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED: | |
1da177e4 LT |
3912 | /* FIXME(hw) need proper specs for proper action */ |
3913 | /* let scsi stack deal with retries and escalation */ | |
3914 | debug_text_event(fsf_req->adapter->erp_dbf, 1, | |
3915 | "fsf_sq_ulp"); | |
1da177e4 LT |
3916 | break; |
3917 | default: | |
1da177e4 | 3918 | ZFCP_LOG_NORMAL |
516a4201 | 3919 | ("Unknown status qualifier 0x%x arrived.\n", |
1da177e4 LT |
3920 | header->fsf_status_qual.word[0]); |
3921 | debug_text_event(fsf_req->adapter->erp_dbf, 0, | |
3922 | "fsf_sq_inval:"); | |
3923 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
3924 | &header->fsf_status_qual.word[0], | |
3925 | sizeof(u32)); | |
3926 | break; | |
3927 | } | |
516a4201 | 3928 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; |
1da177e4 LT |
3929 | break; |
3930 | ||
3931 | case FSF_GOOD: | |
1da177e4 LT |
3932 | break; |
3933 | ||
3934 | case FSF_FCP_RSP_AVAILABLE: | |
1da177e4 LT |
3935 | break; |
3936 | ||
3937 | default: | |
3938 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:"); | |
3939 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
3940 | &header->fsf_status, sizeof(u32)); | |
3941 | break; | |
3942 | } | |
3943 | ||
3944 | skip_fsfstatus: | |
3945 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) { | |
3946 | retval = | |
3947 | zfcp_fsf_send_fcp_command_task_management_handler(fsf_req); | |
3948 | } else { | |
3949 | retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req); | |
059c97d0 AH |
3950 | fsf_req->unit = NULL; |
3951 | zfcp_unit_put(unit); | |
1da177e4 LT |
3952 | } |
3953 | return retval; | |
3954 | } | |
3955 | ||
3956 | /* | |
3957 | * function: zfcp_fsf_send_fcp_command_task_handler | |
3958 | * | |
3959 | * purpose: evaluates FCP_RSP IU | |
3960 | * | |
3961 | * returns: | |
3962 | */ | |
3963 | static int | |
3964 | zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req) | |
3965 | { | |
3966 | int retval = 0; | |
3967 | struct scsi_cmnd *scpnt; | |
3968 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) | |
3969 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | |
3970 | struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *) | |
3971 | &(fsf_req->qtcb->bottom.io.fcp_cmnd); | |
3972 | u32 sns_len; | |
3973 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); | |
3974 | unsigned long flags; | |
059c97d0 | 3975 | struct zfcp_unit *unit = fsf_req->unit; |
1da177e4 LT |
3976 | |
3977 | read_lock_irqsave(&fsf_req->adapter->abort_lock, flags); | |
059c97d0 | 3978 | scpnt = (struct scsi_cmnd *) fsf_req->data; |
1da177e4 LT |
3979 | if (unlikely(!scpnt)) { |
3980 | ZFCP_LOG_DEBUG | |
3981 | ("Command with fsf_req %p is not associated to " | |
3982 | "a scsi command anymore. Aborted?\n", fsf_req); | |
3983 | goto out; | |
3984 | } | |
3985 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) { | |
3986 | /* FIXME: (design) mid-layer should handle DID_ABORT like | |
3987 | * DID_SOFT_ERROR by retrying the request for devices | |
3988 | * that allow retries. | |
3989 | */ | |
3990 | ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n"); | |
3991 | set_host_byte(&scpnt->result, DID_SOFT_ERROR); | |
3992 | set_driver_byte(&scpnt->result, SUGGEST_RETRY); | |
3993 | goto skip_fsfstatus; | |
3994 | } | |
3995 | ||
3996 | if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) { | |
3997 | ZFCP_LOG_DEBUG("Setting DID_ERROR\n"); | |
3998 | set_host_byte(&scpnt->result, DID_ERROR); | |
3999 | goto skip_fsfstatus; | |
4000 | } | |
4001 | ||
4002 | /* set message byte of result in SCSI command */ | |
4003 | scpnt->result |= COMMAND_COMPLETE << 8; | |
4004 | ||
4005 | /* | |
4006 | * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte | |
4007 | * of result in SCSI command | |
4008 | */ | |
4009 | scpnt->result |= fcp_rsp_iu->scsi_status; | |
4010 | if (unlikely(fcp_rsp_iu->scsi_status)) { | |
4011 | /* DEBUG */ | |
4012 | ZFCP_LOG_DEBUG("status for SCSI Command:\n"); | |
4013 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4014 | scpnt->cmnd, scpnt->cmd_len); | |
4015 | ZFCP_LOG_DEBUG("SCSI status code 0x%x\n", | |
4016 | fcp_rsp_iu->scsi_status); | |
4017 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4018 | (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu)); | |
4019 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4020 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), | |
4021 | fcp_rsp_iu->fcp_sns_len); | |
4022 | } | |
4023 | ||
4024 | /* check FCP_RSP_INFO */ | |
4025 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) { | |
4026 | ZFCP_LOG_DEBUG("rsp_len is valid\n"); | |
4027 | switch (fcp_rsp_info[3]) { | |
4028 | case RSP_CODE_GOOD: | |
1da177e4 LT |
4029 | /* ok, continue */ |
4030 | ZFCP_LOG_TRACE("no failure or Task Management " | |
4031 | "Function complete\n"); | |
4032 | set_host_byte(&scpnt->result, DID_OK); | |
4033 | break; | |
4034 | case RSP_CODE_LENGTH_MISMATCH: | |
1da177e4 LT |
4035 | /* hardware bug */ |
4036 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " | |
4037 | "that the fibrechannel protocol data " | |
4038 | "length differs from the burst length. " | |
4039 | "The problem occured on unit 0x%016Lx " | |
4040 | "on port 0x%016Lx on adapter %s", | |
4041 | unit->fcp_lun, | |
4042 | unit->port->wwpn, | |
4043 | zfcp_get_busid_by_unit(unit)); | |
4044 | /* dump SCSI CDB as prepared by zfcp */ | |
4045 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4046 | (char *) &fsf_req->qtcb-> | |
4047 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); | |
1da177e4 LT |
4048 | set_host_byte(&scpnt->result, DID_ERROR); |
4049 | goto skip_fsfstatus; | |
4050 | case RSP_CODE_FIELD_INVALID: | |
1da177e4 LT |
4051 | /* driver or hardware bug */ |
4052 | ZFCP_LOG_NORMAL("bug: FCP response code indictates " | |
4053 | "that the fibrechannel protocol data " | |
4054 | "fields were incorrectly set up. " | |
4055 | "The problem occured on the unit " | |
4056 | "0x%016Lx on port 0x%016Lx on " | |
4057 | "adapter %s", | |
4058 | unit->fcp_lun, | |
4059 | unit->port->wwpn, | |
4060 | zfcp_get_busid_by_unit(unit)); | |
4061 | /* dump SCSI CDB as prepared by zfcp */ | |
4062 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4063 | (char *) &fsf_req->qtcb-> | |
4064 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); | |
4065 | set_host_byte(&scpnt->result, DID_ERROR); | |
1da177e4 LT |
4066 | goto skip_fsfstatus; |
4067 | case RSP_CODE_RO_MISMATCH: | |
1da177e4 LT |
4068 | /* hardware bug */ |
4069 | ZFCP_LOG_NORMAL("bug: The FCP response code indicates " | |
4070 | "that conflicting values for the " | |
4071 | "fibrechannel payload offset from the " | |
4072 | "header were found. " | |
4073 | "The problem occured on unit 0x%016Lx " | |
4074 | "on port 0x%016Lx on adapter %s.\n", | |
4075 | unit->fcp_lun, | |
4076 | unit->port->wwpn, | |
4077 | zfcp_get_busid_by_unit(unit)); | |
4078 | /* dump SCSI CDB as prepared by zfcp */ | |
4079 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4080 | (char *) &fsf_req->qtcb-> | |
4081 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); | |
1da177e4 LT |
4082 | set_host_byte(&scpnt->result, DID_ERROR); |
4083 | goto skip_fsfstatus; | |
4084 | default: | |
4085 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " | |
4086 | "code was detected for a command. " | |
4087 | "The problem occured on the unit " | |
4088 | "0x%016Lx on port 0x%016Lx on " | |
4089 | "adapter %s (debug info 0x%x)\n", | |
4090 | unit->fcp_lun, | |
4091 | unit->port->wwpn, | |
4092 | zfcp_get_busid_by_unit(unit), | |
4093 | fcp_rsp_info[3]); | |
4094 | /* dump SCSI CDB as prepared by zfcp */ | |
4095 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG, | |
4096 | (char *) &fsf_req->qtcb-> | |
4097 | bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE); | |
1da177e4 | 4098 | set_host_byte(&scpnt->result, DID_ERROR); |
6f71d9bc | 4099 | goto skip_fsfstatus; |
1da177e4 LT |
4100 | } |
4101 | } | |
4102 | ||
4103 | /* check for sense data */ | |
4104 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) { | |
4105 | sns_len = FSF_FCP_RSP_SIZE - | |
4106 | sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len; | |
4107 | ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n", | |
4108 | sns_len); | |
4109 | sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE); | |
4110 | ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n", | |
4111 | SCSI_SENSE_BUFFERSIZE); | |
4112 | sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len); | |
4113 | ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n", | |
4114 | scpnt->result); | |
4115 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, | |
4116 | (void *) &scpnt->cmnd, scpnt->cmd_len); | |
4117 | ||
4118 | ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n", | |
4119 | fcp_rsp_iu->fcp_sns_len); | |
4120 | memcpy(&scpnt->sense_buffer, | |
4121 | zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len); | |
4122 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, | |
4123 | (void *) &scpnt->sense_buffer, sns_len); | |
4124 | } | |
4125 | ||
4126 | /* check for overrun */ | |
4127 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) { | |
4128 | ZFCP_LOG_INFO("A data overrun was detected for a command. " | |
4129 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " | |
4130 | "The response data length is " | |
4131 | "%d, the original length was %d.\n", | |
4132 | unit->fcp_lun, | |
4133 | unit->port->wwpn, | |
4134 | zfcp_get_busid_by_unit(unit), | |
4135 | fcp_rsp_iu->fcp_resid, | |
4136 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); | |
4137 | } | |
4138 | ||
4139 | /* check for underrun */ | |
4140 | if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) { | |
4141 | ZFCP_LOG_INFO("A data underrun was detected for a command. " | |
4142 | "unit 0x%016Lx, port 0x%016Lx, adapter %s. " | |
4143 | "The response data length is " | |
4144 | "%d, the original length was %d.\n", | |
4145 | unit->fcp_lun, | |
4146 | unit->port->wwpn, | |
4147 | zfcp_get_busid_by_unit(unit), | |
4148 | fcp_rsp_iu->fcp_resid, | |
4149 | (int) zfcp_get_fcp_dl(fcp_cmnd_iu)); | |
4150 | ||
4151 | scpnt->resid = fcp_rsp_iu->fcp_resid; | |
4152 | if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow) | |
6f71d9bc | 4153 | set_host_byte(&scpnt->result, DID_ERROR); |
1da177e4 LT |
4154 | } |
4155 | ||
4156 | skip_fsfstatus: | |
4157 | ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result); | |
4158 | ||
8a36e453 MS |
4159 | if (scpnt->result != 0) |
4160 | zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt); | |
4161 | else if (scpnt->retries > 0) | |
4162 | zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt); | |
4163 | else | |
4164 | zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt); | |
1da177e4 LT |
4165 | |
4166 | /* cleanup pointer (need this especially for abort) */ | |
4167 | scpnt->host_scribble = NULL; | |
4168 | ||
1da177e4 | 4169 | /* always call back */ |
1da177e4 LT |
4170 | (scpnt->scsi_done) (scpnt); |
4171 | ||
4172 | /* | |
4173 | * We must hold this lock until scsi_done has been called. | |
4174 | * Otherwise we may call scsi_done after abort regarding this | |
4175 | * command has completed. | |
4176 | * Note: scsi_done must not block! | |
4177 | */ | |
4178 | out: | |
4179 | read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags); | |
4180 | return retval; | |
4181 | } | |
4182 | ||
4183 | /* | |
4184 | * function: zfcp_fsf_send_fcp_command_task_management_handler | |
4185 | * | |
4186 | * purpose: evaluates FCP_RSP IU | |
4187 | * | |
4188 | * returns: | |
4189 | */ | |
4190 | static int | |
4191 | zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req) | |
4192 | { | |
4193 | int retval = 0; | |
4194 | struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *) | |
4195 | &(fsf_req->qtcb->bottom.io.fcp_rsp); | |
4196 | char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu); | |
059c97d0 | 4197 | struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data; |
1da177e4 LT |
4198 | |
4199 | del_timer(&fsf_req->adapter->scsi_er_timer); | |
4200 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
4201 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | |
4202 | goto skip_fsfstatus; | |
4203 | } | |
4204 | ||
4205 | /* check FCP_RSP_INFO */ | |
4206 | switch (fcp_rsp_info[3]) { | |
4207 | case RSP_CODE_GOOD: | |
1da177e4 LT |
4208 | /* ok, continue */ |
4209 | ZFCP_LOG_DEBUG("no failure or Task Management " | |
4210 | "Function complete\n"); | |
4211 | break; | |
4212 | case RSP_CODE_TASKMAN_UNSUPP: | |
1da177e4 LT |
4213 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
4214 | "is not supported on the target device " | |
4215 | "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ", | |
4216 | unit->fcp_lun, | |
4217 | unit->port->wwpn, | |
4218 | zfcp_get_busid_by_unit(unit)); | |
4219 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP; | |
4220 | break; | |
4221 | case RSP_CODE_TASKMAN_FAILED: | |
1da177e4 LT |
4222 | ZFCP_LOG_NORMAL("bug: A reuested task management function " |
4223 | "failed to complete successfully. " | |
4224 | "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n", | |
4225 | unit->fcp_lun, | |
4226 | unit->port->wwpn, | |
4227 | zfcp_get_busid_by_unit(unit)); | |
4228 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | |
4229 | break; | |
4230 | default: | |
4231 | ZFCP_LOG_NORMAL("bug: An invalid FCP response " | |
4232 | "code was detected for a command. " | |
4233 | "unit 0x%016Lx, port 0x%016Lx, adapter %s " | |
4234 | "(debug info 0x%x)\n", | |
4235 | unit->fcp_lun, | |
4236 | unit->port->wwpn, | |
4237 | zfcp_get_busid_by_unit(unit), | |
4238 | fcp_rsp_info[3]); | |
4239 | fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED; | |
4240 | } | |
4241 | ||
4242 | skip_fsfstatus: | |
4243 | return retval; | |
4244 | } | |
4245 | ||
4246 | ||
4247 | /* | |
4248 | * function: zfcp_fsf_control_file | |
4249 | * | |
4250 | * purpose: Initiator of the control file upload/download FSF requests | |
4251 | * | |
4252 | * returns: 0 - FSF request is successfuly created and queued | |
4253 | * -EOPNOTSUPP - The FCP adapter does not have Control File support | |
4254 | * -EINVAL - Invalid direction specified | |
4255 | * -ENOMEM - Insufficient memory | |
4256 | * -EPERM - Cannot create FSF request or place it in QDIO queue | |
4257 | */ | |
4258 | int | |
4259 | zfcp_fsf_control_file(struct zfcp_adapter *adapter, | |
4260 | struct zfcp_fsf_req **fsf_req_ptr, | |
4261 | u32 fsf_command, | |
4262 | u32 option, | |
4263 | struct zfcp_sg_list *sg_list) | |
4264 | { | |
4265 | struct zfcp_fsf_req *fsf_req; | |
4266 | struct fsf_qtcb_bottom_support *bottom; | |
4267 | volatile struct qdio_buffer_element *sbale; | |
4268 | struct timer_list *timer; | |
4269 | unsigned long lock_flags; | |
4270 | int req_flags = 0; | |
4271 | int direction; | |
4272 | int retval = 0; | |
4273 | ||
aef4a983 | 4274 | if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) { |
1da177e4 LT |
4275 | ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n", |
4276 | zfcp_get_busid_by_adapter(adapter)); | |
4277 | retval = -EOPNOTSUPP; | |
4278 | goto out; | |
4279 | } | |
4280 | ||
4281 | switch (fsf_command) { | |
4282 | ||
4283 | case FSF_QTCB_DOWNLOAD_CONTROL_FILE: | |
4284 | direction = SBAL_FLAGS0_TYPE_WRITE; | |
4285 | if ((option != FSF_CFDC_OPTION_FULL_ACCESS) && | |
4286 | (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS)) | |
4287 | req_flags = ZFCP_WAIT_FOR_SBAL; | |
4288 | break; | |
4289 | ||
4290 | case FSF_QTCB_UPLOAD_CONTROL_FILE: | |
4291 | direction = SBAL_FLAGS0_TYPE_READ; | |
4292 | break; | |
4293 | ||
4294 | default: | |
4295 | ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command); | |
4296 | retval = -EINVAL; | |
4297 | goto out; | |
4298 | } | |
4299 | ||
4300 | timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL); | |
4301 | if (!timer) { | |
4302 | retval = -ENOMEM; | |
4303 | goto out; | |
4304 | } | |
4305 | ||
4306 | retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags, | |
4307 | NULL, &lock_flags, &fsf_req); | |
4308 | if (retval < 0) { | |
4309 | ZFCP_LOG_INFO("error: Could not create FSF request for the " | |
4310 | "adapter %s\n", | |
4311 | zfcp_get_busid_by_adapter(adapter)); | |
4312 | retval = -EPERM; | |
4313 | goto unlock_queue_lock; | |
4314 | } | |
4315 | ||
4316 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
4317 | sbale[0].flags |= direction; | |
4318 | ||
4319 | bottom = &fsf_req->qtcb->bottom.support; | |
4320 | bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE; | |
4321 | bottom->option = option; | |
4322 | ||
4323 | if (sg_list->count > 0) { | |
4324 | int bytes; | |
4325 | ||
4326 | bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction, | |
4327 | sg_list->sg, sg_list->count, | |
4328 | ZFCP_MAX_SBALS_PER_REQ); | |
4329 | if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) { | |
4330 | ZFCP_LOG_INFO( | |
4331 | "error: Could not create sufficient number of " | |
4332 | "SBALS for an FSF request to the adapter %s\n", | |
4333 | zfcp_get_busid_by_adapter(adapter)); | |
4334 | retval = -ENOMEM; | |
4335 | goto free_fsf_req; | |
4336 | } | |
4337 | } else | |
4338 | sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY; | |
4339 | ||
4340 | init_timer(timer); | |
4341 | timer->function = zfcp_fsf_request_timeout_handler; | |
4342 | timer->data = (unsigned long) adapter; | |
4343 | timer->expires = ZFCP_FSF_REQUEST_TIMEOUT; | |
4344 | ||
4345 | retval = zfcp_fsf_req_send(fsf_req, timer); | |
4346 | if (retval < 0) { | |
4347 | ZFCP_LOG_INFO("initiation of cfdc up/download failed" | |
4348 | "(adapter %s)\n", | |
4349 | zfcp_get_busid_by_adapter(adapter)); | |
4350 | retval = -EPERM; | |
4351 | goto free_fsf_req; | |
4352 | } | |
4353 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
4354 | ||
4355 | ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the " | |
4356 | "adapter %s\n", | |
4357 | fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ? | |
4358 | "download" : "upload", | |
4359 | zfcp_get_busid_by_adapter(adapter)); | |
4360 | ||
4361 | wait_event(fsf_req->completion_wq, | |
4362 | fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED); | |
4363 | ||
4364 | *fsf_req_ptr = fsf_req; | |
4365 | del_timer_sync(timer); | |
4366 | goto free_timer; | |
4367 | ||
4368 | free_fsf_req: | |
4369 | zfcp_fsf_req_free(fsf_req); | |
4370 | unlock_queue_lock: | |
4371 | write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags); | |
4372 | free_timer: | |
4373 | kfree(timer); | |
4374 | out: | |
4375 | return retval; | |
4376 | } | |
4377 | ||
4378 | ||
4379 | /* | |
4380 | * function: zfcp_fsf_control_file_handler | |
4381 | * | |
4382 | * purpose: Handler of the control file upload/download FSF requests | |
4383 | * | |
4384 | * returns: 0 - FSF request successfuly processed | |
4385 | * -EAGAIN - Operation has to be repeated because of a temporary problem | |
4386 | * -EACCES - There is no permission to execute an operation | |
4387 | * -EPERM - The control file is not in a right format | |
4388 | * -EIO - There is a problem with the FCP adapter | |
4389 | * -EINVAL - Invalid operation | |
4390 | * -EFAULT - User space memory I/O operation fault | |
4391 | */ | |
4392 | static int | |
4393 | zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req) | |
4394 | { | |
4395 | struct zfcp_adapter *adapter = fsf_req->adapter; | |
4396 | struct fsf_qtcb_header *header = &fsf_req->qtcb->header; | |
4397 | struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support; | |
4398 | int retval = 0; | |
4399 | ||
4400 | if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) { | |
4401 | retval = -EINVAL; | |
4402 | goto skip_fsfstatus; | |
4403 | } | |
4404 | ||
4405 | switch (header->fsf_status) { | |
4406 | ||
4407 | case FSF_GOOD: | |
1da177e4 LT |
4408 | ZFCP_LOG_NORMAL( |
4409 | "The FSF request has been successfully completed " | |
4410 | "on the adapter %s\n", | |
4411 | zfcp_get_busid_by_adapter(adapter)); | |
4412 | break; | |
4413 | ||
4414 | case FSF_OPERATION_PARTIALLY_SUCCESSFUL: | |
1da177e4 LT |
4415 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) { |
4416 | switch (header->fsf_status_qual.word[0]) { | |
4417 | ||
6f71d9bc JB |
4418 | case FSF_SQ_CFDC_HARDENED_ON_SE: |
4419 | ZFCP_LOG_NORMAL( | |
4420 | "CFDC on the adapter %s has being " | |
4421 | "hardened on primary and secondary SE\n", | |
4422 | zfcp_get_busid_by_adapter(adapter)); | |
4423 | break; | |
4424 | ||
1da177e4 LT |
4425 | case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE: |
4426 | ZFCP_LOG_NORMAL( | |
4427 | "CFDC of the adapter %s could not " | |
4428 | "be saved on the SE\n", | |
4429 | zfcp_get_busid_by_adapter(adapter)); | |
4430 | break; | |
4431 | ||
4432 | case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2: | |
4433 | ZFCP_LOG_NORMAL( | |
4434 | "CFDC of the adapter %s could not " | |
4435 | "be copied to the secondary SE\n", | |
4436 | zfcp_get_busid_by_adapter(adapter)); | |
4437 | break; | |
4438 | ||
4439 | default: | |
4440 | ZFCP_LOG_NORMAL( | |
4441 | "CFDC could not be hardened " | |
4442 | "on the adapter %s\n", | |
4443 | zfcp_get_busid_by_adapter(adapter)); | |
4444 | } | |
4445 | } | |
4446 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4447 | retval = -EAGAIN; | |
4448 | break; | |
4449 | ||
4450 | case FSF_AUTHORIZATION_FAILURE: | |
1da177e4 LT |
4451 | ZFCP_LOG_NORMAL( |
4452 | "Adapter %s does not accept privileged commands\n", | |
4453 | zfcp_get_busid_by_adapter(adapter)); | |
4454 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4455 | retval = -EACCES; | |
4456 | break; | |
4457 | ||
4458 | case FSF_CFDC_ERROR_DETECTED: | |
1da177e4 LT |
4459 | ZFCP_LOG_NORMAL( |
4460 | "Error at position %d in the CFDC, " | |
4461 | "CFDC is discarded by the adapter %s\n", | |
4462 | header->fsf_status_qual.word[0], | |
4463 | zfcp_get_busid_by_adapter(adapter)); | |
4464 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4465 | retval = -EPERM; | |
4466 | break; | |
4467 | ||
4468 | case FSF_CONTROL_FILE_UPDATE_ERROR: | |
1da177e4 LT |
4469 | ZFCP_LOG_NORMAL( |
4470 | "Adapter %s cannot harden the control file, " | |
4471 | "file is discarded\n", | |
4472 | zfcp_get_busid_by_adapter(adapter)); | |
4473 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4474 | retval = -EIO; | |
4475 | break; | |
4476 | ||
4477 | case FSF_CONTROL_FILE_TOO_LARGE: | |
1da177e4 LT |
4478 | ZFCP_LOG_NORMAL( |
4479 | "Control file is too large, file is discarded " | |
4480 | "by the adapter %s\n", | |
4481 | zfcp_get_busid_by_adapter(adapter)); | |
4482 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4483 | retval = -EIO; | |
4484 | break; | |
4485 | ||
4486 | case FSF_ACCESS_CONFLICT_DETECTED: | |
1da177e4 LT |
4487 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) |
4488 | ZFCP_LOG_NORMAL( | |
4489 | "CFDC has been discarded by the adapter %s, " | |
4490 | "because activation would impact " | |
4491 | "%d active connection(s)\n", | |
4492 | zfcp_get_busid_by_adapter(adapter), | |
4493 | header->fsf_status_qual.word[0]); | |
4494 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4495 | retval = -EIO; | |
4496 | break; | |
4497 | ||
4498 | case FSF_CONFLICTS_OVERRULED: | |
1da177e4 LT |
4499 | if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) |
4500 | ZFCP_LOG_NORMAL( | |
4501 | "CFDC has been activated on the adapter %s, " | |
4502 | "but activation has impacted " | |
4503 | "%d active connection(s)\n", | |
4504 | zfcp_get_busid_by_adapter(adapter), | |
4505 | header->fsf_status_qual.word[0]); | |
4506 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4507 | retval = -EIO; | |
4508 | break; | |
4509 | ||
4510 | case FSF_UNKNOWN_OP_SUBTYPE: | |
1da177e4 LT |
4511 | ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, " |
4512 | "op_subtype=0x%x)\n", | |
4513 | zfcp_get_busid_by_adapter(adapter), | |
4514 | bottom->operation_subtype); | |
4515 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4516 | retval = -EINVAL; | |
4517 | break; | |
4518 | ||
4519 | case FSF_INVALID_COMMAND_OPTION: | |
1da177e4 LT |
4520 | ZFCP_LOG_NORMAL( |
4521 | "Invalid option 0x%x has been specified " | |
4522 | "in QTCB bottom sent to the adapter %s\n", | |
4523 | bottom->option, | |
4524 | zfcp_get_busid_by_adapter(adapter)); | |
4525 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4526 | retval = -EINVAL; | |
4527 | break; | |
4528 | ||
4529 | default: | |
4530 | ZFCP_LOG_NORMAL( | |
4531 | "bug: An unknown/unexpected FSF status 0x%08x " | |
4532 | "was presented on the adapter %s\n", | |
4533 | header->fsf_status, | |
4534 | zfcp_get_busid_by_adapter(adapter)); | |
4535 | debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval"); | |
4536 | debug_exception(fsf_req->adapter->erp_dbf, 0, | |
4537 | &header->fsf_status_qual.word[0], sizeof(u32)); | |
4538 | fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR; | |
4539 | retval = -EINVAL; | |
4540 | break; | |
4541 | } | |
4542 | ||
4543 | skip_fsfstatus: | |
4544 | return retval; | |
4545 | } | |
4546 | ||
1da177e4 LT |
4547 | static inline int |
4548 | zfcp_fsf_req_sbal_check(unsigned long *flags, | |
4549 | struct zfcp_qdio_queue *queue, int needed) | |
4550 | { | |
4551 | write_lock_irqsave(&queue->queue_lock, *flags); | |
4552 | if (likely(atomic_read(&queue->free_count) >= needed)) | |
4553 | return 1; | |
4554 | write_unlock_irqrestore(&queue->queue_lock, *flags); | |
4555 | return 0; | |
4556 | } | |
4557 | ||
4558 | /* | |
4559 | * set qtcb pointer in fsf_req and initialize QTCB | |
4560 | */ | |
4561 | static inline void | |
8a36e453 | 4562 | zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req) |
1da177e4 LT |
4563 | { |
4564 | if (likely(fsf_req->qtcb != NULL)) { | |
8a36e453 | 4565 | fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no; |
1da177e4 LT |
4566 | fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req; |
4567 | fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION; | |
8a36e453 | 4568 | fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command]; |
1da177e4 LT |
4569 | fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION; |
4570 | fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req; | |
8a36e453 | 4571 | fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command; |
1da177e4 LT |
4572 | } |
4573 | } | |
4574 | ||
4575 | /** | |
4576 | * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue | |
4577 | * @adapter: adapter for which request queue is examined | |
4578 | * @req_flags: flags indicating whether to wait for needed SBAL or not | |
4579 | * @lock_flags: lock_flags if queue_lock is taken | |
4580 | * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS | |
4581 | * Locks: lock adapter->request_queue->queue_lock on success | |
4582 | */ | |
4583 | static int | |
4584 | zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags, | |
4585 | unsigned long *lock_flags) | |
4586 | { | |
4587 | long ret; | |
4588 | struct zfcp_qdio_queue *req_queue = &adapter->request_queue; | |
4589 | ||
4590 | if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) { | |
4591 | ret = wait_event_interruptible_timeout(adapter->request_wq, | |
4592 | zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1), | |
4593 | ZFCP_SBAL_TIMEOUT); | |
4594 | if (ret < 0) | |
4595 | return ret; | |
4596 | if (!ret) | |
4597 | return -EIO; | |
4598 | } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1)) | |
4599 | return -EIO; | |
4600 | ||
4601 | return 0; | |
4602 | } | |
4603 | ||
4604 | /* | |
4605 | * function: zfcp_fsf_req_create | |
4606 | * | |
4607 | * purpose: create an FSF request at the specified adapter and | |
4608 | * setup common fields | |
4609 | * | |
4610 | * returns: -ENOMEM if there was insufficient memory for a request | |
4611 | * -EIO if no qdio buffers could be allocate to the request | |
4612 | * -EINVAL/-EPERM on bug conditions in req_dequeue | |
4613 | * 0 in success | |
4614 | * | |
4615 | * note: The created request is returned by reference. | |
4616 | * | |
4617 | * locks: lock of concerned request queue must not be held, | |
4618 | * but is held on completion (write, irqsave) | |
4619 | */ | |
4620 | int | |
4621 | zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags, | |
4622 | mempool_t *pool, unsigned long *lock_flags, | |
4623 | struct zfcp_fsf_req **fsf_req_p) | |
4624 | { | |
4625 | volatile struct qdio_buffer_element *sbale; | |
4626 | struct zfcp_fsf_req *fsf_req = NULL; | |
4627 | int ret = 0; | |
4628 | struct zfcp_qdio_queue *req_queue = &adapter->request_queue; | |
4629 | ||
4630 | /* allocate new FSF request */ | |
4631 | fsf_req = zfcp_fsf_req_alloc(pool, req_flags); | |
4632 | if (unlikely(NULL == fsf_req)) { | |
4633 | ZFCP_LOG_DEBUG("error: Could not put an FSF request into" | |
4634 | "the outbound (send) queue.\n"); | |
4635 | ret = -ENOMEM; | |
4636 | goto failed_fsf_req; | |
4637 | } | |
4638 | ||
8a36e453 MS |
4639 | fsf_req->adapter = adapter; |
4640 | fsf_req->fsf_command = fsf_cmd; | |
4641 | ||
4642 | zfcp_fsf_req_qtcb_init(fsf_req); | |
1da177e4 LT |
4643 | |
4644 | /* initialize waitqueue which may be used to wait on | |
4645 | this request completion */ | |
4646 | init_waitqueue_head(&fsf_req->completion_wq); | |
4647 | ||
4648 | ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); | |
4649 | if(ret < 0) { | |
4650 | goto failed_sbals; | |
4651 | } | |
4652 | ||
4653 | /* | |
4654 | * We hold queue_lock here. Check if QDIOUP is set and let request fail | |
4655 | * if it is not set (see also *_open_qdio and *_close_qdio). | |
4656 | */ | |
4657 | ||
4658 | if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) { | |
4659 | write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags); | |
4660 | ret = -EIO; | |
4661 | goto failed_sbals; | |
4662 | } | |
4663 | ||
8a36e453 MS |
4664 | if (fsf_req->qtcb) { |
4665 | fsf_req->seq_no = adapter->fsf_req_seq_no; | |
4666 | fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no; | |
4667 | } | |
1da177e4 LT |
4668 | fsf_req->sbal_number = 1; |
4669 | fsf_req->sbal_first = req_queue->free_index; | |
4670 | fsf_req->sbal_curr = req_queue->free_index; | |
4671 | fsf_req->sbale_curr = 1; | |
4672 | ||
4673 | if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) { | |
4674 | fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP; | |
4675 | } | |
4676 | ||
4677 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0); | |
4678 | ||
4679 | /* setup common SBALE fields */ | |
4680 | sbale[0].addr = fsf_req; | |
4681 | sbale[0].flags |= SBAL_FLAGS0_COMMAND; | |
4682 | if (likely(fsf_req->qtcb != NULL)) { | |
4683 | sbale[1].addr = (void *) fsf_req->qtcb; | |
4684 | sbale[1].length = sizeof(struct fsf_qtcb); | |
4685 | } | |
4686 | ||
4687 | ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n", | |
4688 | fsf_req->sbal_number, fsf_req->sbal_first); | |
4689 | ||
4690 | goto success; | |
4691 | ||
4692 | failed_sbals: | |
4693 | /* dequeue new FSF request previously enqueued */ | |
4694 | zfcp_fsf_req_free(fsf_req); | |
4695 | fsf_req = NULL; | |
4696 | ||
4697 | failed_fsf_req: | |
4698 | write_lock_irqsave(&req_queue->queue_lock, *lock_flags); | |
4699 | success: | |
4700 | *fsf_req_p = fsf_req; | |
4701 | return ret; | |
4702 | } | |
4703 | ||
4704 | /* | |
4705 | * function: zfcp_fsf_req_send | |
4706 | * | |
4707 | * purpose: start transfer of FSF request via QDIO | |
4708 | * | |
4709 | * returns: 0 - request transfer succesfully started | |
4710 | * !0 - start of request transfer failed | |
4711 | */ | |
4712 | static int | |
4713 | zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer) | |
4714 | { | |
4715 | struct zfcp_adapter *adapter; | |
4716 | struct zfcp_qdio_queue *req_queue; | |
4717 | volatile struct qdio_buffer_element *sbale; | |
8a36e453 | 4718 | int inc_seq_no; |
1da177e4 LT |
4719 | int new_distance_from_int; |
4720 | unsigned long flags; | |
1da177e4 LT |
4721 | int retval = 0; |
4722 | ||
4723 | adapter = fsf_req->adapter; | |
4724 | req_queue = &adapter->request_queue, | |
4725 | ||
4726 | ||
4727 | /* FIXME(debug): remove it later */ | |
4728 | sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0); | |
4729 | ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags); | |
4730 | ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n"); | |
4731 | ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr, | |
4732 | sbale[1].length); | |
4733 | ||
1da177e4 | 4734 | /* put allocated FSF request at list tail */ |
1db2c9c0 | 4735 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
1da177e4 | 4736 | list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head); |
1db2c9c0 | 4737 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); |
1da177e4 | 4738 | |
8a36e453 MS |
4739 | inc_seq_no = (fsf_req->qtcb != NULL); |
4740 | ||
1da177e4 LT |
4741 | /* figure out expiration time of timeout and start timeout */ |
4742 | if (unlikely(timer)) { | |
4743 | timer->expires += jiffies; | |
4744 | add_timer(timer); | |
4745 | } | |
4746 | ||
4747 | ZFCP_LOG_TRACE("request queue of adapter %s: " | |
4748 | "next free SBAL is %i, %i free SBALs\n", | |
4749 | zfcp_get_busid_by_adapter(adapter), | |
4750 | req_queue->free_index, | |
4751 | atomic_read(&req_queue->free_count)); | |
4752 | ||
4753 | ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, " | |
4754 | "index_in_queue=%i, count=%i, buffers=%p\n", | |
4755 | zfcp_get_busid_by_adapter(adapter), | |
4756 | QDIO_FLAG_SYNC_OUTPUT, | |
4757 | 0, fsf_req->sbal_first, fsf_req->sbal_number, | |
4758 | &req_queue->buffer[fsf_req->sbal_first]); | |
4759 | ||
4760 | /* | |
4761 | * adjust the number of free SBALs in request queue as well as | |
4762 | * position of first one | |
4763 | */ | |
4764 | atomic_sub(fsf_req->sbal_number, &req_queue->free_count); | |
4765 | ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count)); | |
4766 | req_queue->free_index += fsf_req->sbal_number; /* increase */ | |
4767 | req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */ | |
4768 | new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req); | |
4769 | ||
8a36e453 MS |
4770 | fsf_req->issued = get_clock(); |
4771 | ||
1da177e4 LT |
4772 | retval = do_QDIO(adapter->ccw_device, |
4773 | QDIO_FLAG_SYNC_OUTPUT, | |
4774 | 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL); | |
4775 | ||
4776 | if (unlikely(retval)) { | |
4777 | /* Queues are down..... */ | |
4778 | retval = -EIO; | |
4779 | /* | |
4780 | * FIXME(potential race): | |
4781 | * timer might be expired (absolutely unlikely) | |
4782 | */ | |
4783 | if (timer) | |
4784 | del_timer(timer); | |
1db2c9c0 | 4785 | spin_lock_irqsave(&adapter->fsf_req_list_lock, flags); |
1da177e4 | 4786 | list_del(&fsf_req->list); |
1db2c9c0 | 4787 | spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags); |
1da177e4 LT |
4788 | /* |
4789 | * adjust the number of free SBALs in request queue as well as | |
4790 | * position of first one | |
4791 | */ | |
4792 | zfcp_qdio_zero_sbals(req_queue->buffer, | |
4793 | fsf_req->sbal_first, fsf_req->sbal_number); | |
4794 | atomic_add(fsf_req->sbal_number, &req_queue->free_count); | |
4795 | req_queue->free_index -= fsf_req->sbal_number; /* increase */ | |
4796 | req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q; | |
4797 | req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */ | |
4798 | ZFCP_LOG_DEBUG | |
4799 | ("error: do_QDIO failed. Buffers could not be enqueued " | |
4800 | "to request queue.\n"); | |
4801 | } else { | |
4802 | req_queue->distance_from_int = new_distance_from_int; | |
4803 | /* | |
4804 | * increase FSF sequence counter - | |
4805 | * this must only be done for request successfully enqueued to | |
4806 | * QDIO this rejected requests may be cleaned up by calling | |
4807 | * routines resulting in missing sequence counter values | |
4808 | * otherwise, | |
4809 | */ | |
8a36e453 | 4810 | |
1da177e4 | 4811 | /* Don't increase for unsolicited status */ |
8a36e453 | 4812 | if (inc_seq_no) |
1da177e4 | 4813 | adapter->fsf_req_seq_no++; |
8a36e453 | 4814 | |
1da177e4 LT |
4815 | /* count FSF requests pending */ |
4816 | atomic_inc(&adapter->fsf_reqs_active); | |
4817 | } | |
4818 | return retval; | |
4819 | } | |
4820 | ||
1da177e4 | 4821 | #undef ZFCP_LOG_AREA |