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 switch (link_down->error_code) {
558 case FSF_PSQ_LINK_NO_LIGHT:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(no light detected)\n",
561 zfcp_get_busid_by_adapter(adapter));
563 case FSF_PSQ_LINK_WRAP_PLUG:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(wrap plug detected)\n",
566 zfcp_get_busid_by_adapter(adapter));
568 case FSF_PSQ_LINK_NO_FCP:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(adjacent node on link does not support FCP)\n",
571 zfcp_get_busid_by_adapter(adapter));
573 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
574 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
575 "(firmware update in progress)\n",
576 zfcp_get_busid_by_adapter(adapter));
578 case FSF_PSQ_LINK_INVALID_WWPN:
579 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
580 "(duplicate or invalid WWPN detected)\n",
581 zfcp_get_busid_by_adapter(adapter));
583 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(no support for NPIV by Fabric)\n",
586 zfcp_get_busid_by_adapter(adapter));
588 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
589 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
590 "(out of resource in FCP daughtercard)\n",
591 zfcp_get_busid_by_adapter(adapter));
593 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
594 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
595 "(out of resource in Fabric)\n",
596 zfcp_get_busid_by_adapter(adapter));
598 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
599 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
600 "(unable to Fabric login)\n",
601 zfcp_get_busid_by_adapter(adapter));
603 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
604 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
605 zfcp_get_busid_by_adapter(adapter));
607 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
608 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
609 zfcp_get_busid_by_adapter(adapter));
611 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
612 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
613 zfcp_get_busid_by_adapter(adapter));
616 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
617 "(warning: unknown reason code %d)\n",
618 zfcp_get_busid_by_adapter(adapter),
619 link_down->error_code);
622 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
623 ZFCP_LOG_DEBUG("Debug information to link down: "
624 "primary_status=0x%02x "
626 "action_code=0x%02x "
627 "reason_code=0x%02x "
628 "explanation_code=0x%02x "
629 "vendor_specific_code=0x%02x\n",
630 link_down->primary_status,
631 link_down->ioerr_code,
632 link_down->action_code,
633 link_down->reason_code,
634 link_down->explanation_code,
635 link_down->vendor_specific_code);
637 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
639 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
641 switch (link_down->error_code) {
642 case FSF_PSQ_LINK_NO_LIGHT:
643 case FSF_PSQ_LINK_WRAP_PLUG:
644 case FSF_PSQ_LINK_NO_FCP:
645 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
646 zfcp_erp_adapter_reopen(adapter, 0);
649 zfcp_erp_adapter_failed(adapter);
655 * function: zfcp_fsf_req_dispatch
657 * purpose: calls the appropriate command specific handler
662 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
664 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
665 struct zfcp_adapter *adapter = fsf_req->adapter;
669 switch (fsf_req->fsf_command) {
671 case FSF_QTCB_FCP_CMND:
672 zfcp_fsf_send_fcp_command_handler(fsf_req);
675 case FSF_QTCB_ABORT_FCP_CMND:
676 zfcp_fsf_abort_fcp_command_handler(fsf_req);
679 case FSF_QTCB_SEND_GENERIC:
680 zfcp_fsf_send_ct_handler(fsf_req);
683 case FSF_QTCB_OPEN_PORT_WITH_DID:
684 zfcp_fsf_open_port_handler(fsf_req);
687 case FSF_QTCB_OPEN_LUN:
688 zfcp_fsf_open_unit_handler(fsf_req);
691 case FSF_QTCB_CLOSE_LUN:
692 zfcp_fsf_close_unit_handler(fsf_req);
695 case FSF_QTCB_CLOSE_PORT:
696 zfcp_fsf_close_port_handler(fsf_req);
699 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
700 zfcp_fsf_close_physical_port_handler(fsf_req);
703 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
704 zfcp_fsf_exchange_config_data_handler(fsf_req);
707 case FSF_QTCB_EXCHANGE_PORT_DATA:
708 zfcp_fsf_exchange_port_data_handler(fsf_req);
711 case FSF_QTCB_SEND_ELS:
712 zfcp_fsf_send_els_handler(fsf_req);
715 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
716 zfcp_fsf_control_file_handler(fsf_req);
719 case FSF_QTCB_UPLOAD_CONTROL_FILE:
720 zfcp_fsf_control_file_handler(fsf_req);
724 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
725 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
726 "not supported by the adapter %s\n",
727 zfcp_get_busid_by_adapter(adapter));
728 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
730 ("bug: Command issued by the device driver differs "
731 "from the command returned by the adapter %s "
732 "(debug info 0x%x, 0x%x).\n",
733 zfcp_get_busid_by_adapter(adapter),
734 fsf_req->fsf_command,
735 fsf_req->qtcb->header.fsf_command);
741 zfcp_erp_async_handler(erp_action, 0);
747 * function: zfcp_fsf_status_read
749 * purpose: initiates a Status Read command at the specified adapter
754 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
756 struct zfcp_fsf_req *fsf_req;
757 struct fsf_status_read_buffer *status_buffer;
758 unsigned long lock_flags;
759 volatile struct qdio_buffer_element *sbale;
762 /* setup new FSF request */
763 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
764 req_flags | ZFCP_REQ_NO_QTCB,
765 adapter->pool.fsf_req_status_read,
766 &lock_flags, &fsf_req);
768 ZFCP_LOG_INFO("error: Could not create unsolicited status "
769 "buffer for adapter %s.\n",
770 zfcp_get_busid_by_adapter(adapter));
771 goto failed_req_create;
774 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
775 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
776 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
777 fsf_req->sbale_curr = 2;
780 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
781 if (!status_buffer) {
782 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
785 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
786 fsf_req->data = (unsigned long) status_buffer;
788 /* insert pointer to respective buffer */
789 sbale = zfcp_qdio_sbale_curr(fsf_req);
790 sbale->addr = (void *) status_buffer;
791 sbale->length = sizeof(struct fsf_status_read_buffer);
793 /* start QDIO request for this FSF request */
794 retval = zfcp_fsf_req_send(fsf_req, NULL);
796 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
798 goto failed_req_send;
801 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
802 zfcp_get_busid_by_adapter(adapter));
806 mempool_free(status_buffer, adapter->pool.data_status_read);
809 zfcp_fsf_req_free(fsf_req);
811 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
813 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
818 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
820 struct fsf_status_read_buffer *status_buffer;
821 struct zfcp_adapter *adapter;
822 struct zfcp_port *port;
825 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
826 adapter = fsf_req->adapter;
828 read_lock_irqsave(&zfcp_data.config_lock, flags);
829 list_for_each_entry(port, &adapter->port_list_head, list)
830 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
832 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
834 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
835 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
836 "nonexisting port with d_id 0x%08x on "
837 "adapter %s. Ignored.\n",
838 status_buffer->d_id & ZFCP_DID_MASK,
839 zfcp_get_busid_by_adapter(adapter));
843 switch (status_buffer->status_subtype) {
845 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
846 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
847 zfcp_erp_port_reopen(port, 0);
850 case FSF_STATUS_READ_SUB_ERROR_PORT:
851 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
852 zfcp_erp_port_shutdown(port, 0);
856 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
857 debug_exception(adapter->erp_dbf, 0,
858 &status_buffer->status_subtype, sizeof (u32));
859 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
860 "for a reopen indication on port with "
861 "d_id 0x%08x on the adapter %s. "
862 "Ignored. (debug info 0x%x)\n",
864 zfcp_get_busid_by_adapter(adapter),
865 status_buffer->status_subtype);
872 * function: zfcp_fsf_status_read_handler
874 * purpose: is called for finished Open Port command
879 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
882 struct zfcp_adapter *adapter = fsf_req->adapter;
883 struct fsf_status_read_buffer *status_buffer =
884 (struct fsf_status_read_buffer *) fsf_req->data;
886 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
887 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
888 mempool_free(status_buffer, adapter->pool.data_status_read);
889 zfcp_fsf_req_free(fsf_req);
893 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
895 switch (status_buffer->status_type) {
897 case FSF_STATUS_READ_PORT_CLOSED:
898 zfcp_fsf_status_read_port_closed(fsf_req);
901 case FSF_STATUS_READ_INCOMING_ELS:
902 zfcp_fsf_incoming_els(fsf_req);
905 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
906 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
907 zfcp_get_busid_by_adapter(adapter));
910 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
911 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
912 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
913 (char *) status_buffer,
914 sizeof (struct fsf_status_read_buffer));
917 case FSF_STATUS_READ_LINK_DOWN:
918 switch (status_buffer->status_subtype) {
919 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
920 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
921 zfcp_get_busid_by_adapter(adapter));
923 case FSF_STATUS_READ_SUB_FDISC_FAILED:
924 ZFCP_LOG_INFO("Local link to adapter %s is down "
925 "due to failed FDISC login\n",
926 zfcp_get_busid_by_adapter(adapter));
928 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
929 ZFCP_LOG_INFO("Local link to adapter %s is down "
930 "due to firmware update on adapter\n",
931 zfcp_get_busid_by_adapter(adapter));
934 ZFCP_LOG_INFO("Local link to adapter %s is down "
935 "due to unknown reason\n",
936 zfcp_get_busid_by_adapter(adapter));
938 zfcp_fsf_link_down_info_eval(adapter,
939 (struct fsf_link_down_info *) &status_buffer->payload);
942 case FSF_STATUS_READ_LINK_UP:
943 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
944 "Restarting operations on this adapter\n",
945 zfcp_get_busid_by_adapter(adapter));
946 /* All ports should be marked as ready to run again */
947 zfcp_erp_modify_adapter_status(adapter,
948 ZFCP_STATUS_COMMON_RUNNING,
950 zfcp_erp_adapter_reopen(adapter,
951 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
952 | ZFCP_STATUS_COMMON_ERP_FAILED);
955 case FSF_STATUS_READ_CFDC_UPDATED:
956 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
957 zfcp_get_busid_by_adapter(adapter));
958 zfcp_erp_adapter_access_changed(adapter);
961 case FSF_STATUS_READ_CFDC_HARDENED:
962 switch (status_buffer->status_subtype) {
963 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
964 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
965 zfcp_get_busid_by_adapter(adapter));
967 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
968 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
969 "to the secondary SE\n",
970 zfcp_get_busid_by_adapter(adapter));
973 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
974 zfcp_get_busid_by_adapter(adapter));
978 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
979 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
980 ZFCP_LOG_INFO("List of supported features on adapter %s has "
981 "been changed from 0x%08X to 0x%08X\n",
982 zfcp_get_busid_by_adapter(adapter),
983 *(u32*) (status_buffer->payload + 4),
984 *(u32*) (status_buffer->payload));
985 adapter->adapter_features = *(u32*) status_buffer->payload;
989 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
990 "type was received (debug info 0x%x)\n",
991 status_buffer->status_type);
992 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
994 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
995 (char *) status_buffer,
996 sizeof (struct fsf_status_read_buffer));
999 mempool_free(status_buffer, adapter->pool.data_status_read);
1000 zfcp_fsf_req_free(fsf_req);
1002 * recycle buffer and start new request repeat until outbound
1003 * queue is empty or adapter shutdown is requested
1007 * we may wait in the req_create for 5s during shutdown, so
1008 * qdio_cleanup will have to wait at least that long before returning
1009 * with failure to allow us a proper cleanup under all circumstances
1013 * allocation failure possible? (Is this code needed?)
1015 retval = zfcp_fsf_status_read(adapter, 0);
1017 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1018 "request for the adapter %s.\n",
1019 zfcp_get_busid_by_adapter(adapter));
1020 /* temporary fix to avoid status read buffer shortage */
1021 adapter->status_read_failed++;
1022 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1023 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1024 ZFCP_LOG_INFO("restart adapter %s due to status read "
1025 "buffer shortage\n",
1026 zfcp_get_busid_by_adapter(adapter));
1027 zfcp_erp_adapter_reopen(adapter, 0);
1035 * function: zfcp_fsf_abort_fcp_command
1037 * purpose: tells FSF to abort a running SCSI command
1039 * returns: address of initiated FSF request
1040 * NULL - request could not be initiated
1042 * FIXME(design): should be watched by a timeout !!!
1043 * FIXME(design) shouldn't this be modified to return an int
1044 * also...don't know how though
1046 struct zfcp_fsf_req *
1047 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1048 struct zfcp_adapter *adapter,
1049 struct zfcp_unit *unit, int req_flags)
1051 volatile struct qdio_buffer_element *sbale;
1052 unsigned long lock_flags;
1053 struct zfcp_fsf_req *fsf_req = NULL;
1056 /* setup new FSF request */
1057 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1058 req_flags, adapter->pool.fsf_req_abort,
1059 &lock_flags, &fsf_req);
1061 ZFCP_LOG_INFO("error: Failed to create an abort command "
1062 "request for lun 0x%016Lx on port 0x%016Lx "
1066 zfcp_get_busid_by_adapter(adapter));
1070 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1071 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1072 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1074 fsf_req->data = (unsigned long) unit;
1076 /* set handles of unit and its parent port in QTCB */
1077 fsf_req->qtcb->header.lun_handle = unit->handle;
1078 fsf_req->qtcb->header.port_handle = unit->port->handle;
1080 /* set handle of request which should be aborted */
1081 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1083 /* start QDIO request for this FSF request */
1085 zfcp_fsf_start_scsi_er_timer(adapter);
1086 retval = zfcp_fsf_req_send(fsf_req, NULL);
1088 del_timer(&adapter->scsi_er_timer);
1089 ZFCP_LOG_INFO("error: Failed to send abort command request "
1090 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1091 zfcp_get_busid_by_adapter(adapter),
1092 unit->port->wwpn, unit->fcp_lun);
1093 zfcp_fsf_req_free(fsf_req);
1098 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1099 "(adapter%s, port d_id=0x%08x, "
1100 "unit x%016Lx, old_req_id=0x%lx)\n",
1101 zfcp_get_busid_by_adapter(adapter),
1103 unit->fcp_lun, old_req_id);
1105 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1110 * function: zfcp_fsf_abort_fcp_command_handler
1112 * purpose: is called for finished Abort FCP Command request
1117 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1119 int retval = -EINVAL;
1120 struct zfcp_unit *unit;
1121 unsigned char status_qual =
1122 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1124 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1126 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1127 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1128 goto skip_fsfstatus;
1131 unit = (struct zfcp_unit *) new_fsf_req->data;
1133 /* evaluate FSF status in QTCB */
1134 switch (new_fsf_req->qtcb->header.fsf_status) {
1136 case FSF_PORT_HANDLE_NOT_VALID:
1137 if (status_qual >> 4 != status_qual % 0xf) {
1138 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1141 * In this case a command that was sent prior to a port
1142 * reopen was aborted (handles are different). This is
1146 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1147 "port 0x%016Lx on adapter %s invalid. "
1148 "This may happen occasionally.\n",
1151 zfcp_get_busid_by_unit(unit));
1152 ZFCP_LOG_INFO("status qualifier:\n");
1153 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1154 (char *) &new_fsf_req->qtcb->header.
1156 sizeof (union fsf_status_qual));
1157 /* Let's hope this sorts out the mess */
1158 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1160 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1161 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1165 case FSF_LUN_HANDLE_NOT_VALID:
1166 if (status_qual >> 4 != status_qual % 0xf) {
1168 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1171 * In this case a command that was sent prior to a unit
1172 * reopen was aborted (handles are different).
1177 ("Warning: Temporary LUN identifier 0x%x of LUN "
1178 "0x%016Lx on port 0x%016Lx on adapter %s is "
1179 "invalid. This may happen in rare cases. "
1180 "Trying to re-establish link.\n",
1184 zfcp_get_busid_by_unit(unit));
1185 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1186 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1187 (char *) &new_fsf_req->qtcb->header.
1189 sizeof (union fsf_status_qual));
1190 /* Let's hope this sorts out the mess */
1191 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1193 zfcp_erp_port_reopen(unit->port, 0);
1194 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1198 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1200 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1202 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1205 case FSF_PORT_BOXED:
1206 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1207 "be reopened\n", unit->port->wwpn,
1208 zfcp_get_busid_by_unit(unit));
1209 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1211 zfcp_erp_port_boxed(unit->port);
1212 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1213 | ZFCP_STATUS_FSFREQ_RETRY;
1218 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1220 unit->fcp_lun, unit->port->wwpn,
1221 zfcp_get_busid_by_unit(unit));
1222 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1223 zfcp_erp_unit_boxed(unit);
1224 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1225 | ZFCP_STATUS_FSFREQ_RETRY;
1228 case FSF_ADAPTER_STATUS_AVAILABLE:
1229 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1230 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1231 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1233 zfcp_test_link(unit->port);
1234 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1236 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1237 /* SCSI stack will escalate */
1238 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1240 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1244 ("bug: Wrong status qualifier 0x%x arrived.\n",
1245 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1246 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1248 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1249 &new_fsf_req->qtcb->header.
1250 fsf_status_qual.word[0], sizeof (u32));
1257 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1261 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1262 "(debug info 0x%x)\n",
1263 new_fsf_req->qtcb->header.fsf_status);
1264 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1266 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1267 &new_fsf_req->qtcb->header.fsf_status,
1276 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1278 * Two scatter-gather lists are passed, one for the reqeust and one for the
1282 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1283 struct scatterlist *resp, int resp_count)
1285 return ((req_count == 1) &&
1286 (resp_count == 1) &&
1287 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1289 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1290 req[0].length - 1) & PAGE_MASK)) &&
1291 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1293 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1294 resp[0].length - 1) & PAGE_MASK)));
1298 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1299 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1301 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1302 * a struct zfcp_fsf_req
1303 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1304 * is sent within error recovery
1307 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1308 struct zfcp_erp_action *erp_action)
1310 volatile struct qdio_buffer_element *sbale;
1311 struct zfcp_port *port;
1312 struct zfcp_adapter *adapter;
1313 struct zfcp_fsf_req *fsf_req;
1314 unsigned long lock_flags;
1319 adapter = port->adapter;
1321 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1322 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1323 pool, &lock_flags, &fsf_req);
1325 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1327 zfcp_get_busid_by_adapter(adapter));
1331 if (erp_action != NULL) {
1332 erp_action->fsf_req = fsf_req;
1333 fsf_req->erp_action = erp_action;
1336 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1337 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1338 ct->resp, ct->resp_count)){
1339 /* both request buffer and response buffer
1340 fit into one sbale each */
1341 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1342 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1343 sbale[2].length = ct->req[0].length;
1344 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1345 sbale[3].length = ct->resp[0].length;
1346 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1347 } else if (adapter->adapter_features &
1348 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1349 /* try to use chained SBALs */
1350 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1351 SBAL_FLAGS0_TYPE_WRITE_READ,
1352 ct->req, ct->req_count,
1353 ZFCP_MAX_SBALS_PER_CT_REQ);
1355 ZFCP_LOG_INFO("error: creation of CT request failed "
1357 zfcp_get_busid_by_adapter(adapter));
1365 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1366 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1367 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1368 SBAL_FLAGS0_TYPE_WRITE_READ,
1369 ct->resp, ct->resp_count,
1370 ZFCP_MAX_SBALS_PER_CT_REQ);
1372 ZFCP_LOG_INFO("error: creation of CT request failed "
1374 zfcp_get_busid_by_adapter(adapter));
1382 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1384 /* reject send generic request */
1386 "error: microcode does not support chained SBALs,"
1387 "CT request too big (adapter %s)\n",
1388 zfcp_get_busid_by_adapter(adapter));
1393 /* settings in QTCB */
1394 fsf_req->qtcb->header.port_handle = port->handle;
1395 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1396 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1397 fsf_req->data = (unsigned long) ct;
1399 zfcp_san_dbf_event_ct_request(fsf_req);
1401 /* start QDIO request for this FSF request */
1402 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1404 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1405 "(adapter %s, port 0x%016Lx)\n",
1406 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1410 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1411 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1415 zfcp_fsf_req_free(fsf_req);
1416 if (erp_action != NULL) {
1417 erp_action->fsf_req = NULL;
1421 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1427 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1428 * @fsf_req: pointer to struct zfcp_fsf_req
1430 * Data specific for the Generic Service request is passed using
1431 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1432 * Usually a specific handler for the CT request is called which is
1433 * found in this structure.
1436 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1438 struct zfcp_port *port;
1439 struct zfcp_adapter *adapter;
1440 struct zfcp_send_ct *send_ct;
1441 struct fsf_qtcb_header *header;
1442 struct fsf_qtcb_bottom_support *bottom;
1443 int retval = -EINVAL;
1444 u16 subtable, rule, counter;
1446 adapter = fsf_req->adapter;
1447 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1448 port = send_ct->port;
1449 header = &fsf_req->qtcb->header;
1450 bottom = &fsf_req->qtcb->bottom.support;
1452 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1453 goto skip_fsfstatus;
1455 /* evaluate FSF status in QTCB */
1456 switch (header->fsf_status) {
1459 zfcp_san_dbf_event_ct_response(fsf_req);
1463 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1464 if (adapter->fc_service_class <= 3) {
1465 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1467 zfcp_get_busid_by_port(port),
1468 adapter->fc_service_class);
1470 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1471 "adapter %s is invalid. "
1472 "(debug info %d)\n",
1473 zfcp_get_busid_by_port(port),
1474 adapter->fc_service_class);
1476 /* stop operation for this adapter */
1477 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1478 zfcp_erp_adapter_shutdown(adapter, 0);
1479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1482 case FSF_ADAPTER_STATUS_AVAILABLE:
1483 switch (header->fsf_status_qual.word[0]){
1484 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1485 /* reopening link to port */
1486 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1487 zfcp_test_link(port);
1488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1490 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1491 /* ERP strategy will escalate */
1492 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1493 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1496 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1498 header->fsf_status_qual.word[0]);
1503 case FSF_ACCESS_DENIED:
1504 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1505 "command (adapter %s, port d_id=0x%08x)\n",
1506 zfcp_get_busid_by_port(port), port->d_id);
1507 for (counter = 0; counter < 2; counter++) {
1508 subtable = header->fsf_status_qual.halfword[counter * 2];
1509 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1511 case FSF_SQ_CFDC_SUBTABLE_OS:
1512 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1513 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1514 case FSF_SQ_CFDC_SUBTABLE_LUN:
1515 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1516 zfcp_act_subtable_type[subtable], rule);
1520 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1521 zfcp_erp_port_access_denied(port);
1522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1525 case FSF_GENERIC_COMMAND_REJECTED:
1526 ZFCP_LOG_INFO("generic service command rejected "
1527 "(adapter %s, port d_id=0x%08x)\n",
1528 zfcp_get_busid_by_port(port), port->d_id);
1529 ZFCP_LOG_INFO("status qualifier:\n");
1530 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1531 (char *) &header->fsf_status_qual,
1532 sizeof (union fsf_status_qual));
1533 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1537 case FSF_PORT_HANDLE_NOT_VALID:
1538 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1539 "0x%016Lx on adapter %s invalid. This may "
1540 "happen occasionally.\n", port->handle,
1541 port->wwpn, zfcp_get_busid_by_port(port));
1542 ZFCP_LOG_INFO("status qualifier:\n");
1543 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1544 (char *) &header->fsf_status_qual,
1545 sizeof (union fsf_status_qual));
1546 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1547 zfcp_erp_adapter_reopen(adapter, 0);
1548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1551 case FSF_PORT_BOXED:
1552 ZFCP_LOG_INFO("port needs to be reopened "
1553 "(adapter %s, port d_id=0x%08x)\n",
1554 zfcp_get_busid_by_port(port), port->d_id);
1555 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1556 zfcp_erp_port_boxed(port);
1557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1558 | ZFCP_STATUS_FSFREQ_RETRY;
1561 /* following states should never occure, all cases avoided
1562 in zfcp_fsf_send_ct - but who knows ... */
1563 case FSF_PAYLOAD_SIZE_MISMATCH:
1564 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1565 "req_buf_length=%d, resp_buf_length=%d)\n",
1566 zfcp_get_busid_by_adapter(adapter),
1567 bottom->req_buf_length, bottom->resp_buf_length);
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1570 case FSF_REQUEST_SIZE_TOO_LARGE:
1571 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1572 "req_buf_length=%d)\n",
1573 zfcp_get_busid_by_adapter(adapter),
1574 bottom->req_buf_length);
1575 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1577 case FSF_RESPONSE_SIZE_TOO_LARGE:
1578 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1579 "resp_buf_length=%d)\n",
1580 zfcp_get_busid_by_adapter(adapter),
1581 bottom->resp_buf_length);
1582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1584 case FSF_SBAL_MISMATCH:
1585 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1586 "resp_buf_length=%d)\n",
1587 zfcp_get_busid_by_adapter(adapter),
1588 bottom->req_buf_length, bottom->resp_buf_length);
1589 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1593 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1594 "(debug info 0x%x)\n", header->fsf_status);
1595 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1596 debug_exception(adapter->erp_dbf, 0,
1597 &header->fsf_status_qual.word[0], sizeof (u32));
1602 send_ct->status = retval;
1604 if (send_ct->handler != NULL)
1605 send_ct->handler(send_ct->handler_data);
1611 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1612 * @els: pointer to struct zfcp_send_els which contains all needed data for
1616 zfcp_fsf_send_els(struct zfcp_send_els *els)
1618 volatile struct qdio_buffer_element *sbale;
1619 struct zfcp_fsf_req *fsf_req;
1621 struct zfcp_adapter *adapter;
1622 unsigned long lock_flags;
1627 adapter = els->adapter;
1629 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1630 ZFCP_REQ_AUTO_CLEANUP,
1631 NULL, &lock_flags, &fsf_req);
1633 ZFCP_LOG_INFO("error: creation of ELS request failed "
1634 "(adapter %s, port d_id: 0x%08x)\n",
1635 zfcp_get_busid_by_adapter(adapter), d_id);
1639 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1640 if (zfcp_use_one_sbal(els->req, els->req_count,
1641 els->resp, els->resp_count)){
1642 /* both request buffer and response buffer
1643 fit into one sbale each */
1644 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1645 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1646 sbale[2].length = els->req[0].length;
1647 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1648 sbale[3].length = els->resp[0].length;
1649 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1650 } else if (adapter->adapter_features &
1651 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1652 /* try to use chained SBALs */
1653 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1654 SBAL_FLAGS0_TYPE_WRITE_READ,
1655 els->req, els->req_count,
1656 ZFCP_MAX_SBALS_PER_ELS_REQ);
1658 ZFCP_LOG_INFO("error: creation of ELS request failed "
1659 "(adapter %s, port d_id: 0x%08x)\n",
1660 zfcp_get_busid_by_adapter(adapter), d_id);
1668 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1669 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1670 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1671 SBAL_FLAGS0_TYPE_WRITE_READ,
1672 els->resp, els->resp_count,
1673 ZFCP_MAX_SBALS_PER_ELS_REQ);
1675 ZFCP_LOG_INFO("error: creation of ELS request failed "
1676 "(adapter %s, port d_id: 0x%08x)\n",
1677 zfcp_get_busid_by_adapter(adapter), d_id);
1685 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1687 /* reject request */
1688 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1689 ", ELS request too big (adapter %s, "
1690 "port d_id: 0x%08x)\n",
1691 zfcp_get_busid_by_adapter(adapter), d_id);
1696 /* settings in QTCB */
1697 fsf_req->qtcb->bottom.support.d_id = d_id;
1698 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1699 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1700 fsf_req->data = (unsigned long) els;
1702 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1704 zfcp_san_dbf_event_els_request(fsf_req);
1706 /* start QDIO request for this FSF request */
1707 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1709 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1710 "(adapter %s, port d_id: 0x%08x)\n",
1711 zfcp_get_busid_by_adapter(adapter), d_id);
1715 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1716 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1720 zfcp_fsf_req_free(fsf_req);
1724 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1731 * zfcp_fsf_send_els_handler - handler for ELS commands
1732 * @fsf_req: pointer to struct zfcp_fsf_req
1734 * Data specific for the ELS command is passed using
1735 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1736 * Usually a specific handler for the ELS command is called which is
1737 * found in this structure.
1739 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1741 struct zfcp_adapter *adapter;
1742 struct zfcp_port *port;
1744 struct fsf_qtcb_header *header;
1745 struct fsf_qtcb_bottom_support *bottom;
1746 struct zfcp_send_els *send_els;
1747 int retval = -EINVAL;
1748 u16 subtable, rule, counter;
1750 send_els = (struct zfcp_send_els *) fsf_req->data;
1751 adapter = send_els->adapter;
1752 port = send_els->port;
1753 d_id = send_els->d_id;
1754 header = &fsf_req->qtcb->header;
1755 bottom = &fsf_req->qtcb->bottom.support;
1757 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1758 goto skip_fsfstatus;
1760 switch (header->fsf_status) {
1763 zfcp_san_dbf_event_els_response(fsf_req);
1767 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1768 if (adapter->fc_service_class <= 3) {
1769 ZFCP_LOG_INFO("error: adapter %s does "
1770 "not support fibrechannel class %d.\n",
1771 zfcp_get_busid_by_adapter(adapter),
1772 adapter->fc_service_class);
1774 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1775 "adapter %s is invalid. "
1776 "(debug info %d)\n",
1777 zfcp_get_busid_by_adapter(adapter),
1778 adapter->fc_service_class);
1780 /* stop operation for this adapter */
1781 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1782 zfcp_erp_adapter_shutdown(adapter, 0);
1783 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1786 case FSF_ADAPTER_STATUS_AVAILABLE:
1787 switch (header->fsf_status_qual.word[0]){
1788 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1789 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1790 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1791 zfcp_test_link(port);
1792 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1794 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1795 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1798 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1799 (struct zfcp_ls_rjt_par *)
1800 &header->fsf_status_qual.word[2]);
1802 case FSF_SQ_RETRY_IF_POSSIBLE:
1803 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1804 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1807 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1808 header->fsf_status_qual.word[0]);
1809 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1810 (char*)header->fsf_status_qual.word, 16);
1814 case FSF_ELS_COMMAND_REJECTED:
1815 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1816 "prohibited sending "
1817 "(adapter: %s, port d_id: 0x%08x)\n",
1818 zfcp_get_busid_by_adapter(adapter), d_id);
1822 case FSF_PAYLOAD_SIZE_MISMATCH:
1824 "ELS request size and ELS response size must be either "
1825 "both 0, or both greater than 0 "
1826 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1827 zfcp_get_busid_by_adapter(adapter),
1828 bottom->req_buf_length,
1829 bottom->resp_buf_length);
1832 case FSF_REQUEST_SIZE_TOO_LARGE:
1834 "Length of the ELS request buffer, "
1835 "specified in QTCB bottom, "
1836 "exceeds the size of the buffers "
1837 "that have been allocated for ELS request data "
1838 "(adapter: %s, req_buf_length=%d)\n",
1839 zfcp_get_busid_by_adapter(adapter),
1840 bottom->req_buf_length);
1843 case FSF_RESPONSE_SIZE_TOO_LARGE:
1845 "Length of the ELS response buffer, "
1846 "specified in QTCB bottom, "
1847 "exceeds the size of the buffers "
1848 "that have been allocated for ELS response data "
1849 "(adapter: %s, resp_buf_length=%d)\n",
1850 zfcp_get_busid_by_adapter(adapter),
1851 bottom->resp_buf_length);
1854 case FSF_SBAL_MISMATCH:
1855 /* should never occure, avoided in zfcp_fsf_send_els */
1856 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1857 "resp_buf_length=%d)\n",
1858 zfcp_get_busid_by_adapter(adapter),
1859 bottom->req_buf_length, bottom->resp_buf_length);
1860 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1863 case FSF_ACCESS_DENIED:
1864 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1865 "(adapter %s, port d_id=0x%08x)\n",
1866 zfcp_get_busid_by_adapter(adapter), d_id);
1867 for (counter = 0; counter < 2; counter++) {
1868 subtable = header->fsf_status_qual.halfword[counter * 2];
1869 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1871 case FSF_SQ_CFDC_SUBTABLE_OS:
1872 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1873 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1874 case FSF_SQ_CFDC_SUBTABLE_LUN:
1875 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1876 zfcp_act_subtable_type[subtable], rule);
1880 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1882 zfcp_erp_port_access_denied(port);
1883 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1888 "bug: An unknown FSF Status was presented "
1889 "(adapter: %s, fsf_status=0x%08x)\n",
1890 zfcp_get_busid_by_adapter(adapter),
1891 header->fsf_status);
1892 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1893 debug_exception(adapter->erp_dbf, 0,
1894 &header->fsf_status_qual.word[0], sizeof(u32));
1895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1900 send_els->status = retval;
1902 if (send_els->handler != 0)
1903 send_els->handler(send_els->handler_data);
1913 * returns: address of initiated FSF request
1914 * NULL - request could not be initiated
1917 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1919 volatile struct qdio_buffer_element *sbale;
1920 unsigned long lock_flags;
1923 /* setup new FSF request */
1924 retval = zfcp_fsf_req_create(erp_action->adapter,
1925 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1926 ZFCP_REQ_AUTO_CLEANUP,
1927 erp_action->adapter->pool.fsf_req_erp,
1928 &lock_flags, &(erp_action->fsf_req));
1930 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1931 "data request for adapter %s.\n",
1932 zfcp_get_busid_by_adapter(erp_action->adapter));
1936 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1937 erp_action->fsf_req->sbal_curr, 0);
1938 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1939 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1941 erp_action->fsf_req->erp_action = erp_action;
1942 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1944 FSF_FEATURE_LUN_SHARING |
1945 FSF_FEATURE_UPDATE_ALERT;
1947 /* start QDIO request for this FSF request */
1948 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1951 ("error: Could not send exchange configuration data "
1952 "command on the adapter %s\n",
1953 zfcp_get_busid_by_adapter(erp_action->adapter));
1954 zfcp_fsf_req_free(erp_action->fsf_req);
1955 erp_action->fsf_req = NULL;
1959 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1961 zfcp_get_busid_by_adapter(erp_action->adapter));
1964 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
1970 * zfcp_fsf_exchange_config_evaluate
1971 * @fsf_req: fsf_req which belongs to xchg config data request
1972 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1974 * returns: -EIO on error, 0 otherwise
1977 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1979 struct fsf_qtcb_bottom_config *bottom;
1980 struct zfcp_adapter *adapter = fsf_req->adapter;
1981 struct Scsi_Host *shost = adapter->scsi_host;
1983 bottom = &fsf_req->qtcb->bottom.config;
1984 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1985 bottom->low_qtcb_version, bottom->high_qtcb_version);
1986 adapter->fsf_lic_version = bottom->lic_version;
1987 adapter->adapter_features = bottom->adapter_features;
1988 adapter->connection_features = bottom->connection_features;
1989 adapter->peer_wwpn = 0;
1990 adapter->peer_wwnn = 0;
1991 adapter->peer_d_id = 0;
1994 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
1995 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
1996 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
1997 fc_host_speed(shost) = bottom->fc_link_speed;
1998 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
1999 adapter->fc_topology = bottom->fc_topology;
2000 adapter->hydra_version = bottom->adapter_type;
2001 if (adapter->physical_wwpn == 0)
2002 adapter->physical_wwpn = fc_host_port_name(shost);
2003 if (adapter->physical_s_id == 0)
2004 adapter->physical_s_id = fc_host_port_id(shost);
2006 fc_host_node_name(shost) = 0;
2007 fc_host_port_name(shost) = 0;
2008 fc_host_port_id(shost) = 0;
2009 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2010 adapter->fc_topology = 0;
2011 adapter->hydra_version = 0;
2014 if (adapter->fc_topology == FSF_TOPO_P2P) {
2015 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2016 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2017 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2020 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2021 adapter->hardware_version = bottom->hardware_version;
2022 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2023 min(FC_SERIAL_NUMBER_SIZE, 17));
2024 EBCASC(fc_host_serial_number(shost),
2025 min(FC_SERIAL_NUMBER_SIZE, 17));
2028 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2032 "adapter version 0x%x, "
2033 "LIC version 0x%x, "
2034 "FC link speed %d Gb/s\n",
2035 zfcp_get_busid_by_adapter(adapter),
2036 (wwn_t) fc_host_node_name(shost),
2037 (wwn_t) fc_host_port_name(shost),
2038 fc_host_port_id(shost),
2039 adapter->hydra_version,
2040 adapter->fsf_lic_version,
2041 fc_host_speed(shost));
2042 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2043 ZFCP_LOG_NORMAL("error: the adapter %s "
2044 "only supports newer control block "
2045 "versions in comparison to this device "
2046 "driver (try updated device driver)\n",
2047 zfcp_get_busid_by_adapter(adapter));
2048 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2049 zfcp_erp_adapter_shutdown(adapter, 0);
2052 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2053 ZFCP_LOG_NORMAL("error: the adapter %s "
2054 "only supports older control block "
2055 "versions than this device driver uses"
2056 "(consider a microcode upgrade)\n",
2057 zfcp_get_busid_by_adapter(adapter));
2058 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2059 zfcp_erp_adapter_shutdown(adapter, 0);
2066 * function: zfcp_fsf_exchange_config_data_handler
2068 * purpose: is called for finished Exchange Configuration Data command
2073 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2075 struct fsf_qtcb_bottom_config *bottom;
2076 struct zfcp_adapter *adapter = fsf_req->adapter;
2077 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2079 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2082 switch (qtcb->header.fsf_status) {
2085 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2088 switch (adapter->fc_topology) {
2090 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2091 "configuration detected at adapter %s\n"
2092 "Peer WWNN 0x%016llx, "
2093 "peer WWPN 0x%016llx, "
2094 "peer d_id 0x%06x\n",
2095 zfcp_get_busid_by_adapter(adapter),
2098 adapter->peer_d_id);
2099 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2103 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2104 "topology detected at adapter %s "
2105 "unsupported, shutting down adapter\n",
2106 zfcp_get_busid_by_adapter(adapter));
2107 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2109 zfcp_erp_adapter_shutdown(adapter, 0);
2111 case FSF_TOPO_FABRIC:
2112 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2113 "network detected at adapter %s.\n",
2114 zfcp_get_busid_by_adapter(adapter));
2117 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2118 "reported by the exchange "
2119 "configuration command for "
2120 "the adapter %s is not "
2121 "of a type known to the zfcp "
2122 "driver, shutting down adapter\n",
2123 zfcp_get_busid_by_adapter(adapter));
2124 adapter->fc_topology = FSF_TOPO_ERROR;
2125 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2127 zfcp_erp_adapter_shutdown(adapter, 0);
2130 bottom = &qtcb->bottom.config;
2131 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2132 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2133 "allowed by the adapter %s "
2134 "is lower than the minimum "
2135 "required by the driver (%ld bytes).\n",
2136 bottom->max_qtcb_size,
2137 zfcp_get_busid_by_adapter(adapter),
2138 sizeof(struct fsf_qtcb));
2139 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2141 debug_event(fsf_req->adapter->erp_dbf, 0,
2142 &bottom->max_qtcb_size, sizeof (u32));
2143 zfcp_erp_adapter_shutdown(adapter, 0);
2146 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2149 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2150 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2152 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2155 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2157 zfcp_fsf_link_down_info_eval(adapter,
2158 &qtcb->header.fsf_status_qual.link_down_info);
2161 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2162 debug_event(fsf_req->adapter->erp_dbf, 0,
2163 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2164 zfcp_erp_adapter_shutdown(adapter, 0);
2171 * zfcp_fsf_exchange_port_data - request information about local port
2172 * @erp_action: ERP action for the adapter for which port data is requested
2173 * @adapter: for which port data is requested
2174 * @data: response to exchange port data request
2177 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2178 struct zfcp_adapter *adapter,
2179 struct fsf_qtcb_bottom_port *data)
2181 volatile struct qdio_buffer_element *sbale;
2183 unsigned long lock_flags;
2184 struct zfcp_fsf_req *fsf_req;
2185 struct timer_list *timer;
2187 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2188 ZFCP_LOG_INFO("error: exchange port data "
2189 "command not supported by adapter %s\n",
2190 zfcp_get_busid_by_adapter(adapter));
2194 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2198 /* setup new FSF request */
2199 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2200 0, 0, &lock_flags, &fsf_req);
2202 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2203 "exchange port data request for"
2204 "the adapter %s.\n",
2205 zfcp_get_busid_by_adapter(adapter));
2206 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2212 erp_action->fsf_req = fsf_req;
2213 fsf_req->erp_action = erp_action;
2217 fsf_req->data = (unsigned long) data;
2219 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2220 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2221 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2224 timer->function = zfcp_fsf_request_timeout_handler;
2225 timer->data = (unsigned long) adapter;
2226 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2228 retval = zfcp_fsf_req_send(fsf_req, timer);
2230 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2231 "command on the adapter %s\n",
2232 zfcp_get_busid_by_adapter(adapter));
2233 zfcp_fsf_req_free(fsf_req);
2235 erp_action->fsf_req = NULL;
2236 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2241 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2242 zfcp_get_busid_by_adapter(adapter));
2244 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2247 wait_event(fsf_req->completion_wq,
2248 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2249 del_timer_sync(timer);
2250 zfcp_fsf_req_free(fsf_req);
2258 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2259 * @fsf_req: pointer to struct zfcp_fsf_req
2262 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2264 struct zfcp_adapter *adapter = fsf_req->adapter;
2265 struct Scsi_Host *shost = adapter->scsi_host;
2266 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2267 struct fsf_qtcb_bottom_port *bottom, *data;
2269 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2272 switch (qtcb->header.fsf_status) {
2274 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2276 bottom = &qtcb->bottom.port;
2277 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2279 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2280 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
2281 adapter->physical_wwpn = bottom->wwpn;
2282 adapter->physical_s_id = bottom->fc_port_id;
2284 adapter->physical_wwpn = fc_host_port_name(shost);
2285 adapter->physical_s_id = fc_host_port_id(shost);
2287 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2290 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2291 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2293 zfcp_fsf_link_down_info_eval(adapter,
2294 &qtcb->header.fsf_status_qual.link_down_info);
2298 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2299 debug_event(adapter->erp_dbf, 0,
2300 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2306 * function: zfcp_fsf_open_port
2310 * returns: address of initiated FSF request
2311 * NULL - request could not be initiated
2314 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2316 volatile struct qdio_buffer_element *sbale;
2317 unsigned long lock_flags;
2320 /* setup new FSF request */
2321 retval = zfcp_fsf_req_create(erp_action->adapter,
2322 FSF_QTCB_OPEN_PORT_WITH_DID,
2323 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2324 erp_action->adapter->pool.fsf_req_erp,
2325 &lock_flags, &(erp_action->fsf_req));
2327 ZFCP_LOG_INFO("error: Could not create open port request "
2328 "for port 0x%016Lx on adapter %s.\n",
2329 erp_action->port->wwpn,
2330 zfcp_get_busid_by_adapter(erp_action->adapter));
2334 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2335 erp_action->fsf_req->sbal_curr, 0);
2336 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2337 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2339 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2340 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2341 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2342 erp_action->fsf_req->erp_action = erp_action;
2344 /* start QDIO request for this FSF request */
2345 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2347 ZFCP_LOG_INFO("error: Could not send open port request for "
2348 "port 0x%016Lx on adapter %s.\n",
2349 erp_action->port->wwpn,
2350 zfcp_get_busid_by_adapter(erp_action->adapter));
2351 zfcp_fsf_req_free(erp_action->fsf_req);
2352 erp_action->fsf_req = NULL;
2356 ZFCP_LOG_DEBUG("open port request initiated "
2357 "(adapter %s, port 0x%016Lx)\n",
2358 zfcp_get_busid_by_adapter(erp_action->adapter),
2359 erp_action->port->wwpn);
2361 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2367 * function: zfcp_fsf_open_port_handler
2369 * purpose: is called for finished Open Port command
2374 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2376 int retval = -EINVAL;
2377 struct zfcp_port *port;
2378 struct fsf_plogi *plogi;
2379 struct fsf_qtcb_header *header;
2380 u16 subtable, rule, counter;
2382 port = (struct zfcp_port *) fsf_req->data;
2383 header = &fsf_req->qtcb->header;
2385 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2386 /* don't change port status in our bookkeeping */
2387 goto skip_fsfstatus;
2390 /* evaluate FSF status in QTCB */
2391 switch (header->fsf_status) {
2393 case FSF_PORT_ALREADY_OPEN:
2394 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2395 "is already open.\n",
2396 port->wwpn, zfcp_get_busid_by_port(port));
2397 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2400 * This is a bug, however operation should continue normally
2401 * if it is simply ignored
2405 case FSF_ACCESS_DENIED:
2406 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2408 port->wwpn, zfcp_get_busid_by_port(port));
2409 for (counter = 0; counter < 2; counter++) {
2410 subtable = header->fsf_status_qual.halfword[counter * 2];
2411 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2413 case FSF_SQ_CFDC_SUBTABLE_OS:
2414 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2415 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2416 case FSF_SQ_CFDC_SUBTABLE_LUN:
2417 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2418 zfcp_act_subtable_type[subtable], rule);
2422 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2423 zfcp_erp_port_access_denied(port);
2424 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2427 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2428 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2429 "The remote port 0x%016Lx on adapter %s "
2430 "could not be opened. Disabling it.\n",
2431 port->wwpn, zfcp_get_busid_by_port(port));
2432 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2434 zfcp_erp_port_failed(port);
2435 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2438 case FSF_ADAPTER_STATUS_AVAILABLE:
2439 switch (header->fsf_status_qual.word[0]) {
2440 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2441 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2443 /* ERP strategy will escalate */
2444 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2446 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2447 /* ERP strategy will escalate */
2448 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2450 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2452 case FSF_SQ_NO_RETRY_POSSIBLE:
2453 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2454 "adapter %s could not be opened. "
2457 zfcp_get_busid_by_port(port));
2458 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2460 zfcp_erp_port_failed(port);
2461 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2465 ("bug: Wrong status qualifier 0x%x arrived.\n",
2466 header->fsf_status_qual.word[0]);
2467 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2470 fsf_req->adapter->erp_dbf, 0,
2471 &header->fsf_status_qual.word[0],
2478 /* save port handle assigned by FSF */
2479 port->handle = header->port_handle;
2480 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2481 "was opened, it's port handle is 0x%x\n",
2482 port->wwpn, zfcp_get_busid_by_port(port),
2484 /* mark port as open */
2485 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2486 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2487 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2488 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2491 /* check whether D_ID has changed during open */
2493 * FIXME: This check is not airtight, as the FCP channel does
2494 * not monitor closures of target port connections caused on
2495 * the remote side. Thus, they might miss out on invalidating
2496 * locally cached WWPNs (and other N_Port parameters) of gone
2497 * target ports. So, our heroic attempt to make things safe
2498 * could be undermined by 'open port' response data tagged with
2499 * obsolete WWPNs. Another reason to monitor potential
2500 * connection closures ourself at least (by interpreting
2501 * incoming ELS' and unsolicited status). It just crosses my
2502 * mind that one should be able to cross-check by means of
2503 * another GID_PN straight after a port has been opened.
2504 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2506 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2507 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2509 if (fsf_req->qtcb->bottom.support.els1_length <
2510 ((((unsigned long) &plogi->serv_param.wwpn) -
2511 ((unsigned long) plogi)) + sizeof (u64))) {
2513 "warning: insufficient length of "
2514 "PLOGI payload (%i)\n",
2515 fsf_req->qtcb->bottom.support.els1_length);
2516 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2517 "fsf_s_short_plogi:");
2518 /* skip sanity check and assume wwpn is ok */
2520 if (plogi->serv_param.wwpn != port->wwpn) {
2521 ZFCP_LOG_INFO("warning: d_id of port "
2522 "0x%016Lx changed during "
2523 "open\n", port->wwpn);
2525 fsf_req->adapter->erp_dbf, 0,
2526 "fsf_s_did_change:");
2528 ZFCP_STATUS_PORT_DID_DID,
2531 port->wwnn = plogi->serv_param.wwnn;
2536 case FSF_UNKNOWN_OP_SUBTYPE:
2537 /* should never occure, subtype not set in zfcp_fsf_open_port */
2538 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2539 "op_subtype=0x%x)\n",
2540 zfcp_get_busid_by_port(port),
2541 fsf_req->qtcb->bottom.support.operation_subtype);
2542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2546 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2547 "(debug info 0x%x)\n",
2548 header->fsf_status);
2549 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2550 debug_exception(fsf_req->adapter->erp_dbf, 0,
2551 &header->fsf_status, sizeof (u32));
2556 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2561 * function: zfcp_fsf_close_port
2563 * purpose: submit FSF command "close port"
2565 * returns: address of initiated FSF request
2566 * NULL - request could not be initiated
2569 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2571 volatile struct qdio_buffer_element *sbale;
2572 unsigned long lock_flags;
2575 /* setup new FSF request */
2576 retval = zfcp_fsf_req_create(erp_action->adapter,
2577 FSF_QTCB_CLOSE_PORT,
2578 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2579 erp_action->adapter->pool.fsf_req_erp,
2580 &lock_flags, &(erp_action->fsf_req));
2582 ZFCP_LOG_INFO("error: Could not create a close port request "
2583 "for port 0x%016Lx on adapter %s.\n",
2584 erp_action->port->wwpn,
2585 zfcp_get_busid_by_adapter(erp_action->adapter));
2589 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2590 erp_action->fsf_req->sbal_curr, 0);
2591 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2592 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2594 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2595 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2596 erp_action->fsf_req->erp_action = erp_action;
2597 erp_action->fsf_req->qtcb->header.port_handle =
2598 erp_action->port->handle;
2600 /* start QDIO request for this FSF request */
2601 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2603 ZFCP_LOG_INFO("error: Could not send a close port request for "
2604 "port 0x%016Lx on adapter %s.\n",
2605 erp_action->port->wwpn,
2606 zfcp_get_busid_by_adapter(erp_action->adapter));
2607 zfcp_fsf_req_free(erp_action->fsf_req);
2608 erp_action->fsf_req = NULL;
2612 ZFCP_LOG_TRACE("close port request initiated "
2613 "(adapter %s, port 0x%016Lx)\n",
2614 zfcp_get_busid_by_adapter(erp_action->adapter),
2615 erp_action->port->wwpn);
2617 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2623 * function: zfcp_fsf_close_port_handler
2625 * purpose: is called for finished Close Port FSF command
2630 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2632 int retval = -EINVAL;
2633 struct zfcp_port *port;
2635 port = (struct zfcp_port *) fsf_req->data;
2637 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2638 /* don't change port status in our bookkeeping */
2639 goto skip_fsfstatus;
2642 /* evaluate FSF status in QTCB */
2643 switch (fsf_req->qtcb->header.fsf_status) {
2645 case FSF_PORT_HANDLE_NOT_VALID:
2646 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2647 "0x%016Lx on adapter %s invalid. This may happen "
2648 "occasionally.\n", port->handle,
2649 port->wwpn, zfcp_get_busid_by_port(port));
2650 ZFCP_LOG_DEBUG("status qualifier:\n");
2651 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2652 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2653 sizeof (union fsf_status_qual));
2654 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2656 zfcp_erp_adapter_reopen(port->adapter, 0);
2657 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2660 case FSF_ADAPTER_STATUS_AVAILABLE:
2661 /* Note: FSF has actually closed the port in this case.
2662 * The status code is just daft. Fingers crossed for a change
2668 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2669 "port handle 0x%x\n", port->wwpn,
2670 zfcp_get_busid_by_port(port), port->handle);
2671 zfcp_erp_modify_port_status(port,
2672 ZFCP_STATUS_COMMON_OPEN,
2678 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2679 "(debug info 0x%x)\n",
2680 fsf_req->qtcb->header.fsf_status);
2681 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2682 debug_exception(fsf_req->adapter->erp_dbf, 0,
2683 &fsf_req->qtcb->header.fsf_status,
2689 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2694 * function: zfcp_fsf_close_physical_port
2696 * purpose: submit FSF command "close physical port"
2698 * returns: address of initiated FSF request
2699 * NULL - request could not be initiated
2702 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2705 unsigned long lock_flags;
2706 volatile struct qdio_buffer_element *sbale;
2708 /* setup new FSF request */
2709 retval = zfcp_fsf_req_create(erp_action->adapter,
2710 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2711 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2712 erp_action->adapter->pool.fsf_req_erp,
2713 &lock_flags, &erp_action->fsf_req);
2715 ZFCP_LOG_INFO("error: Could not create close physical port "
2716 "request (adapter %s, port 0x%016Lx)\n",
2717 zfcp_get_busid_by_adapter(erp_action->adapter),
2718 erp_action->port->wwpn);
2723 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2724 erp_action->fsf_req->sbal_curr, 0);
2725 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2726 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2728 /* mark port as being closed */
2729 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2730 &erp_action->port->status);
2731 /* save a pointer to this port */
2732 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2733 /* port to be closed */
2734 erp_action->fsf_req->qtcb->header.port_handle =
2735 erp_action->port->handle;
2736 erp_action->fsf_req->erp_action = erp_action;
2738 /* start QDIO request for this FSF request */
2739 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2741 ZFCP_LOG_INFO("error: Could not send close physical port "
2742 "request (adapter %s, port 0x%016Lx)\n",
2743 zfcp_get_busid_by_adapter(erp_action->adapter),
2744 erp_action->port->wwpn);
2745 zfcp_fsf_req_free(erp_action->fsf_req);
2746 erp_action->fsf_req = NULL;
2750 ZFCP_LOG_TRACE("close physical port request initiated "
2751 "(adapter %s, port 0x%016Lx)\n",
2752 zfcp_get_busid_by_adapter(erp_action->adapter),
2753 erp_action->port->wwpn);
2755 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2761 * function: zfcp_fsf_close_physical_port_handler
2763 * purpose: is called for finished Close Physical Port FSF command
2768 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2770 int retval = -EINVAL;
2771 struct zfcp_port *port;
2772 struct zfcp_unit *unit;
2773 struct fsf_qtcb_header *header;
2774 u16 subtable, rule, counter;
2776 port = (struct zfcp_port *) fsf_req->data;
2777 header = &fsf_req->qtcb->header;
2779 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2780 /* don't change port status in our bookkeeping */
2781 goto skip_fsfstatus;
2784 /* evaluate FSF status in QTCB */
2785 switch (header->fsf_status) {
2787 case FSF_PORT_HANDLE_NOT_VALID:
2788 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2789 "(adapter %s, port 0x%016Lx). "
2790 "This may happen occasionally.\n",
2792 zfcp_get_busid_by_port(port),
2794 ZFCP_LOG_DEBUG("status qualifier:\n");
2795 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2796 (char *) &header->fsf_status_qual,
2797 sizeof (union fsf_status_qual));
2798 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2800 zfcp_erp_adapter_reopen(port->adapter, 0);
2801 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2804 case FSF_ACCESS_DENIED:
2805 ZFCP_LOG_NORMAL("Access denied, cannot close "
2806 "physical port 0x%016Lx on adapter %s\n",
2807 port->wwpn, zfcp_get_busid_by_port(port));
2808 for (counter = 0; counter < 2; counter++) {
2809 subtable = header->fsf_status_qual.halfword[counter * 2];
2810 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2812 case FSF_SQ_CFDC_SUBTABLE_OS:
2813 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2814 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2815 case FSF_SQ_CFDC_SUBTABLE_LUN:
2816 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2817 zfcp_act_subtable_type[subtable], rule);
2821 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2822 zfcp_erp_port_access_denied(port);
2823 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2826 case FSF_PORT_BOXED:
2827 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2828 "%s needs to be reopened but it was attempted "
2829 "to close it physically.\n",
2831 zfcp_get_busid_by_port(port));
2832 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2833 zfcp_erp_port_boxed(port);
2834 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2835 ZFCP_STATUS_FSFREQ_RETRY;
2838 case FSF_ADAPTER_STATUS_AVAILABLE:
2839 switch (header->fsf_status_qual.word[0]) {
2840 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2841 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2843 /* This will now be escalated by ERP */
2844 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2846 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2847 /* ERP strategy will escalate */
2848 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2850 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2854 ("bug: Wrong status qualifier 0x%x arrived.\n",
2855 header->fsf_status_qual.word[0]);
2856 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2859 fsf_req->adapter->erp_dbf, 0,
2860 &header->fsf_status_qual.word[0], sizeof (u32));
2866 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2867 "physically closed, port handle 0x%x\n",
2869 zfcp_get_busid_by_port(port), port->handle);
2870 /* can't use generic zfcp_erp_modify_port_status because
2871 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2873 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2874 list_for_each_entry(unit, &port->unit_list_head, list)
2875 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2880 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2881 "(debug info 0x%x)\n",
2882 header->fsf_status);
2883 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2884 debug_exception(fsf_req->adapter->erp_dbf, 0,
2885 &header->fsf_status, sizeof (u32));
2890 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2895 * function: zfcp_fsf_open_unit
2901 * assumptions: This routine does not check whether the associated
2902 * remote port has already been opened. This should be
2903 * done by calling routines. Otherwise some status
2904 * may be presented by FSF
2907 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2909 volatile struct qdio_buffer_element *sbale;
2910 unsigned long lock_flags;
2913 /* setup new FSF request */
2914 retval = zfcp_fsf_req_create(erp_action->adapter,
2916 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2917 erp_action->adapter->pool.fsf_req_erp,
2918 &lock_flags, &(erp_action->fsf_req));
2920 ZFCP_LOG_INFO("error: Could not create open unit request for "
2921 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2922 erp_action->unit->fcp_lun,
2923 erp_action->unit->port->wwpn,
2924 zfcp_get_busid_by_adapter(erp_action->adapter));
2928 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2929 erp_action->fsf_req->sbal_curr, 0);
2930 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2931 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2933 erp_action->fsf_req->qtcb->header.port_handle =
2934 erp_action->port->handle;
2935 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2936 erp_action->unit->fcp_lun;
2937 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2938 erp_action->fsf_req->qtcb->bottom.support.option =
2939 FSF_OPEN_LUN_SUPPRESS_BOXING;
2940 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2941 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
2942 erp_action->fsf_req->erp_action = erp_action;
2944 /* start QDIO request for this FSF request */
2945 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2947 ZFCP_LOG_INFO("error: Could not send an open unit request "
2948 "on the adapter %s, port 0x%016Lx for "
2950 zfcp_get_busid_by_adapter(erp_action->adapter),
2951 erp_action->port->wwpn,
2952 erp_action->unit->fcp_lun);
2953 zfcp_fsf_req_free(erp_action->fsf_req);
2954 erp_action->fsf_req = NULL;
2958 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2959 "port 0x%016Lx, unit 0x%016Lx)\n",
2960 zfcp_get_busid_by_adapter(erp_action->adapter),
2961 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2963 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2969 * function: zfcp_fsf_open_unit_handler
2971 * purpose: is called for finished Open LUN command
2976 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2978 int retval = -EINVAL;
2979 struct zfcp_adapter *adapter;
2980 struct zfcp_unit *unit;
2981 struct fsf_qtcb_header *header;
2982 struct fsf_qtcb_bottom_support *bottom;
2983 struct fsf_queue_designator *queue_designator;
2984 u16 subtable, rule, counter;
2985 int exclusive, readwrite;
2987 unit = (struct zfcp_unit *) fsf_req->data;
2989 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2990 /* don't change unit status in our bookkeeping */
2991 goto skip_fsfstatus;
2994 adapter = fsf_req->adapter;
2995 header = &fsf_req->qtcb->header;
2996 bottom = &fsf_req->qtcb->bottom.support;
2997 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2999 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3000 ZFCP_STATUS_UNIT_SHARED |
3001 ZFCP_STATUS_UNIT_READONLY,
3004 /* evaluate FSF status in QTCB */
3005 switch (header->fsf_status) {
3007 case FSF_PORT_HANDLE_NOT_VALID:
3008 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3009 "for port 0x%016Lx on adapter %s invalid "
3010 "This may happen occasionally\n",
3012 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3013 ZFCP_LOG_DEBUG("status qualifier:\n");
3014 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3015 (char *) &header->fsf_status_qual,
3016 sizeof (union fsf_status_qual));
3017 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3018 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3019 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3022 case FSF_LUN_ALREADY_OPEN:
3023 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3024 "remote port 0x%016Lx on adapter %s twice.\n",
3026 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3027 debug_text_exception(adapter->erp_dbf, 0,
3029 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3032 case FSF_ACCESS_DENIED:
3033 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3034 "remote port 0x%016Lx on adapter %s\n",
3035 unit->fcp_lun, unit->port->wwpn,
3036 zfcp_get_busid_by_unit(unit));
3037 for (counter = 0; counter < 2; counter++) {
3038 subtable = header->fsf_status_qual.halfword[counter * 2];
3039 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3041 case FSF_SQ_CFDC_SUBTABLE_OS:
3042 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3043 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3044 case FSF_SQ_CFDC_SUBTABLE_LUN:
3045 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3046 zfcp_act_subtable_type[subtable], rule);
3050 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3051 zfcp_erp_unit_access_denied(unit);
3052 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3053 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3054 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3057 case FSF_PORT_BOXED:
3058 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3059 "needs to be reopened\n",
3060 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3061 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3062 zfcp_erp_port_boxed(unit->port);
3063 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3064 ZFCP_STATUS_FSFREQ_RETRY;
3067 case FSF_LUN_SHARING_VIOLATION:
3068 if (header->fsf_status_qual.word[0] != 0) {
3069 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3071 "connected to the adapter %s "
3072 "is already in use in LPAR%d, CSS%d\n",
3075 zfcp_get_busid_by_unit(unit),
3076 queue_designator->hla,
3077 queue_designator->cssid);
3079 subtable = header->fsf_status_qual.halfword[4];
3080 rule = header->fsf_status_qual.halfword[5];
3082 case FSF_SQ_CFDC_SUBTABLE_OS:
3083 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3084 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3085 case FSF_SQ_CFDC_SUBTABLE_LUN:
3086 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3087 "remote port with WWPN 0x%Lx "
3088 "connected to the adapter %s "
3089 "is denied (%s rule %d)\n",
3092 zfcp_get_busid_by_unit(unit),
3093 zfcp_act_subtable_type[subtable],
3098 ZFCP_LOG_DEBUG("status qualifier:\n");
3099 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3100 (char *) &header->fsf_status_qual,
3101 sizeof (union fsf_status_qual));
3102 debug_text_event(adapter->erp_dbf, 2,
3104 zfcp_erp_unit_access_denied(unit);
3105 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3106 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3107 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3110 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3111 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3112 "There is no handle (temporary port identifier) "
3113 "available for unit 0x%016Lx on port 0x%016Lx "
3117 zfcp_get_busid_by_unit(unit));
3118 debug_text_event(adapter->erp_dbf, 1,
3120 zfcp_erp_unit_failed(unit);
3121 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3124 case FSF_ADAPTER_STATUS_AVAILABLE:
3125 switch (header->fsf_status_qual.word[0]) {
3126 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3127 /* Re-establish link to port */
3128 debug_text_event(adapter->erp_dbf, 1,
3130 zfcp_test_link(unit->port);
3131 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3133 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3134 /* ERP strategy will escalate */
3135 debug_text_event(adapter->erp_dbf, 1,
3137 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3141 ("bug: Wrong status qualifier 0x%x arrived.\n",
3142 header->fsf_status_qual.word[0]);
3143 debug_text_event(adapter->erp_dbf, 0,
3145 debug_exception(adapter->erp_dbf, 0,
3146 &header->fsf_status_qual.word[0],
3151 case FSF_INVALID_COMMAND_OPTION:
3153 "Invalid option 0x%x has been specified "
3154 "in QTCB bottom sent to the adapter %s\n",
3156 zfcp_get_busid_by_adapter(adapter));
3157 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3162 /* save LUN handle assigned by FSF */
3163 unit->handle = header->lun_handle;
3164 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3165 "adapter %s opened, port handle 0x%x\n",
3168 zfcp_get_busid_by_unit(unit),
3170 /* mark unit as open */
3171 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3173 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3174 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3175 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3176 exclusive = (bottom->lun_access_info &
3177 FSF_UNIT_ACCESS_EXCLUSIVE);
3178 readwrite = (bottom->lun_access_info &
3179 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3182 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3186 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3188 ZFCP_LOG_NORMAL("read-only access for unit "
3189 "(adapter %s, wwpn=0x%016Lx, "
3190 "fcp_lun=0x%016Lx)\n",
3191 zfcp_get_busid_by_unit(unit),
3196 if (exclusive && !readwrite) {
3197 ZFCP_LOG_NORMAL("exclusive access of read-only "
3198 "unit not supported\n");
3199 zfcp_erp_unit_failed(unit);
3200 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3201 zfcp_erp_unit_shutdown(unit, 0);
3202 } else if (!exclusive && readwrite) {
3203 ZFCP_LOG_NORMAL("shared access of read-write "
3204 "unit not supported\n");
3205 zfcp_erp_unit_failed(unit);
3206 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3207 zfcp_erp_unit_shutdown(unit, 0);
3215 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3216 "(debug info 0x%x)\n",
3217 header->fsf_status);
3218 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3219 debug_exception(adapter->erp_dbf, 0,
3220 &header->fsf_status, sizeof (u32));
3225 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3230 * function: zfcp_fsf_close_unit
3234 * returns: address of fsf_req - request successfully initiated
3237 * assumptions: This routine does not check whether the associated
3238 * remote port/lun has already been opened. This should be
3239 * done by calling routines. Otherwise some status
3240 * may be presented by FSF
3243 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3245 volatile struct qdio_buffer_element *sbale;
3246 unsigned long lock_flags;
3249 /* setup new FSF request */
3250 retval = zfcp_fsf_req_create(erp_action->adapter,
3252 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3253 erp_action->adapter->pool.fsf_req_erp,
3254 &lock_flags, &(erp_action->fsf_req));
3256 ZFCP_LOG_INFO("error: Could not create close unit request for "
3257 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3258 erp_action->unit->fcp_lun,
3259 erp_action->port->wwpn,
3260 zfcp_get_busid_by_adapter(erp_action->adapter));
3264 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3265 erp_action->fsf_req->sbal_curr, 0);
3266 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3267 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3269 erp_action->fsf_req->qtcb->header.port_handle =
3270 erp_action->port->handle;
3271 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3272 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3273 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3274 erp_action->fsf_req->erp_action = erp_action;
3276 /* start QDIO request for this FSF request */
3277 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3279 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3280 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3281 erp_action->unit->fcp_lun,
3282 erp_action->port->wwpn,
3283 zfcp_get_busid_by_adapter(erp_action->adapter));
3284 zfcp_fsf_req_free(erp_action->fsf_req);
3285 erp_action->fsf_req = NULL;
3289 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3290 "port 0x%016Lx, unit 0x%016Lx)\n",
3291 zfcp_get_busid_by_adapter(erp_action->adapter),
3292 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3294 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3300 * function: zfcp_fsf_close_unit_handler
3302 * purpose: is called for finished Close LUN FSF command
3307 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3309 int retval = -EINVAL;
3310 struct zfcp_unit *unit;
3312 unit = (struct zfcp_unit *) fsf_req->data;
3314 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3315 /* don't change unit status in our bookkeeping */
3316 goto skip_fsfstatus;
3319 /* evaluate FSF status in QTCB */
3320 switch (fsf_req->qtcb->header.fsf_status) {
3322 case FSF_PORT_HANDLE_NOT_VALID:
3323 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3324 "0x%016Lx on adapter %s invalid. This may "
3325 "happen in rare circumstances\n",
3328 zfcp_get_busid_by_unit(unit));
3329 ZFCP_LOG_DEBUG("status qualifier:\n");
3330 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3331 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3332 sizeof (union fsf_status_qual));
3333 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3335 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3336 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3339 case FSF_LUN_HANDLE_NOT_VALID:
3340 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3341 "0x%016Lx on port 0x%016Lx on adapter %s is "
3342 "invalid. This may happen occasionally.\n",
3346 zfcp_get_busid_by_unit(unit));
3347 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3348 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3349 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3350 sizeof (union fsf_status_qual));
3351 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3353 zfcp_erp_port_reopen(unit->port, 0);
3354 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3357 case FSF_PORT_BOXED:
3358 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3359 "needs to be reopened\n",
3361 zfcp_get_busid_by_unit(unit));
3362 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3363 zfcp_erp_port_boxed(unit->port);
3364 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3365 ZFCP_STATUS_FSFREQ_RETRY;
3368 case FSF_ADAPTER_STATUS_AVAILABLE:
3369 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3370 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3371 /* re-establish link to port */
3372 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3374 zfcp_test_link(unit->port);
3375 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3377 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3378 /* ERP strategy will escalate */
3379 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3381 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3385 ("bug: Wrong status qualifier 0x%x arrived.\n",
3386 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3387 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3390 fsf_req->adapter->erp_dbf, 0,
3391 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3398 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3399 "closed, port handle 0x%x\n",
3402 zfcp_get_busid_by_unit(unit),
3404 /* mark unit as closed */
3405 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3410 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3411 "(debug info 0x%x)\n",
3412 fsf_req->qtcb->header.fsf_status);
3413 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3414 debug_exception(fsf_req->adapter->erp_dbf, 0,
3415 &fsf_req->qtcb->header.fsf_status,
3421 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3426 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3427 * @adapter: adapter where scsi command is issued
3428 * @unit: unit where command is sent to
3429 * @scsi_cmnd: scsi command to be sent
3430 * @timer: timer to be started when request is initiated
3431 * @req_flags: flags for fsf_request
3434 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3435 struct zfcp_unit *unit,
3436 struct scsi_cmnd * scsi_cmnd,
3437 struct timer_list *timer, int req_flags)
3439 struct zfcp_fsf_req *fsf_req = NULL;
3440 struct fcp_cmnd_iu *fcp_cmnd_iu;
3441 unsigned int sbtype;
3442 unsigned long lock_flags;
3447 /* setup new FSF request */
3448 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3449 adapter->pool.fsf_req_scsi,
3450 &lock_flags, &fsf_req);
3451 if (unlikely(retval < 0)) {
3452 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3453 "for unit 0x%016Lx on port 0x%016Lx on "
3457 zfcp_get_busid_by_adapter(adapter));
3458 goto failed_req_create;
3461 zfcp_unit_get(unit);
3462 fsf_req->unit = unit;
3464 /* associate FSF request with SCSI request (for look up on abort) */
3465 scsi_cmnd->host_scribble = (char *) fsf_req;
3467 /* associate SCSI command with FSF request */
3468 fsf_req->data = (unsigned long) scsi_cmnd;
3470 /* set handles of unit and its parent port in QTCB */
3471 fsf_req->qtcb->header.lun_handle = unit->handle;
3472 fsf_req->qtcb->header.port_handle = unit->port->handle;
3474 /* FSF does not define the structure of the FCP_CMND IU */
3475 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3476 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3479 * set depending on data direction:
3480 * data direction bits in SBALE (SB Type)
3481 * data direction bits in QTCB
3482 * data direction bits in FCP_CMND IU
3484 switch (scsi_cmnd->sc_data_direction) {
3486 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3489 * what is the correct type for commands
3490 * without 'real' data buffers?
3492 sbtype = SBAL_FLAGS0_TYPE_READ;
3494 case DMA_FROM_DEVICE:
3495 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3496 sbtype = SBAL_FLAGS0_TYPE_READ;
3497 fcp_cmnd_iu->rddata = 1;
3500 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3501 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3502 fcp_cmnd_iu->wddata = 1;
3504 case DMA_BIDIRECTIONAL:
3507 * dummy, catch this condition earlier
3508 * in zfcp_scsi_queuecommand
3510 goto failed_scsi_cmnd;
3513 /* set FC service class in QTCB (3 per default) */
3514 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3516 /* set FCP_LUN in FCP_CMND IU in QTCB */
3517 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3519 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3521 /* set task attributes in FCP_CMND IU in QTCB */
3522 if (likely((scsi_cmnd->device->simple_tags) ||
3523 (atomic_test_mask(mask, &unit->status))))
3524 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3526 fcp_cmnd_iu->task_attribute = UNTAGGED;
3528 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3529 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3530 fcp_cmnd_iu->add_fcp_cdb_length
3531 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3532 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3533 "additional FCP_CDB length is 0x%x "
3534 "(shifted right 2 bits)\n",
3536 fcp_cmnd_iu->add_fcp_cdb_length);
3539 * copy SCSI CDB (including additional length, if any) to
3540 * FCP_CDB in FCP_CMND IU in QTCB
3542 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3544 /* FCP CMND IU length in QTCB */
3545 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3546 sizeof (struct fcp_cmnd_iu) +
3547 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3549 /* generate SBALEs from data buffer */
3550 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3551 if (unlikely(real_bytes < 0)) {
3552 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3554 "Data did not fit into available buffer(s), "
3555 "waiting for more...\n");
3558 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3559 "required. Shutting down unit "
3560 "(adapter %s, port 0x%016Lx, "
3562 zfcp_get_busid_by_unit(unit),
3565 zfcp_erp_unit_shutdown(unit, 0);
3571 /* set length of FCP data length in FCP_CMND IU in QTCB */
3572 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3574 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3575 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3576 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3579 * start QDIO request for this FSF request
3580 * covered by an SBALE)
3582 retval = zfcp_fsf_req_send(fsf_req, timer);
3583 if (unlikely(retval < 0)) {
3584 ZFCP_LOG_INFO("error: Could not send FCP command request "
3585 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3586 zfcp_get_busid_by_adapter(adapter),
3592 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3593 "port 0x%016Lx, unit 0x%016Lx)\n",
3594 zfcp_get_busid_by_adapter(adapter),
3602 zfcp_unit_put(unit);
3603 zfcp_fsf_req_free(fsf_req);
3605 scsi_cmnd->host_scribble = NULL;
3608 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3613 * function: zfcp_fsf_send_fcp_command_task_management
3619 * FIXME(design): should be watched by a timeout!!!
3620 * FIXME(design) shouldn't this be modified to return an int
3621 * also...don't know how though
3624 struct zfcp_fsf_req *
3625 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3626 struct zfcp_unit *unit,
3627 u8 tm_flags, int req_flags)
3629 struct zfcp_fsf_req *fsf_req = NULL;
3631 struct fcp_cmnd_iu *fcp_cmnd_iu;
3632 unsigned long lock_flags;
3633 volatile struct qdio_buffer_element *sbale;
3635 /* setup new FSF request */
3636 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3637 adapter->pool.fsf_req_scsi,
3638 &lock_flags, &fsf_req);
3640 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3641 "management) request for adapter %s, port "
3642 " 0x%016Lx, unit 0x%016Lx.\n",
3643 zfcp_get_busid_by_adapter(adapter),
3644 unit->port->wwpn, unit->fcp_lun);
3649 * Used to decide on proper handler in the return path,
3650 * could be either zfcp_fsf_send_fcp_command_task_handler or
3651 * zfcp_fsf_send_fcp_command_task_management_handler */
3653 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3656 * hold a pointer to the unit being target of this
3657 * task management request
3659 fsf_req->data = (unsigned long) unit;
3661 /* set FSF related fields in QTCB */
3662 fsf_req->qtcb->header.lun_handle = unit->handle;
3663 fsf_req->qtcb->header.port_handle = unit->port->handle;
3664 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3665 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3666 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3667 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3669 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3670 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3671 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3673 /* set FCP related fields in FCP_CMND IU in QTCB */
3674 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3675 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3676 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3677 fcp_cmnd_iu->task_management_flags = tm_flags;
3679 /* start QDIO request for this FSF request */
3680 zfcp_fsf_start_scsi_er_timer(adapter);
3681 retval = zfcp_fsf_req_send(fsf_req, NULL);
3683 del_timer(&adapter->scsi_er_timer);
3684 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3685 "management) on adapter %s, port 0x%016Lx for "
3686 "unit LUN 0x%016Lx\n",
3687 zfcp_get_busid_by_adapter(adapter),
3690 zfcp_fsf_req_free(fsf_req);
3695 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3696 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3698 zfcp_get_busid_by_adapter(adapter),
3703 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3708 * function: zfcp_fsf_send_fcp_command_handler
3710 * purpose: is called for finished Send FCP Command
3715 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3717 int retval = -EINVAL;
3718 struct zfcp_unit *unit;
3719 struct fsf_qtcb_header *header;
3720 u16 subtable, rule, counter;
3722 header = &fsf_req->qtcb->header;
3724 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3725 unit = (struct zfcp_unit *) fsf_req->data;
3727 unit = fsf_req->unit;
3729 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3730 /* go directly to calls of special handlers */
3731 goto skip_fsfstatus;
3734 /* evaluate FSF status in QTCB */
3735 switch (header->fsf_status) {
3737 case FSF_PORT_HANDLE_NOT_VALID:
3738 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3739 "0x%016Lx on adapter %s invalid\n",
3741 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3742 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3743 (char *) &header->fsf_status_qual,
3744 sizeof (union fsf_status_qual));
3745 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3747 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3748 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3751 case FSF_LUN_HANDLE_NOT_VALID:
3752 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3753 "0x%016Lx on port 0x%016Lx on adapter %s is "
3754 "invalid. This may happen occasionally.\n",
3758 zfcp_get_busid_by_unit(unit));
3759 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3760 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3761 (char *) &header->fsf_status_qual,
3762 sizeof (union fsf_status_qual));
3763 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3765 zfcp_erp_port_reopen(unit->port, 0);
3766 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3769 case FSF_HANDLE_MISMATCH:
3770 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3771 "unexpectedly. (adapter %s, port 0x%016Lx, "
3774 zfcp_get_busid_by_unit(unit),
3777 ZFCP_LOG_NORMAL("status qualifier:\n");
3778 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3779 (char *) &header->fsf_status_qual,
3780 sizeof (union fsf_status_qual));
3781 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3783 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3784 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3787 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3788 if (fsf_req->adapter->fc_service_class <= 3) {
3789 ZFCP_LOG_NORMAL("error: The adapter %s does "
3790 "not support fibrechannel class %d.\n",
3791 zfcp_get_busid_by_unit(unit),
3792 fsf_req->adapter->fc_service_class);
3794 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3795 "adapter %s is invalid. "
3796 "(debug info %d)\n",
3797 zfcp_get_busid_by_unit(unit),
3798 fsf_req->adapter->fc_service_class);
3800 /* stop operation for this adapter */
3801 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3802 "fsf_s_class_nsup");
3803 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3804 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3807 case FSF_FCPLUN_NOT_VALID:
3808 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3809 "adapter %s does not have correct unit "
3813 zfcp_get_busid_by_unit(unit),
3815 ZFCP_LOG_DEBUG("status qualifier:\n");
3816 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3817 (char *) &header->fsf_status_qual,
3818 sizeof (union fsf_status_qual));
3819 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3820 "fsf_s_fcp_lun_nv");
3821 zfcp_erp_port_reopen(unit->port, 0);
3822 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3825 case FSF_ACCESS_DENIED:
3826 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3827 "unit 0x%016Lx on port 0x%016Lx on "
3828 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3829 zfcp_get_busid_by_unit(unit));
3830 for (counter = 0; counter < 2; counter++) {
3831 subtable = header->fsf_status_qual.halfword[counter * 2];
3832 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3834 case FSF_SQ_CFDC_SUBTABLE_OS:
3835 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3836 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3837 case FSF_SQ_CFDC_SUBTABLE_LUN:
3838 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3839 zfcp_act_subtable_type[subtable], rule);
3843 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3844 zfcp_erp_unit_access_denied(unit);
3845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3848 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3849 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3850 "0x%016Lx on port 0x%016Lx on adapter %s "
3851 "(debug info %d)\n",
3854 zfcp_get_busid_by_unit(unit),
3855 fsf_req->qtcb->bottom.io.data_direction);
3856 /* stop operation for this adapter */
3857 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3858 "fsf_s_dir_ind_nv");
3859 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3860 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3863 case FSF_CMND_LENGTH_NOT_VALID:
3865 ("bug: An invalid control-data-block length field "
3866 "was found in a command for unit 0x%016Lx on port "
3867 "0x%016Lx on adapter %s " "(debug info %d)\n",
3868 unit->fcp_lun, unit->port->wwpn,
3869 zfcp_get_busid_by_unit(unit),
3870 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3871 /* stop operation for this adapter */
3872 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3873 "fsf_s_cmd_len_nv");
3874 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3875 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3878 case FSF_PORT_BOXED:
3879 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3880 "needs to be reopened\n",
3881 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3882 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3883 zfcp_erp_port_boxed(unit->port);
3884 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3885 ZFCP_STATUS_FSFREQ_RETRY;
3889 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3890 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3891 zfcp_get_busid_by_unit(unit),
3892 unit->port->wwpn, unit->fcp_lun);
3893 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3894 zfcp_erp_unit_boxed(unit);
3895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3896 | ZFCP_STATUS_FSFREQ_RETRY;
3899 case FSF_ADAPTER_STATUS_AVAILABLE:
3900 switch (header->fsf_status_qual.word[0]) {
3901 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3902 /* re-establish link to port */
3903 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3905 zfcp_test_link(unit->port);
3907 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3908 /* FIXME(hw) need proper specs for proper action */
3909 /* let scsi stack deal with retries and escalation */
3910 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3915 ("Unknown status qualifier 0x%x arrived.\n",
3916 header->fsf_status_qual.word[0]);
3917 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3919 debug_exception(fsf_req->adapter->erp_dbf, 0,
3920 &header->fsf_status_qual.word[0],
3924 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3930 case FSF_FCP_RSP_AVAILABLE:
3934 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3935 debug_exception(fsf_req->adapter->erp_dbf, 0,
3936 &header->fsf_status, sizeof(u32));
3941 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3943 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3945 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3946 fsf_req->unit = NULL;
3947 zfcp_unit_put(unit);
3953 * function: zfcp_fsf_send_fcp_command_task_handler
3955 * purpose: evaluates FCP_RSP IU
3960 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3963 struct scsi_cmnd *scpnt;
3964 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3965 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3966 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3967 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3969 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3970 unsigned long flags;
3971 struct zfcp_unit *unit = fsf_req->unit;
3973 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3974 scpnt = (struct scsi_cmnd *) fsf_req->data;
3975 if (unlikely(!scpnt)) {
3977 ("Command with fsf_req %p is not associated to "
3978 "a scsi command anymore. Aborted?\n", fsf_req);
3981 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3982 /* FIXME: (design) mid-layer should handle DID_ABORT like
3983 * DID_SOFT_ERROR by retrying the request for devices
3984 * that allow retries.
3986 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3987 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3988 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3989 goto skip_fsfstatus;
3992 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3993 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3994 set_host_byte(&scpnt->result, DID_ERROR);
3995 goto skip_fsfstatus;
3998 /* set message byte of result in SCSI command */
3999 scpnt->result |= COMMAND_COMPLETE << 8;
4002 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4003 * of result in SCSI command
4005 scpnt->result |= fcp_rsp_iu->scsi_status;
4006 if (unlikely(fcp_rsp_iu->scsi_status)) {
4008 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4010 scpnt->cmnd, scpnt->cmd_len);
4011 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4012 fcp_rsp_iu->scsi_status);
4013 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4014 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4015 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4016 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4017 fcp_rsp_iu->fcp_sns_len);
4020 /* check FCP_RSP_INFO */
4021 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4022 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4023 switch (fcp_rsp_info[3]) {
4026 ZFCP_LOG_TRACE("no failure or Task Management "
4027 "Function complete\n");
4028 set_host_byte(&scpnt->result, DID_OK);
4030 case RSP_CODE_LENGTH_MISMATCH:
4032 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4033 "that the fibrechannel protocol data "
4034 "length differs from the burst length. "
4035 "The problem occured on unit 0x%016Lx "
4036 "on port 0x%016Lx on adapter %s",
4039 zfcp_get_busid_by_unit(unit));
4040 /* dump SCSI CDB as prepared by zfcp */
4041 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4042 (char *) &fsf_req->qtcb->
4043 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4044 set_host_byte(&scpnt->result, DID_ERROR);
4045 goto skip_fsfstatus;
4046 case RSP_CODE_FIELD_INVALID:
4047 /* driver or hardware bug */
4048 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4049 "that the fibrechannel protocol data "
4050 "fields were incorrectly set up. "
4051 "The problem occured on the unit "
4052 "0x%016Lx on port 0x%016Lx on "
4056 zfcp_get_busid_by_unit(unit));
4057 /* dump SCSI CDB as prepared by zfcp */
4058 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4059 (char *) &fsf_req->qtcb->
4060 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4061 set_host_byte(&scpnt->result, DID_ERROR);
4062 goto skip_fsfstatus;
4063 case RSP_CODE_RO_MISMATCH:
4065 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4066 "that conflicting values for the "
4067 "fibrechannel payload offset from the "
4068 "header were found. "
4069 "The problem occured on unit 0x%016Lx "
4070 "on port 0x%016Lx on adapter %s.\n",
4073 zfcp_get_busid_by_unit(unit));
4074 /* dump SCSI CDB as prepared by zfcp */
4075 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4076 (char *) &fsf_req->qtcb->
4077 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4078 set_host_byte(&scpnt->result, DID_ERROR);
4079 goto skip_fsfstatus;
4081 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4082 "code was detected for a command. "
4083 "The problem occured on the unit "
4084 "0x%016Lx on port 0x%016Lx on "
4085 "adapter %s (debug info 0x%x)\n",
4088 zfcp_get_busid_by_unit(unit),
4090 /* dump SCSI CDB as prepared by zfcp */
4091 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4092 (char *) &fsf_req->qtcb->
4093 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4094 set_host_byte(&scpnt->result, DID_ERROR);
4095 goto skip_fsfstatus;
4099 /* check for sense data */
4100 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4101 sns_len = FSF_FCP_RSP_SIZE -
4102 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4103 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4105 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4106 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4107 SCSI_SENSE_BUFFERSIZE);
4108 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4109 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4111 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4112 (void *) &scpnt->cmnd, scpnt->cmd_len);
4114 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4115 fcp_rsp_iu->fcp_sns_len);
4116 memcpy(&scpnt->sense_buffer,
4117 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4118 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4119 (void *) &scpnt->sense_buffer, sns_len);
4122 /* check for overrun */
4123 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4124 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4125 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4126 "The response data length is "
4127 "%d, the original length was %d.\n",
4130 zfcp_get_busid_by_unit(unit),
4131 fcp_rsp_iu->fcp_resid,
4132 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4135 /* check for underrun */
4136 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4137 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4138 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4139 "The response data length is "
4140 "%d, the original length was %d.\n",
4143 zfcp_get_busid_by_unit(unit),
4144 fcp_rsp_iu->fcp_resid,
4145 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4147 scpnt->resid = fcp_rsp_iu->fcp_resid;
4148 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4149 set_host_byte(&scpnt->result, DID_ERROR);
4153 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4155 if (scpnt->result != 0)
4156 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4157 else if (scpnt->retries > 0)
4158 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4160 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
4162 /* cleanup pointer (need this especially for abort) */
4163 scpnt->host_scribble = NULL;
4165 /* always call back */
4166 (scpnt->scsi_done) (scpnt);
4169 * We must hold this lock until scsi_done has been called.
4170 * Otherwise we may call scsi_done after abort regarding this
4171 * command has completed.
4172 * Note: scsi_done must not block!
4175 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4180 * function: zfcp_fsf_send_fcp_command_task_management_handler
4182 * purpose: evaluates FCP_RSP IU
4187 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4190 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4191 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4192 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4193 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4195 del_timer(&fsf_req->adapter->scsi_er_timer);
4196 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4197 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4198 goto skip_fsfstatus;
4201 /* check FCP_RSP_INFO */
4202 switch (fcp_rsp_info[3]) {
4205 ZFCP_LOG_DEBUG("no failure or Task Management "
4206 "Function complete\n");
4208 case RSP_CODE_TASKMAN_UNSUPP:
4209 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4210 "is not supported on the target device "
4211 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4214 zfcp_get_busid_by_unit(unit));
4215 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4217 case RSP_CODE_TASKMAN_FAILED:
4218 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4219 "failed to complete successfully. "
4220 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4223 zfcp_get_busid_by_unit(unit));
4224 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4227 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4228 "code was detected for a command. "
4229 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4230 "(debug info 0x%x)\n",
4233 zfcp_get_busid_by_unit(unit),
4235 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4244 * function: zfcp_fsf_control_file
4246 * purpose: Initiator of the control file upload/download FSF requests
4248 * returns: 0 - FSF request is successfuly created and queued
4249 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4250 * -EINVAL - Invalid direction specified
4251 * -ENOMEM - Insufficient memory
4252 * -EPERM - Cannot create FSF request or place it in QDIO queue
4255 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4256 struct zfcp_fsf_req **fsf_req_ptr,
4259 struct zfcp_sg_list *sg_list)
4261 struct zfcp_fsf_req *fsf_req;
4262 struct fsf_qtcb_bottom_support *bottom;
4263 volatile struct qdio_buffer_element *sbale;
4264 struct timer_list *timer;
4265 unsigned long lock_flags;
4270 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4271 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4272 zfcp_get_busid_by_adapter(adapter));
4273 retval = -EOPNOTSUPP;
4277 switch (fsf_command) {
4279 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4280 direction = SBAL_FLAGS0_TYPE_WRITE;
4281 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4282 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4283 req_flags = ZFCP_WAIT_FOR_SBAL;
4286 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4287 direction = SBAL_FLAGS0_TYPE_READ;
4291 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4296 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4302 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4303 NULL, &lock_flags, &fsf_req);
4305 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4307 zfcp_get_busid_by_adapter(adapter));
4309 goto unlock_queue_lock;
4312 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4313 sbale[0].flags |= direction;
4315 bottom = &fsf_req->qtcb->bottom.support;
4316 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4317 bottom->option = option;
4319 if (sg_list->count > 0) {
4322 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4323 sg_list->sg, sg_list->count,
4324 ZFCP_MAX_SBALS_PER_REQ);
4325 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4327 "error: Could not create sufficient number of "
4328 "SBALS for an FSF request to the adapter %s\n",
4329 zfcp_get_busid_by_adapter(adapter));
4334 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4337 timer->function = zfcp_fsf_request_timeout_handler;
4338 timer->data = (unsigned long) adapter;
4339 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4341 retval = zfcp_fsf_req_send(fsf_req, timer);
4343 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4345 zfcp_get_busid_by_adapter(adapter));
4349 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4351 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4353 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4354 "download" : "upload",
4355 zfcp_get_busid_by_adapter(adapter));
4357 wait_event(fsf_req->completion_wq,
4358 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4360 *fsf_req_ptr = fsf_req;
4361 del_timer_sync(timer);
4365 zfcp_fsf_req_free(fsf_req);
4367 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4376 * function: zfcp_fsf_control_file_handler
4378 * purpose: Handler of the control file upload/download FSF requests
4380 * returns: 0 - FSF request successfuly processed
4381 * -EAGAIN - Operation has to be repeated because of a temporary problem
4382 * -EACCES - There is no permission to execute an operation
4383 * -EPERM - The control file is not in a right format
4384 * -EIO - There is a problem with the FCP adapter
4385 * -EINVAL - Invalid operation
4386 * -EFAULT - User space memory I/O operation fault
4389 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4391 struct zfcp_adapter *adapter = fsf_req->adapter;
4392 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4393 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4396 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4398 goto skip_fsfstatus;
4401 switch (header->fsf_status) {
4405 "The FSF request has been successfully completed "
4406 "on the adapter %s\n",
4407 zfcp_get_busid_by_adapter(adapter));
4410 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4411 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4412 switch (header->fsf_status_qual.word[0]) {
4414 case FSF_SQ_CFDC_HARDENED_ON_SE:
4416 "CFDC on the adapter %s has being "
4417 "hardened on primary and secondary SE\n",
4418 zfcp_get_busid_by_adapter(adapter));
4421 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4423 "CFDC of the adapter %s could not "
4424 "be saved on the SE\n",
4425 zfcp_get_busid_by_adapter(adapter));
4428 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4430 "CFDC of the adapter %s could not "
4431 "be copied to the secondary SE\n",
4432 zfcp_get_busid_by_adapter(adapter));
4437 "CFDC could not be hardened "
4438 "on the adapter %s\n",
4439 zfcp_get_busid_by_adapter(adapter));
4442 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4446 case FSF_AUTHORIZATION_FAILURE:
4448 "Adapter %s does not accept privileged commands\n",
4449 zfcp_get_busid_by_adapter(adapter));
4450 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4454 case FSF_CFDC_ERROR_DETECTED:
4456 "Error at position %d in the CFDC, "
4457 "CFDC is discarded by the adapter %s\n",
4458 header->fsf_status_qual.word[0],
4459 zfcp_get_busid_by_adapter(adapter));
4460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4464 case FSF_CONTROL_FILE_UPDATE_ERROR:
4466 "Adapter %s cannot harden the control file, "
4467 "file is discarded\n",
4468 zfcp_get_busid_by_adapter(adapter));
4469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4473 case FSF_CONTROL_FILE_TOO_LARGE:
4475 "Control file is too large, file is discarded "
4476 "by the adapter %s\n",
4477 zfcp_get_busid_by_adapter(adapter));
4478 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4482 case FSF_ACCESS_CONFLICT_DETECTED:
4483 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4485 "CFDC has been discarded by the adapter %s, "
4486 "because activation would impact "
4487 "%d active connection(s)\n",
4488 zfcp_get_busid_by_adapter(adapter),
4489 header->fsf_status_qual.word[0]);
4490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4494 case FSF_CONFLICTS_OVERRULED:
4495 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4497 "CFDC has been activated on the adapter %s, "
4498 "but activation has impacted "
4499 "%d active connection(s)\n",
4500 zfcp_get_busid_by_adapter(adapter),
4501 header->fsf_status_qual.word[0]);
4502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4506 case FSF_UNKNOWN_OP_SUBTYPE:
4507 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4508 "op_subtype=0x%x)\n",
4509 zfcp_get_busid_by_adapter(adapter),
4510 bottom->operation_subtype);
4511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4515 case FSF_INVALID_COMMAND_OPTION:
4517 "Invalid option 0x%x has been specified "
4518 "in QTCB bottom sent to the adapter %s\n",
4520 zfcp_get_busid_by_adapter(adapter));
4521 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4527 "bug: An unknown/unexpected FSF status 0x%08x "
4528 "was presented on the adapter %s\n",
4530 zfcp_get_busid_by_adapter(adapter));
4531 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4532 debug_exception(fsf_req->adapter->erp_dbf, 0,
4533 &header->fsf_status_qual.word[0], sizeof(u32));
4534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4544 zfcp_fsf_req_sbal_check(unsigned long *flags,
4545 struct zfcp_qdio_queue *queue, int needed)
4547 write_lock_irqsave(&queue->queue_lock, *flags);
4548 if (likely(atomic_read(&queue->free_count) >= needed))
4550 write_unlock_irqrestore(&queue->queue_lock, *flags);
4555 * set qtcb pointer in fsf_req and initialize QTCB
4558 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4560 if (likely(fsf_req->qtcb != NULL)) {
4561 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4562 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4563 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4564 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4565 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4566 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4567 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4572 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4573 * @adapter: adapter for which request queue is examined
4574 * @req_flags: flags indicating whether to wait for needed SBAL or not
4575 * @lock_flags: lock_flags if queue_lock is taken
4576 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4577 * Locks: lock adapter->request_queue->queue_lock on success
4580 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4581 unsigned long *lock_flags)
4584 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4586 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4587 ret = wait_event_interruptible_timeout(adapter->request_wq,
4588 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4594 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4601 * function: zfcp_fsf_req_create
4603 * purpose: create an FSF request at the specified adapter and
4604 * setup common fields
4606 * returns: -ENOMEM if there was insufficient memory for a request
4607 * -EIO if no qdio buffers could be allocate to the request
4608 * -EINVAL/-EPERM on bug conditions in req_dequeue
4611 * note: The created request is returned by reference.
4613 * locks: lock of concerned request queue must not be held,
4614 * but is held on completion (write, irqsave)
4617 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4618 mempool_t *pool, unsigned long *lock_flags,
4619 struct zfcp_fsf_req **fsf_req_p)
4621 volatile struct qdio_buffer_element *sbale;
4622 struct zfcp_fsf_req *fsf_req = NULL;
4624 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4626 /* allocate new FSF request */
4627 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4628 if (unlikely(NULL == fsf_req)) {
4629 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4630 "the outbound (send) queue.\n");
4632 goto failed_fsf_req;
4635 fsf_req->adapter = adapter;
4636 fsf_req->fsf_command = fsf_cmd;
4638 zfcp_fsf_req_qtcb_init(fsf_req);
4640 /* initialize waitqueue which may be used to wait on
4641 this request completion */
4642 init_waitqueue_head(&fsf_req->completion_wq);
4644 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4650 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4651 * if it is not set (see also *_open_qdio and *_close_qdio).
4654 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4655 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4660 if (fsf_req->qtcb) {
4661 fsf_req->seq_no = adapter->fsf_req_seq_no;
4662 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4664 fsf_req->sbal_number = 1;
4665 fsf_req->sbal_first = req_queue->free_index;
4666 fsf_req->sbal_curr = req_queue->free_index;
4667 fsf_req->sbale_curr = 1;
4669 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4670 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4675 /* setup common SBALE fields */
4676 sbale[0].addr = fsf_req;
4677 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4678 if (likely(fsf_req->qtcb != NULL)) {
4679 sbale[1].addr = (void *) fsf_req->qtcb;
4680 sbale[1].length = sizeof(struct fsf_qtcb);
4683 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4684 fsf_req->sbal_number, fsf_req->sbal_first);
4689 /* dequeue new FSF request previously enqueued */
4690 zfcp_fsf_req_free(fsf_req);
4694 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4696 *fsf_req_p = fsf_req;
4701 * function: zfcp_fsf_req_send
4703 * purpose: start transfer of FSF request via QDIO
4705 * returns: 0 - request transfer succesfully started
4706 * !0 - start of request transfer failed
4709 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4711 struct zfcp_adapter *adapter;
4712 struct zfcp_qdio_queue *req_queue;
4713 volatile struct qdio_buffer_element *sbale;
4715 int new_distance_from_int;
4716 unsigned long flags;
4719 adapter = fsf_req->adapter;
4720 req_queue = &adapter->request_queue,
4723 /* FIXME(debug): remove it later */
4724 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4725 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4726 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4727 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4730 /* put allocated FSF request at list tail */
4731 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4732 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4733 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4735 inc_seq_no = (fsf_req->qtcb != NULL);
4737 /* figure out expiration time of timeout and start timeout */
4738 if (unlikely(timer)) {
4739 timer->expires += jiffies;
4743 ZFCP_LOG_TRACE("request queue of adapter %s: "
4744 "next free SBAL is %i, %i free SBALs\n",
4745 zfcp_get_busid_by_adapter(adapter),
4746 req_queue->free_index,
4747 atomic_read(&req_queue->free_count));
4749 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4750 "index_in_queue=%i, count=%i, buffers=%p\n",
4751 zfcp_get_busid_by_adapter(adapter),
4752 QDIO_FLAG_SYNC_OUTPUT,
4753 0, fsf_req->sbal_first, fsf_req->sbal_number,
4754 &req_queue->buffer[fsf_req->sbal_first]);
4757 * adjust the number of free SBALs in request queue as well as
4758 * position of first one
4760 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4761 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4762 req_queue->free_index += fsf_req->sbal_number; /* increase */
4763 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4764 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4766 fsf_req->issued = get_clock();
4768 retval = do_QDIO(adapter->ccw_device,
4769 QDIO_FLAG_SYNC_OUTPUT,
4770 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4772 if (unlikely(retval)) {
4773 /* Queues are down..... */
4776 * FIXME(potential race):
4777 * timer might be expired (absolutely unlikely)
4781 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4782 list_del(&fsf_req->list);
4783 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4785 * adjust the number of free SBALs in request queue as well as
4786 * position of first one
4788 zfcp_qdio_zero_sbals(req_queue->buffer,
4789 fsf_req->sbal_first, fsf_req->sbal_number);
4790 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4791 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4792 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4793 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4795 ("error: do_QDIO failed. Buffers could not be enqueued "
4796 "to request queue.\n");
4798 req_queue->distance_from_int = new_distance_from_int;
4800 * increase FSF sequence counter -
4801 * this must only be done for request successfully enqueued to
4802 * QDIO this rejected requests may be cleaned up by calling
4803 * routines resulting in missing sequence counter values
4807 /* Don't increase for unsolicited status */
4809 adapter->fsf_req_seq_no++;
4811 /* count FSF requests pending */
4812 atomic_inc(&adapter->fsf_reqs_active);
4817 #undef ZFCP_LOG_AREA