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>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #define ZFCP_FSF_C_REVISION "$Revision: 1.92 $"
37 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
38 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
45 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
46 static int zfcp_fsf_send_fcp_command_task_management_handler(
47 struct zfcp_fsf_req *);
48 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
51 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
52 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
53 static inline int zfcp_fsf_req_sbal_check(
54 unsigned long *, struct zfcp_qdio_queue *, int);
55 static inline int zfcp_use_one_sbal(
56 struct scatterlist *, int, struct scatterlist *, int);
57 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
58 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
59 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
60 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
61 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
62 static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
63 struct fsf_link_down_info *);
64 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
65 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
67 /* association between FSF command and FSF QTCB type */
68 static u32 fsf_qtcb_type[] = {
69 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
70 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
77 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
78 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
79 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
80 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
81 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
84 static const char zfcp_act_subtable_type[5][8] = {
85 "unknown", "OS", "WWPN", "DID", "LUN"
88 /****************************************************************/
89 /*************** FSF related Functions *************************/
90 /****************************************************************/
92 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
95 * function: zfcp_fsf_req_alloc
97 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
98 * unsolicited requests) via helper functions
99 * Does some initial fsf request set-up.
101 * returns: pointer to allocated fsf_req if successfull
107 static struct zfcp_fsf_req *
108 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
112 struct zfcp_fsf_req *fsf_req = NULL;
114 if (req_flags & ZFCP_REQ_NO_QTCB)
115 size = sizeof(struct zfcp_fsf_req);
117 size = sizeof(struct zfcp_fsf_req_pool_element);
119 if (likely(pool != NULL))
120 ptr = mempool_alloc(pool, GFP_ATOMIC);
122 ptr = kmalloc(size, GFP_ATOMIC);
124 if (unlikely(NULL == ptr))
127 memset(ptr, 0, size);
129 if (req_flags & ZFCP_REQ_NO_QTCB) {
130 fsf_req = (struct zfcp_fsf_req *) ptr;
132 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
134 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
137 fsf_req->pool = pool;
144 * function: zfcp_fsf_req_free
146 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
147 * returns it into the pool via helper functions.
154 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
156 if (likely(fsf_req->pool != NULL))
157 mempool_free(fsf_req, fsf_req->pool);
169 * note: qdio queues shall be down (no ongoing inbound processing)
172 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
174 struct zfcp_fsf_req *fsf_req, *tmp;
176 LIST_HEAD(remove_queue);
178 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
179 list_splice_init(&adapter->fsf_req_list_head, &remove_queue);
180 atomic_set(&adapter->fsf_reqs_active, 0);
181 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
183 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
184 list_del(&fsf_req->list);
185 zfcp_fsf_req_dismiss(fsf_req);
199 zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
201 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
202 zfcp_fsf_req_complete(fsf_req);
206 * function: zfcp_fsf_req_complete
208 * purpose: Updates active counts and timers for openfcp-reqs
209 * May cleanup request after req_eval returns
211 * returns: 0 - success
217 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
222 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
223 ZFCP_LOG_DEBUG("Status read response received\n");
225 * Note: all cleanup handling is done in the callchain of
226 * the function call-chain below.
228 zfcp_fsf_status_read_handler(fsf_req);
231 zfcp_fsf_protstatus_eval(fsf_req);
234 * fsf_req may be deleted due to waking up functions, so
235 * cleanup is saved here and used later
237 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
242 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
244 /* cleanup request if requested by initiator */
245 if (likely(cleanup)) {
246 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
248 * lock must not be held here since it will be
249 * grabed by the called routine, too
251 zfcp_fsf_req_free(fsf_req);
253 /* notify initiator waiting for the requests completion */
254 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
256 * FIXME: Race! We must not access fsf_req here as it might have been
257 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
258 * flag. It's an improbable case. But, we have the same paranoia for
259 * the cleanup flag already.
260 * Might better be handled using complete()?
261 * (setting the flag and doing wakeup ought to be atomic
262 * with regard to checking the flag as long as waitqueue is
263 * part of the to be released structure)
265 wake_up(&fsf_req->completion_wq);
273 * function: zfcp_fsf_protstatus_eval
275 * purpose: evaluates the QTCB of the finished FSF request
276 * and initiates appropriate actions
277 * (usually calling FSF command specific handlers)
286 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
289 struct zfcp_adapter *adapter = fsf_req->adapter;
290 struct fsf_qtcb *qtcb = fsf_req->qtcb;
291 union fsf_prot_status_qual *prot_status_qual =
292 &qtcb->prefix.prot_status_qual;
294 zfcp_hba_dbf_event_fsf_response(fsf_req);
296 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
297 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
298 (unsigned long) fsf_req);
299 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
300 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
301 goto skip_protstatus;
304 /* log additional information provided by FSF (if any) */
305 if (unlikely(qtcb->header.log_length)) {
306 /* do not trust them ;-) */
307 if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
309 ("bug: ULP (FSF logging) log data starts "
310 "beyond end of packet header. Ignored. "
311 "(start=%i, size=%li)\n",
312 qtcb->header.log_start,
313 sizeof(struct fsf_qtcb));
316 if ((size_t) (qtcb->header.log_start + qtcb->header.log_length)
317 > sizeof(struct fsf_qtcb)) {
318 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
319 "beyond end of packet header. Ignored. "
320 "(start=%i, length=%i, size=%li)\n",
321 qtcb->header.log_start,
322 qtcb->header.log_length,
323 sizeof(struct fsf_qtcb));
326 ZFCP_LOG_TRACE("ULP log data: \n");
327 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
328 (char *) qtcb + qtcb->header.log_start,
329 qtcb->header.log_length);
333 /* evaluate FSF Protocol Status */
334 switch (qtcb->prefix.prot_status) {
337 case FSF_PROT_FSF_STATUS_PRESENTED:
340 case FSF_PROT_QTCB_VERSION_ERROR:
341 ZFCP_LOG_NORMAL("error: The adapter %s contains "
342 "microcode of version 0x%x, the device driver "
343 "only supports 0x%x. Aborting.\n",
344 zfcp_get_busid_by_adapter(adapter),
345 prot_status_qual->version_error.fsf_version,
347 zfcp_erp_adapter_shutdown(adapter, 0);
348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
351 case FSF_PROT_SEQ_NUMB_ERROR:
352 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
353 "driver (0x%x) and adapter %s (0x%x). "
354 "Restarting all operations on this adapter.\n",
355 qtcb->prefix.req_seq_no,
356 zfcp_get_busid_by_adapter(adapter),
357 prot_status_qual->sequence_error.exp_req_seq_no);
358 zfcp_erp_adapter_reopen(adapter, 0);
359 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
360 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
363 case FSF_PROT_UNSUPP_QTCB_TYPE:
364 ZFCP_LOG_NORMAL("error: Packet header type used by the "
365 "device driver is incompatible with "
366 "that used on adapter %s. "
367 "Stopping all operations on this adapter.\n",
368 zfcp_get_busid_by_adapter(adapter));
369 zfcp_erp_adapter_shutdown(adapter, 0);
370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
374 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
375 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
379 case FSF_PROT_DUPLICATE_REQUEST_ID:
380 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
381 "to the adapter %s is ambiguous. "
382 "Stopping all operations on this adapter.\n",
383 *(unsigned long long*)
384 (&qtcb->bottom.support.req_handle),
385 zfcp_get_busid_by_adapter(adapter));
386 zfcp_erp_adapter_shutdown(adapter, 0);
387 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
390 case FSF_PROT_LINK_DOWN:
391 zfcp_fsf_link_down_info_eval(adapter,
392 &prot_status_qual->link_down_info);
393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
396 case FSF_PROT_REEST_QUEUE:
397 ZFCP_LOG_NORMAL("The local link to adapter with "
398 "%s was re-plugged. "
399 "Re-starting operations on this adapter.\n",
400 zfcp_get_busid_by_adapter(adapter));
401 /* All ports should be marked as ready to run again */
402 zfcp_erp_modify_adapter_status(adapter,
403 ZFCP_STATUS_COMMON_RUNNING,
405 zfcp_erp_adapter_reopen(adapter,
406 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
407 | ZFCP_STATUS_COMMON_ERP_FAILED);
408 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
411 case FSF_PROT_ERROR_STATE:
412 ZFCP_LOG_NORMAL("error: The adapter %s "
413 "has entered the error state. "
414 "Restarting all operations on this "
416 zfcp_get_busid_by_adapter(adapter));
417 zfcp_erp_adapter_reopen(adapter, 0);
418 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
423 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
424 "provided by the adapter %s "
425 "is not compatible with the device driver. "
426 "Stopping all operations on this adapter. "
427 "(debug info 0x%x).\n",
428 zfcp_get_busid_by_adapter(adapter),
429 qtcb->prefix.prot_status);
430 zfcp_erp_adapter_shutdown(adapter, 0);
431 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
436 * always call specific handlers to give them a chance to do
437 * something meaningful even in error cases
439 zfcp_fsf_fsfstatus_eval(fsf_req);
444 * function: zfcp_fsf_fsfstatus_eval
446 * purpose: evaluates FSF status of completed FSF request
447 * and acts accordingly
452 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
456 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
460 /* evaluate FSF Status */
461 switch (fsf_req->qtcb->header.fsf_status) {
462 case FSF_UNKNOWN_COMMAND:
463 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
464 "not known by the adapter %s "
465 "Stopping all operations on this adapter. "
466 "(debug info 0x%x).\n",
467 zfcp_get_busid_by_adapter(fsf_req->adapter),
468 fsf_req->qtcb->header.fsf_command);
469 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
473 case FSF_FCP_RSP_AVAILABLE:
474 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
478 case FSF_ADAPTER_STATUS_AVAILABLE:
479 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
485 * always call specific handlers to give them a chance to do
486 * something meaningful even in error cases
488 zfcp_fsf_req_dispatch(fsf_req);
494 * function: zfcp_fsf_fsfstatus_qual_eval
496 * purpose: evaluates FSF status-qualifier of completed FSF request
497 * and acts accordingly
502 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
506 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
507 case FSF_SQ_FCP_RSP_AVAILABLE:
509 case FSF_SQ_RETRY_IF_POSSIBLE:
510 /* The SCSI-stack may now issue retries or escalate */
511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
513 case FSF_SQ_COMMAND_ABORTED:
514 /* Carry the aborted state on to upper layer */
515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
518 case FSF_SQ_NO_RECOM:
519 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
520 "problem on the adapter %s "
521 "Stopping all operations on this adapter. ",
522 zfcp_get_busid_by_adapter(fsf_req->adapter));
523 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
526 case FSF_SQ_ULP_PROGRAMMING_ERROR:
527 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
529 zfcp_get_busid_by_adapter(fsf_req->adapter));
530 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
532 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
533 case FSF_SQ_NO_RETRY_POSSIBLE:
534 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
535 /* dealt with in the respective functions */
538 ZFCP_LOG_NORMAL("bug: Additional status info could "
539 "not be interpreted properly.\n");
540 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
541 (char *) &fsf_req->qtcb->header.fsf_status_qual,
542 sizeof (union fsf_status_qual));
543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
551 * zfcp_fsf_link_down_info_eval - evaluate link down information block
554 zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
555 struct fsf_link_down_info *link_down)
557 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
561 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
563 if (link_down == NULL) {
564 zfcp_erp_adapter_reopen(adapter, 0);
568 switch (link_down->error_code) {
569 case FSF_PSQ_LINK_NO_LIGHT:
570 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
571 "(no light detected)\n",
572 zfcp_get_busid_by_adapter(adapter));
574 case FSF_PSQ_LINK_WRAP_PLUG:
575 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
576 "(wrap plug detected)\n",
577 zfcp_get_busid_by_adapter(adapter));
579 case FSF_PSQ_LINK_NO_FCP:
580 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
581 "(adjacent node on link does not support FCP)\n",
582 zfcp_get_busid_by_adapter(adapter));
584 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
585 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
586 "(firmware update in progress)\n",
587 zfcp_get_busid_by_adapter(adapter));
589 case FSF_PSQ_LINK_INVALID_WWPN:
590 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
591 "(duplicate or invalid WWPN detected)\n",
592 zfcp_get_busid_by_adapter(adapter));
594 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
595 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
596 "(no support for NPIV by Fabric)\n",
597 zfcp_get_busid_by_adapter(adapter));
599 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
600 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
601 "(out of resource in FCP daughtercard)\n",
602 zfcp_get_busid_by_adapter(adapter));
604 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
605 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
606 "(out of resource in Fabric)\n",
607 zfcp_get_busid_by_adapter(adapter));
609 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
610 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
611 "(unable to Fabric login)\n",
612 zfcp_get_busid_by_adapter(adapter));
614 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
615 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
616 zfcp_get_busid_by_adapter(adapter));
618 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
619 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
620 zfcp_get_busid_by_adapter(adapter));
622 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
623 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
624 zfcp_get_busid_by_adapter(adapter));
627 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
628 "(warning: unknown reason code %d)\n",
629 zfcp_get_busid_by_adapter(adapter),
630 link_down->error_code);
633 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
634 ZFCP_LOG_DEBUG("Debug information to link down: "
635 "primary_status=0x%02x "
637 "action_code=0x%02x "
638 "reason_code=0x%02x "
639 "explanation_code=0x%02x "
640 "vendor_specific_code=0x%02x\n",
641 link_down->primary_status,
642 link_down->ioerr_code,
643 link_down->action_code,
644 link_down->reason_code,
645 link_down->explanation_code,
646 link_down->vendor_specific_code);
648 switch (link_down->error_code) {
649 case FSF_PSQ_LINK_NO_LIGHT:
650 case FSF_PSQ_LINK_WRAP_PLUG:
651 case FSF_PSQ_LINK_NO_FCP:
652 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
653 zfcp_erp_adapter_reopen(adapter, 0);
656 zfcp_erp_adapter_failed(adapter);
661 * function: zfcp_fsf_req_dispatch
663 * purpose: calls the appropriate command specific handler
668 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
670 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
671 struct zfcp_adapter *adapter = fsf_req->adapter;
675 switch (fsf_req->fsf_command) {
677 case FSF_QTCB_FCP_CMND:
678 zfcp_fsf_send_fcp_command_handler(fsf_req);
681 case FSF_QTCB_ABORT_FCP_CMND:
682 zfcp_fsf_abort_fcp_command_handler(fsf_req);
685 case FSF_QTCB_SEND_GENERIC:
686 zfcp_fsf_send_ct_handler(fsf_req);
689 case FSF_QTCB_OPEN_PORT_WITH_DID:
690 zfcp_fsf_open_port_handler(fsf_req);
693 case FSF_QTCB_OPEN_LUN:
694 zfcp_fsf_open_unit_handler(fsf_req);
697 case FSF_QTCB_CLOSE_LUN:
698 zfcp_fsf_close_unit_handler(fsf_req);
701 case FSF_QTCB_CLOSE_PORT:
702 zfcp_fsf_close_port_handler(fsf_req);
705 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
706 zfcp_fsf_close_physical_port_handler(fsf_req);
709 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
710 zfcp_fsf_exchange_config_data_handler(fsf_req);
713 case FSF_QTCB_EXCHANGE_PORT_DATA:
714 zfcp_fsf_exchange_port_data_handler(fsf_req);
717 case FSF_QTCB_SEND_ELS:
718 zfcp_fsf_send_els_handler(fsf_req);
721 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
722 zfcp_fsf_control_file_handler(fsf_req);
725 case FSF_QTCB_UPLOAD_CONTROL_FILE:
726 zfcp_fsf_control_file_handler(fsf_req);
730 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
731 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
732 "not supported by the adapter %s\n",
733 zfcp_get_busid_by_adapter(adapter));
734 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
736 ("bug: Command issued by the device driver differs "
737 "from the command returned by the adapter %s "
738 "(debug info 0x%x, 0x%x).\n",
739 zfcp_get_busid_by_adapter(adapter),
740 fsf_req->fsf_command,
741 fsf_req->qtcb->header.fsf_command);
747 zfcp_erp_async_handler(erp_action, 0);
753 * function: zfcp_fsf_status_read
755 * purpose: initiates a Status Read command at the specified adapter
760 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
762 struct zfcp_fsf_req *fsf_req;
763 struct fsf_status_read_buffer *status_buffer;
764 unsigned long lock_flags;
765 volatile struct qdio_buffer_element *sbale;
768 /* setup new FSF request */
769 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
770 req_flags | ZFCP_REQ_NO_QTCB,
771 adapter->pool.fsf_req_status_read,
772 &lock_flags, &fsf_req);
774 ZFCP_LOG_INFO("error: Could not create unsolicited status "
775 "buffer for adapter %s.\n",
776 zfcp_get_busid_by_adapter(adapter));
777 goto failed_req_create;
780 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
781 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
782 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
783 fsf_req->sbale_curr = 2;
786 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
787 if (!status_buffer) {
788 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
791 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
792 fsf_req->data = (unsigned long) status_buffer;
794 /* insert pointer to respective buffer */
795 sbale = zfcp_qdio_sbale_curr(fsf_req);
796 sbale->addr = (void *) status_buffer;
797 sbale->length = sizeof(struct fsf_status_read_buffer);
799 /* start QDIO request for this FSF request */
800 retval = zfcp_fsf_req_send(fsf_req, NULL);
802 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
804 goto failed_req_send;
807 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
808 zfcp_get_busid_by_adapter(adapter));
812 mempool_free(status_buffer, adapter->pool.data_status_read);
815 zfcp_fsf_req_free(fsf_req);
817 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
819 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
824 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
826 struct fsf_status_read_buffer *status_buffer;
827 struct zfcp_adapter *adapter;
828 struct zfcp_port *port;
831 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
832 adapter = fsf_req->adapter;
834 read_lock_irqsave(&zfcp_data.config_lock, flags);
835 list_for_each_entry(port, &adapter->port_list_head, list)
836 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
838 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
840 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
841 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
842 "nonexisting port with d_id 0x%08x on "
843 "adapter %s. Ignored.\n",
844 status_buffer->d_id & ZFCP_DID_MASK,
845 zfcp_get_busid_by_adapter(adapter));
849 switch (status_buffer->status_subtype) {
851 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
852 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
853 zfcp_erp_port_reopen(port, 0);
856 case FSF_STATUS_READ_SUB_ERROR_PORT:
857 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
858 zfcp_erp_port_shutdown(port, 0);
862 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
863 debug_exception(adapter->erp_dbf, 0,
864 &status_buffer->status_subtype, sizeof (u32));
865 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
866 "for a reopen indication on port with "
867 "d_id 0x%08x on the adapter %s. "
868 "Ignored. (debug info 0x%x)\n",
870 zfcp_get_busid_by_adapter(adapter),
871 status_buffer->status_subtype);
878 * function: zfcp_fsf_status_read_handler
880 * purpose: is called for finished Open Port command
885 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
888 struct zfcp_adapter *adapter = fsf_req->adapter;
889 struct fsf_status_read_buffer *status_buffer =
890 (struct fsf_status_read_buffer *) fsf_req->data;
892 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
893 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
894 mempool_free(status_buffer, adapter->pool.data_status_read);
895 zfcp_fsf_req_free(fsf_req);
899 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
901 switch (status_buffer->status_type) {
903 case FSF_STATUS_READ_PORT_CLOSED:
904 zfcp_fsf_status_read_port_closed(fsf_req);
907 case FSF_STATUS_READ_INCOMING_ELS:
908 zfcp_fsf_incoming_els(fsf_req);
911 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
912 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
913 zfcp_get_busid_by_adapter(adapter));
916 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
917 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
918 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
919 (char *) status_buffer,
920 sizeof (struct fsf_status_read_buffer));
923 case FSF_STATUS_READ_LINK_DOWN:
924 switch (status_buffer->status_subtype) {
925 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
926 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
927 zfcp_get_busid_by_adapter(adapter));
928 zfcp_fsf_link_down_info_eval(adapter,
929 (struct fsf_link_down_info *)
930 &status_buffer->payload);
932 case FSF_STATUS_READ_SUB_FDISC_FAILED:
933 ZFCP_LOG_INFO("Local link to adapter %s is down "
934 "due to failed FDISC login\n",
935 zfcp_get_busid_by_adapter(adapter));
936 zfcp_fsf_link_down_info_eval(adapter,
937 (struct fsf_link_down_info *)
938 &status_buffer->payload);
940 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
941 ZFCP_LOG_INFO("Local link to adapter %s is down "
942 "due to firmware update on adapter\n",
943 zfcp_get_busid_by_adapter(adapter));
944 zfcp_fsf_link_down_info_eval(adapter, NULL);
947 ZFCP_LOG_INFO("Local link to adapter %s is down "
948 "due to unknown reason\n",
949 zfcp_get_busid_by_adapter(adapter));
950 zfcp_fsf_link_down_info_eval(adapter, NULL);
954 case FSF_STATUS_READ_LINK_UP:
955 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
956 "Restarting operations on this adapter\n",
957 zfcp_get_busid_by_adapter(adapter));
958 /* All ports should be marked as ready to run again */
959 zfcp_erp_modify_adapter_status(adapter,
960 ZFCP_STATUS_COMMON_RUNNING,
962 zfcp_erp_adapter_reopen(adapter,
963 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
964 | ZFCP_STATUS_COMMON_ERP_FAILED);
967 case FSF_STATUS_READ_NOTIFICATION_LOST:
968 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
969 "adapter %s%s%s%s%s%s%s%s%s\n",
970 zfcp_get_busid_by_adapter(adapter),
971 (status_buffer->status_subtype &
972 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
973 ", incoming ELS" : "",
974 (status_buffer->status_subtype &
975 FSF_STATUS_READ_SUB_SENSE_DATA) ?
977 (status_buffer->status_subtype &
978 FSF_STATUS_READ_SUB_LINK_STATUS) ?
979 ", link status change" : "",
980 (status_buffer->status_subtype &
981 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
983 (status_buffer->status_subtype &
984 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
985 ", bit error exception" : "",
986 (status_buffer->status_subtype &
987 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
989 (status_buffer->status_subtype &
990 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
991 ", ACT hardening" : "",
992 (status_buffer->status_subtype &
993 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
994 ", adapter feature change" : "");
996 if (status_buffer->status_subtype &
997 FSF_STATUS_READ_SUB_ACT_UPDATED)
998 zfcp_erp_adapter_access_changed(adapter);
1001 case FSF_STATUS_READ_CFDC_UPDATED:
1002 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1003 zfcp_get_busid_by_adapter(adapter));
1004 zfcp_erp_adapter_access_changed(adapter);
1007 case FSF_STATUS_READ_CFDC_HARDENED:
1008 switch (status_buffer->status_subtype) {
1009 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1010 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1011 zfcp_get_busid_by_adapter(adapter));
1013 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1014 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1015 "to the secondary SE\n",
1016 zfcp_get_busid_by_adapter(adapter));
1019 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1020 zfcp_get_busid_by_adapter(adapter));
1024 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1025 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1026 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1027 "been changed from 0x%08X to 0x%08X\n",
1028 zfcp_get_busid_by_adapter(adapter),
1029 *(u32*) (status_buffer->payload + 4),
1030 *(u32*) (status_buffer->payload));
1031 adapter->adapter_features = *(u32*) status_buffer->payload;
1035 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1036 "type was received (debug info 0x%x)\n",
1037 status_buffer->status_type);
1038 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1040 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1041 (char *) status_buffer,
1042 sizeof (struct fsf_status_read_buffer));
1045 mempool_free(status_buffer, adapter->pool.data_status_read);
1046 zfcp_fsf_req_free(fsf_req);
1048 * recycle buffer and start new request repeat until outbound
1049 * queue is empty or adapter shutdown is requested
1053 * we may wait in the req_create for 5s during shutdown, so
1054 * qdio_cleanup will have to wait at least that long before returning
1055 * with failure to allow us a proper cleanup under all circumstances
1059 * allocation failure possible? (Is this code needed?)
1061 retval = zfcp_fsf_status_read(adapter, 0);
1063 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1064 "request for the adapter %s.\n",
1065 zfcp_get_busid_by_adapter(adapter));
1066 /* temporary fix to avoid status read buffer shortage */
1067 adapter->status_read_failed++;
1068 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1069 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1070 ZFCP_LOG_INFO("restart adapter %s due to status read "
1071 "buffer shortage\n",
1072 zfcp_get_busid_by_adapter(adapter));
1073 zfcp_erp_adapter_reopen(adapter, 0);
1081 * function: zfcp_fsf_abort_fcp_command
1083 * purpose: tells FSF to abort a running SCSI command
1085 * returns: address of initiated FSF request
1086 * NULL - request could not be initiated
1088 * FIXME(design): should be watched by a timeout !!!
1089 * FIXME(design) shouldn't this be modified to return an int
1090 * also...don't know how though
1092 struct zfcp_fsf_req *
1093 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1094 struct zfcp_adapter *adapter,
1095 struct zfcp_unit *unit, int req_flags)
1097 volatile struct qdio_buffer_element *sbale;
1098 unsigned long lock_flags;
1099 struct zfcp_fsf_req *fsf_req = NULL;
1102 /* setup new FSF request */
1103 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1104 req_flags, adapter->pool.fsf_req_abort,
1105 &lock_flags, &fsf_req);
1107 ZFCP_LOG_INFO("error: Failed to create an abort command "
1108 "request for lun 0x%016Lx on port 0x%016Lx "
1112 zfcp_get_busid_by_adapter(adapter));
1116 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1117 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1118 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1120 fsf_req->data = (unsigned long) unit;
1122 /* set handles of unit and its parent port in QTCB */
1123 fsf_req->qtcb->header.lun_handle = unit->handle;
1124 fsf_req->qtcb->header.port_handle = unit->port->handle;
1126 /* set handle of request which should be aborted */
1127 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1129 /* start QDIO request for this FSF request */
1131 zfcp_fsf_start_scsi_er_timer(adapter);
1132 retval = zfcp_fsf_req_send(fsf_req, NULL);
1134 del_timer(&adapter->scsi_er_timer);
1135 ZFCP_LOG_INFO("error: Failed to send abort command request "
1136 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1137 zfcp_get_busid_by_adapter(adapter),
1138 unit->port->wwpn, unit->fcp_lun);
1139 zfcp_fsf_req_free(fsf_req);
1144 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1145 "(adapter%s, port d_id=0x%08x, "
1146 "unit x%016Lx, old_req_id=0x%lx)\n",
1147 zfcp_get_busid_by_adapter(adapter),
1149 unit->fcp_lun, old_req_id);
1151 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1156 * function: zfcp_fsf_abort_fcp_command_handler
1158 * purpose: is called for finished Abort FCP Command request
1163 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1165 int retval = -EINVAL;
1166 struct zfcp_unit *unit;
1167 unsigned char status_qual =
1168 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1170 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1172 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1173 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1174 goto skip_fsfstatus;
1177 unit = (struct zfcp_unit *) new_fsf_req->data;
1179 /* evaluate FSF status in QTCB */
1180 switch (new_fsf_req->qtcb->header.fsf_status) {
1182 case FSF_PORT_HANDLE_NOT_VALID:
1183 if (status_qual >> 4 != status_qual % 0xf) {
1184 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1187 * In this case a command that was sent prior to a port
1188 * reopen was aborted (handles are different). This is
1192 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1193 "port 0x%016Lx on adapter %s invalid. "
1194 "This may happen occasionally.\n",
1197 zfcp_get_busid_by_unit(unit));
1198 ZFCP_LOG_INFO("status qualifier:\n");
1199 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1200 (char *) &new_fsf_req->qtcb->header.
1202 sizeof (union fsf_status_qual));
1203 /* Let's hope this sorts out the mess */
1204 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1206 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1207 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1211 case FSF_LUN_HANDLE_NOT_VALID:
1212 if (status_qual >> 4 != status_qual % 0xf) {
1214 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1217 * In this case a command that was sent prior to a unit
1218 * reopen was aborted (handles are different).
1223 ("Warning: Temporary LUN identifier 0x%x of LUN "
1224 "0x%016Lx on port 0x%016Lx on adapter %s is "
1225 "invalid. This may happen in rare cases. "
1226 "Trying to re-establish link.\n",
1230 zfcp_get_busid_by_unit(unit));
1231 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1232 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1233 (char *) &new_fsf_req->qtcb->header.
1235 sizeof (union fsf_status_qual));
1236 /* Let's hope this sorts out the mess */
1237 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1239 zfcp_erp_port_reopen(unit->port, 0);
1240 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1244 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1246 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1248 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1251 case FSF_PORT_BOXED:
1252 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1253 "be reopened\n", unit->port->wwpn,
1254 zfcp_get_busid_by_unit(unit));
1255 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1257 zfcp_erp_port_boxed(unit->port);
1258 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1259 | ZFCP_STATUS_FSFREQ_RETRY;
1264 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1266 unit->fcp_lun, unit->port->wwpn,
1267 zfcp_get_busid_by_unit(unit));
1268 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1269 zfcp_erp_unit_boxed(unit);
1270 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1271 | ZFCP_STATUS_FSFREQ_RETRY;
1274 case FSF_ADAPTER_STATUS_AVAILABLE:
1275 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1276 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1277 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1279 zfcp_test_link(unit->port);
1280 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1282 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1283 /* SCSI stack will escalate */
1284 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1286 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1290 ("bug: Wrong status qualifier 0x%x arrived.\n",
1291 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1292 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1294 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1295 &new_fsf_req->qtcb->header.
1296 fsf_status_qual.word[0], sizeof (u32));
1303 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1307 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1308 "(debug info 0x%x)\n",
1309 new_fsf_req->qtcb->header.fsf_status);
1310 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1312 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1313 &new_fsf_req->qtcb->header.fsf_status,
1322 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1324 * Two scatter-gather lists are passed, one for the reqeust and one for the
1328 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1329 struct scatterlist *resp, int resp_count)
1331 return ((req_count == 1) &&
1332 (resp_count == 1) &&
1333 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1335 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1336 req[0].length - 1) & PAGE_MASK)) &&
1337 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1339 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1340 resp[0].length - 1) & PAGE_MASK)));
1344 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1345 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1347 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1348 * a struct zfcp_fsf_req
1349 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1350 * is sent within error recovery
1353 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1354 struct zfcp_erp_action *erp_action)
1356 volatile struct qdio_buffer_element *sbale;
1357 struct zfcp_port *port;
1358 struct zfcp_adapter *adapter;
1359 struct zfcp_fsf_req *fsf_req;
1360 unsigned long lock_flags;
1365 adapter = port->adapter;
1367 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1368 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1369 pool, &lock_flags, &fsf_req);
1371 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1373 zfcp_get_busid_by_adapter(adapter));
1377 if (erp_action != NULL) {
1378 erp_action->fsf_req = fsf_req;
1379 fsf_req->erp_action = erp_action;
1382 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1383 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1384 ct->resp, ct->resp_count)){
1385 /* both request buffer and response buffer
1386 fit into one sbale each */
1387 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1388 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1389 sbale[2].length = ct->req[0].length;
1390 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1391 sbale[3].length = ct->resp[0].length;
1392 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1393 } else if (adapter->adapter_features &
1394 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1395 /* try to use chained SBALs */
1396 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1397 SBAL_FLAGS0_TYPE_WRITE_READ,
1398 ct->req, ct->req_count,
1399 ZFCP_MAX_SBALS_PER_CT_REQ);
1401 ZFCP_LOG_INFO("error: creation of CT request failed "
1403 zfcp_get_busid_by_adapter(adapter));
1411 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1412 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1413 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1414 SBAL_FLAGS0_TYPE_WRITE_READ,
1415 ct->resp, ct->resp_count,
1416 ZFCP_MAX_SBALS_PER_CT_REQ);
1418 ZFCP_LOG_INFO("error: creation of CT request failed "
1420 zfcp_get_busid_by_adapter(adapter));
1428 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1430 /* reject send generic request */
1432 "error: microcode does not support chained SBALs,"
1433 "CT request too big (adapter %s)\n",
1434 zfcp_get_busid_by_adapter(adapter));
1439 /* settings in QTCB */
1440 fsf_req->qtcb->header.port_handle = port->handle;
1441 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1442 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1443 fsf_req->data = (unsigned long) ct;
1445 zfcp_san_dbf_event_ct_request(fsf_req);
1447 /* start QDIO request for this FSF request */
1448 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1450 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1451 "(adapter %s, port 0x%016Lx)\n",
1452 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1456 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1457 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1461 zfcp_fsf_req_free(fsf_req);
1462 if (erp_action != NULL) {
1463 erp_action->fsf_req = NULL;
1467 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1473 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1474 * @fsf_req: pointer to struct zfcp_fsf_req
1476 * Data specific for the Generic Service request is passed using
1477 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1478 * Usually a specific handler for the CT request is called which is
1479 * found in this structure.
1482 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1484 struct zfcp_port *port;
1485 struct zfcp_adapter *adapter;
1486 struct zfcp_send_ct *send_ct;
1487 struct fsf_qtcb_header *header;
1488 struct fsf_qtcb_bottom_support *bottom;
1489 int retval = -EINVAL;
1490 u16 subtable, rule, counter;
1492 adapter = fsf_req->adapter;
1493 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1494 port = send_ct->port;
1495 header = &fsf_req->qtcb->header;
1496 bottom = &fsf_req->qtcb->bottom.support;
1498 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1499 goto skip_fsfstatus;
1501 /* evaluate FSF status in QTCB */
1502 switch (header->fsf_status) {
1505 zfcp_san_dbf_event_ct_response(fsf_req);
1509 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1510 if (adapter->fc_service_class <= 3) {
1511 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1513 zfcp_get_busid_by_port(port),
1514 adapter->fc_service_class);
1516 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1517 "adapter %s is invalid. "
1518 "(debug info %d)\n",
1519 zfcp_get_busid_by_port(port),
1520 adapter->fc_service_class);
1522 /* stop operation for this adapter */
1523 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1524 zfcp_erp_adapter_shutdown(adapter, 0);
1525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1528 case FSF_ADAPTER_STATUS_AVAILABLE:
1529 switch (header->fsf_status_qual.word[0]){
1530 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1531 /* reopening link to port */
1532 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1533 zfcp_test_link(port);
1534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1536 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1537 /* ERP strategy will escalate */
1538 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1539 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1542 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1544 header->fsf_status_qual.word[0]);
1549 case FSF_ACCESS_DENIED:
1550 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1551 "command (adapter %s, port d_id=0x%08x)\n",
1552 zfcp_get_busid_by_port(port), port->d_id);
1553 for (counter = 0; counter < 2; counter++) {
1554 subtable = header->fsf_status_qual.halfword[counter * 2];
1555 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1557 case FSF_SQ_CFDC_SUBTABLE_OS:
1558 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1559 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1560 case FSF_SQ_CFDC_SUBTABLE_LUN:
1561 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1562 zfcp_act_subtable_type[subtable], rule);
1566 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1567 zfcp_erp_port_access_denied(port);
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1571 case FSF_GENERIC_COMMAND_REJECTED:
1572 ZFCP_LOG_INFO("generic service command rejected "
1573 "(adapter %s, port d_id=0x%08x)\n",
1574 zfcp_get_busid_by_port(port), port->d_id);
1575 ZFCP_LOG_INFO("status qualifier:\n");
1576 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1577 (char *) &header->fsf_status_qual,
1578 sizeof (union fsf_status_qual));
1579 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1580 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1583 case FSF_PORT_HANDLE_NOT_VALID:
1584 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1585 "0x%016Lx on adapter %s invalid. This may "
1586 "happen occasionally.\n", port->handle,
1587 port->wwpn, zfcp_get_busid_by_port(port));
1588 ZFCP_LOG_INFO("status qualifier:\n");
1589 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1590 (char *) &header->fsf_status_qual,
1591 sizeof (union fsf_status_qual));
1592 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1593 zfcp_erp_adapter_reopen(adapter, 0);
1594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1597 case FSF_PORT_BOXED:
1598 ZFCP_LOG_INFO("port needs to be reopened "
1599 "(adapter %s, port d_id=0x%08x)\n",
1600 zfcp_get_busid_by_port(port), port->d_id);
1601 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1602 zfcp_erp_port_boxed(port);
1603 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1604 | ZFCP_STATUS_FSFREQ_RETRY;
1607 /* following states should never occure, all cases avoided
1608 in zfcp_fsf_send_ct - but who knows ... */
1609 case FSF_PAYLOAD_SIZE_MISMATCH:
1610 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1611 "req_buf_length=%d, resp_buf_length=%d)\n",
1612 zfcp_get_busid_by_adapter(adapter),
1613 bottom->req_buf_length, bottom->resp_buf_length);
1614 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1616 case FSF_REQUEST_SIZE_TOO_LARGE:
1617 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1618 "req_buf_length=%d)\n",
1619 zfcp_get_busid_by_adapter(adapter),
1620 bottom->req_buf_length);
1621 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1623 case FSF_RESPONSE_SIZE_TOO_LARGE:
1624 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1625 "resp_buf_length=%d)\n",
1626 zfcp_get_busid_by_adapter(adapter),
1627 bottom->resp_buf_length);
1628 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1630 case FSF_SBAL_MISMATCH:
1631 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1632 "resp_buf_length=%d)\n",
1633 zfcp_get_busid_by_adapter(adapter),
1634 bottom->req_buf_length, bottom->resp_buf_length);
1635 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1639 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1640 "(debug info 0x%x)\n", header->fsf_status);
1641 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1642 debug_exception(adapter->erp_dbf, 0,
1643 &header->fsf_status_qual.word[0], sizeof (u32));
1648 send_ct->status = retval;
1650 if (send_ct->handler != NULL)
1651 send_ct->handler(send_ct->handler_data);
1657 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1658 * @els: pointer to struct zfcp_send_els which contains all needed data for
1662 zfcp_fsf_send_els(struct zfcp_send_els *els)
1664 volatile struct qdio_buffer_element *sbale;
1665 struct zfcp_fsf_req *fsf_req;
1667 struct zfcp_adapter *adapter;
1668 unsigned long lock_flags;
1673 adapter = els->adapter;
1675 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1676 ZFCP_REQ_AUTO_CLEANUP,
1677 NULL, &lock_flags, &fsf_req);
1679 ZFCP_LOG_INFO("error: creation of ELS request failed "
1680 "(adapter %s, port d_id: 0x%08x)\n",
1681 zfcp_get_busid_by_adapter(adapter), d_id);
1685 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1686 if (zfcp_use_one_sbal(els->req, els->req_count,
1687 els->resp, els->resp_count)){
1688 /* both request buffer and response buffer
1689 fit into one sbale each */
1690 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1691 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1692 sbale[2].length = els->req[0].length;
1693 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1694 sbale[3].length = els->resp[0].length;
1695 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1696 } else if (adapter->adapter_features &
1697 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1698 /* try to use chained SBALs */
1699 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1700 SBAL_FLAGS0_TYPE_WRITE_READ,
1701 els->req, els->req_count,
1702 ZFCP_MAX_SBALS_PER_ELS_REQ);
1704 ZFCP_LOG_INFO("error: creation of ELS request failed "
1705 "(adapter %s, port d_id: 0x%08x)\n",
1706 zfcp_get_busid_by_adapter(adapter), d_id);
1714 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1715 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1716 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1717 SBAL_FLAGS0_TYPE_WRITE_READ,
1718 els->resp, els->resp_count,
1719 ZFCP_MAX_SBALS_PER_ELS_REQ);
1721 ZFCP_LOG_INFO("error: creation of ELS request failed "
1722 "(adapter %s, port d_id: 0x%08x)\n",
1723 zfcp_get_busid_by_adapter(adapter), d_id);
1731 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1733 /* reject request */
1734 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1735 ", ELS request too big (adapter %s, "
1736 "port d_id: 0x%08x)\n",
1737 zfcp_get_busid_by_adapter(adapter), d_id);
1742 /* settings in QTCB */
1743 fsf_req->qtcb->bottom.support.d_id = d_id;
1744 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1745 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1746 fsf_req->data = (unsigned long) els;
1748 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1750 zfcp_san_dbf_event_els_request(fsf_req);
1752 /* start QDIO request for this FSF request */
1753 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1755 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1756 "(adapter %s, port d_id: 0x%08x)\n",
1757 zfcp_get_busid_by_adapter(adapter), d_id);
1761 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1762 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1766 zfcp_fsf_req_free(fsf_req);
1770 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1777 * zfcp_fsf_send_els_handler - handler for ELS commands
1778 * @fsf_req: pointer to struct zfcp_fsf_req
1780 * Data specific for the ELS command is passed using
1781 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1782 * Usually a specific handler for the ELS command is called which is
1783 * found in this structure.
1785 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1787 struct zfcp_adapter *adapter;
1788 struct zfcp_port *port;
1790 struct fsf_qtcb_header *header;
1791 struct fsf_qtcb_bottom_support *bottom;
1792 struct zfcp_send_els *send_els;
1793 int retval = -EINVAL;
1794 u16 subtable, rule, counter;
1796 send_els = (struct zfcp_send_els *) fsf_req->data;
1797 adapter = send_els->adapter;
1798 port = send_els->port;
1799 d_id = send_els->d_id;
1800 header = &fsf_req->qtcb->header;
1801 bottom = &fsf_req->qtcb->bottom.support;
1803 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1804 goto skip_fsfstatus;
1806 switch (header->fsf_status) {
1809 zfcp_san_dbf_event_els_response(fsf_req);
1813 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1814 if (adapter->fc_service_class <= 3) {
1815 ZFCP_LOG_INFO("error: adapter %s does "
1816 "not support fibrechannel class %d.\n",
1817 zfcp_get_busid_by_adapter(adapter),
1818 adapter->fc_service_class);
1820 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1821 "adapter %s is invalid. "
1822 "(debug info %d)\n",
1823 zfcp_get_busid_by_adapter(adapter),
1824 adapter->fc_service_class);
1826 /* stop operation for this adapter */
1827 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1828 zfcp_erp_adapter_shutdown(adapter, 0);
1829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1832 case FSF_ADAPTER_STATUS_AVAILABLE:
1833 switch (header->fsf_status_qual.word[0]){
1834 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1835 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1836 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1837 zfcp_test_link(port);
1838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1840 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1841 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1844 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1845 (struct zfcp_ls_rjt_par *)
1846 &header->fsf_status_qual.word[2]);
1848 case FSF_SQ_RETRY_IF_POSSIBLE:
1849 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1850 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1853 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1854 header->fsf_status_qual.word[0]);
1855 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1856 (char*)header->fsf_status_qual.word, 16);
1860 case FSF_ELS_COMMAND_REJECTED:
1861 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1862 "prohibited sending "
1863 "(adapter: %s, port d_id: 0x%08x)\n",
1864 zfcp_get_busid_by_adapter(adapter), d_id);
1868 case FSF_PAYLOAD_SIZE_MISMATCH:
1870 "ELS request size and ELS response size must be either "
1871 "both 0, or both greater than 0 "
1872 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1873 zfcp_get_busid_by_adapter(adapter),
1874 bottom->req_buf_length,
1875 bottom->resp_buf_length);
1878 case FSF_REQUEST_SIZE_TOO_LARGE:
1880 "Length of the ELS request buffer, "
1881 "specified in QTCB bottom, "
1882 "exceeds the size of the buffers "
1883 "that have been allocated for ELS request data "
1884 "(adapter: %s, req_buf_length=%d)\n",
1885 zfcp_get_busid_by_adapter(adapter),
1886 bottom->req_buf_length);
1889 case FSF_RESPONSE_SIZE_TOO_LARGE:
1891 "Length of the ELS response buffer, "
1892 "specified in QTCB bottom, "
1893 "exceeds the size of the buffers "
1894 "that have been allocated for ELS response data "
1895 "(adapter: %s, resp_buf_length=%d)\n",
1896 zfcp_get_busid_by_adapter(adapter),
1897 bottom->resp_buf_length);
1900 case FSF_SBAL_MISMATCH:
1901 /* should never occure, avoided in zfcp_fsf_send_els */
1902 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1903 "resp_buf_length=%d)\n",
1904 zfcp_get_busid_by_adapter(adapter),
1905 bottom->req_buf_length, bottom->resp_buf_length);
1906 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1909 case FSF_ACCESS_DENIED:
1910 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1911 "(adapter %s, port d_id=0x%08x)\n",
1912 zfcp_get_busid_by_adapter(adapter), d_id);
1913 for (counter = 0; counter < 2; counter++) {
1914 subtable = header->fsf_status_qual.halfword[counter * 2];
1915 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1917 case FSF_SQ_CFDC_SUBTABLE_OS:
1918 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1919 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1920 case FSF_SQ_CFDC_SUBTABLE_LUN:
1921 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1922 zfcp_act_subtable_type[subtable], rule);
1926 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1928 zfcp_erp_port_access_denied(port);
1929 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1934 "bug: An unknown FSF Status was presented "
1935 "(adapter: %s, fsf_status=0x%08x)\n",
1936 zfcp_get_busid_by_adapter(adapter),
1937 header->fsf_status);
1938 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1939 debug_exception(adapter->erp_dbf, 0,
1940 &header->fsf_status_qual.word[0], sizeof(u32));
1941 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1946 send_els->status = retval;
1948 if (send_els->handler != 0)
1949 send_els->handler(send_els->handler_data);
1959 * returns: address of initiated FSF request
1960 * NULL - request could not be initiated
1963 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1965 volatile struct qdio_buffer_element *sbale;
1966 unsigned long lock_flags;
1969 /* setup new FSF request */
1970 retval = zfcp_fsf_req_create(erp_action->adapter,
1971 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1972 ZFCP_REQ_AUTO_CLEANUP,
1973 erp_action->adapter->pool.fsf_req_erp,
1974 &lock_flags, &(erp_action->fsf_req));
1976 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1977 "data request for adapter %s.\n",
1978 zfcp_get_busid_by_adapter(erp_action->adapter));
1982 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1983 erp_action->fsf_req->sbal_curr, 0);
1984 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1985 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1987 erp_action->fsf_req->erp_action = erp_action;
1988 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1990 FSF_FEATURE_LUN_SHARING |
1991 FSF_FEATURE_NOTIFICATION_LOST |
1992 FSF_FEATURE_UPDATE_ALERT;
1994 /* start QDIO request for this FSF request */
1995 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1998 ("error: Could not send exchange configuration data "
1999 "command on the adapter %s\n",
2000 zfcp_get_busid_by_adapter(erp_action->adapter));
2001 zfcp_fsf_req_free(erp_action->fsf_req);
2002 erp_action->fsf_req = NULL;
2006 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2008 zfcp_get_busid_by_adapter(erp_action->adapter));
2011 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2017 * zfcp_fsf_exchange_config_evaluate
2018 * @fsf_req: fsf_req which belongs to xchg config data request
2019 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2021 * returns: -EIO on error, 0 otherwise
2024 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2026 struct fsf_qtcb_bottom_config *bottom;
2027 struct zfcp_adapter *adapter = fsf_req->adapter;
2028 struct Scsi_Host *shost = adapter->scsi_host;
2030 bottom = &fsf_req->qtcb->bottom.config;
2031 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2032 bottom->low_qtcb_version, bottom->high_qtcb_version);
2033 adapter->fsf_lic_version = bottom->lic_version;
2034 adapter->adapter_features = bottom->adapter_features;
2035 adapter->connection_features = bottom->connection_features;
2036 adapter->peer_wwpn = 0;
2037 adapter->peer_wwnn = 0;
2038 adapter->peer_d_id = 0;
2041 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2042 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2043 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2044 fc_host_speed(shost) = bottom->fc_link_speed;
2045 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2046 adapter->hydra_version = bottom->adapter_type;
2047 if (fc_host_permanent_port_name(shost) == -1)
2048 fc_host_permanent_port_name(shost) =
2049 fc_host_port_name(shost);
2050 if (bottom->fc_topology == FSF_TOPO_P2P) {
2051 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2052 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2053 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2054 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2055 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2056 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2057 else if (bottom->fc_topology == FSF_TOPO_AL)
2058 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2060 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2062 fc_host_node_name(shost) = 0;
2063 fc_host_port_name(shost) = 0;
2064 fc_host_port_id(shost) = 0;
2065 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2066 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2067 adapter->hydra_version = 0;
2070 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2071 adapter->hardware_version = bottom->hardware_version;
2072 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2073 min(FC_SERIAL_NUMBER_SIZE, 17));
2074 EBCASC(fc_host_serial_number(shost),
2075 min(FC_SERIAL_NUMBER_SIZE, 17));
2078 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2082 "adapter version 0x%x, "
2083 "LIC version 0x%x, "
2084 "FC link speed %d Gb/s\n",
2085 zfcp_get_busid_by_adapter(adapter),
2086 (wwn_t) fc_host_node_name(shost),
2087 (wwn_t) fc_host_port_name(shost),
2088 fc_host_port_id(shost),
2089 adapter->hydra_version,
2090 adapter->fsf_lic_version,
2091 fc_host_speed(shost));
2092 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2093 ZFCP_LOG_NORMAL("error: the adapter %s "
2094 "only supports newer control block "
2095 "versions in comparison to this device "
2096 "driver (try updated device driver)\n",
2097 zfcp_get_busid_by_adapter(adapter));
2098 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2099 zfcp_erp_adapter_shutdown(adapter, 0);
2102 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2103 ZFCP_LOG_NORMAL("error: the adapter %s "
2104 "only supports older control block "
2105 "versions than this device driver uses"
2106 "(consider a microcode upgrade)\n",
2107 zfcp_get_busid_by_adapter(adapter));
2108 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2109 zfcp_erp_adapter_shutdown(adapter, 0);
2116 * function: zfcp_fsf_exchange_config_data_handler
2118 * purpose: is called for finished Exchange Configuration Data command
2123 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2125 struct fsf_qtcb_bottom_config *bottom;
2126 struct zfcp_adapter *adapter = fsf_req->adapter;
2127 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2129 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2132 switch (qtcb->header.fsf_status) {
2135 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2138 switch (fc_host_port_type(adapter->scsi_host)) {
2139 case FC_PORTTYPE_PTP:
2140 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2141 "configuration detected at adapter %s\n"
2142 "Peer WWNN 0x%016llx, "
2143 "peer WWPN 0x%016llx, "
2144 "peer d_id 0x%06x\n",
2145 zfcp_get_busid_by_adapter(adapter),
2148 adapter->peer_d_id);
2149 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2152 case FC_PORTTYPE_NLPORT:
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 FC_PORTTYPE_NPORT:
2162 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2163 "network detected at adapter %s.\n",
2164 zfcp_get_busid_by_adapter(adapter));
2167 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2168 "reported by the exchange "
2169 "configuration command for "
2170 "the adapter %s is not "
2171 "of a type known to the zfcp "
2172 "driver, shutting down adapter\n",
2173 zfcp_get_busid_by_adapter(adapter));
2174 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2176 zfcp_erp_adapter_shutdown(adapter, 0);
2179 bottom = &qtcb->bottom.config;
2180 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2181 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2182 "allowed by the adapter %s "
2183 "is lower than the minimum "
2184 "required by the driver (%ld bytes).\n",
2185 bottom->max_qtcb_size,
2186 zfcp_get_busid_by_adapter(adapter),
2187 sizeof(struct fsf_qtcb));
2188 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2190 debug_event(fsf_req->adapter->erp_dbf, 0,
2191 &bottom->max_qtcb_size, sizeof (u32));
2192 zfcp_erp_adapter_shutdown(adapter, 0);
2195 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2198 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2199 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2201 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2204 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2206 zfcp_fsf_link_down_info_eval(adapter,
2207 &qtcb->header.fsf_status_qual.link_down_info);
2210 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2211 debug_event(fsf_req->adapter->erp_dbf, 0,
2212 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2213 zfcp_erp_adapter_shutdown(adapter, 0);
2220 * zfcp_fsf_exchange_port_data - request information about local port
2221 * @erp_action: ERP action for the adapter for which port data is requested
2222 * @adapter: for which port data is requested
2223 * @data: response to exchange port data request
2226 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2227 struct zfcp_adapter *adapter,
2228 struct fsf_qtcb_bottom_port *data)
2230 volatile struct qdio_buffer_element *sbale;
2232 unsigned long lock_flags;
2233 struct zfcp_fsf_req *fsf_req;
2234 struct timer_list *timer;
2236 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2237 ZFCP_LOG_INFO("error: exchange port data "
2238 "command not supported by adapter %s\n",
2239 zfcp_get_busid_by_adapter(adapter));
2243 /* setup new FSF request */
2244 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2245 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2246 0, &lock_flags, &fsf_req);
2248 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2249 "exchange port data request for"
2250 "the adapter %s.\n",
2251 zfcp_get_busid_by_adapter(adapter));
2252 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2258 fsf_req->data = (unsigned long) data;
2260 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2261 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2262 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2265 erp_action->fsf_req = fsf_req;
2266 fsf_req->erp_action = erp_action;
2267 timer = &erp_action->timer;
2269 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2271 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2273 zfcp_fsf_req_free(fsf_req);
2277 timer->function = zfcp_fsf_request_timeout_handler;
2278 timer->data = (unsigned long) adapter;
2279 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2282 retval = zfcp_fsf_req_send(fsf_req, timer);
2284 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2285 "command on the adapter %s\n",
2286 zfcp_get_busid_by_adapter(adapter));
2287 zfcp_fsf_req_free(fsf_req);
2289 erp_action->fsf_req = NULL;
2292 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2297 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2300 wait_event(fsf_req->completion_wq,
2301 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2302 del_timer_sync(timer);
2303 zfcp_fsf_req_free(fsf_req);
2311 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2312 * @fsf_req: pointer to struct zfcp_fsf_req
2315 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2317 struct zfcp_adapter *adapter = fsf_req->adapter;
2318 struct Scsi_Host *shost = adapter->scsi_host;
2319 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2320 struct fsf_qtcb_bottom_port *bottom, *data;
2322 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2325 switch (qtcb->header.fsf_status) {
2327 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2329 bottom = &qtcb->bottom.port;
2330 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2332 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2333 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2334 fc_host_permanent_port_name(shost) = bottom->wwpn;
2336 fc_host_permanent_port_name(shost) =
2337 fc_host_port_name(shost);
2338 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2339 fc_host_supported_speeds(shost) = bottom->supported_speed;
2342 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2343 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2345 zfcp_fsf_link_down_info_eval(adapter,
2346 &qtcb->header.fsf_status_qual.link_down_info);
2350 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2351 debug_event(adapter->erp_dbf, 0,
2352 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2358 * function: zfcp_fsf_open_port
2362 * returns: address of initiated FSF request
2363 * NULL - request could not be initiated
2366 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2368 volatile struct qdio_buffer_element *sbale;
2369 unsigned long lock_flags;
2372 /* setup new FSF request */
2373 retval = zfcp_fsf_req_create(erp_action->adapter,
2374 FSF_QTCB_OPEN_PORT_WITH_DID,
2375 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2376 erp_action->adapter->pool.fsf_req_erp,
2377 &lock_flags, &(erp_action->fsf_req));
2379 ZFCP_LOG_INFO("error: Could not create open port request "
2380 "for port 0x%016Lx on adapter %s.\n",
2381 erp_action->port->wwpn,
2382 zfcp_get_busid_by_adapter(erp_action->adapter));
2386 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2387 erp_action->fsf_req->sbal_curr, 0);
2388 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2389 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2391 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2392 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2393 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2394 erp_action->fsf_req->erp_action = erp_action;
2396 /* start QDIO request for this FSF request */
2397 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2399 ZFCP_LOG_INFO("error: Could not send open port request for "
2400 "port 0x%016Lx on adapter %s.\n",
2401 erp_action->port->wwpn,
2402 zfcp_get_busid_by_adapter(erp_action->adapter));
2403 zfcp_fsf_req_free(erp_action->fsf_req);
2404 erp_action->fsf_req = NULL;
2408 ZFCP_LOG_DEBUG("open port request initiated "
2409 "(adapter %s, port 0x%016Lx)\n",
2410 zfcp_get_busid_by_adapter(erp_action->adapter),
2411 erp_action->port->wwpn);
2413 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2419 * function: zfcp_fsf_open_port_handler
2421 * purpose: is called for finished Open Port command
2426 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2428 int retval = -EINVAL;
2429 struct zfcp_port *port;
2430 struct fsf_plogi *plogi;
2431 struct fsf_qtcb_header *header;
2432 u16 subtable, rule, counter;
2434 port = (struct zfcp_port *) fsf_req->data;
2435 header = &fsf_req->qtcb->header;
2437 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2438 /* don't change port status in our bookkeeping */
2439 goto skip_fsfstatus;
2442 /* evaluate FSF status in QTCB */
2443 switch (header->fsf_status) {
2445 case FSF_PORT_ALREADY_OPEN:
2446 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2447 "is already open.\n",
2448 port->wwpn, zfcp_get_busid_by_port(port));
2449 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2452 * This is a bug, however operation should continue normally
2453 * if it is simply ignored
2457 case FSF_ACCESS_DENIED:
2458 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2460 port->wwpn, zfcp_get_busid_by_port(port));
2461 for (counter = 0; counter < 2; counter++) {
2462 subtable = header->fsf_status_qual.halfword[counter * 2];
2463 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2465 case FSF_SQ_CFDC_SUBTABLE_OS:
2466 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2467 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2468 case FSF_SQ_CFDC_SUBTABLE_LUN:
2469 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2470 zfcp_act_subtable_type[subtable], rule);
2474 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2475 zfcp_erp_port_access_denied(port);
2476 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2479 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2480 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2481 "The remote port 0x%016Lx on adapter %s "
2482 "could not be opened. Disabling it.\n",
2483 port->wwpn, zfcp_get_busid_by_port(port));
2484 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2486 zfcp_erp_port_failed(port);
2487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2490 case FSF_ADAPTER_STATUS_AVAILABLE:
2491 switch (header->fsf_status_qual.word[0]) {
2492 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2493 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2495 /* ERP strategy will escalate */
2496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2498 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2499 /* ERP strategy will escalate */
2500 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2504 case FSF_SQ_NO_RETRY_POSSIBLE:
2505 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2506 "adapter %s could not be opened. "
2509 zfcp_get_busid_by_port(port));
2510 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2512 zfcp_erp_port_failed(port);
2513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2517 ("bug: Wrong status qualifier 0x%x arrived.\n",
2518 header->fsf_status_qual.word[0]);
2519 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2522 fsf_req->adapter->erp_dbf, 0,
2523 &header->fsf_status_qual.word[0],
2530 /* save port handle assigned by FSF */
2531 port->handle = header->port_handle;
2532 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2533 "was opened, it's port handle is 0x%x\n",
2534 port->wwpn, zfcp_get_busid_by_port(port),
2536 /* mark port as open */
2537 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2538 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2539 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2540 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2543 /* check whether D_ID has changed during open */
2545 * FIXME: This check is not airtight, as the FCP channel does
2546 * not monitor closures of target port connections caused on
2547 * the remote side. Thus, they might miss out on invalidating
2548 * locally cached WWPNs (and other N_Port parameters) of gone
2549 * target ports. So, our heroic attempt to make things safe
2550 * could be undermined by 'open port' response data tagged with
2551 * obsolete WWPNs. Another reason to monitor potential
2552 * connection closures ourself at least (by interpreting
2553 * incoming ELS' and unsolicited status). It just crosses my
2554 * mind that one should be able to cross-check by means of
2555 * another GID_PN straight after a port has been opened.
2556 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2558 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2559 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2561 if (fsf_req->qtcb->bottom.support.els1_length <
2562 ((((unsigned long) &plogi->serv_param.wwpn) -
2563 ((unsigned long) plogi)) + sizeof (u64))) {
2565 "warning: insufficient length of "
2566 "PLOGI payload (%i)\n",
2567 fsf_req->qtcb->bottom.support.els1_length);
2568 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2569 "fsf_s_short_plogi:");
2570 /* skip sanity check and assume wwpn is ok */
2572 if (plogi->serv_param.wwpn != port->wwpn) {
2573 ZFCP_LOG_INFO("warning: d_id of port "
2574 "0x%016Lx changed during "
2575 "open\n", port->wwpn);
2577 fsf_req->adapter->erp_dbf, 0,
2578 "fsf_s_did_change:");
2580 ZFCP_STATUS_PORT_DID_DID,
2583 port->wwnn = plogi->serv_param.wwnn;
2588 case FSF_UNKNOWN_OP_SUBTYPE:
2589 /* should never occure, subtype not set in zfcp_fsf_open_port */
2590 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2591 "op_subtype=0x%x)\n",
2592 zfcp_get_busid_by_port(port),
2593 fsf_req->qtcb->bottom.support.operation_subtype);
2594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2598 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2599 "(debug info 0x%x)\n",
2600 header->fsf_status);
2601 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2602 debug_exception(fsf_req->adapter->erp_dbf, 0,
2603 &header->fsf_status, sizeof (u32));
2608 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2613 * function: zfcp_fsf_close_port
2615 * purpose: submit FSF command "close port"
2617 * returns: address of initiated FSF request
2618 * NULL - request could not be initiated
2621 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2623 volatile struct qdio_buffer_element *sbale;
2624 unsigned long lock_flags;
2627 /* setup new FSF request */
2628 retval = zfcp_fsf_req_create(erp_action->adapter,
2629 FSF_QTCB_CLOSE_PORT,
2630 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2631 erp_action->adapter->pool.fsf_req_erp,
2632 &lock_flags, &(erp_action->fsf_req));
2634 ZFCP_LOG_INFO("error: Could not create a close port request "
2635 "for port 0x%016Lx on adapter %s.\n",
2636 erp_action->port->wwpn,
2637 zfcp_get_busid_by_adapter(erp_action->adapter));
2641 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2642 erp_action->fsf_req->sbal_curr, 0);
2643 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2644 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2646 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2647 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2648 erp_action->fsf_req->erp_action = erp_action;
2649 erp_action->fsf_req->qtcb->header.port_handle =
2650 erp_action->port->handle;
2652 /* start QDIO request for this FSF request */
2653 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2655 ZFCP_LOG_INFO("error: Could not send a close port request for "
2656 "port 0x%016Lx on adapter %s.\n",
2657 erp_action->port->wwpn,
2658 zfcp_get_busid_by_adapter(erp_action->adapter));
2659 zfcp_fsf_req_free(erp_action->fsf_req);
2660 erp_action->fsf_req = NULL;
2664 ZFCP_LOG_TRACE("close port request initiated "
2665 "(adapter %s, port 0x%016Lx)\n",
2666 zfcp_get_busid_by_adapter(erp_action->adapter),
2667 erp_action->port->wwpn);
2669 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2675 * function: zfcp_fsf_close_port_handler
2677 * purpose: is called for finished Close Port FSF command
2682 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2684 int retval = -EINVAL;
2685 struct zfcp_port *port;
2687 port = (struct zfcp_port *) fsf_req->data;
2689 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2690 /* don't change port status in our bookkeeping */
2691 goto skip_fsfstatus;
2694 /* evaluate FSF status in QTCB */
2695 switch (fsf_req->qtcb->header.fsf_status) {
2697 case FSF_PORT_HANDLE_NOT_VALID:
2698 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2699 "0x%016Lx on adapter %s invalid. This may happen "
2700 "occasionally.\n", port->handle,
2701 port->wwpn, zfcp_get_busid_by_port(port));
2702 ZFCP_LOG_DEBUG("status qualifier:\n");
2703 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2704 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2705 sizeof (union fsf_status_qual));
2706 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2708 zfcp_erp_adapter_reopen(port->adapter, 0);
2709 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2712 case FSF_ADAPTER_STATUS_AVAILABLE:
2713 /* Note: FSF has actually closed the port in this case.
2714 * The status code is just daft. Fingers crossed for a change
2720 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2721 "port handle 0x%x\n", port->wwpn,
2722 zfcp_get_busid_by_port(port), port->handle);
2723 zfcp_erp_modify_port_status(port,
2724 ZFCP_STATUS_COMMON_OPEN,
2730 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2731 "(debug info 0x%x)\n",
2732 fsf_req->qtcb->header.fsf_status);
2733 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2734 debug_exception(fsf_req->adapter->erp_dbf, 0,
2735 &fsf_req->qtcb->header.fsf_status,
2741 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2746 * function: zfcp_fsf_close_physical_port
2748 * purpose: submit FSF command "close physical port"
2750 * returns: address of initiated FSF request
2751 * NULL - request could not be initiated
2754 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2757 unsigned long lock_flags;
2758 volatile struct qdio_buffer_element *sbale;
2760 /* setup new FSF request */
2761 retval = zfcp_fsf_req_create(erp_action->adapter,
2762 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2763 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2764 erp_action->adapter->pool.fsf_req_erp,
2765 &lock_flags, &erp_action->fsf_req);
2767 ZFCP_LOG_INFO("error: Could not create close physical port "
2768 "request (adapter %s, port 0x%016Lx)\n",
2769 zfcp_get_busid_by_adapter(erp_action->adapter),
2770 erp_action->port->wwpn);
2775 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2776 erp_action->fsf_req->sbal_curr, 0);
2777 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2778 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2780 /* mark port as being closed */
2781 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2782 &erp_action->port->status);
2783 /* save a pointer to this port */
2784 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2785 /* port to be closed */
2786 erp_action->fsf_req->qtcb->header.port_handle =
2787 erp_action->port->handle;
2788 erp_action->fsf_req->erp_action = erp_action;
2790 /* start QDIO request for this FSF request */
2791 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2793 ZFCP_LOG_INFO("error: Could not send close physical port "
2794 "request (adapter %s, port 0x%016Lx)\n",
2795 zfcp_get_busid_by_adapter(erp_action->adapter),
2796 erp_action->port->wwpn);
2797 zfcp_fsf_req_free(erp_action->fsf_req);
2798 erp_action->fsf_req = NULL;
2802 ZFCP_LOG_TRACE("close physical port request initiated "
2803 "(adapter %s, port 0x%016Lx)\n",
2804 zfcp_get_busid_by_adapter(erp_action->adapter),
2805 erp_action->port->wwpn);
2807 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2813 * function: zfcp_fsf_close_physical_port_handler
2815 * purpose: is called for finished Close Physical Port FSF command
2820 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2822 int retval = -EINVAL;
2823 struct zfcp_port *port;
2824 struct zfcp_unit *unit;
2825 struct fsf_qtcb_header *header;
2826 u16 subtable, rule, counter;
2828 port = (struct zfcp_port *) fsf_req->data;
2829 header = &fsf_req->qtcb->header;
2831 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2832 /* don't change port status in our bookkeeping */
2833 goto skip_fsfstatus;
2836 /* evaluate FSF status in QTCB */
2837 switch (header->fsf_status) {
2839 case FSF_PORT_HANDLE_NOT_VALID:
2840 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2841 "(adapter %s, port 0x%016Lx). "
2842 "This may happen occasionally.\n",
2844 zfcp_get_busid_by_port(port),
2846 ZFCP_LOG_DEBUG("status qualifier:\n");
2847 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2848 (char *) &header->fsf_status_qual,
2849 sizeof (union fsf_status_qual));
2850 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2852 zfcp_erp_adapter_reopen(port->adapter, 0);
2853 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2856 case FSF_ACCESS_DENIED:
2857 ZFCP_LOG_NORMAL("Access denied, cannot close "
2858 "physical port 0x%016Lx on adapter %s\n",
2859 port->wwpn, zfcp_get_busid_by_port(port));
2860 for (counter = 0; counter < 2; counter++) {
2861 subtable = header->fsf_status_qual.halfword[counter * 2];
2862 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2864 case FSF_SQ_CFDC_SUBTABLE_OS:
2865 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2866 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2867 case FSF_SQ_CFDC_SUBTABLE_LUN:
2868 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2869 zfcp_act_subtable_type[subtable], rule);
2873 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2874 zfcp_erp_port_access_denied(port);
2875 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2878 case FSF_PORT_BOXED:
2879 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2880 "%s needs to be reopened but it was attempted "
2881 "to close it physically.\n",
2883 zfcp_get_busid_by_port(port));
2884 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2885 zfcp_erp_port_boxed(port);
2886 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2887 ZFCP_STATUS_FSFREQ_RETRY;
2890 case FSF_ADAPTER_STATUS_AVAILABLE:
2891 switch (header->fsf_status_qual.word[0]) {
2892 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2893 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2895 /* This will now be escalated by ERP */
2896 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2898 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2899 /* ERP strategy will escalate */
2900 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2902 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2906 ("bug: Wrong status qualifier 0x%x arrived.\n",
2907 header->fsf_status_qual.word[0]);
2908 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2911 fsf_req->adapter->erp_dbf, 0,
2912 &header->fsf_status_qual.word[0], sizeof (u32));
2918 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2919 "physically closed, port handle 0x%x\n",
2921 zfcp_get_busid_by_port(port), port->handle);
2922 /* can't use generic zfcp_erp_modify_port_status because
2923 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2925 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2926 list_for_each_entry(unit, &port->unit_list_head, list)
2927 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2932 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2933 "(debug info 0x%x)\n",
2934 header->fsf_status);
2935 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2936 debug_exception(fsf_req->adapter->erp_dbf, 0,
2937 &header->fsf_status, sizeof (u32));
2942 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2947 * function: zfcp_fsf_open_unit
2953 * assumptions: This routine does not check whether the associated
2954 * remote port has already been opened. This should be
2955 * done by calling routines. Otherwise some status
2956 * may be presented by FSF
2959 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2961 volatile struct qdio_buffer_element *sbale;
2962 unsigned long lock_flags;
2965 /* setup new FSF request */
2966 retval = zfcp_fsf_req_create(erp_action->adapter,
2968 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2969 erp_action->adapter->pool.fsf_req_erp,
2970 &lock_flags, &(erp_action->fsf_req));
2972 ZFCP_LOG_INFO("error: Could not create open unit request for "
2973 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2974 erp_action->unit->fcp_lun,
2975 erp_action->unit->port->wwpn,
2976 zfcp_get_busid_by_adapter(erp_action->adapter));
2980 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2981 erp_action->fsf_req->sbal_curr, 0);
2982 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2983 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2985 erp_action->fsf_req->qtcb->header.port_handle =
2986 erp_action->port->handle;
2987 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2988 erp_action->unit->fcp_lun;
2989 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2990 erp_action->fsf_req->qtcb->bottom.support.option =
2991 FSF_OPEN_LUN_SUPPRESS_BOXING;
2992 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2993 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
2994 erp_action->fsf_req->erp_action = erp_action;
2996 /* start QDIO request for this FSF request */
2997 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2999 ZFCP_LOG_INFO("error: Could not send an open unit request "
3000 "on the adapter %s, port 0x%016Lx for "
3002 zfcp_get_busid_by_adapter(erp_action->adapter),
3003 erp_action->port->wwpn,
3004 erp_action->unit->fcp_lun);
3005 zfcp_fsf_req_free(erp_action->fsf_req);
3006 erp_action->fsf_req = NULL;
3010 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3011 "port 0x%016Lx, unit 0x%016Lx)\n",
3012 zfcp_get_busid_by_adapter(erp_action->adapter),
3013 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3015 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3021 * function: zfcp_fsf_open_unit_handler
3023 * purpose: is called for finished Open LUN command
3028 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3030 int retval = -EINVAL;
3031 struct zfcp_adapter *adapter;
3032 struct zfcp_unit *unit;
3033 struct fsf_qtcb_header *header;
3034 struct fsf_qtcb_bottom_support *bottom;
3035 struct fsf_queue_designator *queue_designator;
3036 u16 subtable, rule, counter;
3037 int exclusive, readwrite;
3039 unit = (struct zfcp_unit *) fsf_req->data;
3041 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3042 /* don't change unit status in our bookkeeping */
3043 goto skip_fsfstatus;
3046 adapter = fsf_req->adapter;
3047 header = &fsf_req->qtcb->header;
3048 bottom = &fsf_req->qtcb->bottom.support;
3049 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3051 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3052 ZFCP_STATUS_UNIT_SHARED |
3053 ZFCP_STATUS_UNIT_READONLY,
3056 /* evaluate FSF status in QTCB */
3057 switch (header->fsf_status) {
3059 case FSF_PORT_HANDLE_NOT_VALID:
3060 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3061 "for port 0x%016Lx on adapter %s invalid "
3062 "This may happen occasionally\n",
3064 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3065 ZFCP_LOG_DEBUG("status qualifier:\n");
3066 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3067 (char *) &header->fsf_status_qual,
3068 sizeof (union fsf_status_qual));
3069 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3070 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3071 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3074 case FSF_LUN_ALREADY_OPEN:
3075 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3076 "remote port 0x%016Lx on adapter %s twice.\n",
3078 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3079 debug_text_exception(adapter->erp_dbf, 0,
3081 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3084 case FSF_ACCESS_DENIED:
3085 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3086 "remote port 0x%016Lx on adapter %s\n",
3087 unit->fcp_lun, unit->port->wwpn,
3088 zfcp_get_busid_by_unit(unit));
3089 for (counter = 0; counter < 2; counter++) {
3090 subtable = header->fsf_status_qual.halfword[counter * 2];
3091 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3093 case FSF_SQ_CFDC_SUBTABLE_OS:
3094 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3095 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3096 case FSF_SQ_CFDC_SUBTABLE_LUN:
3097 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3098 zfcp_act_subtable_type[subtable], rule);
3102 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3103 zfcp_erp_unit_access_denied(unit);
3104 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3105 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3106 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3109 case FSF_PORT_BOXED:
3110 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3111 "needs to be reopened\n",
3112 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3113 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3114 zfcp_erp_port_boxed(unit->port);
3115 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3116 ZFCP_STATUS_FSFREQ_RETRY;
3119 case FSF_LUN_SHARING_VIOLATION:
3120 if (header->fsf_status_qual.word[0] != 0) {
3121 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3123 "connected to the adapter %s "
3124 "is already in use in LPAR%d, CSS%d\n",
3127 zfcp_get_busid_by_unit(unit),
3128 queue_designator->hla,
3129 queue_designator->cssid);
3131 subtable = header->fsf_status_qual.halfword[4];
3132 rule = header->fsf_status_qual.halfword[5];
3134 case FSF_SQ_CFDC_SUBTABLE_OS:
3135 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3136 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3137 case FSF_SQ_CFDC_SUBTABLE_LUN:
3138 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3139 "remote port with WWPN 0x%Lx "
3140 "connected to the adapter %s "
3141 "is denied (%s rule %d)\n",
3144 zfcp_get_busid_by_unit(unit),
3145 zfcp_act_subtable_type[subtable],
3150 ZFCP_LOG_DEBUG("status qualifier:\n");
3151 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3152 (char *) &header->fsf_status_qual,
3153 sizeof (union fsf_status_qual));
3154 debug_text_event(adapter->erp_dbf, 2,
3156 zfcp_erp_unit_access_denied(unit);
3157 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3158 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3159 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3162 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3163 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3164 "There is no handle (temporary port identifier) "
3165 "available for unit 0x%016Lx on port 0x%016Lx "
3169 zfcp_get_busid_by_unit(unit));
3170 debug_text_event(adapter->erp_dbf, 1,
3172 zfcp_erp_unit_failed(unit);
3173 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3176 case FSF_ADAPTER_STATUS_AVAILABLE:
3177 switch (header->fsf_status_qual.word[0]) {
3178 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3179 /* Re-establish link to port */
3180 debug_text_event(adapter->erp_dbf, 1,
3182 zfcp_test_link(unit->port);
3183 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3185 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3186 /* ERP strategy will escalate */
3187 debug_text_event(adapter->erp_dbf, 1,
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3193 ("bug: Wrong status qualifier 0x%x arrived.\n",
3194 header->fsf_status_qual.word[0]);
3195 debug_text_event(adapter->erp_dbf, 0,
3197 debug_exception(adapter->erp_dbf, 0,
3198 &header->fsf_status_qual.word[0],
3203 case FSF_INVALID_COMMAND_OPTION:
3205 "Invalid option 0x%x has been specified "
3206 "in QTCB bottom sent to the adapter %s\n",
3208 zfcp_get_busid_by_adapter(adapter));
3209 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3214 /* save LUN handle assigned by FSF */
3215 unit->handle = header->lun_handle;
3216 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3217 "adapter %s opened, port handle 0x%x\n",
3220 zfcp_get_busid_by_unit(unit),
3222 /* mark unit as open */
3223 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3225 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3226 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3227 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3228 exclusive = (bottom->lun_access_info &
3229 FSF_UNIT_ACCESS_EXCLUSIVE);
3230 readwrite = (bottom->lun_access_info &
3231 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3234 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3238 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3240 ZFCP_LOG_NORMAL("read-only access for unit "
3241 "(adapter %s, wwpn=0x%016Lx, "
3242 "fcp_lun=0x%016Lx)\n",
3243 zfcp_get_busid_by_unit(unit),
3248 if (exclusive && !readwrite) {
3249 ZFCP_LOG_NORMAL("exclusive access of read-only "
3250 "unit not supported\n");
3251 zfcp_erp_unit_failed(unit);
3252 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3253 zfcp_erp_unit_shutdown(unit, 0);
3254 } else if (!exclusive && readwrite) {
3255 ZFCP_LOG_NORMAL("shared access of read-write "
3256 "unit not supported\n");
3257 zfcp_erp_unit_failed(unit);
3258 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3259 zfcp_erp_unit_shutdown(unit, 0);
3267 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3268 "(debug info 0x%x)\n",
3269 header->fsf_status);
3270 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3271 debug_exception(adapter->erp_dbf, 0,
3272 &header->fsf_status, sizeof (u32));
3277 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3282 * function: zfcp_fsf_close_unit
3286 * returns: address of fsf_req - request successfully initiated
3289 * assumptions: This routine does not check whether the associated
3290 * remote port/lun has already been opened. This should be
3291 * done by calling routines. Otherwise some status
3292 * may be presented by FSF
3295 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3297 volatile struct qdio_buffer_element *sbale;
3298 unsigned long lock_flags;
3301 /* setup new FSF request */
3302 retval = zfcp_fsf_req_create(erp_action->adapter,
3304 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3305 erp_action->adapter->pool.fsf_req_erp,
3306 &lock_flags, &(erp_action->fsf_req));
3308 ZFCP_LOG_INFO("error: Could not create close unit request for "
3309 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3310 erp_action->unit->fcp_lun,
3311 erp_action->port->wwpn,
3312 zfcp_get_busid_by_adapter(erp_action->adapter));
3316 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3317 erp_action->fsf_req->sbal_curr, 0);
3318 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3319 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3321 erp_action->fsf_req->qtcb->header.port_handle =
3322 erp_action->port->handle;
3323 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3324 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3325 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3326 erp_action->fsf_req->erp_action = erp_action;
3328 /* start QDIO request for this FSF request */
3329 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3331 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3332 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3333 erp_action->unit->fcp_lun,
3334 erp_action->port->wwpn,
3335 zfcp_get_busid_by_adapter(erp_action->adapter));
3336 zfcp_fsf_req_free(erp_action->fsf_req);
3337 erp_action->fsf_req = NULL;
3341 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3342 "port 0x%016Lx, unit 0x%016Lx)\n",
3343 zfcp_get_busid_by_adapter(erp_action->adapter),
3344 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3346 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3352 * function: zfcp_fsf_close_unit_handler
3354 * purpose: is called for finished Close LUN FSF command
3359 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3361 int retval = -EINVAL;
3362 struct zfcp_unit *unit;
3364 unit = (struct zfcp_unit *) fsf_req->data;
3366 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3367 /* don't change unit status in our bookkeeping */
3368 goto skip_fsfstatus;
3371 /* evaluate FSF status in QTCB */
3372 switch (fsf_req->qtcb->header.fsf_status) {
3374 case FSF_PORT_HANDLE_NOT_VALID:
3375 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3376 "0x%016Lx on adapter %s invalid. This may "
3377 "happen in rare circumstances\n",
3380 zfcp_get_busid_by_unit(unit));
3381 ZFCP_LOG_DEBUG("status qualifier:\n");
3382 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3383 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3384 sizeof (union fsf_status_qual));
3385 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3387 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3388 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3391 case FSF_LUN_HANDLE_NOT_VALID:
3392 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3393 "0x%016Lx on port 0x%016Lx on adapter %s is "
3394 "invalid. This may happen occasionally.\n",
3398 zfcp_get_busid_by_unit(unit));
3399 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3400 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3401 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3402 sizeof (union fsf_status_qual));
3403 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3405 zfcp_erp_port_reopen(unit->port, 0);
3406 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3409 case FSF_PORT_BOXED:
3410 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3411 "needs to be reopened\n",
3413 zfcp_get_busid_by_unit(unit));
3414 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3415 zfcp_erp_port_boxed(unit->port);
3416 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3417 ZFCP_STATUS_FSFREQ_RETRY;
3420 case FSF_ADAPTER_STATUS_AVAILABLE:
3421 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3422 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3423 /* re-establish link to port */
3424 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3426 zfcp_test_link(unit->port);
3427 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3429 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3430 /* ERP strategy will escalate */
3431 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3433 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3437 ("bug: Wrong status qualifier 0x%x arrived.\n",
3438 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3439 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3442 fsf_req->adapter->erp_dbf, 0,
3443 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3450 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3451 "closed, port handle 0x%x\n",
3454 zfcp_get_busid_by_unit(unit),
3456 /* mark unit as closed */
3457 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3462 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3463 "(debug info 0x%x)\n",
3464 fsf_req->qtcb->header.fsf_status);
3465 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3466 debug_exception(fsf_req->adapter->erp_dbf, 0,
3467 &fsf_req->qtcb->header.fsf_status,
3473 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3478 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3479 * @adapter: adapter where scsi command is issued
3480 * @unit: unit where command is sent to
3481 * @scsi_cmnd: scsi command to be sent
3482 * @timer: timer to be started when request is initiated
3483 * @req_flags: flags for fsf_request
3486 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3487 struct zfcp_unit *unit,
3488 struct scsi_cmnd * scsi_cmnd,
3489 struct timer_list *timer, int req_flags)
3491 struct zfcp_fsf_req *fsf_req = NULL;
3492 struct fcp_cmnd_iu *fcp_cmnd_iu;
3493 unsigned int sbtype;
3494 unsigned long lock_flags;
3499 /* setup new FSF request */
3500 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3501 adapter->pool.fsf_req_scsi,
3502 &lock_flags, &fsf_req);
3503 if (unlikely(retval < 0)) {
3504 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3505 "for unit 0x%016Lx on port 0x%016Lx on "
3509 zfcp_get_busid_by_adapter(adapter));
3510 goto failed_req_create;
3513 zfcp_unit_get(unit);
3514 fsf_req->unit = unit;
3516 /* associate FSF request with SCSI request (for look up on abort) */
3517 scsi_cmnd->host_scribble = (char *) fsf_req;
3519 /* associate SCSI command with FSF request */
3520 fsf_req->data = (unsigned long) scsi_cmnd;
3522 /* set handles of unit and its parent port in QTCB */
3523 fsf_req->qtcb->header.lun_handle = unit->handle;
3524 fsf_req->qtcb->header.port_handle = unit->port->handle;
3526 /* FSF does not define the structure of the FCP_CMND IU */
3527 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3528 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3531 * set depending on data direction:
3532 * data direction bits in SBALE (SB Type)
3533 * data direction bits in QTCB
3534 * data direction bits in FCP_CMND IU
3536 switch (scsi_cmnd->sc_data_direction) {
3538 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3541 * what is the correct type for commands
3542 * without 'real' data buffers?
3544 sbtype = SBAL_FLAGS0_TYPE_READ;
3546 case DMA_FROM_DEVICE:
3547 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3548 sbtype = SBAL_FLAGS0_TYPE_READ;
3549 fcp_cmnd_iu->rddata = 1;
3552 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3553 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3554 fcp_cmnd_iu->wddata = 1;
3556 case DMA_BIDIRECTIONAL:
3559 * dummy, catch this condition earlier
3560 * in zfcp_scsi_queuecommand
3562 goto failed_scsi_cmnd;
3565 /* set FC service class in QTCB (3 per default) */
3566 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3568 /* set FCP_LUN in FCP_CMND IU in QTCB */
3569 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3571 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3573 /* set task attributes in FCP_CMND IU in QTCB */
3574 if (likely((scsi_cmnd->device->simple_tags) ||
3575 (atomic_test_mask(mask, &unit->status))))
3576 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3578 fcp_cmnd_iu->task_attribute = UNTAGGED;
3580 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3581 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3582 fcp_cmnd_iu->add_fcp_cdb_length
3583 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3584 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3585 "additional FCP_CDB length is 0x%x "
3586 "(shifted right 2 bits)\n",
3588 fcp_cmnd_iu->add_fcp_cdb_length);
3591 * copy SCSI CDB (including additional length, if any) to
3592 * FCP_CDB in FCP_CMND IU in QTCB
3594 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3596 /* FCP CMND IU length in QTCB */
3597 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3598 sizeof (struct fcp_cmnd_iu) +
3599 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3601 /* generate SBALEs from data buffer */
3602 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3603 if (unlikely(real_bytes < 0)) {
3604 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3606 "Data did not fit into available buffer(s), "
3607 "waiting for more...\n");
3610 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3611 "required. Shutting down unit "
3612 "(adapter %s, port 0x%016Lx, "
3614 zfcp_get_busid_by_unit(unit),
3617 zfcp_erp_unit_shutdown(unit, 0);
3623 /* set length of FCP data length in FCP_CMND IU in QTCB */
3624 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3626 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3627 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3628 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3631 * start QDIO request for this FSF request
3632 * covered by an SBALE)
3634 retval = zfcp_fsf_req_send(fsf_req, timer);
3635 if (unlikely(retval < 0)) {
3636 ZFCP_LOG_INFO("error: Could not send FCP command request "
3637 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3638 zfcp_get_busid_by_adapter(adapter),
3644 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3645 "port 0x%016Lx, unit 0x%016Lx)\n",
3646 zfcp_get_busid_by_adapter(adapter),
3654 zfcp_unit_put(unit);
3655 zfcp_fsf_req_free(fsf_req);
3657 scsi_cmnd->host_scribble = NULL;
3660 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3665 * function: zfcp_fsf_send_fcp_command_task_management
3671 * FIXME(design): should be watched by a timeout!!!
3672 * FIXME(design) shouldn't this be modified to return an int
3673 * also...don't know how though
3676 struct zfcp_fsf_req *
3677 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3678 struct zfcp_unit *unit,
3679 u8 tm_flags, int req_flags)
3681 struct zfcp_fsf_req *fsf_req = NULL;
3683 struct fcp_cmnd_iu *fcp_cmnd_iu;
3684 unsigned long lock_flags;
3685 volatile struct qdio_buffer_element *sbale;
3687 /* setup new FSF request */
3688 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3689 adapter->pool.fsf_req_scsi,
3690 &lock_flags, &fsf_req);
3692 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3693 "management) request for adapter %s, port "
3694 " 0x%016Lx, unit 0x%016Lx.\n",
3695 zfcp_get_busid_by_adapter(adapter),
3696 unit->port->wwpn, unit->fcp_lun);
3701 * Used to decide on proper handler in the return path,
3702 * could be either zfcp_fsf_send_fcp_command_task_handler or
3703 * zfcp_fsf_send_fcp_command_task_management_handler */
3705 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3708 * hold a pointer to the unit being target of this
3709 * task management request
3711 fsf_req->data = (unsigned long) unit;
3713 /* set FSF related fields in QTCB */
3714 fsf_req->qtcb->header.lun_handle = unit->handle;
3715 fsf_req->qtcb->header.port_handle = unit->port->handle;
3716 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3717 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3718 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3719 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3721 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3722 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3723 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3725 /* set FCP related fields in FCP_CMND IU in QTCB */
3726 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3727 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3728 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3729 fcp_cmnd_iu->task_management_flags = tm_flags;
3731 /* start QDIO request for this FSF request */
3732 zfcp_fsf_start_scsi_er_timer(adapter);
3733 retval = zfcp_fsf_req_send(fsf_req, NULL);
3735 del_timer(&adapter->scsi_er_timer);
3736 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3737 "management) on adapter %s, port 0x%016Lx for "
3738 "unit LUN 0x%016Lx\n",
3739 zfcp_get_busid_by_adapter(adapter),
3742 zfcp_fsf_req_free(fsf_req);
3747 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3748 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3750 zfcp_get_busid_by_adapter(adapter),
3755 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3760 * function: zfcp_fsf_send_fcp_command_handler
3762 * purpose: is called for finished Send FCP Command
3767 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3769 int retval = -EINVAL;
3770 struct zfcp_unit *unit;
3771 struct fsf_qtcb_header *header;
3772 u16 subtable, rule, counter;
3774 header = &fsf_req->qtcb->header;
3776 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3777 unit = (struct zfcp_unit *) fsf_req->data;
3779 unit = fsf_req->unit;
3781 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3782 /* go directly to calls of special handlers */
3783 goto skip_fsfstatus;
3786 /* evaluate FSF status in QTCB */
3787 switch (header->fsf_status) {
3789 case FSF_PORT_HANDLE_NOT_VALID:
3790 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3791 "0x%016Lx on adapter %s invalid\n",
3793 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3794 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3795 (char *) &header->fsf_status_qual,
3796 sizeof (union fsf_status_qual));
3797 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3799 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3800 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3803 case FSF_LUN_HANDLE_NOT_VALID:
3804 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3805 "0x%016Lx on port 0x%016Lx on adapter %s is "
3806 "invalid. This may happen occasionally.\n",
3810 zfcp_get_busid_by_unit(unit));
3811 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3812 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3813 (char *) &header->fsf_status_qual,
3814 sizeof (union fsf_status_qual));
3815 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3817 zfcp_erp_port_reopen(unit->port, 0);
3818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3821 case FSF_HANDLE_MISMATCH:
3822 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3823 "unexpectedly. (adapter %s, port 0x%016Lx, "
3826 zfcp_get_busid_by_unit(unit),
3829 ZFCP_LOG_NORMAL("status qualifier:\n");
3830 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3831 (char *) &header->fsf_status_qual,
3832 sizeof (union fsf_status_qual));
3833 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3835 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3836 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3839 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3840 if (fsf_req->adapter->fc_service_class <= 3) {
3841 ZFCP_LOG_NORMAL("error: The adapter %s does "
3842 "not support fibrechannel class %d.\n",
3843 zfcp_get_busid_by_unit(unit),
3844 fsf_req->adapter->fc_service_class);
3846 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3847 "adapter %s is invalid. "
3848 "(debug info %d)\n",
3849 zfcp_get_busid_by_unit(unit),
3850 fsf_req->adapter->fc_service_class);
3852 /* stop operation for this adapter */
3853 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3854 "fsf_s_class_nsup");
3855 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3856 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3859 case FSF_FCPLUN_NOT_VALID:
3860 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3861 "adapter %s does not have correct unit "
3865 zfcp_get_busid_by_unit(unit),
3867 ZFCP_LOG_DEBUG("status qualifier:\n");
3868 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3869 (char *) &header->fsf_status_qual,
3870 sizeof (union fsf_status_qual));
3871 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3872 "fsf_s_fcp_lun_nv");
3873 zfcp_erp_port_reopen(unit->port, 0);
3874 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3877 case FSF_ACCESS_DENIED:
3878 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3879 "unit 0x%016Lx on port 0x%016Lx on "
3880 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3881 zfcp_get_busid_by_unit(unit));
3882 for (counter = 0; counter < 2; counter++) {
3883 subtable = header->fsf_status_qual.halfword[counter * 2];
3884 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3886 case FSF_SQ_CFDC_SUBTABLE_OS:
3887 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3888 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3889 case FSF_SQ_CFDC_SUBTABLE_LUN:
3890 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3891 zfcp_act_subtable_type[subtable], rule);
3895 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3896 zfcp_erp_unit_access_denied(unit);
3897 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3900 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3901 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3902 "0x%016Lx on port 0x%016Lx on adapter %s "
3903 "(debug info %d)\n",
3906 zfcp_get_busid_by_unit(unit),
3907 fsf_req->qtcb->bottom.io.data_direction);
3908 /* stop operation for this adapter */
3909 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3910 "fsf_s_dir_ind_nv");
3911 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3912 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3915 case FSF_CMND_LENGTH_NOT_VALID:
3917 ("bug: An invalid control-data-block length field "
3918 "was found in a command for unit 0x%016Lx on port "
3919 "0x%016Lx on adapter %s " "(debug info %d)\n",
3920 unit->fcp_lun, unit->port->wwpn,
3921 zfcp_get_busid_by_unit(unit),
3922 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3923 /* stop operation for this adapter */
3924 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3925 "fsf_s_cmd_len_nv");
3926 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3927 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3930 case FSF_PORT_BOXED:
3931 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3932 "needs to be reopened\n",
3933 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3934 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3935 zfcp_erp_port_boxed(unit->port);
3936 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3937 ZFCP_STATUS_FSFREQ_RETRY;
3941 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3942 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3943 zfcp_get_busid_by_unit(unit),
3944 unit->port->wwpn, unit->fcp_lun);
3945 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3946 zfcp_erp_unit_boxed(unit);
3947 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3948 | ZFCP_STATUS_FSFREQ_RETRY;
3951 case FSF_ADAPTER_STATUS_AVAILABLE:
3952 switch (header->fsf_status_qual.word[0]) {
3953 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3954 /* re-establish link to port */
3955 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3957 zfcp_test_link(unit->port);
3959 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3960 /* FIXME(hw) need proper specs for proper action */
3961 /* let scsi stack deal with retries and escalation */
3962 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3967 ("Unknown status qualifier 0x%x arrived.\n",
3968 header->fsf_status_qual.word[0]);
3969 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3971 debug_exception(fsf_req->adapter->erp_dbf, 0,
3972 &header->fsf_status_qual.word[0],
3976 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3982 case FSF_FCP_RSP_AVAILABLE:
3986 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3987 debug_exception(fsf_req->adapter->erp_dbf, 0,
3988 &header->fsf_status, sizeof(u32));
3993 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3995 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3997 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3998 fsf_req->unit = NULL;
3999 zfcp_unit_put(unit);
4005 * function: zfcp_fsf_send_fcp_command_task_handler
4007 * purpose: evaluates FCP_RSP IU
4012 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4015 struct scsi_cmnd *scpnt;
4016 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4017 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4018 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4019 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4021 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4022 unsigned long flags;
4023 struct zfcp_unit *unit = fsf_req->unit;
4025 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4026 scpnt = (struct scsi_cmnd *) fsf_req->data;
4027 if (unlikely(!scpnt)) {
4029 ("Command with fsf_req %p is not associated to "
4030 "a scsi command anymore. Aborted?\n", fsf_req);
4033 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4034 /* FIXME: (design) mid-layer should handle DID_ABORT like
4035 * DID_SOFT_ERROR by retrying the request for devices
4036 * that allow retries.
4038 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4039 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4040 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4041 goto skip_fsfstatus;
4044 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4045 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4046 set_host_byte(&scpnt->result, DID_ERROR);
4047 goto skip_fsfstatus;
4050 /* set message byte of result in SCSI command */
4051 scpnt->result |= COMMAND_COMPLETE << 8;
4054 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4055 * of result in SCSI command
4057 scpnt->result |= fcp_rsp_iu->scsi_status;
4058 if (unlikely(fcp_rsp_iu->scsi_status)) {
4060 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4061 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4062 scpnt->cmnd, scpnt->cmd_len);
4063 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4064 fcp_rsp_iu->scsi_status);
4065 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4066 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4067 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4068 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4069 fcp_rsp_iu->fcp_sns_len);
4072 /* check FCP_RSP_INFO */
4073 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4074 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4075 switch (fcp_rsp_info[3]) {
4078 ZFCP_LOG_TRACE("no failure or Task Management "
4079 "Function complete\n");
4080 set_host_byte(&scpnt->result, DID_OK);
4082 case RSP_CODE_LENGTH_MISMATCH:
4084 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4085 "that the fibrechannel protocol data "
4086 "length differs from the burst length. "
4087 "The problem occured on unit 0x%016Lx "
4088 "on port 0x%016Lx on adapter %s",
4091 zfcp_get_busid_by_unit(unit));
4092 /* dump SCSI CDB as prepared by zfcp */
4093 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4094 (char *) &fsf_req->qtcb->
4095 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4096 set_host_byte(&scpnt->result, DID_ERROR);
4097 goto skip_fsfstatus;
4098 case RSP_CODE_FIELD_INVALID:
4099 /* driver or hardware bug */
4100 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4101 "that the fibrechannel protocol data "
4102 "fields were incorrectly set up. "
4103 "The problem occured on the unit "
4104 "0x%016Lx on port 0x%016Lx on "
4108 zfcp_get_busid_by_unit(unit));
4109 /* dump SCSI CDB as prepared by zfcp */
4110 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4111 (char *) &fsf_req->qtcb->
4112 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4113 set_host_byte(&scpnt->result, DID_ERROR);
4114 goto skip_fsfstatus;
4115 case RSP_CODE_RO_MISMATCH:
4117 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4118 "that conflicting values for the "
4119 "fibrechannel payload offset from the "
4120 "header were found. "
4121 "The problem occured on unit 0x%016Lx "
4122 "on port 0x%016Lx on adapter %s.\n",
4125 zfcp_get_busid_by_unit(unit));
4126 /* dump SCSI CDB as prepared by zfcp */
4127 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4128 (char *) &fsf_req->qtcb->
4129 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4130 set_host_byte(&scpnt->result, DID_ERROR);
4131 goto skip_fsfstatus;
4133 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4134 "code was detected for a command. "
4135 "The problem occured on the unit "
4136 "0x%016Lx on port 0x%016Lx on "
4137 "adapter %s (debug info 0x%x)\n",
4140 zfcp_get_busid_by_unit(unit),
4142 /* dump SCSI CDB as prepared by zfcp */
4143 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4144 (char *) &fsf_req->qtcb->
4145 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4146 set_host_byte(&scpnt->result, DID_ERROR);
4147 goto skip_fsfstatus;
4151 /* check for sense data */
4152 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4153 sns_len = FSF_FCP_RSP_SIZE -
4154 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4155 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4157 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4158 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4159 SCSI_SENSE_BUFFERSIZE);
4160 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4161 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4163 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4164 (void *) &scpnt->cmnd, scpnt->cmd_len);
4166 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4167 fcp_rsp_iu->fcp_sns_len);
4168 memcpy(&scpnt->sense_buffer,
4169 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4170 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4171 (void *) &scpnt->sense_buffer, sns_len);
4174 /* check for overrun */
4175 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4176 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4177 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4178 "The response data length is "
4179 "%d, the original length was %d.\n",
4182 zfcp_get_busid_by_unit(unit),
4183 fcp_rsp_iu->fcp_resid,
4184 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4187 /* check for underrun */
4188 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4189 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4190 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4191 "The response data length is "
4192 "%d, the original length was %d.\n",
4195 zfcp_get_busid_by_unit(unit),
4196 fcp_rsp_iu->fcp_resid,
4197 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4199 scpnt->resid = fcp_rsp_iu->fcp_resid;
4200 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4201 set_host_byte(&scpnt->result, DID_ERROR);
4205 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4207 if (scpnt->result != 0)
4208 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4209 else if (scpnt->retries > 0)
4210 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4212 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
4214 /* cleanup pointer (need this especially for abort) */
4215 scpnt->host_scribble = NULL;
4217 /* always call back */
4218 (scpnt->scsi_done) (scpnt);
4221 * We must hold this lock until scsi_done has been called.
4222 * Otherwise we may call scsi_done after abort regarding this
4223 * command has completed.
4224 * Note: scsi_done must not block!
4227 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4232 * function: zfcp_fsf_send_fcp_command_task_management_handler
4234 * purpose: evaluates FCP_RSP IU
4239 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4242 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4243 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4244 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4245 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4247 del_timer(&fsf_req->adapter->scsi_er_timer);
4248 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4249 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4250 goto skip_fsfstatus;
4253 /* check FCP_RSP_INFO */
4254 switch (fcp_rsp_info[3]) {
4257 ZFCP_LOG_DEBUG("no failure or Task Management "
4258 "Function complete\n");
4260 case RSP_CODE_TASKMAN_UNSUPP:
4261 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4262 "is not supported on the target device "
4263 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4266 zfcp_get_busid_by_unit(unit));
4267 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4269 case RSP_CODE_TASKMAN_FAILED:
4270 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4271 "failed to complete successfully. "
4272 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4275 zfcp_get_busid_by_unit(unit));
4276 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4279 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4280 "code was detected for a command. "
4281 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4282 "(debug info 0x%x)\n",
4285 zfcp_get_busid_by_unit(unit),
4287 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4296 * function: zfcp_fsf_control_file
4298 * purpose: Initiator of the control file upload/download FSF requests
4300 * returns: 0 - FSF request is successfuly created and queued
4301 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4302 * -EINVAL - Invalid direction specified
4303 * -ENOMEM - Insufficient memory
4304 * -EPERM - Cannot create FSF request or place it in QDIO queue
4307 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4308 struct zfcp_fsf_req **fsf_req_ptr,
4311 struct zfcp_sg_list *sg_list)
4313 struct zfcp_fsf_req *fsf_req;
4314 struct fsf_qtcb_bottom_support *bottom;
4315 volatile struct qdio_buffer_element *sbale;
4316 struct timer_list *timer;
4317 unsigned long lock_flags;
4322 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4323 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4324 zfcp_get_busid_by_adapter(adapter));
4325 retval = -EOPNOTSUPP;
4329 switch (fsf_command) {
4331 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4332 direction = SBAL_FLAGS0_TYPE_WRITE;
4333 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4334 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4335 req_flags = ZFCP_WAIT_FOR_SBAL;
4338 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4339 direction = SBAL_FLAGS0_TYPE_READ;
4343 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4348 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4354 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4355 NULL, &lock_flags, &fsf_req);
4357 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4359 zfcp_get_busid_by_adapter(adapter));
4361 goto unlock_queue_lock;
4364 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4365 sbale[0].flags |= direction;
4367 bottom = &fsf_req->qtcb->bottom.support;
4368 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4369 bottom->option = option;
4371 if (sg_list->count > 0) {
4374 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4375 sg_list->sg, sg_list->count,
4376 ZFCP_MAX_SBALS_PER_REQ);
4377 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4379 "error: Could not create sufficient number of "
4380 "SBALS for an FSF request to the adapter %s\n",
4381 zfcp_get_busid_by_adapter(adapter));
4386 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4389 timer->function = zfcp_fsf_request_timeout_handler;
4390 timer->data = (unsigned long) adapter;
4391 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4393 retval = zfcp_fsf_req_send(fsf_req, timer);
4395 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4397 zfcp_get_busid_by_adapter(adapter));
4401 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4403 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4405 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4406 "download" : "upload",
4407 zfcp_get_busid_by_adapter(adapter));
4409 wait_event(fsf_req->completion_wq,
4410 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4412 *fsf_req_ptr = fsf_req;
4413 del_timer_sync(timer);
4417 zfcp_fsf_req_free(fsf_req);
4419 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4428 * function: zfcp_fsf_control_file_handler
4430 * purpose: Handler of the control file upload/download FSF requests
4432 * returns: 0 - FSF request successfuly processed
4433 * -EAGAIN - Operation has to be repeated because of a temporary problem
4434 * -EACCES - There is no permission to execute an operation
4435 * -EPERM - The control file is not in a right format
4436 * -EIO - There is a problem with the FCP adapter
4437 * -EINVAL - Invalid operation
4438 * -EFAULT - User space memory I/O operation fault
4441 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4443 struct zfcp_adapter *adapter = fsf_req->adapter;
4444 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4445 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4448 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4450 goto skip_fsfstatus;
4453 switch (header->fsf_status) {
4457 "The FSF request has been successfully completed "
4458 "on the adapter %s\n",
4459 zfcp_get_busid_by_adapter(adapter));
4462 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4463 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4464 switch (header->fsf_status_qual.word[0]) {
4466 case FSF_SQ_CFDC_HARDENED_ON_SE:
4468 "CFDC on the adapter %s has being "
4469 "hardened on primary and secondary SE\n",
4470 zfcp_get_busid_by_adapter(adapter));
4473 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4475 "CFDC of the adapter %s could not "
4476 "be saved on the SE\n",
4477 zfcp_get_busid_by_adapter(adapter));
4480 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4482 "CFDC of the adapter %s could not "
4483 "be copied to the secondary SE\n",
4484 zfcp_get_busid_by_adapter(adapter));
4489 "CFDC could not be hardened "
4490 "on the adapter %s\n",
4491 zfcp_get_busid_by_adapter(adapter));
4494 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4498 case FSF_AUTHORIZATION_FAILURE:
4500 "Adapter %s does not accept privileged commands\n",
4501 zfcp_get_busid_by_adapter(adapter));
4502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4506 case FSF_CFDC_ERROR_DETECTED:
4508 "Error at position %d in the CFDC, "
4509 "CFDC is discarded by the adapter %s\n",
4510 header->fsf_status_qual.word[0],
4511 zfcp_get_busid_by_adapter(adapter));
4512 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4516 case FSF_CONTROL_FILE_UPDATE_ERROR:
4518 "Adapter %s cannot harden the control file, "
4519 "file is discarded\n",
4520 zfcp_get_busid_by_adapter(adapter));
4521 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4525 case FSF_CONTROL_FILE_TOO_LARGE:
4527 "Control file is too large, file is discarded "
4528 "by the adapter %s\n",
4529 zfcp_get_busid_by_adapter(adapter));
4530 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4534 case FSF_ACCESS_CONFLICT_DETECTED:
4535 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4537 "CFDC has been discarded by the adapter %s, "
4538 "because activation would impact "
4539 "%d active connection(s)\n",
4540 zfcp_get_busid_by_adapter(adapter),
4541 header->fsf_status_qual.word[0]);
4542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4546 case FSF_CONFLICTS_OVERRULED:
4547 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4549 "CFDC has been activated on the adapter %s, "
4550 "but activation has impacted "
4551 "%d active connection(s)\n",
4552 zfcp_get_busid_by_adapter(adapter),
4553 header->fsf_status_qual.word[0]);
4554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4558 case FSF_UNKNOWN_OP_SUBTYPE:
4559 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4560 "op_subtype=0x%x)\n",
4561 zfcp_get_busid_by_adapter(adapter),
4562 bottom->operation_subtype);
4563 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4567 case FSF_INVALID_COMMAND_OPTION:
4569 "Invalid option 0x%x has been specified "
4570 "in QTCB bottom sent to the adapter %s\n",
4572 zfcp_get_busid_by_adapter(adapter));
4573 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4579 "bug: An unknown/unexpected FSF status 0x%08x "
4580 "was presented on the adapter %s\n",
4582 zfcp_get_busid_by_adapter(adapter));
4583 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4584 debug_exception(fsf_req->adapter->erp_dbf, 0,
4585 &header->fsf_status_qual.word[0], sizeof(u32));
4586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4596 zfcp_fsf_req_sbal_check(unsigned long *flags,
4597 struct zfcp_qdio_queue *queue, int needed)
4599 write_lock_irqsave(&queue->queue_lock, *flags);
4600 if (likely(atomic_read(&queue->free_count) >= needed))
4602 write_unlock_irqrestore(&queue->queue_lock, *flags);
4607 * set qtcb pointer in fsf_req and initialize QTCB
4610 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4612 if (likely(fsf_req->qtcb != NULL)) {
4613 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4614 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4615 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4616 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4617 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4618 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4619 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4624 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4625 * @adapter: adapter for which request queue is examined
4626 * @req_flags: flags indicating whether to wait for needed SBAL or not
4627 * @lock_flags: lock_flags if queue_lock is taken
4628 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4629 * Locks: lock adapter->request_queue->queue_lock on success
4632 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4633 unsigned long *lock_flags)
4636 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4638 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4639 ret = wait_event_interruptible_timeout(adapter->request_wq,
4640 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4646 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4653 * function: zfcp_fsf_req_create
4655 * purpose: create an FSF request at the specified adapter and
4656 * setup common fields
4658 * returns: -ENOMEM if there was insufficient memory for a request
4659 * -EIO if no qdio buffers could be allocate to the request
4660 * -EINVAL/-EPERM on bug conditions in req_dequeue
4663 * note: The created request is returned by reference.
4665 * locks: lock of concerned request queue must not be held,
4666 * but is held on completion (write, irqsave)
4669 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4670 mempool_t *pool, unsigned long *lock_flags,
4671 struct zfcp_fsf_req **fsf_req_p)
4673 volatile struct qdio_buffer_element *sbale;
4674 struct zfcp_fsf_req *fsf_req = NULL;
4676 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4678 /* allocate new FSF request */
4679 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4680 if (unlikely(NULL == fsf_req)) {
4681 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4682 "the outbound (send) queue.\n");
4684 goto failed_fsf_req;
4687 fsf_req->adapter = adapter;
4688 fsf_req->fsf_command = fsf_cmd;
4690 zfcp_fsf_req_qtcb_init(fsf_req);
4692 /* initialize waitqueue which may be used to wait on
4693 this request completion */
4694 init_waitqueue_head(&fsf_req->completion_wq);
4696 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4702 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4703 * if it is not set (see also *_open_qdio and *_close_qdio).
4706 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4707 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4712 if (fsf_req->qtcb) {
4713 fsf_req->seq_no = adapter->fsf_req_seq_no;
4714 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4716 fsf_req->sbal_number = 1;
4717 fsf_req->sbal_first = req_queue->free_index;
4718 fsf_req->sbal_curr = req_queue->free_index;
4719 fsf_req->sbale_curr = 1;
4721 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4722 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4725 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4727 /* setup common SBALE fields */
4728 sbale[0].addr = fsf_req;
4729 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4730 if (likely(fsf_req->qtcb != NULL)) {
4731 sbale[1].addr = (void *) fsf_req->qtcb;
4732 sbale[1].length = sizeof(struct fsf_qtcb);
4735 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4736 fsf_req->sbal_number, fsf_req->sbal_first);
4741 /* dequeue new FSF request previously enqueued */
4742 zfcp_fsf_req_free(fsf_req);
4746 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4748 *fsf_req_p = fsf_req;
4753 * function: zfcp_fsf_req_send
4755 * purpose: start transfer of FSF request via QDIO
4757 * returns: 0 - request transfer succesfully started
4758 * !0 - start of request transfer failed
4761 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4763 struct zfcp_adapter *adapter;
4764 struct zfcp_qdio_queue *req_queue;
4765 volatile struct qdio_buffer_element *sbale;
4767 int new_distance_from_int;
4768 unsigned long flags;
4771 adapter = fsf_req->adapter;
4772 req_queue = &adapter->request_queue,
4775 /* FIXME(debug): remove it later */
4776 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4777 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4778 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4779 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4782 /* put allocated FSF request at list tail */
4783 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4784 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4785 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4787 inc_seq_no = (fsf_req->qtcb != NULL);
4789 /* figure out expiration time of timeout and start timeout */
4790 if (unlikely(timer)) {
4791 timer->expires += jiffies;
4795 ZFCP_LOG_TRACE("request queue of adapter %s: "
4796 "next free SBAL is %i, %i free SBALs\n",
4797 zfcp_get_busid_by_adapter(adapter),
4798 req_queue->free_index,
4799 atomic_read(&req_queue->free_count));
4801 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4802 "index_in_queue=%i, count=%i, buffers=%p\n",
4803 zfcp_get_busid_by_adapter(adapter),
4804 QDIO_FLAG_SYNC_OUTPUT,
4805 0, fsf_req->sbal_first, fsf_req->sbal_number,
4806 &req_queue->buffer[fsf_req->sbal_first]);
4809 * adjust the number of free SBALs in request queue as well as
4810 * position of first one
4812 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4813 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4814 req_queue->free_index += fsf_req->sbal_number; /* increase */
4815 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4816 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4818 fsf_req->issued = get_clock();
4820 retval = do_QDIO(adapter->ccw_device,
4821 QDIO_FLAG_SYNC_OUTPUT,
4822 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4824 if (unlikely(retval)) {
4825 /* Queues are down..... */
4828 * FIXME(potential race):
4829 * timer might be expired (absolutely unlikely)
4833 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4834 list_del(&fsf_req->list);
4835 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4837 * adjust the number of free SBALs in request queue as well as
4838 * position of first one
4840 zfcp_qdio_zero_sbals(req_queue->buffer,
4841 fsf_req->sbal_first, fsf_req->sbal_number);
4842 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4843 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4844 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4845 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4847 ("error: do_QDIO failed. Buffers could not be enqueued "
4848 "to request queue.\n");
4850 req_queue->distance_from_int = new_distance_from_int;
4852 * increase FSF sequence counter -
4853 * this must only be done for request successfully enqueued to
4854 * QDIO this rejected requests may be cleaned up by calling
4855 * routines resulting in missing sequence counter values
4859 /* Don't increase for unsolicited status */
4861 adapter->fsf_req_seq_no++;
4863 /* count FSF requests pending */
4864 atomic_inc(&adapter->fsf_reqs_active);
4869 #undef ZFCP_LOG_AREA