3 * linux/drivers/s390/scsi/zfcp_fsf.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /* this drivers version (do not edit !!! generated and updated by cvs) */
32 #define ZFCP_FSF_C_REVISION "$Revision: 1.55 $"
36 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
37 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
38 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_task_management_handler(
45 struct zfcp_fsf_req *);
46 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
47 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
48 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
51 static inline int zfcp_fsf_req_create_sbal_check(
52 unsigned long *, struct zfcp_qdio_queue *, int);
53 static inline int zfcp_use_one_sbal(
54 struct scatterlist *, int, struct scatterlist *, int);
55 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
56 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
57 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
58 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
59 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
60 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
61 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
62 static void zfcp_fsf_req_free(struct zfcp_fsf_req *);
64 /* association between FSF command and FSF QTCB type */
65 static u32 fsf_qtcb_type[] = {
66 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
67 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
68 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
76 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
77 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
78 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
81 static const char zfcp_act_subtable_type[5][8] = {
82 {"unknown"}, {"OS"}, {"WWPN"}, {"DID"}, {"LUN"}
86 /****************************************************************/
87 /*************** FSF related Functions *************************/
88 /****************************************************************/
90 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
93 * function: zfcp_fsf_req_alloc
95 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
96 * unsolicited requests) via helper functions
97 * Does some initial fsf request set-up.
99 * returns: pointer to allocated fsf_req if successfull
105 static struct zfcp_fsf_req *
106 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
110 struct zfcp_fsf_req *fsf_req = NULL;
112 if (req_flags & ZFCP_REQ_NO_QTCB)
113 size = sizeof(struct zfcp_fsf_req);
115 size = sizeof(struct zfcp_fsf_req_pool_element);
117 if (likely(pool != NULL))
118 ptr = mempool_alloc(pool, GFP_ATOMIC);
120 ptr = kmalloc(size, GFP_ATOMIC);
122 if (unlikely(NULL == ptr))
125 memset(ptr, 0, size);
127 if (req_flags & ZFCP_REQ_NO_QTCB) {
128 fsf_req = (struct zfcp_fsf_req *) ptr;
130 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
132 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
135 fsf_req->pool = pool;
142 * function: zfcp_fsf_req_free
144 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
145 * returns it into the pool via helper functions.
152 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
154 if (likely(fsf_req->pool != NULL))
155 mempool_free(fsf_req, fsf_req->pool);
167 * note: qdio queues shall be down (no ongoing inbound processing)
170 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
173 struct zfcp_fsf_req *fsf_req, *tmp;
175 list_for_each_entry_safe(fsf_req, tmp, &adapter->fsf_req_list_head,
177 zfcp_fsf_req_dismiss(fsf_req);
178 /* wait_event_timeout? */
179 while (!list_empty(&adapter->fsf_req_list_head)) {
180 ZFCP_LOG_DEBUG("fsf req list of adapter %s not yet empty\n",
181 zfcp_get_busid_by_adapter(adapter));
182 /* wait for woken intiators to clean up their requests */
183 msleep(jiffies_to_msecs(ZFCP_FSFREQ_CLEANUP_TIMEOUT));
186 /* consistency check */
187 if (atomic_read(&adapter->fsf_reqs_active)) {
188 ZFCP_LOG_NORMAL("bug: There are still %d FSF requests pending "
189 "on adapter %s after cleanup.\n",
190 atomic_read(&adapter->fsf_reqs_active),
191 zfcp_get_busid_by_adapter(adapter));
192 atomic_set(&adapter->fsf_reqs_active, 0);
206 zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
208 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
209 zfcp_fsf_req_complete(fsf_req);
213 * function: zfcp_fsf_req_complete
215 * purpose: Updates active counts and timers for openfcp-reqs
216 * May cleanup request after req_eval returns
218 * returns: 0 - success
224 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
228 struct zfcp_adapter *adapter = fsf_req->adapter;
230 /* do some statistics */
231 atomic_dec(&adapter->fsf_reqs_active);
233 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
234 ZFCP_LOG_DEBUG("Status read response received\n");
236 * Note: all cleanup handling is done in the callchain of
237 * the function call-chain below.
239 zfcp_fsf_status_read_handler(fsf_req);
242 zfcp_fsf_protstatus_eval(fsf_req);
245 * fsf_req may be deleted due to waking up functions, so
246 * cleanup is saved here and used later
248 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
253 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
255 /* cleanup request if requested by initiator */
256 if (likely(cleanup)) {
257 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
259 * lock must not be held here since it will be
260 * grabed by the called routine, too
262 zfcp_fsf_req_cleanup(fsf_req);
264 /* notify initiator waiting for the requests completion */
265 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
267 * FIXME: Race! We must not access fsf_req here as it might have been
268 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
269 * flag. It's an improbable case. But, we have the same paranoia for
270 * the cleanup flag already.
271 * Might better be handled using complete()?
272 * (setting the flag and doing wakeup ought to be atomic
273 * with regard to checking the flag as long as waitqueue is
274 * part of the to be released structure)
276 wake_up(&fsf_req->completion_wq);
284 * function: zfcp_fsf_protstatus_eval
286 * purpose: evaluates the QTCB of the finished FSF request
287 * and initiates appropriate actions
288 * (usually calling FSF command specific handlers)
297 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
300 struct zfcp_adapter *adapter = fsf_req->adapter;
302 ZFCP_LOG_DEBUG("QTCB is at %p\n", fsf_req->qtcb);
304 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
305 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
306 (unsigned long) fsf_req);
307 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
308 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
309 zfcp_cmd_dbf_event_fsf("dismiss", fsf_req, NULL, 0);
310 goto skip_protstatus;
313 /* log additional information provided by FSF (if any) */
314 if (unlikely(fsf_req->qtcb->header.log_length)) {
315 /* do not trust them ;-) */
316 if (fsf_req->qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
318 ("bug: ULP (FSF logging) log data starts "
319 "beyond end of packet header. Ignored. "
320 "(start=%i, size=%li)\n",
321 fsf_req->qtcb->header.log_start,
322 sizeof(struct fsf_qtcb));
325 if ((size_t) (fsf_req->qtcb->header.log_start +
326 fsf_req->qtcb->header.log_length)
327 > sizeof(struct fsf_qtcb)) {
328 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
329 "beyond end of packet header. Ignored. "
330 "(start=%i, length=%i, size=%li)\n",
331 fsf_req->qtcb->header.log_start,
332 fsf_req->qtcb->header.log_length,
333 sizeof(struct fsf_qtcb));
336 ZFCP_LOG_TRACE("ULP log data: \n");
337 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
338 (char *) fsf_req->qtcb +
339 fsf_req->qtcb->header.log_start,
340 fsf_req->qtcb->header.log_length);
344 /* evaluate FSF Protocol Status */
345 switch (fsf_req->qtcb->prefix.prot_status) {
348 ZFCP_LOG_TRACE("FSF_PROT_GOOD\n");
351 case FSF_PROT_FSF_STATUS_PRESENTED:
352 ZFCP_LOG_TRACE("FSF_PROT_FSF_STATUS_PRESENTED\n");
355 case FSF_PROT_QTCB_VERSION_ERROR:
356 ZFCP_LOG_FLAGS(0, "FSF_PROT_QTCB_VERSION_ERROR\n");
357 ZFCP_LOG_NORMAL("error: The adapter %s contains "
358 "microcode of version 0x%x, the device driver "
359 "only supports 0x%x. Aborting.\n",
360 zfcp_get_busid_by_adapter(adapter),
361 fsf_req->qtcb->prefix.prot_status_qual.
362 version_error.fsf_version, ZFCP_QTCB_VERSION);
363 /* stop operation for this adapter */
364 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
365 zfcp_erp_adapter_shutdown(adapter, 0);
366 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
367 &fsf_req->qtcb->prefix.prot_status_qual,
368 sizeof (union fsf_prot_status_qual));
369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
372 case FSF_PROT_SEQ_NUMB_ERROR:
373 ZFCP_LOG_FLAGS(0, "FSF_PROT_SEQ_NUMB_ERROR\n");
374 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
375 "driver (0x%x) and adapter %s (0x%x). "
376 "Restarting all operations on this adapter.\n",
377 fsf_req->qtcb->prefix.req_seq_no,
378 zfcp_get_busid_by_adapter(adapter),
379 fsf_req->qtcb->prefix.prot_status_qual.
380 sequence_error.exp_req_seq_no);
381 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
382 /* restart operation on this adapter */
383 zfcp_erp_adapter_reopen(adapter, 0);
384 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
385 &fsf_req->qtcb->prefix.prot_status_qual,
386 sizeof (union fsf_prot_status_qual));
387 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
388 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
391 case FSF_PROT_UNSUPP_QTCB_TYPE:
392 ZFCP_LOG_FLAGS(0, "FSF_PROT_UNSUP_QTCB_TYPE\n");
393 ZFCP_LOG_NORMAL("error: Packet header type used by the "
394 "device driver is incompatible with "
395 "that used on adapter %s. "
396 "Stopping all operations on this adapter.\n",
397 zfcp_get_busid_by_adapter(adapter));
398 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
399 zfcp_erp_adapter_shutdown(adapter, 0);
400 zfcp_cmd_dbf_event_fsf("unsqtcbt", fsf_req,
401 &fsf_req->qtcb->prefix.prot_status_qual,
402 sizeof (union fsf_prot_status_qual));
403 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
406 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
407 ZFCP_LOG_FLAGS(1, "FSF_PROT_HOST_CONNECTION_INITIALIZING\n");
408 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
409 &fsf_req->qtcb->prefix.prot_status_qual,
410 sizeof (union fsf_prot_status_qual));
411 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
412 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
414 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
417 case FSF_PROT_DUPLICATE_REQUEST_ID:
418 ZFCP_LOG_FLAGS(0, "FSF_PROT_DUPLICATE_REQUEST_IDS\n");
420 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
421 "to the adapter %s is ambiguous. "
422 "Stopping all operations on this "
424 *(unsigned long long *)
425 (&fsf_req->qtcb->bottom.support.
427 zfcp_get_busid_by_adapter(adapter));
429 ZFCP_LOG_NORMAL("bug: The request identifier %p "
430 "to the adapter %s is ambiguous. "
431 "Stopping all operations on this "
433 "(bug: got this for an unsolicited "
434 "status read request)\n",
436 zfcp_get_busid_by_adapter(adapter));
438 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
439 zfcp_erp_adapter_shutdown(adapter, 0);
440 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
441 &fsf_req->qtcb->prefix.prot_status_qual,
442 sizeof (union fsf_prot_status_qual));
443 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
446 case FSF_PROT_LINK_DOWN:
447 ZFCP_LOG_FLAGS(1, "FSF_PROT_LINK_DOWN\n");
449 * 'test and set' is not atomic here -
450 * it's ok as long as calls to our response queue handler
451 * (and thus execution of this code here) are serialized
454 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
456 switch (fsf_req->qtcb->prefix.prot_status_qual.
457 locallink_error.code) {
458 case FSF_PSQ_LINK_NOLIGHT:
459 ZFCP_LOG_INFO("The local link to adapter %s "
460 "is down (no light detected).\n",
461 zfcp_get_busid_by_adapter(
464 case FSF_PSQ_LINK_WRAPPLUG:
465 ZFCP_LOG_INFO("The local link to adapter %s "
466 "is down (wrap plug detected).\n",
467 zfcp_get_busid_by_adapter(
470 case FSF_PSQ_LINK_NOFCP:
471 ZFCP_LOG_INFO("The local link to adapter %s "
472 "is down (adjacent node on "
473 "link does not support FCP).\n",
474 zfcp_get_busid_by_adapter(
478 ZFCP_LOG_INFO("The local link to adapter %s "
480 "(warning: unknown reason "
482 zfcp_get_busid_by_adapter(
488 * Due to the 'erp failed' flag the adapter won't
489 * be recovered but will be just set to 'blocked'
490 * state. All subordinary devices will have state
491 * 'blocked' and 'erp failed', too.
492 * Thus the adapter is still able to provide
493 * 'link up' status without being flooded with
495 * (note: even 'close port' is not permitted)
497 ZFCP_LOG_INFO("Stopping all operations for adapter "
499 zfcp_get_busid_by_adapter(adapter));
500 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
501 ZFCP_STATUS_COMMON_ERP_FAILED,
503 zfcp_erp_adapter_reopen(adapter, 0);
504 debug_text_event(adapter->erp_dbf, 1, "prot_link_down");
506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
509 case FSF_PROT_REEST_QUEUE:
510 ZFCP_LOG_FLAGS(1, "FSF_PROT_REEST_QUEUE\n");
511 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
512 ZFCP_LOG_INFO("The local link to adapter with "
513 "%s was re-plugged. "
514 "Re-starting operations on this adapter.\n",
515 zfcp_get_busid_by_adapter(adapter));
516 /* All ports should be marked as ready to run again */
517 zfcp_erp_modify_adapter_status(adapter,
518 ZFCP_STATUS_COMMON_RUNNING,
520 zfcp_erp_adapter_reopen(adapter,
521 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
522 | ZFCP_STATUS_COMMON_ERP_FAILED);
523 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
524 &fsf_req->qtcb->prefix.prot_status_qual,
525 sizeof (union fsf_prot_status_qual));
526 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
529 case FSF_PROT_ERROR_STATE:
530 ZFCP_LOG_FLAGS(0, "FSF_PROT_ERROR_STATE\n");
531 ZFCP_LOG_NORMAL("error: The adapter %s "
532 "has entered the error state. "
533 "Restarting all operations on this "
535 zfcp_get_busid_by_adapter(adapter));
536 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
537 /* restart operation on this adapter */
538 zfcp_erp_adapter_reopen(adapter, 0);
539 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
540 &fsf_req->qtcb->prefix.prot_status_qual,
541 sizeof (union fsf_prot_status_qual));
542 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
547 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
548 "provided by the adapter %s "
549 "is not compatible with the device driver. "
550 "Stopping all operations on this adapter. "
551 "(debug info 0x%x).\n",
552 zfcp_get_busid_by_adapter(adapter),
553 fsf_req->qtcb->prefix.prot_status);
554 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
555 debug_exception(adapter->erp_dbf, 0,
556 &fsf_req->qtcb->prefix.prot_status,
558 zfcp_erp_adapter_shutdown(adapter, 0);
559 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
564 * always call specific handlers to give them a chance to do
565 * something meaningful even in error cases
567 zfcp_fsf_fsfstatus_eval(fsf_req);
572 * function: zfcp_fsf_fsfstatus_eval
574 * purpose: evaluates FSF status of completed FSF request
575 * and acts accordingly
580 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
584 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
588 /* evaluate FSF Status */
589 switch (fsf_req->qtcb->header.fsf_status) {
590 case FSF_UNKNOWN_COMMAND:
591 ZFCP_LOG_FLAGS(0, "FSF_UNKNOWN_COMMAND\n");
592 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
593 "not known by the adapter %s "
594 "Stopping all operations on this adapter. "
595 "(debug info 0x%x).\n",
596 zfcp_get_busid_by_adapter(fsf_req->adapter),
597 fsf_req->qtcb->header.fsf_command);
598 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
600 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
601 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
602 &fsf_req->qtcb->header.fsf_status_qual,
603 sizeof (union fsf_status_qual));
604 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
607 case FSF_FCP_RSP_AVAILABLE:
608 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
609 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
611 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
614 case FSF_ADAPTER_STATUS_AVAILABLE:
615 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
616 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
617 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
626 * always call specific handlers to give them a chance to do
627 * something meaningful even in error cases
629 zfcp_fsf_req_dispatch(fsf_req);
635 * function: zfcp_fsf_fsfstatus_qual_eval
637 * purpose: evaluates FSF status-qualifier of completed FSF request
638 * and acts accordingly
643 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
647 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
648 case FSF_SQ_FCP_RSP_AVAILABLE:
649 ZFCP_LOG_FLAGS(2, "FSF_SQ_FCP_RSP_AVAILABLE\n");
650 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
652 case FSF_SQ_RETRY_IF_POSSIBLE:
653 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
654 /* The SCSI-stack may now issue retries or escalate */
655 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
656 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
657 &fsf_req->qtcb->header.fsf_status_qual,
658 sizeof (union fsf_status_qual));
659 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
661 case FSF_SQ_COMMAND_ABORTED:
662 ZFCP_LOG_FLAGS(2, "FSF_SQ_COMMAND_ABORTED\n");
663 /* Carry the aborted state on to upper layer */
664 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
665 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
666 &fsf_req->qtcb->header.fsf_status_qual,
667 sizeof (union fsf_status_qual));
668 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
669 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
671 case FSF_SQ_NO_RECOM:
672 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RECOM\n");
673 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
675 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
676 "problem on the adapter %s "
677 "Stopping all operations on this adapter. ",
678 zfcp_get_busid_by_adapter(fsf_req->adapter));
679 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
680 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
681 &fsf_req->qtcb->header.fsf_status_qual,
682 sizeof (union fsf_status_qual));
683 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
685 case FSF_SQ_ULP_PROGRAMMING_ERROR:
686 ZFCP_LOG_FLAGS(0, "FSF_SQ_ULP_PROGRAMMING_ERROR\n");
687 ZFCP_LOG_NORMAL("bug: An illegal amount of data was attempted "
688 "to be sent to the adapter %s "
689 "Stopping all operations on this adapter. ",
690 zfcp_get_busid_by_adapter(fsf_req->adapter));
691 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
693 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
694 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
696 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
697 case FSF_SQ_NO_RETRY_POSSIBLE:
698 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
699 /* dealt with in the respective functions */
702 ZFCP_LOG_NORMAL("bug: Additional status info could "
703 "not be interpreted properly.\n");
704 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
705 (char *) &fsf_req->qtcb->header.fsf_status_qual,
706 sizeof (union fsf_status_qual));
707 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
708 debug_exception(fsf_req->adapter->erp_dbf, 0,
709 &fsf_req->qtcb->header.fsf_status_qual.word[0],
711 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
712 &fsf_req->qtcb->header.fsf_status_qual,
713 sizeof (union fsf_status_qual));
714 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
722 * function: zfcp_fsf_req_dispatch
724 * purpose: calls the appropriate command specific handler
729 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
731 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
732 struct zfcp_adapter *adapter = fsf_req->adapter;
735 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
736 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
737 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
738 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
741 switch (fsf_req->fsf_command) {
743 case FSF_QTCB_FCP_CMND:
744 ZFCP_LOG_FLAGS(3, "FSF_QTCB_FCP_CMND\n");
745 zfcp_fsf_send_fcp_command_handler(fsf_req);
748 case FSF_QTCB_ABORT_FCP_CMND:
749 ZFCP_LOG_FLAGS(2, "FSF_QTCB_ABORT_FCP_CMND\n");
750 zfcp_fsf_abort_fcp_command_handler(fsf_req);
753 case FSF_QTCB_SEND_GENERIC:
754 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_GENERIC\n");
755 zfcp_fsf_send_ct_handler(fsf_req);
758 case FSF_QTCB_OPEN_PORT_WITH_DID:
759 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_PORT_WITH_DID\n");
760 zfcp_fsf_open_port_handler(fsf_req);
763 case FSF_QTCB_OPEN_LUN:
764 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_LUN\n");
765 zfcp_fsf_open_unit_handler(fsf_req);
768 case FSF_QTCB_CLOSE_LUN:
769 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_LUN\n");
770 zfcp_fsf_close_unit_handler(fsf_req);
773 case FSF_QTCB_CLOSE_PORT:
774 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PORT\n");
775 zfcp_fsf_close_port_handler(fsf_req);
778 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
779 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PHYSICAL_PORT\n");
780 zfcp_fsf_close_physical_port_handler(fsf_req);
783 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
784 ZFCP_LOG_FLAGS(2, "FSF_QTCB_EXCHANGE_CONFIG_DATA\n");
785 zfcp_fsf_exchange_config_data_handler(fsf_req);
788 case FSF_QTCB_SEND_ELS :
789 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_ELS\n");
790 zfcp_fsf_send_els_handler(fsf_req);
793 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
794 ZFCP_LOG_FLAGS(2, "FSF_QTCB_DOWNLOAD_CONTROL_FILE\n");
795 zfcp_fsf_control_file_handler(fsf_req);
798 case FSF_QTCB_UPLOAD_CONTROL_FILE:
799 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UPLOAD_CONTROL_FILE\n");
800 zfcp_fsf_control_file_handler(fsf_req);
804 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UNKNOWN\n");
805 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
806 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
807 "not supported by the adapter %s\n",
808 zfcp_get_busid_by_adapter(fsf_req->adapter));
809 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
811 ("bug: Command issued by the device driver differs "
812 "from the command returned by the adapter %s "
813 "(debug info 0x%x, 0x%x).\n",
814 zfcp_get_busid_by_adapter(fsf_req->adapter),
815 fsf_req->fsf_command,
816 fsf_req->qtcb->header.fsf_command);
822 debug_text_event(adapter->erp_dbf, 3, "a_frh");
823 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
824 zfcp_erp_async_handler(erp_action, 0);
830 * function: zfcp_fsf_status_read
832 * purpose: initiates a Status Read command at the specified adapter
837 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
839 struct zfcp_fsf_req *fsf_req;
840 struct fsf_status_read_buffer *status_buffer;
841 unsigned long lock_flags;
842 volatile struct qdio_buffer_element *sbale;
845 /* setup new FSF request */
846 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
847 req_flags | ZFCP_REQ_NO_QTCB,
848 adapter->pool.fsf_req_status_read,
849 &lock_flags, &fsf_req);
851 ZFCP_LOG_INFO("error: Could not create unsolicited status "
852 "buffer for adapter %s.\n",
853 zfcp_get_busid_by_adapter(adapter));
854 goto failed_req_create;
857 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
858 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
859 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
860 fsf_req->sbale_curr = 2;
863 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
864 if (!status_buffer) {
865 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
868 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
869 fsf_req->data.status_read.buffer = status_buffer;
871 /* insert pointer to respective buffer */
872 sbale = zfcp_qdio_sbale_curr(fsf_req);
873 sbale->addr = (void *) status_buffer;
874 sbale->length = sizeof(struct fsf_status_read_buffer);
876 /* start QDIO request for this FSF request */
877 retval = zfcp_fsf_req_send(fsf_req, NULL);
879 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
881 goto failed_req_send;
884 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
885 zfcp_get_busid_by_adapter(adapter));
889 mempool_free(status_buffer, adapter->pool.data_status_read);
892 zfcp_fsf_req_free(fsf_req);
895 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
900 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
902 struct fsf_status_read_buffer *status_buffer;
903 struct zfcp_adapter *adapter;
904 struct zfcp_port *port;
907 status_buffer = fsf_req->data.status_read.buffer;
908 adapter = fsf_req->adapter;
910 read_lock_irqsave(&zfcp_data.config_lock, flags);
911 list_for_each_entry(port, &adapter->port_list_head, list)
912 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
914 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
916 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
917 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
918 "nonexisting port with d_id 0x%08x on "
919 "adapter %s. Ignored.\n",
920 status_buffer->d_id & ZFCP_DID_MASK,
921 zfcp_get_busid_by_adapter(adapter));
925 switch (status_buffer->status_subtype) {
927 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
928 ZFCP_LOG_FLAGS(2, "FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT\n");
929 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
930 zfcp_erp_port_reopen(port, 0);
933 case FSF_STATUS_READ_SUB_ERROR_PORT:
934 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_SUB_ERROR_PORT\n");
935 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
936 zfcp_erp_port_shutdown(port, 0);
940 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
941 debug_exception(adapter->erp_dbf, 0,
942 &status_buffer->status_subtype, sizeof (u32));
943 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
944 "for a reopen indication on port with "
945 "d_id 0x%08x on the adapter %s. "
946 "Ignored. (debug info 0x%x)\n",
948 zfcp_get_busid_by_adapter(adapter),
949 status_buffer->status_subtype);
956 * function: zfcp_fsf_status_read_handler
958 * purpose: is called for finished Open Port command
963 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
966 struct zfcp_adapter *adapter = fsf_req->adapter;
967 struct fsf_status_read_buffer *status_buffer =
968 fsf_req->data.status_read.buffer;
970 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
971 mempool_free(status_buffer, adapter->pool.data_status_read);
972 zfcp_fsf_req_cleanup(fsf_req);
976 switch (status_buffer->status_type) {
978 case FSF_STATUS_READ_PORT_CLOSED:
979 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_PORT_CLOSED\n");
980 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
981 debug_event(adapter->erp_dbf, 3,
982 &status_buffer->d_id, sizeof (u32));
983 zfcp_fsf_status_read_port_closed(fsf_req);
986 case FSF_STATUS_READ_INCOMING_ELS:
987 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_INCOMING_ELS\n");
988 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
989 zfcp_fsf_incoming_els(fsf_req);
992 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
993 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_BIT_ERROR_THRESHOLD\n");
994 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
995 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
996 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
997 (char *) status_buffer,
998 sizeof (struct fsf_status_read_buffer));
1001 case FSF_STATUS_READ_LINK_DOWN:
1002 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_DOWN\n");
1003 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
1004 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
1005 zfcp_get_busid_by_adapter(adapter));
1006 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
1008 zfcp_erp_adapter_failed(adapter);
1011 case FSF_STATUS_READ_LINK_UP:
1012 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_UP\n");
1013 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
1014 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
1015 "Restarting operations on this adapter\n",
1016 zfcp_get_busid_by_adapter(adapter));
1017 /* All ports should be marked as ready to run again */
1018 zfcp_erp_modify_adapter_status(adapter,
1019 ZFCP_STATUS_COMMON_RUNNING,
1021 zfcp_erp_adapter_reopen(adapter,
1022 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
1023 | ZFCP_STATUS_COMMON_ERP_FAILED);
1027 case FSF_STATUS_READ_CFDC_UPDATED:
1028 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_UPDATED\n");
1029 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
1030 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
1031 zfcp_get_busid_by_adapter(adapter));
1034 case FSF_STATUS_READ_CFDC_HARDENED:
1035 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_HARDENED\n");
1036 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
1037 switch (status_buffer->status_subtype) {
1038 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1039 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
1040 zfcp_get_busid_by_adapter(adapter));
1042 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1043 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
1044 "to the secondary SE\n",
1045 zfcp_get_busid_by_adapter(adapter));
1048 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1049 zfcp_get_busid_by_adapter(adapter));
1054 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1055 debug_exception(adapter->erp_dbf, 0,
1056 &status_buffer->status_type, sizeof (u32));
1057 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1058 "type was received (debug info 0x%x)\n",
1059 status_buffer->status_type);
1060 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1062 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1063 (char *) status_buffer,
1064 sizeof (struct fsf_status_read_buffer));
1067 mempool_free(status_buffer, adapter->pool.data_status_read);
1068 zfcp_fsf_req_cleanup(fsf_req);
1070 * recycle buffer and start new request repeat until outbound
1071 * queue is empty or adapter shutdown is requested
1075 * we may wait in the req_create for 5s during shutdown, so
1076 * qdio_cleanup will have to wait at least that long before returning
1077 * with failure to allow us a proper cleanup under all circumstances
1081 * allocation failure possible? (Is this code needed?)
1083 retval = zfcp_fsf_status_read(adapter, 0);
1085 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1086 "request for the adapter %s.\n",
1087 zfcp_get_busid_by_adapter(adapter));
1088 /* temporary fix to avoid status read buffer shortage */
1089 adapter->status_read_failed++;
1090 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1091 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1092 ZFCP_LOG_INFO("restart adapter %s due to status read "
1093 "buffer shortage\n",
1094 zfcp_get_busid_by_adapter(adapter));
1095 zfcp_erp_adapter_reopen(adapter, 0);
1103 * function: zfcp_fsf_abort_fcp_command
1105 * purpose: tells FSF to abort a running SCSI command
1107 * returns: address of initiated FSF request
1108 * NULL - request could not be initiated
1110 * FIXME(design): should be watched by a timeout !!!
1111 * FIXME(design) shouldn't this be modified to return an int
1112 * also...don't know how though
1114 struct zfcp_fsf_req *
1115 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1116 struct zfcp_adapter *adapter,
1117 struct zfcp_unit *unit, int req_flags)
1119 volatile struct qdio_buffer_element *sbale;
1120 unsigned long lock_flags;
1121 struct zfcp_fsf_req *fsf_req = NULL;
1124 /* setup new FSF request */
1125 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1126 req_flags, adapter->pool.fsf_req_abort,
1127 &lock_flags, &fsf_req);
1129 ZFCP_LOG_INFO("error: Failed to create an abort command "
1130 "request for lun 0x%016Lx on port 0x%016Lx "
1134 zfcp_get_busid_by_adapter(adapter));
1138 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1139 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1140 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1142 fsf_req->data.abort_fcp_command.unit = unit;
1144 /* set handles of unit and its parent port in QTCB */
1145 fsf_req->qtcb->header.lun_handle = unit->handle;
1146 fsf_req->qtcb->header.port_handle = unit->port->handle;
1148 /* set handle of request which should be aborted */
1149 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1151 /* start QDIO request for this FSF request */
1153 zfcp_fsf_start_scsi_er_timer(adapter);
1154 retval = zfcp_fsf_req_send(fsf_req, NULL);
1156 del_timer(&adapter->scsi_er_timer);
1157 ZFCP_LOG_INFO("error: Failed to send abort command request "
1158 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1159 zfcp_get_busid_by_adapter(adapter),
1160 unit->port->wwpn, unit->fcp_lun);
1161 zfcp_fsf_req_free(fsf_req);
1166 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1167 "(adapter%s, port d_id=0x%08x, "
1168 "unit x%016Lx, old_req_id=0x%lx)\n",
1169 zfcp_get_busid_by_adapter(adapter),
1171 unit->fcp_lun, old_req_id);
1173 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1178 * function: zfcp_fsf_abort_fcp_command_handler
1180 * purpose: is called for finished Abort FCP Command request
1185 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1187 int retval = -EINVAL;
1188 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1189 unsigned char status_qual =
1190 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1192 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1194 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1195 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1196 goto skip_fsfstatus;
1199 /* evaluate FSF status in QTCB */
1200 switch (new_fsf_req->qtcb->header.fsf_status) {
1202 case FSF_PORT_HANDLE_NOT_VALID:
1203 if (status_qual >> 4 != status_qual % 0xf) {
1204 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1205 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1208 * In this case a command that was sent prior to a port
1209 * reopen was aborted (handles are different). This is
1213 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
1214 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1215 "port 0x%016Lx on adapter %s invalid. "
1216 "This may happen occasionally.\n",
1219 zfcp_get_busid_by_unit(unit));
1220 ZFCP_LOG_INFO("status qualifier:\n");
1221 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1222 (char *) &new_fsf_req->qtcb->header.
1224 sizeof (union fsf_status_qual));
1225 /* Let's hope this sorts out the mess */
1226 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1228 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1229 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1233 case FSF_LUN_HANDLE_NOT_VALID:
1234 if (status_qual >> 4 != status_qual % 0xf) {
1236 ZFCP_LOG_FLAGS(0, "FSF_LUN_HANDLE_NOT_VALID\n");
1237 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1240 * In this case a command that was sent prior to a unit
1241 * reopen was aborted (handles are different).
1245 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
1247 ("Warning: Temporary LUN identifier 0x%x of LUN "
1248 "0x%016Lx on port 0x%016Lx on adapter %s is "
1249 "invalid. This may happen in rare cases. "
1250 "Trying to re-establish link.\n",
1254 zfcp_get_busid_by_unit(unit));
1255 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1256 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1257 (char *) &new_fsf_req->qtcb->header.
1259 sizeof (union fsf_status_qual));
1260 /* Let's hope this sorts out the mess */
1261 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1263 zfcp_erp_port_reopen(unit->port, 0);
1264 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1268 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1269 ZFCP_LOG_FLAGS(2, "FSF_FCP_COMMAND_DOES_NOT_EXIST\n");
1271 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1273 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1276 case FSF_PORT_BOXED:
1278 ZFCP_LOG_FLAGS(0, "FSF_PORT_BOXED\n");
1279 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1280 "be reopened\n", unit->port->wwpn,
1281 zfcp_get_busid_by_unit(unit));
1282 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1284 zfcp_erp_port_reopen(unit->port, 0);
1285 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1286 | ZFCP_STATUS_FSFREQ_RETRY;
1289 case FSF_ADAPTER_STATUS_AVAILABLE:
1291 ZFCP_LOG_FLAGS(0, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1292 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1293 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1295 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1296 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1298 /* reopening link to port */
1299 zfcp_erp_port_reopen(unit->port, 0);
1300 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1302 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1304 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1305 /* SCSI stack will escalate */
1306 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1308 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1312 ("bug: Wrong status qualifier 0x%x arrived.\n",
1313 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1314 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1316 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1317 &new_fsf_req->qtcb->header.
1318 fsf_status_qual.word[0], sizeof (u32));
1325 ZFCP_LOG_FLAGS(0, "FSF_GOOD\n");
1327 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1331 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1332 "(debug info 0x%x)\n",
1333 new_fsf_req->qtcb->header.fsf_status);
1334 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1336 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1337 &new_fsf_req->qtcb->header.fsf_status,
1346 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1348 * Two scatter-gather lists are passed, one for the reqeust and one for the
1352 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1353 struct scatterlist *resp, int resp_count)
1355 return ((req_count == 1) &&
1356 (resp_count == 1) &&
1357 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1359 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1360 req[0].length - 1) & PAGE_MASK)) &&
1361 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1363 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1364 resp[0].length - 1) & PAGE_MASK)));
1368 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1369 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1371 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1372 * a struct zfcp_fsf_req
1373 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1374 * is sent within error recovery
1377 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1378 struct zfcp_erp_action *erp_action)
1380 volatile struct qdio_buffer_element *sbale;
1381 struct zfcp_port *port;
1382 struct zfcp_adapter *adapter;
1383 struct zfcp_fsf_req *fsf_req;
1384 unsigned long lock_flags;
1389 adapter = port->adapter;
1391 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1392 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1393 pool, &lock_flags, &fsf_req);
1395 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1397 zfcp_get_busid_by_adapter(adapter));
1401 if (erp_action != NULL) {
1402 erp_action->fsf_req = fsf_req;
1403 fsf_req->erp_action = erp_action;
1406 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1407 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1408 ct->resp, ct->resp_count)){
1409 /* both request buffer and response buffer
1410 fit into one sbale each */
1411 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1412 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1413 sbale[2].length = ct->req[0].length;
1414 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1415 sbale[3].length = ct->resp[0].length;
1416 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1417 } else if (adapter->supported_features &
1418 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1419 /* try to use chained SBALs */
1420 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1421 SBAL_FLAGS0_TYPE_WRITE_READ,
1422 ct->req, ct->req_count,
1423 ZFCP_MAX_SBALS_PER_CT_REQ);
1425 ZFCP_LOG_INFO("error: creation of CT request failed "
1427 zfcp_get_busid_by_adapter(adapter));
1435 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1436 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1437 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1438 SBAL_FLAGS0_TYPE_WRITE_READ,
1439 ct->resp, ct->resp_count,
1440 ZFCP_MAX_SBALS_PER_CT_REQ);
1442 ZFCP_LOG_INFO("error: creation of CT request failed "
1444 zfcp_get_busid_by_adapter(adapter));
1452 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1454 /* reject send generic request */
1456 "error: microcode does not support chained SBALs,"
1457 "CT request too big (adapter %s)\n",
1458 zfcp_get_busid_by_adapter(adapter));
1463 /* settings in QTCB */
1464 fsf_req->qtcb->header.port_handle = port->handle;
1465 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1466 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1467 fsf_req->data.send_ct = ct;
1469 /* start QDIO request for this FSF request */
1470 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1472 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1473 "(adapter %s, port 0x%016Lx)\n",
1474 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1478 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1479 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1483 zfcp_fsf_req_free(fsf_req);
1484 if (erp_action != NULL) {
1485 erp_action->fsf_req = NULL;
1489 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1495 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1496 * @fsf_req: pointer to struct zfcp_fsf_req
1498 * Data specific for the Generic Service request is passed by
1499 * fsf_req->data.send_ct
1500 * Usually a specific handler for the request is called via
1501 * fsf_req->data.send_ct->handler at end of this function.
1504 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1506 struct zfcp_port *port;
1507 struct zfcp_adapter *adapter;
1508 struct zfcp_send_ct *send_ct;
1509 struct fsf_qtcb_header *header;
1510 struct fsf_qtcb_bottom_support *bottom;
1511 int retval = -EINVAL;
1512 u16 subtable, rule, counter;
1514 adapter = fsf_req->adapter;
1515 send_ct = fsf_req->data.send_ct;
1516 port = send_ct->port;
1517 header = &fsf_req->qtcb->header;
1518 bottom = &fsf_req->qtcb->bottom.support;
1520 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1521 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1522 goto skip_fsfstatus;
1525 /* evaluate FSF status in QTCB */
1526 switch (header->fsf_status) {
1529 ZFCP_LOG_FLAGS(2,"FSF_GOOD\n");
1533 case FSF_SERVICE_CLASS_NOT_SUPPORTED :
1534 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1535 if (adapter->fc_service_class <= 3) {
1536 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1538 zfcp_get_busid_by_port(port),
1539 adapter->fc_service_class);
1541 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1542 "adapter %s is invalid. "
1543 "(debug info %d)\n",
1544 zfcp_get_busid_by_port(port),
1545 adapter->fc_service_class);
1547 /* stop operation for this adapter */
1548 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1549 zfcp_erp_adapter_shutdown(port->adapter, 0);
1550 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1553 case FSF_ADAPTER_STATUS_AVAILABLE :
1554 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1555 switch (header->fsf_status_qual.word[0]){
1556 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE :
1557 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1558 /* reopening link to port */
1559 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1560 zfcp_test_link(port);
1561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1563 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED :
1564 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1565 /* ERP strategy will escalate */
1566 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1570 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1572 header->fsf_status_qual.word[0]);
1577 case FSF_ACCESS_DENIED:
1578 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1579 ZFCP_LOG_NORMAL("Access denied, cannot send generic command "
1580 "to port 0x%016Lx on adapter %s\n", port->wwpn,
1581 zfcp_get_busid_by_port(port));
1582 for (counter = 0; counter < 2; counter++) {
1583 subtable = header->fsf_status_qual.halfword[counter * 2];
1584 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1586 case FSF_SQ_CFDC_SUBTABLE_OS:
1587 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1588 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1589 case FSF_SQ_CFDC_SUBTABLE_LUN:
1590 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1591 zfcp_act_subtable_type[subtable], rule);
1595 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
1596 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1599 case FSF_GENERIC_COMMAND_REJECTED :
1600 ZFCP_LOG_FLAGS(2, "FSF_GENERIC_COMMAND_REJECTED\n");
1601 ZFCP_LOG_INFO("warning: The port 0x%016Lx on adapter %s has "
1602 "rejected a generic services command.\n",
1603 port->wwpn, zfcp_get_busid_by_port(port));
1604 ZFCP_LOG_INFO("status qualifier:\n");
1605 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1606 (char *) &header->fsf_status_qual,
1607 sizeof (union fsf_status_qual));
1608 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1612 case FSF_PORT_HANDLE_NOT_VALID :
1613 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1614 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1615 "0x%016Lx on adapter %s invalid. This may "
1616 "happen occasionally.\n", port->handle,
1617 port->wwpn, zfcp_get_busid_by_port(port));
1618 ZFCP_LOG_INFO("status qualifier:\n");
1619 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1620 (char *) &header->fsf_status_qual,
1621 sizeof (union fsf_status_qual));
1622 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1623 zfcp_erp_adapter_reopen(port->adapter, 0);
1624 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1627 case FSF_REQUEST_BUF_NOT_VALID :
1628 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_BUF_NOT_VALID\n");
1629 ZFCP_LOG_NORMAL("error: The port 0x%016Lx on adapter %s has "
1630 "rejected a generic services command "
1631 "due to invalid request buffer.\n",
1632 port->wwpn, zfcp_get_busid_by_port(port));
1633 debug_text_event(adapter->erp_dbf, 1, "fsf_s_reqiv");
1634 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1637 case FSF_RESPONSE_BUF_NOT_VALID :
1638 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_BUF_NOT_VALID\n");
1639 ZFCP_LOG_NORMAL("error: The port 0x%016Lx on adapter %s has "
1640 "rejected a generic services command "
1641 "due to invalid response buffer.\n",
1642 port->wwpn, zfcp_get_busid_by_port(port));
1643 debug_text_event(adapter->erp_dbf, 1, "fsf_s_resiv");
1644 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1647 case FSF_PORT_BOXED :
1648 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
1649 ZFCP_LOG_INFO("The remote port 0x%016Lx on adapter %s "
1650 "needs to be reopened\n",
1651 port->wwpn, zfcp_get_busid_by_port(port));
1652 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1653 zfcp_erp_port_reopen(port, 0);
1654 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1655 | ZFCP_STATUS_FSFREQ_RETRY;
1659 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1660 "(debug info 0x%x)\n", header->fsf_status);
1661 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1662 debug_exception(adapter->erp_dbf, 0,
1663 &header->fsf_status_qual.word[0], sizeof (u32));
1668 if (send_ct->handler != NULL) {
1669 send_ct->handler(send_ct->handler_data);
1676 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1677 * @els: pointer to struct zfcp_send_els which contains all needed data for
1681 zfcp_fsf_send_els(struct zfcp_send_els *els)
1683 volatile struct qdio_buffer_element *sbale;
1684 struct zfcp_fsf_req *fsf_req;
1685 struct zfcp_port *port;
1686 struct zfcp_adapter *adapter;
1687 unsigned long lock_flags;
1692 adapter = port->adapter;
1694 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1695 ZFCP_WAIT_FOR_SBAL|ZFCP_REQ_AUTO_CLEANUP,
1696 NULL, &lock_flags, &fsf_req);
1698 ZFCP_LOG_INFO("error: creation of ELS request failed "
1699 "(adapter %s, port d_id: 0x%08x)\n",
1700 zfcp_get_busid_by_adapter(adapter), port->d_id);
1704 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1705 if (zfcp_use_one_sbal(els->req, els->req_count,
1706 els->resp, els->resp_count)){
1707 /* both request buffer and response buffer
1708 fit into one sbale each */
1709 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1710 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1711 sbale[2].length = els->req[0].length;
1712 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1713 sbale[3].length = els->resp[0].length;
1714 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1715 } else if (adapter->supported_features &
1716 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1717 /* try to use chained SBALs */
1718 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1719 SBAL_FLAGS0_TYPE_WRITE_READ,
1720 els->req, els->req_count,
1721 ZFCP_MAX_SBALS_PER_ELS_REQ);
1723 ZFCP_LOG_INFO("error: creation of ELS request failed "
1724 "(adapter %s, port d_id: 0x%08x)\n",
1725 zfcp_get_busid_by_adapter(adapter),
1734 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1735 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1736 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1737 SBAL_FLAGS0_TYPE_WRITE_READ,
1738 els->resp, els->resp_count,
1739 ZFCP_MAX_SBALS_PER_ELS_REQ);
1741 ZFCP_LOG_INFO("error: creation of ELS request failed "
1742 "(adapter %s, port d_id: 0x%08x)\n",
1743 zfcp_get_busid_by_adapter(adapter),
1752 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1754 /* reject request */
1755 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1756 ", ELS request too big (adapter %s, "
1757 "port d_id: 0x%08x)\n",
1758 zfcp_get_busid_by_adapter(adapter), port->d_id);
1763 /* settings in QTCB */
1764 fsf_req->qtcb->bottom.support.d_id = port->d_id;
1765 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1766 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1767 fsf_req->data.send_els = els;
1769 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1771 /* start QDIO request for this FSF request */
1772 ret = zfcp_fsf_req_send(fsf_req, NULL);
1774 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1775 "(adapter %s, port 0x%016Lx)\n",
1776 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1780 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port 0x%016Lx)\n",
1781 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1785 zfcp_fsf_req_free(fsf_req);
1789 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1796 * zfcp_fsf_send_els_handler - handler for ELS commands
1797 * @fsf_req: pointer to struct zfcp_fsf_req
1799 * Data specific for the ELS command is passed by
1800 * fsf_req->data.send_els
1801 * Usually a specific handler for the command is called via
1802 * fsf_req->data.send_els->handler at end of this function.
1804 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1806 struct zfcp_adapter *adapter;
1807 struct zfcp_port *port;
1808 struct fsf_qtcb_header *header;
1809 struct fsf_qtcb_bottom_support *bottom;
1810 struct zfcp_send_els *send_els;
1811 int retval = -EINVAL;
1812 u16 subtable, rule, counter;
1814 adapter = fsf_req->adapter;
1815 send_els = fsf_req->data.send_els;
1816 port = send_els->port;
1817 header = &fsf_req->qtcb->header;
1818 bottom = &fsf_req->qtcb->bottom.support;
1820 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1821 goto skip_fsfstatus;
1823 switch (header->fsf_status) {
1826 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
1830 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1831 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1832 if (adapter->fc_service_class <= 3) {
1833 ZFCP_LOG_INFO("error: adapter %s does "
1834 "not support fibrechannel class %d.\n",
1835 zfcp_get_busid_by_port(port),
1836 adapter->fc_service_class);
1838 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1839 "adapter %s is invalid. "
1840 "(debug info %d)\n",
1841 zfcp_get_busid_by_port(port),
1842 adapter->fc_service_class);
1844 /* stop operation for this adapter */
1845 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1846 zfcp_erp_adapter_shutdown(port->adapter, 0);
1847 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1850 case FSF_ADAPTER_STATUS_AVAILABLE:
1851 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1852 switch (header->fsf_status_qual.word[0]){
1853 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: {
1854 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1855 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1856 if (send_els->ls_code != ZFCP_LS_ADISC)
1857 zfcp_test_link(port);
1858 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1861 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1862 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1863 /* ERP strategy will escalate */
1864 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1865 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1867 case FSF_SQ_RETRY_IF_POSSIBLE:
1868 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
1869 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1873 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1874 header->fsf_status_qual.word[0]);
1875 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1876 (char*)header->fsf_status_qual.word, 16);
1880 case FSF_ELS_COMMAND_REJECTED:
1881 ZFCP_LOG_FLAGS(2, "FSF_ELS_COMMAND_REJECTED\n");
1882 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1883 "prohibited sending "
1884 "(adapter: %s, wwpn=0x%016Lx)\n",
1885 zfcp_get_busid_by_port(port), port->wwpn);
1889 case FSF_PAYLOAD_SIZE_MISMATCH:
1890 ZFCP_LOG_FLAGS(2, "FSF_PAYLOAD_SIZE_MISMATCH\n");
1892 "ELS request size and ELS response size must be either "
1893 "both 0, or both greater than 0 "
1894 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1895 zfcp_get_busid_by_port(port),
1896 bottom->req_buf_length,
1897 bottom->resp_buf_length);
1900 case FSF_REQUEST_SIZE_TOO_LARGE:
1901 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_SIZE_TOO_LARGE\n");
1903 "Length of the ELS request buffer, "
1904 "specified in QTCB bottom, "
1905 "exceeds the size of the buffers "
1906 "that have been allocated for ELS request data "
1907 "(adapter: %s, req_buf_length=%d)\n",
1908 zfcp_get_busid_by_port(port),
1909 bottom->req_buf_length);
1912 case FSF_RESPONSE_SIZE_TOO_LARGE:
1913 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_SIZE_TOO_LARGE\n");
1915 "Length of the ELS response buffer, "
1916 "specified in QTCB bottom, "
1917 "exceeds the size of the buffers "
1918 "that have been allocated for ELS response data "
1919 "(adapter: %s, resp_buf_length=%d)\n",
1920 zfcp_get_busid_by_port(port),
1921 bottom->resp_buf_length);
1924 case FSF_UNKNOWN_COMMAND:
1925 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_COMMAND\n");
1927 "FSF command 0x%x is not supported by FCP adapter "
1928 "(adapter: %s)\n", fsf_req->fsf_command,
1929 zfcp_get_busid_by_port(port));
1930 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1933 case FSF_ACCESS_DENIED:
1934 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1935 ZFCP_LOG_NORMAL("Access denied, cannot send ELS "
1936 "(adapter: %s, wwpn=0x%016Lx)\n",
1937 zfcp_get_busid_by_port(port), port->wwpn);
1938 for (counter = 0; counter < 2; counter++) {
1939 subtable = header->fsf_status_qual.halfword[counter * 2];
1940 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1942 case FSF_SQ_CFDC_SUBTABLE_OS:
1943 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1944 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1945 case FSF_SQ_CFDC_SUBTABLE_LUN:
1946 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1947 zfcp_act_subtable_type[subtable], rule);
1951 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1952 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1957 "bug: An unknown FSF Status was presented "
1958 "(adapter: %s, fsf_status=0x%08x)\n",
1959 zfcp_get_busid_by_port(port),
1960 header->fsf_status);
1961 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1962 debug_exception(adapter->erp_dbf, 0,
1963 &header->fsf_status_qual.word[0], sizeof(u32));
1964 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1969 send_els->status = retval;
1971 if (send_els->handler != 0)
1972 send_els->handler(send_els->handler_data);
1984 * returns: address of initiated FSF request
1985 * NULL - request could not be initiated
1988 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1990 volatile struct qdio_buffer_element *sbale;
1991 unsigned long lock_flags;
1994 /* setup new FSF request */
1995 retval = zfcp_fsf_req_create(erp_action->adapter,
1996 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1997 ZFCP_REQ_AUTO_CLEANUP,
1998 erp_action->adapter->pool.fsf_req_erp,
1999 &lock_flags, &(erp_action->fsf_req));
2001 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2002 "data request for adapter %s.\n",
2003 zfcp_get_busid_by_adapter(erp_action->adapter));
2007 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2008 erp_action->fsf_req->sbal_curr, 0);
2009 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2010 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2012 erp_action->fsf_req->erp_action = erp_action;
2013 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
2016 /* start QDIO request for this FSF request */
2017 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2020 ("error: Could not send exchange configuration data "
2021 "command on the adapter %s\n",
2022 zfcp_get_busid_by_adapter(erp_action->adapter));
2023 zfcp_fsf_req_free(erp_action->fsf_req);
2024 erp_action->fsf_req = NULL;
2028 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2030 zfcp_get_busid_by_adapter(erp_action->adapter));
2033 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2039 * zfcp_fsf_exchange_config_evaluate
2040 * @fsf_req: fsf_req which belongs to xchg config data request
2041 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2043 * returns: -EIO on error, 0 otherwise
2046 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2048 struct fsf_qtcb_bottom_config *bottom;
2049 struct zfcp_adapter *adapter = fsf_req->adapter;
2051 bottom = &fsf_req->qtcb->bottom.config;
2052 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2053 bottom->low_qtcb_version, bottom->high_qtcb_version);
2054 adapter->fsf_lic_version = bottom->lic_version;
2055 adapter->supported_features = bottom->supported_features;
2058 adapter->wwnn = bottom->nport_serv_param.wwnn;
2059 adapter->wwpn = bottom->nport_serv_param.wwpn;
2060 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2061 adapter->fc_topology = bottom->fc_topology;
2062 adapter->fc_link_speed = bottom->fc_link_speed;
2063 adapter->hydra_version = bottom->adapter_type;
2068 adapter->fc_topology = 0;
2069 adapter->fc_link_speed = 0;
2070 adapter->hydra_version = 0;
2073 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2074 adapter->hardware_version = bottom->hardware_version;
2075 memcpy(adapter->serial_number, bottom->serial_number, 17);
2076 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2079 ZFCP_LOG_INFO("The adapter %s reported the following characteristics:\n"
2083 "adapter version 0x%x, "
2084 "LIC version 0x%x, "
2085 "FC link speed %d Gb/s\n",
2086 zfcp_get_busid_by_adapter(adapter),
2089 (unsigned int) adapter->s_id,
2090 adapter->hydra_version,
2091 adapter->fsf_lic_version,
2092 adapter->fc_link_speed);
2093 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2094 ZFCP_LOG_NORMAL("error: the adapter %s "
2095 "only supports newer control block "
2096 "versions in comparison to this device "
2097 "driver (try updated device driver)\n",
2098 zfcp_get_busid_by_adapter(adapter));
2099 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2100 zfcp_erp_adapter_shutdown(adapter, 0);
2103 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2104 ZFCP_LOG_NORMAL("error: the adapter %s "
2105 "only supports older control block "
2106 "versions than this device driver uses"
2107 "(consider a microcode upgrade)\n",
2108 zfcp_get_busid_by_adapter(adapter));
2109 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2110 zfcp_erp_adapter_shutdown(adapter, 0);
2117 * function: zfcp_fsf_exchange_config_data_handler
2119 * purpose: is called for finished Exchange Configuration Data command
2124 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2126 struct fsf_qtcb_bottom_config *bottom;
2127 struct zfcp_adapter *adapter = fsf_req->adapter;
2129 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2132 switch (fsf_req->qtcb->header.fsf_status) {
2135 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
2137 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2140 switch (adapter->fc_topology) {
2142 ZFCP_LOG_FLAGS(1, "FSF_TOPO_P2P\n");
2143 ZFCP_LOG_NORMAL("error: Point-to-point fibrechannel "
2144 "configuration detected at adapter %s "
2145 "unsupported, shutting down adapter\n",
2146 zfcp_get_busid_by_adapter(adapter));
2147 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2149 zfcp_erp_adapter_shutdown(adapter, 0);
2152 ZFCP_LOG_FLAGS(1, "FSF_TOPO_AL\n");
2153 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2154 "topology detected at adapter %s "
2155 "unsupported, shutting down adapter\n",
2156 zfcp_get_busid_by_adapter(adapter));
2157 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2159 zfcp_erp_adapter_shutdown(adapter, 0);
2161 case FSF_TOPO_FABRIC:
2162 ZFCP_LOG_FLAGS(1, "FSF_TOPO_FABRIC\n");
2163 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2164 "network detected at adapter %s.\n",
2165 zfcp_get_busid_by_adapter(adapter));
2168 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2169 "reported by the exchange "
2170 "configuration command for "
2171 "the adapter %s is not "
2172 "of a type known to the zfcp "
2173 "driver, shutting down adapter\n",
2174 zfcp_get_busid_by_adapter(adapter));
2175 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2177 zfcp_erp_adapter_shutdown(adapter, 0);
2180 bottom = &fsf_req->qtcb->bottom.config;
2181 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2182 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2183 "allowed by the adapter %s "
2184 "is lower than the minimum "
2185 "required by the driver (%ld bytes).\n",
2186 bottom->max_qtcb_size,
2187 zfcp_get_busid_by_adapter(adapter),
2188 sizeof(struct fsf_qtcb));
2189 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2191 debug_event(fsf_req->adapter->erp_dbf, 0,
2192 &bottom->max_qtcb_size, sizeof (u32));
2193 zfcp_erp_adapter_shutdown(adapter, 0);
2196 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2199 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2200 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2202 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2205 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2206 zfcp_get_busid_by_adapter(adapter));
2207 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2208 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2210 zfcp_erp_adapter_failed(adapter);
2213 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2214 debug_event(fsf_req->adapter->erp_dbf, 0,
2215 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2216 zfcp_erp_adapter_shutdown(adapter, 0);
2223 * function: zfcp_fsf_open_port
2227 * returns: address of initiated FSF request
2228 * NULL - request could not be initiated
2231 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2233 volatile struct qdio_buffer_element *sbale;
2234 unsigned long lock_flags;
2237 /* setup new FSF request */
2238 retval = zfcp_fsf_req_create(erp_action->adapter,
2239 FSF_QTCB_OPEN_PORT_WITH_DID,
2240 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2241 erp_action->adapter->pool.fsf_req_erp,
2242 &lock_flags, &(erp_action->fsf_req));
2244 ZFCP_LOG_INFO("error: Could not create open port request "
2245 "for port 0x%016Lx on adapter %s.\n",
2246 erp_action->port->wwpn,
2247 zfcp_get_busid_by_adapter(erp_action->adapter));
2251 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2252 erp_action->fsf_req->sbal_curr, 0);
2253 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2254 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2256 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2257 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2258 erp_action->fsf_req->data.open_port.port = erp_action->port;
2259 erp_action->fsf_req->erp_action = erp_action;
2261 /* start QDIO request for this FSF request */
2262 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2264 ZFCP_LOG_INFO("error: Could not send open port request for "
2265 "port 0x%016Lx on adapter %s.\n",
2266 erp_action->port->wwpn,
2267 zfcp_get_busid_by_adapter(erp_action->adapter));
2268 zfcp_fsf_req_free(erp_action->fsf_req);
2269 erp_action->fsf_req = NULL;
2273 ZFCP_LOG_DEBUG("open port request initiated "
2274 "(adapter %s, port 0x%016Lx)\n",
2275 zfcp_get_busid_by_adapter(erp_action->adapter),
2276 erp_action->port->wwpn);
2278 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2284 * function: zfcp_fsf_open_port_handler
2286 * purpose: is called for finished Open Port command
2291 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2293 int retval = -EINVAL;
2294 struct zfcp_port *port;
2295 struct fsf_plogi *plogi;
2296 struct fsf_qtcb_header *header;
2297 u16 subtable, rule, counter;
2299 port = fsf_req->data.open_port.port;
2300 header = &fsf_req->qtcb->header;
2302 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2303 /* don't change port status in our bookkeeping */
2304 goto skip_fsfstatus;
2307 /* evaluate FSF status in QTCB */
2308 switch (header->fsf_status) {
2310 case FSF_PORT_ALREADY_OPEN:
2311 ZFCP_LOG_FLAGS(0, "FSF_PORT_ALREADY_OPEN\n");
2312 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2313 "is already open.\n",
2314 port->wwpn, zfcp_get_busid_by_port(port));
2315 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2318 * This is a bug, however operation should continue normally
2319 * if it is simply ignored
2323 case FSF_ACCESS_DENIED:
2324 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2325 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2327 port->wwpn, zfcp_get_busid_by_port(port));
2328 for (counter = 0; counter < 2; counter++) {
2329 subtable = header->fsf_status_qual.halfword[counter * 2];
2330 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2332 case FSF_SQ_CFDC_SUBTABLE_OS:
2333 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2334 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2335 case FSF_SQ_CFDC_SUBTABLE_LUN:
2336 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2337 zfcp_act_subtable_type[subtable], rule);
2341 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2342 zfcp_erp_port_failed(port);
2343 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2346 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2347 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED\n");
2348 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2349 "The remote port 0x%016Lx on adapter %s "
2350 "could not be opened. Disabling it.\n",
2351 port->wwpn, zfcp_get_busid_by_port(port));
2352 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2354 zfcp_erp_port_failed(port);
2355 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2358 case FSF_ADAPTER_STATUS_AVAILABLE:
2359 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2360 switch (header->fsf_status_qual.word[0]) {
2361 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2363 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2364 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2366 /* ERP strategy will escalate */
2367 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2369 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2370 /* ERP strategy will escalate */
2371 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2373 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2375 case FSF_SQ_NO_RETRY_POSSIBLE:
2376 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RETRY_POSSIBLE\n");
2377 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2378 "adapter %s could not be opened. "
2381 zfcp_get_busid_by_port(port));
2382 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2384 zfcp_erp_port_failed(port);
2385 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2389 ("bug: Wrong status qualifier 0x%x arrived.\n",
2390 header->fsf_status_qual.word[0]);
2391 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2394 fsf_req->adapter->erp_dbf, 0,
2395 &header->fsf_status_qual.word[0],
2402 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2403 /* save port handle assigned by FSF */
2404 port->handle = header->port_handle;
2405 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2406 "was opened, it's port handle is 0x%x\n",
2407 port->wwpn, zfcp_get_busid_by_port(port),
2409 /* mark port as open */
2410 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2411 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2413 /* check whether D_ID has changed during open */
2415 * FIXME: This check is not airtight, as the FCP channel does
2416 * not monitor closures of target port connections caused on
2417 * the remote side. Thus, they might miss out on invalidating
2418 * locally cached WWPNs (and other N_Port parameters) of gone
2419 * target ports. So, our heroic attempt to make things safe
2420 * could be undermined by 'open port' response data tagged with
2421 * obsolete WWPNs. Another reason to monitor potential
2422 * connection closures ourself at least (by interpreting
2423 * incoming ELS' and unsolicited status). It just crosses my
2424 * mind that one should be able to cross-check by means of
2425 * another GID_PN straight after a port has been opened.
2426 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2428 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2429 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2431 if (fsf_req->qtcb->bottom.support.els1_length <
2432 ((((unsigned long) &plogi->serv_param.wwpn) -
2433 ((unsigned long) plogi)) + sizeof (u64))) {
2435 "warning: insufficient length of "
2436 "PLOGI payload (%i)\n",
2437 fsf_req->qtcb->bottom.support.els1_length);
2438 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2439 "fsf_s_short_plogi:");
2440 /* skip sanity check and assume wwpn is ok */
2442 if (plogi->serv_param.wwpn != port->wwpn) {
2443 ZFCP_LOG_INFO("warning: d_id of port "
2444 "0x%016Lx changed during "
2445 "open\n", port->wwpn);
2447 fsf_req->adapter->erp_dbf, 0,
2448 "fsf_s_did_change:");
2450 ZFCP_STATUS_PORT_DID_DID,
2453 port->wwnn = plogi->serv_param.wwnn;
2459 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2460 "(debug info 0x%x)\n",
2461 header->fsf_status);
2462 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2463 debug_exception(fsf_req->adapter->erp_dbf, 0,
2464 &header->fsf_status, sizeof (u32));
2469 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2474 * function: zfcp_fsf_close_port
2476 * purpose: submit FSF command "close port"
2478 * returns: address of initiated FSF request
2479 * NULL - request could not be initiated
2482 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2484 volatile struct qdio_buffer_element *sbale;
2485 unsigned long lock_flags;
2488 /* setup new FSF request */
2489 retval = zfcp_fsf_req_create(erp_action->adapter,
2490 FSF_QTCB_CLOSE_PORT,
2491 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2492 erp_action->adapter->pool.fsf_req_erp,
2493 &lock_flags, &(erp_action->fsf_req));
2495 ZFCP_LOG_INFO("error: Could not create a close port request "
2496 "for port 0x%016Lx on adapter %s.\n",
2497 erp_action->port->wwpn,
2498 zfcp_get_busid_by_adapter(erp_action->adapter));
2502 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2503 erp_action->fsf_req->sbal_curr, 0);
2504 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2505 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2507 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2508 erp_action->fsf_req->data.close_port.port = erp_action->port;
2509 erp_action->fsf_req->erp_action = erp_action;
2510 erp_action->fsf_req->qtcb->header.port_handle =
2511 erp_action->port->handle;
2513 /* start QDIO request for this FSF request */
2514 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2516 ZFCP_LOG_INFO("error: Could not send a close port request for "
2517 "port 0x%016Lx on adapter %s.\n",
2518 erp_action->port->wwpn,
2519 zfcp_get_busid_by_adapter(erp_action->adapter));
2520 zfcp_fsf_req_free(erp_action->fsf_req);
2521 erp_action->fsf_req = NULL;
2525 ZFCP_LOG_TRACE("close port request initiated "
2526 "(adapter %s, port 0x%016Lx)\n",
2527 zfcp_get_busid_by_adapter(erp_action->adapter),
2528 erp_action->port->wwpn);
2530 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2536 * function: zfcp_fsf_close_port_handler
2538 * purpose: is called for finished Close Port FSF command
2543 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2545 int retval = -EINVAL;
2546 struct zfcp_port *port;
2548 port = fsf_req->data.close_port.port;
2550 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2551 /* don't change port status in our bookkeeping */
2552 goto skip_fsfstatus;
2555 /* evaluate FSF status in QTCB */
2556 switch (fsf_req->qtcb->header.fsf_status) {
2558 case FSF_PORT_HANDLE_NOT_VALID:
2559 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2560 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2561 "0x%016Lx on adapter %s invalid. This may happen "
2562 "occasionally.\n", port->handle,
2563 port->wwpn, zfcp_get_busid_by_port(port));
2564 ZFCP_LOG_DEBUG("status qualifier:\n");
2565 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2566 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2567 sizeof (union fsf_status_qual));
2568 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2570 zfcp_erp_adapter_reopen(port->adapter, 0);
2571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2574 case FSF_ADAPTER_STATUS_AVAILABLE:
2575 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2576 /* Note: FSF has actually closed the port in this case.
2577 * The status code is just daft. Fingers crossed for a change
2583 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2584 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2585 "port handle 0x%x\n", port->wwpn,
2586 zfcp_get_busid_by_port(port), port->handle);
2587 zfcp_erp_modify_port_status(port,
2588 ZFCP_STATUS_COMMON_OPEN,
2594 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2595 "(debug info 0x%x)\n",
2596 fsf_req->qtcb->header.fsf_status);
2597 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2598 debug_exception(fsf_req->adapter->erp_dbf, 0,
2599 &fsf_req->qtcb->header.fsf_status,
2605 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2610 * function: zfcp_fsf_close_physical_port
2612 * purpose: submit FSF command "close physical port"
2614 * returns: address of initiated FSF request
2615 * NULL - request could not be initiated
2618 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2621 unsigned long lock_flags;
2622 volatile struct qdio_buffer_element *sbale;
2624 /* setup new FSF request */
2625 retval = zfcp_fsf_req_create(erp_action->adapter,
2626 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2627 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2628 erp_action->adapter->pool.fsf_req_erp,
2629 &lock_flags, &erp_action->fsf_req);
2631 ZFCP_LOG_INFO("error: Could not create close physical port "
2632 "request (adapter %s, port 0x%016Lx)\n",
2633 zfcp_get_busid_by_adapter(erp_action->adapter),
2634 erp_action->port->wwpn);
2639 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2640 erp_action->fsf_req->sbal_curr, 0);
2641 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2642 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2644 /* mark port as being closed */
2645 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2646 &erp_action->port->status);
2647 /* save a pointer to this port */
2648 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2649 /* port to be closeed */
2650 erp_action->fsf_req->qtcb->header.port_handle =
2651 erp_action->port->handle;
2652 erp_action->fsf_req->erp_action = erp_action;
2654 /* start QDIO request for this FSF request */
2655 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2657 ZFCP_LOG_INFO("error: Could not send close physical port "
2658 "request (adapter %s, port 0x%016Lx)\n",
2659 zfcp_get_busid_by_adapter(erp_action->adapter),
2660 erp_action->port->wwpn);
2661 zfcp_fsf_req_free(erp_action->fsf_req);
2662 erp_action->fsf_req = NULL;
2666 ZFCP_LOG_TRACE("close physical port request initiated "
2667 "(adapter %s, port 0x%016Lx)\n",
2668 zfcp_get_busid_by_adapter(erp_action->adapter),
2669 erp_action->port->wwpn);
2671 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2677 * function: zfcp_fsf_close_physical_port_handler
2679 * purpose: is called for finished Close Physical Port FSF command
2684 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2686 int retval = -EINVAL;
2687 struct zfcp_port *port;
2688 struct zfcp_unit *unit;
2689 struct fsf_qtcb_header *header;
2690 u16 subtable, rule, counter;
2692 port = fsf_req->data.close_physical_port.port;
2693 header = &fsf_req->qtcb->header;
2695 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2696 /* don't change port status in our bookkeeping */
2697 goto skip_fsfstatus;
2700 /* evaluate FSF status in QTCB */
2701 switch (header->fsf_status) {
2703 case FSF_PORT_HANDLE_NOT_VALID:
2704 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2705 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2706 "(adapter %s, port 0x%016Lx). "
2707 "This may happen occasionally.\n",
2709 zfcp_get_busid_by_port(port),
2711 ZFCP_LOG_DEBUG("status qualifier:\n");
2712 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2713 (char *) &header->fsf_status_qual,
2714 sizeof (union fsf_status_qual));
2715 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2717 zfcp_erp_adapter_reopen(port->adapter, 0);
2718 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2721 case FSF_ACCESS_DENIED:
2722 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2723 ZFCP_LOG_NORMAL("Access denied, cannot close "
2724 "physical port 0x%016Lx on "
2725 "adapter %s\n", port->wwpn,
2726 zfcp_get_busid_by_port(port));
2727 for (counter = 0; counter < 2; counter++) {
2728 subtable = header->fsf_status_qual.halfword[counter * 2];
2729 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2731 case FSF_SQ_CFDC_SUBTABLE_OS:
2732 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2733 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2734 case FSF_SQ_CFDC_SUBTABLE_LUN:
2735 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2736 zfcp_act_subtable_type[subtable], rule);
2740 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2741 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2744 case FSF_PORT_BOXED:
2745 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
2746 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2747 "%s needs to be reopened but it was attempted "
2748 "to close it physically.\n",
2750 zfcp_get_busid_by_port(port));
2751 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2752 zfcp_erp_port_reopen(port, 0);
2753 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2754 ZFCP_STATUS_FSFREQ_RETRY;
2757 case FSF_ADAPTER_STATUS_AVAILABLE:
2758 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2759 switch (header->fsf_status_qual.word[0]) {
2760 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2762 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2763 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2765 /* This will now be escalated by ERP */
2766 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2768 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2770 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
2771 /* ERP strategy will escalate */
2772 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2774 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2778 ("bug: Wrong status qualifier 0x%x arrived.\n",
2779 header->fsf_status_qual.word[0]);
2780 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2783 fsf_req->adapter->erp_dbf, 0,
2784 &header->fsf_status_qual.word[0], sizeof (u32));
2790 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2791 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2792 "physically closed, port handle 0x%x\n",
2794 zfcp_get_busid_by_port(port), port->handle);
2795 /* can't use generic zfcp_erp_modify_port_status because
2796 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2798 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2799 list_for_each_entry(unit, &port->unit_list_head, list)
2800 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2805 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2806 "(debug info 0x%x)\n",
2807 header->fsf_status);
2808 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2809 debug_exception(fsf_req->adapter->erp_dbf, 0,
2810 &header->fsf_status, sizeof (u32));
2815 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2820 * function: zfcp_fsf_open_unit
2826 * assumptions: This routine does not check whether the associated
2827 * remote port has already been opened. This should be
2828 * done by calling routines. Otherwise some status
2829 * may be presented by FSF
2832 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2834 volatile struct qdio_buffer_element *sbale;
2835 unsigned long lock_flags;
2838 /* setup new FSF request */
2839 retval = zfcp_fsf_req_create(erp_action->adapter,
2841 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2842 erp_action->adapter->pool.fsf_req_erp,
2843 &lock_flags, &(erp_action->fsf_req));
2845 ZFCP_LOG_INFO("error: Could not create open unit request for "
2846 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2847 erp_action->unit->fcp_lun,
2848 erp_action->unit->port->wwpn,
2849 zfcp_get_busid_by_adapter(erp_action->adapter));
2853 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2854 erp_action->fsf_req->sbal_curr, 0);
2855 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2856 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2858 erp_action->fsf_req->qtcb->header.port_handle =
2859 erp_action->port->handle;
2860 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2861 erp_action->unit->fcp_lun;
2862 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2863 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2864 erp_action->fsf_req->erp_action = erp_action;
2866 /* start QDIO request for this FSF request */
2867 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2869 ZFCP_LOG_INFO("error: Could not send an open unit request "
2870 "on the adapter %s, port 0x%016Lx for "
2872 zfcp_get_busid_by_adapter(erp_action->adapter),
2873 erp_action->port->wwpn,
2874 erp_action->unit->fcp_lun);
2875 zfcp_fsf_req_free(erp_action->fsf_req);
2876 erp_action->fsf_req = NULL;
2880 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2881 "port 0x%016Lx, unit 0x%016Lx)\n",
2882 zfcp_get_busid_by_adapter(erp_action->adapter),
2883 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2885 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2891 * function: zfcp_fsf_open_unit_handler
2893 * purpose: is called for finished Open LUN command
2898 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2900 int retval = -EINVAL;
2901 struct zfcp_adapter *adapter;
2902 struct zfcp_unit *unit;
2903 struct fsf_qtcb_header *header;
2904 struct fsf_qtcb_bottom_support *bottom;
2905 u16 subtable, rule, counter;
2907 adapter = fsf_req->adapter;
2908 unit = fsf_req->data.open_unit.unit;
2909 header = &fsf_req->qtcb->header;
2910 bottom = &fsf_req->qtcb->bottom.support;
2912 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2913 /* don't change unit status in our bookkeeping */
2914 goto skip_fsfstatus;
2917 /* evaluate FSF status in QTCB */
2918 switch (header->fsf_status) {
2920 case FSF_PORT_HANDLE_NOT_VALID:
2921 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2922 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2923 "for port 0x%016Lx on adapter %s invalid "
2924 "This may happen occasionally\n",
2926 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2927 ZFCP_LOG_DEBUG("status qualifier:\n");
2928 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2929 (char *) &header->fsf_status_qual,
2930 sizeof (union fsf_status_qual));
2931 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
2932 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
2933 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2936 case FSF_LUN_ALREADY_OPEN:
2937 ZFCP_LOG_FLAGS(0, "FSF_LUN_ALREADY_OPEN\n");
2938 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
2939 "remote port 0x%016Lx on adapter %s twice.\n",
2941 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2942 debug_text_exception(adapter->erp_dbf, 0,
2944 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2947 case FSF_ACCESS_DENIED:
2948 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2949 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
2950 "remote port 0x%016Lx on adapter %s\n",
2951 unit->fcp_lun, unit->port->wwpn,
2952 zfcp_get_busid_by_unit(unit));
2953 for (counter = 0; counter < 2; counter++) {
2954 subtable = header->fsf_status_qual.halfword[counter * 2];
2955 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2957 case FSF_SQ_CFDC_SUBTABLE_OS:
2958 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2959 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2960 case FSF_SQ_CFDC_SUBTABLE_LUN:
2961 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2962 zfcp_act_subtable_type[subtable], rule);
2966 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
2967 zfcp_erp_unit_failed(unit);
2968 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2971 case FSF_PORT_BOXED:
2972 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
2973 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
2974 "needs to be reopened\n",
2975 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2976 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
2977 zfcp_erp_port_reopen(unit->port, 0);
2978 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2979 ZFCP_STATUS_FSFREQ_RETRY;
2982 case FSF_LUN_SHARING_VIOLATION :
2983 ZFCP_LOG_FLAGS(2, "FSF_LUN_SHARING_VIOLATION\n");
2984 if (header->fsf_status_qual.word[0] != 0) {
2985 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
2987 "connected to the adapter %s "
2988 "is already in use in LPAR%d\n",
2991 zfcp_get_busid_by_unit(unit),
2992 header->fsf_status_qual.fsf_queue_designator.hla);
2994 subtable = header->fsf_status_qual.halfword[4];
2995 rule = header->fsf_status_qual.halfword[5];
2997 case FSF_SQ_CFDC_SUBTABLE_OS:
2998 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2999 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3000 case FSF_SQ_CFDC_SUBTABLE_LUN:
3001 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3002 "remote port with WWPN 0x%Lx "
3003 "connected to the adapter %s "
3004 "is denied (%s rule %d)\n",
3007 zfcp_get_busid_by_unit(unit),
3008 zfcp_act_subtable_type[subtable],
3013 ZFCP_LOG_DEBUG("status qualifier:\n");
3014 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3015 (char *) &header->fsf_status_qual,
3016 sizeof (union fsf_status_qual));
3017 debug_text_event(adapter->erp_dbf, 2,
3019 zfcp_erp_unit_failed(unit);
3020 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3023 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3024 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED\n");
3025 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3026 "There is no handle (temporary port identifier) "
3027 "available for unit 0x%016Lx on port 0x%016Lx "
3031 zfcp_get_busid_by_unit(unit));
3032 debug_text_event(adapter->erp_dbf, 1,
3034 zfcp_erp_unit_failed(unit);
3035 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3038 case FSF_ADAPTER_STATUS_AVAILABLE:
3039 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3040 switch (header->fsf_status_qual.word[0]) {
3041 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3043 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3044 /* Re-establish link to port */
3045 debug_text_event(adapter->erp_dbf, 1,
3047 zfcp_erp_port_reopen(unit->port, 0);
3048 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3050 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3052 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3053 /* ERP strategy will escalate */
3054 debug_text_event(adapter->erp_dbf, 1,
3056 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3060 ("bug: Wrong status qualifier 0x%x arrived.\n",
3061 header->fsf_status_qual.word[0]);
3062 debug_text_event(adapter->erp_dbf, 0,
3064 debug_exception(adapter->erp_dbf, 0,
3065 &header->fsf_status_qual.word[0],
3070 case FSF_INVALID_COMMAND_OPTION:
3071 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
3073 "Invalid option 0x%x has been specified "
3074 "in QTCB bottom sent to the adapter %s\n",
3076 zfcp_get_busid_by_adapter(adapter));
3077 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3082 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3083 /* save LUN handle assigned by FSF */
3084 unit->handle = header->lun_handle;
3085 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3086 "adapter %s opened, port handle 0x%x\n",
3089 zfcp_get_busid_by_unit(unit),
3091 /* mark unit as open */
3092 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3097 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3098 "(debug info 0x%x)\n",
3099 header->fsf_status);
3100 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3101 debug_exception(adapter->erp_dbf, 0,
3102 &header->fsf_status, sizeof (u32));
3107 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3112 * function: zfcp_fsf_close_unit
3116 * returns: address of fsf_req - request successfully initiated
3119 * assumptions: This routine does not check whether the associated
3120 * remote port/lun has already been opened. This should be
3121 * done by calling routines. Otherwise some status
3122 * may be presented by FSF
3125 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3127 volatile struct qdio_buffer_element *sbale;
3128 unsigned long lock_flags;
3131 /* setup new FSF request */
3132 retval = zfcp_fsf_req_create(erp_action->adapter,
3134 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3135 erp_action->adapter->pool.fsf_req_erp,
3136 &lock_flags, &(erp_action->fsf_req));
3138 ZFCP_LOG_INFO("error: Could not create close unit request for "
3139 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3140 erp_action->unit->fcp_lun,
3141 erp_action->port->wwpn,
3142 zfcp_get_busid_by_adapter(erp_action->adapter));
3146 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3147 erp_action->fsf_req->sbal_curr, 0);
3148 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3149 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3151 erp_action->fsf_req->qtcb->header.port_handle =
3152 erp_action->port->handle;
3153 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3154 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3155 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3156 erp_action->fsf_req->erp_action = erp_action;
3158 /* start QDIO request for this FSF request */
3159 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3161 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3162 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3163 erp_action->unit->fcp_lun,
3164 erp_action->port->wwpn,
3165 zfcp_get_busid_by_adapter(erp_action->adapter));
3166 zfcp_fsf_req_free(erp_action->fsf_req);
3167 erp_action->fsf_req = NULL;
3171 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3172 "port 0x%016Lx, unit 0x%016Lx)\n",
3173 zfcp_get_busid_by_adapter(erp_action->adapter),
3174 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3176 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3182 * function: zfcp_fsf_close_unit_handler
3184 * purpose: is called for finished Close LUN FSF command
3189 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3191 int retval = -EINVAL;
3192 struct zfcp_unit *unit;
3194 unit = fsf_req->data.close_unit.unit; /* restore unit */
3196 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3197 /* don't change unit status in our bookkeeping */
3198 goto skip_fsfstatus;
3201 /* evaluate FSF status in QTCB */
3202 switch (fsf_req->qtcb->header.fsf_status) {
3204 case FSF_PORT_HANDLE_NOT_VALID:
3205 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3206 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3207 "0x%016Lx on adapter %s invalid. This may "
3208 "happen in rare circumstances\n",
3211 zfcp_get_busid_by_unit(unit));
3212 ZFCP_LOG_DEBUG("status qualifier:\n");
3213 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3214 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3215 sizeof (union fsf_status_qual));
3216 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3218 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3219 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3220 &fsf_req->qtcb->header.fsf_status_qual,
3221 sizeof (union fsf_status_qual));
3222 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3225 case FSF_LUN_HANDLE_NOT_VALID:
3226 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3227 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3228 "0x%016Lx on port 0x%016Lx on adapter %s is "
3229 "invalid. This may happen occasionally.\n",
3233 zfcp_get_busid_by_unit(unit));
3234 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3235 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3236 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3237 sizeof (union fsf_status_qual));
3238 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3240 zfcp_erp_port_reopen(unit->port, 0);
3241 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3242 &fsf_req->qtcb->header.fsf_status_qual,
3243 sizeof (union fsf_status_qual));
3244 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3247 case FSF_PORT_BOXED:
3248 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3249 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3250 "needs to be reopened\n",
3252 zfcp_get_busid_by_unit(unit));
3253 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3254 zfcp_erp_port_reopen(unit->port, 0);
3255 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3256 ZFCP_STATUS_FSFREQ_RETRY;
3259 case FSF_ADAPTER_STATUS_AVAILABLE:
3260 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3261 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3262 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3264 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3265 /* re-establish link to port */
3266 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3268 zfcp_erp_port_reopen(unit->port, 0);
3269 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3271 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3273 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3274 /* ERP strategy will escalate */
3275 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3277 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3281 ("bug: Wrong status qualifier 0x%x arrived.\n",
3282 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3283 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3286 fsf_req->adapter->erp_dbf, 0,
3287 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3294 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3295 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3296 "closed, port handle 0x%x\n",
3299 zfcp_get_busid_by_unit(unit),
3301 /* mark unit as closed */
3302 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3307 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3308 "(debug info 0x%x)\n",
3309 fsf_req->qtcb->header.fsf_status);
3310 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3311 debug_exception(fsf_req->adapter->erp_dbf, 0,
3312 &fsf_req->qtcb->header.fsf_status,
3318 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3323 * function: zfcp_fsf_send_fcp_command_task
3329 * note: we do not employ linked commands (not supported by HBA anyway)
3332 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3333 struct zfcp_unit *unit,
3334 struct scsi_cmnd * scsi_cmnd, int req_flags)
3336 struct zfcp_fsf_req *fsf_req = NULL;
3337 struct fcp_cmnd_iu *fcp_cmnd_iu;
3338 unsigned int sbtype;
3339 unsigned long lock_flags;
3343 /* setup new FSF request */
3344 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3345 adapter->pool.fsf_req_scsi,
3346 &lock_flags, &fsf_req);
3347 if (unlikely(retval < 0)) {
3348 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3349 "for unit 0x%016Lx on port 0x%016Lx on "
3353 zfcp_get_busid_by_adapter(adapter));
3354 goto failed_req_create;
3358 * associate FSF request with SCSI request
3359 * (need this for look up on abort)
3361 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3362 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3365 * associate SCSI command with FSF request
3366 * (need this for look up on normal command completion)
3368 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3369 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3370 fsf_req->data.send_fcp_command_task.unit = unit;
3371 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3373 /* set handles of unit and its parent port in QTCB */
3374 fsf_req->qtcb->header.lun_handle = unit->handle;
3375 fsf_req->qtcb->header.port_handle = unit->port->handle;
3377 /* FSF does not define the structure of the FCP_CMND IU */
3378 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3379 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3382 * set depending on data direction:
3383 * data direction bits in SBALE (SB Type)
3384 * data direction bits in QTCB
3385 * data direction bits in FCP_CMND IU
3387 switch (scsi_cmnd->sc_data_direction) {
3389 ZFCP_LOG_FLAGS(3, "DMA_NONE\n");
3390 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3393 * what is the correct type for commands
3394 * without 'real' data buffers?
3396 sbtype = SBAL_FLAGS0_TYPE_READ;
3398 case DMA_FROM_DEVICE:
3399 ZFCP_LOG_FLAGS(3, "DMA_FROM_DEVICE\n");
3400 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3401 sbtype = SBAL_FLAGS0_TYPE_READ;
3402 fcp_cmnd_iu->rddata = 1;
3405 ZFCP_LOG_FLAGS(3, "DMA_TO_DEVICE\n");
3406 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3407 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3408 fcp_cmnd_iu->wddata = 1;
3410 case DMA_BIDIRECTIONAL:
3411 ZFCP_LOG_FLAGS(0, "DMA_BIDIRECTIONAL not supported\n");
3414 * dummy, catch this condition earlier
3415 * in zfcp_scsi_queuecommand
3417 goto failed_scsi_cmnd;
3420 /* set FC service class in QTCB (3 per default) */
3421 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3423 /* set FCP_LUN in FCP_CMND IU in QTCB */
3424 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3426 /* set task attributes in FCP_CMND IU in QTCB */
3427 if (likely(scsi_cmnd->device->simple_tags)) {
3428 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3429 ZFCP_LOG_TRACE("setting SIMPLE_Q task attribute\n");
3431 fcp_cmnd_iu->task_attribute = UNTAGGED;
3432 ZFCP_LOG_TRACE("setting UNTAGGED task attribute\n");
3435 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3436 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3437 fcp_cmnd_iu->add_fcp_cdb_length
3438 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3439 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3440 "additional FCP_CDB length is 0x%x "
3441 "(shifted right 2 bits)\n",
3443 fcp_cmnd_iu->add_fcp_cdb_length);
3446 * copy SCSI CDB (including additional length, if any) to
3447 * FCP_CDB in FCP_CMND IU in QTCB
3449 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3451 /* FCP CMND IU length in QTCB */
3452 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3453 sizeof (struct fcp_cmnd_iu) +
3454 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3456 /* generate SBALEs from data buffer */
3457 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3458 if (unlikely(real_bytes < 0)) {
3459 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3461 "Data did not fit into available buffer(s), "
3462 "waiting for more...\n");
3465 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3466 "required. Shutting down unit "
3467 "(adapter %s, port 0x%016Lx, "
3469 zfcp_get_busid_by_unit(unit),
3472 zfcp_erp_unit_shutdown(unit, 0);
3478 /* set length of FCP data length in FCP_CMND IU in QTCB */
3479 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3481 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3482 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3483 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3486 * start QDIO request for this FSF request
3487 * covered by an SBALE)
3489 retval = zfcp_fsf_req_send(fsf_req, NULL);
3490 if (unlikely(retval < 0)) {
3491 ZFCP_LOG_INFO("error: Could not send FCP command request "
3492 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3493 zfcp_get_busid_by_adapter(adapter),
3499 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3500 "port 0x%016Lx, unit 0x%016Lx)\n",
3501 zfcp_get_busid_by_adapter(adapter),
3509 zfcp_fsf_req_free(fsf_req);
3511 scsi_cmnd->host_scribble = NULL;
3514 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3519 * function: zfcp_fsf_send_fcp_command_task_management
3525 * FIXME(design): should be watched by a timeout!!!
3526 * FIXME(design) shouldn't this be modified to return an int
3527 * also...don't know how though
3530 struct zfcp_fsf_req *
3531 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3532 struct zfcp_unit *unit,
3533 u8 tm_flags, int req_flags)
3535 struct zfcp_fsf_req *fsf_req = NULL;
3537 struct fcp_cmnd_iu *fcp_cmnd_iu;
3538 unsigned long lock_flags;
3539 volatile struct qdio_buffer_element *sbale;
3541 /* setup new FSF request */
3542 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3543 adapter->pool.fsf_req_scsi,
3544 &lock_flags, &fsf_req);
3546 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3547 "management) request for adapter %s, port "
3548 " 0x%016Lx, unit 0x%016Lx.\n",
3549 zfcp_get_busid_by_adapter(adapter),
3550 unit->port->wwpn, unit->fcp_lun);
3555 * Used to decide on proper handler in the return path,
3556 * could be either zfcp_fsf_send_fcp_command_task_handler or
3557 * zfcp_fsf_send_fcp_command_task_management_handler */
3559 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3562 * hold a pointer to the unit being target of this
3563 * task management request
3565 fsf_req->data.send_fcp_command_task_management.unit = unit;
3567 /* set FSF related fields in QTCB */
3568 fsf_req->qtcb->header.lun_handle = unit->handle;
3569 fsf_req->qtcb->header.port_handle = unit->port->handle;
3570 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3571 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3572 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3573 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3575 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3576 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3577 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3579 /* set FCP related fields in FCP_CMND IU in QTCB */
3580 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3581 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3582 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3583 fcp_cmnd_iu->task_management_flags = tm_flags;
3585 /* start QDIO request for this FSF request */
3586 zfcp_fsf_start_scsi_er_timer(adapter);
3587 retval = zfcp_fsf_req_send(fsf_req, NULL);
3589 del_timer(&adapter->scsi_er_timer);
3590 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3591 "management) on adapter %s, port 0x%016Lx for "
3592 "unit LUN 0x%016Lx\n",
3593 zfcp_get_busid_by_adapter(adapter),
3596 zfcp_fsf_req_free(fsf_req);
3601 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3602 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3604 zfcp_get_busid_by_adapter(adapter),
3609 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3614 * function: zfcp_fsf_send_fcp_command_handler
3616 * purpose: is called for finished Send FCP Command
3621 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3623 int retval = -EINVAL;
3624 struct zfcp_unit *unit;
3625 struct fsf_qtcb_header *header;
3626 u16 subtable, rule, counter;
3628 header = &fsf_req->qtcb->header;
3630 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3631 unit = fsf_req->data.send_fcp_command_task_management.unit;
3633 unit = fsf_req->data.send_fcp_command_task.unit;
3635 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3636 /* go directly to calls of special handlers */
3637 goto skip_fsfstatus;
3640 /* evaluate FSF status in QTCB */
3641 switch (header->fsf_status) {
3643 case FSF_PORT_HANDLE_NOT_VALID:
3644 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3645 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3646 "0x%016Lx on adapter %s invalid\n",
3648 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3649 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3650 (char *) &header->fsf_status_qual,
3651 sizeof (union fsf_status_qual));
3652 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3654 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3655 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3658 case FSF_LUN_HANDLE_NOT_VALID:
3659 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3660 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3661 "0x%016Lx on port 0x%016Lx on adapter %s is "
3662 "invalid. This may happen occasionally.\n",
3666 zfcp_get_busid_by_unit(unit));
3667 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3668 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3669 (char *) &header->fsf_status_qual,
3670 sizeof (union fsf_status_qual));
3671 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3673 zfcp_erp_port_reopen(unit->port, 0);
3674 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3677 case FSF_HANDLE_MISMATCH:
3678 ZFCP_LOG_FLAGS(0, "FSF_HANDLE_MISMATCH\n");
3679 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3680 "unexpectedly. (adapter %s, port 0x%016Lx, "
3683 zfcp_get_busid_by_unit(unit),
3686 ZFCP_LOG_NORMAL("status qualifier:\n");
3687 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3688 (char *) &header->fsf_status_qual,
3689 sizeof (union fsf_status_qual));
3690 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3692 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3693 zfcp_cmd_dbf_event_fsf("handmism",
3695 &header->fsf_status_qual,
3696 sizeof (union fsf_status_qual));
3697 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3700 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3701 ZFCP_LOG_FLAGS(0, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
3702 if (fsf_req->adapter->fc_service_class <= 3) {
3703 ZFCP_LOG_NORMAL("error: The adapter %s does "
3704 "not support fibrechannel class %d.\n",
3705 zfcp_get_busid_by_unit(unit),
3706 fsf_req->adapter->fc_service_class);
3708 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3709 "adapter %s is invalid. "
3710 "(debug info %d)\n",
3711 zfcp_get_busid_by_unit(unit),
3712 fsf_req->adapter->fc_service_class);
3714 /* stop operation for this adapter */
3715 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3716 "fsf_s_class_nsup");
3717 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3718 zfcp_cmd_dbf_event_fsf("unsclass",
3720 &header->fsf_status_qual,
3721 sizeof (union fsf_status_qual));
3722 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3725 case FSF_FCPLUN_NOT_VALID:
3726 ZFCP_LOG_FLAGS(0, "FSF_FCPLUN_NOT_VALID\n");
3727 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3728 "adapter %s does not have correct unit "
3732 zfcp_get_busid_by_unit(unit),
3734 ZFCP_LOG_DEBUG("status qualifier:\n");
3735 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3736 (char *) &header->fsf_status_qual,
3737 sizeof (union fsf_status_qual));
3738 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3739 "fsf_s_fcp_lun_nv");
3740 zfcp_erp_port_reopen(unit->port, 0);
3741 zfcp_cmd_dbf_event_fsf("fluninv",
3743 &header->fsf_status_qual,
3744 sizeof (union fsf_status_qual));
3745 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3748 case FSF_ACCESS_DENIED:
3749 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
3750 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3751 "unit 0x%016Lx on port 0x%016Lx on "
3752 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3753 zfcp_get_busid_by_unit(unit));
3754 for (counter = 0; counter < 2; counter++) {
3755 subtable = header->fsf_status_qual.halfword[counter * 2];
3756 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3758 case FSF_SQ_CFDC_SUBTABLE_OS:
3759 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3760 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3761 case FSF_SQ_CFDC_SUBTABLE_LUN:
3762 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3763 zfcp_act_subtable_type[subtable], rule);
3767 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3768 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3771 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3772 ZFCP_LOG_FLAGS(0, "FSF_DIRECTION_INDICATOR_NOT_VALID\n");
3773 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3774 "0x%016Lx on port 0x%016Lx on adapter %s "
3775 "(debug info %d)\n",
3778 zfcp_get_busid_by_unit(unit),
3779 fsf_req->qtcb->bottom.io.data_direction);
3780 /* stop operation for this adapter */
3781 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3782 "fsf_s_dir_ind_nv");
3783 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3784 zfcp_cmd_dbf_event_fsf("dirinv",
3786 &header->fsf_status_qual,
3787 sizeof (union fsf_status_qual));
3788 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3791 /* FIXME: this should be obsolete, isn' it? */
3792 case FSF_INBOUND_DATA_LENGTH_NOT_VALID:
3793 ZFCP_LOG_FLAGS(0, "FSF_INBOUND_DATA_LENGTH_NOT_VALID\n");
3794 ZFCP_LOG_NORMAL("bug: An invalid inbound data length field "
3795 "was found in a command for unit 0x%016Lx "
3796 "on port 0x%016Lx on adapter %s.\n",
3798 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3799 /* stop operation for this adapter */
3800 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3802 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3803 zfcp_cmd_dbf_event_fsf("idleninv",
3805 &header->fsf_status_qual,
3806 sizeof (union fsf_status_qual));
3807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3810 /* FIXME: this should be obsolete, isn' it? */
3811 case FSF_OUTBOUND_DATA_LENGTH_NOT_VALID:
3812 ZFCP_LOG_FLAGS(0, "FSF_OUTBOUND_DATA_LENGTH_NOT_VALID\n");
3813 ZFCP_LOG_NORMAL("bug: An invalid outbound data length field "
3814 "was found in a command unit 0x%016Lx on port "
3815 "0x%016Lx on adapter %s\n",
3818 zfcp_get_busid_by_unit(unit));
3819 /* stop operation for this adapter */
3820 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3822 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3823 zfcp_cmd_dbf_event_fsf("odleninv", fsf_req,
3824 &header->fsf_status_qual,
3825 sizeof (union fsf_status_qual));
3826 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3829 case FSF_CMND_LENGTH_NOT_VALID:
3830 ZFCP_LOG_FLAGS(0, "FSF_CMND_LENGTH_NOT_VALID\n");
3832 ("bug: An invalid control-data-block length field "
3833 "was found in a command for unit 0x%016Lx on port "
3834 "0x%016Lx on adapter %s " "(debug info %d)\n",
3835 unit->fcp_lun, unit->port->wwpn,
3836 zfcp_get_busid_by_unit(unit),
3837 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3838 /* stop operation for this adapter */
3839 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3840 "fsf_s_cmd_len_nv");
3841 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3842 zfcp_cmd_dbf_event_fsf("cleninv",
3844 &header->fsf_status_qual,
3845 sizeof (union fsf_status_qual));
3846 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3849 case FSF_PORT_BOXED:
3850 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3851 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3852 "needs to be reopened\n",
3853 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3854 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3855 zfcp_erp_port_reopen(unit->port, 0);
3856 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3857 &header->fsf_status_qual,
3858 sizeof (union fsf_status_qual));
3859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3860 ZFCP_STATUS_FSFREQ_RETRY;
3864 ZFCP_LOG_FLAGS(0, "FSF_LUN_BOXED\n");
3866 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
3868 unit->fcp_lun, unit->port->wwpn,
3869 zfcp_get_busid_by_unit(unit));
3870 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3871 zfcp_erp_unit_reopen(unit, 0);
3872 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3873 &header->fsf_status_qual,
3874 sizeof(union fsf_status_qual));
3875 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3876 | ZFCP_STATUS_FSFREQ_RETRY;
3879 case FSF_ADAPTER_STATUS_AVAILABLE:
3880 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3881 switch (header->fsf_status_qual.word[0]) {
3882 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3884 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3885 /* re-establish link to port */
3886 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3888 zfcp_erp_port_reopen(unit->port, 0);
3889 zfcp_cmd_dbf_event_fsf(
3892 &header->fsf_status_qual,
3893 sizeof (union fsf_status_qual));
3894 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3896 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3898 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3899 /* FIXME(hw) need proper specs for proper action */
3900 /* let scsi stack deal with retries and escalation */
3901 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3903 zfcp_cmd_dbf_event_fsf(
3906 &header->fsf_status_qual,
3907 sizeof (union fsf_status_qual));
3908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3911 /* FIXME: shall we consider this a successful transfer? */
3913 ("bug: Wrong status qualifier 0x%x arrived.\n",
3914 header->fsf_status_qual.word[0]);
3915 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3917 debug_exception(fsf_req->adapter->erp_dbf, 0,
3918 &header->fsf_status_qual.word[0],
3925 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3928 case FSF_FCP_RSP_AVAILABLE:
3929 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
3933 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3934 debug_exception(fsf_req->adapter->erp_dbf, 0,
3935 &header->fsf_status, sizeof(u32));
3940 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3942 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3944 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3950 * function: zfcp_fsf_send_fcp_command_task_handler
3952 * purpose: evaluates FCP_RSP IU
3957 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3960 struct scsi_cmnd *scpnt;
3961 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3962 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3963 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3964 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3966 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3967 unsigned long flags;
3968 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3970 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3971 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
3972 if (unlikely(!scpnt)) {
3974 ("Command with fsf_req %p is not associated to "
3975 "a scsi command anymore. Aborted?\n", fsf_req);
3978 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3979 /* FIXME: (design) mid-layer should handle DID_ABORT like
3980 * DID_SOFT_ERROR by retrying the request for devices
3981 * that allow retries.
3983 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3984 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3985 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3986 goto skip_fsfstatus;
3989 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3990 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3991 set_host_byte(&scpnt->result, DID_ERROR);
3992 goto skip_fsfstatus;
3995 /* set message byte of result in SCSI command */
3996 scpnt->result |= COMMAND_COMPLETE << 8;
3999 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4000 * of result in SCSI command
4002 scpnt->result |= fcp_rsp_iu->scsi_status;
4003 if (unlikely(fcp_rsp_iu->scsi_status)) {
4005 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4006 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4007 scpnt->cmnd, scpnt->cmd_len);
4008 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4009 fcp_rsp_iu->scsi_status);
4010 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4011 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4012 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4013 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4014 fcp_rsp_iu->fcp_sns_len);
4017 /* check FCP_RSP_INFO */
4018 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4019 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4020 switch (fcp_rsp_info[3]) {
4022 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4024 ZFCP_LOG_TRACE("no failure or Task Management "
4025 "Function complete\n");
4026 set_host_byte(&scpnt->result, DID_OK);
4028 case RSP_CODE_LENGTH_MISMATCH:
4029 ZFCP_LOG_FLAGS(0, "RSP_CODE_LENGTH_MISMATCH\n");
4031 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4032 "that the fibrechannel protocol data "
4033 "length differs from the burst length. "
4034 "The problem occured on unit 0x%016Lx "
4035 "on port 0x%016Lx on adapter %s",
4038 zfcp_get_busid_by_unit(unit));
4039 /* dump SCSI CDB as prepared by zfcp */
4040 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4041 (char *) &fsf_req->qtcb->
4042 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4043 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4044 set_host_byte(&scpnt->result, DID_ERROR);
4045 goto skip_fsfstatus;
4046 case RSP_CODE_FIELD_INVALID:
4047 ZFCP_LOG_FLAGS(0, "RSP_CODE_FIELD_INVALID\n");
4048 /* driver or hardware bug */
4049 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4050 "that the fibrechannel protocol data "
4051 "fields were incorrectly set up. "
4052 "The problem occured on the unit "
4053 "0x%016Lx on port 0x%016Lx on "
4057 zfcp_get_busid_by_unit(unit));
4058 /* dump SCSI CDB as prepared by zfcp */
4059 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4060 (char *) &fsf_req->qtcb->
4061 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4062 set_host_byte(&scpnt->result, DID_ERROR);
4063 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4064 goto skip_fsfstatus;
4065 case RSP_CODE_RO_MISMATCH:
4066 ZFCP_LOG_FLAGS(0, "RSP_CODE_RO_MISMATCH\n");
4068 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4069 "that conflicting values for the "
4070 "fibrechannel payload offset from the "
4071 "header were found. "
4072 "The problem occured on unit 0x%016Lx "
4073 "on port 0x%016Lx on adapter %s.\n",
4076 zfcp_get_busid_by_unit(unit));
4077 /* dump SCSI CDB as prepared by zfcp */
4078 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4079 (char *) &fsf_req->qtcb->
4080 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4081 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4082 set_host_byte(&scpnt->result, DID_ERROR);
4083 goto skip_fsfstatus;
4085 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4086 "code was detected for a command. "
4087 "The problem occured on the unit "
4088 "0x%016Lx on port 0x%016Lx on "
4089 "adapter %s (debug info 0x%x)\n",
4092 zfcp_get_busid_by_unit(unit),
4094 /* dump SCSI CDB as prepared by zfcp */
4095 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4096 (char *) &fsf_req->qtcb->
4097 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4098 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4099 set_host_byte(&scpnt->result, DID_ERROR);
4103 /* check for sense data */
4104 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4105 sns_len = FSF_FCP_RSP_SIZE -
4106 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4107 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4109 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4110 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4111 SCSI_SENSE_BUFFERSIZE);
4112 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4113 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4115 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4116 (void *) &scpnt->cmnd, scpnt->cmd_len);
4118 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4119 fcp_rsp_iu->fcp_sns_len);
4120 memcpy(&scpnt->sense_buffer,
4121 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4122 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4123 (void *) &scpnt->sense_buffer, sns_len);
4126 /* check for overrun */
4127 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4128 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4129 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4130 "The response data length is "
4131 "%d, the original length was %d.\n",
4134 zfcp_get_busid_by_unit(unit),
4135 fcp_rsp_iu->fcp_resid,
4136 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4139 /* check for underrun */
4140 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4141 ZFCP_LOG_DEBUG("A data underrun was detected for a command. "
4142 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4143 "The response data length is "
4144 "%d, the original length was %d.\n",
4147 zfcp_get_busid_by_unit(unit),
4148 fcp_rsp_iu->fcp_resid,
4149 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4151 * It may not have been possible to send all data and the
4152 * underrun on send may already be in scpnt->resid, so it's add
4153 * not equals in the below statement.
4155 scpnt->resid += fcp_rsp_iu->fcp_resid;
4156 ZFCP_LOG_TRACE("scpnt->resid=0x%x\n", scpnt->resid);
4162 * This nasty chop at the problem is not working anymore
4163 * as we do not adjust the retry count anylonger in order
4164 * to have a number of retries that avoids I/O errors.
4165 * The manipulation of the retry count has been removed
4166 * in favour of a safe tape device handling. We must not
4167 * sent SCSI commands more than once to a device if no
4168 * retries are permitted by the high level driver. Generally
4169 * speaking, it was a mess to change retry counts. So it is
4170 * fine that this sort of workaround is gone.
4171 * Then, we had to face a certain number of immediate retries in case of
4172 * busy and queue full conditions (see below).
4173 * This is not acceptable
4174 * for the latter. Queue full conditions are used
4175 * by devices to indicate to a host that the host can rely
4176 * on the completion (or timeout) of at least one outstanding
4177 * command as a suggested trigger for command retries.
4178 * Busy conditions require a different trigger since
4179 * no commands are outstanding for that initiator from the
4180 * devices perspective.
4181 * The drawback of mapping a queue full condition to a
4182 * busy condition is the chance of wasting all retries prior
4183 * to the time when the device indicates that a command
4184 * rejected due to a queue full condition should be re-driven.
4185 * This case would lead to unnecessary I/O errors that
4186 * have to be considered fatal if for example ext3's
4187 * journaling would be torpedoed by such an avoidable
4189 * So, what issues are there with not mapping a queue-full
4190 * condition to a busy condition?
4191 * Due to the 'exclusive LUN'
4192 * policy enforced by the zSeries FCP channel, this
4193 * Linux instance is the only initiator with regard to
4194 * this adapter. It is safe to rely on the information
4195 * 'don't disturb me now ... and btw. no other commands
4196 * pending for you' (= queue full) sent by the LU,
4197 * since no other Linux can use this LUN via this adapter
4198 * at the same time. If there is a potential race
4199 * introduced by the FCP channel by not inhibiting Linux A
4200 * to give up a LU with commands pending while Linux B
4201 * grabs this LU and sends commands - thus providing
4202 * an exploit at the 'exclusive LUN' policy - then this
4203 * issue has to be considered a hardware problem. It should
4204 * be tracked as such if it really occurs. Even if the
4205 * FCP Channel spec. begs exploiters to wait for the
4206 * completion of all request sent to a LU prior to
4207 * closing this LU connection.
4208 * This spec. statement in conjunction with
4209 * the 'exclusive LUN' policy is not consistent design.
4210 * Another issue is how resource constraints for SCSI commands
4211 * might be handled by the FCP channel (just guessing for now).
4212 * If the FCP channel would always map resource constraints,
4213 * e.g. no free FC exchange ID due to I/O stress caused by
4214 * other sharing Linux instances, to faked queue-full
4215 * conditions then this would be a misinterpretation and
4216 * violation of SCSI standards.
4217 * If there are SCSI stack races as indicated below
4218 * then they need to be fixed just there.
4219 * Providing all issue above are not applicable or will
4220 * be fixed appropriately, removing the following hack
4221 * is the right thing to do.
4225 * Note: This is a rather nasty chop at the problem. We cannot
4226 * risk adding to the mlqueue however as this will block the
4227 * device. If it is the last outstanding command for this host
4228 * it will remain blocked indefinitely. This would be quite possible
4229 * on the zSeries FCP adapter.
4230 * Also, there exists a race with scsi_insert_special relying on
4231 * scsi_request_fn to recalculate some command data which may not
4232 * happen when q->plugged is true in scsi_request_fn
4234 if (status_byte(scpnt->result) == QUEUE_FULL) {
4235 ZFCP_LOG_DEBUG("Changing QUEUE_FULL to BUSY....\n");
4236 scpnt->result &= ~(QUEUE_FULL << 1);
4237 scpnt->result |= (BUSY << 1);
4241 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4243 zfcp_cmd_dbf_event_scsi("response", scpnt);
4245 /* cleanup pointer (need this especially for abort) */
4246 scpnt->host_scribble = NULL;
4250 * according to the outcome of a discussion on linux-scsi we
4251 * don't need to grab the io_request_lock here since we use
4254 /* always call back */
4256 (scpnt->scsi_done) (scpnt);
4259 * We must hold this lock until scsi_done has been called.
4260 * Otherwise we may call scsi_done after abort regarding this
4261 * command has completed.
4262 * Note: scsi_done must not block!
4265 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4270 * function: zfcp_fsf_send_fcp_command_task_management_handler
4272 * purpose: evaluates FCP_RSP IU
4277 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4280 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4281 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4282 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4283 struct zfcp_unit *unit =
4284 fsf_req->data.send_fcp_command_task_management.unit;
4286 del_timer(&fsf_req->adapter->scsi_er_timer);
4287 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4288 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4289 goto skip_fsfstatus;
4292 /* check FCP_RSP_INFO */
4293 switch (fcp_rsp_info[3]) {
4295 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4297 ZFCP_LOG_DEBUG("no failure or Task Management "
4298 "Function complete\n");
4300 case RSP_CODE_TASKMAN_UNSUPP:
4301 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_UNSUPP\n");
4302 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4303 "is not supported on the target device "
4304 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4307 zfcp_get_busid_by_unit(unit));
4308 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4310 case RSP_CODE_TASKMAN_FAILED:
4311 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_FAILED\n");
4312 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4313 "failed to complete successfully. "
4314 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4317 zfcp_get_busid_by_unit(unit));
4318 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4321 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4322 "code was detected for a command. "
4323 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4324 "(debug info 0x%x)\n",
4327 zfcp_get_busid_by_unit(unit),
4329 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4338 * function: zfcp_fsf_control_file
4340 * purpose: Initiator of the control file upload/download FSF requests
4342 * returns: 0 - FSF request is successfuly created and queued
4343 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4344 * -EINVAL - Invalid direction specified
4345 * -ENOMEM - Insufficient memory
4346 * -EPERM - Cannot create FSF request or or place it in QDIO queue
4349 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4350 struct zfcp_fsf_req **fsf_req_ptr,
4353 struct zfcp_sg_list *sg_list)
4355 struct zfcp_fsf_req *fsf_req;
4356 struct fsf_qtcb_bottom_support *bottom;
4357 volatile struct qdio_buffer_element *sbale;
4358 unsigned long lock_flags;
4363 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4365 "Adapter %s does not support control file\n",
4366 zfcp_get_busid_by_adapter(adapter));
4367 retval = -EOPNOTSUPP;
4368 goto no_cfdc_support;
4371 switch (fsf_command) {
4373 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4374 direction = SBAL_FLAGS0_TYPE_WRITE;
4375 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4376 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4377 req_flags = ZFCP_WAIT_FOR_SBAL;
4380 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4381 direction = SBAL_FLAGS0_TYPE_READ;
4385 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4386 goto invalid_command;
4389 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4390 NULL, &lock_flags, &fsf_req);
4392 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4394 zfcp_get_busid_by_adapter(adapter));
4399 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4400 sbale[0].flags |= direction;
4402 bottom = &fsf_req->qtcb->bottom.support;
4403 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4404 bottom->option = option;
4406 if (sg_list->count > 0) {
4409 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4410 sg_list->sg, sg_list->count,
4411 ZFCP_MAX_SBALS_PER_REQ);
4412 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4414 "error: Could not create sufficient number of "
4415 "SBALS for an FSF request to the adapter %s\n",
4416 zfcp_get_busid_by_adapter(adapter));
4421 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4424 retval = zfcp_fsf_req_send(fsf_req, NULL);
4427 "error: Could not send FSF request to the adapter %s\n",
4428 zfcp_get_busid_by_adapter(adapter));
4434 "Control file %s FSF request has been sent to the adapter %s\n",
4435 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4436 "download" : "upload",
4437 zfcp_get_busid_by_adapter(adapter));
4439 *fsf_req_ptr = fsf_req;
4445 zfcp_fsf_req_free(fsf_req);
4448 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4457 * function: zfcp_fsf_control_file_handler
4459 * purpose: Handler of the control file upload/download FSF requests
4461 * returns: 0 - FSF request successfuly processed
4462 * -EAGAIN - Operation has to be repeated because of a temporary problem
4463 * -EACCES - There is no permission to execute an operation
4464 * -EPERM - The control file is not in a right format
4465 * -EIO - There is a problem with the FCP adapter
4466 * -EINVAL - Invalid operation
4467 * -EFAULT - User space memory I/O operation fault
4470 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4472 struct zfcp_adapter *adapter = fsf_req->adapter;
4473 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4474 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4477 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4479 goto skip_fsfstatus;
4482 switch (header->fsf_status) {
4485 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
4487 "The FSF request has been successfully completed "
4488 "on the adapter %s\n",
4489 zfcp_get_busid_by_adapter(adapter));
4492 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4493 ZFCP_LOG_FLAGS(2, "FSF_OPERATION_PARTIALLY_SUCCESSFUL\n");
4494 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4495 switch (header->fsf_status_qual.word[0]) {
4497 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4499 "CFDC of the adapter %s could not "
4500 "be saved on the SE\n",
4501 zfcp_get_busid_by_adapter(adapter));
4504 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4506 "CFDC of the adapter %s could not "
4507 "be copied to the secondary SE\n",
4508 zfcp_get_busid_by_adapter(adapter));
4513 "CFDC could not be hardened "
4514 "on the adapter %s\n",
4515 zfcp_get_busid_by_adapter(adapter));
4518 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4522 case FSF_AUTHORIZATION_FAILURE:
4523 ZFCP_LOG_FLAGS(2, "FSF_AUTHORIZATION_FAILURE\n");
4525 "Adapter %s does not accept privileged commands\n",
4526 zfcp_get_busid_by_adapter(adapter));
4527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4531 case FSF_CFDC_ERROR_DETECTED:
4532 ZFCP_LOG_FLAGS(2, "FSF_CFDC_ERROR_DETECTED\n");
4534 "Error at position %d in the CFDC, "
4535 "CFDC is discarded by the adapter %s\n",
4536 header->fsf_status_qual.word[0],
4537 zfcp_get_busid_by_adapter(adapter));
4538 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4542 case FSF_CONTROL_FILE_UPDATE_ERROR:
4543 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_UPDATE_ERROR\n");
4545 "Adapter %s cannot harden the control file, "
4546 "file is discarded\n",
4547 zfcp_get_busid_by_adapter(adapter));
4548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4552 case FSF_CONTROL_FILE_TOO_LARGE:
4553 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_TOO_LARGE\n");
4555 "Control file is too large, file is discarded "
4556 "by the adapter %s\n",
4557 zfcp_get_busid_by_adapter(adapter));
4558 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4562 case FSF_ACCESS_CONFLICT_DETECTED:
4563 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_CONFLICT_DETECTED\n");
4564 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4566 "CFDC has been discarded by the adapter %s, "
4567 "because activation would impact "
4568 "%d active connection(s)\n",
4569 zfcp_get_busid_by_adapter(adapter),
4570 header->fsf_status_qual.word[0]);
4571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4575 case FSF_CONFLICTS_OVERRULED:
4576 ZFCP_LOG_FLAGS(2, "FSF_CONFLICTS_OVERRULED\n");
4577 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4579 "CFDC has been activated on the adapter %s, "
4580 "but activation has impacted "
4581 "%d active connection(s)\n",
4582 zfcp_get_busid_by_adapter(adapter),
4583 header->fsf_status_qual.word[0]);
4584 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4588 case FSF_UNKNOWN_COMMAND:
4589 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_COMMAND\n");
4591 "FSF command 0x%x is not supported by the adapter %s\n",
4592 fsf_req->fsf_command,
4593 zfcp_get_busid_by_adapter(adapter));
4594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4598 case FSF_UNKNOWN_OP_SUBTYPE:
4599 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_OP_SUBTYPE\n");
4601 "Invalid operation subtype 0x%x has been specified "
4602 "in QTCB bottom sent to the adapter %s\n",
4603 bottom->operation_subtype,
4604 zfcp_get_busid_by_adapter(adapter));
4605 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4609 case FSF_INVALID_COMMAND_OPTION:
4610 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
4612 "Invalid option 0x%x has been specified "
4613 "in QTCB bottom sent to the adapter %s\n",
4615 zfcp_get_busid_by_adapter(adapter));
4616 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4622 "bug: An unknown/unexpected FSF status 0x%08x "
4623 "was presented on the adapter %s\n",
4625 zfcp_get_busid_by_adapter(adapter));
4626 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4627 debug_exception(fsf_req->adapter->erp_dbf, 0,
4628 &header->fsf_status_qual.word[0], sizeof(u32));
4629 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4640 * function: zfcp_fsf_req_wait_and_cleanup
4644 * FIXME(design): signal seems to be <0 !!!
4645 * returns: 0 - request completed (*status is valid), cleanup succ.
4646 * <0 - request completed (*status is valid), cleanup failed
4647 * >0 - signal which interrupted waiting (*status invalid),
4648 * request not completed, no cleanup
4650 * *status is a copy of status of completed fsf_req
4653 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4654 int interruptible, u32 * status)
4659 if (interruptible) {
4660 __wait_event_interruptible(fsf_req->completion_wq,
4662 ZFCP_STATUS_FSFREQ_COMPLETED,
4665 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4666 "completion of the request at %p\n",
4672 __wait_event(fsf_req->completion_wq,
4673 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4676 *status = fsf_req->status;
4678 /* cleanup request */
4679 zfcp_fsf_req_cleanup(fsf_req);
4685 zfcp_fsf_req_create_sbal_check(unsigned long *flags,
4686 struct zfcp_qdio_queue *queue, int needed)
4688 write_lock_irqsave(&queue->queue_lock, *flags);
4689 if (likely(atomic_read(&queue->free_count) >= needed))
4691 write_unlock_irqrestore(&queue->queue_lock, *flags);
4696 * set qtcb pointer in fsf_req and initialize QTCB
4699 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4701 if (likely(fsf_req->qtcb != NULL)) {
4702 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4703 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4704 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4705 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4706 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4707 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4712 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4713 * @adapter: adapter for which request queue is examined
4714 * @req_flags: flags indicating whether to wait for needed SBAL or not
4715 * @lock_flags: lock_flags is queue_lock is taken
4717 * locking: on success the queue_lock for the request queue of the adapter
4721 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4722 unsigned long *lock_flags)
4725 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4727 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4728 wait_event_interruptible_timeout(adapter->request_wq,
4730 zfcp_fsf_req_create_sbal_check
4731 (lock_flags, req_queue, 1)),
4736 } else if (!zfcp_fsf_req_create_sbal_check(lock_flags, req_queue, 1)) {
4744 * function: zfcp_fsf_req_create
4746 * purpose: create an FSF request at the specified adapter and
4747 * setup common fields
4749 * returns: -ENOMEM if there was insufficient memory for a request
4750 * -EIO if no qdio buffers could be allocate to the request
4751 * -EINVAL/-EPERM on bug conditions in req_dequeue
4754 * note: The created request is returned by reference.
4756 * locks: lock of concerned request queue must not be held,
4757 * but is held on completion (write, irqsave)
4760 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4761 mempool_t *pool, unsigned long *lock_flags,
4762 struct zfcp_fsf_req **fsf_req_p)
4764 volatile struct qdio_buffer_element *sbale;
4765 struct zfcp_fsf_req *fsf_req = NULL;
4767 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4769 /* allocate new FSF request */
4770 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4771 if (unlikely(NULL == fsf_req)) {
4772 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4773 "the outbound (send) queue.\n");
4775 goto failed_fsf_req;
4778 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4780 /* initialize waitqueue which may be used to wait on
4781 this request completion */
4782 init_waitqueue_head(&fsf_req->completion_wq);
4784 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4790 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4791 * if it is not set (see also *_open_qdio and *_close_qdio).
4794 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4795 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4800 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4801 fsf_req->fsf_command = fsf_cmd;
4802 fsf_req->sbal_number = 1;
4803 fsf_req->sbal_first = req_queue->free_index;
4804 fsf_req->sbal_curr = req_queue->free_index;
4805 fsf_req->sbale_curr = 1;
4807 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4808 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4811 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4813 /* setup common SBALE fields */
4814 sbale[0].addr = fsf_req;
4815 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4816 if (likely(fsf_req->qtcb != NULL)) {
4817 sbale[1].addr = (void *) fsf_req->qtcb;
4818 sbale[1].length = sizeof(struct fsf_qtcb);
4821 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4822 fsf_req->sbal_number, fsf_req->sbal_first);
4827 /* dequeue new FSF request previously enqueued */
4828 zfcp_fsf_req_free(fsf_req);
4832 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4834 *fsf_req_p = fsf_req;
4839 * function: zfcp_fsf_req_send
4841 * purpose: start transfer of FSF request via QDIO
4843 * returns: 0 - request transfer succesfully started
4844 * !0 - start of request transfer failed
4847 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4849 struct zfcp_adapter *adapter;
4850 struct zfcp_qdio_queue *req_queue;
4851 volatile struct qdio_buffer_element *sbale;
4852 int new_distance_from_int;
4853 unsigned long flags;
4857 adapter = fsf_req->adapter;
4858 req_queue = &adapter->request_queue,
4861 /* FIXME(debug): remove it later */
4862 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4863 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4864 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4865 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4868 /* set sequence counter in QTCB */
4869 if (likely(fsf_req->qtcb)) {
4870 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4871 fsf_req->seq_no = adapter->fsf_req_seq_no;
4872 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4873 "FSF sequence counter value of %i\n",
4875 zfcp_get_busid_by_adapter(adapter),
4876 fsf_req->qtcb->prefix.req_seq_no);
4880 /* put allocated FSF request at list tail */
4881 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4882 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4883 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4885 /* figure out expiration time of timeout and start timeout */
4886 if (unlikely(timer)) {
4887 timer->expires += jiffies;
4891 ZFCP_LOG_TRACE("request queue of adapter %s: "
4892 "next free SBAL is %i, %i free SBALs\n",
4893 zfcp_get_busid_by_adapter(adapter),
4894 req_queue->free_index,
4895 atomic_read(&req_queue->free_count));
4897 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4898 "index_in_queue=%i, count=%i, buffers=%p\n",
4899 zfcp_get_busid_by_adapter(adapter),
4900 QDIO_FLAG_SYNC_OUTPUT,
4901 0, fsf_req->sbal_first, fsf_req->sbal_number,
4902 &req_queue->buffer[fsf_req->sbal_first]);
4905 * adjust the number of free SBALs in request queue as well as
4906 * position of first one
4908 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4909 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4910 req_queue->free_index += fsf_req->sbal_number; /* increase */
4911 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4912 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4914 retval = do_QDIO(adapter->ccw_device,
4915 QDIO_FLAG_SYNC_OUTPUT,
4916 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4918 if (unlikely(retval)) {
4919 /* Queues are down..... */
4922 * FIXME(potential race):
4923 * timer might be expired (absolutely unlikely)
4926 del_timer_sync(timer);
4927 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4928 list_del(&fsf_req->list);
4929 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4931 * adjust the number of free SBALs in request queue as well as
4932 * position of first one
4934 zfcp_qdio_zero_sbals(req_queue->buffer,
4935 fsf_req->sbal_first, fsf_req->sbal_number);
4936 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4937 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4938 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4939 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4941 ("error: do_QDIO failed. Buffers could not be enqueued "
4942 "to request queue.\n");
4944 req_queue->distance_from_int = new_distance_from_int;
4946 * increase FSF sequence counter -
4947 * this must only be done for request successfully enqueued to
4948 * QDIO this rejected requests may be cleaned up by calling
4949 * routines resulting in missing sequence counter values
4952 /* Don't increase for unsolicited status */
4953 if (likely(inc_seq_no)) {
4954 adapter->fsf_req_seq_no++;
4956 ("FSF sequence counter value of adapter %s "
4957 "increased to %i\n",
4958 zfcp_get_busid_by_adapter(adapter),
4959 adapter->fsf_req_seq_no);
4961 /* count FSF requests pending */
4962 atomic_inc(&adapter->fsf_reqs_active);
4968 * function: zfcp_fsf_req_cleanup
4970 * purpose: cleans up an FSF request and removes it from the specified list
4974 * assumption: no pending SB in SBALEs other than QTCB
4977 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4979 struct zfcp_adapter *adapter = fsf_req->adapter;
4980 unsigned long flags;
4982 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4983 list_del(&fsf_req->list);
4984 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4985 zfcp_fsf_req_free(fsf_req);
4988 #undef ZFCP_LOG_AREA