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;
1982 bottom = &fsf_req->qtcb->bottom.config;
1983 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1984 bottom->low_qtcb_version, bottom->high_qtcb_version);
1985 adapter->fsf_lic_version = bottom->lic_version;
1986 adapter->adapter_features = bottom->adapter_features;
1987 adapter->connection_features = bottom->connection_features;
1988 adapter->peer_wwpn = 0;
1989 adapter->peer_wwnn = 0;
1990 adapter->peer_d_id = 0;
1993 adapter->wwnn = bottom->nport_serv_param.wwnn;
1994 adapter->wwpn = bottom->nport_serv_param.wwpn;
1995 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
1996 adapter->fc_topology = bottom->fc_topology;
1997 adapter->fc_link_speed = bottom->fc_link_speed;
1998 adapter->hydra_version = bottom->adapter_type;
1999 if (adapter->physical_wwpn == 0)
2000 adapter->physical_wwpn = adapter->wwpn;
2001 if (adapter->physical_s_id == 0)
2002 adapter->physical_s_id = adapter->s_id;
2007 adapter->fc_topology = 0;
2008 adapter->fc_link_speed = 0;
2009 adapter->hydra_version = 0;
2012 if (adapter->fc_topology == FSF_TOPO_P2P) {
2013 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2014 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2015 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2018 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2019 adapter->hardware_version = bottom->hardware_version;
2020 memcpy(adapter->serial_number, bottom->serial_number, 17);
2021 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2024 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2028 "adapter version 0x%x, "
2029 "LIC version 0x%x, "
2030 "FC link speed %d Gb/s\n",
2031 zfcp_get_busid_by_adapter(adapter),
2034 (unsigned int) adapter->s_id,
2035 adapter->hydra_version,
2036 adapter->fsf_lic_version,
2037 adapter->fc_link_speed);
2038 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2039 ZFCP_LOG_NORMAL("error: the adapter %s "
2040 "only supports newer control block "
2041 "versions in comparison to this device "
2042 "driver (try updated device driver)\n",
2043 zfcp_get_busid_by_adapter(adapter));
2044 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2045 zfcp_erp_adapter_shutdown(adapter, 0);
2048 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2049 ZFCP_LOG_NORMAL("error: the adapter %s "
2050 "only supports older control block "
2051 "versions than this device driver uses"
2052 "(consider a microcode upgrade)\n",
2053 zfcp_get_busid_by_adapter(adapter));
2054 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2055 zfcp_erp_adapter_shutdown(adapter, 0);
2058 zfcp_set_fc_host_attrs(adapter);
2063 * function: zfcp_fsf_exchange_config_data_handler
2065 * purpose: is called for finished Exchange Configuration Data command
2070 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2072 struct fsf_qtcb_bottom_config *bottom;
2073 struct zfcp_adapter *adapter = fsf_req->adapter;
2074 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2076 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2079 switch (qtcb->header.fsf_status) {
2082 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2085 switch (adapter->fc_topology) {
2087 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2088 "configuration detected at adapter %s\n"
2089 "Peer WWNN 0x%016llx, "
2090 "peer WWPN 0x%016llx, "
2091 "peer d_id 0x%06x\n",
2092 zfcp_get_busid_by_adapter(adapter),
2095 adapter->peer_d_id);
2096 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2100 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2101 "topology detected at adapter %s "
2102 "unsupported, shutting down adapter\n",
2103 zfcp_get_busid_by_adapter(adapter));
2104 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2106 zfcp_erp_adapter_shutdown(adapter, 0);
2108 case FSF_TOPO_FABRIC:
2109 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2110 "network detected at adapter %s.\n",
2111 zfcp_get_busid_by_adapter(adapter));
2114 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2115 "reported by the exchange "
2116 "configuration command for "
2117 "the adapter %s is not "
2118 "of a type known to the zfcp "
2119 "driver, shutting down adapter\n",
2120 zfcp_get_busid_by_adapter(adapter));
2121 adapter->fc_topology = FSF_TOPO_ERROR;
2122 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2124 zfcp_erp_adapter_shutdown(adapter, 0);
2127 bottom = &qtcb->bottom.config;
2128 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2129 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2130 "allowed by the adapter %s "
2131 "is lower than the minimum "
2132 "required by the driver (%ld bytes).\n",
2133 bottom->max_qtcb_size,
2134 zfcp_get_busid_by_adapter(adapter),
2135 sizeof(struct fsf_qtcb));
2136 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2138 debug_event(fsf_req->adapter->erp_dbf, 0,
2139 &bottom->max_qtcb_size, sizeof (u32));
2140 zfcp_erp_adapter_shutdown(adapter, 0);
2143 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2146 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2147 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2149 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2152 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2154 zfcp_fsf_link_down_info_eval(adapter,
2155 &qtcb->header.fsf_status_qual.link_down_info);
2158 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2159 debug_event(fsf_req->adapter->erp_dbf, 0,
2160 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2161 zfcp_erp_adapter_shutdown(adapter, 0);
2168 * zfcp_fsf_exchange_port_data - request information about local port
2169 * @erp_action: ERP action for the adapter for which port data is requested
2170 * @adapter: for which port data is requested
2171 * @data: response to exchange port data request
2174 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2175 struct zfcp_adapter *adapter,
2176 struct fsf_qtcb_bottom_port *data)
2178 volatile struct qdio_buffer_element *sbale;
2180 unsigned long lock_flags;
2181 struct zfcp_fsf_req *fsf_req;
2182 struct timer_list *timer;
2184 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2185 ZFCP_LOG_INFO("error: exchange port data "
2186 "command not supported by adapter %s\n",
2187 zfcp_get_busid_by_adapter(adapter));
2191 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2195 /* setup new FSF request */
2196 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2197 0, 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 erp_action->fsf_req = fsf_req;
2210 fsf_req->erp_action = erp_action;
2214 fsf_req->data = (unsigned long) data;
2216 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2217 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2218 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2221 timer->function = zfcp_fsf_request_timeout_handler;
2222 timer->data = (unsigned long) adapter;
2223 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2225 retval = zfcp_fsf_req_send(fsf_req, timer);
2227 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2228 "command on the adapter %s\n",
2229 zfcp_get_busid_by_adapter(adapter));
2230 zfcp_fsf_req_free(fsf_req);
2232 erp_action->fsf_req = NULL;
2233 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2238 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2239 zfcp_get_busid_by_adapter(adapter));
2241 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2244 wait_event(fsf_req->completion_wq,
2245 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2246 del_timer_sync(timer);
2247 zfcp_fsf_req_free(fsf_req);
2255 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2256 * @fsf_req: pointer to struct zfcp_fsf_req
2259 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2261 struct zfcp_adapter *adapter = fsf_req->adapter;
2262 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2263 struct fsf_qtcb_bottom_port *bottom, *data;
2265 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2268 switch (qtcb->header.fsf_status) {
2270 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2272 bottom = &qtcb->bottom.port;
2273 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2275 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2276 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
2277 adapter->physical_wwpn = bottom->wwpn;
2278 adapter->physical_s_id = bottom->fc_port_id;
2280 adapter->physical_wwpn = adapter->wwpn;
2281 adapter->physical_s_id = adapter->s_id;
2285 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2286 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2288 zfcp_fsf_link_down_info_eval(adapter,
2289 &qtcb->header.fsf_status_qual.link_down_info);
2293 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2294 debug_event(adapter->erp_dbf, 0,
2295 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2301 * function: zfcp_fsf_open_port
2305 * returns: address of initiated FSF request
2306 * NULL - request could not be initiated
2309 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2311 volatile struct qdio_buffer_element *sbale;
2312 unsigned long lock_flags;
2315 /* setup new FSF request */
2316 retval = zfcp_fsf_req_create(erp_action->adapter,
2317 FSF_QTCB_OPEN_PORT_WITH_DID,
2318 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2319 erp_action->adapter->pool.fsf_req_erp,
2320 &lock_flags, &(erp_action->fsf_req));
2322 ZFCP_LOG_INFO("error: Could not create open port request "
2323 "for port 0x%016Lx on adapter %s.\n",
2324 erp_action->port->wwpn,
2325 zfcp_get_busid_by_adapter(erp_action->adapter));
2329 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2330 erp_action->fsf_req->sbal_curr, 0);
2331 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2332 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2334 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2335 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2336 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2337 erp_action->fsf_req->erp_action = erp_action;
2339 /* start QDIO request for this FSF request */
2340 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2342 ZFCP_LOG_INFO("error: Could not send open port request for "
2343 "port 0x%016Lx on adapter %s.\n",
2344 erp_action->port->wwpn,
2345 zfcp_get_busid_by_adapter(erp_action->adapter));
2346 zfcp_fsf_req_free(erp_action->fsf_req);
2347 erp_action->fsf_req = NULL;
2351 ZFCP_LOG_DEBUG("open port request initiated "
2352 "(adapter %s, port 0x%016Lx)\n",
2353 zfcp_get_busid_by_adapter(erp_action->adapter),
2354 erp_action->port->wwpn);
2356 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2362 * function: zfcp_fsf_open_port_handler
2364 * purpose: is called for finished Open Port command
2369 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2371 int retval = -EINVAL;
2372 struct zfcp_port *port;
2373 struct fsf_plogi *plogi;
2374 struct fsf_qtcb_header *header;
2375 u16 subtable, rule, counter;
2377 port = (struct zfcp_port *) fsf_req->data;
2378 header = &fsf_req->qtcb->header;
2380 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2381 /* don't change port status in our bookkeeping */
2382 goto skip_fsfstatus;
2385 /* evaluate FSF status in QTCB */
2386 switch (header->fsf_status) {
2388 case FSF_PORT_ALREADY_OPEN:
2389 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2390 "is already open.\n",
2391 port->wwpn, zfcp_get_busid_by_port(port));
2392 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2395 * This is a bug, however operation should continue normally
2396 * if it is simply ignored
2400 case FSF_ACCESS_DENIED:
2401 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2403 port->wwpn, zfcp_get_busid_by_port(port));
2404 for (counter = 0; counter < 2; counter++) {
2405 subtable = header->fsf_status_qual.halfword[counter * 2];
2406 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2408 case FSF_SQ_CFDC_SUBTABLE_OS:
2409 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2410 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2411 case FSF_SQ_CFDC_SUBTABLE_LUN:
2412 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2413 zfcp_act_subtable_type[subtable], rule);
2417 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2418 zfcp_erp_port_access_denied(port);
2419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2422 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2423 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2424 "The remote port 0x%016Lx on adapter %s "
2425 "could not be opened. Disabling it.\n",
2426 port->wwpn, zfcp_get_busid_by_port(port));
2427 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2429 zfcp_erp_port_failed(port);
2430 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2433 case FSF_ADAPTER_STATUS_AVAILABLE:
2434 switch (header->fsf_status_qual.word[0]) {
2435 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2436 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2438 /* ERP strategy will escalate */
2439 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2441 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2442 /* ERP strategy will escalate */
2443 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2447 case FSF_SQ_NO_RETRY_POSSIBLE:
2448 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2449 "adapter %s could not be opened. "
2452 zfcp_get_busid_by_port(port));
2453 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2455 zfcp_erp_port_failed(port);
2456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2460 ("bug: Wrong status qualifier 0x%x arrived.\n",
2461 header->fsf_status_qual.word[0]);
2462 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2465 fsf_req->adapter->erp_dbf, 0,
2466 &header->fsf_status_qual.word[0],
2473 /* save port handle assigned by FSF */
2474 port->handle = header->port_handle;
2475 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2476 "was opened, it's port handle is 0x%x\n",
2477 port->wwpn, zfcp_get_busid_by_port(port),
2479 /* mark port as open */
2480 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2481 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2482 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2483 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2486 /* check whether D_ID has changed during open */
2488 * FIXME: This check is not airtight, as the FCP channel does
2489 * not monitor closures of target port connections caused on
2490 * the remote side. Thus, they might miss out on invalidating
2491 * locally cached WWPNs (and other N_Port parameters) of gone
2492 * target ports. So, our heroic attempt to make things safe
2493 * could be undermined by 'open port' response data tagged with
2494 * obsolete WWPNs. Another reason to monitor potential
2495 * connection closures ourself at least (by interpreting
2496 * incoming ELS' and unsolicited status). It just crosses my
2497 * mind that one should be able to cross-check by means of
2498 * another GID_PN straight after a port has been opened.
2499 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2501 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2502 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2504 if (fsf_req->qtcb->bottom.support.els1_length <
2505 ((((unsigned long) &plogi->serv_param.wwpn) -
2506 ((unsigned long) plogi)) + sizeof (u64))) {
2508 "warning: insufficient length of "
2509 "PLOGI payload (%i)\n",
2510 fsf_req->qtcb->bottom.support.els1_length);
2511 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2512 "fsf_s_short_plogi:");
2513 /* skip sanity check and assume wwpn is ok */
2515 if (plogi->serv_param.wwpn != port->wwpn) {
2516 ZFCP_LOG_INFO("warning: d_id of port "
2517 "0x%016Lx changed during "
2518 "open\n", port->wwpn);
2520 fsf_req->adapter->erp_dbf, 0,
2521 "fsf_s_did_change:");
2523 ZFCP_STATUS_PORT_DID_DID,
2526 port->wwnn = plogi->serv_param.wwnn;
2531 case FSF_UNKNOWN_OP_SUBTYPE:
2532 /* should never occure, subtype not set in zfcp_fsf_open_port */
2533 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2534 "op_subtype=0x%x)\n",
2535 zfcp_get_busid_by_port(port),
2536 fsf_req->qtcb->bottom.support.operation_subtype);
2537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2541 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2542 "(debug info 0x%x)\n",
2543 header->fsf_status);
2544 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2545 debug_exception(fsf_req->adapter->erp_dbf, 0,
2546 &header->fsf_status, sizeof (u32));
2551 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2556 * function: zfcp_fsf_close_port
2558 * purpose: submit FSF command "close port"
2560 * returns: address of initiated FSF request
2561 * NULL - request could not be initiated
2564 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2566 volatile struct qdio_buffer_element *sbale;
2567 unsigned long lock_flags;
2570 /* setup new FSF request */
2571 retval = zfcp_fsf_req_create(erp_action->adapter,
2572 FSF_QTCB_CLOSE_PORT,
2573 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2574 erp_action->adapter->pool.fsf_req_erp,
2575 &lock_flags, &(erp_action->fsf_req));
2577 ZFCP_LOG_INFO("error: Could not create a close port request "
2578 "for port 0x%016Lx on adapter %s.\n",
2579 erp_action->port->wwpn,
2580 zfcp_get_busid_by_adapter(erp_action->adapter));
2584 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2585 erp_action->fsf_req->sbal_curr, 0);
2586 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2587 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2589 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2590 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2591 erp_action->fsf_req->erp_action = erp_action;
2592 erp_action->fsf_req->qtcb->header.port_handle =
2593 erp_action->port->handle;
2595 /* start QDIO request for this FSF request */
2596 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2598 ZFCP_LOG_INFO("error: Could not send a close port request for "
2599 "port 0x%016Lx on adapter %s.\n",
2600 erp_action->port->wwpn,
2601 zfcp_get_busid_by_adapter(erp_action->adapter));
2602 zfcp_fsf_req_free(erp_action->fsf_req);
2603 erp_action->fsf_req = NULL;
2607 ZFCP_LOG_TRACE("close port request initiated "
2608 "(adapter %s, port 0x%016Lx)\n",
2609 zfcp_get_busid_by_adapter(erp_action->adapter),
2610 erp_action->port->wwpn);
2612 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2618 * function: zfcp_fsf_close_port_handler
2620 * purpose: is called for finished Close Port FSF command
2625 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2627 int retval = -EINVAL;
2628 struct zfcp_port *port;
2630 port = (struct zfcp_port *) fsf_req->data;
2632 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2633 /* don't change port status in our bookkeeping */
2634 goto skip_fsfstatus;
2637 /* evaluate FSF status in QTCB */
2638 switch (fsf_req->qtcb->header.fsf_status) {
2640 case FSF_PORT_HANDLE_NOT_VALID:
2641 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2642 "0x%016Lx on adapter %s invalid. This may happen "
2643 "occasionally.\n", port->handle,
2644 port->wwpn, zfcp_get_busid_by_port(port));
2645 ZFCP_LOG_DEBUG("status qualifier:\n");
2646 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2647 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2648 sizeof (union fsf_status_qual));
2649 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2651 zfcp_erp_adapter_reopen(port->adapter, 0);
2652 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2655 case FSF_ADAPTER_STATUS_AVAILABLE:
2656 /* Note: FSF has actually closed the port in this case.
2657 * The status code is just daft. Fingers crossed for a change
2663 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2664 "port handle 0x%x\n", port->wwpn,
2665 zfcp_get_busid_by_port(port), port->handle);
2666 zfcp_erp_modify_port_status(port,
2667 ZFCP_STATUS_COMMON_OPEN,
2673 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2674 "(debug info 0x%x)\n",
2675 fsf_req->qtcb->header.fsf_status);
2676 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2677 debug_exception(fsf_req->adapter->erp_dbf, 0,
2678 &fsf_req->qtcb->header.fsf_status,
2684 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2689 * function: zfcp_fsf_close_physical_port
2691 * purpose: submit FSF command "close physical port"
2693 * returns: address of initiated FSF request
2694 * NULL - request could not be initiated
2697 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2700 unsigned long lock_flags;
2701 volatile struct qdio_buffer_element *sbale;
2703 /* setup new FSF request */
2704 retval = zfcp_fsf_req_create(erp_action->adapter,
2705 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2706 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2707 erp_action->adapter->pool.fsf_req_erp,
2708 &lock_flags, &erp_action->fsf_req);
2710 ZFCP_LOG_INFO("error: Could not create close physical port "
2711 "request (adapter %s, port 0x%016Lx)\n",
2712 zfcp_get_busid_by_adapter(erp_action->adapter),
2713 erp_action->port->wwpn);
2718 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2719 erp_action->fsf_req->sbal_curr, 0);
2720 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2721 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2723 /* mark port as being closed */
2724 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2725 &erp_action->port->status);
2726 /* save a pointer to this port */
2727 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2728 /* port to be closed */
2729 erp_action->fsf_req->qtcb->header.port_handle =
2730 erp_action->port->handle;
2731 erp_action->fsf_req->erp_action = erp_action;
2733 /* start QDIO request for this FSF request */
2734 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2736 ZFCP_LOG_INFO("error: Could not send close physical port "
2737 "request (adapter %s, port 0x%016Lx)\n",
2738 zfcp_get_busid_by_adapter(erp_action->adapter),
2739 erp_action->port->wwpn);
2740 zfcp_fsf_req_free(erp_action->fsf_req);
2741 erp_action->fsf_req = NULL;
2745 ZFCP_LOG_TRACE("close physical port request initiated "
2746 "(adapter %s, port 0x%016Lx)\n",
2747 zfcp_get_busid_by_adapter(erp_action->adapter),
2748 erp_action->port->wwpn);
2750 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2756 * function: zfcp_fsf_close_physical_port_handler
2758 * purpose: is called for finished Close Physical Port FSF command
2763 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2765 int retval = -EINVAL;
2766 struct zfcp_port *port;
2767 struct zfcp_unit *unit;
2768 struct fsf_qtcb_header *header;
2769 u16 subtable, rule, counter;
2771 port = (struct zfcp_port *) fsf_req->data;
2772 header = &fsf_req->qtcb->header;
2774 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2775 /* don't change port status in our bookkeeping */
2776 goto skip_fsfstatus;
2779 /* evaluate FSF status in QTCB */
2780 switch (header->fsf_status) {
2782 case FSF_PORT_HANDLE_NOT_VALID:
2783 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2784 "(adapter %s, port 0x%016Lx). "
2785 "This may happen occasionally.\n",
2787 zfcp_get_busid_by_port(port),
2789 ZFCP_LOG_DEBUG("status qualifier:\n");
2790 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2791 (char *) &header->fsf_status_qual,
2792 sizeof (union fsf_status_qual));
2793 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2795 zfcp_erp_adapter_reopen(port->adapter, 0);
2796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2799 case FSF_ACCESS_DENIED:
2800 ZFCP_LOG_NORMAL("Access denied, cannot close "
2801 "physical port 0x%016Lx on adapter %s\n",
2802 port->wwpn, zfcp_get_busid_by_port(port));
2803 for (counter = 0; counter < 2; counter++) {
2804 subtable = header->fsf_status_qual.halfword[counter * 2];
2805 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2807 case FSF_SQ_CFDC_SUBTABLE_OS:
2808 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2809 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2810 case FSF_SQ_CFDC_SUBTABLE_LUN:
2811 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2812 zfcp_act_subtable_type[subtable], rule);
2816 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2817 zfcp_erp_port_access_denied(port);
2818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2821 case FSF_PORT_BOXED:
2822 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2823 "%s needs to be reopened but it was attempted "
2824 "to close it physically.\n",
2826 zfcp_get_busid_by_port(port));
2827 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2828 zfcp_erp_port_boxed(port);
2829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2830 ZFCP_STATUS_FSFREQ_RETRY;
2833 case FSF_ADAPTER_STATUS_AVAILABLE:
2834 switch (header->fsf_status_qual.word[0]) {
2835 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2836 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2838 /* This will now be escalated by ERP */
2839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2841 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2842 /* ERP strategy will escalate */
2843 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2849 ("bug: Wrong status qualifier 0x%x arrived.\n",
2850 header->fsf_status_qual.word[0]);
2851 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2854 fsf_req->adapter->erp_dbf, 0,
2855 &header->fsf_status_qual.word[0], sizeof (u32));
2861 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2862 "physically closed, port handle 0x%x\n",
2864 zfcp_get_busid_by_port(port), port->handle);
2865 /* can't use generic zfcp_erp_modify_port_status because
2866 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2868 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2869 list_for_each_entry(unit, &port->unit_list_head, list)
2870 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2875 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2876 "(debug info 0x%x)\n",
2877 header->fsf_status);
2878 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2879 debug_exception(fsf_req->adapter->erp_dbf, 0,
2880 &header->fsf_status, sizeof (u32));
2885 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2890 * function: zfcp_fsf_open_unit
2896 * assumptions: This routine does not check whether the associated
2897 * remote port has already been opened. This should be
2898 * done by calling routines. Otherwise some status
2899 * may be presented by FSF
2902 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2904 volatile struct qdio_buffer_element *sbale;
2905 unsigned long lock_flags;
2908 /* setup new FSF request */
2909 retval = zfcp_fsf_req_create(erp_action->adapter,
2911 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2912 erp_action->adapter->pool.fsf_req_erp,
2913 &lock_flags, &(erp_action->fsf_req));
2915 ZFCP_LOG_INFO("error: Could not create open unit request for "
2916 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2917 erp_action->unit->fcp_lun,
2918 erp_action->unit->port->wwpn,
2919 zfcp_get_busid_by_adapter(erp_action->adapter));
2923 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2924 erp_action->fsf_req->sbal_curr, 0);
2925 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2926 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2928 erp_action->fsf_req->qtcb->header.port_handle =
2929 erp_action->port->handle;
2930 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2931 erp_action->unit->fcp_lun;
2932 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2933 erp_action->fsf_req->qtcb->bottom.support.option =
2934 FSF_OPEN_LUN_SUPPRESS_BOXING;
2935 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2936 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
2937 erp_action->fsf_req->erp_action = erp_action;
2939 /* start QDIO request for this FSF request */
2940 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2942 ZFCP_LOG_INFO("error: Could not send an open unit request "
2943 "on the adapter %s, port 0x%016Lx for "
2945 zfcp_get_busid_by_adapter(erp_action->adapter),
2946 erp_action->port->wwpn,
2947 erp_action->unit->fcp_lun);
2948 zfcp_fsf_req_free(erp_action->fsf_req);
2949 erp_action->fsf_req = NULL;
2953 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2954 "port 0x%016Lx, unit 0x%016Lx)\n",
2955 zfcp_get_busid_by_adapter(erp_action->adapter),
2956 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2958 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2964 * function: zfcp_fsf_open_unit_handler
2966 * purpose: is called for finished Open LUN command
2971 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2973 int retval = -EINVAL;
2974 struct zfcp_adapter *adapter;
2975 struct zfcp_unit *unit;
2976 struct fsf_qtcb_header *header;
2977 struct fsf_qtcb_bottom_support *bottom;
2978 struct fsf_queue_designator *queue_designator;
2979 u16 subtable, rule, counter;
2980 int exclusive, readwrite;
2982 unit = (struct zfcp_unit *) fsf_req->data;
2984 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2985 /* don't change unit status in our bookkeeping */
2986 goto skip_fsfstatus;
2989 adapter = fsf_req->adapter;
2990 header = &fsf_req->qtcb->header;
2991 bottom = &fsf_req->qtcb->bottom.support;
2992 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2994 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2995 ZFCP_STATUS_UNIT_SHARED |
2996 ZFCP_STATUS_UNIT_READONLY,
2999 /* evaluate FSF status in QTCB */
3000 switch (header->fsf_status) {
3002 case FSF_PORT_HANDLE_NOT_VALID:
3003 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3004 "for port 0x%016Lx on adapter %s invalid "
3005 "This may happen occasionally\n",
3007 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3008 ZFCP_LOG_DEBUG("status qualifier:\n");
3009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3010 (char *) &header->fsf_status_qual,
3011 sizeof (union fsf_status_qual));
3012 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3013 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3014 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3017 case FSF_LUN_ALREADY_OPEN:
3018 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3019 "remote port 0x%016Lx on adapter %s twice.\n",
3021 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3022 debug_text_exception(adapter->erp_dbf, 0,
3024 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3027 case FSF_ACCESS_DENIED:
3028 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3029 "remote port 0x%016Lx on adapter %s\n",
3030 unit->fcp_lun, unit->port->wwpn,
3031 zfcp_get_busid_by_unit(unit));
3032 for (counter = 0; counter < 2; counter++) {
3033 subtable = header->fsf_status_qual.halfword[counter * 2];
3034 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3036 case FSF_SQ_CFDC_SUBTABLE_OS:
3037 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3038 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3039 case FSF_SQ_CFDC_SUBTABLE_LUN:
3040 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3041 zfcp_act_subtable_type[subtable], rule);
3045 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3046 zfcp_erp_unit_access_denied(unit);
3047 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3048 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3049 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3052 case FSF_PORT_BOXED:
3053 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3054 "needs to be reopened\n",
3055 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3056 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3057 zfcp_erp_port_boxed(unit->port);
3058 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3059 ZFCP_STATUS_FSFREQ_RETRY;
3062 case FSF_LUN_SHARING_VIOLATION:
3063 if (header->fsf_status_qual.word[0] != 0) {
3064 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3066 "connected to the adapter %s "
3067 "is already in use in LPAR%d, CSS%d\n",
3070 zfcp_get_busid_by_unit(unit),
3071 queue_designator->hla,
3072 queue_designator->cssid);
3074 subtable = header->fsf_status_qual.halfword[4];
3075 rule = header->fsf_status_qual.halfword[5];
3077 case FSF_SQ_CFDC_SUBTABLE_OS:
3078 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3079 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3080 case FSF_SQ_CFDC_SUBTABLE_LUN:
3081 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3082 "remote port with WWPN 0x%Lx "
3083 "connected to the adapter %s "
3084 "is denied (%s rule %d)\n",
3087 zfcp_get_busid_by_unit(unit),
3088 zfcp_act_subtable_type[subtable],
3093 ZFCP_LOG_DEBUG("status qualifier:\n");
3094 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3095 (char *) &header->fsf_status_qual,
3096 sizeof (union fsf_status_qual));
3097 debug_text_event(adapter->erp_dbf, 2,
3099 zfcp_erp_unit_access_denied(unit);
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3101 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3102 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3105 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3106 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3107 "There is no handle (temporary port identifier) "
3108 "available for unit 0x%016Lx on port 0x%016Lx "
3112 zfcp_get_busid_by_unit(unit));
3113 debug_text_event(adapter->erp_dbf, 1,
3115 zfcp_erp_unit_failed(unit);
3116 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3119 case FSF_ADAPTER_STATUS_AVAILABLE:
3120 switch (header->fsf_status_qual.word[0]) {
3121 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3122 /* Re-establish link to port */
3123 debug_text_event(adapter->erp_dbf, 1,
3125 zfcp_test_link(unit->port);
3126 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3128 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3129 /* ERP strategy will escalate */
3130 debug_text_event(adapter->erp_dbf, 1,
3132 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3136 ("bug: Wrong status qualifier 0x%x arrived.\n",
3137 header->fsf_status_qual.word[0]);
3138 debug_text_event(adapter->erp_dbf, 0,
3140 debug_exception(adapter->erp_dbf, 0,
3141 &header->fsf_status_qual.word[0],
3146 case FSF_INVALID_COMMAND_OPTION:
3148 "Invalid option 0x%x has been specified "
3149 "in QTCB bottom sent to the adapter %s\n",
3151 zfcp_get_busid_by_adapter(adapter));
3152 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3157 /* save LUN handle assigned by FSF */
3158 unit->handle = header->lun_handle;
3159 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3160 "adapter %s opened, port handle 0x%x\n",
3163 zfcp_get_busid_by_unit(unit),
3165 /* mark unit as open */
3166 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3168 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3169 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3170 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3171 exclusive = (bottom->lun_access_info &
3172 FSF_UNIT_ACCESS_EXCLUSIVE);
3173 readwrite = (bottom->lun_access_info &
3174 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3177 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3181 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3183 ZFCP_LOG_NORMAL("read-only access for unit "
3184 "(adapter %s, wwpn=0x%016Lx, "
3185 "fcp_lun=0x%016Lx)\n",
3186 zfcp_get_busid_by_unit(unit),
3191 if (exclusive && !readwrite) {
3192 ZFCP_LOG_NORMAL("exclusive access of read-only "
3193 "unit not supported\n");
3194 zfcp_erp_unit_failed(unit);
3195 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3196 zfcp_erp_unit_shutdown(unit, 0);
3197 } else if (!exclusive && readwrite) {
3198 ZFCP_LOG_NORMAL("shared access of read-write "
3199 "unit not supported\n");
3200 zfcp_erp_unit_failed(unit);
3201 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3202 zfcp_erp_unit_shutdown(unit, 0);
3210 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3211 "(debug info 0x%x)\n",
3212 header->fsf_status);
3213 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3214 debug_exception(adapter->erp_dbf, 0,
3215 &header->fsf_status, sizeof (u32));
3220 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3225 * function: zfcp_fsf_close_unit
3229 * returns: address of fsf_req - request successfully initiated
3232 * assumptions: This routine does not check whether the associated
3233 * remote port/lun has already been opened. This should be
3234 * done by calling routines. Otherwise some status
3235 * may be presented by FSF
3238 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3240 volatile struct qdio_buffer_element *sbale;
3241 unsigned long lock_flags;
3244 /* setup new FSF request */
3245 retval = zfcp_fsf_req_create(erp_action->adapter,
3247 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3248 erp_action->adapter->pool.fsf_req_erp,
3249 &lock_flags, &(erp_action->fsf_req));
3251 ZFCP_LOG_INFO("error: Could not create close unit request for "
3252 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3253 erp_action->unit->fcp_lun,
3254 erp_action->port->wwpn,
3255 zfcp_get_busid_by_adapter(erp_action->adapter));
3259 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3260 erp_action->fsf_req->sbal_curr, 0);
3261 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3262 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3264 erp_action->fsf_req->qtcb->header.port_handle =
3265 erp_action->port->handle;
3266 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3267 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3268 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3269 erp_action->fsf_req->erp_action = erp_action;
3271 /* start QDIO request for this FSF request */
3272 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3274 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3275 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3276 erp_action->unit->fcp_lun,
3277 erp_action->port->wwpn,
3278 zfcp_get_busid_by_adapter(erp_action->adapter));
3279 zfcp_fsf_req_free(erp_action->fsf_req);
3280 erp_action->fsf_req = NULL;
3284 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3285 "port 0x%016Lx, unit 0x%016Lx)\n",
3286 zfcp_get_busid_by_adapter(erp_action->adapter),
3287 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3289 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3295 * function: zfcp_fsf_close_unit_handler
3297 * purpose: is called for finished Close LUN FSF command
3302 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3304 int retval = -EINVAL;
3305 struct zfcp_unit *unit;
3307 unit = (struct zfcp_unit *) fsf_req->data;
3309 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3310 /* don't change unit status in our bookkeeping */
3311 goto skip_fsfstatus;
3314 /* evaluate FSF status in QTCB */
3315 switch (fsf_req->qtcb->header.fsf_status) {
3317 case FSF_PORT_HANDLE_NOT_VALID:
3318 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3319 "0x%016Lx on adapter %s invalid. This may "
3320 "happen in rare circumstances\n",
3323 zfcp_get_busid_by_unit(unit));
3324 ZFCP_LOG_DEBUG("status qualifier:\n");
3325 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3326 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3327 sizeof (union fsf_status_qual));
3328 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3330 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3331 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3334 case FSF_LUN_HANDLE_NOT_VALID:
3335 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3336 "0x%016Lx on port 0x%016Lx on adapter %s is "
3337 "invalid. This may happen occasionally.\n",
3341 zfcp_get_busid_by_unit(unit));
3342 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3343 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3344 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3345 sizeof (union fsf_status_qual));
3346 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3348 zfcp_erp_port_reopen(unit->port, 0);
3349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3352 case FSF_PORT_BOXED:
3353 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3354 "needs to be reopened\n",
3356 zfcp_get_busid_by_unit(unit));
3357 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3358 zfcp_erp_port_boxed(unit->port);
3359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3360 ZFCP_STATUS_FSFREQ_RETRY;
3363 case FSF_ADAPTER_STATUS_AVAILABLE:
3364 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3365 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3366 /* re-establish link to port */
3367 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3369 zfcp_test_link(unit->port);
3370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3372 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3373 /* ERP strategy will escalate */
3374 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3376 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3380 ("bug: Wrong status qualifier 0x%x arrived.\n",
3381 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3382 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3385 fsf_req->adapter->erp_dbf, 0,
3386 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3393 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3394 "closed, port handle 0x%x\n",
3397 zfcp_get_busid_by_unit(unit),
3399 /* mark unit as closed */
3400 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3405 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3406 "(debug info 0x%x)\n",
3407 fsf_req->qtcb->header.fsf_status);
3408 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3409 debug_exception(fsf_req->adapter->erp_dbf, 0,
3410 &fsf_req->qtcb->header.fsf_status,
3416 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3421 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3422 * @adapter: adapter where scsi command is issued
3423 * @unit: unit where command is sent to
3424 * @scsi_cmnd: scsi command to be sent
3425 * @timer: timer to be started when request is initiated
3426 * @req_flags: flags for fsf_request
3429 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3430 struct zfcp_unit *unit,
3431 struct scsi_cmnd * scsi_cmnd,
3432 struct timer_list *timer, int req_flags)
3434 struct zfcp_fsf_req *fsf_req = NULL;
3435 struct fcp_cmnd_iu *fcp_cmnd_iu;
3436 unsigned int sbtype;
3437 unsigned long lock_flags;
3442 /* setup new FSF request */
3443 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3444 adapter->pool.fsf_req_scsi,
3445 &lock_flags, &fsf_req);
3446 if (unlikely(retval < 0)) {
3447 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3448 "for unit 0x%016Lx on port 0x%016Lx on "
3452 zfcp_get_busid_by_adapter(adapter));
3453 goto failed_req_create;
3456 zfcp_unit_get(unit);
3457 fsf_req->unit = unit;
3459 /* associate FSF request with SCSI request (for look up on abort) */
3460 scsi_cmnd->host_scribble = (char *) fsf_req;
3462 /* associate SCSI command with FSF request */
3463 fsf_req->data = (unsigned long) scsi_cmnd;
3465 /* set handles of unit and its parent port in QTCB */
3466 fsf_req->qtcb->header.lun_handle = unit->handle;
3467 fsf_req->qtcb->header.port_handle = unit->port->handle;
3469 /* FSF does not define the structure of the FCP_CMND IU */
3470 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3471 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3474 * set depending on data direction:
3475 * data direction bits in SBALE (SB Type)
3476 * data direction bits in QTCB
3477 * data direction bits in FCP_CMND IU
3479 switch (scsi_cmnd->sc_data_direction) {
3481 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3484 * what is the correct type for commands
3485 * without 'real' data buffers?
3487 sbtype = SBAL_FLAGS0_TYPE_READ;
3489 case DMA_FROM_DEVICE:
3490 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3491 sbtype = SBAL_FLAGS0_TYPE_READ;
3492 fcp_cmnd_iu->rddata = 1;
3495 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3496 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3497 fcp_cmnd_iu->wddata = 1;
3499 case DMA_BIDIRECTIONAL:
3502 * dummy, catch this condition earlier
3503 * in zfcp_scsi_queuecommand
3505 goto failed_scsi_cmnd;
3508 /* set FC service class in QTCB (3 per default) */
3509 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3511 /* set FCP_LUN in FCP_CMND IU in QTCB */
3512 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3514 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3516 /* set task attributes in FCP_CMND IU in QTCB */
3517 if (likely((scsi_cmnd->device->simple_tags) ||
3518 (atomic_test_mask(mask, &unit->status))))
3519 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3521 fcp_cmnd_iu->task_attribute = UNTAGGED;
3523 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3524 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3525 fcp_cmnd_iu->add_fcp_cdb_length
3526 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3527 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3528 "additional FCP_CDB length is 0x%x "
3529 "(shifted right 2 bits)\n",
3531 fcp_cmnd_iu->add_fcp_cdb_length);
3534 * copy SCSI CDB (including additional length, if any) to
3535 * FCP_CDB in FCP_CMND IU in QTCB
3537 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3539 /* FCP CMND IU length in QTCB */
3540 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3541 sizeof (struct fcp_cmnd_iu) +
3542 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3544 /* generate SBALEs from data buffer */
3545 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3546 if (unlikely(real_bytes < 0)) {
3547 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3549 "Data did not fit into available buffer(s), "
3550 "waiting for more...\n");
3553 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3554 "required. Shutting down unit "
3555 "(adapter %s, port 0x%016Lx, "
3557 zfcp_get_busid_by_unit(unit),
3560 zfcp_erp_unit_shutdown(unit, 0);
3566 /* set length of FCP data length in FCP_CMND IU in QTCB */
3567 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3569 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3570 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3571 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3574 * start QDIO request for this FSF request
3575 * covered by an SBALE)
3577 retval = zfcp_fsf_req_send(fsf_req, timer);
3578 if (unlikely(retval < 0)) {
3579 ZFCP_LOG_INFO("error: Could not send FCP command request "
3580 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3581 zfcp_get_busid_by_adapter(adapter),
3587 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3588 "port 0x%016Lx, unit 0x%016Lx)\n",
3589 zfcp_get_busid_by_adapter(adapter),
3597 zfcp_unit_put(unit);
3598 zfcp_fsf_req_free(fsf_req);
3600 scsi_cmnd->host_scribble = NULL;
3603 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3608 * function: zfcp_fsf_send_fcp_command_task_management
3614 * FIXME(design): should be watched by a timeout!!!
3615 * FIXME(design) shouldn't this be modified to return an int
3616 * also...don't know how though
3619 struct zfcp_fsf_req *
3620 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3621 struct zfcp_unit *unit,
3622 u8 tm_flags, int req_flags)
3624 struct zfcp_fsf_req *fsf_req = NULL;
3626 struct fcp_cmnd_iu *fcp_cmnd_iu;
3627 unsigned long lock_flags;
3628 volatile struct qdio_buffer_element *sbale;
3630 /* setup new FSF request */
3631 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3632 adapter->pool.fsf_req_scsi,
3633 &lock_flags, &fsf_req);
3635 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3636 "management) request for adapter %s, port "
3637 " 0x%016Lx, unit 0x%016Lx.\n",
3638 zfcp_get_busid_by_adapter(adapter),
3639 unit->port->wwpn, unit->fcp_lun);
3644 * Used to decide on proper handler in the return path,
3645 * could be either zfcp_fsf_send_fcp_command_task_handler or
3646 * zfcp_fsf_send_fcp_command_task_management_handler */
3648 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3651 * hold a pointer to the unit being target of this
3652 * task management request
3654 fsf_req->data = (unsigned long) unit;
3656 /* set FSF related fields in QTCB */
3657 fsf_req->qtcb->header.lun_handle = unit->handle;
3658 fsf_req->qtcb->header.port_handle = unit->port->handle;
3659 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3660 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3661 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3662 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3664 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3665 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3666 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3668 /* set FCP related fields in FCP_CMND IU in QTCB */
3669 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3670 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3671 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3672 fcp_cmnd_iu->task_management_flags = tm_flags;
3674 /* start QDIO request for this FSF request */
3675 zfcp_fsf_start_scsi_er_timer(adapter);
3676 retval = zfcp_fsf_req_send(fsf_req, NULL);
3678 del_timer(&adapter->scsi_er_timer);
3679 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3680 "management) on adapter %s, port 0x%016Lx for "
3681 "unit LUN 0x%016Lx\n",
3682 zfcp_get_busid_by_adapter(adapter),
3685 zfcp_fsf_req_free(fsf_req);
3690 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3691 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3693 zfcp_get_busid_by_adapter(adapter),
3698 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3703 * function: zfcp_fsf_send_fcp_command_handler
3705 * purpose: is called for finished Send FCP Command
3710 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3712 int retval = -EINVAL;
3713 struct zfcp_unit *unit;
3714 struct fsf_qtcb_header *header;
3715 u16 subtable, rule, counter;
3717 header = &fsf_req->qtcb->header;
3719 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3720 unit = (struct zfcp_unit *) fsf_req->data;
3722 unit = fsf_req->unit;
3724 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3725 /* go directly to calls of special handlers */
3726 goto skip_fsfstatus;
3729 /* evaluate FSF status in QTCB */
3730 switch (header->fsf_status) {
3732 case FSF_PORT_HANDLE_NOT_VALID:
3733 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3734 "0x%016Lx on adapter %s invalid\n",
3736 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3737 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3738 (char *) &header->fsf_status_qual,
3739 sizeof (union fsf_status_qual));
3740 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3742 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3743 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3746 case FSF_LUN_HANDLE_NOT_VALID:
3747 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3748 "0x%016Lx on port 0x%016Lx on adapter %s is "
3749 "invalid. This may happen occasionally.\n",
3753 zfcp_get_busid_by_unit(unit));
3754 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3755 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3756 (char *) &header->fsf_status_qual,
3757 sizeof (union fsf_status_qual));
3758 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3760 zfcp_erp_port_reopen(unit->port, 0);
3761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3764 case FSF_HANDLE_MISMATCH:
3765 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3766 "unexpectedly. (adapter %s, port 0x%016Lx, "
3769 zfcp_get_busid_by_unit(unit),
3772 ZFCP_LOG_NORMAL("status qualifier:\n");
3773 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3774 (char *) &header->fsf_status_qual,
3775 sizeof (union fsf_status_qual));
3776 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3778 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3779 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3782 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3783 if (fsf_req->adapter->fc_service_class <= 3) {
3784 ZFCP_LOG_NORMAL("error: The adapter %s does "
3785 "not support fibrechannel class %d.\n",
3786 zfcp_get_busid_by_unit(unit),
3787 fsf_req->adapter->fc_service_class);
3789 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3790 "adapter %s is invalid. "
3791 "(debug info %d)\n",
3792 zfcp_get_busid_by_unit(unit),
3793 fsf_req->adapter->fc_service_class);
3795 /* stop operation for this adapter */
3796 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3797 "fsf_s_class_nsup");
3798 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3799 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3802 case FSF_FCPLUN_NOT_VALID:
3803 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3804 "adapter %s does not have correct unit "
3808 zfcp_get_busid_by_unit(unit),
3810 ZFCP_LOG_DEBUG("status qualifier:\n");
3811 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3812 (char *) &header->fsf_status_qual,
3813 sizeof (union fsf_status_qual));
3814 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3815 "fsf_s_fcp_lun_nv");
3816 zfcp_erp_port_reopen(unit->port, 0);
3817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3820 case FSF_ACCESS_DENIED:
3821 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3822 "unit 0x%016Lx on port 0x%016Lx on "
3823 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3824 zfcp_get_busid_by_unit(unit));
3825 for (counter = 0; counter < 2; counter++) {
3826 subtable = header->fsf_status_qual.halfword[counter * 2];
3827 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3829 case FSF_SQ_CFDC_SUBTABLE_OS:
3830 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3831 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3832 case FSF_SQ_CFDC_SUBTABLE_LUN:
3833 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3834 zfcp_act_subtable_type[subtable], rule);
3838 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3839 zfcp_erp_unit_access_denied(unit);
3840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3843 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3844 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3845 "0x%016Lx on port 0x%016Lx on adapter %s "
3846 "(debug info %d)\n",
3849 zfcp_get_busid_by_unit(unit),
3850 fsf_req->qtcb->bottom.io.data_direction);
3851 /* stop operation for this adapter */
3852 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3853 "fsf_s_dir_ind_nv");
3854 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3855 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3858 case FSF_CMND_LENGTH_NOT_VALID:
3860 ("bug: An invalid control-data-block length field "
3861 "was found in a command for unit 0x%016Lx on port "
3862 "0x%016Lx on adapter %s " "(debug info %d)\n",
3863 unit->fcp_lun, unit->port->wwpn,
3864 zfcp_get_busid_by_unit(unit),
3865 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3866 /* stop operation for this adapter */
3867 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3868 "fsf_s_cmd_len_nv");
3869 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3873 case FSF_PORT_BOXED:
3874 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3875 "needs to be reopened\n",
3876 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3877 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3878 zfcp_erp_port_boxed(unit->port);
3879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3880 ZFCP_STATUS_FSFREQ_RETRY;
3884 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3885 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3886 zfcp_get_busid_by_unit(unit),
3887 unit->port->wwpn, unit->fcp_lun);
3888 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3889 zfcp_erp_unit_boxed(unit);
3890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3891 | ZFCP_STATUS_FSFREQ_RETRY;
3894 case FSF_ADAPTER_STATUS_AVAILABLE:
3895 switch (header->fsf_status_qual.word[0]) {
3896 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3897 /* re-establish link to port */
3898 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3900 zfcp_test_link(unit->port);
3902 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3903 /* FIXME(hw) need proper specs for proper action */
3904 /* let scsi stack deal with retries and escalation */
3905 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3910 ("Unknown status qualifier 0x%x arrived.\n",
3911 header->fsf_status_qual.word[0]);
3912 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3914 debug_exception(fsf_req->adapter->erp_dbf, 0,
3915 &header->fsf_status_qual.word[0],
3919 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3925 case FSF_FCP_RSP_AVAILABLE:
3929 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3930 debug_exception(fsf_req->adapter->erp_dbf, 0,
3931 &header->fsf_status, sizeof(u32));
3936 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3938 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3940 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3941 fsf_req->unit = NULL;
3942 zfcp_unit_put(unit);
3948 * function: zfcp_fsf_send_fcp_command_task_handler
3950 * purpose: evaluates FCP_RSP IU
3955 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3958 struct scsi_cmnd *scpnt;
3959 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3960 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3961 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3962 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3964 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3965 unsigned long flags;
3966 struct zfcp_unit *unit = fsf_req->unit;
3968 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3969 scpnt = (struct scsi_cmnd *) fsf_req->data;
3970 if (unlikely(!scpnt)) {
3972 ("Command with fsf_req %p is not associated to "
3973 "a scsi command anymore. Aborted?\n", fsf_req);
3976 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3977 /* FIXME: (design) mid-layer should handle DID_ABORT like
3978 * DID_SOFT_ERROR by retrying the request for devices
3979 * that allow retries.
3981 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3982 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3983 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3984 goto skip_fsfstatus;
3987 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3988 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3989 set_host_byte(&scpnt->result, DID_ERROR);
3990 goto skip_fsfstatus;
3993 /* set message byte of result in SCSI command */
3994 scpnt->result |= COMMAND_COMPLETE << 8;
3997 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3998 * of result in SCSI command
4000 scpnt->result |= fcp_rsp_iu->scsi_status;
4001 if (unlikely(fcp_rsp_iu->scsi_status)) {
4003 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4004 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4005 scpnt->cmnd, scpnt->cmd_len);
4006 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4007 fcp_rsp_iu->scsi_status);
4008 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4009 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4010 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4011 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4012 fcp_rsp_iu->fcp_sns_len);
4015 /* check FCP_RSP_INFO */
4016 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4017 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4018 switch (fcp_rsp_info[3]) {
4021 ZFCP_LOG_TRACE("no failure or Task Management "
4022 "Function complete\n");
4023 set_host_byte(&scpnt->result, DID_OK);
4025 case RSP_CODE_LENGTH_MISMATCH:
4027 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4028 "that the fibrechannel protocol data "
4029 "length differs from the burst length. "
4030 "The problem occured on unit 0x%016Lx "
4031 "on port 0x%016Lx on adapter %s",
4034 zfcp_get_busid_by_unit(unit));
4035 /* dump SCSI CDB as prepared by zfcp */
4036 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4037 (char *) &fsf_req->qtcb->
4038 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4039 set_host_byte(&scpnt->result, DID_ERROR);
4040 goto skip_fsfstatus;
4041 case RSP_CODE_FIELD_INVALID:
4042 /* driver or hardware bug */
4043 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4044 "that the fibrechannel protocol data "
4045 "fields were incorrectly set up. "
4046 "The problem occured on the unit "
4047 "0x%016Lx on port 0x%016Lx on "
4051 zfcp_get_busid_by_unit(unit));
4052 /* dump SCSI CDB as prepared by zfcp */
4053 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4054 (char *) &fsf_req->qtcb->
4055 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4056 set_host_byte(&scpnt->result, DID_ERROR);
4057 goto skip_fsfstatus;
4058 case RSP_CODE_RO_MISMATCH:
4060 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4061 "that conflicting values for the "
4062 "fibrechannel payload offset from the "
4063 "header were found. "
4064 "The problem occured on unit 0x%016Lx "
4065 "on port 0x%016Lx on adapter %s.\n",
4068 zfcp_get_busid_by_unit(unit));
4069 /* dump SCSI CDB as prepared by zfcp */
4070 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4071 (char *) &fsf_req->qtcb->
4072 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4073 set_host_byte(&scpnt->result, DID_ERROR);
4074 goto skip_fsfstatus;
4076 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4077 "code was detected for a command. "
4078 "The problem occured on the unit "
4079 "0x%016Lx on port 0x%016Lx on "
4080 "adapter %s (debug info 0x%x)\n",
4083 zfcp_get_busid_by_unit(unit),
4085 /* dump SCSI CDB as prepared by zfcp */
4086 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4087 (char *) &fsf_req->qtcb->
4088 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4089 set_host_byte(&scpnt->result, DID_ERROR);
4090 goto skip_fsfstatus;
4094 /* check for sense data */
4095 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4096 sns_len = FSF_FCP_RSP_SIZE -
4097 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4098 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4100 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4101 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4102 SCSI_SENSE_BUFFERSIZE);
4103 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4104 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4106 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4107 (void *) &scpnt->cmnd, scpnt->cmd_len);
4109 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4110 fcp_rsp_iu->fcp_sns_len);
4111 memcpy(&scpnt->sense_buffer,
4112 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4113 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4114 (void *) &scpnt->sense_buffer, sns_len);
4117 /* check for overrun */
4118 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4119 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4120 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4121 "The response data length is "
4122 "%d, the original length was %d.\n",
4125 zfcp_get_busid_by_unit(unit),
4126 fcp_rsp_iu->fcp_resid,
4127 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4130 /* check for underrun */
4131 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4132 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4133 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4134 "The response data length is "
4135 "%d, the original length was %d.\n",
4138 zfcp_get_busid_by_unit(unit),
4139 fcp_rsp_iu->fcp_resid,
4140 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4142 scpnt->resid = fcp_rsp_iu->fcp_resid;
4143 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4144 set_host_byte(&scpnt->result, DID_ERROR);
4148 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4150 if (scpnt->result != 0)
4151 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4152 else if (scpnt->retries > 0)
4153 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4155 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
4157 /* cleanup pointer (need this especially for abort) */
4158 scpnt->host_scribble = NULL;
4160 /* always call back */
4161 (scpnt->scsi_done) (scpnt);
4164 * We must hold this lock until scsi_done has been called.
4165 * Otherwise we may call scsi_done after abort regarding this
4166 * command has completed.
4167 * Note: scsi_done must not block!
4170 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4175 * function: zfcp_fsf_send_fcp_command_task_management_handler
4177 * purpose: evaluates FCP_RSP IU
4182 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4185 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4186 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4187 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4188 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4190 del_timer(&fsf_req->adapter->scsi_er_timer);
4191 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4192 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4193 goto skip_fsfstatus;
4196 /* check FCP_RSP_INFO */
4197 switch (fcp_rsp_info[3]) {
4200 ZFCP_LOG_DEBUG("no failure or Task Management "
4201 "Function complete\n");
4203 case RSP_CODE_TASKMAN_UNSUPP:
4204 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4205 "is not supported on the target device "
4206 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4209 zfcp_get_busid_by_unit(unit));
4210 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4212 case RSP_CODE_TASKMAN_FAILED:
4213 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4214 "failed to complete successfully. "
4215 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4218 zfcp_get_busid_by_unit(unit));
4219 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4222 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4223 "code was detected for a command. "
4224 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4225 "(debug info 0x%x)\n",
4228 zfcp_get_busid_by_unit(unit),
4230 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4239 * function: zfcp_fsf_control_file
4241 * purpose: Initiator of the control file upload/download FSF requests
4243 * returns: 0 - FSF request is successfuly created and queued
4244 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4245 * -EINVAL - Invalid direction specified
4246 * -ENOMEM - Insufficient memory
4247 * -EPERM - Cannot create FSF request or place it in QDIO queue
4250 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4251 struct zfcp_fsf_req **fsf_req_ptr,
4254 struct zfcp_sg_list *sg_list)
4256 struct zfcp_fsf_req *fsf_req;
4257 struct fsf_qtcb_bottom_support *bottom;
4258 volatile struct qdio_buffer_element *sbale;
4259 struct timer_list *timer;
4260 unsigned long lock_flags;
4265 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4266 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4267 zfcp_get_busid_by_adapter(adapter));
4268 retval = -EOPNOTSUPP;
4272 switch (fsf_command) {
4274 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4275 direction = SBAL_FLAGS0_TYPE_WRITE;
4276 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4277 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4278 req_flags = ZFCP_WAIT_FOR_SBAL;
4281 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4282 direction = SBAL_FLAGS0_TYPE_READ;
4286 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4291 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4297 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4298 NULL, &lock_flags, &fsf_req);
4300 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4302 zfcp_get_busid_by_adapter(adapter));
4304 goto unlock_queue_lock;
4307 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4308 sbale[0].flags |= direction;
4310 bottom = &fsf_req->qtcb->bottom.support;
4311 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4312 bottom->option = option;
4314 if (sg_list->count > 0) {
4317 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4318 sg_list->sg, sg_list->count,
4319 ZFCP_MAX_SBALS_PER_REQ);
4320 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4322 "error: Could not create sufficient number of "
4323 "SBALS for an FSF request to the adapter %s\n",
4324 zfcp_get_busid_by_adapter(adapter));
4329 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4332 timer->function = zfcp_fsf_request_timeout_handler;
4333 timer->data = (unsigned long) adapter;
4334 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4336 retval = zfcp_fsf_req_send(fsf_req, timer);
4338 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4340 zfcp_get_busid_by_adapter(adapter));
4344 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4346 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4348 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4349 "download" : "upload",
4350 zfcp_get_busid_by_adapter(adapter));
4352 wait_event(fsf_req->completion_wq,
4353 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4355 *fsf_req_ptr = fsf_req;
4356 del_timer_sync(timer);
4360 zfcp_fsf_req_free(fsf_req);
4362 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4371 * function: zfcp_fsf_control_file_handler
4373 * purpose: Handler of the control file upload/download FSF requests
4375 * returns: 0 - FSF request successfuly processed
4376 * -EAGAIN - Operation has to be repeated because of a temporary problem
4377 * -EACCES - There is no permission to execute an operation
4378 * -EPERM - The control file is not in a right format
4379 * -EIO - There is a problem with the FCP adapter
4380 * -EINVAL - Invalid operation
4381 * -EFAULT - User space memory I/O operation fault
4384 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4386 struct zfcp_adapter *adapter = fsf_req->adapter;
4387 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4388 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4391 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4393 goto skip_fsfstatus;
4396 switch (header->fsf_status) {
4400 "The FSF request has been successfully completed "
4401 "on the adapter %s\n",
4402 zfcp_get_busid_by_adapter(adapter));
4405 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4406 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4407 switch (header->fsf_status_qual.word[0]) {
4409 case FSF_SQ_CFDC_HARDENED_ON_SE:
4411 "CFDC on the adapter %s has being "
4412 "hardened on primary and secondary SE\n",
4413 zfcp_get_busid_by_adapter(adapter));
4416 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4418 "CFDC of the adapter %s could not "
4419 "be saved on the SE\n",
4420 zfcp_get_busid_by_adapter(adapter));
4423 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4425 "CFDC of the adapter %s could not "
4426 "be copied to the secondary SE\n",
4427 zfcp_get_busid_by_adapter(adapter));
4432 "CFDC could not be hardened "
4433 "on the adapter %s\n",
4434 zfcp_get_busid_by_adapter(adapter));
4437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4441 case FSF_AUTHORIZATION_FAILURE:
4443 "Adapter %s does not accept privileged commands\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4449 case FSF_CFDC_ERROR_DETECTED:
4451 "Error at position %d in the CFDC, "
4452 "CFDC is discarded by the adapter %s\n",
4453 header->fsf_status_qual.word[0],
4454 zfcp_get_busid_by_adapter(adapter));
4455 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4459 case FSF_CONTROL_FILE_UPDATE_ERROR:
4461 "Adapter %s cannot harden the control file, "
4462 "file is discarded\n",
4463 zfcp_get_busid_by_adapter(adapter));
4464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4468 case FSF_CONTROL_FILE_TOO_LARGE:
4470 "Control file is too large, file is discarded "
4471 "by the adapter %s\n",
4472 zfcp_get_busid_by_adapter(adapter));
4473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4477 case FSF_ACCESS_CONFLICT_DETECTED:
4478 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4480 "CFDC has been discarded by the adapter %s, "
4481 "because activation would impact "
4482 "%d active connection(s)\n",
4483 zfcp_get_busid_by_adapter(adapter),
4484 header->fsf_status_qual.word[0]);
4485 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4489 case FSF_CONFLICTS_OVERRULED:
4490 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4492 "CFDC has been activated on the adapter %s, "
4493 "but activation has impacted "
4494 "%d active connection(s)\n",
4495 zfcp_get_busid_by_adapter(adapter),
4496 header->fsf_status_qual.word[0]);
4497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4501 case FSF_UNKNOWN_OP_SUBTYPE:
4502 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4503 "op_subtype=0x%x)\n",
4504 zfcp_get_busid_by_adapter(adapter),
4505 bottom->operation_subtype);
4506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4510 case FSF_INVALID_COMMAND_OPTION:
4512 "Invalid option 0x%x has been specified "
4513 "in QTCB bottom sent to the adapter %s\n",
4515 zfcp_get_busid_by_adapter(adapter));
4516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4522 "bug: An unknown/unexpected FSF status 0x%08x "
4523 "was presented on the adapter %s\n",
4525 zfcp_get_busid_by_adapter(adapter));
4526 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4527 debug_exception(fsf_req->adapter->erp_dbf, 0,
4528 &header->fsf_status_qual.word[0], sizeof(u32));
4529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4539 zfcp_fsf_req_sbal_check(unsigned long *flags,
4540 struct zfcp_qdio_queue *queue, int needed)
4542 write_lock_irqsave(&queue->queue_lock, *flags);
4543 if (likely(atomic_read(&queue->free_count) >= needed))
4545 write_unlock_irqrestore(&queue->queue_lock, *flags);
4550 * set qtcb pointer in fsf_req and initialize QTCB
4553 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4555 if (likely(fsf_req->qtcb != NULL)) {
4556 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4557 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4558 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4559 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4560 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4561 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4562 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4567 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4568 * @adapter: adapter for which request queue is examined
4569 * @req_flags: flags indicating whether to wait for needed SBAL or not
4570 * @lock_flags: lock_flags if queue_lock is taken
4571 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4572 * Locks: lock adapter->request_queue->queue_lock on success
4575 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4576 unsigned long *lock_flags)
4579 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4581 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4582 ret = wait_event_interruptible_timeout(adapter->request_wq,
4583 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4589 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4596 * function: zfcp_fsf_req_create
4598 * purpose: create an FSF request at the specified adapter and
4599 * setup common fields
4601 * returns: -ENOMEM if there was insufficient memory for a request
4602 * -EIO if no qdio buffers could be allocate to the request
4603 * -EINVAL/-EPERM on bug conditions in req_dequeue
4606 * note: The created request is returned by reference.
4608 * locks: lock of concerned request queue must not be held,
4609 * but is held on completion (write, irqsave)
4612 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4613 mempool_t *pool, unsigned long *lock_flags,
4614 struct zfcp_fsf_req **fsf_req_p)
4616 volatile struct qdio_buffer_element *sbale;
4617 struct zfcp_fsf_req *fsf_req = NULL;
4619 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4621 /* allocate new FSF request */
4622 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4623 if (unlikely(NULL == fsf_req)) {
4624 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4625 "the outbound (send) queue.\n");
4627 goto failed_fsf_req;
4630 fsf_req->adapter = adapter;
4631 fsf_req->fsf_command = fsf_cmd;
4633 zfcp_fsf_req_qtcb_init(fsf_req);
4635 /* initialize waitqueue which may be used to wait on
4636 this request completion */
4637 init_waitqueue_head(&fsf_req->completion_wq);
4639 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4645 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4646 * if it is not set (see also *_open_qdio and *_close_qdio).
4649 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4650 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4655 if (fsf_req->qtcb) {
4656 fsf_req->seq_no = adapter->fsf_req_seq_no;
4657 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4659 fsf_req->sbal_number = 1;
4660 fsf_req->sbal_first = req_queue->free_index;
4661 fsf_req->sbal_curr = req_queue->free_index;
4662 fsf_req->sbale_curr = 1;
4664 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4665 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4668 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4670 /* setup common SBALE fields */
4671 sbale[0].addr = fsf_req;
4672 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4673 if (likely(fsf_req->qtcb != NULL)) {
4674 sbale[1].addr = (void *) fsf_req->qtcb;
4675 sbale[1].length = sizeof(struct fsf_qtcb);
4678 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4679 fsf_req->sbal_number, fsf_req->sbal_first);
4684 /* dequeue new FSF request previously enqueued */
4685 zfcp_fsf_req_free(fsf_req);
4689 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4691 *fsf_req_p = fsf_req;
4696 * function: zfcp_fsf_req_send
4698 * purpose: start transfer of FSF request via QDIO
4700 * returns: 0 - request transfer succesfully started
4701 * !0 - start of request transfer failed
4704 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4706 struct zfcp_adapter *adapter;
4707 struct zfcp_qdio_queue *req_queue;
4708 volatile struct qdio_buffer_element *sbale;
4710 int new_distance_from_int;
4711 unsigned long flags;
4714 adapter = fsf_req->adapter;
4715 req_queue = &adapter->request_queue,
4718 /* FIXME(debug): remove it later */
4719 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4720 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4721 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4722 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4725 /* put allocated FSF request at list tail */
4726 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4727 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4728 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4730 inc_seq_no = (fsf_req->qtcb != NULL);
4732 /* figure out expiration time of timeout and start timeout */
4733 if (unlikely(timer)) {
4734 timer->expires += jiffies;
4738 ZFCP_LOG_TRACE("request queue of adapter %s: "
4739 "next free SBAL is %i, %i free SBALs\n",
4740 zfcp_get_busid_by_adapter(adapter),
4741 req_queue->free_index,
4742 atomic_read(&req_queue->free_count));
4744 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4745 "index_in_queue=%i, count=%i, buffers=%p\n",
4746 zfcp_get_busid_by_adapter(adapter),
4747 QDIO_FLAG_SYNC_OUTPUT,
4748 0, fsf_req->sbal_first, fsf_req->sbal_number,
4749 &req_queue->buffer[fsf_req->sbal_first]);
4752 * adjust the number of free SBALs in request queue as well as
4753 * position of first one
4755 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4756 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4757 req_queue->free_index += fsf_req->sbal_number; /* increase */
4758 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4759 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4761 fsf_req->issued = get_clock();
4763 retval = do_QDIO(adapter->ccw_device,
4764 QDIO_FLAG_SYNC_OUTPUT,
4765 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4767 if (unlikely(retval)) {
4768 /* Queues are down..... */
4771 * FIXME(potential race):
4772 * timer might be expired (absolutely unlikely)
4776 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4777 list_del(&fsf_req->list);
4778 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4780 * adjust the number of free SBALs in request queue as well as
4781 * position of first one
4783 zfcp_qdio_zero_sbals(req_queue->buffer,
4784 fsf_req->sbal_first, fsf_req->sbal_number);
4785 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4786 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4787 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4788 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4790 ("error: do_QDIO failed. Buffers could not be enqueued "
4791 "to request queue.\n");
4793 req_queue->distance_from_int = new_distance_from_int;
4795 * increase FSF sequence counter -
4796 * this must only be done for request successfully enqueued to
4797 * QDIO this rejected requests may be cleaned up by calling
4798 * routines resulting in missing sequence counter values
4802 /* Don't increase for unsolicited status */
4804 adapter->fsf_req_seq_no++;
4806 /* count FSF requests pending */
4807 atomic_inc(&adapter->fsf_reqs_active);
4812 #undef ZFCP_LOG_AREA