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.
35 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
36 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
37 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
38 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_task_management_handler(
45 struct zfcp_fsf_req *);
46 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
47 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
48 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
51 static inline int zfcp_fsf_req_sbal_check(
52 unsigned long *, struct zfcp_qdio_queue *, int);
53 static inline int zfcp_use_one_sbal(
54 struct scatterlist *, int, struct scatterlist *, int);
55 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
56 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
57 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
58 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
59 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
60 static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
61 struct fsf_link_down_info *);
62 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
63 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
65 /* association between FSF command and FSF QTCB type */
66 static u32 fsf_qtcb_type[] = {
67 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
68 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
77 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
78 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
79 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
82 static const char zfcp_act_subtable_type[5][8] = {
83 "unknown", "OS", "WWPN", "DID", "LUN"
86 /****************************************************************/
87 /*************** FSF related Functions *************************/
88 /****************************************************************/
90 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
93 * function: zfcp_fsf_req_alloc
95 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
96 * unsolicited requests) via helper functions
97 * Does some initial fsf request set-up.
99 * returns: pointer to allocated fsf_req if successfull
105 static struct zfcp_fsf_req *
106 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
110 struct zfcp_fsf_req *fsf_req = NULL;
112 if (req_flags & ZFCP_REQ_NO_QTCB)
113 size = sizeof(struct zfcp_fsf_req);
115 size = sizeof(struct zfcp_fsf_req_pool_element);
117 if (likely(pool != NULL))
118 ptr = mempool_alloc(pool, GFP_ATOMIC);
120 ptr = kmalloc(size, GFP_ATOMIC);
122 if (unlikely(NULL == ptr))
125 memset(ptr, 0, size);
127 if (req_flags & ZFCP_REQ_NO_QTCB) {
128 fsf_req = (struct zfcp_fsf_req *) ptr;
130 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
132 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
135 fsf_req->pool = pool;
142 * function: zfcp_fsf_req_free
144 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
145 * returns it into the pool via helper functions.
152 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
154 if (likely(fsf_req->pool != NULL))
155 mempool_free(fsf_req, fsf_req->pool);
167 * note: qdio queues shall be down (no ongoing inbound processing)
170 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
172 struct zfcp_fsf_req *fsf_req, *tmp;
174 LIST_HEAD(remove_queue);
176 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
177 list_splice_init(&adapter->fsf_req_list_head, &remove_queue);
178 atomic_set(&adapter->fsf_reqs_active, 0);
179 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
181 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
182 list_del(&fsf_req->list);
183 zfcp_fsf_req_dismiss(fsf_req);
197 zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
199 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
200 zfcp_fsf_req_complete(fsf_req);
204 * function: zfcp_fsf_req_complete
206 * purpose: Updates active counts and timers for openfcp-reqs
207 * May cleanup request after req_eval returns
209 * returns: 0 - success
215 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
220 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
221 ZFCP_LOG_DEBUG("Status read response received\n");
223 * Note: all cleanup handling is done in the callchain of
224 * the function call-chain below.
226 zfcp_fsf_status_read_handler(fsf_req);
229 zfcp_fsf_protstatus_eval(fsf_req);
232 * fsf_req may be deleted due to waking up functions, so
233 * cleanup is saved here and used later
235 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
240 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
242 /* cleanup request if requested by initiator */
243 if (likely(cleanup)) {
244 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
246 * lock must not be held here since it will be
247 * grabed by the called routine, too
249 zfcp_fsf_req_free(fsf_req);
251 /* notify initiator waiting for the requests completion */
252 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
254 * FIXME: Race! We must not access fsf_req here as it might have been
255 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
256 * flag. It's an improbable case. But, we have the same paranoia for
257 * the cleanup flag already.
258 * Might better be handled using complete()?
259 * (setting the flag and doing wakeup ought to be atomic
260 * with regard to checking the flag as long as waitqueue is
261 * part of the to be released structure)
263 wake_up(&fsf_req->completion_wq);
271 * function: zfcp_fsf_protstatus_eval
273 * purpose: evaluates the QTCB of the finished FSF request
274 * and initiates appropriate actions
275 * (usually calling FSF command specific handlers)
284 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
287 struct zfcp_adapter *adapter = fsf_req->adapter;
288 struct fsf_qtcb *qtcb = fsf_req->qtcb;
289 union fsf_prot_status_qual *prot_status_qual =
290 &qtcb->prefix.prot_status_qual;
292 zfcp_hba_dbf_event_fsf_response(fsf_req);
294 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
295 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
296 (unsigned long) fsf_req);
297 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
298 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
299 goto skip_protstatus;
302 /* log additional information provided by FSF (if any) */
303 if (unlikely(qtcb->header.log_length)) {
304 /* do not trust them ;-) */
305 if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
307 ("bug: ULP (FSF logging) log data starts "
308 "beyond end of packet header. Ignored. "
309 "(start=%i, size=%li)\n",
310 qtcb->header.log_start,
311 sizeof(struct fsf_qtcb));
314 if ((size_t) (qtcb->header.log_start + qtcb->header.log_length)
315 > sizeof(struct fsf_qtcb)) {
316 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
317 "beyond end of packet header. Ignored. "
318 "(start=%i, length=%i, size=%li)\n",
319 qtcb->header.log_start,
320 qtcb->header.log_length,
321 sizeof(struct fsf_qtcb));
324 ZFCP_LOG_TRACE("ULP log data: \n");
325 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
326 (char *) qtcb + qtcb->header.log_start,
327 qtcb->header.log_length);
331 /* evaluate FSF Protocol Status */
332 switch (qtcb->prefix.prot_status) {
335 case FSF_PROT_FSF_STATUS_PRESENTED:
338 case FSF_PROT_QTCB_VERSION_ERROR:
339 ZFCP_LOG_NORMAL("error: The adapter %s contains "
340 "microcode of version 0x%x, the device driver "
341 "only supports 0x%x. Aborting.\n",
342 zfcp_get_busid_by_adapter(adapter),
343 prot_status_qual->version_error.fsf_version,
345 zfcp_erp_adapter_shutdown(adapter, 0);
346 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
349 case FSF_PROT_SEQ_NUMB_ERROR:
350 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
351 "driver (0x%x) and adapter %s (0x%x). "
352 "Restarting all operations on this adapter.\n",
353 qtcb->prefix.req_seq_no,
354 zfcp_get_busid_by_adapter(adapter),
355 prot_status_qual->sequence_error.exp_req_seq_no);
356 zfcp_erp_adapter_reopen(adapter, 0);
357 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
358 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
361 case FSF_PROT_UNSUPP_QTCB_TYPE:
362 ZFCP_LOG_NORMAL("error: Packet header type used by the "
363 "device driver is incompatible with "
364 "that used on adapter %s. "
365 "Stopping all operations on this adapter.\n",
366 zfcp_get_busid_by_adapter(adapter));
367 zfcp_erp_adapter_shutdown(adapter, 0);
368 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
371 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
377 case FSF_PROT_DUPLICATE_REQUEST_ID:
378 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
379 "to the adapter %s is ambiguous. "
380 "Stopping all operations on this adapter.\n",
381 *(unsigned long long*)
382 (&qtcb->bottom.support.req_handle),
383 zfcp_get_busid_by_adapter(adapter));
384 zfcp_erp_adapter_shutdown(adapter, 0);
385 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
388 case FSF_PROT_LINK_DOWN:
389 zfcp_fsf_link_down_info_eval(adapter,
390 &prot_status_qual->link_down_info);
391 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
394 case FSF_PROT_REEST_QUEUE:
395 ZFCP_LOG_NORMAL("The local link to adapter with "
396 "%s was re-plugged. "
397 "Re-starting operations on this adapter.\n",
398 zfcp_get_busid_by_adapter(adapter));
399 /* All ports should be marked as ready to run again */
400 zfcp_erp_modify_adapter_status(adapter,
401 ZFCP_STATUS_COMMON_RUNNING,
403 zfcp_erp_adapter_reopen(adapter,
404 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
405 | ZFCP_STATUS_COMMON_ERP_FAILED);
406 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
409 case FSF_PROT_ERROR_STATE:
410 ZFCP_LOG_NORMAL("error: The adapter %s "
411 "has entered the error state. "
412 "Restarting all operations on this "
414 zfcp_get_busid_by_adapter(adapter));
415 zfcp_erp_adapter_reopen(adapter, 0);
416 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
421 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
422 "provided by the adapter %s "
423 "is not compatible with the device driver. "
424 "Stopping all operations on this adapter. "
425 "(debug info 0x%x).\n",
426 zfcp_get_busid_by_adapter(adapter),
427 qtcb->prefix.prot_status);
428 zfcp_erp_adapter_shutdown(adapter, 0);
429 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
434 * always call specific handlers to give them a chance to do
435 * something meaningful even in error cases
437 zfcp_fsf_fsfstatus_eval(fsf_req);
442 * function: zfcp_fsf_fsfstatus_eval
444 * purpose: evaluates FSF status of completed FSF request
445 * and acts accordingly
450 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
454 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
458 /* evaluate FSF Status */
459 switch (fsf_req->qtcb->header.fsf_status) {
460 case FSF_UNKNOWN_COMMAND:
461 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
462 "not known by the adapter %s "
463 "Stopping all operations on this adapter. "
464 "(debug info 0x%x).\n",
465 zfcp_get_busid_by_adapter(fsf_req->adapter),
466 fsf_req->qtcb->header.fsf_command);
467 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
471 case FSF_FCP_RSP_AVAILABLE:
472 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
476 case FSF_ADAPTER_STATUS_AVAILABLE:
477 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
483 * always call specific handlers to give them a chance to do
484 * something meaningful even in error cases
486 zfcp_fsf_req_dispatch(fsf_req);
492 * function: zfcp_fsf_fsfstatus_qual_eval
494 * purpose: evaluates FSF status-qualifier of completed FSF request
495 * and acts accordingly
500 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
504 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
505 case FSF_SQ_FCP_RSP_AVAILABLE:
507 case FSF_SQ_RETRY_IF_POSSIBLE:
508 /* The SCSI-stack may now issue retries or escalate */
509 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
511 case FSF_SQ_COMMAND_ABORTED:
512 /* Carry the aborted state on to upper layer */
513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
516 case FSF_SQ_NO_RECOM:
517 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
518 "problem on the adapter %s "
519 "Stopping all operations on this adapter. ",
520 zfcp_get_busid_by_adapter(fsf_req->adapter));
521 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
524 case FSF_SQ_ULP_PROGRAMMING_ERROR:
525 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
527 zfcp_get_busid_by_adapter(fsf_req->adapter));
528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
530 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
531 case FSF_SQ_NO_RETRY_POSSIBLE:
532 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
533 /* dealt with in the respective functions */
536 ZFCP_LOG_NORMAL("bug: Additional status info could "
537 "not be interpreted properly.\n");
538 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
539 (char *) &fsf_req->qtcb->header.fsf_status_qual,
540 sizeof (union fsf_status_qual));
541 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
549 * zfcp_fsf_link_down_info_eval - evaluate link down information block
552 zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
553 struct fsf_link_down_info *link_down)
555 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
559 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
561 if (link_down == NULL) {
562 zfcp_erp_adapter_reopen(adapter, 0);
566 switch (link_down->error_code) {
567 case FSF_PSQ_LINK_NO_LIGHT:
568 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
569 "(no light detected)\n",
570 zfcp_get_busid_by_adapter(adapter));
572 case FSF_PSQ_LINK_WRAP_PLUG:
573 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
574 "(wrap plug detected)\n",
575 zfcp_get_busid_by_adapter(adapter));
577 case FSF_PSQ_LINK_NO_FCP:
578 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
579 "(adjacent node on link does not support FCP)\n",
580 zfcp_get_busid_by_adapter(adapter));
582 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
583 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
584 "(firmware update in progress)\n",
585 zfcp_get_busid_by_adapter(adapter));
587 case FSF_PSQ_LINK_INVALID_WWPN:
588 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
589 "(duplicate or invalid WWPN detected)\n",
590 zfcp_get_busid_by_adapter(adapter));
592 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
593 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
594 "(no support for NPIV by Fabric)\n",
595 zfcp_get_busid_by_adapter(adapter));
597 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
598 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
599 "(out of resource in FCP daughtercard)\n",
600 zfcp_get_busid_by_adapter(adapter));
602 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
603 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
604 "(out of resource in Fabric)\n",
605 zfcp_get_busid_by_adapter(adapter));
607 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
608 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
609 "(unable to Fabric login)\n",
610 zfcp_get_busid_by_adapter(adapter));
612 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
613 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
614 zfcp_get_busid_by_adapter(adapter));
616 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
617 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
618 zfcp_get_busid_by_adapter(adapter));
620 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
621 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
622 zfcp_get_busid_by_adapter(adapter));
625 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
626 "(warning: unknown reason code %d)\n",
627 zfcp_get_busid_by_adapter(adapter),
628 link_down->error_code);
631 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
632 ZFCP_LOG_DEBUG("Debug information to link down: "
633 "primary_status=0x%02x "
635 "action_code=0x%02x "
636 "reason_code=0x%02x "
637 "explanation_code=0x%02x "
638 "vendor_specific_code=0x%02x\n",
639 link_down->primary_status,
640 link_down->ioerr_code,
641 link_down->action_code,
642 link_down->reason_code,
643 link_down->explanation_code,
644 link_down->vendor_specific_code);
646 switch (link_down->error_code) {
647 case FSF_PSQ_LINK_NO_LIGHT:
648 case FSF_PSQ_LINK_WRAP_PLUG:
649 case FSF_PSQ_LINK_NO_FCP:
650 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
651 zfcp_erp_adapter_reopen(adapter, 0);
654 zfcp_erp_adapter_failed(adapter);
659 * function: zfcp_fsf_req_dispatch
661 * purpose: calls the appropriate command specific handler
666 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
668 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
669 struct zfcp_adapter *adapter = fsf_req->adapter;
673 switch (fsf_req->fsf_command) {
675 case FSF_QTCB_FCP_CMND:
676 zfcp_fsf_send_fcp_command_handler(fsf_req);
679 case FSF_QTCB_ABORT_FCP_CMND:
680 zfcp_fsf_abort_fcp_command_handler(fsf_req);
683 case FSF_QTCB_SEND_GENERIC:
684 zfcp_fsf_send_ct_handler(fsf_req);
687 case FSF_QTCB_OPEN_PORT_WITH_DID:
688 zfcp_fsf_open_port_handler(fsf_req);
691 case FSF_QTCB_OPEN_LUN:
692 zfcp_fsf_open_unit_handler(fsf_req);
695 case FSF_QTCB_CLOSE_LUN:
696 zfcp_fsf_close_unit_handler(fsf_req);
699 case FSF_QTCB_CLOSE_PORT:
700 zfcp_fsf_close_port_handler(fsf_req);
703 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
704 zfcp_fsf_close_physical_port_handler(fsf_req);
707 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
708 zfcp_fsf_exchange_config_data_handler(fsf_req);
711 case FSF_QTCB_EXCHANGE_PORT_DATA:
712 zfcp_fsf_exchange_port_data_handler(fsf_req);
715 case FSF_QTCB_SEND_ELS:
716 zfcp_fsf_send_els_handler(fsf_req);
719 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
720 zfcp_fsf_control_file_handler(fsf_req);
723 case FSF_QTCB_UPLOAD_CONTROL_FILE:
724 zfcp_fsf_control_file_handler(fsf_req);
728 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
729 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
730 "not supported by the adapter %s\n",
731 zfcp_get_busid_by_adapter(adapter));
732 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
734 ("bug: Command issued by the device driver differs "
735 "from the command returned by the adapter %s "
736 "(debug info 0x%x, 0x%x).\n",
737 zfcp_get_busid_by_adapter(adapter),
738 fsf_req->fsf_command,
739 fsf_req->qtcb->header.fsf_command);
745 zfcp_erp_async_handler(erp_action, 0);
751 * function: zfcp_fsf_status_read
753 * purpose: initiates a Status Read command at the specified adapter
758 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
760 struct zfcp_fsf_req *fsf_req;
761 struct fsf_status_read_buffer *status_buffer;
762 unsigned long lock_flags;
763 volatile struct qdio_buffer_element *sbale;
766 /* setup new FSF request */
767 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
768 req_flags | ZFCP_REQ_NO_QTCB,
769 adapter->pool.fsf_req_status_read,
770 &lock_flags, &fsf_req);
772 ZFCP_LOG_INFO("error: Could not create unsolicited status "
773 "buffer for adapter %s.\n",
774 zfcp_get_busid_by_adapter(adapter));
775 goto failed_req_create;
778 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
779 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
780 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
781 fsf_req->sbale_curr = 2;
784 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
785 if (!status_buffer) {
786 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
789 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
790 fsf_req->data = (unsigned long) status_buffer;
792 /* insert pointer to respective buffer */
793 sbale = zfcp_qdio_sbale_curr(fsf_req);
794 sbale->addr = (void *) status_buffer;
795 sbale->length = sizeof(struct fsf_status_read_buffer);
797 /* start QDIO request for this FSF request */
798 retval = zfcp_fsf_req_send(fsf_req, NULL);
800 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
802 goto failed_req_send;
805 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
806 zfcp_get_busid_by_adapter(adapter));
810 mempool_free(status_buffer, adapter->pool.data_status_read);
813 zfcp_fsf_req_free(fsf_req);
815 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
817 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
822 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
824 struct fsf_status_read_buffer *status_buffer;
825 struct zfcp_adapter *adapter;
826 struct zfcp_port *port;
829 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
830 adapter = fsf_req->adapter;
832 read_lock_irqsave(&zfcp_data.config_lock, flags);
833 list_for_each_entry(port, &adapter->port_list_head, list)
834 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
836 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
838 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
839 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
840 "nonexisting port with d_id 0x%08x on "
841 "adapter %s. Ignored.\n",
842 status_buffer->d_id & ZFCP_DID_MASK,
843 zfcp_get_busid_by_adapter(adapter));
847 switch (status_buffer->status_subtype) {
849 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
850 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
851 zfcp_erp_port_reopen(port, 0);
854 case FSF_STATUS_READ_SUB_ERROR_PORT:
855 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
856 zfcp_erp_port_shutdown(port, 0);
860 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
861 debug_exception(adapter->erp_dbf, 0,
862 &status_buffer->status_subtype, sizeof (u32));
863 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
864 "for a reopen indication on port with "
865 "d_id 0x%08x on the adapter %s. "
866 "Ignored. (debug info 0x%x)\n",
868 zfcp_get_busid_by_adapter(adapter),
869 status_buffer->status_subtype);
876 * function: zfcp_fsf_status_read_handler
878 * purpose: is called for finished Open Port command
883 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
886 struct zfcp_adapter *adapter = fsf_req->adapter;
887 struct fsf_status_read_buffer *status_buffer =
888 (struct fsf_status_read_buffer *) fsf_req->data;
890 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
891 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
892 mempool_free(status_buffer, adapter->pool.data_status_read);
893 zfcp_fsf_req_free(fsf_req);
897 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
899 switch (status_buffer->status_type) {
901 case FSF_STATUS_READ_PORT_CLOSED:
902 zfcp_fsf_status_read_port_closed(fsf_req);
905 case FSF_STATUS_READ_INCOMING_ELS:
906 zfcp_fsf_incoming_els(fsf_req);
909 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
910 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
911 zfcp_get_busid_by_adapter(adapter));
914 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
915 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
916 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
917 (char *) status_buffer,
918 sizeof (struct fsf_status_read_buffer));
921 case FSF_STATUS_READ_LINK_DOWN:
922 switch (status_buffer->status_subtype) {
923 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
924 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
925 zfcp_get_busid_by_adapter(adapter));
926 zfcp_fsf_link_down_info_eval(adapter,
927 (struct fsf_link_down_info *)
928 &status_buffer->payload);
930 case FSF_STATUS_READ_SUB_FDISC_FAILED:
931 ZFCP_LOG_INFO("Local link to adapter %s is down "
932 "due to failed FDISC login\n",
933 zfcp_get_busid_by_adapter(adapter));
934 zfcp_fsf_link_down_info_eval(adapter,
935 (struct fsf_link_down_info *)
936 &status_buffer->payload);
938 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
939 ZFCP_LOG_INFO("Local link to adapter %s is down "
940 "due to firmware update on adapter\n",
941 zfcp_get_busid_by_adapter(adapter));
942 zfcp_fsf_link_down_info_eval(adapter, NULL);
945 ZFCP_LOG_INFO("Local link to adapter %s is down "
946 "due to unknown reason\n",
947 zfcp_get_busid_by_adapter(adapter));
948 zfcp_fsf_link_down_info_eval(adapter, NULL);
952 case FSF_STATUS_READ_LINK_UP:
953 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
954 "Restarting operations on this adapter\n",
955 zfcp_get_busid_by_adapter(adapter));
956 /* All ports should be marked as ready to run again */
957 zfcp_erp_modify_adapter_status(adapter,
958 ZFCP_STATUS_COMMON_RUNNING,
960 zfcp_erp_adapter_reopen(adapter,
961 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
962 | ZFCP_STATUS_COMMON_ERP_FAILED);
965 case FSF_STATUS_READ_NOTIFICATION_LOST:
966 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
967 "adapter %s%s%s%s%s%s%s%s%s\n",
968 zfcp_get_busid_by_adapter(adapter),
969 (status_buffer->status_subtype &
970 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
971 ", incoming ELS" : "",
972 (status_buffer->status_subtype &
973 FSF_STATUS_READ_SUB_SENSE_DATA) ?
975 (status_buffer->status_subtype &
976 FSF_STATUS_READ_SUB_LINK_STATUS) ?
977 ", link status change" : "",
978 (status_buffer->status_subtype &
979 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
981 (status_buffer->status_subtype &
982 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
983 ", bit error exception" : "",
984 (status_buffer->status_subtype &
985 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
987 (status_buffer->status_subtype &
988 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
989 ", ACT hardening" : "",
990 (status_buffer->status_subtype &
991 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
992 ", adapter feature change" : "");
994 if (status_buffer->status_subtype &
995 FSF_STATUS_READ_SUB_ACT_UPDATED)
996 zfcp_erp_adapter_access_changed(adapter);
999 case FSF_STATUS_READ_CFDC_UPDATED:
1000 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1001 zfcp_get_busid_by_adapter(adapter));
1002 zfcp_erp_adapter_access_changed(adapter);
1005 case FSF_STATUS_READ_CFDC_HARDENED:
1006 switch (status_buffer->status_subtype) {
1007 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1008 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1009 zfcp_get_busid_by_adapter(adapter));
1011 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1012 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1013 "to the secondary SE\n",
1014 zfcp_get_busid_by_adapter(adapter));
1017 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1018 zfcp_get_busid_by_adapter(adapter));
1022 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1023 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1024 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1025 "been changed from 0x%08X to 0x%08X\n",
1026 zfcp_get_busid_by_adapter(adapter),
1027 *(u32*) (status_buffer->payload + 4),
1028 *(u32*) (status_buffer->payload));
1029 adapter->adapter_features = *(u32*) status_buffer->payload;
1033 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1034 "type was received (debug info 0x%x)\n",
1035 status_buffer->status_type);
1036 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1038 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1039 (char *) status_buffer,
1040 sizeof (struct fsf_status_read_buffer));
1043 mempool_free(status_buffer, adapter->pool.data_status_read);
1044 zfcp_fsf_req_free(fsf_req);
1046 * recycle buffer and start new request repeat until outbound
1047 * queue is empty or adapter shutdown is requested
1051 * we may wait in the req_create for 5s during shutdown, so
1052 * qdio_cleanup will have to wait at least that long before returning
1053 * with failure to allow us a proper cleanup under all circumstances
1057 * allocation failure possible? (Is this code needed?)
1059 retval = zfcp_fsf_status_read(adapter, 0);
1061 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1062 "request for the adapter %s.\n",
1063 zfcp_get_busid_by_adapter(adapter));
1064 /* temporary fix to avoid status read buffer shortage */
1065 adapter->status_read_failed++;
1066 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1067 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1068 ZFCP_LOG_INFO("restart adapter %s due to status read "
1069 "buffer shortage\n",
1070 zfcp_get_busid_by_adapter(adapter));
1071 zfcp_erp_adapter_reopen(adapter, 0);
1079 * function: zfcp_fsf_abort_fcp_command
1081 * purpose: tells FSF to abort a running SCSI command
1083 * returns: address of initiated FSF request
1084 * NULL - request could not be initiated
1086 * FIXME(design): should be watched by a timeout !!!
1087 * FIXME(design) shouldn't this be modified to return an int
1088 * also...don't know how though
1090 struct zfcp_fsf_req *
1091 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1092 struct zfcp_adapter *adapter,
1093 struct zfcp_unit *unit, int req_flags)
1095 volatile struct qdio_buffer_element *sbale;
1096 unsigned long lock_flags;
1097 struct zfcp_fsf_req *fsf_req = NULL;
1100 /* setup new FSF request */
1101 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1102 req_flags, adapter->pool.fsf_req_abort,
1103 &lock_flags, &fsf_req);
1105 ZFCP_LOG_INFO("error: Failed to create an abort command "
1106 "request for lun 0x%016Lx on port 0x%016Lx "
1110 zfcp_get_busid_by_adapter(adapter));
1114 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1115 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1116 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1118 fsf_req->data = (unsigned long) unit;
1120 /* set handles of unit and its parent port in QTCB */
1121 fsf_req->qtcb->header.lun_handle = unit->handle;
1122 fsf_req->qtcb->header.port_handle = unit->port->handle;
1124 /* set handle of request which should be aborted */
1125 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1127 /* start QDIO request for this FSF request */
1129 zfcp_fsf_start_scsi_er_timer(adapter);
1130 retval = zfcp_fsf_req_send(fsf_req, NULL);
1132 del_timer(&adapter->scsi_er_timer);
1133 ZFCP_LOG_INFO("error: Failed to send abort command request "
1134 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1135 zfcp_get_busid_by_adapter(adapter),
1136 unit->port->wwpn, unit->fcp_lun);
1137 zfcp_fsf_req_free(fsf_req);
1142 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1143 "(adapter%s, port d_id=0x%08x, "
1144 "unit x%016Lx, old_req_id=0x%lx)\n",
1145 zfcp_get_busid_by_adapter(adapter),
1147 unit->fcp_lun, old_req_id);
1149 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1154 * function: zfcp_fsf_abort_fcp_command_handler
1156 * purpose: is called for finished Abort FCP Command request
1161 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1163 int retval = -EINVAL;
1164 struct zfcp_unit *unit;
1165 unsigned char status_qual =
1166 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1168 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1170 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1171 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1172 goto skip_fsfstatus;
1175 unit = (struct zfcp_unit *) new_fsf_req->data;
1177 /* evaluate FSF status in QTCB */
1178 switch (new_fsf_req->qtcb->header.fsf_status) {
1180 case FSF_PORT_HANDLE_NOT_VALID:
1181 if (status_qual >> 4 != status_qual % 0xf) {
1182 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1185 * In this case a command that was sent prior to a port
1186 * reopen was aborted (handles are different). This is
1190 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1191 "port 0x%016Lx on adapter %s invalid. "
1192 "This may happen occasionally.\n",
1195 zfcp_get_busid_by_unit(unit));
1196 ZFCP_LOG_INFO("status qualifier:\n");
1197 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1198 (char *) &new_fsf_req->qtcb->header.
1200 sizeof (union fsf_status_qual));
1201 /* Let's hope this sorts out the mess */
1202 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1204 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1205 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1209 case FSF_LUN_HANDLE_NOT_VALID:
1210 if (status_qual >> 4 != status_qual % 0xf) {
1212 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1215 * In this case a command that was sent prior to a unit
1216 * reopen was aborted (handles are different).
1221 ("Warning: Temporary LUN identifier 0x%x of LUN "
1222 "0x%016Lx on port 0x%016Lx on adapter %s is "
1223 "invalid. This may happen in rare cases. "
1224 "Trying to re-establish link.\n",
1228 zfcp_get_busid_by_unit(unit));
1229 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1230 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1231 (char *) &new_fsf_req->qtcb->header.
1233 sizeof (union fsf_status_qual));
1234 /* Let's hope this sorts out the mess */
1235 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1237 zfcp_erp_port_reopen(unit->port, 0);
1238 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1242 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1244 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1246 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1249 case FSF_PORT_BOXED:
1250 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1251 "be reopened\n", unit->port->wwpn,
1252 zfcp_get_busid_by_unit(unit));
1253 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1255 zfcp_erp_port_boxed(unit->port);
1256 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1257 | ZFCP_STATUS_FSFREQ_RETRY;
1262 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1264 unit->fcp_lun, unit->port->wwpn,
1265 zfcp_get_busid_by_unit(unit));
1266 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1267 zfcp_erp_unit_boxed(unit);
1268 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1269 | ZFCP_STATUS_FSFREQ_RETRY;
1272 case FSF_ADAPTER_STATUS_AVAILABLE:
1273 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1274 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1275 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1277 zfcp_test_link(unit->port);
1278 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1280 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1281 /* SCSI stack will escalate */
1282 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1284 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1288 ("bug: Wrong status qualifier 0x%x arrived.\n",
1289 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1290 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1292 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1293 &new_fsf_req->qtcb->header.
1294 fsf_status_qual.word[0], sizeof (u32));
1301 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1305 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1306 "(debug info 0x%x)\n",
1307 new_fsf_req->qtcb->header.fsf_status);
1308 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1310 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1311 &new_fsf_req->qtcb->header.fsf_status,
1320 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1322 * Two scatter-gather lists are passed, one for the reqeust and one for the
1326 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1327 struct scatterlist *resp, int resp_count)
1329 return ((req_count == 1) &&
1330 (resp_count == 1) &&
1331 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1333 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1334 req[0].length - 1) & PAGE_MASK)) &&
1335 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1337 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1338 resp[0].length - 1) & PAGE_MASK)));
1342 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1343 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1345 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1346 * a struct zfcp_fsf_req
1347 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1348 * is sent within error recovery
1351 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1352 struct zfcp_erp_action *erp_action)
1354 volatile struct qdio_buffer_element *sbale;
1355 struct zfcp_port *port;
1356 struct zfcp_adapter *adapter;
1357 struct zfcp_fsf_req *fsf_req;
1358 unsigned long lock_flags;
1363 adapter = port->adapter;
1365 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1366 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1367 pool, &lock_flags, &fsf_req);
1369 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1371 zfcp_get_busid_by_adapter(adapter));
1375 if (erp_action != NULL) {
1376 erp_action->fsf_req = fsf_req;
1377 fsf_req->erp_action = erp_action;
1380 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1381 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1382 ct->resp, ct->resp_count)){
1383 /* both request buffer and response buffer
1384 fit into one sbale each */
1385 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1386 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1387 sbale[2].length = ct->req[0].length;
1388 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1389 sbale[3].length = ct->resp[0].length;
1390 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1391 } else if (adapter->adapter_features &
1392 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1393 /* try to use chained SBALs */
1394 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1395 SBAL_FLAGS0_TYPE_WRITE_READ,
1396 ct->req, ct->req_count,
1397 ZFCP_MAX_SBALS_PER_CT_REQ);
1399 ZFCP_LOG_INFO("error: creation of CT request failed "
1401 zfcp_get_busid_by_adapter(adapter));
1409 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1410 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1411 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1412 SBAL_FLAGS0_TYPE_WRITE_READ,
1413 ct->resp, ct->resp_count,
1414 ZFCP_MAX_SBALS_PER_CT_REQ);
1416 ZFCP_LOG_INFO("error: creation of CT request failed "
1418 zfcp_get_busid_by_adapter(adapter));
1426 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1428 /* reject send generic request */
1430 "error: microcode does not support chained SBALs,"
1431 "CT request too big (adapter %s)\n",
1432 zfcp_get_busid_by_adapter(adapter));
1437 /* settings in QTCB */
1438 fsf_req->qtcb->header.port_handle = port->handle;
1439 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1440 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1441 fsf_req->data = (unsigned long) ct;
1443 zfcp_san_dbf_event_ct_request(fsf_req);
1445 /* start QDIO request for this FSF request */
1446 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1448 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1449 "(adapter %s, port 0x%016Lx)\n",
1450 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1454 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1455 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1459 zfcp_fsf_req_free(fsf_req);
1460 if (erp_action != NULL) {
1461 erp_action->fsf_req = NULL;
1465 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1471 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1472 * @fsf_req: pointer to struct zfcp_fsf_req
1474 * Data specific for the Generic Service request is passed using
1475 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1476 * Usually a specific handler for the CT request is called which is
1477 * found in this structure.
1480 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1482 struct zfcp_port *port;
1483 struct zfcp_adapter *adapter;
1484 struct zfcp_send_ct *send_ct;
1485 struct fsf_qtcb_header *header;
1486 struct fsf_qtcb_bottom_support *bottom;
1487 int retval = -EINVAL;
1488 u16 subtable, rule, counter;
1490 adapter = fsf_req->adapter;
1491 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1492 port = send_ct->port;
1493 header = &fsf_req->qtcb->header;
1494 bottom = &fsf_req->qtcb->bottom.support;
1496 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1497 goto skip_fsfstatus;
1499 /* evaluate FSF status in QTCB */
1500 switch (header->fsf_status) {
1503 zfcp_san_dbf_event_ct_response(fsf_req);
1507 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1508 if (adapter->fc_service_class <= 3) {
1509 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1511 zfcp_get_busid_by_port(port),
1512 adapter->fc_service_class);
1514 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1515 "adapter %s is invalid. "
1516 "(debug info %d)\n",
1517 zfcp_get_busid_by_port(port),
1518 adapter->fc_service_class);
1520 /* stop operation for this adapter */
1521 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1522 zfcp_erp_adapter_shutdown(adapter, 0);
1523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1526 case FSF_ADAPTER_STATUS_AVAILABLE:
1527 switch (header->fsf_status_qual.word[0]){
1528 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1529 /* reopening link to port */
1530 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1531 zfcp_test_link(port);
1532 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1534 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1535 /* ERP strategy will escalate */
1536 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1540 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1542 header->fsf_status_qual.word[0]);
1547 case FSF_ACCESS_DENIED:
1548 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1549 "command (adapter %s, port d_id=0x%08x)\n",
1550 zfcp_get_busid_by_port(port), port->d_id);
1551 for (counter = 0; counter < 2; counter++) {
1552 subtable = header->fsf_status_qual.halfword[counter * 2];
1553 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1555 case FSF_SQ_CFDC_SUBTABLE_OS:
1556 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1557 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1558 case FSF_SQ_CFDC_SUBTABLE_LUN:
1559 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1560 zfcp_act_subtable_type[subtable], rule);
1564 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1565 zfcp_erp_port_access_denied(port);
1566 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1569 case FSF_GENERIC_COMMAND_REJECTED:
1570 ZFCP_LOG_INFO("generic service command rejected "
1571 "(adapter %s, port d_id=0x%08x)\n",
1572 zfcp_get_busid_by_port(port), port->d_id);
1573 ZFCP_LOG_INFO("status qualifier:\n");
1574 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1575 (char *) &header->fsf_status_qual,
1576 sizeof (union fsf_status_qual));
1577 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1578 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1581 case FSF_PORT_HANDLE_NOT_VALID:
1582 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1583 "0x%016Lx on adapter %s invalid. This may "
1584 "happen occasionally.\n", port->handle,
1585 port->wwpn, zfcp_get_busid_by_port(port));
1586 ZFCP_LOG_INFO("status qualifier:\n");
1587 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1588 (char *) &header->fsf_status_qual,
1589 sizeof (union fsf_status_qual));
1590 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1591 zfcp_erp_adapter_reopen(adapter, 0);
1592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1595 case FSF_PORT_BOXED:
1596 ZFCP_LOG_INFO("port needs to be reopened "
1597 "(adapter %s, port d_id=0x%08x)\n",
1598 zfcp_get_busid_by_port(port), port->d_id);
1599 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1600 zfcp_erp_port_boxed(port);
1601 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1602 | ZFCP_STATUS_FSFREQ_RETRY;
1605 /* following states should never occure, all cases avoided
1606 in zfcp_fsf_send_ct - but who knows ... */
1607 case FSF_PAYLOAD_SIZE_MISMATCH:
1608 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1609 "req_buf_length=%d, resp_buf_length=%d)\n",
1610 zfcp_get_busid_by_adapter(adapter),
1611 bottom->req_buf_length, bottom->resp_buf_length);
1612 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1614 case FSF_REQUEST_SIZE_TOO_LARGE:
1615 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1616 "req_buf_length=%d)\n",
1617 zfcp_get_busid_by_adapter(adapter),
1618 bottom->req_buf_length);
1619 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1621 case FSF_RESPONSE_SIZE_TOO_LARGE:
1622 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1623 "resp_buf_length=%d)\n",
1624 zfcp_get_busid_by_adapter(adapter),
1625 bottom->resp_buf_length);
1626 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1628 case FSF_SBAL_MISMATCH:
1629 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1630 "resp_buf_length=%d)\n",
1631 zfcp_get_busid_by_adapter(adapter),
1632 bottom->req_buf_length, bottom->resp_buf_length);
1633 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1637 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1638 "(debug info 0x%x)\n", header->fsf_status);
1639 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1640 debug_exception(adapter->erp_dbf, 0,
1641 &header->fsf_status_qual.word[0], sizeof (u32));
1646 send_ct->status = retval;
1648 if (send_ct->handler != NULL)
1649 send_ct->handler(send_ct->handler_data);
1655 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1656 * @els: pointer to struct zfcp_send_els which contains all needed data for
1660 zfcp_fsf_send_els(struct zfcp_send_els *els)
1662 volatile struct qdio_buffer_element *sbale;
1663 struct zfcp_fsf_req *fsf_req;
1665 struct zfcp_adapter *adapter;
1666 unsigned long lock_flags;
1671 adapter = els->adapter;
1673 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1674 ZFCP_REQ_AUTO_CLEANUP,
1675 NULL, &lock_flags, &fsf_req);
1677 ZFCP_LOG_INFO("error: creation of ELS request failed "
1678 "(adapter %s, port d_id: 0x%08x)\n",
1679 zfcp_get_busid_by_adapter(adapter), d_id);
1683 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1684 if (zfcp_use_one_sbal(els->req, els->req_count,
1685 els->resp, els->resp_count)){
1686 /* both request buffer and response buffer
1687 fit into one sbale each */
1688 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1689 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1690 sbale[2].length = els->req[0].length;
1691 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1692 sbale[3].length = els->resp[0].length;
1693 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1694 } else if (adapter->adapter_features &
1695 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1696 /* try to use chained SBALs */
1697 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1698 SBAL_FLAGS0_TYPE_WRITE_READ,
1699 els->req, els->req_count,
1700 ZFCP_MAX_SBALS_PER_ELS_REQ);
1702 ZFCP_LOG_INFO("error: creation of ELS request failed "
1703 "(adapter %s, port d_id: 0x%08x)\n",
1704 zfcp_get_busid_by_adapter(adapter), d_id);
1712 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1713 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1714 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1715 SBAL_FLAGS0_TYPE_WRITE_READ,
1716 els->resp, els->resp_count,
1717 ZFCP_MAX_SBALS_PER_ELS_REQ);
1719 ZFCP_LOG_INFO("error: creation of ELS request failed "
1720 "(adapter %s, port d_id: 0x%08x)\n",
1721 zfcp_get_busid_by_adapter(adapter), d_id);
1729 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1731 /* reject request */
1732 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1733 ", ELS request too big (adapter %s, "
1734 "port d_id: 0x%08x)\n",
1735 zfcp_get_busid_by_adapter(adapter), d_id);
1740 /* settings in QTCB */
1741 fsf_req->qtcb->bottom.support.d_id = d_id;
1742 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1743 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1744 fsf_req->data = (unsigned long) els;
1746 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1748 zfcp_san_dbf_event_els_request(fsf_req);
1750 /* start QDIO request for this FSF request */
1751 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1753 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1754 "(adapter %s, port d_id: 0x%08x)\n",
1755 zfcp_get_busid_by_adapter(adapter), d_id);
1759 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1760 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1764 zfcp_fsf_req_free(fsf_req);
1768 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1775 * zfcp_fsf_send_els_handler - handler for ELS commands
1776 * @fsf_req: pointer to struct zfcp_fsf_req
1778 * Data specific for the ELS command is passed using
1779 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1780 * Usually a specific handler for the ELS command is called which is
1781 * found in this structure.
1783 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1785 struct zfcp_adapter *adapter;
1786 struct zfcp_port *port;
1788 struct fsf_qtcb_header *header;
1789 struct fsf_qtcb_bottom_support *bottom;
1790 struct zfcp_send_els *send_els;
1791 int retval = -EINVAL;
1792 u16 subtable, rule, counter;
1794 send_els = (struct zfcp_send_els *) fsf_req->data;
1795 adapter = send_els->adapter;
1796 port = send_els->port;
1797 d_id = send_els->d_id;
1798 header = &fsf_req->qtcb->header;
1799 bottom = &fsf_req->qtcb->bottom.support;
1801 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1802 goto skip_fsfstatus;
1804 switch (header->fsf_status) {
1807 zfcp_san_dbf_event_els_response(fsf_req);
1811 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1812 if (adapter->fc_service_class <= 3) {
1813 ZFCP_LOG_INFO("error: adapter %s does "
1814 "not support fibrechannel class %d.\n",
1815 zfcp_get_busid_by_adapter(adapter),
1816 adapter->fc_service_class);
1818 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1819 "adapter %s is invalid. "
1820 "(debug info %d)\n",
1821 zfcp_get_busid_by_adapter(adapter),
1822 adapter->fc_service_class);
1824 /* stop operation for this adapter */
1825 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1826 zfcp_erp_adapter_shutdown(adapter, 0);
1827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1830 case FSF_ADAPTER_STATUS_AVAILABLE:
1831 switch (header->fsf_status_qual.word[0]){
1832 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1833 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1834 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1835 zfcp_test_link(port);
1836 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1838 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1839 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1842 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1843 (struct zfcp_ls_rjt_par *)
1844 &header->fsf_status_qual.word[2]);
1846 case FSF_SQ_RETRY_IF_POSSIBLE:
1847 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1848 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1851 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1852 header->fsf_status_qual.word[0]);
1853 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1854 (char*)header->fsf_status_qual.word, 16);
1858 case FSF_ELS_COMMAND_REJECTED:
1859 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1860 "prohibited sending "
1861 "(adapter: %s, port d_id: 0x%08x)\n",
1862 zfcp_get_busid_by_adapter(adapter), d_id);
1866 case FSF_PAYLOAD_SIZE_MISMATCH:
1868 "ELS request size and ELS response size must be either "
1869 "both 0, or both greater than 0 "
1870 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1871 zfcp_get_busid_by_adapter(adapter),
1872 bottom->req_buf_length,
1873 bottom->resp_buf_length);
1876 case FSF_REQUEST_SIZE_TOO_LARGE:
1878 "Length of the ELS request buffer, "
1879 "specified in QTCB bottom, "
1880 "exceeds the size of the buffers "
1881 "that have been allocated for ELS request data "
1882 "(adapter: %s, req_buf_length=%d)\n",
1883 zfcp_get_busid_by_adapter(adapter),
1884 bottom->req_buf_length);
1887 case FSF_RESPONSE_SIZE_TOO_LARGE:
1889 "Length of the ELS response buffer, "
1890 "specified in QTCB bottom, "
1891 "exceeds the size of the buffers "
1892 "that have been allocated for ELS response data "
1893 "(adapter: %s, resp_buf_length=%d)\n",
1894 zfcp_get_busid_by_adapter(adapter),
1895 bottom->resp_buf_length);
1898 case FSF_SBAL_MISMATCH:
1899 /* should never occure, avoided in zfcp_fsf_send_els */
1900 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1901 "resp_buf_length=%d)\n",
1902 zfcp_get_busid_by_adapter(adapter),
1903 bottom->req_buf_length, bottom->resp_buf_length);
1904 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1907 case FSF_ACCESS_DENIED:
1908 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1909 "(adapter %s, port d_id=0x%08x)\n",
1910 zfcp_get_busid_by_adapter(adapter), d_id);
1911 for (counter = 0; counter < 2; counter++) {
1912 subtable = header->fsf_status_qual.halfword[counter * 2];
1913 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1915 case FSF_SQ_CFDC_SUBTABLE_OS:
1916 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1917 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1918 case FSF_SQ_CFDC_SUBTABLE_LUN:
1919 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1920 zfcp_act_subtable_type[subtable], rule);
1924 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1926 zfcp_erp_port_access_denied(port);
1927 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1932 "bug: An unknown FSF Status was presented "
1933 "(adapter: %s, fsf_status=0x%08x)\n",
1934 zfcp_get_busid_by_adapter(adapter),
1935 header->fsf_status);
1936 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1937 debug_exception(adapter->erp_dbf, 0,
1938 &header->fsf_status_qual.word[0], sizeof(u32));
1939 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1944 send_els->status = retval;
1946 if (send_els->handler != 0)
1947 send_els->handler(send_els->handler_data);
1957 * returns: address of initiated FSF request
1958 * NULL - request could not be initiated
1961 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1963 volatile struct qdio_buffer_element *sbale;
1964 unsigned long lock_flags;
1967 /* setup new FSF request */
1968 retval = zfcp_fsf_req_create(erp_action->adapter,
1969 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1970 ZFCP_REQ_AUTO_CLEANUP,
1971 erp_action->adapter->pool.fsf_req_erp,
1972 &lock_flags, &(erp_action->fsf_req));
1974 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1975 "data request for adapter %s.\n",
1976 zfcp_get_busid_by_adapter(erp_action->adapter));
1980 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1981 erp_action->fsf_req->sbal_curr, 0);
1982 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1983 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1985 erp_action->fsf_req->erp_action = erp_action;
1986 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1988 FSF_FEATURE_LUN_SHARING |
1989 FSF_FEATURE_NOTIFICATION_LOST |
1990 FSF_FEATURE_UPDATE_ALERT;
1992 /* start QDIO request for this FSF request */
1993 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1996 ("error: Could not send exchange configuration data "
1997 "command on the adapter %s\n",
1998 zfcp_get_busid_by_adapter(erp_action->adapter));
1999 zfcp_fsf_req_free(erp_action->fsf_req);
2000 erp_action->fsf_req = NULL;
2004 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2006 zfcp_get_busid_by_adapter(erp_action->adapter));
2009 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2015 * zfcp_fsf_exchange_config_evaluate
2016 * @fsf_req: fsf_req which belongs to xchg config data request
2017 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2019 * returns: -EIO on error, 0 otherwise
2022 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2024 struct fsf_qtcb_bottom_config *bottom;
2025 struct zfcp_adapter *adapter = fsf_req->adapter;
2026 struct Scsi_Host *shost = adapter->scsi_host;
2028 bottom = &fsf_req->qtcb->bottom.config;
2029 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2030 bottom->low_qtcb_version, bottom->high_qtcb_version);
2031 adapter->fsf_lic_version = bottom->lic_version;
2032 adapter->adapter_features = bottom->adapter_features;
2033 adapter->connection_features = bottom->connection_features;
2034 adapter->peer_wwpn = 0;
2035 adapter->peer_wwnn = 0;
2036 adapter->peer_d_id = 0;
2039 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2040 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2041 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2042 fc_host_speed(shost) = bottom->fc_link_speed;
2043 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2044 adapter->hydra_version = bottom->adapter_type;
2045 if (fc_host_permanent_port_name(shost) == -1)
2046 fc_host_permanent_port_name(shost) =
2047 fc_host_port_name(shost);
2048 if (bottom->fc_topology == FSF_TOPO_P2P) {
2049 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2050 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2051 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2052 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2053 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2054 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2055 else if (bottom->fc_topology == FSF_TOPO_AL)
2056 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2058 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2060 fc_host_node_name(shost) = 0;
2061 fc_host_port_name(shost) = 0;
2062 fc_host_port_id(shost) = 0;
2063 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2064 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2065 adapter->hydra_version = 0;
2068 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2069 adapter->hardware_version = bottom->hardware_version;
2070 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2071 min(FC_SERIAL_NUMBER_SIZE, 17));
2072 EBCASC(fc_host_serial_number(shost),
2073 min(FC_SERIAL_NUMBER_SIZE, 17));
2076 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2080 "adapter version 0x%x, "
2081 "LIC version 0x%x, "
2082 "FC link speed %d Gb/s\n",
2083 zfcp_get_busid_by_adapter(adapter),
2084 (wwn_t) fc_host_node_name(shost),
2085 (wwn_t) fc_host_port_name(shost),
2086 fc_host_port_id(shost),
2087 adapter->hydra_version,
2088 adapter->fsf_lic_version,
2089 fc_host_speed(shost));
2090 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2091 ZFCP_LOG_NORMAL("error: the adapter %s "
2092 "only supports newer control block "
2093 "versions in comparison to this device "
2094 "driver (try updated device driver)\n",
2095 zfcp_get_busid_by_adapter(adapter));
2096 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2097 zfcp_erp_adapter_shutdown(adapter, 0);
2100 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2101 ZFCP_LOG_NORMAL("error: the adapter %s "
2102 "only supports older control block "
2103 "versions than this device driver uses"
2104 "(consider a microcode upgrade)\n",
2105 zfcp_get_busid_by_adapter(adapter));
2106 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2107 zfcp_erp_adapter_shutdown(adapter, 0);
2114 * function: zfcp_fsf_exchange_config_data_handler
2116 * purpose: is called for finished Exchange Configuration Data command
2121 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2123 struct fsf_qtcb_bottom_config *bottom;
2124 struct zfcp_adapter *adapter = fsf_req->adapter;
2125 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2127 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2130 switch (qtcb->header.fsf_status) {
2133 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2136 switch (fc_host_port_type(adapter->scsi_host)) {
2137 case FC_PORTTYPE_PTP:
2138 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2139 "configuration detected at adapter %s\n"
2140 "Peer WWNN 0x%016llx, "
2141 "peer WWPN 0x%016llx, "
2142 "peer d_id 0x%06x\n",
2143 zfcp_get_busid_by_adapter(adapter),
2146 adapter->peer_d_id);
2147 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2150 case FC_PORTTYPE_NLPORT:
2151 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2152 "topology detected at adapter %s "
2153 "unsupported, shutting down adapter\n",
2154 zfcp_get_busid_by_adapter(adapter));
2155 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2157 zfcp_erp_adapter_shutdown(adapter, 0);
2159 case FC_PORTTYPE_NPORT:
2160 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2161 "network detected at adapter %s.\n",
2162 zfcp_get_busid_by_adapter(adapter));
2165 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2166 "reported by the exchange "
2167 "configuration command for "
2168 "the adapter %s is not "
2169 "of a type known to the zfcp "
2170 "driver, shutting down adapter\n",
2171 zfcp_get_busid_by_adapter(adapter));
2172 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2174 zfcp_erp_adapter_shutdown(adapter, 0);
2177 bottom = &qtcb->bottom.config;
2178 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2179 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2180 "allowed by the adapter %s "
2181 "is lower than the minimum "
2182 "required by the driver (%ld bytes).\n",
2183 bottom->max_qtcb_size,
2184 zfcp_get_busid_by_adapter(adapter),
2185 sizeof(struct fsf_qtcb));
2186 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2188 debug_event(fsf_req->adapter->erp_dbf, 0,
2189 &bottom->max_qtcb_size, sizeof (u32));
2190 zfcp_erp_adapter_shutdown(adapter, 0);
2193 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2196 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2197 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2199 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2202 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2204 zfcp_fsf_link_down_info_eval(adapter,
2205 &qtcb->header.fsf_status_qual.link_down_info);
2208 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2209 debug_event(fsf_req->adapter->erp_dbf, 0,
2210 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2211 zfcp_erp_adapter_shutdown(adapter, 0);
2218 * zfcp_fsf_exchange_port_data - request information about local port
2219 * @erp_action: ERP action for the adapter for which port data is requested
2220 * @adapter: for which port data is requested
2221 * @data: response to exchange port data request
2224 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2225 struct zfcp_adapter *adapter,
2226 struct fsf_qtcb_bottom_port *data)
2228 volatile struct qdio_buffer_element *sbale;
2230 unsigned long lock_flags;
2231 struct zfcp_fsf_req *fsf_req;
2232 struct timer_list *timer;
2234 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2235 ZFCP_LOG_INFO("error: exchange port data "
2236 "command not supported by adapter %s\n",
2237 zfcp_get_busid_by_adapter(adapter));
2241 /* setup new FSF request */
2242 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2243 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2244 0, &lock_flags, &fsf_req);
2246 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2247 "exchange port data request for"
2248 "the adapter %s.\n",
2249 zfcp_get_busid_by_adapter(adapter));
2250 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2256 fsf_req->data = (unsigned long) data;
2258 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2259 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2260 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2263 erp_action->fsf_req = fsf_req;
2264 fsf_req->erp_action = erp_action;
2265 timer = &erp_action->timer;
2267 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2269 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2271 zfcp_fsf_req_free(fsf_req);
2275 timer->function = zfcp_fsf_request_timeout_handler;
2276 timer->data = (unsigned long) adapter;
2277 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2280 retval = zfcp_fsf_req_send(fsf_req, timer);
2282 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2283 "command on the adapter %s\n",
2284 zfcp_get_busid_by_adapter(adapter));
2285 zfcp_fsf_req_free(fsf_req);
2287 erp_action->fsf_req = NULL;
2290 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2295 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2298 wait_event(fsf_req->completion_wq,
2299 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2300 del_timer_sync(timer);
2301 zfcp_fsf_req_free(fsf_req);
2309 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2310 * @fsf_req: pointer to struct zfcp_fsf_req
2313 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2315 struct zfcp_adapter *adapter = fsf_req->adapter;
2316 struct Scsi_Host *shost = adapter->scsi_host;
2317 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2318 struct fsf_qtcb_bottom_port *bottom, *data;
2320 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2323 switch (qtcb->header.fsf_status) {
2325 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2327 bottom = &qtcb->bottom.port;
2328 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2330 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2331 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2332 fc_host_permanent_port_name(shost) = bottom->wwpn;
2334 fc_host_permanent_port_name(shost) =
2335 fc_host_port_name(shost);
2336 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2337 fc_host_supported_speeds(shost) = bottom->supported_speed;
2340 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2341 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2343 zfcp_fsf_link_down_info_eval(adapter,
2344 &qtcb->header.fsf_status_qual.link_down_info);
2348 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2349 debug_event(adapter->erp_dbf, 0,
2350 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2356 * function: zfcp_fsf_open_port
2360 * returns: address of initiated FSF request
2361 * NULL - request could not be initiated
2364 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2366 volatile struct qdio_buffer_element *sbale;
2367 unsigned long lock_flags;
2370 /* setup new FSF request */
2371 retval = zfcp_fsf_req_create(erp_action->adapter,
2372 FSF_QTCB_OPEN_PORT_WITH_DID,
2373 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2374 erp_action->adapter->pool.fsf_req_erp,
2375 &lock_flags, &(erp_action->fsf_req));
2377 ZFCP_LOG_INFO("error: Could not create open port request "
2378 "for port 0x%016Lx on adapter %s.\n",
2379 erp_action->port->wwpn,
2380 zfcp_get_busid_by_adapter(erp_action->adapter));
2384 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2385 erp_action->fsf_req->sbal_curr, 0);
2386 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2387 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2389 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2390 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2391 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2392 erp_action->fsf_req->erp_action = erp_action;
2394 /* start QDIO request for this FSF request */
2395 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2397 ZFCP_LOG_INFO("error: Could not send open port request for "
2398 "port 0x%016Lx on adapter %s.\n",
2399 erp_action->port->wwpn,
2400 zfcp_get_busid_by_adapter(erp_action->adapter));
2401 zfcp_fsf_req_free(erp_action->fsf_req);
2402 erp_action->fsf_req = NULL;
2406 ZFCP_LOG_DEBUG("open port request initiated "
2407 "(adapter %s, port 0x%016Lx)\n",
2408 zfcp_get_busid_by_adapter(erp_action->adapter),
2409 erp_action->port->wwpn);
2411 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2417 * function: zfcp_fsf_open_port_handler
2419 * purpose: is called for finished Open Port command
2424 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2426 int retval = -EINVAL;
2427 struct zfcp_port *port;
2428 struct fsf_plogi *plogi;
2429 struct fsf_qtcb_header *header;
2430 u16 subtable, rule, counter;
2432 port = (struct zfcp_port *) fsf_req->data;
2433 header = &fsf_req->qtcb->header;
2435 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2436 /* don't change port status in our bookkeeping */
2437 goto skip_fsfstatus;
2440 /* evaluate FSF status in QTCB */
2441 switch (header->fsf_status) {
2443 case FSF_PORT_ALREADY_OPEN:
2444 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2445 "is already open.\n",
2446 port->wwpn, zfcp_get_busid_by_port(port));
2447 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2450 * This is a bug, however operation should continue normally
2451 * if it is simply ignored
2455 case FSF_ACCESS_DENIED:
2456 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2458 port->wwpn, zfcp_get_busid_by_port(port));
2459 for (counter = 0; counter < 2; counter++) {
2460 subtable = header->fsf_status_qual.halfword[counter * 2];
2461 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2463 case FSF_SQ_CFDC_SUBTABLE_OS:
2464 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2465 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2466 case FSF_SQ_CFDC_SUBTABLE_LUN:
2467 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2468 zfcp_act_subtable_type[subtable], rule);
2472 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2473 zfcp_erp_port_access_denied(port);
2474 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2477 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2478 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2479 "The remote port 0x%016Lx on adapter %s "
2480 "could not be opened. Disabling it.\n",
2481 port->wwpn, zfcp_get_busid_by_port(port));
2482 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2484 zfcp_erp_port_failed(port);
2485 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2488 case FSF_ADAPTER_STATUS_AVAILABLE:
2489 switch (header->fsf_status_qual.word[0]) {
2490 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2491 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2493 /* ERP strategy will escalate */
2494 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2496 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2497 /* ERP strategy will escalate */
2498 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2502 case FSF_SQ_NO_RETRY_POSSIBLE:
2503 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2504 "adapter %s could not be opened. "
2507 zfcp_get_busid_by_port(port));
2508 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2510 zfcp_erp_port_failed(port);
2511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2515 ("bug: Wrong status qualifier 0x%x arrived.\n",
2516 header->fsf_status_qual.word[0]);
2517 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2520 fsf_req->adapter->erp_dbf, 0,
2521 &header->fsf_status_qual.word[0],
2528 /* save port handle assigned by FSF */
2529 port->handle = header->port_handle;
2530 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2531 "was opened, it's port handle is 0x%x\n",
2532 port->wwpn, zfcp_get_busid_by_port(port),
2534 /* mark port as open */
2535 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2536 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2537 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2538 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2541 /* check whether D_ID has changed during open */
2543 * FIXME: This check is not airtight, as the FCP channel does
2544 * not monitor closures of target port connections caused on
2545 * the remote side. Thus, they might miss out on invalidating
2546 * locally cached WWPNs (and other N_Port parameters) of gone
2547 * target ports. So, our heroic attempt to make things safe
2548 * could be undermined by 'open port' response data tagged with
2549 * obsolete WWPNs. Another reason to monitor potential
2550 * connection closures ourself at least (by interpreting
2551 * incoming ELS' and unsolicited status). It just crosses my
2552 * mind that one should be able to cross-check by means of
2553 * another GID_PN straight after a port has been opened.
2554 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2556 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2557 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2559 if (fsf_req->qtcb->bottom.support.els1_length <
2560 ((((unsigned long) &plogi->serv_param.wwpn) -
2561 ((unsigned long) plogi)) + sizeof (u64))) {
2563 "warning: insufficient length of "
2564 "PLOGI payload (%i)\n",
2565 fsf_req->qtcb->bottom.support.els1_length);
2566 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2567 "fsf_s_short_plogi:");
2568 /* skip sanity check and assume wwpn is ok */
2570 if (plogi->serv_param.wwpn != port->wwpn) {
2571 ZFCP_LOG_INFO("warning: d_id of port "
2572 "0x%016Lx changed during "
2573 "open\n", port->wwpn);
2575 fsf_req->adapter->erp_dbf, 0,
2576 "fsf_s_did_change:");
2578 ZFCP_STATUS_PORT_DID_DID,
2581 port->wwnn = plogi->serv_param.wwnn;
2586 case FSF_UNKNOWN_OP_SUBTYPE:
2587 /* should never occure, subtype not set in zfcp_fsf_open_port */
2588 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2589 "op_subtype=0x%x)\n",
2590 zfcp_get_busid_by_port(port),
2591 fsf_req->qtcb->bottom.support.operation_subtype);
2592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2596 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2597 "(debug info 0x%x)\n",
2598 header->fsf_status);
2599 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2600 debug_exception(fsf_req->adapter->erp_dbf, 0,
2601 &header->fsf_status, sizeof (u32));
2606 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2611 * function: zfcp_fsf_close_port
2613 * purpose: submit FSF command "close port"
2615 * returns: address of initiated FSF request
2616 * NULL - request could not be initiated
2619 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2621 volatile struct qdio_buffer_element *sbale;
2622 unsigned long lock_flags;
2625 /* setup new FSF request */
2626 retval = zfcp_fsf_req_create(erp_action->adapter,
2627 FSF_QTCB_CLOSE_PORT,
2628 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2629 erp_action->adapter->pool.fsf_req_erp,
2630 &lock_flags, &(erp_action->fsf_req));
2632 ZFCP_LOG_INFO("error: Could not create a close port request "
2633 "for port 0x%016Lx on adapter %s.\n",
2634 erp_action->port->wwpn,
2635 zfcp_get_busid_by_adapter(erp_action->adapter));
2639 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2640 erp_action->fsf_req->sbal_curr, 0);
2641 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2642 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2644 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2645 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2646 erp_action->fsf_req->erp_action = erp_action;
2647 erp_action->fsf_req->qtcb->header.port_handle =
2648 erp_action->port->handle;
2650 /* start QDIO request for this FSF request */
2651 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2653 ZFCP_LOG_INFO("error: Could not send a close port request for "
2654 "port 0x%016Lx on adapter %s.\n",
2655 erp_action->port->wwpn,
2656 zfcp_get_busid_by_adapter(erp_action->adapter));
2657 zfcp_fsf_req_free(erp_action->fsf_req);
2658 erp_action->fsf_req = NULL;
2662 ZFCP_LOG_TRACE("close port request initiated "
2663 "(adapter %s, port 0x%016Lx)\n",
2664 zfcp_get_busid_by_adapter(erp_action->adapter),
2665 erp_action->port->wwpn);
2667 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2673 * function: zfcp_fsf_close_port_handler
2675 * purpose: is called for finished Close Port FSF command
2680 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2682 int retval = -EINVAL;
2683 struct zfcp_port *port;
2685 port = (struct zfcp_port *) fsf_req->data;
2687 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2688 /* don't change port status in our bookkeeping */
2689 goto skip_fsfstatus;
2692 /* evaluate FSF status in QTCB */
2693 switch (fsf_req->qtcb->header.fsf_status) {
2695 case FSF_PORT_HANDLE_NOT_VALID:
2696 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2697 "0x%016Lx on adapter %s invalid. This may happen "
2698 "occasionally.\n", port->handle,
2699 port->wwpn, zfcp_get_busid_by_port(port));
2700 ZFCP_LOG_DEBUG("status qualifier:\n");
2701 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2702 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2703 sizeof (union fsf_status_qual));
2704 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2706 zfcp_erp_adapter_reopen(port->adapter, 0);
2707 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2710 case FSF_ADAPTER_STATUS_AVAILABLE:
2711 /* Note: FSF has actually closed the port in this case.
2712 * The status code is just daft. Fingers crossed for a change
2718 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2719 "port handle 0x%x\n", port->wwpn,
2720 zfcp_get_busid_by_port(port), port->handle);
2721 zfcp_erp_modify_port_status(port,
2722 ZFCP_STATUS_COMMON_OPEN,
2728 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2729 "(debug info 0x%x)\n",
2730 fsf_req->qtcb->header.fsf_status);
2731 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2732 debug_exception(fsf_req->adapter->erp_dbf, 0,
2733 &fsf_req->qtcb->header.fsf_status,
2739 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2744 * function: zfcp_fsf_close_physical_port
2746 * purpose: submit FSF command "close physical port"
2748 * returns: address of initiated FSF request
2749 * NULL - request could not be initiated
2752 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2755 unsigned long lock_flags;
2756 volatile struct qdio_buffer_element *sbale;
2758 /* setup new FSF request */
2759 retval = zfcp_fsf_req_create(erp_action->adapter,
2760 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2761 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2762 erp_action->adapter->pool.fsf_req_erp,
2763 &lock_flags, &erp_action->fsf_req);
2765 ZFCP_LOG_INFO("error: Could not create close physical port "
2766 "request (adapter %s, port 0x%016Lx)\n",
2767 zfcp_get_busid_by_adapter(erp_action->adapter),
2768 erp_action->port->wwpn);
2773 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2774 erp_action->fsf_req->sbal_curr, 0);
2775 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2776 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2778 /* mark port as being closed */
2779 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2780 &erp_action->port->status);
2781 /* save a pointer to this port */
2782 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2783 /* port to be closed */
2784 erp_action->fsf_req->qtcb->header.port_handle =
2785 erp_action->port->handle;
2786 erp_action->fsf_req->erp_action = erp_action;
2788 /* start QDIO request for this FSF request */
2789 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2791 ZFCP_LOG_INFO("error: Could not send close physical port "
2792 "request (adapter %s, port 0x%016Lx)\n",
2793 zfcp_get_busid_by_adapter(erp_action->adapter),
2794 erp_action->port->wwpn);
2795 zfcp_fsf_req_free(erp_action->fsf_req);
2796 erp_action->fsf_req = NULL;
2800 ZFCP_LOG_TRACE("close physical port request initiated "
2801 "(adapter %s, port 0x%016Lx)\n",
2802 zfcp_get_busid_by_adapter(erp_action->adapter),
2803 erp_action->port->wwpn);
2805 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2811 * function: zfcp_fsf_close_physical_port_handler
2813 * purpose: is called for finished Close Physical Port FSF command
2818 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2820 int retval = -EINVAL;
2821 struct zfcp_port *port;
2822 struct zfcp_unit *unit;
2823 struct fsf_qtcb_header *header;
2824 u16 subtable, rule, counter;
2826 port = (struct zfcp_port *) fsf_req->data;
2827 header = &fsf_req->qtcb->header;
2829 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2830 /* don't change port status in our bookkeeping */
2831 goto skip_fsfstatus;
2834 /* evaluate FSF status in QTCB */
2835 switch (header->fsf_status) {
2837 case FSF_PORT_HANDLE_NOT_VALID:
2838 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2839 "(adapter %s, port 0x%016Lx). "
2840 "This may happen occasionally.\n",
2842 zfcp_get_busid_by_port(port),
2844 ZFCP_LOG_DEBUG("status qualifier:\n");
2845 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2846 (char *) &header->fsf_status_qual,
2847 sizeof (union fsf_status_qual));
2848 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2850 zfcp_erp_adapter_reopen(port->adapter, 0);
2851 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2854 case FSF_ACCESS_DENIED:
2855 ZFCP_LOG_NORMAL("Access denied, cannot close "
2856 "physical port 0x%016Lx on adapter %s\n",
2857 port->wwpn, zfcp_get_busid_by_port(port));
2858 for (counter = 0; counter < 2; counter++) {
2859 subtable = header->fsf_status_qual.halfword[counter * 2];
2860 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2862 case FSF_SQ_CFDC_SUBTABLE_OS:
2863 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2864 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2865 case FSF_SQ_CFDC_SUBTABLE_LUN:
2866 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2867 zfcp_act_subtable_type[subtable], rule);
2871 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2872 zfcp_erp_port_access_denied(port);
2873 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2876 case FSF_PORT_BOXED:
2877 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2878 "%s needs to be reopened but it was attempted "
2879 "to close it physically.\n",
2881 zfcp_get_busid_by_port(port));
2882 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2883 zfcp_erp_port_boxed(port);
2884 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2885 ZFCP_STATUS_FSFREQ_RETRY;
2888 case FSF_ADAPTER_STATUS_AVAILABLE:
2889 switch (header->fsf_status_qual.word[0]) {
2890 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2891 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2893 /* This will now be escalated by ERP */
2894 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2896 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2897 /* ERP strategy will escalate */
2898 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2900 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2904 ("bug: Wrong status qualifier 0x%x arrived.\n",
2905 header->fsf_status_qual.word[0]);
2906 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2909 fsf_req->adapter->erp_dbf, 0,
2910 &header->fsf_status_qual.word[0], sizeof (u32));
2916 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2917 "physically closed, port handle 0x%x\n",
2919 zfcp_get_busid_by_port(port), port->handle);
2920 /* can't use generic zfcp_erp_modify_port_status because
2921 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2923 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2924 list_for_each_entry(unit, &port->unit_list_head, list)
2925 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2930 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2931 "(debug info 0x%x)\n",
2932 header->fsf_status);
2933 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2934 debug_exception(fsf_req->adapter->erp_dbf, 0,
2935 &header->fsf_status, sizeof (u32));
2940 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2945 * function: zfcp_fsf_open_unit
2951 * assumptions: This routine does not check whether the associated
2952 * remote port has already been opened. This should be
2953 * done by calling routines. Otherwise some status
2954 * may be presented by FSF
2957 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2959 volatile struct qdio_buffer_element *sbale;
2960 unsigned long lock_flags;
2963 /* setup new FSF request */
2964 retval = zfcp_fsf_req_create(erp_action->adapter,
2966 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2967 erp_action->adapter->pool.fsf_req_erp,
2968 &lock_flags, &(erp_action->fsf_req));
2970 ZFCP_LOG_INFO("error: Could not create open unit request for "
2971 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2972 erp_action->unit->fcp_lun,
2973 erp_action->unit->port->wwpn,
2974 zfcp_get_busid_by_adapter(erp_action->adapter));
2978 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2979 erp_action->fsf_req->sbal_curr, 0);
2980 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2981 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2983 erp_action->fsf_req->qtcb->header.port_handle =
2984 erp_action->port->handle;
2985 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2986 erp_action->unit->fcp_lun;
2987 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2988 erp_action->fsf_req->qtcb->bottom.support.option =
2989 FSF_OPEN_LUN_SUPPRESS_BOXING;
2990 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2991 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
2992 erp_action->fsf_req->erp_action = erp_action;
2994 /* start QDIO request for this FSF request */
2995 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2997 ZFCP_LOG_INFO("error: Could not send an open unit request "
2998 "on the adapter %s, port 0x%016Lx for "
3000 zfcp_get_busid_by_adapter(erp_action->adapter),
3001 erp_action->port->wwpn,
3002 erp_action->unit->fcp_lun);
3003 zfcp_fsf_req_free(erp_action->fsf_req);
3004 erp_action->fsf_req = NULL;
3008 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3009 "port 0x%016Lx, unit 0x%016Lx)\n",
3010 zfcp_get_busid_by_adapter(erp_action->adapter),
3011 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3013 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3019 * function: zfcp_fsf_open_unit_handler
3021 * purpose: is called for finished Open LUN command
3026 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3028 int retval = -EINVAL;
3029 struct zfcp_adapter *adapter;
3030 struct zfcp_unit *unit;
3031 struct fsf_qtcb_header *header;
3032 struct fsf_qtcb_bottom_support *bottom;
3033 struct fsf_queue_designator *queue_designator;
3034 u16 subtable, rule, counter;
3035 int exclusive, readwrite;
3037 unit = (struct zfcp_unit *) fsf_req->data;
3039 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3040 /* don't change unit status in our bookkeeping */
3041 goto skip_fsfstatus;
3044 adapter = fsf_req->adapter;
3045 header = &fsf_req->qtcb->header;
3046 bottom = &fsf_req->qtcb->bottom.support;
3047 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3049 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3050 ZFCP_STATUS_UNIT_SHARED |
3051 ZFCP_STATUS_UNIT_READONLY,
3054 /* evaluate FSF status in QTCB */
3055 switch (header->fsf_status) {
3057 case FSF_PORT_HANDLE_NOT_VALID:
3058 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3059 "for port 0x%016Lx on adapter %s invalid "
3060 "This may happen occasionally\n",
3062 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3063 ZFCP_LOG_DEBUG("status qualifier:\n");
3064 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3065 (char *) &header->fsf_status_qual,
3066 sizeof (union fsf_status_qual));
3067 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3068 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3069 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3072 case FSF_LUN_ALREADY_OPEN:
3073 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3074 "remote port 0x%016Lx on adapter %s twice.\n",
3076 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3077 debug_text_exception(adapter->erp_dbf, 0,
3079 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3082 case FSF_ACCESS_DENIED:
3083 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3084 "remote port 0x%016Lx on adapter %s\n",
3085 unit->fcp_lun, unit->port->wwpn,
3086 zfcp_get_busid_by_unit(unit));
3087 for (counter = 0; counter < 2; counter++) {
3088 subtable = header->fsf_status_qual.halfword[counter * 2];
3089 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3091 case FSF_SQ_CFDC_SUBTABLE_OS:
3092 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3093 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3094 case FSF_SQ_CFDC_SUBTABLE_LUN:
3095 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3096 zfcp_act_subtable_type[subtable], rule);
3100 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3101 zfcp_erp_unit_access_denied(unit);
3102 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3103 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3104 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3107 case FSF_PORT_BOXED:
3108 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3109 "needs to be reopened\n",
3110 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3111 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3112 zfcp_erp_port_boxed(unit->port);
3113 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3114 ZFCP_STATUS_FSFREQ_RETRY;
3117 case FSF_LUN_SHARING_VIOLATION:
3118 if (header->fsf_status_qual.word[0] != 0) {
3119 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3121 "connected to the adapter %s "
3122 "is already in use in LPAR%d, CSS%d\n",
3125 zfcp_get_busid_by_unit(unit),
3126 queue_designator->hla,
3127 queue_designator->cssid);
3129 subtable = header->fsf_status_qual.halfword[4];
3130 rule = header->fsf_status_qual.halfword[5];
3132 case FSF_SQ_CFDC_SUBTABLE_OS:
3133 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3134 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3135 case FSF_SQ_CFDC_SUBTABLE_LUN:
3136 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3137 "remote port with WWPN 0x%Lx "
3138 "connected to the adapter %s "
3139 "is denied (%s rule %d)\n",
3142 zfcp_get_busid_by_unit(unit),
3143 zfcp_act_subtable_type[subtable],
3148 ZFCP_LOG_DEBUG("status qualifier:\n");
3149 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3150 (char *) &header->fsf_status_qual,
3151 sizeof (union fsf_status_qual));
3152 debug_text_event(adapter->erp_dbf, 2,
3154 zfcp_erp_unit_access_denied(unit);
3155 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3156 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3157 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3160 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3161 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3162 "There is no handle (temporary port identifier) "
3163 "available for unit 0x%016Lx on port 0x%016Lx "
3167 zfcp_get_busid_by_unit(unit));
3168 debug_text_event(adapter->erp_dbf, 1,
3170 zfcp_erp_unit_failed(unit);
3171 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3174 case FSF_ADAPTER_STATUS_AVAILABLE:
3175 switch (header->fsf_status_qual.word[0]) {
3176 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3177 /* Re-establish link to port */
3178 debug_text_event(adapter->erp_dbf, 1,
3180 zfcp_test_link(unit->port);
3181 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3183 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3184 /* ERP strategy will escalate */
3185 debug_text_event(adapter->erp_dbf, 1,
3187 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3191 ("bug: Wrong status qualifier 0x%x arrived.\n",
3192 header->fsf_status_qual.word[0]);
3193 debug_text_event(adapter->erp_dbf, 0,
3195 debug_exception(adapter->erp_dbf, 0,
3196 &header->fsf_status_qual.word[0],
3201 case FSF_INVALID_COMMAND_OPTION:
3203 "Invalid option 0x%x has been specified "
3204 "in QTCB bottom sent to the adapter %s\n",
3206 zfcp_get_busid_by_adapter(adapter));
3207 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3212 /* save LUN handle assigned by FSF */
3213 unit->handle = header->lun_handle;
3214 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3215 "adapter %s opened, port handle 0x%x\n",
3218 zfcp_get_busid_by_unit(unit),
3220 /* mark unit as open */
3221 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3223 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3224 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3225 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3226 exclusive = (bottom->lun_access_info &
3227 FSF_UNIT_ACCESS_EXCLUSIVE);
3228 readwrite = (bottom->lun_access_info &
3229 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3232 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3236 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3238 ZFCP_LOG_NORMAL("read-only access for unit "
3239 "(adapter %s, wwpn=0x%016Lx, "
3240 "fcp_lun=0x%016Lx)\n",
3241 zfcp_get_busid_by_unit(unit),
3246 if (exclusive && !readwrite) {
3247 ZFCP_LOG_NORMAL("exclusive access of read-only "
3248 "unit not supported\n");
3249 zfcp_erp_unit_failed(unit);
3250 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3251 zfcp_erp_unit_shutdown(unit, 0);
3252 } else if (!exclusive && readwrite) {
3253 ZFCP_LOG_NORMAL("shared access of read-write "
3254 "unit not supported\n");
3255 zfcp_erp_unit_failed(unit);
3256 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3257 zfcp_erp_unit_shutdown(unit, 0);
3265 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3266 "(debug info 0x%x)\n",
3267 header->fsf_status);
3268 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3269 debug_exception(adapter->erp_dbf, 0,
3270 &header->fsf_status, sizeof (u32));
3275 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3280 * function: zfcp_fsf_close_unit
3284 * returns: address of fsf_req - request successfully initiated
3287 * assumptions: This routine does not check whether the associated
3288 * remote port/lun has already been opened. This should be
3289 * done by calling routines. Otherwise some status
3290 * may be presented by FSF
3293 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3295 volatile struct qdio_buffer_element *sbale;
3296 unsigned long lock_flags;
3299 /* setup new FSF request */
3300 retval = zfcp_fsf_req_create(erp_action->adapter,
3302 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3303 erp_action->adapter->pool.fsf_req_erp,
3304 &lock_flags, &(erp_action->fsf_req));
3306 ZFCP_LOG_INFO("error: Could not create close unit request for "
3307 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3308 erp_action->unit->fcp_lun,
3309 erp_action->port->wwpn,
3310 zfcp_get_busid_by_adapter(erp_action->adapter));
3314 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3315 erp_action->fsf_req->sbal_curr, 0);
3316 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3317 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3319 erp_action->fsf_req->qtcb->header.port_handle =
3320 erp_action->port->handle;
3321 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3322 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3323 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3324 erp_action->fsf_req->erp_action = erp_action;
3326 /* start QDIO request for this FSF request */
3327 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3329 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3330 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3331 erp_action->unit->fcp_lun,
3332 erp_action->port->wwpn,
3333 zfcp_get_busid_by_adapter(erp_action->adapter));
3334 zfcp_fsf_req_free(erp_action->fsf_req);
3335 erp_action->fsf_req = NULL;
3339 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3340 "port 0x%016Lx, unit 0x%016Lx)\n",
3341 zfcp_get_busid_by_adapter(erp_action->adapter),
3342 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3344 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3350 * function: zfcp_fsf_close_unit_handler
3352 * purpose: is called for finished Close LUN FSF command
3357 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3359 int retval = -EINVAL;
3360 struct zfcp_unit *unit;
3362 unit = (struct zfcp_unit *) fsf_req->data;
3364 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3365 /* don't change unit status in our bookkeeping */
3366 goto skip_fsfstatus;
3369 /* evaluate FSF status in QTCB */
3370 switch (fsf_req->qtcb->header.fsf_status) {
3372 case FSF_PORT_HANDLE_NOT_VALID:
3373 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3374 "0x%016Lx on adapter %s invalid. This may "
3375 "happen in rare circumstances\n",
3378 zfcp_get_busid_by_unit(unit));
3379 ZFCP_LOG_DEBUG("status qualifier:\n");
3380 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3381 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3382 sizeof (union fsf_status_qual));
3383 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3385 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3386 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3389 case FSF_LUN_HANDLE_NOT_VALID:
3390 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3391 "0x%016Lx on port 0x%016Lx on adapter %s is "
3392 "invalid. This may happen occasionally.\n",
3396 zfcp_get_busid_by_unit(unit));
3397 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3398 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3399 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3400 sizeof (union fsf_status_qual));
3401 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3403 zfcp_erp_port_reopen(unit->port, 0);
3404 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3407 case FSF_PORT_BOXED:
3408 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3409 "needs to be reopened\n",
3411 zfcp_get_busid_by_unit(unit));
3412 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3413 zfcp_erp_port_boxed(unit->port);
3414 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3415 ZFCP_STATUS_FSFREQ_RETRY;
3418 case FSF_ADAPTER_STATUS_AVAILABLE:
3419 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3420 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3421 /* re-establish link to port */
3422 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3424 zfcp_test_link(unit->port);
3425 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3427 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3428 /* ERP strategy will escalate */
3429 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3431 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3435 ("bug: Wrong status qualifier 0x%x arrived.\n",
3436 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3437 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3440 fsf_req->adapter->erp_dbf, 0,
3441 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3448 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3449 "closed, port handle 0x%x\n",
3452 zfcp_get_busid_by_unit(unit),
3454 /* mark unit as closed */
3455 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3460 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3461 "(debug info 0x%x)\n",
3462 fsf_req->qtcb->header.fsf_status);
3463 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3464 debug_exception(fsf_req->adapter->erp_dbf, 0,
3465 &fsf_req->qtcb->header.fsf_status,
3471 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3476 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3477 * @adapter: adapter where scsi command is issued
3478 * @unit: unit where command is sent to
3479 * @scsi_cmnd: scsi command to be sent
3480 * @timer: timer to be started when request is initiated
3481 * @req_flags: flags for fsf_request
3484 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3485 struct zfcp_unit *unit,
3486 struct scsi_cmnd * scsi_cmnd,
3487 struct timer_list *timer, int req_flags)
3489 struct zfcp_fsf_req *fsf_req = NULL;
3490 struct fcp_cmnd_iu *fcp_cmnd_iu;
3491 unsigned int sbtype;
3492 unsigned long lock_flags;
3497 /* setup new FSF request */
3498 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3499 adapter->pool.fsf_req_scsi,
3500 &lock_flags, &fsf_req);
3501 if (unlikely(retval < 0)) {
3502 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3503 "for unit 0x%016Lx on port 0x%016Lx on "
3507 zfcp_get_busid_by_adapter(adapter));
3508 goto failed_req_create;
3511 zfcp_unit_get(unit);
3512 fsf_req->unit = unit;
3514 /* associate FSF request with SCSI request (for look up on abort) */
3515 scsi_cmnd->host_scribble = (char *) fsf_req;
3517 /* associate SCSI command with FSF request */
3518 fsf_req->data = (unsigned long) scsi_cmnd;
3520 /* set handles of unit and its parent port in QTCB */
3521 fsf_req->qtcb->header.lun_handle = unit->handle;
3522 fsf_req->qtcb->header.port_handle = unit->port->handle;
3524 /* FSF does not define the structure of the FCP_CMND IU */
3525 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3526 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3529 * set depending on data direction:
3530 * data direction bits in SBALE (SB Type)
3531 * data direction bits in QTCB
3532 * data direction bits in FCP_CMND IU
3534 switch (scsi_cmnd->sc_data_direction) {
3536 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3539 * what is the correct type for commands
3540 * without 'real' data buffers?
3542 sbtype = SBAL_FLAGS0_TYPE_READ;
3544 case DMA_FROM_DEVICE:
3545 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3546 sbtype = SBAL_FLAGS0_TYPE_READ;
3547 fcp_cmnd_iu->rddata = 1;
3550 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3551 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3552 fcp_cmnd_iu->wddata = 1;
3554 case DMA_BIDIRECTIONAL:
3557 * dummy, catch this condition earlier
3558 * in zfcp_scsi_queuecommand
3560 goto failed_scsi_cmnd;
3563 /* set FC service class in QTCB (3 per default) */
3564 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3566 /* set FCP_LUN in FCP_CMND IU in QTCB */
3567 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3569 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3571 /* set task attributes in FCP_CMND IU in QTCB */
3572 if (likely((scsi_cmnd->device->simple_tags) ||
3573 (atomic_test_mask(mask, &unit->status))))
3574 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3576 fcp_cmnd_iu->task_attribute = UNTAGGED;
3578 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3579 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3580 fcp_cmnd_iu->add_fcp_cdb_length
3581 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3582 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3583 "additional FCP_CDB length is 0x%x "
3584 "(shifted right 2 bits)\n",
3586 fcp_cmnd_iu->add_fcp_cdb_length);
3589 * copy SCSI CDB (including additional length, if any) to
3590 * FCP_CDB in FCP_CMND IU in QTCB
3592 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3594 /* FCP CMND IU length in QTCB */
3595 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3596 sizeof (struct fcp_cmnd_iu) +
3597 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3599 /* generate SBALEs from data buffer */
3600 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3601 if (unlikely(real_bytes < 0)) {
3602 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3604 "Data did not fit into available buffer(s), "
3605 "waiting for more...\n");
3608 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3609 "required. Shutting down unit "
3610 "(adapter %s, port 0x%016Lx, "
3612 zfcp_get_busid_by_unit(unit),
3615 zfcp_erp_unit_shutdown(unit, 0);
3621 /* set length of FCP data length in FCP_CMND IU in QTCB */
3622 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3624 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3625 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3626 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3629 * start QDIO request for this FSF request
3630 * covered by an SBALE)
3632 retval = zfcp_fsf_req_send(fsf_req, timer);
3633 if (unlikely(retval < 0)) {
3634 ZFCP_LOG_INFO("error: Could not send FCP command request "
3635 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3636 zfcp_get_busid_by_adapter(adapter),
3642 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3643 "port 0x%016Lx, unit 0x%016Lx)\n",
3644 zfcp_get_busid_by_adapter(adapter),
3652 zfcp_unit_put(unit);
3653 zfcp_fsf_req_free(fsf_req);
3655 scsi_cmnd->host_scribble = NULL;
3658 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3663 * function: zfcp_fsf_send_fcp_command_task_management
3669 * FIXME(design): should be watched by a timeout!!!
3670 * FIXME(design) shouldn't this be modified to return an int
3671 * also...don't know how though
3674 struct zfcp_fsf_req *
3675 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3676 struct zfcp_unit *unit,
3677 u8 tm_flags, int req_flags)
3679 struct zfcp_fsf_req *fsf_req = NULL;
3681 struct fcp_cmnd_iu *fcp_cmnd_iu;
3682 unsigned long lock_flags;
3683 volatile struct qdio_buffer_element *sbale;
3685 /* setup new FSF request */
3686 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3687 adapter->pool.fsf_req_scsi,
3688 &lock_flags, &fsf_req);
3690 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3691 "management) request for adapter %s, port "
3692 " 0x%016Lx, unit 0x%016Lx.\n",
3693 zfcp_get_busid_by_adapter(adapter),
3694 unit->port->wwpn, unit->fcp_lun);
3699 * Used to decide on proper handler in the return path,
3700 * could be either zfcp_fsf_send_fcp_command_task_handler or
3701 * zfcp_fsf_send_fcp_command_task_management_handler */
3703 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3706 * hold a pointer to the unit being target of this
3707 * task management request
3709 fsf_req->data = (unsigned long) unit;
3711 /* set FSF related fields in QTCB */
3712 fsf_req->qtcb->header.lun_handle = unit->handle;
3713 fsf_req->qtcb->header.port_handle = unit->port->handle;
3714 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3715 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3716 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3717 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3719 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3720 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3721 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3723 /* set FCP related fields in FCP_CMND IU in QTCB */
3724 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3725 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3726 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3727 fcp_cmnd_iu->task_management_flags = tm_flags;
3729 /* start QDIO request for this FSF request */
3730 zfcp_fsf_start_scsi_er_timer(adapter);
3731 retval = zfcp_fsf_req_send(fsf_req, NULL);
3733 del_timer(&adapter->scsi_er_timer);
3734 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3735 "management) on adapter %s, port 0x%016Lx for "
3736 "unit LUN 0x%016Lx\n",
3737 zfcp_get_busid_by_adapter(adapter),
3740 zfcp_fsf_req_free(fsf_req);
3745 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3746 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3748 zfcp_get_busid_by_adapter(adapter),
3753 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3758 * function: zfcp_fsf_send_fcp_command_handler
3760 * purpose: is called for finished Send FCP Command
3765 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3767 int retval = -EINVAL;
3768 struct zfcp_unit *unit;
3769 struct fsf_qtcb_header *header;
3770 u16 subtable, rule, counter;
3772 header = &fsf_req->qtcb->header;
3774 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3775 unit = (struct zfcp_unit *) fsf_req->data;
3777 unit = fsf_req->unit;
3779 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3780 /* go directly to calls of special handlers */
3781 goto skip_fsfstatus;
3784 /* evaluate FSF status in QTCB */
3785 switch (header->fsf_status) {
3787 case FSF_PORT_HANDLE_NOT_VALID:
3788 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3789 "0x%016Lx on adapter %s invalid\n",
3791 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3792 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3793 (char *) &header->fsf_status_qual,
3794 sizeof (union fsf_status_qual));
3795 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3797 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3798 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3801 case FSF_LUN_HANDLE_NOT_VALID:
3802 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3803 "0x%016Lx on port 0x%016Lx on adapter %s is "
3804 "invalid. This may happen occasionally.\n",
3808 zfcp_get_busid_by_unit(unit));
3809 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3810 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3811 (char *) &header->fsf_status_qual,
3812 sizeof (union fsf_status_qual));
3813 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3815 zfcp_erp_port_reopen(unit->port, 0);
3816 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3819 case FSF_HANDLE_MISMATCH:
3820 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3821 "unexpectedly. (adapter %s, port 0x%016Lx, "
3824 zfcp_get_busid_by_unit(unit),
3827 ZFCP_LOG_NORMAL("status qualifier:\n");
3828 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3829 (char *) &header->fsf_status_qual,
3830 sizeof (union fsf_status_qual));
3831 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3833 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3834 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3837 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3838 if (fsf_req->adapter->fc_service_class <= 3) {
3839 ZFCP_LOG_NORMAL("error: The adapter %s does "
3840 "not support fibrechannel class %d.\n",
3841 zfcp_get_busid_by_unit(unit),
3842 fsf_req->adapter->fc_service_class);
3844 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3845 "adapter %s is invalid. "
3846 "(debug info %d)\n",
3847 zfcp_get_busid_by_unit(unit),
3848 fsf_req->adapter->fc_service_class);
3850 /* stop operation for this adapter */
3851 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3852 "fsf_s_class_nsup");
3853 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3854 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3857 case FSF_FCPLUN_NOT_VALID:
3858 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3859 "adapter %s does not have correct unit "
3863 zfcp_get_busid_by_unit(unit),
3865 ZFCP_LOG_DEBUG("status qualifier:\n");
3866 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3867 (char *) &header->fsf_status_qual,
3868 sizeof (union fsf_status_qual));
3869 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3870 "fsf_s_fcp_lun_nv");
3871 zfcp_erp_port_reopen(unit->port, 0);
3872 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3875 case FSF_ACCESS_DENIED:
3876 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3877 "unit 0x%016Lx on port 0x%016Lx on "
3878 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3879 zfcp_get_busid_by_unit(unit));
3880 for (counter = 0; counter < 2; counter++) {
3881 subtable = header->fsf_status_qual.halfword[counter * 2];
3882 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3884 case FSF_SQ_CFDC_SUBTABLE_OS:
3885 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3886 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3887 case FSF_SQ_CFDC_SUBTABLE_LUN:
3888 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3889 zfcp_act_subtable_type[subtable], rule);
3893 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3894 zfcp_erp_unit_access_denied(unit);
3895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3898 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3899 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3900 "0x%016Lx on port 0x%016Lx on adapter %s "
3901 "(debug info %d)\n",
3904 zfcp_get_busid_by_unit(unit),
3905 fsf_req->qtcb->bottom.io.data_direction);
3906 /* stop operation for this adapter */
3907 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3908 "fsf_s_dir_ind_nv");
3909 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3910 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3913 case FSF_CMND_LENGTH_NOT_VALID:
3915 ("bug: An invalid control-data-block length field "
3916 "was found in a command for unit 0x%016Lx on port "
3917 "0x%016Lx on adapter %s " "(debug info %d)\n",
3918 unit->fcp_lun, unit->port->wwpn,
3919 zfcp_get_busid_by_unit(unit),
3920 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3921 /* stop operation for this adapter */
3922 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3923 "fsf_s_cmd_len_nv");
3924 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3925 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3928 case FSF_PORT_BOXED:
3929 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3930 "needs to be reopened\n",
3931 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3932 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3933 zfcp_erp_port_boxed(unit->port);
3934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3935 ZFCP_STATUS_FSFREQ_RETRY;
3939 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3940 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3941 zfcp_get_busid_by_unit(unit),
3942 unit->port->wwpn, unit->fcp_lun);
3943 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3944 zfcp_erp_unit_boxed(unit);
3945 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3946 | ZFCP_STATUS_FSFREQ_RETRY;
3949 case FSF_ADAPTER_STATUS_AVAILABLE:
3950 switch (header->fsf_status_qual.word[0]) {
3951 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3952 /* re-establish link to port */
3953 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3955 zfcp_test_link(unit->port);
3957 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3958 /* FIXME(hw) need proper specs for proper action */
3959 /* let scsi stack deal with retries and escalation */
3960 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3965 ("Unknown status qualifier 0x%x arrived.\n",
3966 header->fsf_status_qual.word[0]);
3967 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3969 debug_exception(fsf_req->adapter->erp_dbf, 0,
3970 &header->fsf_status_qual.word[0],
3974 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3980 case FSF_FCP_RSP_AVAILABLE:
3984 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3985 debug_exception(fsf_req->adapter->erp_dbf, 0,
3986 &header->fsf_status, sizeof(u32));
3991 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3993 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3995 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3996 fsf_req->unit = NULL;
3997 zfcp_unit_put(unit);
4003 * function: zfcp_fsf_send_fcp_command_task_handler
4005 * purpose: evaluates FCP_RSP IU
4010 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4013 struct scsi_cmnd *scpnt;
4014 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4015 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4016 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4017 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4019 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4020 unsigned long flags;
4021 struct zfcp_unit *unit = fsf_req->unit;
4023 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4024 scpnt = (struct scsi_cmnd *) fsf_req->data;
4025 if (unlikely(!scpnt)) {
4027 ("Command with fsf_req %p is not associated to "
4028 "a scsi command anymore. Aborted?\n", fsf_req);
4031 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4032 /* FIXME: (design) mid-layer should handle DID_ABORT like
4033 * DID_SOFT_ERROR by retrying the request for devices
4034 * that allow retries.
4036 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4037 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4038 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4039 goto skip_fsfstatus;
4042 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4043 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4044 set_host_byte(&scpnt->result, DID_ERROR);
4045 goto skip_fsfstatus;
4048 /* set message byte of result in SCSI command */
4049 scpnt->result |= COMMAND_COMPLETE << 8;
4052 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4053 * of result in SCSI command
4055 scpnt->result |= fcp_rsp_iu->scsi_status;
4056 if (unlikely(fcp_rsp_iu->scsi_status)) {
4058 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4059 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4060 scpnt->cmnd, scpnt->cmd_len);
4061 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4062 fcp_rsp_iu->scsi_status);
4063 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4064 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4065 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4066 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4067 fcp_rsp_iu->fcp_sns_len);
4070 /* check FCP_RSP_INFO */
4071 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4072 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4073 switch (fcp_rsp_info[3]) {
4076 ZFCP_LOG_TRACE("no failure or Task Management "
4077 "Function complete\n");
4078 set_host_byte(&scpnt->result, DID_OK);
4080 case RSP_CODE_LENGTH_MISMATCH:
4082 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4083 "that the fibrechannel protocol data "
4084 "length differs from the burst length. "
4085 "The problem occured on unit 0x%016Lx "
4086 "on port 0x%016Lx on adapter %s",
4089 zfcp_get_busid_by_unit(unit));
4090 /* dump SCSI CDB as prepared by zfcp */
4091 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4092 (char *) &fsf_req->qtcb->
4093 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4094 set_host_byte(&scpnt->result, DID_ERROR);
4095 goto skip_fsfstatus;
4096 case RSP_CODE_FIELD_INVALID:
4097 /* driver or hardware bug */
4098 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4099 "that the fibrechannel protocol data "
4100 "fields were incorrectly set up. "
4101 "The problem occured on the unit "
4102 "0x%016Lx on port 0x%016Lx on "
4106 zfcp_get_busid_by_unit(unit));
4107 /* dump SCSI CDB as prepared by zfcp */
4108 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4109 (char *) &fsf_req->qtcb->
4110 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4111 set_host_byte(&scpnt->result, DID_ERROR);
4112 goto skip_fsfstatus;
4113 case RSP_CODE_RO_MISMATCH:
4115 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4116 "that conflicting values for the "
4117 "fibrechannel payload offset from the "
4118 "header were found. "
4119 "The problem occured on unit 0x%016Lx "
4120 "on port 0x%016Lx on adapter %s.\n",
4123 zfcp_get_busid_by_unit(unit));
4124 /* dump SCSI CDB as prepared by zfcp */
4125 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4126 (char *) &fsf_req->qtcb->
4127 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4128 set_host_byte(&scpnt->result, DID_ERROR);
4129 goto skip_fsfstatus;
4131 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4132 "code was detected for a command. "
4133 "The problem occured on the unit "
4134 "0x%016Lx on port 0x%016Lx on "
4135 "adapter %s (debug info 0x%x)\n",
4138 zfcp_get_busid_by_unit(unit),
4140 /* dump SCSI CDB as prepared by zfcp */
4141 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4142 (char *) &fsf_req->qtcb->
4143 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4144 set_host_byte(&scpnt->result, DID_ERROR);
4145 goto skip_fsfstatus;
4149 /* check for sense data */
4150 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4151 sns_len = FSF_FCP_RSP_SIZE -
4152 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4153 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4155 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4156 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4157 SCSI_SENSE_BUFFERSIZE);
4158 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4159 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4161 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4162 (void *) &scpnt->cmnd, scpnt->cmd_len);
4164 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4165 fcp_rsp_iu->fcp_sns_len);
4166 memcpy(&scpnt->sense_buffer,
4167 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4168 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4169 (void *) &scpnt->sense_buffer, sns_len);
4172 /* check for overrun */
4173 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4174 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4175 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4176 "The response data length is "
4177 "%d, the original length was %d.\n",
4180 zfcp_get_busid_by_unit(unit),
4181 fcp_rsp_iu->fcp_resid,
4182 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4185 /* check for underrun */
4186 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4187 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4188 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4189 "The response data length is "
4190 "%d, the original length was %d.\n",
4193 zfcp_get_busid_by_unit(unit),
4194 fcp_rsp_iu->fcp_resid,
4195 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4197 scpnt->resid = fcp_rsp_iu->fcp_resid;
4198 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4199 set_host_byte(&scpnt->result, DID_ERROR);
4203 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4205 if (scpnt->result != 0)
4206 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt);
4207 else if (scpnt->retries > 0)
4208 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt);
4210 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt);
4212 /* cleanup pointer (need this especially for abort) */
4213 scpnt->host_scribble = NULL;
4215 /* always call back */
4216 (scpnt->scsi_done) (scpnt);
4219 * We must hold this lock until scsi_done has been called.
4220 * Otherwise we may call scsi_done after abort regarding this
4221 * command has completed.
4222 * Note: scsi_done must not block!
4225 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4230 * function: zfcp_fsf_send_fcp_command_task_management_handler
4232 * purpose: evaluates FCP_RSP IU
4237 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4240 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4241 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4242 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4243 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4245 del_timer(&fsf_req->adapter->scsi_er_timer);
4246 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4247 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4248 goto skip_fsfstatus;
4251 /* check FCP_RSP_INFO */
4252 switch (fcp_rsp_info[3]) {
4255 ZFCP_LOG_DEBUG("no failure or Task Management "
4256 "Function complete\n");
4258 case RSP_CODE_TASKMAN_UNSUPP:
4259 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4260 "is not supported on the target device "
4261 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4264 zfcp_get_busid_by_unit(unit));
4265 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4267 case RSP_CODE_TASKMAN_FAILED:
4268 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4269 "failed to complete successfully. "
4270 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4273 zfcp_get_busid_by_unit(unit));
4274 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4277 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4278 "code was detected for a command. "
4279 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4280 "(debug info 0x%x)\n",
4283 zfcp_get_busid_by_unit(unit),
4285 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4294 * function: zfcp_fsf_control_file
4296 * purpose: Initiator of the control file upload/download FSF requests
4298 * returns: 0 - FSF request is successfuly created and queued
4299 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4300 * -EINVAL - Invalid direction specified
4301 * -ENOMEM - Insufficient memory
4302 * -EPERM - Cannot create FSF request or place it in QDIO queue
4305 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4306 struct zfcp_fsf_req **fsf_req_ptr,
4309 struct zfcp_sg_list *sg_list)
4311 struct zfcp_fsf_req *fsf_req;
4312 struct fsf_qtcb_bottom_support *bottom;
4313 volatile struct qdio_buffer_element *sbale;
4314 struct timer_list *timer;
4315 unsigned long lock_flags;
4320 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4321 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4322 zfcp_get_busid_by_adapter(adapter));
4323 retval = -EOPNOTSUPP;
4327 switch (fsf_command) {
4329 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4330 direction = SBAL_FLAGS0_TYPE_WRITE;
4331 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4332 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4333 req_flags = ZFCP_WAIT_FOR_SBAL;
4336 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4337 direction = SBAL_FLAGS0_TYPE_READ;
4341 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4346 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4352 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4353 NULL, &lock_flags, &fsf_req);
4355 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4357 zfcp_get_busid_by_adapter(adapter));
4359 goto unlock_queue_lock;
4362 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4363 sbale[0].flags |= direction;
4365 bottom = &fsf_req->qtcb->bottom.support;
4366 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4367 bottom->option = option;
4369 if (sg_list->count > 0) {
4372 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4373 sg_list->sg, sg_list->count,
4374 ZFCP_MAX_SBALS_PER_REQ);
4375 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4377 "error: Could not create sufficient number of "
4378 "SBALS for an FSF request to the adapter %s\n",
4379 zfcp_get_busid_by_adapter(adapter));
4384 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4387 timer->function = zfcp_fsf_request_timeout_handler;
4388 timer->data = (unsigned long) adapter;
4389 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4391 retval = zfcp_fsf_req_send(fsf_req, timer);
4393 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4395 zfcp_get_busid_by_adapter(adapter));
4399 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4401 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4403 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4404 "download" : "upload",
4405 zfcp_get_busid_by_adapter(adapter));
4407 wait_event(fsf_req->completion_wq,
4408 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4410 *fsf_req_ptr = fsf_req;
4411 del_timer_sync(timer);
4415 zfcp_fsf_req_free(fsf_req);
4417 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4426 * function: zfcp_fsf_control_file_handler
4428 * purpose: Handler of the control file upload/download FSF requests
4430 * returns: 0 - FSF request successfuly processed
4431 * -EAGAIN - Operation has to be repeated because of a temporary problem
4432 * -EACCES - There is no permission to execute an operation
4433 * -EPERM - The control file is not in a right format
4434 * -EIO - There is a problem with the FCP adapter
4435 * -EINVAL - Invalid operation
4436 * -EFAULT - User space memory I/O operation fault
4439 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4441 struct zfcp_adapter *adapter = fsf_req->adapter;
4442 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4443 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4446 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4448 goto skip_fsfstatus;
4451 switch (header->fsf_status) {
4455 "The FSF request has been successfully completed "
4456 "on the adapter %s\n",
4457 zfcp_get_busid_by_adapter(adapter));
4460 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4461 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4462 switch (header->fsf_status_qual.word[0]) {
4464 case FSF_SQ_CFDC_HARDENED_ON_SE:
4466 "CFDC on the adapter %s has being "
4467 "hardened on primary and secondary SE\n",
4468 zfcp_get_busid_by_adapter(adapter));
4471 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4473 "CFDC of the adapter %s could not "
4474 "be saved on the SE\n",
4475 zfcp_get_busid_by_adapter(adapter));
4478 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4480 "CFDC of the adapter %s could not "
4481 "be copied to the secondary SE\n",
4482 zfcp_get_busid_by_adapter(adapter));
4487 "CFDC could not be hardened "
4488 "on the adapter %s\n",
4489 zfcp_get_busid_by_adapter(adapter));
4492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4496 case FSF_AUTHORIZATION_FAILURE:
4498 "Adapter %s does not accept privileged commands\n",
4499 zfcp_get_busid_by_adapter(adapter));
4500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4504 case FSF_CFDC_ERROR_DETECTED:
4506 "Error at position %d in the CFDC, "
4507 "CFDC is discarded by the adapter %s\n",
4508 header->fsf_status_qual.word[0],
4509 zfcp_get_busid_by_adapter(adapter));
4510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4514 case FSF_CONTROL_FILE_UPDATE_ERROR:
4516 "Adapter %s cannot harden the control file, "
4517 "file is discarded\n",
4518 zfcp_get_busid_by_adapter(adapter));
4519 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4523 case FSF_CONTROL_FILE_TOO_LARGE:
4525 "Control file is too large, file is discarded "
4526 "by the adapter %s\n",
4527 zfcp_get_busid_by_adapter(adapter));
4528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4532 case FSF_ACCESS_CONFLICT_DETECTED:
4533 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4535 "CFDC has been discarded by the adapter %s, "
4536 "because activation would impact "
4537 "%d active connection(s)\n",
4538 zfcp_get_busid_by_adapter(adapter),
4539 header->fsf_status_qual.word[0]);
4540 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4544 case FSF_CONFLICTS_OVERRULED:
4545 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4547 "CFDC has been activated on the adapter %s, "
4548 "but activation has impacted "
4549 "%d active connection(s)\n",
4550 zfcp_get_busid_by_adapter(adapter),
4551 header->fsf_status_qual.word[0]);
4552 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4556 case FSF_UNKNOWN_OP_SUBTYPE:
4557 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4558 "op_subtype=0x%x)\n",
4559 zfcp_get_busid_by_adapter(adapter),
4560 bottom->operation_subtype);
4561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4565 case FSF_INVALID_COMMAND_OPTION:
4567 "Invalid option 0x%x has been specified "
4568 "in QTCB bottom sent to the adapter %s\n",
4570 zfcp_get_busid_by_adapter(adapter));
4571 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4577 "bug: An unknown/unexpected FSF status 0x%08x "
4578 "was presented on the adapter %s\n",
4580 zfcp_get_busid_by_adapter(adapter));
4581 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4582 debug_exception(fsf_req->adapter->erp_dbf, 0,
4583 &header->fsf_status_qual.word[0], sizeof(u32));
4584 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4594 zfcp_fsf_req_sbal_check(unsigned long *flags,
4595 struct zfcp_qdio_queue *queue, int needed)
4597 write_lock_irqsave(&queue->queue_lock, *flags);
4598 if (likely(atomic_read(&queue->free_count) >= needed))
4600 write_unlock_irqrestore(&queue->queue_lock, *flags);
4605 * set qtcb pointer in fsf_req and initialize QTCB
4608 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4610 if (likely(fsf_req->qtcb != NULL)) {
4611 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4612 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4613 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4614 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4615 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4616 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4617 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4622 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4623 * @adapter: adapter for which request queue is examined
4624 * @req_flags: flags indicating whether to wait for needed SBAL or not
4625 * @lock_flags: lock_flags if queue_lock is taken
4626 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4627 * Locks: lock adapter->request_queue->queue_lock on success
4630 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4631 unsigned long *lock_flags)
4634 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4636 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4637 ret = wait_event_interruptible_timeout(adapter->request_wq,
4638 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4644 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4651 * function: zfcp_fsf_req_create
4653 * purpose: create an FSF request at the specified adapter and
4654 * setup common fields
4656 * returns: -ENOMEM if there was insufficient memory for a request
4657 * -EIO if no qdio buffers could be allocate to the request
4658 * -EINVAL/-EPERM on bug conditions in req_dequeue
4661 * note: The created request is returned by reference.
4663 * locks: lock of concerned request queue must not be held,
4664 * but is held on completion (write, irqsave)
4667 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4668 mempool_t *pool, unsigned long *lock_flags,
4669 struct zfcp_fsf_req **fsf_req_p)
4671 volatile struct qdio_buffer_element *sbale;
4672 struct zfcp_fsf_req *fsf_req = NULL;
4674 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4676 /* allocate new FSF request */
4677 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4678 if (unlikely(NULL == fsf_req)) {
4679 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4680 "the outbound (send) queue.\n");
4682 goto failed_fsf_req;
4685 fsf_req->adapter = adapter;
4686 fsf_req->fsf_command = fsf_cmd;
4688 zfcp_fsf_req_qtcb_init(fsf_req);
4690 /* initialize waitqueue which may be used to wait on
4691 this request completion */
4692 init_waitqueue_head(&fsf_req->completion_wq);
4694 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4700 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4701 * if it is not set (see also *_open_qdio and *_close_qdio).
4704 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4705 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4710 if (fsf_req->qtcb) {
4711 fsf_req->seq_no = adapter->fsf_req_seq_no;
4712 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4714 fsf_req->sbal_number = 1;
4715 fsf_req->sbal_first = req_queue->free_index;
4716 fsf_req->sbal_curr = req_queue->free_index;
4717 fsf_req->sbale_curr = 1;
4719 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4720 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4723 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4725 /* setup common SBALE fields */
4726 sbale[0].addr = fsf_req;
4727 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4728 if (likely(fsf_req->qtcb != NULL)) {
4729 sbale[1].addr = (void *) fsf_req->qtcb;
4730 sbale[1].length = sizeof(struct fsf_qtcb);
4733 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4734 fsf_req->sbal_number, fsf_req->sbal_first);
4739 /* dequeue new FSF request previously enqueued */
4740 zfcp_fsf_req_free(fsf_req);
4744 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4746 *fsf_req_p = fsf_req;
4751 * function: zfcp_fsf_req_send
4753 * purpose: start transfer of FSF request via QDIO
4755 * returns: 0 - request transfer succesfully started
4756 * !0 - start of request transfer failed
4759 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4761 struct zfcp_adapter *adapter;
4762 struct zfcp_qdio_queue *req_queue;
4763 volatile struct qdio_buffer_element *sbale;
4765 int new_distance_from_int;
4766 unsigned long flags;
4769 adapter = fsf_req->adapter;
4770 req_queue = &adapter->request_queue,
4773 /* FIXME(debug): remove it later */
4774 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4775 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4776 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4777 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4780 /* put allocated FSF request at list tail */
4781 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4782 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4783 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4785 inc_seq_no = (fsf_req->qtcb != NULL);
4787 /* figure out expiration time of timeout and start timeout */
4788 if (unlikely(timer)) {
4789 timer->expires += jiffies;
4793 ZFCP_LOG_TRACE("request queue of adapter %s: "
4794 "next free SBAL is %i, %i free SBALs\n",
4795 zfcp_get_busid_by_adapter(adapter),
4796 req_queue->free_index,
4797 atomic_read(&req_queue->free_count));
4799 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4800 "index_in_queue=%i, count=%i, buffers=%p\n",
4801 zfcp_get_busid_by_adapter(adapter),
4802 QDIO_FLAG_SYNC_OUTPUT,
4803 0, fsf_req->sbal_first, fsf_req->sbal_number,
4804 &req_queue->buffer[fsf_req->sbal_first]);
4807 * adjust the number of free SBALs in request queue as well as
4808 * position of first one
4810 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4811 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4812 req_queue->free_index += fsf_req->sbal_number; /* increase */
4813 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4814 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4816 fsf_req->issued = get_clock();
4818 retval = do_QDIO(adapter->ccw_device,
4819 QDIO_FLAG_SYNC_OUTPUT,
4820 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4822 if (unlikely(retval)) {
4823 /* Queues are down..... */
4826 * FIXME(potential race):
4827 * timer might be expired (absolutely unlikely)
4831 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4832 list_del(&fsf_req->list);
4833 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4835 * adjust the number of free SBALs in request queue as well as
4836 * position of first one
4838 zfcp_qdio_zero_sbals(req_queue->buffer,
4839 fsf_req->sbal_first, fsf_req->sbal_number);
4840 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4841 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4842 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4843 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4845 ("error: do_QDIO failed. Buffers could not be enqueued "
4846 "to request queue.\n");
4848 req_queue->distance_from_int = new_distance_from_int;
4850 * increase FSF sequence counter -
4851 * this must only be done for request successfully enqueued to
4852 * QDIO this rejected requests may be cleaned up by calling
4853 * routines resulting in missing sequence counter values
4857 /* Don't increase for unsolicited status */
4859 adapter->fsf_req_seq_no++;
4861 /* count FSF requests pending */
4862 atomic_inc(&adapter->fsf_reqs_active);
4867 #undef ZFCP_LOG_AREA