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 zfcp_erp_adapter_reopen(adapter, 0);
392 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
395 case FSF_PROT_REEST_QUEUE:
396 ZFCP_LOG_NORMAL("The local link to adapter with "
397 "%s was re-plugged. "
398 "Re-starting operations on this adapter.\n",
399 zfcp_get_busid_by_adapter(adapter));
400 /* All ports should be marked as ready to run again */
401 zfcp_erp_modify_adapter_status(adapter,
402 ZFCP_STATUS_COMMON_RUNNING,
404 zfcp_erp_adapter_reopen(adapter,
405 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
406 | ZFCP_STATUS_COMMON_ERP_FAILED);
407 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
410 case FSF_PROT_ERROR_STATE:
411 ZFCP_LOG_NORMAL("error: The adapter %s "
412 "has entered the error state. "
413 "Restarting all operations on this "
415 zfcp_get_busid_by_adapter(adapter));
416 zfcp_erp_adapter_reopen(adapter, 0);
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
418 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
422 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
423 "provided by the adapter %s "
424 "is not compatible with the device driver. "
425 "Stopping all operations on this adapter. "
426 "(debug info 0x%x).\n",
427 zfcp_get_busid_by_adapter(adapter),
428 qtcb->prefix.prot_status);
429 zfcp_erp_adapter_shutdown(adapter, 0);
430 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
435 * always call specific handlers to give them a chance to do
436 * something meaningful even in error cases
438 zfcp_fsf_fsfstatus_eval(fsf_req);
443 * function: zfcp_fsf_fsfstatus_eval
445 * purpose: evaluates FSF status of completed FSF request
446 * and acts accordingly
451 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
455 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
459 /* evaluate FSF Status */
460 switch (fsf_req->qtcb->header.fsf_status) {
461 case FSF_UNKNOWN_COMMAND:
462 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
463 "not known by the adapter %s "
464 "Stopping all operations on this adapter. "
465 "(debug info 0x%x).\n",
466 zfcp_get_busid_by_adapter(fsf_req->adapter),
467 fsf_req->qtcb->header.fsf_command);
468 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
472 case FSF_FCP_RSP_AVAILABLE:
473 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
477 case FSF_ADAPTER_STATUS_AVAILABLE:
478 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
484 * always call specific handlers to give them a chance to do
485 * something meaningful even in error cases
487 zfcp_fsf_req_dispatch(fsf_req);
493 * function: zfcp_fsf_fsfstatus_qual_eval
495 * purpose: evaluates FSF status-qualifier of completed FSF request
496 * and acts accordingly
501 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
505 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
506 case FSF_SQ_FCP_RSP_AVAILABLE:
508 case FSF_SQ_RETRY_IF_POSSIBLE:
509 /* The SCSI-stack may now issue retries or escalate */
510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
512 case FSF_SQ_COMMAND_ABORTED:
513 /* Carry the aborted state on to upper layer */
514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
517 case FSF_SQ_NO_RECOM:
518 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
519 "problem on the adapter %s "
520 "Stopping all operations on this adapter. ",
521 zfcp_get_busid_by_adapter(fsf_req->adapter));
522 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
525 case FSF_SQ_ULP_PROGRAMMING_ERROR:
526 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
528 zfcp_get_busid_by_adapter(fsf_req->adapter));
529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
531 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
532 case FSF_SQ_NO_RETRY_POSSIBLE:
533 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
534 /* dealt with in the respective functions */
537 ZFCP_LOG_NORMAL("bug: Additional status info could "
538 "not be interpreted properly.\n");
539 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
540 (char *) &fsf_req->qtcb->header.fsf_status_qual,
541 sizeof (union fsf_status_qual));
542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
550 * zfcp_fsf_link_down_info_eval - evaluate link down information block
553 zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
554 struct fsf_link_down_info *link_down)
556 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
560 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
562 if (link_down == NULL)
565 switch (link_down->error_code) {
566 case FSF_PSQ_LINK_NO_LIGHT:
567 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
568 "(no light detected)\n",
569 zfcp_get_busid_by_adapter(adapter));
571 case FSF_PSQ_LINK_WRAP_PLUG:
572 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
573 "(wrap plug detected)\n",
574 zfcp_get_busid_by_adapter(adapter));
576 case FSF_PSQ_LINK_NO_FCP:
577 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
578 "(adjacent node on link does not support FCP)\n",
579 zfcp_get_busid_by_adapter(adapter));
581 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
582 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
583 "(firmware update in progress)\n",
584 zfcp_get_busid_by_adapter(adapter));
586 case FSF_PSQ_LINK_INVALID_WWPN:
587 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
588 "(duplicate or invalid WWPN detected)\n",
589 zfcp_get_busid_by_adapter(adapter));
591 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
592 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
593 "(no support for NPIV by Fabric)\n",
594 zfcp_get_busid_by_adapter(adapter));
596 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
597 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
598 "(out of resource in FCP daughtercard)\n",
599 zfcp_get_busid_by_adapter(adapter));
601 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
602 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
603 "(out of resource in Fabric)\n",
604 zfcp_get_busid_by_adapter(adapter));
606 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
607 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
608 "(unable to Fabric login)\n",
609 zfcp_get_busid_by_adapter(adapter));
611 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
612 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
613 zfcp_get_busid_by_adapter(adapter));
615 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
616 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
617 zfcp_get_busid_by_adapter(adapter));
619 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
620 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
621 zfcp_get_busid_by_adapter(adapter));
624 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
625 "(warning: unknown reason code %d)\n",
626 zfcp_get_busid_by_adapter(adapter),
627 link_down->error_code);
630 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
631 ZFCP_LOG_DEBUG("Debug information to link down: "
632 "primary_status=0x%02x "
634 "action_code=0x%02x "
635 "reason_code=0x%02x "
636 "explanation_code=0x%02x "
637 "vendor_specific_code=0x%02x\n",
638 link_down->primary_status,
639 link_down->ioerr_code,
640 link_down->action_code,
641 link_down->reason_code,
642 link_down->explanation_code,
643 link_down->vendor_specific_code);
646 zfcp_erp_adapter_failed(adapter);
650 * function: zfcp_fsf_req_dispatch
652 * purpose: calls the appropriate command specific handler
657 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
659 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
660 struct zfcp_adapter *adapter = fsf_req->adapter;
664 switch (fsf_req->fsf_command) {
666 case FSF_QTCB_FCP_CMND:
667 zfcp_fsf_send_fcp_command_handler(fsf_req);
670 case FSF_QTCB_ABORT_FCP_CMND:
671 zfcp_fsf_abort_fcp_command_handler(fsf_req);
674 case FSF_QTCB_SEND_GENERIC:
675 zfcp_fsf_send_ct_handler(fsf_req);
678 case FSF_QTCB_OPEN_PORT_WITH_DID:
679 zfcp_fsf_open_port_handler(fsf_req);
682 case FSF_QTCB_OPEN_LUN:
683 zfcp_fsf_open_unit_handler(fsf_req);
686 case FSF_QTCB_CLOSE_LUN:
687 zfcp_fsf_close_unit_handler(fsf_req);
690 case FSF_QTCB_CLOSE_PORT:
691 zfcp_fsf_close_port_handler(fsf_req);
694 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
695 zfcp_fsf_close_physical_port_handler(fsf_req);
698 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
699 zfcp_fsf_exchange_config_data_handler(fsf_req);
702 case FSF_QTCB_EXCHANGE_PORT_DATA:
703 zfcp_fsf_exchange_port_data_handler(fsf_req);
706 case FSF_QTCB_SEND_ELS:
707 zfcp_fsf_send_els_handler(fsf_req);
710 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
711 zfcp_fsf_control_file_handler(fsf_req);
714 case FSF_QTCB_UPLOAD_CONTROL_FILE:
715 zfcp_fsf_control_file_handler(fsf_req);
719 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
720 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
721 "not supported by the adapter %s\n",
722 zfcp_get_busid_by_adapter(adapter));
723 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
725 ("bug: Command issued by the device driver differs "
726 "from the command returned by the adapter %s "
727 "(debug info 0x%x, 0x%x).\n",
728 zfcp_get_busid_by_adapter(adapter),
729 fsf_req->fsf_command,
730 fsf_req->qtcb->header.fsf_command);
736 zfcp_erp_async_handler(erp_action, 0);
742 * function: zfcp_fsf_status_read
744 * purpose: initiates a Status Read command at the specified adapter
749 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
751 struct zfcp_fsf_req *fsf_req;
752 struct fsf_status_read_buffer *status_buffer;
753 unsigned long lock_flags;
754 volatile struct qdio_buffer_element *sbale;
757 /* setup new FSF request */
758 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
759 req_flags | ZFCP_REQ_NO_QTCB,
760 adapter->pool.fsf_req_status_read,
761 &lock_flags, &fsf_req);
763 ZFCP_LOG_INFO("error: Could not create unsolicited status "
764 "buffer for adapter %s.\n",
765 zfcp_get_busid_by_adapter(adapter));
766 goto failed_req_create;
769 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
770 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
771 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
772 fsf_req->sbale_curr = 2;
775 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
776 if (!status_buffer) {
777 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
780 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
781 fsf_req->data = (unsigned long) status_buffer;
783 /* insert pointer to respective buffer */
784 sbale = zfcp_qdio_sbale_curr(fsf_req);
785 sbale->addr = (void *) status_buffer;
786 sbale->length = sizeof(struct fsf_status_read_buffer);
788 /* start QDIO request for this FSF request */
789 retval = zfcp_fsf_req_send(fsf_req, NULL);
791 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
793 goto failed_req_send;
796 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
797 zfcp_get_busid_by_adapter(adapter));
801 mempool_free(status_buffer, adapter->pool.data_status_read);
804 zfcp_fsf_req_free(fsf_req);
806 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
808 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
813 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
815 struct fsf_status_read_buffer *status_buffer;
816 struct zfcp_adapter *adapter;
817 struct zfcp_port *port;
820 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
821 adapter = fsf_req->adapter;
823 read_lock_irqsave(&zfcp_data.config_lock, flags);
824 list_for_each_entry(port, &adapter->port_list_head, list)
825 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
827 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
829 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
830 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
831 "nonexisting port with d_id 0x%08x on "
832 "adapter %s. Ignored.\n",
833 status_buffer->d_id & ZFCP_DID_MASK,
834 zfcp_get_busid_by_adapter(adapter));
838 switch (status_buffer->status_subtype) {
840 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
841 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
842 zfcp_erp_port_reopen(port, 0);
845 case FSF_STATUS_READ_SUB_ERROR_PORT:
846 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
847 zfcp_erp_port_shutdown(port, 0);
851 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
852 debug_exception(adapter->erp_dbf, 0,
853 &status_buffer->status_subtype, sizeof (u32));
854 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
855 "for a reopen indication on port with "
856 "d_id 0x%08x on the adapter %s. "
857 "Ignored. (debug info 0x%x)\n",
859 zfcp_get_busid_by_adapter(adapter),
860 status_buffer->status_subtype);
867 * function: zfcp_fsf_status_read_handler
869 * purpose: is called for finished Open Port command
874 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
877 struct zfcp_adapter *adapter = fsf_req->adapter;
878 struct fsf_status_read_buffer *status_buffer =
879 (struct fsf_status_read_buffer *) fsf_req->data;
881 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
882 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
883 mempool_free(status_buffer, adapter->pool.data_status_read);
884 zfcp_fsf_req_free(fsf_req);
888 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
890 switch (status_buffer->status_type) {
892 case FSF_STATUS_READ_PORT_CLOSED:
893 zfcp_fsf_status_read_port_closed(fsf_req);
896 case FSF_STATUS_READ_INCOMING_ELS:
897 zfcp_fsf_incoming_els(fsf_req);
900 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
901 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
902 zfcp_get_busid_by_adapter(adapter));
905 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
906 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
907 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
908 (char *) status_buffer,
909 sizeof (struct fsf_status_read_buffer));
912 case FSF_STATUS_READ_LINK_DOWN:
913 switch (status_buffer->status_subtype) {
914 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
915 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
916 zfcp_get_busid_by_adapter(adapter));
917 zfcp_fsf_link_down_info_eval(adapter,
918 (struct fsf_link_down_info *)
919 &status_buffer->payload);
921 case FSF_STATUS_READ_SUB_FDISC_FAILED:
922 ZFCP_LOG_INFO("Local link to adapter %s is down "
923 "due to failed FDISC login\n",
924 zfcp_get_busid_by_adapter(adapter));
925 zfcp_fsf_link_down_info_eval(adapter,
926 (struct fsf_link_down_info *)
927 &status_buffer->payload);
929 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
930 ZFCP_LOG_INFO("Local link to adapter %s is down "
931 "due to firmware update on adapter\n",
932 zfcp_get_busid_by_adapter(adapter));
933 zfcp_fsf_link_down_info_eval(adapter, NULL);
936 ZFCP_LOG_INFO("Local link to adapter %s is down "
937 "due to unknown reason\n",
938 zfcp_get_busid_by_adapter(adapter));
939 zfcp_fsf_link_down_info_eval(adapter, NULL);
943 case FSF_STATUS_READ_LINK_UP:
944 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
945 "Restarting operations on this adapter\n",
946 zfcp_get_busid_by_adapter(adapter));
947 /* All ports should be marked as ready to run again */
948 zfcp_erp_modify_adapter_status(adapter,
949 ZFCP_STATUS_COMMON_RUNNING,
951 zfcp_erp_adapter_reopen(adapter,
952 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
953 | ZFCP_STATUS_COMMON_ERP_FAILED);
956 case FSF_STATUS_READ_NOTIFICATION_LOST:
957 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
958 "adapter %s%s%s%s%s%s%s%s%s\n",
959 zfcp_get_busid_by_adapter(adapter),
960 (status_buffer->status_subtype &
961 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
962 ", incoming ELS" : "",
963 (status_buffer->status_subtype &
964 FSF_STATUS_READ_SUB_SENSE_DATA) ?
966 (status_buffer->status_subtype &
967 FSF_STATUS_READ_SUB_LINK_STATUS) ?
968 ", link status change" : "",
969 (status_buffer->status_subtype &
970 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
972 (status_buffer->status_subtype &
973 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
974 ", bit error exception" : "",
975 (status_buffer->status_subtype &
976 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
978 (status_buffer->status_subtype &
979 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
980 ", ACT hardening" : "",
981 (status_buffer->status_subtype &
982 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
983 ", adapter feature change" : "");
985 if (status_buffer->status_subtype &
986 FSF_STATUS_READ_SUB_ACT_UPDATED)
987 zfcp_erp_adapter_access_changed(adapter);
990 case FSF_STATUS_READ_CFDC_UPDATED:
991 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
992 zfcp_get_busid_by_adapter(adapter));
993 zfcp_erp_adapter_access_changed(adapter);
996 case FSF_STATUS_READ_CFDC_HARDENED:
997 switch (status_buffer->status_subtype) {
998 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
999 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1000 zfcp_get_busid_by_adapter(adapter));
1002 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1003 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1004 "to the secondary SE\n",
1005 zfcp_get_busid_by_adapter(adapter));
1008 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1009 zfcp_get_busid_by_adapter(adapter));
1013 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1014 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1015 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1016 "been changed from 0x%08X to 0x%08X\n",
1017 zfcp_get_busid_by_adapter(adapter),
1018 *(u32*) (status_buffer->payload + 4),
1019 *(u32*) (status_buffer->payload));
1020 adapter->adapter_features = *(u32*) status_buffer->payload;
1024 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1025 "type was received (debug info 0x%x)\n",
1026 status_buffer->status_type);
1027 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1029 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1030 (char *) status_buffer,
1031 sizeof (struct fsf_status_read_buffer));
1034 mempool_free(status_buffer, adapter->pool.data_status_read);
1035 zfcp_fsf_req_free(fsf_req);
1037 * recycle buffer and start new request repeat until outbound
1038 * queue is empty or adapter shutdown is requested
1042 * we may wait in the req_create for 5s during shutdown, so
1043 * qdio_cleanup will have to wait at least that long before returning
1044 * with failure to allow us a proper cleanup under all circumstances
1048 * allocation failure possible? (Is this code needed?)
1050 retval = zfcp_fsf_status_read(adapter, 0);
1052 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1053 "request for the adapter %s.\n",
1054 zfcp_get_busid_by_adapter(adapter));
1055 /* temporary fix to avoid status read buffer shortage */
1056 adapter->status_read_failed++;
1057 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1058 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1059 ZFCP_LOG_INFO("restart adapter %s due to status read "
1060 "buffer shortage\n",
1061 zfcp_get_busid_by_adapter(adapter));
1062 zfcp_erp_adapter_reopen(adapter, 0);
1070 * function: zfcp_fsf_abort_fcp_command
1072 * purpose: tells FSF to abort a running SCSI command
1074 * returns: address of initiated FSF request
1075 * NULL - request could not be initiated
1077 * FIXME(design): should be watched by a timeout !!!
1078 * FIXME(design) shouldn't this be modified to return an int
1079 * also...don't know how though
1081 struct zfcp_fsf_req *
1082 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1083 struct zfcp_adapter *adapter,
1084 struct zfcp_unit *unit, int req_flags)
1086 volatile struct qdio_buffer_element *sbale;
1087 unsigned long lock_flags;
1088 struct zfcp_fsf_req *fsf_req = NULL;
1091 /* setup new FSF request */
1092 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1093 req_flags, adapter->pool.fsf_req_abort,
1094 &lock_flags, &fsf_req);
1096 ZFCP_LOG_INFO("error: Failed to create an abort command "
1097 "request for lun 0x%016Lx on port 0x%016Lx "
1101 zfcp_get_busid_by_adapter(adapter));
1105 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1106 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1107 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1109 fsf_req->data = (unsigned long) unit;
1111 /* set handles of unit and its parent port in QTCB */
1112 fsf_req->qtcb->header.lun_handle = unit->handle;
1113 fsf_req->qtcb->header.port_handle = unit->port->handle;
1115 /* set handle of request which should be aborted */
1116 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1118 /* start QDIO request for this FSF request */
1120 zfcp_fsf_start_scsi_er_timer(adapter);
1121 retval = zfcp_fsf_req_send(fsf_req, NULL);
1123 del_timer(&adapter->scsi_er_timer);
1124 ZFCP_LOG_INFO("error: Failed to send abort command request "
1125 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1126 zfcp_get_busid_by_adapter(adapter),
1127 unit->port->wwpn, unit->fcp_lun);
1128 zfcp_fsf_req_free(fsf_req);
1133 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1134 "(adapter%s, port d_id=0x%08x, "
1135 "unit x%016Lx, old_req_id=0x%lx)\n",
1136 zfcp_get_busid_by_adapter(adapter),
1138 unit->fcp_lun, old_req_id);
1140 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1145 * function: zfcp_fsf_abort_fcp_command_handler
1147 * purpose: is called for finished Abort FCP Command request
1152 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1154 int retval = -EINVAL;
1155 struct zfcp_unit *unit;
1156 unsigned char status_qual =
1157 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1159 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1161 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1162 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1163 goto skip_fsfstatus;
1166 unit = (struct zfcp_unit *) new_fsf_req->data;
1168 /* evaluate FSF status in QTCB */
1169 switch (new_fsf_req->qtcb->header.fsf_status) {
1171 case FSF_PORT_HANDLE_NOT_VALID:
1172 if (status_qual >> 4 != status_qual % 0xf) {
1173 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1176 * In this case a command that was sent prior to a port
1177 * reopen was aborted (handles are different). This is
1181 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1182 "port 0x%016Lx on adapter %s invalid. "
1183 "This may happen occasionally.\n",
1186 zfcp_get_busid_by_unit(unit));
1187 ZFCP_LOG_INFO("status qualifier:\n");
1188 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1189 (char *) &new_fsf_req->qtcb->header.
1191 sizeof (union fsf_status_qual));
1192 /* Let's hope this sorts out the mess */
1193 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1195 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1196 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1200 case FSF_LUN_HANDLE_NOT_VALID:
1201 if (status_qual >> 4 != status_qual % 0xf) {
1203 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1206 * In this case a command that was sent prior to a unit
1207 * reopen was aborted (handles are different).
1212 ("Warning: Temporary LUN identifier 0x%x of LUN "
1213 "0x%016Lx on port 0x%016Lx on adapter %s is "
1214 "invalid. This may happen in rare cases. "
1215 "Trying to re-establish link.\n",
1219 zfcp_get_busid_by_unit(unit));
1220 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1221 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1222 (char *) &new_fsf_req->qtcb->header.
1224 sizeof (union fsf_status_qual));
1225 /* Let's hope this sorts out the mess */
1226 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1228 zfcp_erp_port_reopen(unit->port, 0);
1229 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1233 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1235 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1237 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1240 case FSF_PORT_BOXED:
1241 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1242 "be reopened\n", unit->port->wwpn,
1243 zfcp_get_busid_by_unit(unit));
1244 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1246 zfcp_erp_port_boxed(unit->port);
1247 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1248 | ZFCP_STATUS_FSFREQ_RETRY;
1253 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1255 unit->fcp_lun, unit->port->wwpn,
1256 zfcp_get_busid_by_unit(unit));
1257 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1258 zfcp_erp_unit_boxed(unit);
1259 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1260 | ZFCP_STATUS_FSFREQ_RETRY;
1263 case FSF_ADAPTER_STATUS_AVAILABLE:
1264 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1265 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1266 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1268 zfcp_test_link(unit->port);
1269 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1271 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1272 /* SCSI stack will escalate */
1273 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1275 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1279 ("bug: Wrong status qualifier 0x%x arrived.\n",
1280 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1281 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1283 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1284 &new_fsf_req->qtcb->header.
1285 fsf_status_qual.word[0], sizeof (u32));
1292 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1296 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1297 "(debug info 0x%x)\n",
1298 new_fsf_req->qtcb->header.fsf_status);
1299 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1301 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1302 &new_fsf_req->qtcb->header.fsf_status,
1311 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1313 * Two scatter-gather lists are passed, one for the reqeust and one for the
1317 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1318 struct scatterlist *resp, int resp_count)
1320 return ((req_count == 1) &&
1321 (resp_count == 1) &&
1322 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1324 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1325 req[0].length - 1) & PAGE_MASK)) &&
1326 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1328 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1329 resp[0].length - 1) & PAGE_MASK)));
1333 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1334 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1336 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1337 * a struct zfcp_fsf_req
1338 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1339 * is sent within error recovery
1342 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1343 struct zfcp_erp_action *erp_action)
1345 volatile struct qdio_buffer_element *sbale;
1346 struct zfcp_port *port;
1347 struct zfcp_adapter *adapter;
1348 struct zfcp_fsf_req *fsf_req;
1349 unsigned long lock_flags;
1354 adapter = port->adapter;
1356 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1357 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1358 pool, &lock_flags, &fsf_req);
1360 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1362 zfcp_get_busid_by_adapter(adapter));
1366 if (erp_action != NULL) {
1367 erp_action->fsf_req = fsf_req;
1368 fsf_req->erp_action = erp_action;
1371 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1372 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1373 ct->resp, ct->resp_count)){
1374 /* both request buffer and response buffer
1375 fit into one sbale each */
1376 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1377 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1378 sbale[2].length = ct->req[0].length;
1379 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1380 sbale[3].length = ct->resp[0].length;
1381 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1382 } else if (adapter->adapter_features &
1383 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1384 /* try to use chained SBALs */
1385 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1386 SBAL_FLAGS0_TYPE_WRITE_READ,
1387 ct->req, ct->req_count,
1388 ZFCP_MAX_SBALS_PER_CT_REQ);
1390 ZFCP_LOG_INFO("error: creation of CT request failed "
1392 zfcp_get_busid_by_adapter(adapter));
1400 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1401 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1402 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1403 SBAL_FLAGS0_TYPE_WRITE_READ,
1404 ct->resp, ct->resp_count,
1405 ZFCP_MAX_SBALS_PER_CT_REQ);
1407 ZFCP_LOG_INFO("error: creation of CT request failed "
1409 zfcp_get_busid_by_adapter(adapter));
1417 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1419 /* reject send generic request */
1421 "error: microcode does not support chained SBALs,"
1422 "CT request too big (adapter %s)\n",
1423 zfcp_get_busid_by_adapter(adapter));
1428 /* settings in QTCB */
1429 fsf_req->qtcb->header.port_handle = port->handle;
1430 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1431 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1432 fsf_req->data = (unsigned long) ct;
1434 zfcp_san_dbf_event_ct_request(fsf_req);
1436 /* start QDIO request for this FSF request */
1437 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1439 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1440 "(adapter %s, port 0x%016Lx)\n",
1441 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1445 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1446 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1450 zfcp_fsf_req_free(fsf_req);
1451 if (erp_action != NULL) {
1452 erp_action->fsf_req = NULL;
1456 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1462 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1463 * @fsf_req: pointer to struct zfcp_fsf_req
1465 * Data specific for the Generic Service request is passed using
1466 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1467 * Usually a specific handler for the CT request is called which is
1468 * found in this structure.
1471 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1473 struct zfcp_port *port;
1474 struct zfcp_adapter *adapter;
1475 struct zfcp_send_ct *send_ct;
1476 struct fsf_qtcb_header *header;
1477 struct fsf_qtcb_bottom_support *bottom;
1478 int retval = -EINVAL;
1479 u16 subtable, rule, counter;
1481 adapter = fsf_req->adapter;
1482 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1483 port = send_ct->port;
1484 header = &fsf_req->qtcb->header;
1485 bottom = &fsf_req->qtcb->bottom.support;
1487 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1488 goto skip_fsfstatus;
1490 /* evaluate FSF status in QTCB */
1491 switch (header->fsf_status) {
1494 zfcp_san_dbf_event_ct_response(fsf_req);
1498 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1499 if (adapter->fc_service_class <= 3) {
1500 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1502 zfcp_get_busid_by_port(port),
1503 adapter->fc_service_class);
1505 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1506 "adapter %s is invalid. "
1507 "(debug info %d)\n",
1508 zfcp_get_busid_by_port(port),
1509 adapter->fc_service_class);
1511 /* stop operation for this adapter */
1512 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1513 zfcp_erp_adapter_shutdown(adapter, 0);
1514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 case FSF_ADAPTER_STATUS_AVAILABLE:
1518 switch (header->fsf_status_qual.word[0]){
1519 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1520 /* reopening link to port */
1521 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1522 zfcp_test_link(port);
1523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1525 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1526 /* ERP strategy will escalate */
1527 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1531 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1533 header->fsf_status_qual.word[0]);
1538 case FSF_ACCESS_DENIED:
1539 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1540 "command (adapter %s, port d_id=0x%08x)\n",
1541 zfcp_get_busid_by_port(port), port->d_id);
1542 for (counter = 0; counter < 2; counter++) {
1543 subtable = header->fsf_status_qual.halfword[counter * 2];
1544 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1546 case FSF_SQ_CFDC_SUBTABLE_OS:
1547 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1548 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1549 case FSF_SQ_CFDC_SUBTABLE_LUN:
1550 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1551 zfcp_act_subtable_type[subtable], rule);
1555 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1556 zfcp_erp_port_access_denied(port);
1557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1560 case FSF_GENERIC_COMMAND_REJECTED:
1561 ZFCP_LOG_INFO("generic service command rejected "
1562 "(adapter %s, port d_id=0x%08x)\n",
1563 zfcp_get_busid_by_port(port), port->d_id);
1564 ZFCP_LOG_INFO("status qualifier:\n");
1565 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1566 (char *) &header->fsf_status_qual,
1567 sizeof (union fsf_status_qual));
1568 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1569 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1572 case FSF_PORT_HANDLE_NOT_VALID:
1573 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1574 "0x%016Lx on adapter %s invalid. This may "
1575 "happen occasionally.\n", port->handle,
1576 port->wwpn, zfcp_get_busid_by_port(port));
1577 ZFCP_LOG_INFO("status qualifier:\n");
1578 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1579 (char *) &header->fsf_status_qual,
1580 sizeof (union fsf_status_qual));
1581 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1582 zfcp_erp_adapter_reopen(adapter, 0);
1583 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1586 case FSF_PORT_BOXED:
1587 ZFCP_LOG_INFO("port needs to be reopened "
1588 "(adapter %s, port d_id=0x%08x)\n",
1589 zfcp_get_busid_by_port(port), port->d_id);
1590 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1591 zfcp_erp_port_boxed(port);
1592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1593 | ZFCP_STATUS_FSFREQ_RETRY;
1596 /* following states should never occure, all cases avoided
1597 in zfcp_fsf_send_ct - but who knows ... */
1598 case FSF_PAYLOAD_SIZE_MISMATCH:
1599 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1600 "req_buf_length=%d, resp_buf_length=%d)\n",
1601 zfcp_get_busid_by_adapter(adapter),
1602 bottom->req_buf_length, bottom->resp_buf_length);
1603 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1605 case FSF_REQUEST_SIZE_TOO_LARGE:
1606 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1607 "req_buf_length=%d)\n",
1608 zfcp_get_busid_by_adapter(adapter),
1609 bottom->req_buf_length);
1610 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1612 case FSF_RESPONSE_SIZE_TOO_LARGE:
1613 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1614 "resp_buf_length=%d)\n",
1615 zfcp_get_busid_by_adapter(adapter),
1616 bottom->resp_buf_length);
1617 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1619 case FSF_SBAL_MISMATCH:
1620 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1621 "resp_buf_length=%d)\n",
1622 zfcp_get_busid_by_adapter(adapter),
1623 bottom->req_buf_length, bottom->resp_buf_length);
1624 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1628 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1629 "(debug info 0x%x)\n", header->fsf_status);
1630 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1631 debug_exception(adapter->erp_dbf, 0,
1632 &header->fsf_status_qual.word[0], sizeof (u32));
1637 send_ct->status = retval;
1639 if (send_ct->handler != NULL)
1640 send_ct->handler(send_ct->handler_data);
1646 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1647 * @els: pointer to struct zfcp_send_els which contains all needed data for
1651 zfcp_fsf_send_els(struct zfcp_send_els *els)
1653 volatile struct qdio_buffer_element *sbale;
1654 struct zfcp_fsf_req *fsf_req;
1656 struct zfcp_adapter *adapter;
1657 unsigned long lock_flags;
1662 adapter = els->adapter;
1664 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1665 ZFCP_REQ_AUTO_CLEANUP,
1666 NULL, &lock_flags, &fsf_req);
1668 ZFCP_LOG_INFO("error: creation of ELS request failed "
1669 "(adapter %s, port d_id: 0x%08x)\n",
1670 zfcp_get_busid_by_adapter(adapter), d_id);
1674 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1675 if (zfcp_use_one_sbal(els->req, els->req_count,
1676 els->resp, els->resp_count)){
1677 /* both request buffer and response buffer
1678 fit into one sbale each */
1679 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1680 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1681 sbale[2].length = els->req[0].length;
1682 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1683 sbale[3].length = els->resp[0].length;
1684 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1685 } else if (adapter->adapter_features &
1686 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1687 /* try to use chained SBALs */
1688 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1689 SBAL_FLAGS0_TYPE_WRITE_READ,
1690 els->req, els->req_count,
1691 ZFCP_MAX_SBALS_PER_ELS_REQ);
1693 ZFCP_LOG_INFO("error: creation of ELS request failed "
1694 "(adapter %s, port d_id: 0x%08x)\n",
1695 zfcp_get_busid_by_adapter(adapter), d_id);
1703 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1704 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1705 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1706 SBAL_FLAGS0_TYPE_WRITE_READ,
1707 els->resp, els->resp_count,
1708 ZFCP_MAX_SBALS_PER_ELS_REQ);
1710 ZFCP_LOG_INFO("error: creation of ELS request failed "
1711 "(adapter %s, port d_id: 0x%08x)\n",
1712 zfcp_get_busid_by_adapter(adapter), d_id);
1720 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1722 /* reject request */
1723 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1724 ", ELS request too big (adapter %s, "
1725 "port d_id: 0x%08x)\n",
1726 zfcp_get_busid_by_adapter(adapter), d_id);
1731 /* settings in QTCB */
1732 fsf_req->qtcb->bottom.support.d_id = d_id;
1733 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1734 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1735 fsf_req->data = (unsigned long) els;
1737 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1739 zfcp_san_dbf_event_els_request(fsf_req);
1741 /* start QDIO request for this FSF request */
1742 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1744 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1745 "(adapter %s, port d_id: 0x%08x)\n",
1746 zfcp_get_busid_by_adapter(adapter), d_id);
1750 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1751 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1755 zfcp_fsf_req_free(fsf_req);
1759 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1766 * zfcp_fsf_send_els_handler - handler for ELS commands
1767 * @fsf_req: pointer to struct zfcp_fsf_req
1769 * Data specific for the ELS command is passed using
1770 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1771 * Usually a specific handler for the ELS command is called which is
1772 * found in this structure.
1774 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1776 struct zfcp_adapter *adapter;
1777 struct zfcp_port *port;
1779 struct fsf_qtcb_header *header;
1780 struct fsf_qtcb_bottom_support *bottom;
1781 struct zfcp_send_els *send_els;
1782 int retval = -EINVAL;
1783 u16 subtable, rule, counter;
1785 send_els = (struct zfcp_send_els *) fsf_req->data;
1786 adapter = send_els->adapter;
1787 port = send_els->port;
1788 d_id = send_els->d_id;
1789 header = &fsf_req->qtcb->header;
1790 bottom = &fsf_req->qtcb->bottom.support;
1792 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1793 goto skip_fsfstatus;
1795 switch (header->fsf_status) {
1798 zfcp_san_dbf_event_els_response(fsf_req);
1802 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1803 if (adapter->fc_service_class <= 3) {
1804 ZFCP_LOG_INFO("error: adapter %s does "
1805 "not support fibrechannel class %d.\n",
1806 zfcp_get_busid_by_adapter(adapter),
1807 adapter->fc_service_class);
1809 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1810 "adapter %s is invalid. "
1811 "(debug info %d)\n",
1812 zfcp_get_busid_by_adapter(adapter),
1813 adapter->fc_service_class);
1815 /* stop operation for this adapter */
1816 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1817 zfcp_erp_adapter_shutdown(adapter, 0);
1818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1821 case FSF_ADAPTER_STATUS_AVAILABLE:
1822 switch (header->fsf_status_qual.word[0]){
1823 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1824 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1825 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1826 zfcp_test_link(port);
1827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1830 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1833 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1834 (struct zfcp_ls_rjt_par *)
1835 &header->fsf_status_qual.word[2]);
1837 case FSF_SQ_RETRY_IF_POSSIBLE:
1838 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1842 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1843 header->fsf_status_qual.word[0]);
1844 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1845 (char*)header->fsf_status_qual.word, 16);
1849 case FSF_ELS_COMMAND_REJECTED:
1850 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1851 "prohibited sending "
1852 "(adapter: %s, port d_id: 0x%08x)\n",
1853 zfcp_get_busid_by_adapter(adapter), d_id);
1857 case FSF_PAYLOAD_SIZE_MISMATCH:
1859 "ELS request size and ELS response size must be either "
1860 "both 0, or both greater than 0 "
1861 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1862 zfcp_get_busid_by_adapter(adapter),
1863 bottom->req_buf_length,
1864 bottom->resp_buf_length);
1867 case FSF_REQUEST_SIZE_TOO_LARGE:
1869 "Length of the ELS request buffer, "
1870 "specified in QTCB bottom, "
1871 "exceeds the size of the buffers "
1872 "that have been allocated for ELS request data "
1873 "(adapter: %s, req_buf_length=%d)\n",
1874 zfcp_get_busid_by_adapter(adapter),
1875 bottom->req_buf_length);
1878 case FSF_RESPONSE_SIZE_TOO_LARGE:
1880 "Length of the ELS response buffer, "
1881 "specified in QTCB bottom, "
1882 "exceeds the size of the buffers "
1883 "that have been allocated for ELS response data "
1884 "(adapter: %s, resp_buf_length=%d)\n",
1885 zfcp_get_busid_by_adapter(adapter),
1886 bottom->resp_buf_length);
1889 case FSF_SBAL_MISMATCH:
1890 /* should never occure, avoided in zfcp_fsf_send_els */
1891 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1892 "resp_buf_length=%d)\n",
1893 zfcp_get_busid_by_adapter(adapter),
1894 bottom->req_buf_length, bottom->resp_buf_length);
1895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1898 case FSF_ACCESS_DENIED:
1899 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1900 "(adapter %s, port d_id=0x%08x)\n",
1901 zfcp_get_busid_by_adapter(adapter), d_id);
1902 for (counter = 0; counter < 2; counter++) {
1903 subtable = header->fsf_status_qual.halfword[counter * 2];
1904 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1906 case FSF_SQ_CFDC_SUBTABLE_OS:
1907 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1908 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1909 case FSF_SQ_CFDC_SUBTABLE_LUN:
1910 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1911 zfcp_act_subtable_type[subtable], rule);
1915 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1917 zfcp_erp_port_access_denied(port);
1918 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1923 "bug: An unknown FSF Status was presented "
1924 "(adapter: %s, fsf_status=0x%08x)\n",
1925 zfcp_get_busid_by_adapter(adapter),
1926 header->fsf_status);
1927 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1928 debug_exception(adapter->erp_dbf, 0,
1929 &header->fsf_status_qual.word[0], sizeof(u32));
1930 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1935 send_els->status = retval;
1937 if (send_els->handler != 0)
1938 send_els->handler(send_els->handler_data);
1948 * returns: address of initiated FSF request
1949 * NULL - request could not be initiated
1952 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1954 volatile struct qdio_buffer_element *sbale;
1955 unsigned long lock_flags;
1958 /* setup new FSF request */
1959 retval = zfcp_fsf_req_create(erp_action->adapter,
1960 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1961 ZFCP_REQ_AUTO_CLEANUP,
1962 erp_action->adapter->pool.fsf_req_erp,
1963 &lock_flags, &(erp_action->fsf_req));
1965 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1966 "data request for adapter %s.\n",
1967 zfcp_get_busid_by_adapter(erp_action->adapter));
1971 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1972 erp_action->fsf_req->sbal_curr, 0);
1973 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1974 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1976 erp_action->fsf_req->erp_action = erp_action;
1977 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1979 FSF_FEATURE_LUN_SHARING |
1980 FSF_FEATURE_NOTIFICATION_LOST |
1981 FSF_FEATURE_UPDATE_ALERT;
1983 /* start QDIO request for this FSF request */
1984 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1987 ("error: Could not send exchange configuration data "
1988 "command on the adapter %s\n",
1989 zfcp_get_busid_by_adapter(erp_action->adapter));
1990 zfcp_fsf_req_free(erp_action->fsf_req);
1991 erp_action->fsf_req = NULL;
1995 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1997 zfcp_get_busid_by_adapter(erp_action->adapter));
2000 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2006 * zfcp_fsf_exchange_config_evaluate
2007 * @fsf_req: fsf_req which belongs to xchg config data request
2008 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2010 * returns: -EIO on error, 0 otherwise
2013 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2015 struct fsf_qtcb_bottom_config *bottom;
2016 struct zfcp_adapter *adapter = fsf_req->adapter;
2017 struct Scsi_Host *shost = adapter->scsi_host;
2019 bottom = &fsf_req->qtcb->bottom.config;
2020 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2021 bottom->low_qtcb_version, bottom->high_qtcb_version);
2022 adapter->fsf_lic_version = bottom->lic_version;
2023 adapter->adapter_features = bottom->adapter_features;
2024 adapter->connection_features = bottom->connection_features;
2025 adapter->peer_wwpn = 0;
2026 adapter->peer_wwnn = 0;
2027 adapter->peer_d_id = 0;
2030 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2031 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2032 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2033 fc_host_speed(shost) = bottom->fc_link_speed;
2034 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2035 adapter->hydra_version = bottom->adapter_type;
2036 if (fc_host_permanent_port_name(shost) == -1)
2037 fc_host_permanent_port_name(shost) =
2038 fc_host_port_name(shost);
2039 if (bottom->fc_topology == FSF_TOPO_P2P) {
2040 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2041 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2042 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2043 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2044 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2045 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2046 else if (bottom->fc_topology == FSF_TOPO_AL)
2047 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2049 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2051 fc_host_node_name(shost) = 0;
2052 fc_host_port_name(shost) = 0;
2053 fc_host_port_id(shost) = 0;
2054 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2055 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2056 adapter->hydra_version = 0;
2059 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2060 adapter->hardware_version = bottom->hardware_version;
2061 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2062 min(FC_SERIAL_NUMBER_SIZE, 17));
2063 EBCASC(fc_host_serial_number(shost),
2064 min(FC_SERIAL_NUMBER_SIZE, 17));
2067 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2071 "adapter version 0x%x, "
2072 "LIC version 0x%x, "
2073 "FC link speed %d Gb/s\n",
2074 zfcp_get_busid_by_adapter(adapter),
2075 (wwn_t) fc_host_node_name(shost),
2076 (wwn_t) fc_host_port_name(shost),
2077 fc_host_port_id(shost),
2078 adapter->hydra_version,
2079 adapter->fsf_lic_version,
2080 fc_host_speed(shost));
2081 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2082 ZFCP_LOG_NORMAL("error: the adapter %s "
2083 "only supports newer control block "
2084 "versions in comparison to this device "
2085 "driver (try updated device driver)\n",
2086 zfcp_get_busid_by_adapter(adapter));
2087 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2088 zfcp_erp_adapter_shutdown(adapter, 0);
2091 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2092 ZFCP_LOG_NORMAL("error: the adapter %s "
2093 "only supports older control block "
2094 "versions than this device driver uses"
2095 "(consider a microcode upgrade)\n",
2096 zfcp_get_busid_by_adapter(adapter));
2097 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2098 zfcp_erp_adapter_shutdown(adapter, 0);
2105 * function: zfcp_fsf_exchange_config_data_handler
2107 * purpose: is called for finished Exchange Configuration Data command
2112 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2114 struct fsf_qtcb_bottom_config *bottom;
2115 struct zfcp_adapter *adapter = fsf_req->adapter;
2116 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2118 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2121 switch (qtcb->header.fsf_status) {
2124 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2127 switch (fc_host_port_type(adapter->scsi_host)) {
2128 case FC_PORTTYPE_PTP:
2129 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2130 "configuration detected at adapter %s\n"
2131 "Peer WWNN 0x%016llx, "
2132 "peer WWPN 0x%016llx, "
2133 "peer d_id 0x%06x\n",
2134 zfcp_get_busid_by_adapter(adapter),
2137 adapter->peer_d_id);
2138 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2141 case FC_PORTTYPE_NLPORT:
2142 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2143 "topology detected at adapter %s "
2144 "unsupported, shutting down adapter\n",
2145 zfcp_get_busid_by_adapter(adapter));
2146 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2148 zfcp_erp_adapter_shutdown(adapter, 0);
2150 case FC_PORTTYPE_NPORT:
2151 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2152 "network detected at adapter %s.\n",
2153 zfcp_get_busid_by_adapter(adapter));
2156 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2157 "reported by the exchange "
2158 "configuration command for "
2159 "the adapter %s is not "
2160 "of a type known to the zfcp "
2161 "driver, shutting down adapter\n",
2162 zfcp_get_busid_by_adapter(adapter));
2163 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2165 zfcp_erp_adapter_shutdown(adapter, 0);
2168 bottom = &qtcb->bottom.config;
2169 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2170 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2171 "allowed by the adapter %s "
2172 "is lower than the minimum "
2173 "required by the driver (%ld bytes).\n",
2174 bottom->max_qtcb_size,
2175 zfcp_get_busid_by_adapter(adapter),
2176 sizeof(struct fsf_qtcb));
2177 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2179 debug_event(fsf_req->adapter->erp_dbf, 0,
2180 &bottom->max_qtcb_size, sizeof (u32));
2181 zfcp_erp_adapter_shutdown(adapter, 0);
2184 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2187 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2188 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2190 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2193 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2195 zfcp_fsf_link_down_info_eval(adapter,
2196 &qtcb->header.fsf_status_qual.link_down_info);
2199 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2200 debug_event(fsf_req->adapter->erp_dbf, 0,
2201 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2202 zfcp_erp_adapter_shutdown(adapter, 0);
2209 * zfcp_fsf_exchange_port_data - request information about local port
2210 * @erp_action: ERP action for the adapter for which port data is requested
2211 * @adapter: for which port data is requested
2212 * @data: response to exchange port data request
2215 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2216 struct zfcp_adapter *adapter,
2217 struct fsf_qtcb_bottom_port *data)
2219 volatile struct qdio_buffer_element *sbale;
2221 unsigned long lock_flags;
2222 struct zfcp_fsf_req *fsf_req;
2223 struct timer_list *timer;
2225 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2226 ZFCP_LOG_INFO("error: exchange port data "
2227 "command not supported by adapter %s\n",
2228 zfcp_get_busid_by_adapter(adapter));
2232 /* setup new FSF request */
2233 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2234 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2235 0, &lock_flags, &fsf_req);
2237 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2238 "exchange port data request for"
2239 "the adapter %s.\n",
2240 zfcp_get_busid_by_adapter(adapter));
2241 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2247 fsf_req->data = (unsigned long) data;
2249 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2250 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2251 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2254 erp_action->fsf_req = fsf_req;
2255 fsf_req->erp_action = erp_action;
2256 timer = &erp_action->timer;
2258 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2260 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2262 zfcp_fsf_req_free(fsf_req);
2266 timer->function = zfcp_fsf_request_timeout_handler;
2267 timer->data = (unsigned long) adapter;
2268 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2271 retval = zfcp_fsf_req_send(fsf_req, timer);
2273 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2274 "command on the adapter %s\n",
2275 zfcp_get_busid_by_adapter(adapter));
2276 zfcp_fsf_req_free(fsf_req);
2278 erp_action->fsf_req = NULL;
2281 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2286 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2289 wait_event(fsf_req->completion_wq,
2290 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2291 del_timer_sync(timer);
2292 zfcp_fsf_req_free(fsf_req);
2299 * zfcp_fsf_exchange_port_evaluate
2300 * @fsf_req: fsf_req which belongs to xchg port data request
2301 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2304 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2306 struct zfcp_adapter *adapter;
2307 struct fsf_qtcb *qtcb;
2308 struct fsf_qtcb_bottom_port *bottom, *data;
2309 struct Scsi_Host *shost;
2311 adapter = fsf_req->adapter;
2312 qtcb = fsf_req->qtcb;
2313 bottom = &qtcb->bottom.port;
2314 shost = adapter->scsi_host;
2316 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2318 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2320 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2321 fc_host_permanent_port_name(shost) = bottom->wwpn;
2323 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2324 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2325 fc_host_supported_speeds(shost) = bottom->supported_speed;
2329 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2330 * @fsf_req: pointer to struct zfcp_fsf_req
2333 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2335 struct zfcp_adapter *adapter;
2336 struct fsf_qtcb *qtcb;
2338 adapter = fsf_req->adapter;
2339 qtcb = fsf_req->qtcb;
2341 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2344 switch (qtcb->header.fsf_status) {
2346 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2347 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2349 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2350 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2351 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2352 zfcp_fsf_link_down_info_eval(adapter,
2353 &qtcb->header.fsf_status_qual.link_down_info);
2356 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2357 debug_event(adapter->erp_dbf, 0,
2358 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2364 * function: zfcp_fsf_open_port
2368 * returns: address of initiated FSF request
2369 * NULL - request could not be initiated
2372 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2374 volatile struct qdio_buffer_element *sbale;
2375 unsigned long lock_flags;
2378 /* setup new FSF request */
2379 retval = zfcp_fsf_req_create(erp_action->adapter,
2380 FSF_QTCB_OPEN_PORT_WITH_DID,
2381 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2382 erp_action->adapter->pool.fsf_req_erp,
2383 &lock_flags, &(erp_action->fsf_req));
2385 ZFCP_LOG_INFO("error: Could not create open port request "
2386 "for port 0x%016Lx on adapter %s.\n",
2387 erp_action->port->wwpn,
2388 zfcp_get_busid_by_adapter(erp_action->adapter));
2392 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2393 erp_action->fsf_req->sbal_curr, 0);
2394 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2395 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2397 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2398 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2399 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2400 erp_action->fsf_req->erp_action = erp_action;
2402 /* start QDIO request for this FSF request */
2403 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2405 ZFCP_LOG_INFO("error: Could not send open port request for "
2406 "port 0x%016Lx on adapter %s.\n",
2407 erp_action->port->wwpn,
2408 zfcp_get_busid_by_adapter(erp_action->adapter));
2409 zfcp_fsf_req_free(erp_action->fsf_req);
2410 erp_action->fsf_req = NULL;
2414 ZFCP_LOG_DEBUG("open port request initiated "
2415 "(adapter %s, port 0x%016Lx)\n",
2416 zfcp_get_busid_by_adapter(erp_action->adapter),
2417 erp_action->port->wwpn);
2419 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2425 * function: zfcp_fsf_open_port_handler
2427 * purpose: is called for finished Open Port command
2432 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2434 int retval = -EINVAL;
2435 struct zfcp_port *port;
2436 struct fsf_plogi *plogi;
2437 struct fsf_qtcb_header *header;
2438 u16 subtable, rule, counter;
2440 port = (struct zfcp_port *) fsf_req->data;
2441 header = &fsf_req->qtcb->header;
2443 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2444 /* don't change port status in our bookkeeping */
2445 goto skip_fsfstatus;
2448 /* evaluate FSF status in QTCB */
2449 switch (header->fsf_status) {
2451 case FSF_PORT_ALREADY_OPEN:
2452 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2453 "is already open.\n",
2454 port->wwpn, zfcp_get_busid_by_port(port));
2455 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2458 * This is a bug, however operation should continue normally
2459 * if it is simply ignored
2463 case FSF_ACCESS_DENIED:
2464 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2466 port->wwpn, zfcp_get_busid_by_port(port));
2467 for (counter = 0; counter < 2; counter++) {
2468 subtable = header->fsf_status_qual.halfword[counter * 2];
2469 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2471 case FSF_SQ_CFDC_SUBTABLE_OS:
2472 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2473 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2474 case FSF_SQ_CFDC_SUBTABLE_LUN:
2475 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2476 zfcp_act_subtable_type[subtable], rule);
2480 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2481 zfcp_erp_port_access_denied(port);
2482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2485 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2486 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2487 "The remote port 0x%016Lx on adapter %s "
2488 "could not be opened. Disabling it.\n",
2489 port->wwpn, zfcp_get_busid_by_port(port));
2490 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2492 zfcp_erp_port_failed(port);
2493 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2496 case FSF_ADAPTER_STATUS_AVAILABLE:
2497 switch (header->fsf_status_qual.word[0]) {
2498 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2499 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2501 /* ERP strategy will escalate */
2502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2504 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2505 /* ERP strategy will escalate */
2506 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2510 case FSF_SQ_NO_RETRY_POSSIBLE:
2511 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2512 "adapter %s could not be opened. "
2515 zfcp_get_busid_by_port(port));
2516 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2518 zfcp_erp_port_failed(port);
2519 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2523 ("bug: Wrong status qualifier 0x%x arrived.\n",
2524 header->fsf_status_qual.word[0]);
2525 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2528 fsf_req->adapter->erp_dbf, 0,
2529 &header->fsf_status_qual.word[0],
2536 /* save port handle assigned by FSF */
2537 port->handle = header->port_handle;
2538 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2539 "was opened, it's port handle is 0x%x\n",
2540 port->wwpn, zfcp_get_busid_by_port(port),
2542 /* mark port as open */
2543 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2544 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2545 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2546 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2549 /* check whether D_ID has changed during open */
2551 * FIXME: This check is not airtight, as the FCP channel does
2552 * not monitor closures of target port connections caused on
2553 * the remote side. Thus, they might miss out on invalidating
2554 * locally cached WWPNs (and other N_Port parameters) of gone
2555 * target ports. So, our heroic attempt to make things safe
2556 * could be undermined by 'open port' response data tagged with
2557 * obsolete WWPNs. Another reason to monitor potential
2558 * connection closures ourself at least (by interpreting
2559 * incoming ELS' and unsolicited status). It just crosses my
2560 * mind that one should be able to cross-check by means of
2561 * another GID_PN straight after a port has been opened.
2562 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2564 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2565 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2567 if (fsf_req->qtcb->bottom.support.els1_length <
2568 ((((unsigned long) &plogi->serv_param.wwpn) -
2569 ((unsigned long) plogi)) + sizeof (u64))) {
2571 "warning: insufficient length of "
2572 "PLOGI payload (%i)\n",
2573 fsf_req->qtcb->bottom.support.els1_length);
2574 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2575 "fsf_s_short_plogi:");
2576 /* skip sanity check and assume wwpn is ok */
2578 if (plogi->serv_param.wwpn != port->wwpn) {
2579 ZFCP_LOG_INFO("warning: d_id of port "
2580 "0x%016Lx changed during "
2581 "open\n", port->wwpn);
2583 fsf_req->adapter->erp_dbf, 0,
2584 "fsf_s_did_change:");
2586 ZFCP_STATUS_PORT_DID_DID,
2589 port->wwnn = plogi->serv_param.wwnn;
2594 case FSF_UNKNOWN_OP_SUBTYPE:
2595 /* should never occure, subtype not set in zfcp_fsf_open_port */
2596 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2597 "op_subtype=0x%x)\n",
2598 zfcp_get_busid_by_port(port),
2599 fsf_req->qtcb->bottom.support.operation_subtype);
2600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2604 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2605 "(debug info 0x%x)\n",
2606 header->fsf_status);
2607 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2608 debug_exception(fsf_req->adapter->erp_dbf, 0,
2609 &header->fsf_status, sizeof (u32));
2614 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2619 * function: zfcp_fsf_close_port
2621 * purpose: submit FSF command "close port"
2623 * returns: address of initiated FSF request
2624 * NULL - request could not be initiated
2627 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2629 volatile struct qdio_buffer_element *sbale;
2630 unsigned long lock_flags;
2633 /* setup new FSF request */
2634 retval = zfcp_fsf_req_create(erp_action->adapter,
2635 FSF_QTCB_CLOSE_PORT,
2636 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2637 erp_action->adapter->pool.fsf_req_erp,
2638 &lock_flags, &(erp_action->fsf_req));
2640 ZFCP_LOG_INFO("error: Could not create a close port request "
2641 "for port 0x%016Lx on adapter %s.\n",
2642 erp_action->port->wwpn,
2643 zfcp_get_busid_by_adapter(erp_action->adapter));
2647 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2648 erp_action->fsf_req->sbal_curr, 0);
2649 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2650 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2652 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2653 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2654 erp_action->fsf_req->erp_action = erp_action;
2655 erp_action->fsf_req->qtcb->header.port_handle =
2656 erp_action->port->handle;
2658 /* start QDIO request for this FSF request */
2659 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2661 ZFCP_LOG_INFO("error: Could not send a close port request for "
2662 "port 0x%016Lx on adapter %s.\n",
2663 erp_action->port->wwpn,
2664 zfcp_get_busid_by_adapter(erp_action->adapter));
2665 zfcp_fsf_req_free(erp_action->fsf_req);
2666 erp_action->fsf_req = NULL;
2670 ZFCP_LOG_TRACE("close port request initiated "
2671 "(adapter %s, port 0x%016Lx)\n",
2672 zfcp_get_busid_by_adapter(erp_action->adapter),
2673 erp_action->port->wwpn);
2675 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2681 * function: zfcp_fsf_close_port_handler
2683 * purpose: is called for finished Close Port FSF command
2688 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2690 int retval = -EINVAL;
2691 struct zfcp_port *port;
2693 port = (struct zfcp_port *) fsf_req->data;
2695 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2696 /* don't change port status in our bookkeeping */
2697 goto skip_fsfstatus;
2700 /* evaluate FSF status in QTCB */
2701 switch (fsf_req->qtcb->header.fsf_status) {
2703 case FSF_PORT_HANDLE_NOT_VALID:
2704 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2705 "0x%016Lx on adapter %s invalid. This may happen "
2706 "occasionally.\n", port->handle,
2707 port->wwpn, zfcp_get_busid_by_port(port));
2708 ZFCP_LOG_DEBUG("status qualifier:\n");
2709 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2710 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2711 sizeof (union fsf_status_qual));
2712 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2714 zfcp_erp_adapter_reopen(port->adapter, 0);
2715 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2718 case FSF_ADAPTER_STATUS_AVAILABLE:
2719 /* Note: FSF has actually closed the port in this case.
2720 * The status code is just daft. Fingers crossed for a change
2726 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2727 "port handle 0x%x\n", port->wwpn,
2728 zfcp_get_busid_by_port(port), port->handle);
2729 zfcp_erp_modify_port_status(port,
2730 ZFCP_STATUS_COMMON_OPEN,
2736 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2737 "(debug info 0x%x)\n",
2738 fsf_req->qtcb->header.fsf_status);
2739 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2740 debug_exception(fsf_req->adapter->erp_dbf, 0,
2741 &fsf_req->qtcb->header.fsf_status,
2747 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2752 * function: zfcp_fsf_close_physical_port
2754 * purpose: submit FSF command "close physical port"
2756 * returns: address of initiated FSF request
2757 * NULL - request could not be initiated
2760 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2763 unsigned long lock_flags;
2764 volatile struct qdio_buffer_element *sbale;
2766 /* setup new FSF request */
2767 retval = zfcp_fsf_req_create(erp_action->adapter,
2768 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2769 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2770 erp_action->adapter->pool.fsf_req_erp,
2771 &lock_flags, &erp_action->fsf_req);
2773 ZFCP_LOG_INFO("error: Could not create close physical port "
2774 "request (adapter %s, port 0x%016Lx)\n",
2775 zfcp_get_busid_by_adapter(erp_action->adapter),
2776 erp_action->port->wwpn);
2781 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2782 erp_action->fsf_req->sbal_curr, 0);
2783 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2784 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2786 /* mark port as being closed */
2787 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2788 &erp_action->port->status);
2789 /* save a pointer to this port */
2790 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2791 /* port to be closed */
2792 erp_action->fsf_req->qtcb->header.port_handle =
2793 erp_action->port->handle;
2794 erp_action->fsf_req->erp_action = erp_action;
2796 /* start QDIO request for this FSF request */
2797 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2799 ZFCP_LOG_INFO("error: Could not send close physical port "
2800 "request (adapter %s, port 0x%016Lx)\n",
2801 zfcp_get_busid_by_adapter(erp_action->adapter),
2802 erp_action->port->wwpn);
2803 zfcp_fsf_req_free(erp_action->fsf_req);
2804 erp_action->fsf_req = NULL;
2808 ZFCP_LOG_TRACE("close physical port request initiated "
2809 "(adapter %s, port 0x%016Lx)\n",
2810 zfcp_get_busid_by_adapter(erp_action->adapter),
2811 erp_action->port->wwpn);
2813 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2819 * function: zfcp_fsf_close_physical_port_handler
2821 * purpose: is called for finished Close Physical Port FSF command
2826 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2828 int retval = -EINVAL;
2829 struct zfcp_port *port;
2830 struct zfcp_unit *unit;
2831 struct fsf_qtcb_header *header;
2832 u16 subtable, rule, counter;
2834 port = (struct zfcp_port *) fsf_req->data;
2835 header = &fsf_req->qtcb->header;
2837 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2838 /* don't change port status in our bookkeeping */
2839 goto skip_fsfstatus;
2842 /* evaluate FSF status in QTCB */
2843 switch (header->fsf_status) {
2845 case FSF_PORT_HANDLE_NOT_VALID:
2846 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2847 "(adapter %s, port 0x%016Lx). "
2848 "This may happen occasionally.\n",
2850 zfcp_get_busid_by_port(port),
2852 ZFCP_LOG_DEBUG("status qualifier:\n");
2853 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2854 (char *) &header->fsf_status_qual,
2855 sizeof (union fsf_status_qual));
2856 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2858 zfcp_erp_adapter_reopen(port->adapter, 0);
2859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2862 case FSF_ACCESS_DENIED:
2863 ZFCP_LOG_NORMAL("Access denied, cannot close "
2864 "physical port 0x%016Lx on adapter %s\n",
2865 port->wwpn, zfcp_get_busid_by_port(port));
2866 for (counter = 0; counter < 2; counter++) {
2867 subtable = header->fsf_status_qual.halfword[counter * 2];
2868 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2870 case FSF_SQ_CFDC_SUBTABLE_OS:
2871 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2872 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2873 case FSF_SQ_CFDC_SUBTABLE_LUN:
2874 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2875 zfcp_act_subtable_type[subtable], rule);
2879 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2880 zfcp_erp_port_access_denied(port);
2881 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2884 case FSF_PORT_BOXED:
2885 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2886 "%s needs to be reopened but it was attempted "
2887 "to close it physically.\n",
2889 zfcp_get_busid_by_port(port));
2890 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2891 zfcp_erp_port_boxed(port);
2892 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2893 ZFCP_STATUS_FSFREQ_RETRY;
2896 case FSF_ADAPTER_STATUS_AVAILABLE:
2897 switch (header->fsf_status_qual.word[0]) {
2898 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2899 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2901 /* This will now be escalated by ERP */
2902 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2904 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2905 /* ERP strategy will escalate */
2906 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2912 ("bug: Wrong status qualifier 0x%x arrived.\n",
2913 header->fsf_status_qual.word[0]);
2914 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2917 fsf_req->adapter->erp_dbf, 0,
2918 &header->fsf_status_qual.word[0], sizeof (u32));
2924 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2925 "physically closed, port handle 0x%x\n",
2927 zfcp_get_busid_by_port(port), port->handle);
2928 /* can't use generic zfcp_erp_modify_port_status because
2929 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2931 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2932 list_for_each_entry(unit, &port->unit_list_head, list)
2933 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2938 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2939 "(debug info 0x%x)\n",
2940 header->fsf_status);
2941 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2942 debug_exception(fsf_req->adapter->erp_dbf, 0,
2943 &header->fsf_status, sizeof (u32));
2948 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2953 * function: zfcp_fsf_open_unit
2959 * assumptions: This routine does not check whether the associated
2960 * remote port has already been opened. This should be
2961 * done by calling routines. Otherwise some status
2962 * may be presented by FSF
2965 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2967 volatile struct qdio_buffer_element *sbale;
2968 unsigned long lock_flags;
2971 /* setup new FSF request */
2972 retval = zfcp_fsf_req_create(erp_action->adapter,
2974 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2975 erp_action->adapter->pool.fsf_req_erp,
2976 &lock_flags, &(erp_action->fsf_req));
2978 ZFCP_LOG_INFO("error: Could not create open unit request for "
2979 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2980 erp_action->unit->fcp_lun,
2981 erp_action->unit->port->wwpn,
2982 zfcp_get_busid_by_adapter(erp_action->adapter));
2986 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2987 erp_action->fsf_req->sbal_curr, 0);
2988 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2989 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2991 erp_action->fsf_req->qtcb->header.port_handle =
2992 erp_action->port->handle;
2993 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2994 erp_action->unit->fcp_lun;
2995 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2996 erp_action->fsf_req->qtcb->bottom.support.option =
2997 FSF_OPEN_LUN_SUPPRESS_BOXING;
2998 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2999 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3000 erp_action->fsf_req->erp_action = erp_action;
3002 /* start QDIO request for this FSF request */
3003 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3005 ZFCP_LOG_INFO("error: Could not send an open unit request "
3006 "on the adapter %s, port 0x%016Lx for "
3008 zfcp_get_busid_by_adapter(erp_action->adapter),
3009 erp_action->port->wwpn,
3010 erp_action->unit->fcp_lun);
3011 zfcp_fsf_req_free(erp_action->fsf_req);
3012 erp_action->fsf_req = NULL;
3016 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3017 "port 0x%016Lx, unit 0x%016Lx)\n",
3018 zfcp_get_busid_by_adapter(erp_action->adapter),
3019 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3021 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3027 * function: zfcp_fsf_open_unit_handler
3029 * purpose: is called for finished Open LUN command
3034 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3036 int retval = -EINVAL;
3037 struct zfcp_adapter *adapter;
3038 struct zfcp_unit *unit;
3039 struct fsf_qtcb_header *header;
3040 struct fsf_qtcb_bottom_support *bottom;
3041 struct fsf_queue_designator *queue_designator;
3042 u16 subtable, rule, counter;
3043 int exclusive, readwrite;
3045 unit = (struct zfcp_unit *) fsf_req->data;
3047 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3048 /* don't change unit status in our bookkeeping */
3049 goto skip_fsfstatus;
3052 adapter = fsf_req->adapter;
3053 header = &fsf_req->qtcb->header;
3054 bottom = &fsf_req->qtcb->bottom.support;
3055 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3057 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3058 ZFCP_STATUS_UNIT_SHARED |
3059 ZFCP_STATUS_UNIT_READONLY,
3062 /* evaluate FSF status in QTCB */
3063 switch (header->fsf_status) {
3065 case FSF_PORT_HANDLE_NOT_VALID:
3066 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3067 "for port 0x%016Lx on adapter %s invalid "
3068 "This may happen occasionally\n",
3070 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3071 ZFCP_LOG_DEBUG("status qualifier:\n");
3072 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3073 (char *) &header->fsf_status_qual,
3074 sizeof (union fsf_status_qual));
3075 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3076 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3077 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3080 case FSF_LUN_ALREADY_OPEN:
3081 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3082 "remote port 0x%016Lx on adapter %s twice.\n",
3084 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3085 debug_text_exception(adapter->erp_dbf, 0,
3087 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3090 case FSF_ACCESS_DENIED:
3091 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3092 "remote port 0x%016Lx on adapter %s\n",
3093 unit->fcp_lun, unit->port->wwpn,
3094 zfcp_get_busid_by_unit(unit));
3095 for (counter = 0; counter < 2; counter++) {
3096 subtable = header->fsf_status_qual.halfword[counter * 2];
3097 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3099 case FSF_SQ_CFDC_SUBTABLE_OS:
3100 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3101 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3102 case FSF_SQ_CFDC_SUBTABLE_LUN:
3103 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3104 zfcp_act_subtable_type[subtable], rule);
3108 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3109 zfcp_erp_unit_access_denied(unit);
3110 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3111 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3112 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3115 case FSF_PORT_BOXED:
3116 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3117 "needs to be reopened\n",
3118 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3119 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3120 zfcp_erp_port_boxed(unit->port);
3121 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3122 ZFCP_STATUS_FSFREQ_RETRY;
3125 case FSF_LUN_SHARING_VIOLATION:
3126 if (header->fsf_status_qual.word[0] != 0) {
3127 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3129 "connected to the adapter %s "
3130 "is already in use in LPAR%d, CSS%d\n",
3133 zfcp_get_busid_by_unit(unit),
3134 queue_designator->hla,
3135 queue_designator->cssid);
3137 subtable = header->fsf_status_qual.halfword[4];
3138 rule = header->fsf_status_qual.halfword[5];
3140 case FSF_SQ_CFDC_SUBTABLE_OS:
3141 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3142 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3143 case FSF_SQ_CFDC_SUBTABLE_LUN:
3144 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3145 "remote port with WWPN 0x%Lx "
3146 "connected to the adapter %s "
3147 "is denied (%s rule %d)\n",
3150 zfcp_get_busid_by_unit(unit),
3151 zfcp_act_subtable_type[subtable],
3156 ZFCP_LOG_DEBUG("status qualifier:\n");
3157 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3158 (char *) &header->fsf_status_qual,
3159 sizeof (union fsf_status_qual));
3160 debug_text_event(adapter->erp_dbf, 2,
3162 zfcp_erp_unit_access_denied(unit);
3163 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3164 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3165 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3168 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3169 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3170 "There is no handle (temporary port identifier) "
3171 "available for unit 0x%016Lx on port 0x%016Lx "
3175 zfcp_get_busid_by_unit(unit));
3176 debug_text_event(adapter->erp_dbf, 1,
3178 zfcp_erp_unit_failed(unit);
3179 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3182 case FSF_ADAPTER_STATUS_AVAILABLE:
3183 switch (header->fsf_status_qual.word[0]) {
3184 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3185 /* Re-establish link to port */
3186 debug_text_event(adapter->erp_dbf, 1,
3188 zfcp_test_link(unit->port);
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3191 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3192 /* ERP strategy will escalate */
3193 debug_text_event(adapter->erp_dbf, 1,
3195 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3199 ("bug: Wrong status qualifier 0x%x arrived.\n",
3200 header->fsf_status_qual.word[0]);
3201 debug_text_event(adapter->erp_dbf, 0,
3203 debug_exception(adapter->erp_dbf, 0,
3204 &header->fsf_status_qual.word[0],
3209 case FSF_INVALID_COMMAND_OPTION:
3211 "Invalid option 0x%x has been specified "
3212 "in QTCB bottom sent to the adapter %s\n",
3214 zfcp_get_busid_by_adapter(adapter));
3215 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3220 /* save LUN handle assigned by FSF */
3221 unit->handle = header->lun_handle;
3222 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3223 "adapter %s opened, port handle 0x%x\n",
3226 zfcp_get_busid_by_unit(unit),
3228 /* mark unit as open */
3229 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3231 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3232 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3233 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3234 exclusive = (bottom->lun_access_info &
3235 FSF_UNIT_ACCESS_EXCLUSIVE);
3236 readwrite = (bottom->lun_access_info &
3237 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3240 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3244 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3246 ZFCP_LOG_NORMAL("read-only access for unit "
3247 "(adapter %s, wwpn=0x%016Lx, "
3248 "fcp_lun=0x%016Lx)\n",
3249 zfcp_get_busid_by_unit(unit),
3254 if (exclusive && !readwrite) {
3255 ZFCP_LOG_NORMAL("exclusive access of read-only "
3256 "unit not supported\n");
3257 zfcp_erp_unit_failed(unit);
3258 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3259 zfcp_erp_unit_shutdown(unit, 0);
3260 } else if (!exclusive && readwrite) {
3261 ZFCP_LOG_NORMAL("shared access of read-write "
3262 "unit not supported\n");
3263 zfcp_erp_unit_failed(unit);
3264 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3265 zfcp_erp_unit_shutdown(unit, 0);
3273 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3274 "(debug info 0x%x)\n",
3275 header->fsf_status);
3276 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3277 debug_exception(adapter->erp_dbf, 0,
3278 &header->fsf_status, sizeof (u32));
3283 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3288 * function: zfcp_fsf_close_unit
3292 * returns: address of fsf_req - request successfully initiated
3295 * assumptions: This routine does not check whether the associated
3296 * remote port/lun has already been opened. This should be
3297 * done by calling routines. Otherwise some status
3298 * may be presented by FSF
3301 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3303 volatile struct qdio_buffer_element *sbale;
3304 unsigned long lock_flags;
3307 /* setup new FSF request */
3308 retval = zfcp_fsf_req_create(erp_action->adapter,
3310 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3311 erp_action->adapter->pool.fsf_req_erp,
3312 &lock_flags, &(erp_action->fsf_req));
3314 ZFCP_LOG_INFO("error: Could not create close unit request for "
3315 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3316 erp_action->unit->fcp_lun,
3317 erp_action->port->wwpn,
3318 zfcp_get_busid_by_adapter(erp_action->adapter));
3322 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3323 erp_action->fsf_req->sbal_curr, 0);
3324 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3325 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3327 erp_action->fsf_req->qtcb->header.port_handle =
3328 erp_action->port->handle;
3329 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3330 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3331 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3332 erp_action->fsf_req->erp_action = erp_action;
3334 /* start QDIO request for this FSF request */
3335 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3337 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3338 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3339 erp_action->unit->fcp_lun,
3340 erp_action->port->wwpn,
3341 zfcp_get_busid_by_adapter(erp_action->adapter));
3342 zfcp_fsf_req_free(erp_action->fsf_req);
3343 erp_action->fsf_req = NULL;
3347 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3348 "port 0x%016Lx, unit 0x%016Lx)\n",
3349 zfcp_get_busid_by_adapter(erp_action->adapter),
3350 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3352 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3358 * function: zfcp_fsf_close_unit_handler
3360 * purpose: is called for finished Close LUN FSF command
3365 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3367 int retval = -EINVAL;
3368 struct zfcp_unit *unit;
3370 unit = (struct zfcp_unit *) fsf_req->data;
3372 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3373 /* don't change unit status in our bookkeeping */
3374 goto skip_fsfstatus;
3377 /* evaluate FSF status in QTCB */
3378 switch (fsf_req->qtcb->header.fsf_status) {
3380 case FSF_PORT_HANDLE_NOT_VALID:
3381 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3382 "0x%016Lx on adapter %s invalid. This may "
3383 "happen in rare circumstances\n",
3386 zfcp_get_busid_by_unit(unit));
3387 ZFCP_LOG_DEBUG("status qualifier:\n");
3388 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3389 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3390 sizeof (union fsf_status_qual));
3391 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3393 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3394 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3397 case FSF_LUN_HANDLE_NOT_VALID:
3398 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3399 "0x%016Lx on port 0x%016Lx on adapter %s is "
3400 "invalid. This may happen occasionally.\n",
3404 zfcp_get_busid_by_unit(unit));
3405 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3406 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3407 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3408 sizeof (union fsf_status_qual));
3409 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3411 zfcp_erp_port_reopen(unit->port, 0);
3412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3415 case FSF_PORT_BOXED:
3416 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3417 "needs to be reopened\n",
3419 zfcp_get_busid_by_unit(unit));
3420 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3421 zfcp_erp_port_boxed(unit->port);
3422 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3423 ZFCP_STATUS_FSFREQ_RETRY;
3426 case FSF_ADAPTER_STATUS_AVAILABLE:
3427 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3428 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3429 /* re-establish link to port */
3430 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3432 zfcp_test_link(unit->port);
3433 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3435 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3436 /* ERP strategy will escalate */
3437 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3439 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3443 ("bug: Wrong status qualifier 0x%x arrived.\n",
3444 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3445 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3448 fsf_req->adapter->erp_dbf, 0,
3449 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3456 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3457 "closed, port handle 0x%x\n",
3460 zfcp_get_busid_by_unit(unit),
3462 /* mark unit as closed */
3463 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3468 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3469 "(debug info 0x%x)\n",
3470 fsf_req->qtcb->header.fsf_status);
3471 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3472 debug_exception(fsf_req->adapter->erp_dbf, 0,
3473 &fsf_req->qtcb->header.fsf_status,
3479 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3484 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3485 * @adapter: adapter where scsi command is issued
3486 * @unit: unit where command is sent to
3487 * @scsi_cmnd: scsi command to be sent
3488 * @timer: timer to be started when request is initiated
3489 * @req_flags: flags for fsf_request
3492 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3493 struct zfcp_unit *unit,
3494 struct scsi_cmnd * scsi_cmnd,
3495 struct timer_list *timer, int req_flags)
3497 struct zfcp_fsf_req *fsf_req = NULL;
3498 struct fcp_cmnd_iu *fcp_cmnd_iu;
3499 unsigned int sbtype;
3500 unsigned long lock_flags;
3505 /* setup new FSF request */
3506 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3507 adapter->pool.fsf_req_scsi,
3508 &lock_flags, &fsf_req);
3509 if (unlikely(retval < 0)) {
3510 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3511 "for unit 0x%016Lx on port 0x%016Lx on "
3515 zfcp_get_busid_by_adapter(adapter));
3516 goto failed_req_create;
3519 zfcp_unit_get(unit);
3520 fsf_req->unit = unit;
3522 /* associate FSF request with SCSI request (for look up on abort) */
3523 scsi_cmnd->host_scribble = (char *) fsf_req;
3525 /* associate SCSI command with FSF request */
3526 fsf_req->data = (unsigned long) scsi_cmnd;
3528 /* set handles of unit and its parent port in QTCB */
3529 fsf_req->qtcb->header.lun_handle = unit->handle;
3530 fsf_req->qtcb->header.port_handle = unit->port->handle;
3532 /* FSF does not define the structure of the FCP_CMND IU */
3533 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3534 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3537 * set depending on data direction:
3538 * data direction bits in SBALE (SB Type)
3539 * data direction bits in QTCB
3540 * data direction bits in FCP_CMND IU
3542 switch (scsi_cmnd->sc_data_direction) {
3544 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3547 * what is the correct type for commands
3548 * without 'real' data buffers?
3550 sbtype = SBAL_FLAGS0_TYPE_READ;
3552 case DMA_FROM_DEVICE:
3553 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3554 sbtype = SBAL_FLAGS0_TYPE_READ;
3555 fcp_cmnd_iu->rddata = 1;
3558 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3559 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3560 fcp_cmnd_iu->wddata = 1;
3562 case DMA_BIDIRECTIONAL:
3565 * dummy, catch this condition earlier
3566 * in zfcp_scsi_queuecommand
3568 goto failed_scsi_cmnd;
3571 /* set FC service class in QTCB (3 per default) */
3572 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3574 /* set FCP_LUN in FCP_CMND IU in QTCB */
3575 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3577 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3579 /* set task attributes in FCP_CMND IU in QTCB */
3580 if (likely((scsi_cmnd->device->simple_tags) ||
3581 (atomic_test_mask(mask, &unit->status))))
3582 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3584 fcp_cmnd_iu->task_attribute = UNTAGGED;
3586 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3587 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3588 fcp_cmnd_iu->add_fcp_cdb_length
3589 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3590 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3591 "additional FCP_CDB length is 0x%x "
3592 "(shifted right 2 bits)\n",
3594 fcp_cmnd_iu->add_fcp_cdb_length);
3597 * copy SCSI CDB (including additional length, if any) to
3598 * FCP_CDB in FCP_CMND IU in QTCB
3600 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3602 /* FCP CMND IU length in QTCB */
3603 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3604 sizeof (struct fcp_cmnd_iu) +
3605 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3607 /* generate SBALEs from data buffer */
3608 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3609 if (unlikely(real_bytes < 0)) {
3610 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3612 "Data did not fit into available buffer(s), "
3613 "waiting for more...\n");
3616 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3617 "required. Shutting down unit "
3618 "(adapter %s, port 0x%016Lx, "
3620 zfcp_get_busid_by_unit(unit),
3623 zfcp_erp_unit_shutdown(unit, 0);
3629 /* set length of FCP data length in FCP_CMND IU in QTCB */
3630 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3632 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3633 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3634 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3637 * start QDIO request for this FSF request
3638 * covered by an SBALE)
3640 retval = zfcp_fsf_req_send(fsf_req, timer);
3641 if (unlikely(retval < 0)) {
3642 ZFCP_LOG_INFO("error: Could not send FCP command request "
3643 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3644 zfcp_get_busid_by_adapter(adapter),
3650 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3651 "port 0x%016Lx, unit 0x%016Lx)\n",
3652 zfcp_get_busid_by_adapter(adapter),
3660 zfcp_unit_put(unit);
3661 zfcp_fsf_req_free(fsf_req);
3663 scsi_cmnd->host_scribble = NULL;
3666 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3671 * function: zfcp_fsf_send_fcp_command_task_management
3677 * FIXME(design): should be watched by a timeout!!!
3678 * FIXME(design) shouldn't this be modified to return an int
3679 * also...don't know how though
3682 struct zfcp_fsf_req *
3683 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3684 struct zfcp_unit *unit,
3685 u8 tm_flags, int req_flags)
3687 struct zfcp_fsf_req *fsf_req = NULL;
3689 struct fcp_cmnd_iu *fcp_cmnd_iu;
3690 unsigned long lock_flags;
3691 volatile struct qdio_buffer_element *sbale;
3693 /* setup new FSF request */
3694 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3695 adapter->pool.fsf_req_scsi,
3696 &lock_flags, &fsf_req);
3698 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3699 "management) request for adapter %s, port "
3700 " 0x%016Lx, unit 0x%016Lx.\n",
3701 zfcp_get_busid_by_adapter(adapter),
3702 unit->port->wwpn, unit->fcp_lun);
3707 * Used to decide on proper handler in the return path,
3708 * could be either zfcp_fsf_send_fcp_command_task_handler or
3709 * zfcp_fsf_send_fcp_command_task_management_handler */
3711 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3714 * hold a pointer to the unit being target of this
3715 * task management request
3717 fsf_req->data = (unsigned long) unit;
3719 /* set FSF related fields in QTCB */
3720 fsf_req->qtcb->header.lun_handle = unit->handle;
3721 fsf_req->qtcb->header.port_handle = unit->port->handle;
3722 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3723 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3724 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3725 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3727 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3728 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3729 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3731 /* set FCP related fields in FCP_CMND IU in QTCB */
3732 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3733 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3734 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3735 fcp_cmnd_iu->task_management_flags = tm_flags;
3737 /* start QDIO request for this FSF request */
3738 zfcp_fsf_start_scsi_er_timer(adapter);
3739 retval = zfcp_fsf_req_send(fsf_req, NULL);
3741 del_timer(&adapter->scsi_er_timer);
3742 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3743 "management) on adapter %s, port 0x%016Lx for "
3744 "unit LUN 0x%016Lx\n",
3745 zfcp_get_busid_by_adapter(adapter),
3748 zfcp_fsf_req_free(fsf_req);
3753 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3754 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3756 zfcp_get_busid_by_adapter(adapter),
3761 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3766 * function: zfcp_fsf_send_fcp_command_handler
3768 * purpose: is called for finished Send FCP Command
3773 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3775 int retval = -EINVAL;
3776 struct zfcp_unit *unit;
3777 struct fsf_qtcb_header *header;
3778 u16 subtable, rule, counter;
3780 header = &fsf_req->qtcb->header;
3782 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3783 unit = (struct zfcp_unit *) fsf_req->data;
3785 unit = fsf_req->unit;
3787 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3788 /* go directly to calls of special handlers */
3789 goto skip_fsfstatus;
3792 /* evaluate FSF status in QTCB */
3793 switch (header->fsf_status) {
3795 case FSF_PORT_HANDLE_NOT_VALID:
3796 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3797 "0x%016Lx on adapter %s invalid\n",
3799 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3800 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3801 (char *) &header->fsf_status_qual,
3802 sizeof (union fsf_status_qual));
3803 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3805 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3806 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3809 case FSF_LUN_HANDLE_NOT_VALID:
3810 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3811 "0x%016Lx on port 0x%016Lx on adapter %s is "
3812 "invalid. This may happen occasionally.\n",
3816 zfcp_get_busid_by_unit(unit));
3817 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3818 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3819 (char *) &header->fsf_status_qual,
3820 sizeof (union fsf_status_qual));
3821 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3823 zfcp_erp_port_reopen(unit->port, 0);
3824 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3827 case FSF_HANDLE_MISMATCH:
3828 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3829 "unexpectedly. (adapter %s, port 0x%016Lx, "
3832 zfcp_get_busid_by_unit(unit),
3835 ZFCP_LOG_NORMAL("status qualifier:\n");
3836 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3837 (char *) &header->fsf_status_qual,
3838 sizeof (union fsf_status_qual));
3839 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3841 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3845 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3846 if (fsf_req->adapter->fc_service_class <= 3) {
3847 ZFCP_LOG_NORMAL("error: The adapter %s does "
3848 "not support fibrechannel class %d.\n",
3849 zfcp_get_busid_by_unit(unit),
3850 fsf_req->adapter->fc_service_class);
3852 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3853 "adapter %s is invalid. "
3854 "(debug info %d)\n",
3855 zfcp_get_busid_by_unit(unit),
3856 fsf_req->adapter->fc_service_class);
3858 /* stop operation for this adapter */
3859 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3860 "fsf_s_class_nsup");
3861 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3862 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3865 case FSF_FCPLUN_NOT_VALID:
3866 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3867 "adapter %s does not have correct unit "
3871 zfcp_get_busid_by_unit(unit),
3873 ZFCP_LOG_DEBUG("status qualifier:\n");
3874 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3875 (char *) &header->fsf_status_qual,
3876 sizeof (union fsf_status_qual));
3877 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3878 "fsf_s_fcp_lun_nv");
3879 zfcp_erp_port_reopen(unit->port, 0);
3880 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3883 case FSF_ACCESS_DENIED:
3884 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3885 "unit 0x%016Lx on port 0x%016Lx on "
3886 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3887 zfcp_get_busid_by_unit(unit));
3888 for (counter = 0; counter < 2; counter++) {
3889 subtable = header->fsf_status_qual.halfword[counter * 2];
3890 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3892 case FSF_SQ_CFDC_SUBTABLE_OS:
3893 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3894 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3895 case FSF_SQ_CFDC_SUBTABLE_LUN:
3896 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3897 zfcp_act_subtable_type[subtable], rule);
3901 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3902 zfcp_erp_unit_access_denied(unit);
3903 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3906 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3907 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3908 "0x%016Lx on port 0x%016Lx on adapter %s "
3909 "(debug info %d)\n",
3912 zfcp_get_busid_by_unit(unit),
3913 fsf_req->qtcb->bottom.io.data_direction);
3914 /* stop operation for this adapter */
3915 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3916 "fsf_s_dir_ind_nv");
3917 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3918 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3921 case FSF_CMND_LENGTH_NOT_VALID:
3923 ("bug: An invalid control-data-block length field "
3924 "was found in a command for unit 0x%016Lx on port "
3925 "0x%016Lx on adapter %s " "(debug info %d)\n",
3926 unit->fcp_lun, unit->port->wwpn,
3927 zfcp_get_busid_by_unit(unit),
3928 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3929 /* stop operation for this adapter */
3930 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3931 "fsf_s_cmd_len_nv");
3932 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3933 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3936 case FSF_PORT_BOXED:
3937 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3938 "needs to be reopened\n",
3939 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3940 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3941 zfcp_erp_port_boxed(unit->port);
3942 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3943 ZFCP_STATUS_FSFREQ_RETRY;
3947 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3948 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3949 zfcp_get_busid_by_unit(unit),
3950 unit->port->wwpn, unit->fcp_lun);
3951 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3952 zfcp_erp_unit_boxed(unit);
3953 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3954 | ZFCP_STATUS_FSFREQ_RETRY;
3957 case FSF_ADAPTER_STATUS_AVAILABLE:
3958 switch (header->fsf_status_qual.word[0]) {
3959 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3960 /* re-establish link to port */
3961 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3963 zfcp_test_link(unit->port);
3965 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3966 /* FIXME(hw) need proper specs for proper action */
3967 /* let scsi stack deal with retries and escalation */
3968 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3973 ("Unknown status qualifier 0x%x arrived.\n",
3974 header->fsf_status_qual.word[0]);
3975 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3977 debug_exception(fsf_req->adapter->erp_dbf, 0,
3978 &header->fsf_status_qual.word[0],
3982 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3988 case FSF_FCP_RSP_AVAILABLE:
3992 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3993 debug_exception(fsf_req->adapter->erp_dbf, 0,
3994 &header->fsf_status, sizeof(u32));
3999 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4001 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4003 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
4004 fsf_req->unit = NULL;
4005 zfcp_unit_put(unit);
4011 * function: zfcp_fsf_send_fcp_command_task_handler
4013 * purpose: evaluates FCP_RSP IU
4018 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4021 struct scsi_cmnd *scpnt;
4022 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4023 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4024 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4025 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4027 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4028 unsigned long flags;
4029 struct zfcp_unit *unit = fsf_req->unit;
4031 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4032 scpnt = (struct scsi_cmnd *) fsf_req->data;
4033 if (unlikely(!scpnt)) {
4035 ("Command with fsf_req %p is not associated to "
4036 "a scsi command anymore. Aborted?\n", fsf_req);
4039 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4040 /* FIXME: (design) mid-layer should handle DID_ABORT like
4041 * DID_SOFT_ERROR by retrying the request for devices
4042 * that allow retries.
4044 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4045 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4046 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4047 goto skip_fsfstatus;
4050 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4051 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4052 set_host_byte(&scpnt->result, DID_ERROR);
4053 goto skip_fsfstatus;
4056 /* set message byte of result in SCSI command */
4057 scpnt->result |= COMMAND_COMPLETE << 8;
4060 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4061 * of result in SCSI command
4063 scpnt->result |= fcp_rsp_iu->scsi_status;
4064 if (unlikely(fcp_rsp_iu->scsi_status)) {
4066 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4067 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4068 scpnt->cmnd, scpnt->cmd_len);
4069 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4070 fcp_rsp_iu->scsi_status);
4071 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4072 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4073 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4074 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4075 fcp_rsp_iu->fcp_sns_len);
4078 /* check FCP_RSP_INFO */
4079 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4080 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4081 switch (fcp_rsp_info[3]) {
4084 ZFCP_LOG_TRACE("no failure or Task Management "
4085 "Function complete\n");
4086 set_host_byte(&scpnt->result, DID_OK);
4088 case RSP_CODE_LENGTH_MISMATCH:
4090 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4091 "that the fibrechannel protocol data "
4092 "length differs from the burst length. "
4093 "The problem occured on unit 0x%016Lx "
4094 "on port 0x%016Lx on adapter %s",
4097 zfcp_get_busid_by_unit(unit));
4098 /* dump SCSI CDB as prepared by zfcp */
4099 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4100 (char *) &fsf_req->qtcb->
4101 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4102 set_host_byte(&scpnt->result, DID_ERROR);
4103 goto skip_fsfstatus;
4104 case RSP_CODE_FIELD_INVALID:
4105 /* driver or hardware bug */
4106 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4107 "that the fibrechannel protocol data "
4108 "fields were incorrectly set up. "
4109 "The problem occured on the unit "
4110 "0x%016Lx on port 0x%016Lx on "
4114 zfcp_get_busid_by_unit(unit));
4115 /* dump SCSI CDB as prepared by zfcp */
4116 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4117 (char *) &fsf_req->qtcb->
4118 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4119 set_host_byte(&scpnt->result, DID_ERROR);
4120 goto skip_fsfstatus;
4121 case RSP_CODE_RO_MISMATCH:
4123 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4124 "that conflicting values for the "
4125 "fibrechannel payload offset from the "
4126 "header were found. "
4127 "The problem occured on unit 0x%016Lx "
4128 "on port 0x%016Lx on adapter %s.\n",
4131 zfcp_get_busid_by_unit(unit));
4132 /* dump SCSI CDB as prepared by zfcp */
4133 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4134 (char *) &fsf_req->qtcb->
4135 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4136 set_host_byte(&scpnt->result, DID_ERROR);
4137 goto skip_fsfstatus;
4139 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4140 "code was detected for a command. "
4141 "The problem occured on the unit "
4142 "0x%016Lx on port 0x%016Lx on "
4143 "adapter %s (debug info 0x%x)\n",
4146 zfcp_get_busid_by_unit(unit),
4148 /* dump SCSI CDB as prepared by zfcp */
4149 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4150 (char *) &fsf_req->qtcb->
4151 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4152 set_host_byte(&scpnt->result, DID_ERROR);
4153 goto skip_fsfstatus;
4157 /* check for sense data */
4158 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4159 sns_len = FSF_FCP_RSP_SIZE -
4160 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4161 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4163 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4164 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4165 SCSI_SENSE_BUFFERSIZE);
4166 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4167 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4169 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4170 (void *) &scpnt->cmnd, scpnt->cmd_len);
4172 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4173 fcp_rsp_iu->fcp_sns_len);
4174 memcpy(&scpnt->sense_buffer,
4175 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4176 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4177 (void *) &scpnt->sense_buffer, sns_len);
4180 /* check for overrun */
4181 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4182 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4183 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4184 "The response data length is "
4185 "%d, the original length was %d.\n",
4188 zfcp_get_busid_by_unit(unit),
4189 fcp_rsp_iu->fcp_resid,
4190 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4193 /* check for underrun */
4194 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4195 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4196 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4197 "The response data length is "
4198 "%d, the original length was %d.\n",
4201 zfcp_get_busid_by_unit(unit),
4202 fcp_rsp_iu->fcp_resid,
4203 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4205 scpnt->resid = fcp_rsp_iu->fcp_resid;
4206 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4207 set_host_byte(&scpnt->result, DID_ERROR);
4211 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4213 if (scpnt->result != 0)
4214 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4215 else if (scpnt->retries > 0)
4216 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4218 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4220 /* cleanup pointer (need this especially for abort) */
4221 scpnt->host_scribble = NULL;
4223 /* always call back */
4224 (scpnt->scsi_done) (scpnt);
4227 * We must hold this lock until scsi_done has been called.
4228 * Otherwise we may call scsi_done after abort regarding this
4229 * command has completed.
4230 * Note: scsi_done must not block!
4233 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4238 * function: zfcp_fsf_send_fcp_command_task_management_handler
4240 * purpose: evaluates FCP_RSP IU
4245 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4248 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4249 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4250 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4251 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4253 del_timer(&fsf_req->adapter->scsi_er_timer);
4254 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4255 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4256 goto skip_fsfstatus;
4259 /* check FCP_RSP_INFO */
4260 switch (fcp_rsp_info[3]) {
4263 ZFCP_LOG_DEBUG("no failure or Task Management "
4264 "Function complete\n");
4266 case RSP_CODE_TASKMAN_UNSUPP:
4267 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4268 "is not supported on the target device "
4269 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4272 zfcp_get_busid_by_unit(unit));
4273 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4275 case RSP_CODE_TASKMAN_FAILED:
4276 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4277 "failed to complete successfully. "
4278 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4281 zfcp_get_busid_by_unit(unit));
4282 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4285 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4286 "code was detected for a command. "
4287 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4288 "(debug info 0x%x)\n",
4291 zfcp_get_busid_by_unit(unit),
4293 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4302 * function: zfcp_fsf_control_file
4304 * purpose: Initiator of the control file upload/download FSF requests
4306 * returns: 0 - FSF request is successfuly created and queued
4307 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4308 * -EINVAL - Invalid direction specified
4309 * -ENOMEM - Insufficient memory
4310 * -EPERM - Cannot create FSF request or place it in QDIO queue
4313 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4314 struct zfcp_fsf_req **fsf_req_ptr,
4317 struct zfcp_sg_list *sg_list)
4319 struct zfcp_fsf_req *fsf_req;
4320 struct fsf_qtcb_bottom_support *bottom;
4321 volatile struct qdio_buffer_element *sbale;
4322 struct timer_list *timer;
4323 unsigned long lock_flags;
4328 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4329 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4330 zfcp_get_busid_by_adapter(adapter));
4331 retval = -EOPNOTSUPP;
4335 switch (fsf_command) {
4337 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4338 direction = SBAL_FLAGS0_TYPE_WRITE;
4339 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4340 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4341 req_flags = ZFCP_WAIT_FOR_SBAL;
4344 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4345 direction = SBAL_FLAGS0_TYPE_READ;
4349 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4354 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4360 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4361 NULL, &lock_flags, &fsf_req);
4363 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4365 zfcp_get_busid_by_adapter(adapter));
4367 goto unlock_queue_lock;
4370 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4371 sbale[0].flags |= direction;
4373 bottom = &fsf_req->qtcb->bottom.support;
4374 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4375 bottom->option = option;
4377 if (sg_list->count > 0) {
4380 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4381 sg_list->sg, sg_list->count,
4382 ZFCP_MAX_SBALS_PER_REQ);
4383 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4385 "error: Could not create sufficient number of "
4386 "SBALS for an FSF request to the adapter %s\n",
4387 zfcp_get_busid_by_adapter(adapter));
4392 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4395 timer->function = zfcp_fsf_request_timeout_handler;
4396 timer->data = (unsigned long) adapter;
4397 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4399 retval = zfcp_fsf_req_send(fsf_req, timer);
4401 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4403 zfcp_get_busid_by_adapter(adapter));
4407 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4409 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4411 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4412 "download" : "upload",
4413 zfcp_get_busid_by_adapter(adapter));
4415 wait_event(fsf_req->completion_wq,
4416 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4418 *fsf_req_ptr = fsf_req;
4419 del_timer_sync(timer);
4423 zfcp_fsf_req_free(fsf_req);
4425 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4434 * function: zfcp_fsf_control_file_handler
4436 * purpose: Handler of the control file upload/download FSF requests
4438 * returns: 0 - FSF request successfuly processed
4439 * -EAGAIN - Operation has to be repeated because of a temporary problem
4440 * -EACCES - There is no permission to execute an operation
4441 * -EPERM - The control file is not in a right format
4442 * -EIO - There is a problem with the FCP adapter
4443 * -EINVAL - Invalid operation
4444 * -EFAULT - User space memory I/O operation fault
4447 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4449 struct zfcp_adapter *adapter = fsf_req->adapter;
4450 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4451 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4454 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4456 goto skip_fsfstatus;
4459 switch (header->fsf_status) {
4463 "The FSF request has been successfully completed "
4464 "on the adapter %s\n",
4465 zfcp_get_busid_by_adapter(adapter));
4468 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4469 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4470 switch (header->fsf_status_qual.word[0]) {
4472 case FSF_SQ_CFDC_HARDENED_ON_SE:
4474 "CFDC on the adapter %s has being "
4475 "hardened on primary and secondary SE\n",
4476 zfcp_get_busid_by_adapter(adapter));
4479 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4481 "CFDC of the adapter %s could not "
4482 "be saved on the SE\n",
4483 zfcp_get_busid_by_adapter(adapter));
4486 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4488 "CFDC of the adapter %s could not "
4489 "be copied to the secondary SE\n",
4490 zfcp_get_busid_by_adapter(adapter));
4495 "CFDC could not be hardened "
4496 "on the adapter %s\n",
4497 zfcp_get_busid_by_adapter(adapter));
4500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4504 case FSF_AUTHORIZATION_FAILURE:
4506 "Adapter %s does not accept privileged commands\n",
4507 zfcp_get_busid_by_adapter(adapter));
4508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4512 case FSF_CFDC_ERROR_DETECTED:
4514 "Error at position %d in the CFDC, "
4515 "CFDC is discarded by the adapter %s\n",
4516 header->fsf_status_qual.word[0],
4517 zfcp_get_busid_by_adapter(adapter));
4518 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4522 case FSF_CONTROL_FILE_UPDATE_ERROR:
4524 "Adapter %s cannot harden the control file, "
4525 "file is discarded\n",
4526 zfcp_get_busid_by_adapter(adapter));
4527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4531 case FSF_CONTROL_FILE_TOO_LARGE:
4533 "Control file is too large, file is discarded "
4534 "by the adapter %s\n",
4535 zfcp_get_busid_by_adapter(adapter));
4536 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4540 case FSF_ACCESS_CONFLICT_DETECTED:
4541 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4543 "CFDC has been discarded by the adapter %s, "
4544 "because activation would impact "
4545 "%d active connection(s)\n",
4546 zfcp_get_busid_by_adapter(adapter),
4547 header->fsf_status_qual.word[0]);
4548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4552 case FSF_CONFLICTS_OVERRULED:
4553 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4555 "CFDC has been activated on the adapter %s, "
4556 "but activation has impacted "
4557 "%d active connection(s)\n",
4558 zfcp_get_busid_by_adapter(adapter),
4559 header->fsf_status_qual.word[0]);
4560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4564 case FSF_UNKNOWN_OP_SUBTYPE:
4565 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4566 "op_subtype=0x%x)\n",
4567 zfcp_get_busid_by_adapter(adapter),
4568 bottom->operation_subtype);
4569 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4573 case FSF_INVALID_COMMAND_OPTION:
4575 "Invalid option 0x%x has been specified "
4576 "in QTCB bottom sent to the adapter %s\n",
4578 zfcp_get_busid_by_adapter(adapter));
4579 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4585 "bug: An unknown/unexpected FSF status 0x%08x "
4586 "was presented on the adapter %s\n",
4588 zfcp_get_busid_by_adapter(adapter));
4589 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4590 debug_exception(fsf_req->adapter->erp_dbf, 0,
4591 &header->fsf_status_qual.word[0], sizeof(u32));
4592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4602 zfcp_fsf_req_sbal_check(unsigned long *flags,
4603 struct zfcp_qdio_queue *queue, int needed)
4605 write_lock_irqsave(&queue->queue_lock, *flags);
4606 if (likely(atomic_read(&queue->free_count) >= needed))
4608 write_unlock_irqrestore(&queue->queue_lock, *flags);
4613 * set qtcb pointer in fsf_req and initialize QTCB
4616 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4618 if (likely(fsf_req->qtcb != NULL)) {
4619 fsf_req->qtcb->prefix.req_seq_no = fsf_req->adapter->fsf_req_seq_no;
4620 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4621 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4622 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_req->fsf_command];
4623 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4624 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4625 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4630 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4631 * @adapter: adapter for which request queue is examined
4632 * @req_flags: flags indicating whether to wait for needed SBAL or not
4633 * @lock_flags: lock_flags if queue_lock is taken
4634 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4635 * Locks: lock adapter->request_queue->queue_lock on success
4638 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4639 unsigned long *lock_flags)
4642 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4644 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4645 ret = wait_event_interruptible_timeout(adapter->request_wq,
4646 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4652 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4659 * function: zfcp_fsf_req_create
4661 * purpose: create an FSF request at the specified adapter and
4662 * setup common fields
4664 * returns: -ENOMEM if there was insufficient memory for a request
4665 * -EIO if no qdio buffers could be allocate to the request
4666 * -EINVAL/-EPERM on bug conditions in req_dequeue
4669 * note: The created request is returned by reference.
4671 * locks: lock of concerned request queue must not be held,
4672 * but is held on completion (write, irqsave)
4675 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4676 mempool_t *pool, unsigned long *lock_flags,
4677 struct zfcp_fsf_req **fsf_req_p)
4679 volatile struct qdio_buffer_element *sbale;
4680 struct zfcp_fsf_req *fsf_req = NULL;
4682 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4684 /* allocate new FSF request */
4685 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4686 if (unlikely(NULL == fsf_req)) {
4687 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4688 "the outbound (send) queue.\n");
4690 goto failed_fsf_req;
4693 fsf_req->adapter = adapter;
4694 fsf_req->fsf_command = fsf_cmd;
4696 zfcp_fsf_req_qtcb_init(fsf_req);
4698 /* initialize waitqueue which may be used to wait on
4699 this request completion */
4700 init_waitqueue_head(&fsf_req->completion_wq);
4702 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4708 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4709 * if it is not set (see also *_open_qdio and *_close_qdio).
4712 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4713 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4718 if (fsf_req->qtcb) {
4719 fsf_req->seq_no = adapter->fsf_req_seq_no;
4720 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4722 fsf_req->sbal_number = 1;
4723 fsf_req->sbal_first = req_queue->free_index;
4724 fsf_req->sbal_curr = req_queue->free_index;
4725 fsf_req->sbale_curr = 1;
4727 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4728 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4731 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4733 /* setup common SBALE fields */
4734 sbale[0].addr = fsf_req;
4735 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4736 if (likely(fsf_req->qtcb != NULL)) {
4737 sbale[1].addr = (void *) fsf_req->qtcb;
4738 sbale[1].length = sizeof(struct fsf_qtcb);
4741 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4742 fsf_req->sbal_number, fsf_req->sbal_first);
4747 /* dequeue new FSF request previously enqueued */
4748 zfcp_fsf_req_free(fsf_req);
4752 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4754 *fsf_req_p = fsf_req;
4759 * function: zfcp_fsf_req_send
4761 * purpose: start transfer of FSF request via QDIO
4763 * returns: 0 - request transfer succesfully started
4764 * !0 - start of request transfer failed
4767 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4769 struct zfcp_adapter *adapter;
4770 struct zfcp_qdio_queue *req_queue;
4771 volatile struct qdio_buffer_element *sbale;
4773 int new_distance_from_int;
4774 unsigned long flags;
4777 adapter = fsf_req->adapter;
4778 req_queue = &adapter->request_queue,
4781 /* FIXME(debug): remove it later */
4782 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4783 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4784 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4785 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4788 /* put allocated FSF request at list tail */
4789 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4790 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4791 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4793 inc_seq_no = (fsf_req->qtcb != NULL);
4795 /* figure out expiration time of timeout and start timeout */
4796 if (unlikely(timer)) {
4797 timer->expires += jiffies;
4801 ZFCP_LOG_TRACE("request queue of adapter %s: "
4802 "next free SBAL is %i, %i free SBALs\n",
4803 zfcp_get_busid_by_adapter(adapter),
4804 req_queue->free_index,
4805 atomic_read(&req_queue->free_count));
4807 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4808 "index_in_queue=%i, count=%i, buffers=%p\n",
4809 zfcp_get_busid_by_adapter(adapter),
4810 QDIO_FLAG_SYNC_OUTPUT,
4811 0, fsf_req->sbal_first, fsf_req->sbal_number,
4812 &req_queue->buffer[fsf_req->sbal_first]);
4815 * adjust the number of free SBALs in request queue as well as
4816 * position of first one
4818 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4819 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4820 req_queue->free_index += fsf_req->sbal_number; /* increase */
4821 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4822 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4824 fsf_req->issued = get_clock();
4826 retval = do_QDIO(adapter->ccw_device,
4827 QDIO_FLAG_SYNC_OUTPUT,
4828 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4830 if (unlikely(retval)) {
4831 /* Queues are down..... */
4834 * FIXME(potential race):
4835 * timer might be expired (absolutely unlikely)
4839 spin_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4840 list_del(&fsf_req->list);
4841 spin_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4843 * adjust the number of free SBALs in request queue as well as
4844 * position of first one
4846 zfcp_qdio_zero_sbals(req_queue->buffer,
4847 fsf_req->sbal_first, fsf_req->sbal_number);
4848 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4849 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4850 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4851 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4853 ("error: do_QDIO failed. Buffers could not be enqueued "
4854 "to request queue.\n");
4856 req_queue->distance_from_int = new_distance_from_int;
4858 * increase FSF sequence counter -
4859 * this must only be done for request successfully enqueued to
4860 * QDIO this rejected requests may be cleaned up by calling
4861 * routines resulting in missing sequence counter values
4865 /* Don't increase for unsolicited status */
4867 adapter->fsf_req_seq_no++;
4869 /* count FSF requests pending */
4870 atomic_inc(&adapter->fsf_reqs_active);
4875 #undef ZFCP_LOG_AREA