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