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