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 /* setup new FSF request */
2195 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2196 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2197 0, &lock_flags, &fsf_req);
2199 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2200 "exchange port data request for"
2201 "the adapter %s.\n",
2202 zfcp_get_busid_by_adapter(adapter));
2203 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2209 fsf_req->data = (unsigned long) data;
2211 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2212 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2213 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2216 erp_action->fsf_req = fsf_req;
2217 fsf_req->erp_action = erp_action;
2218 timer = &erp_action->timer;
2220 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2222 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2224 zfcp_fsf_req_free(fsf_req);
2228 timer->function = zfcp_fsf_request_timeout_handler;
2229 timer->data = (unsigned long) adapter;
2230 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2233 retval = zfcp_fsf_req_send(fsf_req, timer);
2235 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2236 "command on the adapter %s\n",
2237 zfcp_get_busid_by_adapter(adapter));
2238 zfcp_fsf_req_free(fsf_req);
2240 erp_action->fsf_req = NULL;
2243 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2248 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2251 wait_event(fsf_req->completion_wq,
2252 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2253 del_timer_sync(timer);
2254 zfcp_fsf_req_free(fsf_req);
2262 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2263 * @fsf_req: pointer to struct zfcp_fsf_req
2266 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2268 struct zfcp_adapter *adapter = fsf_req->adapter;
2269 struct Scsi_Host *shost = adapter->scsi_host;
2270 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2271 struct fsf_qtcb_bottom_port *bottom, *data;
2273 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2276 switch (qtcb->header.fsf_status) {
2278 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2280 bottom = &qtcb->bottom.port;
2281 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2283 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2284 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
2285 adapter->physical_wwpn = bottom->wwpn;
2286 adapter->physical_s_id = bottom->fc_port_id;
2288 adapter->physical_wwpn = fc_host_port_name(shost);
2289 adapter->physical_s_id = fc_host_port_id(shost);
2291 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2294 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2295 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2297 zfcp_fsf_link_down_info_eval(adapter,
2298 &qtcb->header.fsf_status_qual.link_down_info);
2302 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2303 debug_event(adapter->erp_dbf, 0,
2304 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2310 * function: zfcp_fsf_open_port
2314 * returns: address of initiated FSF request
2315 * NULL - request could not be initiated
2318 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2320 volatile struct qdio_buffer_element *sbale;
2321 unsigned long lock_flags;
2324 /* setup new FSF request */
2325 retval = zfcp_fsf_req_create(erp_action->adapter,
2326 FSF_QTCB_OPEN_PORT_WITH_DID,
2327 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2328 erp_action->adapter->pool.fsf_req_erp,
2329 &lock_flags, &(erp_action->fsf_req));
2331 ZFCP_LOG_INFO("error: Could not create open port request "
2332 "for port 0x%016Lx on adapter %s.\n",
2333 erp_action->port->wwpn,
2334 zfcp_get_busid_by_adapter(erp_action->adapter));
2338 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2339 erp_action->fsf_req->sbal_curr, 0);
2340 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2341 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2343 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2344 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2345 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2346 erp_action->fsf_req->erp_action = erp_action;
2348 /* start QDIO request for this FSF request */
2349 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2351 ZFCP_LOG_INFO("error: Could not send open port request for "
2352 "port 0x%016Lx on adapter %s.\n",
2353 erp_action->port->wwpn,
2354 zfcp_get_busid_by_adapter(erp_action->adapter));
2355 zfcp_fsf_req_free(erp_action->fsf_req);
2356 erp_action->fsf_req = NULL;
2360 ZFCP_LOG_DEBUG("open port request initiated "
2361 "(adapter %s, port 0x%016Lx)\n",
2362 zfcp_get_busid_by_adapter(erp_action->adapter),
2363 erp_action->port->wwpn);
2365 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2371 * function: zfcp_fsf_open_port_handler
2373 * purpose: is called for finished Open Port command
2378 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2380 int retval = -EINVAL;
2381 struct zfcp_port *port;
2382 struct fsf_plogi *plogi;
2383 struct fsf_qtcb_header *header;
2384 u16 subtable, rule, counter;
2386 port = (struct zfcp_port *) fsf_req->data;
2387 header = &fsf_req->qtcb->header;
2389 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2390 /* don't change port status in our bookkeeping */
2391 goto skip_fsfstatus;
2394 /* evaluate FSF status in QTCB */
2395 switch (header->fsf_status) {
2397 case FSF_PORT_ALREADY_OPEN:
2398 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2399 "is already open.\n",
2400 port->wwpn, zfcp_get_busid_by_port(port));
2401 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2404 * This is a bug, however operation should continue normally
2405 * if it is simply ignored
2409 case FSF_ACCESS_DENIED:
2410 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2412 port->wwpn, zfcp_get_busid_by_port(port));
2413 for (counter = 0; counter < 2; counter++) {
2414 subtable = header->fsf_status_qual.halfword[counter * 2];
2415 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2417 case FSF_SQ_CFDC_SUBTABLE_OS:
2418 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2419 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2420 case FSF_SQ_CFDC_SUBTABLE_LUN:
2421 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2422 zfcp_act_subtable_type[subtable], rule);
2426 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2427 zfcp_erp_port_access_denied(port);
2428 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2431 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2432 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2433 "The remote port 0x%016Lx on adapter %s "
2434 "could not be opened. Disabling it.\n",
2435 port->wwpn, zfcp_get_busid_by_port(port));
2436 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2438 zfcp_erp_port_failed(port);
2439 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2442 case FSF_ADAPTER_STATUS_AVAILABLE:
2443 switch (header->fsf_status_qual.word[0]) {
2444 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2445 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2447 /* ERP strategy will escalate */
2448 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2450 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2451 /* ERP strategy will escalate */
2452 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2454 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2456 case FSF_SQ_NO_RETRY_POSSIBLE:
2457 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2458 "adapter %s could not be opened. "
2461 zfcp_get_busid_by_port(port));
2462 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2464 zfcp_erp_port_failed(port);
2465 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2469 ("bug: Wrong status qualifier 0x%x arrived.\n",
2470 header->fsf_status_qual.word[0]);
2471 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2474 fsf_req->adapter->erp_dbf, 0,
2475 &header->fsf_status_qual.word[0],
2482 /* save port handle assigned by FSF */
2483 port->handle = header->port_handle;
2484 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2485 "was opened, it's port handle is 0x%x\n",
2486 port->wwpn, zfcp_get_busid_by_port(port),
2488 /* mark port as open */
2489 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2490 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2491 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2492 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2495 /* check whether D_ID has changed during open */
2497 * FIXME: This check is not airtight, as the FCP channel does
2498 * not monitor closures of target port connections caused on
2499 * the remote side. Thus, they might miss out on invalidating
2500 * locally cached WWPNs (and other N_Port parameters) of gone
2501 * target ports. So, our heroic attempt to make things safe
2502 * could be undermined by 'open port' response data tagged with
2503 * obsolete WWPNs. Another reason to monitor potential
2504 * connection closures ourself at least (by interpreting
2505 * incoming ELS' and unsolicited status). It just crosses my
2506 * mind that one should be able to cross-check by means of
2507 * another GID_PN straight after a port has been opened.
2508 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2510 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2511 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2513 if (fsf_req->qtcb->bottom.support.els1_length <
2514 ((((unsigned long) &plogi->serv_param.wwpn) -
2515 ((unsigned long) plogi)) + sizeof (u64))) {
2517 "warning: insufficient length of "
2518 "PLOGI payload (%i)\n",
2519 fsf_req->qtcb->bottom.support.els1_length);
2520 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2521 "fsf_s_short_plogi:");
2522 /* skip sanity check and assume wwpn is ok */
2524 if (plogi->serv_param.wwpn != port->wwpn) {
2525 ZFCP_LOG_INFO("warning: d_id of port "
2526 "0x%016Lx changed during "
2527 "open\n", port->wwpn);
2529 fsf_req->adapter->erp_dbf, 0,
2530 "fsf_s_did_change:");
2532 ZFCP_STATUS_PORT_DID_DID,
2535 port->wwnn = plogi->serv_param.wwnn;
2540 case FSF_UNKNOWN_OP_SUBTYPE:
2541 /* should never occure, subtype not set in zfcp_fsf_open_port */
2542 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2543 "op_subtype=0x%x)\n",
2544 zfcp_get_busid_by_port(port),
2545 fsf_req->qtcb->bottom.support.operation_subtype);
2546 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2550 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2551 "(debug info 0x%x)\n",
2552 header->fsf_status);
2553 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2554 debug_exception(fsf_req->adapter->erp_dbf, 0,
2555 &header->fsf_status, sizeof (u32));
2560 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2565 * function: zfcp_fsf_close_port
2567 * purpose: submit FSF command "close port"
2569 * returns: address of initiated FSF request
2570 * NULL - request could not be initiated
2573 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2575 volatile struct qdio_buffer_element *sbale;
2576 unsigned long lock_flags;
2579 /* setup new FSF request */
2580 retval = zfcp_fsf_req_create(erp_action->adapter,
2581 FSF_QTCB_CLOSE_PORT,
2582 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2583 erp_action->adapter->pool.fsf_req_erp,
2584 &lock_flags, &(erp_action->fsf_req));
2586 ZFCP_LOG_INFO("error: Could not create a close port request "
2587 "for port 0x%016Lx on adapter %s.\n",
2588 erp_action->port->wwpn,
2589 zfcp_get_busid_by_adapter(erp_action->adapter));
2593 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2594 erp_action->fsf_req->sbal_curr, 0);
2595 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2596 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2598 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2599 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2600 erp_action->fsf_req->erp_action = erp_action;
2601 erp_action->fsf_req->qtcb->header.port_handle =
2602 erp_action->port->handle;
2604 /* start QDIO request for this FSF request */
2605 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2607 ZFCP_LOG_INFO("error: Could not send a close port request for "
2608 "port 0x%016Lx on adapter %s.\n",
2609 erp_action->port->wwpn,
2610 zfcp_get_busid_by_adapter(erp_action->adapter));
2611 zfcp_fsf_req_free(erp_action->fsf_req);
2612 erp_action->fsf_req = NULL;
2616 ZFCP_LOG_TRACE("close port request initiated "
2617 "(adapter %s, port 0x%016Lx)\n",
2618 zfcp_get_busid_by_adapter(erp_action->adapter),
2619 erp_action->port->wwpn);
2621 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2627 * function: zfcp_fsf_close_port_handler
2629 * purpose: is called for finished Close Port FSF command
2634 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2636 int retval = -EINVAL;
2637 struct zfcp_port *port;
2639 port = (struct zfcp_port *) fsf_req->data;
2641 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2642 /* don't change port status in our bookkeeping */
2643 goto skip_fsfstatus;
2646 /* evaluate FSF status in QTCB */
2647 switch (fsf_req->qtcb->header.fsf_status) {
2649 case FSF_PORT_HANDLE_NOT_VALID:
2650 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2651 "0x%016Lx on adapter %s invalid. This may happen "
2652 "occasionally.\n", port->handle,
2653 port->wwpn, zfcp_get_busid_by_port(port));
2654 ZFCP_LOG_DEBUG("status qualifier:\n");
2655 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2656 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2657 sizeof (union fsf_status_qual));
2658 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2660 zfcp_erp_adapter_reopen(port->adapter, 0);
2661 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2664 case FSF_ADAPTER_STATUS_AVAILABLE:
2665 /* Note: FSF has actually closed the port in this case.
2666 * The status code is just daft. Fingers crossed for a change
2672 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2673 "port handle 0x%x\n", port->wwpn,
2674 zfcp_get_busid_by_port(port), port->handle);
2675 zfcp_erp_modify_port_status(port,
2676 ZFCP_STATUS_COMMON_OPEN,
2682 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2683 "(debug info 0x%x)\n",
2684 fsf_req->qtcb->header.fsf_status);
2685 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2686 debug_exception(fsf_req->adapter->erp_dbf, 0,
2687 &fsf_req->qtcb->header.fsf_status,
2693 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2698 * function: zfcp_fsf_close_physical_port
2700 * purpose: submit FSF command "close physical port"
2702 * returns: address of initiated FSF request
2703 * NULL - request could not be initiated
2706 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2709 unsigned long lock_flags;
2710 volatile struct qdio_buffer_element *sbale;
2712 /* setup new FSF request */
2713 retval = zfcp_fsf_req_create(erp_action->adapter,
2714 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2715 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2716 erp_action->adapter->pool.fsf_req_erp,
2717 &lock_flags, &erp_action->fsf_req);
2719 ZFCP_LOG_INFO("error: Could not create close physical port "
2720 "request (adapter %s, port 0x%016Lx)\n",
2721 zfcp_get_busid_by_adapter(erp_action->adapter),
2722 erp_action->port->wwpn);
2727 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2728 erp_action->fsf_req->sbal_curr, 0);
2729 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2730 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2732 /* mark port as being closed */
2733 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2734 &erp_action->port->status);
2735 /* save a pointer to this port */
2736 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2737 /* port to be closed */
2738 erp_action->fsf_req->qtcb->header.port_handle =
2739 erp_action->port->handle;
2740 erp_action->fsf_req->erp_action = erp_action;
2742 /* start QDIO request for this FSF request */
2743 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2745 ZFCP_LOG_INFO("error: Could not send close physical port "
2746 "request (adapter %s, port 0x%016Lx)\n",
2747 zfcp_get_busid_by_adapter(erp_action->adapter),
2748 erp_action->port->wwpn);
2749 zfcp_fsf_req_free(erp_action->fsf_req);
2750 erp_action->fsf_req = NULL;
2754 ZFCP_LOG_TRACE("close physical port request initiated "
2755 "(adapter %s, port 0x%016Lx)\n",
2756 zfcp_get_busid_by_adapter(erp_action->adapter),
2757 erp_action->port->wwpn);
2759 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2765 * function: zfcp_fsf_close_physical_port_handler
2767 * purpose: is called for finished Close Physical Port FSF command
2772 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2774 int retval = -EINVAL;
2775 struct zfcp_port *port;
2776 struct zfcp_unit *unit;
2777 struct fsf_qtcb_header *header;
2778 u16 subtable, rule, counter;
2780 port = (struct zfcp_port *) fsf_req->data;
2781 header = &fsf_req->qtcb->header;
2783 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2784 /* don't change port status in our bookkeeping */
2785 goto skip_fsfstatus;
2788 /* evaluate FSF status in QTCB */
2789 switch (header->fsf_status) {
2791 case FSF_PORT_HANDLE_NOT_VALID:
2792 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2793 "(adapter %s, port 0x%016Lx). "
2794 "This may happen occasionally.\n",
2796 zfcp_get_busid_by_port(port),
2798 ZFCP_LOG_DEBUG("status qualifier:\n");
2799 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2800 (char *) &header->fsf_status_qual,
2801 sizeof (union fsf_status_qual));
2802 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2804 zfcp_erp_adapter_reopen(port->adapter, 0);
2805 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2808 case FSF_ACCESS_DENIED:
2809 ZFCP_LOG_NORMAL("Access denied, cannot close "
2810 "physical port 0x%016Lx on adapter %s\n",
2811 port->wwpn, zfcp_get_busid_by_port(port));
2812 for (counter = 0; counter < 2; counter++) {
2813 subtable = header->fsf_status_qual.halfword[counter * 2];
2814 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2816 case FSF_SQ_CFDC_SUBTABLE_OS:
2817 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2818 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2819 case FSF_SQ_CFDC_SUBTABLE_LUN:
2820 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2821 zfcp_act_subtable_type[subtable], rule);
2825 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2826 zfcp_erp_port_access_denied(port);
2827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2830 case FSF_PORT_BOXED:
2831 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2832 "%s needs to be reopened but it was attempted "
2833 "to close it physically.\n",
2835 zfcp_get_busid_by_port(port));
2836 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2837 zfcp_erp_port_boxed(port);
2838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2839 ZFCP_STATUS_FSFREQ_RETRY;
2842 case FSF_ADAPTER_STATUS_AVAILABLE:
2843 switch (header->fsf_status_qual.word[0]) {
2844 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2845 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2847 /* This will now be escalated by ERP */
2848 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2850 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2851 /* ERP strategy will escalate */
2852 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2854 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2858 ("bug: Wrong status qualifier 0x%x arrived.\n",
2859 header->fsf_status_qual.word[0]);
2860 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2863 fsf_req->adapter->erp_dbf, 0,
2864 &header->fsf_status_qual.word[0], sizeof (u32));
2870 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2871 "physically closed, port handle 0x%x\n",
2873 zfcp_get_busid_by_port(port), port->handle);
2874 /* can't use generic zfcp_erp_modify_port_status because
2875 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2877 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2878 list_for_each_entry(unit, &port->unit_list_head, list)
2879 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2884 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2885 "(debug info 0x%x)\n",
2886 header->fsf_status);
2887 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2888 debug_exception(fsf_req->adapter->erp_dbf, 0,
2889 &header->fsf_status, sizeof (u32));
2894 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2899 * function: zfcp_fsf_open_unit
2905 * assumptions: This routine does not check whether the associated
2906 * remote port has already been opened. This should be
2907 * done by calling routines. Otherwise some status
2908 * may be presented by FSF
2911 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2913 volatile struct qdio_buffer_element *sbale;
2914 unsigned long lock_flags;
2917 /* setup new FSF request */
2918 retval = zfcp_fsf_req_create(erp_action->adapter,
2920 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2921 erp_action->adapter->pool.fsf_req_erp,
2922 &lock_flags, &(erp_action->fsf_req));
2924 ZFCP_LOG_INFO("error: Could not create open unit request for "
2925 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2926 erp_action->unit->fcp_lun,
2927 erp_action->unit->port->wwpn,
2928 zfcp_get_busid_by_adapter(erp_action->adapter));
2932 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2933 erp_action->fsf_req->sbal_curr, 0);
2934 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2935 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2937 erp_action->fsf_req->qtcb->header.port_handle =
2938 erp_action->port->handle;
2939 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2940 erp_action->unit->fcp_lun;
2941 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2942 erp_action->fsf_req->qtcb->bottom.support.option =
2943 FSF_OPEN_LUN_SUPPRESS_BOXING;
2944 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2945 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
2946 erp_action->fsf_req->erp_action = erp_action;
2948 /* start QDIO request for this FSF request */
2949 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2951 ZFCP_LOG_INFO("error: Could not send an open unit request "
2952 "on the adapter %s, port 0x%016Lx for "
2954 zfcp_get_busid_by_adapter(erp_action->adapter),
2955 erp_action->port->wwpn,
2956 erp_action->unit->fcp_lun);
2957 zfcp_fsf_req_free(erp_action->fsf_req);
2958 erp_action->fsf_req = NULL;
2962 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2963 "port 0x%016Lx, unit 0x%016Lx)\n",
2964 zfcp_get_busid_by_adapter(erp_action->adapter),
2965 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2967 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2973 * function: zfcp_fsf_open_unit_handler
2975 * purpose: is called for finished Open LUN command
2980 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2982 int retval = -EINVAL;
2983 struct zfcp_adapter *adapter;
2984 struct zfcp_unit *unit;
2985 struct fsf_qtcb_header *header;
2986 struct fsf_qtcb_bottom_support *bottom;
2987 struct fsf_queue_designator *queue_designator;
2988 u16 subtable, rule, counter;
2989 int exclusive, readwrite;
2991 unit = (struct zfcp_unit *) fsf_req->data;
2993 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2994 /* don't change unit status in our bookkeeping */
2995 goto skip_fsfstatus;
2998 adapter = fsf_req->adapter;
2999 header = &fsf_req->qtcb->header;
3000 bottom = &fsf_req->qtcb->bottom.support;
3001 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3003 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3004 ZFCP_STATUS_UNIT_SHARED |
3005 ZFCP_STATUS_UNIT_READONLY,
3008 /* evaluate FSF status in QTCB */
3009 switch (header->fsf_status) {
3011 case FSF_PORT_HANDLE_NOT_VALID:
3012 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3013 "for port 0x%016Lx on adapter %s invalid "
3014 "This may happen occasionally\n",
3016 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3017 ZFCP_LOG_DEBUG("status qualifier:\n");
3018 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3019 (char *) &header->fsf_status_qual,
3020 sizeof (union fsf_status_qual));
3021 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3022 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3023 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3026 case FSF_LUN_ALREADY_OPEN:
3027 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3028 "remote port 0x%016Lx on adapter %s twice.\n",
3030 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3031 debug_text_exception(adapter->erp_dbf, 0,
3033 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3036 case FSF_ACCESS_DENIED:
3037 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3038 "remote port 0x%016Lx on adapter %s\n",
3039 unit->fcp_lun, unit->port->wwpn,
3040 zfcp_get_busid_by_unit(unit));
3041 for (counter = 0; counter < 2; counter++) {
3042 subtable = header->fsf_status_qual.halfword[counter * 2];
3043 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3045 case FSF_SQ_CFDC_SUBTABLE_OS:
3046 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3047 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3048 case FSF_SQ_CFDC_SUBTABLE_LUN:
3049 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3050 zfcp_act_subtable_type[subtable], rule);
3054 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3055 zfcp_erp_unit_access_denied(unit);
3056 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3057 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3058 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3061 case FSF_PORT_BOXED:
3062 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3063 "needs to be reopened\n",
3064 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3065 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3066 zfcp_erp_port_boxed(unit->port);
3067 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3068 ZFCP_STATUS_FSFREQ_RETRY;
3071 case FSF_LUN_SHARING_VIOLATION:
3072 if (header->fsf_status_qual.word[0] != 0) {
3073 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3075 "connected to the adapter %s "
3076 "is already in use in LPAR%d, CSS%d\n",
3079 zfcp_get_busid_by_unit(unit),
3080 queue_designator->hla,
3081 queue_designator->cssid);
3083 subtable = header->fsf_status_qual.halfword[4];
3084 rule = header->fsf_status_qual.halfword[5];
3086 case FSF_SQ_CFDC_SUBTABLE_OS:
3087 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3088 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3089 case FSF_SQ_CFDC_SUBTABLE_LUN:
3090 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3091 "remote port with WWPN 0x%Lx "
3092 "connected to the adapter %s "
3093 "is denied (%s rule %d)\n",
3096 zfcp_get_busid_by_unit(unit),
3097 zfcp_act_subtable_type[subtable],
3102 ZFCP_LOG_DEBUG("status qualifier:\n");
3103 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3104 (char *) &header->fsf_status_qual,
3105 sizeof (union fsf_status_qual));
3106 debug_text_event(adapter->erp_dbf, 2,
3108 zfcp_erp_unit_access_denied(unit);
3109 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3110 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3111 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3114 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3115 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3116 "There is no handle (temporary port identifier) "
3117 "available for unit 0x%016Lx on port 0x%016Lx "
3121 zfcp_get_busid_by_unit(unit));
3122 debug_text_event(adapter->erp_dbf, 1,
3124 zfcp_erp_unit_failed(unit);
3125 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3128 case FSF_ADAPTER_STATUS_AVAILABLE:
3129 switch (header->fsf_status_qual.word[0]) {
3130 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3131 /* Re-establish link to port */
3132 debug_text_event(adapter->erp_dbf, 1,
3134 zfcp_test_link(unit->port);
3135 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3137 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3138 /* ERP strategy will escalate */
3139 debug_text_event(adapter->erp_dbf, 1,
3141 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3145 ("bug: Wrong status qualifier 0x%x arrived.\n",
3146 header->fsf_status_qual.word[0]);
3147 debug_text_event(adapter->erp_dbf, 0,
3149 debug_exception(adapter->erp_dbf, 0,
3150 &header->fsf_status_qual.word[0],
3155 case FSF_INVALID_COMMAND_OPTION:
3157 "Invalid option 0x%x has been specified "
3158 "in QTCB bottom sent to the adapter %s\n",
3160 zfcp_get_busid_by_adapter(adapter));
3161 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3166 /* save LUN handle assigned by FSF */
3167 unit->handle = header->lun_handle;
3168 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3169 "adapter %s opened, port handle 0x%x\n",
3172 zfcp_get_busid_by_unit(unit),
3174 /* mark unit as open */
3175 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3177 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3178 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3179 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3180 exclusive = (bottom->lun_access_info &
3181 FSF_UNIT_ACCESS_EXCLUSIVE);
3182 readwrite = (bottom->lun_access_info &
3183 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3186 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3190 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3192 ZFCP_LOG_NORMAL("read-only access for unit "
3193 "(adapter %s, wwpn=0x%016Lx, "
3194 "fcp_lun=0x%016Lx)\n",
3195 zfcp_get_busid_by_unit(unit),
3200 if (exclusive && !readwrite) {
3201 ZFCP_LOG_NORMAL("exclusive access of read-only "
3202 "unit not supported\n");
3203 zfcp_erp_unit_failed(unit);
3204 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3205 zfcp_erp_unit_shutdown(unit, 0);
3206 } else if (!exclusive && readwrite) {
3207 ZFCP_LOG_NORMAL("shared access of read-write "
3208 "unit not supported\n");
3209 zfcp_erp_unit_failed(unit);
3210 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3211 zfcp_erp_unit_shutdown(unit, 0);
3219 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3220 "(debug info 0x%x)\n",
3221 header->fsf_status);
3222 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3223 debug_exception(adapter->erp_dbf, 0,
3224 &header->fsf_status, sizeof (u32));
3229 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3234 * function: zfcp_fsf_close_unit
3238 * returns: address of fsf_req - request successfully initiated
3241 * assumptions: This routine does not check whether the associated
3242 * remote port/lun has already been opened. This should be
3243 * done by calling routines. Otherwise some status
3244 * may be presented by FSF
3247 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3249 volatile struct qdio_buffer_element *sbale;
3250 unsigned long lock_flags;
3253 /* setup new FSF request */
3254 retval = zfcp_fsf_req_create(erp_action->adapter,
3256 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3257 erp_action->adapter->pool.fsf_req_erp,
3258 &lock_flags, &(erp_action->fsf_req));
3260 ZFCP_LOG_INFO("error: Could not create close unit request for "
3261 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3262 erp_action->unit->fcp_lun,
3263 erp_action->port->wwpn,
3264 zfcp_get_busid_by_adapter(erp_action->adapter));
3268 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3269 erp_action->fsf_req->sbal_curr, 0);
3270 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3271 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3273 erp_action->fsf_req->qtcb->header.port_handle =
3274 erp_action->port->handle;
3275 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3276 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3277 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3278 erp_action->fsf_req->erp_action = erp_action;
3280 /* start QDIO request for this FSF request */
3281 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3283 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3284 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3285 erp_action->unit->fcp_lun,
3286 erp_action->port->wwpn,
3287 zfcp_get_busid_by_adapter(erp_action->adapter));
3288 zfcp_fsf_req_free(erp_action->fsf_req);
3289 erp_action->fsf_req = NULL;
3293 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3294 "port 0x%016Lx, unit 0x%016Lx)\n",
3295 zfcp_get_busid_by_adapter(erp_action->adapter),
3296 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3298 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3304 * function: zfcp_fsf_close_unit_handler
3306 * purpose: is called for finished Close LUN FSF command
3311 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3313 int retval = -EINVAL;
3314 struct zfcp_unit *unit;
3316 unit = (struct zfcp_unit *) fsf_req->data;
3318 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3319 /* don't change unit status in our bookkeeping */
3320 goto skip_fsfstatus;
3323 /* evaluate FSF status in QTCB */
3324 switch (fsf_req->qtcb->header.fsf_status) {
3326 case FSF_PORT_HANDLE_NOT_VALID:
3327 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3328 "0x%016Lx on adapter %s invalid. This may "
3329 "happen in rare circumstances\n",
3332 zfcp_get_busid_by_unit(unit));
3333 ZFCP_LOG_DEBUG("status qualifier:\n");
3334 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3335 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3336 sizeof (union fsf_status_qual));
3337 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3339 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3340 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3343 case FSF_LUN_HANDLE_NOT_VALID:
3344 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3345 "0x%016Lx on port 0x%016Lx on adapter %s is "
3346 "invalid. This may happen occasionally.\n",
3350 zfcp_get_busid_by_unit(unit));
3351 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3352 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3353 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3354 sizeof (union fsf_status_qual));
3355 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3357 zfcp_erp_port_reopen(unit->port, 0);
3358 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3361 case FSF_PORT_BOXED:
3362 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3363 "needs to be reopened\n",
3365 zfcp_get_busid_by_unit(unit));
3366 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3367 zfcp_erp_port_boxed(unit->port);
3368 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3369 ZFCP_STATUS_FSFREQ_RETRY;
3372 case FSF_ADAPTER_STATUS_AVAILABLE:
3373 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3374 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3375 /* re-establish link to port */
3376 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3378 zfcp_test_link(unit->port);
3379 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3381 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3382 /* ERP strategy will escalate */
3383 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3385 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3389 ("bug: Wrong status qualifier 0x%x arrived.\n",
3390 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3391 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3394 fsf_req->adapter->erp_dbf, 0,
3395 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3402 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3403 "closed, port handle 0x%x\n",
3406 zfcp_get_busid_by_unit(unit),
3408 /* mark unit as closed */
3409 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3414 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3415 "(debug info 0x%x)\n",
3416 fsf_req->qtcb->header.fsf_status);
3417 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3418 debug_exception(fsf_req->adapter->erp_dbf, 0,
3419 &fsf_req->qtcb->header.fsf_status,
3425 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3430 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3431 * @adapter: adapter where scsi command is issued
3432 * @unit: unit where command is sent to
3433 * @scsi_cmnd: scsi command to be sent
3434 * @timer: timer to be started when request is initiated
3435 * @req_flags: flags for fsf_request
3438 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3439 struct zfcp_unit *unit,
3440 struct scsi_cmnd * scsi_cmnd,
3441 struct timer_list *timer, int req_flags)
3443 struct zfcp_fsf_req *fsf_req = NULL;
3444 struct fcp_cmnd_iu *fcp_cmnd_iu;
3445 unsigned int sbtype;
3446 unsigned long lock_flags;
3451 /* setup new FSF request */
3452 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3453 adapter->pool.fsf_req_scsi,
3454 &lock_flags, &fsf_req);
3455 if (unlikely(retval < 0)) {
3456 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3457 "for unit 0x%016Lx on port 0x%016Lx on "
3461 zfcp_get_busid_by_adapter(adapter));
3462 goto failed_req_create;
3465 zfcp_unit_get(unit);
3466 fsf_req->unit = unit;
3468 /* associate FSF request with SCSI request (for look up on abort) */
3469 scsi_cmnd->host_scribble = (char *) fsf_req;
3471 /* associate SCSI command with FSF request */
3472 fsf_req->data = (unsigned long) scsi_cmnd;
3474 /* set handles of unit and its parent port in QTCB */
3475 fsf_req->qtcb->header.lun_handle = unit->handle;
3476 fsf_req->qtcb->header.port_handle = unit->port->handle;
3478 /* FSF does not define the structure of the FCP_CMND IU */
3479 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3480 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3483 * set depending on data direction:
3484 * data direction bits in SBALE (SB Type)
3485 * data direction bits in QTCB
3486 * data direction bits in FCP_CMND IU
3488 switch (scsi_cmnd->sc_data_direction) {
3490 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3493 * what is the correct type for commands
3494 * without 'real' data buffers?
3496 sbtype = SBAL_FLAGS0_TYPE_READ;
3498 case DMA_FROM_DEVICE:
3499 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3500 sbtype = SBAL_FLAGS0_TYPE_READ;
3501 fcp_cmnd_iu->rddata = 1;
3504 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3505 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3506 fcp_cmnd_iu->wddata = 1;
3508 case DMA_BIDIRECTIONAL:
3511 * dummy, catch this condition earlier
3512 * in zfcp_scsi_queuecommand
3514 goto failed_scsi_cmnd;
3517 /* set FC service class in QTCB (3 per default) */
3518 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3520 /* set FCP_LUN in FCP_CMND IU in QTCB */
3521 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3523 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3525 /* set task attributes in FCP_CMND IU in QTCB */
3526 if (likely((scsi_cmnd->device->simple_tags) ||
3527 (atomic_test_mask(mask, &unit->status))))
3528 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3530 fcp_cmnd_iu->task_attribute = UNTAGGED;
3532 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3533 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3534 fcp_cmnd_iu->add_fcp_cdb_length
3535 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3536 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3537 "additional FCP_CDB length is 0x%x "
3538 "(shifted right 2 bits)\n",
3540 fcp_cmnd_iu->add_fcp_cdb_length);
3543 * copy SCSI CDB (including additional length, if any) to
3544 * FCP_CDB in FCP_CMND IU in QTCB
3546 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3548 /* FCP CMND IU length in QTCB */
3549 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3550 sizeof (struct fcp_cmnd_iu) +
3551 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3553 /* generate SBALEs from data buffer */
3554 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3555 if (unlikely(real_bytes < 0)) {
3556 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3558 "Data did not fit into available buffer(s), "
3559 "waiting for more...\n");
3562 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3563 "required. Shutting down unit "
3564 "(adapter %s, port 0x%016Lx, "
3566 zfcp_get_busid_by_unit(unit),
3569 zfcp_erp_unit_shutdown(unit, 0);
3575 /* set length of FCP data length in FCP_CMND IU in QTCB */
3576 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3578 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3579 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3580 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3583 * start QDIO request for this FSF request
3584 * covered by an SBALE)
3586 retval = zfcp_fsf_req_send(fsf_req, timer);
3587 if (unlikely(retval < 0)) {
3588 ZFCP_LOG_INFO("error: Could not send FCP command request "
3589 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3590 zfcp_get_busid_by_adapter(adapter),
3596 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3597 "port 0x%016Lx, unit 0x%016Lx)\n",
3598 zfcp_get_busid_by_adapter(adapter),
3606 zfcp_unit_put(unit);
3607 zfcp_fsf_req_free(fsf_req);
3609 scsi_cmnd->host_scribble = NULL;
3612 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3617 * function: zfcp_fsf_send_fcp_command_task_management
3623 * FIXME(design): should be watched by a timeout!!!
3624 * FIXME(design) shouldn't this be modified to return an int
3625 * also...don't know how though
3628 struct zfcp_fsf_req *
3629 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3630 struct zfcp_unit *unit,
3631 u8 tm_flags, int req_flags)
3633 struct zfcp_fsf_req *fsf_req = NULL;
3635 struct fcp_cmnd_iu *fcp_cmnd_iu;
3636 unsigned long lock_flags;
3637 volatile struct qdio_buffer_element *sbale;
3639 /* setup new FSF request */
3640 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3641 adapter->pool.fsf_req_scsi,
3642 &lock_flags, &fsf_req);
3644 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3645 "management) request for adapter %s, port "
3646 " 0x%016Lx, unit 0x%016Lx.\n",
3647 zfcp_get_busid_by_adapter(adapter),
3648 unit->port->wwpn, unit->fcp_lun);
3653 * Used to decide on proper handler in the return path,
3654 * could be either zfcp_fsf_send_fcp_command_task_handler or
3655 * zfcp_fsf_send_fcp_command_task_management_handler */
3657 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3660 * hold a pointer to the unit being target of this
3661 * task management request
3663 fsf_req->data = (unsigned long) unit;
3665 /* set FSF related fields in QTCB */
3666 fsf_req->qtcb->header.lun_handle = unit->handle;
3667 fsf_req->qtcb->header.port_handle = unit->port->handle;
3668 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3669 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3670 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3671 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3674 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3675 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3677 /* set FCP related fields in FCP_CMND IU in QTCB */
3678 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3679 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3680 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3681 fcp_cmnd_iu->task_management_flags = tm_flags;
3683 /* start QDIO request for this FSF request */
3684 zfcp_fsf_start_scsi_er_timer(adapter);
3685 retval = zfcp_fsf_req_send(fsf_req, NULL);
3687 del_timer(&adapter->scsi_er_timer);
3688 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3689 "management) on adapter %s, port 0x%016Lx for "
3690 "unit LUN 0x%016Lx\n",
3691 zfcp_get_busid_by_adapter(adapter),
3694 zfcp_fsf_req_free(fsf_req);
3699 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3700 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3702 zfcp_get_busid_by_adapter(adapter),
3707 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3712 * function: zfcp_fsf_send_fcp_command_handler
3714 * purpose: is called for finished Send FCP Command
3719 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3721 int retval = -EINVAL;
3722 struct zfcp_unit *unit;
3723 struct fsf_qtcb_header *header;
3724 u16 subtable, rule, counter;
3726 header = &fsf_req->qtcb->header;
3728 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3729 unit = (struct zfcp_unit *) fsf_req->data;
3731 unit = fsf_req->unit;
3733 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3734 /* go directly to calls of special handlers */
3735 goto skip_fsfstatus;
3738 /* evaluate FSF status in QTCB */
3739 switch (header->fsf_status) {
3741 case FSF_PORT_HANDLE_NOT_VALID:
3742 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3743 "0x%016Lx on adapter %s invalid\n",
3745 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3746 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3747 (char *) &header->fsf_status_qual,
3748 sizeof (union fsf_status_qual));
3749 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3751 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3752 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3755 case FSF_LUN_HANDLE_NOT_VALID:
3756 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3757 "0x%016Lx on port 0x%016Lx on adapter %s is "
3758 "invalid. This may happen occasionally.\n",
3762 zfcp_get_busid_by_unit(unit));
3763 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3764 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3765 (char *) &header->fsf_status_qual,
3766 sizeof (union fsf_status_qual));
3767 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3769 zfcp_erp_port_reopen(unit->port, 0);
3770 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3773 case FSF_HANDLE_MISMATCH:
3774 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3775 "unexpectedly. (adapter %s, port 0x%016Lx, "
3778 zfcp_get_busid_by_unit(unit),
3781 ZFCP_LOG_NORMAL("status qualifier:\n");
3782 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3783 (char *) &header->fsf_status_qual,
3784 sizeof (union fsf_status_qual));
3785 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3787 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3788 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3791 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3792 if (fsf_req->adapter->fc_service_class <= 3) {
3793 ZFCP_LOG_NORMAL("error: The adapter %s does "
3794 "not support fibrechannel class %d.\n",
3795 zfcp_get_busid_by_unit(unit),
3796 fsf_req->adapter->fc_service_class);
3798 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3799 "adapter %s is invalid. "
3800 "(debug info %d)\n",
3801 zfcp_get_busid_by_unit(unit),
3802 fsf_req->adapter->fc_service_class);
3804 /* stop operation for this adapter */
3805 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3806 "fsf_s_class_nsup");
3807 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3808 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3811 case FSF_FCPLUN_NOT_VALID:
3812 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3813 "adapter %s does not have correct unit "
3817 zfcp_get_busid_by_unit(unit),
3819 ZFCP_LOG_DEBUG("status qualifier:\n");
3820 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3821 (char *) &header->fsf_status_qual,
3822 sizeof (union fsf_status_qual));
3823 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3824 "fsf_s_fcp_lun_nv");
3825 zfcp_erp_port_reopen(unit->port, 0);
3826 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3829 case FSF_ACCESS_DENIED:
3830 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3831 "unit 0x%016Lx on port 0x%016Lx on "
3832 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3833 zfcp_get_busid_by_unit(unit));
3834 for (counter = 0; counter < 2; counter++) {
3835 subtable = header->fsf_status_qual.halfword[counter * 2];
3836 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3838 case FSF_SQ_CFDC_SUBTABLE_OS:
3839 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3840 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3841 case FSF_SQ_CFDC_SUBTABLE_LUN:
3842 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3843 zfcp_act_subtable_type[subtable], rule);
3847 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3848 zfcp_erp_unit_access_denied(unit);
3849 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3852 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3853 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3854 "0x%016Lx on port 0x%016Lx on adapter %s "
3855 "(debug info %d)\n",
3858 zfcp_get_busid_by_unit(unit),
3859 fsf_req->qtcb->bottom.io.data_direction);
3860 /* stop operation for this adapter */
3861 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3862 "fsf_s_dir_ind_nv");
3863 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3864 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3867 case FSF_CMND_LENGTH_NOT_VALID:
3869 ("bug: An invalid control-data-block length field "
3870 "was found in a command for unit 0x%016Lx on port "
3871 "0x%016Lx on adapter %s " "(debug info %d)\n",
3872 unit->fcp_lun, unit->port->wwpn,
3873 zfcp_get_busid_by_unit(unit),
3874 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3875 /* stop operation for this adapter */
3876 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3877 "fsf_s_cmd_len_nv");
3878 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3882 case FSF_PORT_BOXED:
3883 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3884 "needs to be reopened\n",
3885 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3886 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3887 zfcp_erp_port_boxed(unit->port);
3888 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3889 ZFCP_STATUS_FSFREQ_RETRY;
3893 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3894 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3895 zfcp_get_busid_by_unit(unit),
3896 unit->port->wwpn, unit->fcp_lun);
3897 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3898 zfcp_erp_unit_boxed(unit);
3899 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3900 | ZFCP_STATUS_FSFREQ_RETRY;
3903 case FSF_ADAPTER_STATUS_AVAILABLE:
3904 switch (header->fsf_status_qual.word[0]) {
3905 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3906 /* re-establish link to port */
3907 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3909 zfcp_test_link(unit->port);
3911 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3912 /* FIXME(hw) need proper specs for proper action */
3913 /* let scsi stack deal with retries and escalation */
3914 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3919 ("Unknown status qualifier 0x%x arrived.\n",
3920 header->fsf_status_qual.word[0]);
3921 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3923 debug_exception(fsf_req->adapter->erp_dbf, 0,
3924 &header->fsf_status_qual.word[0],
3928 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3934 case FSF_FCP_RSP_AVAILABLE:
3938 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3939 debug_exception(fsf_req->adapter->erp_dbf, 0,
3940 &header->fsf_status, sizeof(u32));
3945 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3947 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3949 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3950 fsf_req->unit = NULL;
3951 zfcp_unit_put(unit);
3957 * function: zfcp_fsf_send_fcp_command_task_handler
3959 * purpose: evaluates FCP_RSP IU
3964 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3967 struct scsi_cmnd *scpnt;
3968 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3969 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3970 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3971 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3973 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3974 unsigned long flags;
3975 struct zfcp_unit *unit = fsf_req->unit;
3977 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3978 scpnt = (struct scsi_cmnd *) fsf_req->data;
3979 if (unlikely(!scpnt)) {
3981 ("Command with fsf_req %p is not associated to "
3982 "a scsi command anymore. Aborted?\n", fsf_req);
3985 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3986 /* FIXME: (design) mid-layer should handle DID_ABORT like
3987 * DID_SOFT_ERROR by retrying the request for devices
3988 * that allow retries.
3990 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3991 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3992 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3993 goto skip_fsfstatus;
3996 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3997 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3998 set_host_byte(&scpnt->result, DID_ERROR);
3999 goto skip_fsfstatus;
4002 /* set message byte of result in SCSI command */
4003 scpnt->result |= COMMAND_COMPLETE << 8;
4006 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4007 * of result in SCSI command
4009 scpnt->result |= fcp_rsp_iu->scsi_status;
4010 if (unlikely(fcp_rsp_iu->scsi_status)) {
4012 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4013 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4014 scpnt->cmnd, scpnt->cmd_len);
4015 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4016 fcp_rsp_iu->scsi_status);
4017 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4018 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4019 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4020 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4021 fcp_rsp_iu->fcp_sns_len);
4024 /* check FCP_RSP_INFO */
4025 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4026 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4027 switch (fcp_rsp_info[3]) {
4030 ZFCP_LOG_TRACE("no failure or Task Management "
4031 "Function complete\n");
4032 set_host_byte(&scpnt->result, DID_OK);
4034 case RSP_CODE_LENGTH_MISMATCH:
4036 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4037 "that the fibrechannel protocol data "
4038 "length differs from the burst length. "
4039 "The problem occured on unit 0x%016Lx "
4040 "on port 0x%016Lx on adapter %s",
4043 zfcp_get_busid_by_unit(unit));
4044 /* dump SCSI CDB as prepared by zfcp */
4045 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4046 (char *) &fsf_req->qtcb->
4047 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4048 set_host_byte(&scpnt->result, DID_ERROR);
4049 goto skip_fsfstatus;
4050 case RSP_CODE_FIELD_INVALID:
4051 /* driver or hardware bug */
4052 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4053 "that the fibrechannel protocol data "
4054 "fields were incorrectly set up. "
4055 "The problem occured on the unit "
4056 "0x%016Lx on port 0x%016Lx on "
4060 zfcp_get_busid_by_unit(unit));
4061 /* dump SCSI CDB as prepared by zfcp */
4062 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4063 (char *) &fsf_req->qtcb->
4064 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4065 set_host_byte(&scpnt->result, DID_ERROR);
4066 goto skip_fsfstatus;
4067 case RSP_CODE_RO_MISMATCH:
4069 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4070 "that conflicting values for the "
4071 "fibrechannel payload offset from the "
4072 "header were found. "
4073 "The problem occured on unit 0x%016Lx "
4074 "on port 0x%016Lx on adapter %s.\n",
4077 zfcp_get_busid_by_unit(unit));
4078 /* dump SCSI CDB as prepared by zfcp */
4079 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4080 (char *) &fsf_req->qtcb->
4081 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4082 set_host_byte(&scpnt->result, DID_ERROR);
4083 goto skip_fsfstatus;
4085 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4086 "code was detected for a command. "
4087 "The problem occured on the unit "
4088 "0x%016Lx on port 0x%016Lx on "
4089 "adapter %s (debug info 0x%x)\n",
4092 zfcp_get_busid_by_unit(unit),
4094 /* dump SCSI CDB as prepared by zfcp */
4095 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4096 (char *) &fsf_req->qtcb->
4097 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4098 set_host_byte(&scpnt->result, DID_ERROR);
4099 goto skip_fsfstatus;
4103 /* check for sense data */
4104 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4105 sns_len = FSF_FCP_RSP_SIZE -
4106 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4107 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4109 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4110 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4111 SCSI_SENSE_BUFFERSIZE);
4112 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4113 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4115 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4116 (void *) &scpnt->cmnd, scpnt->cmd_len);
4118 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4119 fcp_rsp_iu->fcp_sns_len);
4120 memcpy(&scpnt->sense_buffer,
4121 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4122 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4123 (void *) &scpnt->sense_buffer, sns_len);
4126 /* check for overrun */
4127 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4128 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4129 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4130 "The response data length is "
4131 "%d, the original length was %d.\n",
4134 zfcp_get_busid_by_unit(unit),
4135 fcp_rsp_iu->fcp_resid,
4136 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4139 /* check for underrun */
4140 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4141 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4142 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4143 "The response data length is "
4144 "%d, the original length was %d.\n",
4147 zfcp_get_busid_by_unit(unit),
4148 fcp_rsp_iu->fcp_resid,
4149 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4151 scpnt->resid = fcp_rsp_iu->fcp_resid;
4152 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4153 set_host_byte(&scpnt->result, DID_ERROR);
4157 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4159 if (scpnt->result != 0)
4160 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4161 else if (scpnt->retries > 0)
4162 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4164 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
4166 /* cleanup pointer (need this especially for abort) */
4167 scpnt->host_scribble = NULL;
4169 /* always call back */
4170 (scpnt->scsi_done) (scpnt);
4173 * We must hold this lock until scsi_done has been called.
4174 * Otherwise we may call scsi_done after abort regarding this
4175 * command has completed.
4176 * Note: scsi_done must not block!
4179 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4184 * function: zfcp_fsf_send_fcp_command_task_management_handler
4186 * purpose: evaluates FCP_RSP IU
4191 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4194 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4195 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4196 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4197 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4199 del_timer(&fsf_req->adapter->scsi_er_timer);
4200 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4201 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4202 goto skip_fsfstatus;
4205 /* check FCP_RSP_INFO */
4206 switch (fcp_rsp_info[3]) {
4209 ZFCP_LOG_DEBUG("no failure or Task Management "
4210 "Function complete\n");
4212 case RSP_CODE_TASKMAN_UNSUPP:
4213 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4214 "is not supported on the target device "
4215 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4218 zfcp_get_busid_by_unit(unit));
4219 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4221 case RSP_CODE_TASKMAN_FAILED:
4222 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4223 "failed to complete successfully. "
4224 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4227 zfcp_get_busid_by_unit(unit));
4228 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4231 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4232 "code was detected for a command. "
4233 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4234 "(debug info 0x%x)\n",
4237 zfcp_get_busid_by_unit(unit),
4239 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4248 * function: zfcp_fsf_control_file
4250 * purpose: Initiator of the control file upload/download FSF requests
4252 * returns: 0 - FSF request is successfuly created and queued
4253 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4254 * -EINVAL - Invalid direction specified
4255 * -ENOMEM - Insufficient memory
4256 * -EPERM - Cannot create FSF request or place it in QDIO queue
4259 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4260 struct zfcp_fsf_req **fsf_req_ptr,
4263 struct zfcp_sg_list *sg_list)
4265 struct zfcp_fsf_req *fsf_req;
4266 struct fsf_qtcb_bottom_support *bottom;
4267 volatile struct qdio_buffer_element *sbale;
4268 struct timer_list *timer;
4269 unsigned long lock_flags;
4274 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4275 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4276 zfcp_get_busid_by_adapter(adapter));
4277 retval = -EOPNOTSUPP;
4281 switch (fsf_command) {
4283 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4284 direction = SBAL_FLAGS0_TYPE_WRITE;
4285 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4286 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4287 req_flags = ZFCP_WAIT_FOR_SBAL;
4290 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4291 direction = SBAL_FLAGS0_TYPE_READ;
4295 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4300 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4306 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4307 NULL, &lock_flags, &fsf_req);
4309 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4311 zfcp_get_busid_by_adapter(adapter));
4313 goto unlock_queue_lock;
4316 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4317 sbale[0].flags |= direction;
4319 bottom = &fsf_req->qtcb->bottom.support;
4320 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4321 bottom->option = option;
4323 if (sg_list->count > 0) {
4326 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4327 sg_list->sg, sg_list->count,
4328 ZFCP_MAX_SBALS_PER_REQ);
4329 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4331 "error: Could not create sufficient number of "
4332 "SBALS for an FSF request to the adapter %s\n",
4333 zfcp_get_busid_by_adapter(adapter));
4338 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4341 timer->function = zfcp_fsf_request_timeout_handler;
4342 timer->data = (unsigned long) adapter;
4343 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4345 retval = zfcp_fsf_req_send(fsf_req, timer);
4347 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4349 zfcp_get_busid_by_adapter(adapter));
4353 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4355 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4357 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4358 "download" : "upload",
4359 zfcp_get_busid_by_adapter(adapter));
4361 wait_event(fsf_req->completion_wq,
4362 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4364 *fsf_req_ptr = fsf_req;
4365 del_timer_sync(timer);
4369 zfcp_fsf_req_free(fsf_req);
4371 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4380 * function: zfcp_fsf_control_file_handler
4382 * purpose: Handler of the control file upload/download FSF requests
4384 * returns: 0 - FSF request successfuly processed
4385 * -EAGAIN - Operation has to be repeated because of a temporary problem
4386 * -EACCES - There is no permission to execute an operation
4387 * -EPERM - The control file is not in a right format
4388 * -EIO - There is a problem with the FCP adapter
4389 * -EINVAL - Invalid operation
4390 * -EFAULT - User space memory I/O operation fault
4393 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4395 struct zfcp_adapter *adapter = fsf_req->adapter;
4396 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4397 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4400 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4402 goto skip_fsfstatus;
4405 switch (header->fsf_status) {
4409 "The FSF request has been successfully completed "
4410 "on the adapter %s\n",
4411 zfcp_get_busid_by_adapter(adapter));
4414 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4415 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4416 switch (header->fsf_status_qual.word[0]) {
4418 case FSF_SQ_CFDC_HARDENED_ON_SE:
4420 "CFDC on the adapter %s has being "
4421 "hardened on primary and secondary SE\n",
4422 zfcp_get_busid_by_adapter(adapter));
4425 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4427 "CFDC of the adapter %s could not "
4428 "be saved on the SE\n",
4429 zfcp_get_busid_by_adapter(adapter));
4432 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4434 "CFDC of the adapter %s could not "
4435 "be copied to the secondary SE\n",
4436 zfcp_get_busid_by_adapter(adapter));
4441 "CFDC could not be hardened "
4442 "on the adapter %s\n",
4443 zfcp_get_busid_by_adapter(adapter));
4446 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4450 case FSF_AUTHORIZATION_FAILURE:
4452 "Adapter %s does not accept privileged commands\n",
4453 zfcp_get_busid_by_adapter(adapter));
4454 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4458 case FSF_CFDC_ERROR_DETECTED:
4460 "Error at position %d in the CFDC, "
4461 "CFDC is discarded by the adapter %s\n",
4462 header->fsf_status_qual.word[0],
4463 zfcp_get_busid_by_adapter(adapter));
4464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4468 case FSF_CONTROL_FILE_UPDATE_ERROR:
4470 "Adapter %s cannot harden the control file, "
4471 "file is discarded\n",
4472 zfcp_get_busid_by_adapter(adapter));
4473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4477 case FSF_CONTROL_FILE_TOO_LARGE:
4479 "Control file is too large, file is discarded "
4480 "by the adapter %s\n",
4481 zfcp_get_busid_by_adapter(adapter));
4482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4486 case FSF_ACCESS_CONFLICT_DETECTED:
4487 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4489 "CFDC has been discarded by the adapter %s, "
4490 "because activation would impact "
4491 "%d active connection(s)\n",
4492 zfcp_get_busid_by_adapter(adapter),
4493 header->fsf_status_qual.word[0]);
4494 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4498 case FSF_CONFLICTS_OVERRULED:
4499 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4501 "CFDC has been activated on the adapter %s, "
4502 "but activation has impacted "
4503 "%d active connection(s)\n",
4504 zfcp_get_busid_by_adapter(adapter),
4505 header->fsf_status_qual.word[0]);
4506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4510 case FSF_UNKNOWN_OP_SUBTYPE:
4511 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4512 "op_subtype=0x%x)\n",
4513 zfcp_get_busid_by_adapter(adapter),
4514 bottom->operation_subtype);
4515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4519 case FSF_INVALID_COMMAND_OPTION:
4521 "Invalid option 0x%x has been specified "
4522 "in QTCB bottom sent to the adapter %s\n",
4524 zfcp_get_busid_by_adapter(adapter));
4525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4531 "bug: An unknown/unexpected FSF status 0x%08x "
4532 "was presented on the adapter %s\n",
4534 zfcp_get_busid_by_adapter(adapter));
4535 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4536 debug_exception(fsf_req->adapter->erp_dbf, 0,
4537 &header->fsf_status_qual.word[0], sizeof(u32));
4538 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4548 zfcp_fsf_req_sbal_check(unsigned long *flags,
4549 struct zfcp_qdio_queue *queue, int needed)
4551 write_lock_irqsave(&queue->queue_lock, *flags);
4552 if (likely(atomic_read(&queue->free_count) >= needed))
4554 write_unlock_irqrestore(&queue->queue_lock, *flags);
4559 * set qtcb pointer in fsf_req and initialize QTCB
4562 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4564 if (likely(fsf_req->qtcb != NULL)) {
4565 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4566 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4567 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4568 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4569 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4570 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4571 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4576 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4577 * @adapter: adapter for which request queue is examined
4578 * @req_flags: flags indicating whether to wait for needed SBAL or not
4579 * @lock_flags: lock_flags if queue_lock is taken
4580 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4581 * Locks: lock adapter->request_queue->queue_lock on success
4584 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4585 unsigned long *lock_flags)
4588 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4590 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4591 ret = wait_event_interruptible_timeout(adapter->request_wq,
4592 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4598 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4605 * function: zfcp_fsf_req_create
4607 * purpose: create an FSF request at the specified adapter and
4608 * setup common fields
4610 * returns: -ENOMEM if there was insufficient memory for a request
4611 * -EIO if no qdio buffers could be allocate to the request
4612 * -EINVAL/-EPERM on bug conditions in req_dequeue
4615 * note: The created request is returned by reference.
4617 * locks: lock of concerned request queue must not be held,
4618 * but is held on completion (write, irqsave)
4621 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4622 mempool_t *pool, unsigned long *lock_flags,
4623 struct zfcp_fsf_req **fsf_req_p)
4625 volatile struct qdio_buffer_element *sbale;
4626 struct zfcp_fsf_req *fsf_req = NULL;
4628 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4630 /* allocate new FSF request */
4631 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4632 if (unlikely(NULL == fsf_req)) {
4633 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4634 "the outbound (send) queue.\n");
4636 goto failed_fsf_req;
4639 fsf_req->adapter = adapter;
4640 fsf_req->fsf_command = fsf_cmd;
4642 zfcp_fsf_req_qtcb_init(fsf_req);
4644 /* initialize waitqueue which may be used to wait on
4645 this request completion */
4646 init_waitqueue_head(&fsf_req->completion_wq);
4648 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4654 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4655 * if it is not set (see also *_open_qdio and *_close_qdio).
4658 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4659 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4664 if (fsf_req->qtcb) {
4665 fsf_req->seq_no = adapter->fsf_req_seq_no;
4666 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4668 fsf_req->sbal_number = 1;
4669 fsf_req->sbal_first = req_queue->free_index;
4670 fsf_req->sbal_curr = req_queue->free_index;
4671 fsf_req->sbale_curr = 1;
4673 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4674 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4677 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4679 /* setup common SBALE fields */
4680 sbale[0].addr = fsf_req;
4681 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4682 if (likely(fsf_req->qtcb != NULL)) {
4683 sbale[1].addr = (void *) fsf_req->qtcb;
4684 sbale[1].length = sizeof(struct fsf_qtcb);
4687 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4688 fsf_req->sbal_number, fsf_req->sbal_first);
4693 /* dequeue new FSF request previously enqueued */
4694 zfcp_fsf_req_free(fsf_req);
4698 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4700 *fsf_req_p = fsf_req;
4705 * function: zfcp_fsf_req_send
4707 * purpose: start transfer of FSF request via QDIO
4709 * returns: 0 - request transfer succesfully started
4710 * !0 - start of request transfer failed
4713 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4715 struct zfcp_adapter *adapter;
4716 struct zfcp_qdio_queue *req_queue;
4717 volatile struct qdio_buffer_element *sbale;
4719 int new_distance_from_int;
4720 unsigned long flags;
4723 adapter = fsf_req->adapter;
4724 req_queue = &adapter->request_queue,
4727 /* FIXME(debug): remove it later */
4728 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4729 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4730 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4731 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4734 /* put allocated FSF request at list tail */
4735 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4736 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4737 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4739 inc_seq_no = (fsf_req->qtcb != NULL);
4741 /* figure out expiration time of timeout and start timeout */
4742 if (unlikely(timer)) {
4743 timer->expires += jiffies;
4747 ZFCP_LOG_TRACE("request queue of adapter %s: "
4748 "next free SBAL is %i, %i free SBALs\n",
4749 zfcp_get_busid_by_adapter(adapter),
4750 req_queue->free_index,
4751 atomic_read(&req_queue->free_count));
4753 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4754 "index_in_queue=%i, count=%i, buffers=%p\n",
4755 zfcp_get_busid_by_adapter(adapter),
4756 QDIO_FLAG_SYNC_OUTPUT,
4757 0, fsf_req->sbal_first, fsf_req->sbal_number,
4758 &req_queue->buffer[fsf_req->sbal_first]);
4761 * adjust the number of free SBALs in request queue as well as
4762 * position of first one
4764 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4765 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4766 req_queue->free_index += fsf_req->sbal_number; /* increase */
4767 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4768 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4770 fsf_req->issued = get_clock();
4772 retval = do_QDIO(adapter->ccw_device,
4773 QDIO_FLAG_SYNC_OUTPUT,
4774 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4776 if (unlikely(retval)) {
4777 /* Queues are down..... */
4780 * FIXME(potential race):
4781 * timer might be expired (absolutely unlikely)
4785 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4786 list_del(&fsf_req->list);
4787 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4789 * adjust the number of free SBALs in request queue as well as
4790 * position of first one
4792 zfcp_qdio_zero_sbals(req_queue->buffer,
4793 fsf_req->sbal_first, fsf_req->sbal_number);
4794 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4795 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4796 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4797 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4799 ("error: do_QDIO failed. Buffers could not be enqueued "
4800 "to request queue.\n");
4802 req_queue->distance_from_int = new_distance_from_int;
4804 * increase FSF sequence counter -
4805 * this must only be done for request successfully enqueued to
4806 * QDIO this rejected requests may be cleaned up by calling
4807 * routines resulting in missing sequence counter values
4811 /* Don't increase for unsolicited status */
4813 adapter->fsf_req_seq_no++;
4815 /* count FSF requests pending */
4816 atomic_inc(&adapter->fsf_reqs_active);
4821 #undef ZFCP_LOG_AREA