2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
25 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
26 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
27 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
28 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
29 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
30 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
31 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
32 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
33 static int zfcp_fsf_send_fcp_command_task_management_handler(
34 struct zfcp_fsf_req *);
35 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
36 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
37 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
38 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
40 static inline int zfcp_fsf_req_sbal_check(
41 unsigned long *, struct zfcp_qdio_queue *, int);
42 static inline int zfcp_use_one_sbal(
43 struct scatterlist *, int, struct scatterlist *, int);
44 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
45 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
46 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
47 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
48 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
49 static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
50 struct fsf_link_down_info *);
51 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
53 /* association between FSF command and FSF QTCB type */
54 static u32 fsf_qtcb_type[] = {
55 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
56 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
65 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
66 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
67 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
70 static const char zfcp_act_subtable_type[5][8] = {
71 "unknown", "OS", "WWPN", "DID", "LUN"
74 /****************************************************************/
75 /*************** FSF related Functions *************************/
76 /****************************************************************/
78 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
81 * function: zfcp_fsf_req_alloc
83 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
84 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
87 * returns: pointer to allocated fsf_req if successfull
93 static struct zfcp_fsf_req *
94 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
98 struct zfcp_fsf_req *fsf_req = NULL;
100 if (req_flags & ZFCP_REQ_NO_QTCB)
101 size = sizeof(struct zfcp_fsf_req);
103 size = sizeof(struct zfcp_fsf_req_qtcb);
106 ptr = mempool_alloc(pool, GFP_ATOMIC);
108 if (req_flags & ZFCP_REQ_NO_QTCB)
109 ptr = kmalloc(size, GFP_ATOMIC);
111 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
118 memset(ptr, 0, size);
120 if (req_flags & ZFCP_REQ_NO_QTCB) {
121 fsf_req = (struct zfcp_fsf_req *) ptr;
123 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
124 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
127 fsf_req->pool = pool;
134 * function: zfcp_fsf_req_free
136 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
137 * returns it into the pool via helper functions.
144 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
146 if (likely(fsf_req->pool)) {
147 mempool_free(fsf_req, fsf_req->pool);
152 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
160 * zfcp_fsf_req_dismiss - dismiss a single fsf request
162 static void zfcp_fsf_req_dismiss(struct zfcp_adapter *adapter,
163 struct zfcp_fsf_req *fsf_req,
164 unsigned int counter)
168 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
169 dbg_tmp[1] = (u64) counter;
170 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
171 list_del(&fsf_req->list);
172 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
173 zfcp_fsf_req_complete(fsf_req);
177 * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests
179 int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
181 struct zfcp_fsf_req *request, *tmp;
183 unsigned int i, counter;
185 spin_lock_irqsave(&adapter->req_list_lock, flags);
186 atomic_set(&adapter->reqs_active, 0);
187 for (i=0; i<REQUEST_LIST_SIZE; i++) {
188 if (list_empty(&adapter->req_list[i]))
192 list_for_each_entry_safe(request, tmp,
193 &adapter->req_list[i], list) {
194 zfcp_fsf_req_dismiss(adapter, request, counter);
198 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
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;
880 struct fsf_bit_error_payload *fsf_bit_error;
882 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
883 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
884 mempool_free(status_buffer, adapter->pool.data_status_read);
885 zfcp_fsf_req_free(fsf_req);
889 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
891 switch (status_buffer->status_type) {
893 case FSF_STATUS_READ_PORT_CLOSED:
894 zfcp_fsf_status_read_port_closed(fsf_req);
897 case FSF_STATUS_READ_INCOMING_ELS:
898 zfcp_fsf_incoming_els(fsf_req);
901 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
902 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
903 zfcp_get_busid_by_adapter(adapter));
906 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
907 fsf_bit_error = (struct fsf_bit_error_payload *)
908 status_buffer->payload;
909 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
910 "received (adapter %s, "
911 "link failures = %i, loss of sync errors = %i, "
912 "loss of signal errors = %i, "
913 "primitive sequence errors = %i, "
914 "invalid transmission word errors = %i, "
915 "CRC errors = %i)\n",
916 zfcp_get_busid_by_adapter(adapter),
917 fsf_bit_error->link_failure_error_count,
918 fsf_bit_error->loss_of_sync_error_count,
919 fsf_bit_error->loss_of_signal_error_count,
920 fsf_bit_error->primitive_sequence_error_count,
921 fsf_bit_error->invalid_transmission_word_error_count,
922 fsf_bit_error->crc_error_count);
923 ZFCP_LOG_INFO("Additional bit error threshold data "
925 "primitive sequence event time-outs = %i, "
926 "elastic buffer overrun errors = %i, "
927 "advertised receive buffer-to-buffer credit = %i, "
928 "current receice buffer-to-buffer credit = %i, "
929 "advertised transmit buffer-to-buffer credit = %i, "
930 "current transmit buffer-to-buffer credit = %i)\n",
931 zfcp_get_busid_by_adapter(adapter),
932 fsf_bit_error->primitive_sequence_event_timeout_count,
933 fsf_bit_error->elastic_buffer_overrun_error_count,
934 fsf_bit_error->advertised_receive_b2b_credit,
935 fsf_bit_error->current_receive_b2b_credit,
936 fsf_bit_error->advertised_transmit_b2b_credit,
937 fsf_bit_error->current_transmit_b2b_credit);
940 case FSF_STATUS_READ_LINK_DOWN:
941 switch (status_buffer->status_subtype) {
942 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
943 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
944 zfcp_get_busid_by_adapter(adapter));
945 zfcp_fsf_link_down_info_eval(adapter,
946 (struct fsf_link_down_info *)
947 &status_buffer->payload);
949 case FSF_STATUS_READ_SUB_FDISC_FAILED:
950 ZFCP_LOG_INFO("Local link to adapter %s is down "
951 "due to failed FDISC login\n",
952 zfcp_get_busid_by_adapter(adapter));
953 zfcp_fsf_link_down_info_eval(adapter,
954 (struct fsf_link_down_info *)
955 &status_buffer->payload);
957 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
958 ZFCP_LOG_INFO("Local link to adapter %s is down "
959 "due to firmware update on adapter\n",
960 zfcp_get_busid_by_adapter(adapter));
961 zfcp_fsf_link_down_info_eval(adapter, NULL);
964 ZFCP_LOG_INFO("Local link to adapter %s is down "
965 "due to unknown reason\n",
966 zfcp_get_busid_by_adapter(adapter));
967 zfcp_fsf_link_down_info_eval(adapter, NULL);
971 case FSF_STATUS_READ_LINK_UP:
972 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
973 "Restarting operations on this adapter\n",
974 zfcp_get_busid_by_adapter(adapter));
975 /* All ports should be marked as ready to run again */
976 zfcp_erp_modify_adapter_status(adapter,
977 ZFCP_STATUS_COMMON_RUNNING,
979 zfcp_erp_adapter_reopen(adapter,
980 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
981 | ZFCP_STATUS_COMMON_ERP_FAILED);
984 case FSF_STATUS_READ_NOTIFICATION_LOST:
985 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
986 "adapter %s%s%s%s%s%s%s%s%s\n",
987 zfcp_get_busid_by_adapter(adapter),
988 (status_buffer->status_subtype &
989 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
990 ", incoming ELS" : "",
991 (status_buffer->status_subtype &
992 FSF_STATUS_READ_SUB_SENSE_DATA) ?
994 (status_buffer->status_subtype &
995 FSF_STATUS_READ_SUB_LINK_STATUS) ?
996 ", link status change" : "",
997 (status_buffer->status_subtype &
998 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
1000 (status_buffer->status_subtype &
1001 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
1002 ", bit error exception" : "",
1003 (status_buffer->status_subtype &
1004 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
1005 ", ACT update" : "",
1006 (status_buffer->status_subtype &
1007 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
1008 ", ACT hardening" : "",
1009 (status_buffer->status_subtype &
1010 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
1011 ", adapter feature change" : "");
1013 if (status_buffer->status_subtype &
1014 FSF_STATUS_READ_SUB_ACT_UPDATED)
1015 zfcp_erp_adapter_access_changed(adapter);
1018 case FSF_STATUS_READ_CFDC_UPDATED:
1019 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1020 zfcp_get_busid_by_adapter(adapter));
1021 zfcp_erp_adapter_access_changed(adapter);
1024 case FSF_STATUS_READ_CFDC_HARDENED:
1025 switch (status_buffer->status_subtype) {
1026 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1027 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1028 zfcp_get_busid_by_adapter(adapter));
1030 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1031 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1032 "to the secondary SE\n",
1033 zfcp_get_busid_by_adapter(adapter));
1036 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1037 zfcp_get_busid_by_adapter(adapter));
1041 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1042 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1043 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1044 "been changed from 0x%08X to 0x%08X\n",
1045 zfcp_get_busid_by_adapter(adapter),
1046 *(u32*) (status_buffer->payload + 4),
1047 *(u32*) (status_buffer->payload));
1048 adapter->adapter_features = *(u32*) status_buffer->payload;
1052 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1053 "type was received (debug info 0x%x)\n",
1054 status_buffer->status_type);
1055 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1057 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1058 (char *) status_buffer,
1059 sizeof (struct fsf_status_read_buffer));
1062 mempool_free(status_buffer, adapter->pool.data_status_read);
1063 zfcp_fsf_req_free(fsf_req);
1065 * recycle buffer and start new request repeat until outbound
1066 * queue is empty or adapter shutdown is requested
1070 * we may wait in the req_create for 5s during shutdown, so
1071 * qdio_cleanup will have to wait at least that long before returning
1072 * with failure to allow us a proper cleanup under all circumstances
1076 * allocation failure possible? (Is this code needed?)
1078 retval = zfcp_fsf_status_read(adapter, 0);
1080 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1081 "request for the adapter %s.\n",
1082 zfcp_get_busid_by_adapter(adapter));
1083 /* temporary fix to avoid status read buffer shortage */
1084 adapter->status_read_failed++;
1085 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1086 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1087 ZFCP_LOG_INFO("restart adapter %s due to status read "
1088 "buffer shortage\n",
1089 zfcp_get_busid_by_adapter(adapter));
1090 zfcp_erp_adapter_reopen(adapter, 0);
1098 * function: zfcp_fsf_abort_fcp_command
1100 * purpose: tells FSF to abort a running SCSI command
1102 * returns: address of initiated FSF request
1103 * NULL - request could not be initiated
1105 * FIXME(design): should be watched by a timeout !!!
1106 * FIXME(design) shouldn't this be modified to return an int
1107 * also...don't know how though
1109 struct zfcp_fsf_req *
1110 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1111 struct zfcp_adapter *adapter,
1112 struct zfcp_unit *unit, int req_flags)
1114 volatile struct qdio_buffer_element *sbale;
1115 unsigned long lock_flags;
1116 struct zfcp_fsf_req *fsf_req = NULL;
1119 /* setup new FSF request */
1120 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1121 req_flags, adapter->pool.fsf_req_abort,
1122 &lock_flags, &fsf_req);
1124 ZFCP_LOG_INFO("error: Failed to create an abort command "
1125 "request for lun 0x%016Lx on port 0x%016Lx "
1129 zfcp_get_busid_by_adapter(adapter));
1133 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1134 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1135 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1137 fsf_req->data = (unsigned long) unit;
1139 /* set handles of unit and its parent port in QTCB */
1140 fsf_req->qtcb->header.lun_handle = unit->handle;
1141 fsf_req->qtcb->header.port_handle = unit->port->handle;
1143 /* set handle of request which should be aborted */
1144 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1146 /* start QDIO request for this FSF request */
1148 zfcp_fsf_start_scsi_er_timer(adapter);
1149 retval = zfcp_fsf_req_send(fsf_req, NULL);
1151 del_timer(&adapter->scsi_er_timer);
1152 ZFCP_LOG_INFO("error: Failed to send abort command request "
1153 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1154 zfcp_get_busid_by_adapter(adapter),
1155 unit->port->wwpn, unit->fcp_lun);
1156 zfcp_fsf_req_free(fsf_req);
1161 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1162 "(adapter%s, port d_id=0x%08x, "
1163 "unit x%016Lx, old_req_id=0x%lx)\n",
1164 zfcp_get_busid_by_adapter(adapter),
1166 unit->fcp_lun, old_req_id);
1168 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1173 * function: zfcp_fsf_abort_fcp_command_handler
1175 * purpose: is called for finished Abort FCP Command request
1180 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1182 int retval = -EINVAL;
1183 struct zfcp_unit *unit;
1184 unsigned char status_qual =
1185 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1187 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1189 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1190 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1191 goto skip_fsfstatus;
1194 unit = (struct zfcp_unit *) new_fsf_req->data;
1196 /* evaluate FSF status in QTCB */
1197 switch (new_fsf_req->qtcb->header.fsf_status) {
1199 case FSF_PORT_HANDLE_NOT_VALID:
1200 if (status_qual >> 4 != status_qual % 0xf) {
1201 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1204 * In this case a command that was sent prior to a port
1205 * reopen was aborted (handles are different). This is
1209 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1210 "port 0x%016Lx on adapter %s invalid. "
1211 "This may happen occasionally.\n",
1214 zfcp_get_busid_by_unit(unit));
1215 ZFCP_LOG_INFO("status qualifier:\n");
1216 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1217 (char *) &new_fsf_req->qtcb->header.
1219 sizeof (union fsf_status_qual));
1220 /* Let's hope this sorts out the mess */
1221 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1223 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1224 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1228 case FSF_LUN_HANDLE_NOT_VALID:
1229 if (status_qual >> 4 != status_qual % 0xf) {
1231 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1234 * In this case a command that was sent prior to a unit
1235 * reopen was aborted (handles are different).
1240 ("Warning: Temporary LUN identifier 0x%x of LUN "
1241 "0x%016Lx on port 0x%016Lx on adapter %s is "
1242 "invalid. This may happen in rare cases. "
1243 "Trying to re-establish link.\n",
1247 zfcp_get_busid_by_unit(unit));
1248 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1249 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1250 (char *) &new_fsf_req->qtcb->header.
1252 sizeof (union fsf_status_qual));
1253 /* Let's hope this sorts out the mess */
1254 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1256 zfcp_erp_port_reopen(unit->port, 0);
1257 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1261 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1263 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1265 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1268 case FSF_PORT_BOXED:
1269 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1270 "be reopened\n", unit->port->wwpn,
1271 zfcp_get_busid_by_unit(unit));
1272 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1274 zfcp_erp_port_boxed(unit->port);
1275 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1276 | ZFCP_STATUS_FSFREQ_RETRY;
1281 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1283 unit->fcp_lun, unit->port->wwpn,
1284 zfcp_get_busid_by_unit(unit));
1285 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1286 zfcp_erp_unit_boxed(unit);
1287 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1288 | ZFCP_STATUS_FSFREQ_RETRY;
1291 case FSF_ADAPTER_STATUS_AVAILABLE:
1292 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1293 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1294 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1296 zfcp_test_link(unit->port);
1297 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1299 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1300 /* SCSI stack will escalate */
1301 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1303 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1307 ("bug: Wrong status qualifier 0x%x arrived.\n",
1308 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1309 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1311 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1312 &new_fsf_req->qtcb->header.
1313 fsf_status_qual.word[0], sizeof (u32));
1320 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1324 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1325 "(debug info 0x%x)\n",
1326 new_fsf_req->qtcb->header.fsf_status);
1327 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1329 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1330 &new_fsf_req->qtcb->header.fsf_status,
1339 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1341 * Two scatter-gather lists are passed, one for the reqeust and one for the
1345 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1346 struct scatterlist *resp, int resp_count)
1348 return ((req_count == 1) &&
1349 (resp_count == 1) &&
1350 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1352 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1353 req[0].length - 1) & PAGE_MASK)) &&
1354 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1356 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1357 resp[0].length - 1) & PAGE_MASK)));
1361 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1362 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1364 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1365 * a struct zfcp_fsf_req
1366 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1367 * is sent within error recovery
1370 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1371 struct zfcp_erp_action *erp_action)
1373 volatile struct qdio_buffer_element *sbale;
1374 struct zfcp_port *port;
1375 struct zfcp_adapter *adapter;
1376 struct zfcp_fsf_req *fsf_req;
1377 unsigned long lock_flags;
1382 adapter = port->adapter;
1384 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1385 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1386 pool, &lock_flags, &fsf_req);
1388 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1390 zfcp_get_busid_by_adapter(adapter));
1394 if (erp_action != NULL) {
1395 erp_action->fsf_req = fsf_req;
1396 fsf_req->erp_action = erp_action;
1399 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1400 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1401 ct->resp, ct->resp_count)){
1402 /* both request buffer and response buffer
1403 fit into one sbale each */
1404 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1405 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1406 sbale[2].length = ct->req[0].length;
1407 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1408 sbale[3].length = ct->resp[0].length;
1409 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1410 } else if (adapter->adapter_features &
1411 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1412 /* try to use chained SBALs */
1413 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1414 SBAL_FLAGS0_TYPE_WRITE_READ,
1415 ct->req, ct->req_count,
1416 ZFCP_MAX_SBALS_PER_CT_REQ);
1418 ZFCP_LOG_INFO("error: creation of CT request failed "
1420 zfcp_get_busid_by_adapter(adapter));
1428 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1429 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1430 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1431 SBAL_FLAGS0_TYPE_WRITE_READ,
1432 ct->resp, ct->resp_count,
1433 ZFCP_MAX_SBALS_PER_CT_REQ);
1435 ZFCP_LOG_INFO("error: creation of CT request failed "
1437 zfcp_get_busid_by_adapter(adapter));
1445 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1447 /* reject send generic request */
1449 "error: microcode does not support chained SBALs,"
1450 "CT request too big (adapter %s)\n",
1451 zfcp_get_busid_by_adapter(adapter));
1456 /* settings in QTCB */
1457 fsf_req->qtcb->header.port_handle = port->handle;
1458 fsf_req->qtcb->bottom.support.service_class =
1459 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1460 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1461 fsf_req->data = (unsigned long) ct;
1463 zfcp_san_dbf_event_ct_request(fsf_req);
1465 /* start QDIO request for this FSF request */
1466 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1468 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1469 "(adapter %s, port 0x%016Lx)\n",
1470 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1474 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1475 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1479 zfcp_fsf_req_free(fsf_req);
1480 if (erp_action != NULL) {
1481 erp_action->fsf_req = NULL;
1485 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1491 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1492 * @fsf_req: pointer to struct zfcp_fsf_req
1494 * Data specific for the Generic Service request is passed using
1495 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1496 * Usually a specific handler for the CT request is called which is
1497 * found in this structure.
1500 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1502 struct zfcp_port *port;
1503 struct zfcp_adapter *adapter;
1504 struct zfcp_send_ct *send_ct;
1505 struct fsf_qtcb_header *header;
1506 struct fsf_qtcb_bottom_support *bottom;
1507 int retval = -EINVAL;
1508 u16 subtable, rule, counter;
1510 adapter = fsf_req->adapter;
1511 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1512 port = send_ct->port;
1513 header = &fsf_req->qtcb->header;
1514 bottom = &fsf_req->qtcb->bottom.support;
1516 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1517 goto skip_fsfstatus;
1519 /* evaluate FSF status in QTCB */
1520 switch (header->fsf_status) {
1523 zfcp_san_dbf_event_ct_response(fsf_req);
1527 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1528 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1530 zfcp_get_busid_by_port(port),
1531 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1532 /* stop operation for this adapter */
1533 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1534 zfcp_erp_adapter_shutdown(adapter, 0);
1535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1538 case FSF_ADAPTER_STATUS_AVAILABLE:
1539 switch (header->fsf_status_qual.word[0]){
1540 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1541 /* reopening link to port */
1542 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1543 zfcp_test_link(port);
1544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1546 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1547 /* ERP strategy will escalate */
1548 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1552 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1554 header->fsf_status_qual.word[0]);
1559 case FSF_ACCESS_DENIED:
1560 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1561 "command (adapter %s, port d_id=0x%08x)\n",
1562 zfcp_get_busid_by_port(port), port->d_id);
1563 for (counter = 0; counter < 2; counter++) {
1564 subtable = header->fsf_status_qual.halfword[counter * 2];
1565 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1567 case FSF_SQ_CFDC_SUBTABLE_OS:
1568 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1569 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1570 case FSF_SQ_CFDC_SUBTABLE_LUN:
1571 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1572 zfcp_act_subtable_type[subtable], rule);
1576 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1577 zfcp_erp_port_access_denied(port);
1578 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1581 case FSF_GENERIC_COMMAND_REJECTED:
1582 ZFCP_LOG_INFO("generic service command rejected "
1583 "(adapter %s, port d_id=0x%08x)\n",
1584 zfcp_get_busid_by_port(port), port->d_id);
1585 ZFCP_LOG_INFO("status qualifier:\n");
1586 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1587 (char *) &header->fsf_status_qual,
1588 sizeof (union fsf_status_qual));
1589 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1590 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1593 case FSF_PORT_HANDLE_NOT_VALID:
1594 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1595 "0x%016Lx on adapter %s invalid. This may "
1596 "happen occasionally.\n", port->handle,
1597 port->wwpn, zfcp_get_busid_by_port(port));
1598 ZFCP_LOG_INFO("status qualifier:\n");
1599 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1600 (char *) &header->fsf_status_qual,
1601 sizeof (union fsf_status_qual));
1602 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1603 zfcp_erp_adapter_reopen(adapter, 0);
1604 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1607 case FSF_PORT_BOXED:
1608 ZFCP_LOG_INFO("port needs to be reopened "
1609 "(adapter %s, port d_id=0x%08x)\n",
1610 zfcp_get_busid_by_port(port), port->d_id);
1611 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1612 zfcp_erp_port_boxed(port);
1613 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1614 | ZFCP_STATUS_FSFREQ_RETRY;
1617 /* following states should never occure, all cases avoided
1618 in zfcp_fsf_send_ct - but who knows ... */
1619 case FSF_PAYLOAD_SIZE_MISMATCH:
1620 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1621 "req_buf_length=%d, 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;
1626 case FSF_REQUEST_SIZE_TOO_LARGE:
1627 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1628 "req_buf_length=%d)\n",
1629 zfcp_get_busid_by_adapter(adapter),
1630 bottom->req_buf_length);
1631 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1633 case FSF_RESPONSE_SIZE_TOO_LARGE:
1634 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1635 "resp_buf_length=%d)\n",
1636 zfcp_get_busid_by_adapter(adapter),
1637 bottom->resp_buf_length);
1638 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1640 case FSF_SBAL_MISMATCH:
1641 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1642 "resp_buf_length=%d)\n",
1643 zfcp_get_busid_by_adapter(adapter),
1644 bottom->req_buf_length, bottom->resp_buf_length);
1645 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1649 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1650 "(debug info 0x%x)\n", header->fsf_status);
1651 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1652 debug_exception(adapter->erp_dbf, 0,
1653 &header->fsf_status_qual.word[0], sizeof (u32));
1658 send_ct->status = retval;
1660 if (send_ct->handler != NULL)
1661 send_ct->handler(send_ct->handler_data);
1667 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1668 * @els: pointer to struct zfcp_send_els which contains all needed data for
1672 zfcp_fsf_send_els(struct zfcp_send_els *els)
1674 volatile struct qdio_buffer_element *sbale;
1675 struct zfcp_fsf_req *fsf_req;
1677 struct zfcp_adapter *adapter;
1678 unsigned long lock_flags;
1683 adapter = els->adapter;
1685 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1686 ZFCP_REQ_AUTO_CLEANUP,
1687 NULL, &lock_flags, &fsf_req);
1689 ZFCP_LOG_INFO("error: creation of ELS request failed "
1690 "(adapter %s, port d_id: 0x%08x)\n",
1691 zfcp_get_busid_by_adapter(adapter), d_id);
1695 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1696 if (zfcp_use_one_sbal(els->req, els->req_count,
1697 els->resp, els->resp_count)){
1698 /* both request buffer and response buffer
1699 fit into one sbale each */
1700 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1701 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1702 sbale[2].length = els->req[0].length;
1703 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1704 sbale[3].length = els->resp[0].length;
1705 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1706 } else if (adapter->adapter_features &
1707 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1708 /* try to use chained SBALs */
1709 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1710 SBAL_FLAGS0_TYPE_WRITE_READ,
1711 els->req, els->req_count,
1712 ZFCP_MAX_SBALS_PER_ELS_REQ);
1714 ZFCP_LOG_INFO("error: creation of ELS request failed "
1715 "(adapter %s, port d_id: 0x%08x)\n",
1716 zfcp_get_busid_by_adapter(adapter), d_id);
1724 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1725 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1726 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1727 SBAL_FLAGS0_TYPE_WRITE_READ,
1728 els->resp, els->resp_count,
1729 ZFCP_MAX_SBALS_PER_ELS_REQ);
1731 ZFCP_LOG_INFO("error: creation of ELS request failed "
1732 "(adapter %s, port d_id: 0x%08x)\n",
1733 zfcp_get_busid_by_adapter(adapter), d_id);
1741 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1743 /* reject request */
1744 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1745 ", ELS request too big (adapter %s, "
1746 "port d_id: 0x%08x)\n",
1747 zfcp_get_busid_by_adapter(adapter), d_id);
1752 /* settings in QTCB */
1753 fsf_req->qtcb->bottom.support.d_id = d_id;
1754 fsf_req->qtcb->bottom.support.service_class =
1755 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1756 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1757 fsf_req->data = (unsigned long) els;
1759 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1761 zfcp_san_dbf_event_els_request(fsf_req);
1763 /* start QDIO request for this FSF request */
1764 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1766 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1767 "(adapter %s, port d_id: 0x%08x)\n",
1768 zfcp_get_busid_by_adapter(adapter), d_id);
1772 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1773 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1777 zfcp_fsf_req_free(fsf_req);
1781 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1788 * zfcp_fsf_send_els_handler - handler for ELS commands
1789 * @fsf_req: pointer to struct zfcp_fsf_req
1791 * Data specific for the ELS command is passed using
1792 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1793 * Usually a specific handler for the ELS command is called which is
1794 * found in this structure.
1796 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1798 struct zfcp_adapter *adapter;
1799 struct zfcp_port *port;
1801 struct fsf_qtcb_header *header;
1802 struct fsf_qtcb_bottom_support *bottom;
1803 struct zfcp_send_els *send_els;
1804 int retval = -EINVAL;
1805 u16 subtable, rule, counter;
1807 send_els = (struct zfcp_send_els *) fsf_req->data;
1808 adapter = send_els->adapter;
1809 port = send_els->port;
1810 d_id = send_els->d_id;
1811 header = &fsf_req->qtcb->header;
1812 bottom = &fsf_req->qtcb->bottom.support;
1814 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1815 goto skip_fsfstatus;
1817 switch (header->fsf_status) {
1820 zfcp_san_dbf_event_els_response(fsf_req);
1824 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1825 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1827 zfcp_get_busid_by_adapter(adapter),
1828 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1829 /* stop operation for this adapter */
1830 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1831 zfcp_erp_adapter_shutdown(adapter, 0);
1832 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1835 case FSF_ADAPTER_STATUS_AVAILABLE:
1836 switch (header->fsf_status_qual.word[0]){
1837 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1838 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1839 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1840 zfcp_test_link(port);
1841 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1843 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1844 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1847 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1848 (struct zfcp_ls_rjt_par *)
1849 &header->fsf_status_qual.word[2]);
1851 case FSF_SQ_RETRY_IF_POSSIBLE:
1852 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1853 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1857 header->fsf_status_qual.word[0]);
1858 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1859 (char*)header->fsf_status_qual.word, 16);
1863 case FSF_ELS_COMMAND_REJECTED:
1864 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1865 "prohibited sending "
1866 "(adapter: %s, port d_id: 0x%08x)\n",
1867 zfcp_get_busid_by_adapter(adapter), d_id);
1871 case FSF_PAYLOAD_SIZE_MISMATCH:
1873 "ELS request size and ELS response size must be either "
1874 "both 0, or both greater than 0 "
1875 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1876 zfcp_get_busid_by_adapter(adapter),
1877 bottom->req_buf_length,
1878 bottom->resp_buf_length);
1881 case FSF_REQUEST_SIZE_TOO_LARGE:
1883 "Length of the ELS request buffer, "
1884 "specified in QTCB bottom, "
1885 "exceeds the size of the buffers "
1886 "that have been allocated for ELS request data "
1887 "(adapter: %s, req_buf_length=%d)\n",
1888 zfcp_get_busid_by_adapter(adapter),
1889 bottom->req_buf_length);
1892 case FSF_RESPONSE_SIZE_TOO_LARGE:
1894 "Length of the ELS response buffer, "
1895 "specified in QTCB bottom, "
1896 "exceeds the size of the buffers "
1897 "that have been allocated for ELS response data "
1898 "(adapter: %s, resp_buf_length=%d)\n",
1899 zfcp_get_busid_by_adapter(adapter),
1900 bottom->resp_buf_length);
1903 case FSF_SBAL_MISMATCH:
1904 /* should never occure, avoided in zfcp_fsf_send_els */
1905 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1906 "resp_buf_length=%d)\n",
1907 zfcp_get_busid_by_adapter(adapter),
1908 bottom->req_buf_length, bottom->resp_buf_length);
1909 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1912 case FSF_ACCESS_DENIED:
1913 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1914 "(adapter %s, port d_id=0x%08x)\n",
1915 zfcp_get_busid_by_adapter(adapter), d_id);
1916 for (counter = 0; counter < 2; counter++) {
1917 subtable = header->fsf_status_qual.halfword[counter * 2];
1918 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1920 case FSF_SQ_CFDC_SUBTABLE_OS:
1921 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1922 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1923 case FSF_SQ_CFDC_SUBTABLE_LUN:
1924 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1925 zfcp_act_subtable_type[subtable], rule);
1929 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1931 zfcp_erp_port_access_denied(port);
1932 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1937 "bug: An unknown FSF Status was presented "
1938 "(adapter: %s, fsf_status=0x%08x)\n",
1939 zfcp_get_busid_by_adapter(adapter),
1940 header->fsf_status);
1941 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1942 debug_exception(adapter->erp_dbf, 0,
1943 &header->fsf_status_qual.word[0], sizeof(u32));
1944 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1949 send_els->status = retval;
1951 if (send_els->handler != 0)
1952 send_els->handler(send_els->handler_data);
1958 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1960 volatile struct qdio_buffer_element *sbale;
1961 unsigned long lock_flags;
1964 /* setup new FSF request */
1965 retval = zfcp_fsf_req_create(erp_action->adapter,
1966 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1967 ZFCP_REQ_AUTO_CLEANUP,
1968 erp_action->adapter->pool.fsf_req_erp,
1969 &lock_flags, &(erp_action->fsf_req));
1971 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1972 "data request for adapter %s.\n",
1973 zfcp_get_busid_by_adapter(erp_action->adapter));
1977 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1978 erp_action->fsf_req->sbal_curr, 0);
1979 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1980 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1982 erp_action->fsf_req->erp_action = erp_action;
1983 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1985 FSF_FEATURE_LUN_SHARING |
1986 FSF_FEATURE_NOTIFICATION_LOST |
1987 FSF_FEATURE_UPDATE_ALERT;
1989 /* start QDIO request for this FSF request */
1990 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1993 ("error: Could not send exchange configuration data "
1994 "command on the adapter %s\n",
1995 zfcp_get_busid_by_adapter(erp_action->adapter));
1996 zfcp_fsf_req_free(erp_action->fsf_req);
1997 erp_action->fsf_req = NULL;
2001 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2003 zfcp_get_busid_by_adapter(erp_action->adapter));
2006 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2012 * zfcp_fsf_exchange_config_evaluate
2013 * @fsf_req: fsf_req which belongs to xchg config data request
2014 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2016 * returns: -EIO on error, 0 otherwise
2019 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2021 struct fsf_qtcb_bottom_config *bottom;
2022 struct zfcp_adapter *adapter = fsf_req->adapter;
2023 struct Scsi_Host *shost = adapter->scsi_host;
2025 bottom = &fsf_req->qtcb->bottom.config;
2026 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2027 bottom->low_qtcb_version, bottom->high_qtcb_version);
2028 adapter->fsf_lic_version = bottom->lic_version;
2029 adapter->adapter_features = bottom->adapter_features;
2030 adapter->connection_features = bottom->connection_features;
2031 adapter->peer_wwpn = 0;
2032 adapter->peer_wwnn = 0;
2033 adapter->peer_d_id = 0;
2036 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2037 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2038 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2039 fc_host_speed(shost) = bottom->fc_link_speed;
2040 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2041 adapter->hydra_version = bottom->adapter_type;
2042 if (fc_host_permanent_port_name(shost) == -1)
2043 fc_host_permanent_port_name(shost) =
2044 fc_host_port_name(shost);
2045 if (bottom->fc_topology == FSF_TOPO_P2P) {
2046 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2047 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2048 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2049 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2050 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2051 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2052 else if (bottom->fc_topology == FSF_TOPO_AL)
2053 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2055 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2057 fc_host_node_name(shost) = 0;
2058 fc_host_port_name(shost) = 0;
2059 fc_host_port_id(shost) = 0;
2060 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2061 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2062 adapter->hydra_version = 0;
2065 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2066 adapter->hardware_version = bottom->hardware_version;
2067 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2068 min(FC_SERIAL_NUMBER_SIZE, 17));
2069 EBCASC(fc_host_serial_number(shost),
2070 min(FC_SERIAL_NUMBER_SIZE, 17));
2073 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2077 "adapter version 0x%x, "
2078 "LIC version 0x%x, "
2079 "FC link speed %d Gb/s\n",
2080 zfcp_get_busid_by_adapter(adapter),
2081 (wwn_t) fc_host_node_name(shost),
2082 (wwn_t) fc_host_port_name(shost),
2083 fc_host_port_id(shost),
2084 adapter->hydra_version,
2085 adapter->fsf_lic_version,
2086 fc_host_speed(shost));
2087 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2088 ZFCP_LOG_NORMAL("error: the adapter %s "
2089 "only supports newer control block "
2090 "versions in comparison to this device "
2091 "driver (try updated device driver)\n",
2092 zfcp_get_busid_by_adapter(adapter));
2093 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2094 zfcp_erp_adapter_shutdown(adapter, 0);
2097 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2098 ZFCP_LOG_NORMAL("error: the adapter %s "
2099 "only supports older control block "
2100 "versions than this device driver uses"
2101 "(consider a microcode upgrade)\n",
2102 zfcp_get_busid_by_adapter(adapter));
2103 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2104 zfcp_erp_adapter_shutdown(adapter, 0);
2111 * function: zfcp_fsf_exchange_config_data_handler
2113 * purpose: is called for finished Exchange Configuration Data command
2118 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2120 struct fsf_qtcb_bottom_config *bottom;
2121 struct zfcp_adapter *adapter = fsf_req->adapter;
2122 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2124 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2127 switch (qtcb->header.fsf_status) {
2130 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2133 switch (fc_host_port_type(adapter->scsi_host)) {
2134 case FC_PORTTYPE_PTP:
2135 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2136 "configuration detected at adapter %s\n"
2137 "Peer WWNN 0x%016llx, "
2138 "peer WWPN 0x%016llx, "
2139 "peer d_id 0x%06x\n",
2140 zfcp_get_busid_by_adapter(adapter),
2143 adapter->peer_d_id);
2144 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2147 case FC_PORTTYPE_NLPORT:
2148 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2149 "topology detected at adapter %s "
2150 "unsupported, shutting down adapter\n",
2151 zfcp_get_busid_by_adapter(adapter));
2152 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2154 zfcp_erp_adapter_shutdown(adapter, 0);
2156 case FC_PORTTYPE_NPORT:
2157 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2158 "network detected at adapter %s.\n",
2159 zfcp_get_busid_by_adapter(adapter));
2162 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2163 "reported by the exchange "
2164 "configuration command for "
2165 "the adapter %s is not "
2166 "of a type known to the zfcp "
2167 "driver, shutting down adapter\n",
2168 zfcp_get_busid_by_adapter(adapter));
2169 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2171 zfcp_erp_adapter_shutdown(adapter, 0);
2174 bottom = &qtcb->bottom.config;
2175 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2176 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2177 "allowed by the adapter %s "
2178 "is lower than the minimum "
2179 "required by the driver (%ld bytes).\n",
2180 bottom->max_qtcb_size,
2181 zfcp_get_busid_by_adapter(adapter),
2182 sizeof(struct fsf_qtcb));
2183 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2185 debug_event(fsf_req->adapter->erp_dbf, 0,
2186 &bottom->max_qtcb_size, sizeof (u32));
2187 zfcp_erp_adapter_shutdown(adapter, 0);
2190 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2193 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2194 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2196 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2199 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2201 zfcp_fsf_link_down_info_eval(adapter,
2202 &qtcb->header.fsf_status_qual.link_down_info);
2205 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2206 debug_event(fsf_req->adapter->erp_dbf, 0,
2207 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2208 zfcp_erp_adapter_shutdown(adapter, 0);
2215 * zfcp_fsf_exchange_port_data - request information about local port
2216 * @erp_action: ERP action for the adapter for which port data is requested
2217 * @adapter: for which port data is requested
2218 * @data: response to exchange port data request
2221 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2222 struct zfcp_adapter *adapter,
2223 struct fsf_qtcb_bottom_port *data)
2225 volatile struct qdio_buffer_element *sbale;
2227 unsigned long lock_flags;
2228 struct zfcp_fsf_req *fsf_req;
2229 struct timer_list *timer;
2231 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2232 ZFCP_LOG_INFO("error: exchange port data "
2233 "command not supported by adapter %s\n",
2234 zfcp_get_busid_by_adapter(adapter));
2238 /* setup new FSF request */
2239 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2240 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2241 NULL, &lock_flags, &fsf_req);
2243 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2244 "exchange port data request for"
2245 "the adapter %s.\n",
2246 zfcp_get_busid_by_adapter(adapter));
2247 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2253 fsf_req->data = (unsigned long) data;
2255 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2256 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2257 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2260 erp_action->fsf_req = fsf_req;
2261 fsf_req->erp_action = erp_action;
2262 timer = &erp_action->timer;
2264 timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
2266 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2268 zfcp_fsf_req_free(fsf_req);
2272 timer->function = zfcp_fsf_request_timeout_handler;
2273 timer->data = (unsigned long) adapter;
2274 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2277 retval = zfcp_fsf_req_send(fsf_req, timer);
2279 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2280 "command on the adapter %s\n",
2281 zfcp_get_busid_by_adapter(adapter));
2282 zfcp_fsf_req_free(fsf_req);
2284 erp_action->fsf_req = NULL;
2287 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2292 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2295 wait_event(fsf_req->completion_wq,
2296 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2297 del_timer_sync(timer);
2298 zfcp_fsf_req_free(fsf_req);
2305 * zfcp_fsf_exchange_port_evaluate
2306 * @fsf_req: fsf_req which belongs to xchg port data request
2307 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2310 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2312 struct zfcp_adapter *adapter;
2313 struct fsf_qtcb *qtcb;
2314 struct fsf_qtcb_bottom_port *bottom, *data;
2315 struct Scsi_Host *shost;
2317 adapter = fsf_req->adapter;
2318 qtcb = fsf_req->qtcb;
2319 bottom = &qtcb->bottom.port;
2320 shost = adapter->scsi_host;
2322 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2324 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2326 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2327 fc_host_permanent_port_name(shost) = bottom->wwpn;
2329 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2330 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2331 fc_host_supported_speeds(shost) = bottom->supported_speed;
2335 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2336 * @fsf_req: pointer to struct zfcp_fsf_req
2339 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2341 struct zfcp_adapter *adapter;
2342 struct fsf_qtcb *qtcb;
2344 adapter = fsf_req->adapter;
2345 qtcb = fsf_req->qtcb;
2347 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2350 switch (qtcb->header.fsf_status) {
2352 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2353 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2355 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2356 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2357 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2358 zfcp_fsf_link_down_info_eval(adapter,
2359 &qtcb->header.fsf_status_qual.link_down_info);
2362 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2363 debug_event(adapter->erp_dbf, 0,
2364 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2370 * function: zfcp_fsf_open_port
2374 * returns: address of initiated FSF request
2375 * NULL - request could not be initiated
2378 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2380 volatile struct qdio_buffer_element *sbale;
2381 unsigned long lock_flags;
2384 /* setup new FSF request */
2385 retval = zfcp_fsf_req_create(erp_action->adapter,
2386 FSF_QTCB_OPEN_PORT_WITH_DID,
2387 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2388 erp_action->adapter->pool.fsf_req_erp,
2389 &lock_flags, &(erp_action->fsf_req));
2391 ZFCP_LOG_INFO("error: Could not create open port request "
2392 "for port 0x%016Lx on adapter %s.\n",
2393 erp_action->port->wwpn,
2394 zfcp_get_busid_by_adapter(erp_action->adapter));
2398 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2399 erp_action->fsf_req->sbal_curr, 0);
2400 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2401 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2403 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2404 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2405 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2406 erp_action->fsf_req->erp_action = erp_action;
2408 /* start QDIO request for this FSF request */
2409 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2411 ZFCP_LOG_INFO("error: Could not send open port request for "
2412 "port 0x%016Lx on adapter %s.\n",
2413 erp_action->port->wwpn,
2414 zfcp_get_busid_by_adapter(erp_action->adapter));
2415 zfcp_fsf_req_free(erp_action->fsf_req);
2416 erp_action->fsf_req = NULL;
2420 ZFCP_LOG_DEBUG("open port request initiated "
2421 "(adapter %s, port 0x%016Lx)\n",
2422 zfcp_get_busid_by_adapter(erp_action->adapter),
2423 erp_action->port->wwpn);
2425 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2431 * function: zfcp_fsf_open_port_handler
2433 * purpose: is called for finished Open Port command
2438 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2440 int retval = -EINVAL;
2441 struct zfcp_port *port;
2442 struct fsf_plogi *plogi;
2443 struct fsf_qtcb_header *header;
2444 u16 subtable, rule, counter;
2446 port = (struct zfcp_port *) fsf_req->data;
2447 header = &fsf_req->qtcb->header;
2449 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2450 /* don't change port status in our bookkeeping */
2451 goto skip_fsfstatus;
2454 /* evaluate FSF status in QTCB */
2455 switch (header->fsf_status) {
2457 case FSF_PORT_ALREADY_OPEN:
2458 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2459 "is already open.\n",
2460 port->wwpn, zfcp_get_busid_by_port(port));
2461 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2464 * This is a bug, however operation should continue normally
2465 * if it is simply ignored
2469 case FSF_ACCESS_DENIED:
2470 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2472 port->wwpn, zfcp_get_busid_by_port(port));
2473 for (counter = 0; counter < 2; counter++) {
2474 subtable = header->fsf_status_qual.halfword[counter * 2];
2475 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2477 case FSF_SQ_CFDC_SUBTABLE_OS:
2478 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2479 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2480 case FSF_SQ_CFDC_SUBTABLE_LUN:
2481 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2482 zfcp_act_subtable_type[subtable], rule);
2486 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2487 zfcp_erp_port_access_denied(port);
2488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2491 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2492 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2493 "The remote port 0x%016Lx on adapter %s "
2494 "could not be opened. Disabling it.\n",
2495 port->wwpn, zfcp_get_busid_by_port(port));
2496 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2498 zfcp_erp_port_failed(port);
2499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2502 case FSF_ADAPTER_STATUS_AVAILABLE:
2503 switch (header->fsf_status_qual.word[0]) {
2504 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2505 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2507 /* ERP strategy will escalate */
2508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2510 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2511 /* ERP strategy will escalate */
2512 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2516 case FSF_SQ_NO_RETRY_POSSIBLE:
2517 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2518 "adapter %s could not be opened. "
2521 zfcp_get_busid_by_port(port));
2522 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2524 zfcp_erp_port_failed(port);
2525 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2529 ("bug: Wrong status qualifier 0x%x arrived.\n",
2530 header->fsf_status_qual.word[0]);
2531 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2534 fsf_req->adapter->erp_dbf, 0,
2535 &header->fsf_status_qual.word[0],
2542 /* save port handle assigned by FSF */
2543 port->handle = header->port_handle;
2544 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2545 "was opened, it's port handle is 0x%x\n",
2546 port->wwpn, zfcp_get_busid_by_port(port),
2548 /* mark port as open */
2549 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2550 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2551 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2552 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2555 /* check whether D_ID has changed during open */
2557 * FIXME: This check is not airtight, as the FCP channel does
2558 * not monitor closures of target port connections caused on
2559 * the remote side. Thus, they might miss out on invalidating
2560 * locally cached WWPNs (and other N_Port parameters) of gone
2561 * target ports. So, our heroic attempt to make things safe
2562 * could be undermined by 'open port' response data tagged with
2563 * obsolete WWPNs. Another reason to monitor potential
2564 * connection closures ourself at least (by interpreting
2565 * incoming ELS' and unsolicited status). It just crosses my
2566 * mind that one should be able to cross-check by means of
2567 * another GID_PN straight after a port has been opened.
2568 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2570 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2571 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2573 if (fsf_req->qtcb->bottom.support.els1_length <
2574 sizeof (struct fsf_plogi)) {
2576 "warning: insufficient length of "
2577 "PLOGI payload (%i)\n",
2578 fsf_req->qtcb->bottom.support.els1_length);
2579 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2580 "fsf_s_short_plogi:");
2581 /* skip sanity check and assume wwpn is ok */
2583 if (plogi->serv_param.wwpn != port->wwpn) {
2584 ZFCP_LOG_INFO("warning: d_id of port "
2585 "0x%016Lx changed during "
2586 "open\n", port->wwpn);
2588 fsf_req->adapter->erp_dbf, 0,
2589 "fsf_s_did_change:");
2591 ZFCP_STATUS_PORT_DID_DID,
2594 port->wwnn = plogi->serv_param.wwnn;
2595 zfcp_plogi_evaluate(port, plogi);
2601 case FSF_UNKNOWN_OP_SUBTYPE:
2602 /* should never occure, subtype not set in zfcp_fsf_open_port */
2603 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2604 "op_subtype=0x%x)\n",
2605 zfcp_get_busid_by_port(port),
2606 fsf_req->qtcb->bottom.support.operation_subtype);
2607 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2611 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2612 "(debug info 0x%x)\n",
2613 header->fsf_status);
2614 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2615 debug_exception(fsf_req->adapter->erp_dbf, 0,
2616 &header->fsf_status, sizeof (u32));
2621 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2626 * function: zfcp_fsf_close_port
2628 * purpose: submit FSF command "close port"
2630 * returns: address of initiated FSF request
2631 * NULL - request could not be initiated
2634 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2636 volatile struct qdio_buffer_element *sbale;
2637 unsigned long lock_flags;
2640 /* setup new FSF request */
2641 retval = zfcp_fsf_req_create(erp_action->adapter,
2642 FSF_QTCB_CLOSE_PORT,
2643 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2644 erp_action->adapter->pool.fsf_req_erp,
2645 &lock_flags, &(erp_action->fsf_req));
2647 ZFCP_LOG_INFO("error: Could not create a close port request "
2648 "for port 0x%016Lx on adapter %s.\n",
2649 erp_action->port->wwpn,
2650 zfcp_get_busid_by_adapter(erp_action->adapter));
2654 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2655 erp_action->fsf_req->sbal_curr, 0);
2656 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2657 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2659 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2660 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2661 erp_action->fsf_req->erp_action = erp_action;
2662 erp_action->fsf_req->qtcb->header.port_handle =
2663 erp_action->port->handle;
2665 /* start QDIO request for this FSF request */
2666 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2668 ZFCP_LOG_INFO("error: Could not send a close port request for "
2669 "port 0x%016Lx on adapter %s.\n",
2670 erp_action->port->wwpn,
2671 zfcp_get_busid_by_adapter(erp_action->adapter));
2672 zfcp_fsf_req_free(erp_action->fsf_req);
2673 erp_action->fsf_req = NULL;
2677 ZFCP_LOG_TRACE("close port request initiated "
2678 "(adapter %s, port 0x%016Lx)\n",
2679 zfcp_get_busid_by_adapter(erp_action->adapter),
2680 erp_action->port->wwpn);
2682 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2688 * function: zfcp_fsf_close_port_handler
2690 * purpose: is called for finished Close Port FSF command
2695 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2697 int retval = -EINVAL;
2698 struct zfcp_port *port;
2700 port = (struct zfcp_port *) fsf_req->data;
2702 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2703 /* don't change port status in our bookkeeping */
2704 goto skip_fsfstatus;
2707 /* evaluate FSF status in QTCB */
2708 switch (fsf_req->qtcb->header.fsf_status) {
2710 case FSF_PORT_HANDLE_NOT_VALID:
2711 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2712 "0x%016Lx on adapter %s invalid. This may happen "
2713 "occasionally.\n", port->handle,
2714 port->wwpn, zfcp_get_busid_by_port(port));
2715 ZFCP_LOG_DEBUG("status qualifier:\n");
2716 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2717 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2718 sizeof (union fsf_status_qual));
2719 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2721 zfcp_erp_adapter_reopen(port->adapter, 0);
2722 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2725 case FSF_ADAPTER_STATUS_AVAILABLE:
2726 /* Note: FSF has actually closed the port in this case.
2727 * The status code is just daft. Fingers crossed for a change
2733 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2734 "port handle 0x%x\n", port->wwpn,
2735 zfcp_get_busid_by_port(port), port->handle);
2736 zfcp_erp_modify_port_status(port,
2737 ZFCP_STATUS_COMMON_OPEN,
2743 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2744 "(debug info 0x%x)\n",
2745 fsf_req->qtcb->header.fsf_status);
2746 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2747 debug_exception(fsf_req->adapter->erp_dbf, 0,
2748 &fsf_req->qtcb->header.fsf_status,
2754 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2759 * function: zfcp_fsf_close_physical_port
2761 * purpose: submit FSF command "close physical port"
2763 * returns: address of initiated FSF request
2764 * NULL - request could not be initiated
2767 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2770 unsigned long lock_flags;
2771 volatile struct qdio_buffer_element *sbale;
2773 /* setup new FSF request */
2774 retval = zfcp_fsf_req_create(erp_action->adapter,
2775 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2776 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2777 erp_action->adapter->pool.fsf_req_erp,
2778 &lock_flags, &erp_action->fsf_req);
2780 ZFCP_LOG_INFO("error: Could not create close physical port "
2781 "request (adapter %s, port 0x%016Lx)\n",
2782 zfcp_get_busid_by_adapter(erp_action->adapter),
2783 erp_action->port->wwpn);
2788 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2789 erp_action->fsf_req->sbal_curr, 0);
2790 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2791 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2793 /* mark port as being closed */
2794 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2795 &erp_action->port->status);
2796 /* save a pointer to this port */
2797 erp_action->fsf_req->data = (unsigned long) erp_action->port;
2798 /* port to be closed */
2799 erp_action->fsf_req->qtcb->header.port_handle =
2800 erp_action->port->handle;
2801 erp_action->fsf_req->erp_action = erp_action;
2803 /* start QDIO request for this FSF request */
2804 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2806 ZFCP_LOG_INFO("error: Could not send close physical port "
2807 "request (adapter %s, port 0x%016Lx)\n",
2808 zfcp_get_busid_by_adapter(erp_action->adapter),
2809 erp_action->port->wwpn);
2810 zfcp_fsf_req_free(erp_action->fsf_req);
2811 erp_action->fsf_req = NULL;
2815 ZFCP_LOG_TRACE("close physical port request initiated "
2816 "(adapter %s, port 0x%016Lx)\n",
2817 zfcp_get_busid_by_adapter(erp_action->adapter),
2818 erp_action->port->wwpn);
2820 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2826 * function: zfcp_fsf_close_physical_port_handler
2828 * purpose: is called for finished Close Physical Port FSF command
2833 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2835 int retval = -EINVAL;
2836 struct zfcp_port *port;
2837 struct zfcp_unit *unit;
2838 struct fsf_qtcb_header *header;
2839 u16 subtable, rule, counter;
2841 port = (struct zfcp_port *) fsf_req->data;
2842 header = &fsf_req->qtcb->header;
2844 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2845 /* don't change port status in our bookkeeping */
2846 goto skip_fsfstatus;
2849 /* evaluate FSF status in QTCB */
2850 switch (header->fsf_status) {
2852 case FSF_PORT_HANDLE_NOT_VALID:
2853 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2854 "(adapter %s, port 0x%016Lx). "
2855 "This may happen occasionally.\n",
2857 zfcp_get_busid_by_port(port),
2859 ZFCP_LOG_DEBUG("status qualifier:\n");
2860 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2861 (char *) &header->fsf_status_qual,
2862 sizeof (union fsf_status_qual));
2863 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2865 zfcp_erp_adapter_reopen(port->adapter, 0);
2866 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2869 case FSF_ACCESS_DENIED:
2870 ZFCP_LOG_NORMAL("Access denied, cannot close "
2871 "physical port 0x%016Lx on adapter %s\n",
2872 port->wwpn, zfcp_get_busid_by_port(port));
2873 for (counter = 0; counter < 2; counter++) {
2874 subtable = header->fsf_status_qual.halfword[counter * 2];
2875 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2877 case FSF_SQ_CFDC_SUBTABLE_OS:
2878 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2879 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2880 case FSF_SQ_CFDC_SUBTABLE_LUN:
2881 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2882 zfcp_act_subtable_type[subtable], rule);
2886 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2887 zfcp_erp_port_access_denied(port);
2888 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2891 case FSF_PORT_BOXED:
2892 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2893 "%s needs to be reopened but it was attempted "
2894 "to close it physically.\n",
2896 zfcp_get_busid_by_port(port));
2897 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2898 zfcp_erp_port_boxed(port);
2899 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2900 ZFCP_STATUS_FSFREQ_RETRY;
2903 case FSF_ADAPTER_STATUS_AVAILABLE:
2904 switch (header->fsf_status_qual.word[0]) {
2905 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2906 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2908 /* This will now be escalated by ERP */
2909 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2911 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2912 /* ERP strategy will escalate */
2913 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2915 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2919 ("bug: Wrong status qualifier 0x%x arrived.\n",
2920 header->fsf_status_qual.word[0]);
2921 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2924 fsf_req->adapter->erp_dbf, 0,
2925 &header->fsf_status_qual.word[0], sizeof (u32));
2931 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2932 "physically closed, port handle 0x%x\n",
2934 zfcp_get_busid_by_port(port), port->handle);
2935 /* can't use generic zfcp_erp_modify_port_status because
2936 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2938 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2939 list_for_each_entry(unit, &port->unit_list_head, list)
2940 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2945 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2946 "(debug info 0x%x)\n",
2947 header->fsf_status);
2948 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2949 debug_exception(fsf_req->adapter->erp_dbf, 0,
2950 &header->fsf_status, sizeof (u32));
2955 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2960 * function: zfcp_fsf_open_unit
2966 * assumptions: This routine does not check whether the associated
2967 * remote port has already been opened. This should be
2968 * done by calling routines. Otherwise some status
2969 * may be presented by FSF
2972 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2974 volatile struct qdio_buffer_element *sbale;
2975 unsigned long lock_flags;
2978 /* setup new FSF request */
2979 retval = zfcp_fsf_req_create(erp_action->adapter,
2981 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2982 erp_action->adapter->pool.fsf_req_erp,
2983 &lock_flags, &(erp_action->fsf_req));
2985 ZFCP_LOG_INFO("error: Could not create open unit request for "
2986 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2987 erp_action->unit->fcp_lun,
2988 erp_action->unit->port->wwpn,
2989 zfcp_get_busid_by_adapter(erp_action->adapter));
2993 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2994 erp_action->fsf_req->sbal_curr, 0);
2995 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2996 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2998 erp_action->fsf_req->qtcb->header.port_handle =
2999 erp_action->port->handle;
3000 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
3001 erp_action->unit->fcp_lun;
3002 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
3003 erp_action->fsf_req->qtcb->bottom.support.option =
3004 FSF_OPEN_LUN_SUPPRESS_BOXING;
3005 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
3006 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3007 erp_action->fsf_req->erp_action = erp_action;
3009 /* start QDIO request for this FSF request */
3010 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3012 ZFCP_LOG_INFO("error: Could not send an open unit request "
3013 "on the adapter %s, port 0x%016Lx for "
3015 zfcp_get_busid_by_adapter(erp_action->adapter),
3016 erp_action->port->wwpn,
3017 erp_action->unit->fcp_lun);
3018 zfcp_fsf_req_free(erp_action->fsf_req);
3019 erp_action->fsf_req = NULL;
3023 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3024 "port 0x%016Lx, unit 0x%016Lx)\n",
3025 zfcp_get_busid_by_adapter(erp_action->adapter),
3026 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3028 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3034 * function: zfcp_fsf_open_unit_handler
3036 * purpose: is called for finished Open LUN command
3041 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3043 int retval = -EINVAL;
3044 struct zfcp_adapter *adapter;
3045 struct zfcp_unit *unit;
3046 struct fsf_qtcb_header *header;
3047 struct fsf_qtcb_bottom_support *bottom;
3048 struct fsf_queue_designator *queue_designator;
3049 u16 subtable, rule, counter;
3050 int exclusive, readwrite;
3052 unit = (struct zfcp_unit *) fsf_req->data;
3054 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3055 /* don't change unit status in our bookkeeping */
3056 goto skip_fsfstatus;
3059 adapter = fsf_req->adapter;
3060 header = &fsf_req->qtcb->header;
3061 bottom = &fsf_req->qtcb->bottom.support;
3062 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3064 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3065 ZFCP_STATUS_UNIT_SHARED |
3066 ZFCP_STATUS_UNIT_READONLY,
3069 /* evaluate FSF status in QTCB */
3070 switch (header->fsf_status) {
3072 case FSF_PORT_HANDLE_NOT_VALID:
3073 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3074 "for port 0x%016Lx on adapter %s invalid "
3075 "This may happen occasionally\n",
3077 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3078 ZFCP_LOG_DEBUG("status qualifier:\n");
3079 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3080 (char *) &header->fsf_status_qual,
3081 sizeof (union fsf_status_qual));
3082 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3083 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3084 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3087 case FSF_LUN_ALREADY_OPEN:
3088 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3089 "remote port 0x%016Lx on adapter %s twice.\n",
3091 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3092 debug_text_exception(adapter->erp_dbf, 0,
3094 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3097 case FSF_ACCESS_DENIED:
3098 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3099 "remote port 0x%016Lx on adapter %s\n",
3100 unit->fcp_lun, unit->port->wwpn,
3101 zfcp_get_busid_by_unit(unit));
3102 for (counter = 0; counter < 2; counter++) {
3103 subtable = header->fsf_status_qual.halfword[counter * 2];
3104 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3106 case FSF_SQ_CFDC_SUBTABLE_OS:
3107 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3108 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3109 case FSF_SQ_CFDC_SUBTABLE_LUN:
3110 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3111 zfcp_act_subtable_type[subtable], rule);
3115 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3116 zfcp_erp_unit_access_denied(unit);
3117 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3118 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3119 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3122 case FSF_PORT_BOXED:
3123 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3124 "needs to be reopened\n",
3125 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3126 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3127 zfcp_erp_port_boxed(unit->port);
3128 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3129 ZFCP_STATUS_FSFREQ_RETRY;
3132 case FSF_LUN_SHARING_VIOLATION:
3133 if (header->fsf_status_qual.word[0] != 0) {
3134 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3136 "connected to the adapter %s "
3137 "is already in use in LPAR%d, CSS%d\n",
3140 zfcp_get_busid_by_unit(unit),
3141 queue_designator->hla,
3142 queue_designator->cssid);
3144 subtable = header->fsf_status_qual.halfword[4];
3145 rule = header->fsf_status_qual.halfword[5];
3147 case FSF_SQ_CFDC_SUBTABLE_OS:
3148 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3149 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3150 case FSF_SQ_CFDC_SUBTABLE_LUN:
3151 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3152 "remote port with WWPN 0x%Lx "
3153 "connected to the adapter %s "
3154 "is denied (%s rule %d)\n",
3157 zfcp_get_busid_by_unit(unit),
3158 zfcp_act_subtable_type[subtable],
3163 ZFCP_LOG_DEBUG("status qualifier:\n");
3164 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3165 (char *) &header->fsf_status_qual,
3166 sizeof (union fsf_status_qual));
3167 debug_text_event(adapter->erp_dbf, 2,
3169 zfcp_erp_unit_access_denied(unit);
3170 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3171 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3172 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3175 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3176 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3177 "There is no handle (temporary port identifier) "
3178 "available for unit 0x%016Lx on port 0x%016Lx "
3182 zfcp_get_busid_by_unit(unit));
3183 debug_text_event(adapter->erp_dbf, 1,
3185 zfcp_erp_unit_failed(unit);
3186 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3189 case FSF_ADAPTER_STATUS_AVAILABLE:
3190 switch (header->fsf_status_qual.word[0]) {
3191 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3192 /* Re-establish link to port */
3193 debug_text_event(adapter->erp_dbf, 1,
3195 zfcp_test_link(unit->port);
3196 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3198 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3199 /* ERP strategy will escalate */
3200 debug_text_event(adapter->erp_dbf, 1,
3202 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3206 ("bug: Wrong status qualifier 0x%x arrived.\n",
3207 header->fsf_status_qual.word[0]);
3208 debug_text_event(adapter->erp_dbf, 0,
3210 debug_exception(adapter->erp_dbf, 0,
3211 &header->fsf_status_qual.word[0],
3216 case FSF_INVALID_COMMAND_OPTION:
3218 "Invalid option 0x%x has been specified "
3219 "in QTCB bottom sent to the adapter %s\n",
3221 zfcp_get_busid_by_adapter(adapter));
3222 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3227 /* save LUN handle assigned by FSF */
3228 unit->handle = header->lun_handle;
3229 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3230 "adapter %s opened, port handle 0x%x\n",
3233 zfcp_get_busid_by_unit(unit),
3235 /* mark unit as open */
3236 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3238 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3239 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3240 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3241 exclusive = (bottom->lun_access_info &
3242 FSF_UNIT_ACCESS_EXCLUSIVE);
3243 readwrite = (bottom->lun_access_info &
3244 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3247 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3251 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3253 ZFCP_LOG_NORMAL("read-only access for unit "
3254 "(adapter %s, wwpn=0x%016Lx, "
3255 "fcp_lun=0x%016Lx)\n",
3256 zfcp_get_busid_by_unit(unit),
3261 if (exclusive && !readwrite) {
3262 ZFCP_LOG_NORMAL("exclusive access of read-only "
3263 "unit not supported\n");
3264 zfcp_erp_unit_failed(unit);
3265 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3266 zfcp_erp_unit_shutdown(unit, 0);
3267 } else if (!exclusive && readwrite) {
3268 ZFCP_LOG_NORMAL("shared access of read-write "
3269 "unit not supported\n");
3270 zfcp_erp_unit_failed(unit);
3271 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3272 zfcp_erp_unit_shutdown(unit, 0);
3280 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3281 "(debug info 0x%x)\n",
3282 header->fsf_status);
3283 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3284 debug_exception(adapter->erp_dbf, 0,
3285 &header->fsf_status, sizeof (u32));
3290 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3295 * function: zfcp_fsf_close_unit
3299 * returns: address of fsf_req - request successfully initiated
3302 * assumptions: This routine does not check whether the associated
3303 * remote port/lun has already been opened. This should be
3304 * done by calling routines. Otherwise some status
3305 * may be presented by FSF
3308 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3310 volatile struct qdio_buffer_element *sbale;
3311 unsigned long lock_flags;
3314 /* setup new FSF request */
3315 retval = zfcp_fsf_req_create(erp_action->adapter,
3317 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3318 erp_action->adapter->pool.fsf_req_erp,
3319 &lock_flags, &(erp_action->fsf_req));
3321 ZFCP_LOG_INFO("error: Could not create close unit request for "
3322 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3323 erp_action->unit->fcp_lun,
3324 erp_action->port->wwpn,
3325 zfcp_get_busid_by_adapter(erp_action->adapter));
3329 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3330 erp_action->fsf_req->sbal_curr, 0);
3331 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3332 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3334 erp_action->fsf_req->qtcb->header.port_handle =
3335 erp_action->port->handle;
3336 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3337 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3338 erp_action->fsf_req->data = (unsigned long) erp_action->unit;
3339 erp_action->fsf_req->erp_action = erp_action;
3341 /* start QDIO request for this FSF request */
3342 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3344 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3345 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3346 erp_action->unit->fcp_lun,
3347 erp_action->port->wwpn,
3348 zfcp_get_busid_by_adapter(erp_action->adapter));
3349 zfcp_fsf_req_free(erp_action->fsf_req);
3350 erp_action->fsf_req = NULL;
3354 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3355 "port 0x%016Lx, unit 0x%016Lx)\n",
3356 zfcp_get_busid_by_adapter(erp_action->adapter),
3357 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3359 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3365 * function: zfcp_fsf_close_unit_handler
3367 * purpose: is called for finished Close LUN FSF command
3372 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3374 int retval = -EINVAL;
3375 struct zfcp_unit *unit;
3377 unit = (struct zfcp_unit *) fsf_req->data;
3379 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3380 /* don't change unit status in our bookkeeping */
3381 goto skip_fsfstatus;
3384 /* evaluate FSF status in QTCB */
3385 switch (fsf_req->qtcb->header.fsf_status) {
3387 case FSF_PORT_HANDLE_NOT_VALID:
3388 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3389 "0x%016Lx on adapter %s invalid. This may "
3390 "happen in rare circumstances\n",
3393 zfcp_get_busid_by_unit(unit));
3394 ZFCP_LOG_DEBUG("status qualifier:\n");
3395 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3396 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3397 sizeof (union fsf_status_qual));
3398 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3400 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3401 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3404 case FSF_LUN_HANDLE_NOT_VALID:
3405 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3406 "0x%016Lx on port 0x%016Lx on adapter %s is "
3407 "invalid. This may happen occasionally.\n",
3411 zfcp_get_busid_by_unit(unit));
3412 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3413 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3414 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3415 sizeof (union fsf_status_qual));
3416 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3418 zfcp_erp_port_reopen(unit->port, 0);
3419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3422 case FSF_PORT_BOXED:
3423 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3424 "needs to be reopened\n",
3426 zfcp_get_busid_by_unit(unit));
3427 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3428 zfcp_erp_port_boxed(unit->port);
3429 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3430 ZFCP_STATUS_FSFREQ_RETRY;
3433 case FSF_ADAPTER_STATUS_AVAILABLE:
3434 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3435 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3436 /* re-establish link to port */
3437 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3439 zfcp_test_link(unit->port);
3440 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3442 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3443 /* ERP strategy will escalate */
3444 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3446 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3450 ("bug: Wrong status qualifier 0x%x arrived.\n",
3451 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3452 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3455 fsf_req->adapter->erp_dbf, 0,
3456 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3463 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3464 "closed, port handle 0x%x\n",
3467 zfcp_get_busid_by_unit(unit),
3469 /* mark unit as closed */
3470 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3475 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3476 "(debug info 0x%x)\n",
3477 fsf_req->qtcb->header.fsf_status);
3478 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3479 debug_exception(fsf_req->adapter->erp_dbf, 0,
3480 &fsf_req->qtcb->header.fsf_status,
3486 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3491 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3492 * @adapter: adapter where scsi command is issued
3493 * @unit: unit where command is sent to
3494 * @scsi_cmnd: scsi command to be sent
3495 * @timer: timer to be started when request is initiated
3496 * @req_flags: flags for fsf_request
3499 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3500 struct zfcp_unit *unit,
3501 struct scsi_cmnd * scsi_cmnd,
3502 struct timer_list *timer, int req_flags)
3504 struct zfcp_fsf_req *fsf_req = NULL;
3505 struct fcp_cmnd_iu *fcp_cmnd_iu;
3506 unsigned int sbtype;
3507 unsigned long lock_flags;
3512 /* setup new FSF request */
3513 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3514 adapter->pool.fsf_req_scsi,
3515 &lock_flags, &fsf_req);
3516 if (unlikely(retval < 0)) {
3517 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3518 "for unit 0x%016Lx on port 0x%016Lx on "
3522 zfcp_get_busid_by_adapter(adapter));
3523 goto failed_req_create;
3526 zfcp_unit_get(unit);
3527 fsf_req->unit = unit;
3529 /* associate FSF request with SCSI request (for look up on abort) */
3530 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3532 /* associate SCSI command with FSF request */
3533 fsf_req->data = (unsigned long) scsi_cmnd;
3535 /* set handles of unit and its parent port in QTCB */
3536 fsf_req->qtcb->header.lun_handle = unit->handle;
3537 fsf_req->qtcb->header.port_handle = unit->port->handle;
3539 /* FSF does not define the structure of the FCP_CMND IU */
3540 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3541 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3544 * set depending on data direction:
3545 * data direction bits in SBALE (SB Type)
3546 * data direction bits in QTCB
3547 * data direction bits in FCP_CMND IU
3549 switch (scsi_cmnd->sc_data_direction) {
3551 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3554 * what is the correct type for commands
3555 * without 'real' data buffers?
3557 sbtype = SBAL_FLAGS0_TYPE_READ;
3559 case DMA_FROM_DEVICE:
3560 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3561 sbtype = SBAL_FLAGS0_TYPE_READ;
3562 fcp_cmnd_iu->rddata = 1;
3565 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3566 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3567 fcp_cmnd_iu->wddata = 1;
3569 case DMA_BIDIRECTIONAL:
3572 * dummy, catch this condition earlier
3573 * in zfcp_scsi_queuecommand
3575 goto failed_scsi_cmnd;
3578 /* set FC service class in QTCB (3 per default) */
3579 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3581 /* set FCP_LUN in FCP_CMND IU in QTCB */
3582 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3584 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3586 /* set task attributes in FCP_CMND IU in QTCB */
3587 if (likely((scsi_cmnd->device->simple_tags) ||
3588 (atomic_test_mask(mask, &unit->status))))
3589 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3591 fcp_cmnd_iu->task_attribute = UNTAGGED;
3593 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3594 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3595 fcp_cmnd_iu->add_fcp_cdb_length
3596 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3597 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3598 "additional FCP_CDB length is 0x%x "
3599 "(shifted right 2 bits)\n",
3601 fcp_cmnd_iu->add_fcp_cdb_length);
3604 * copy SCSI CDB (including additional length, if any) to
3605 * FCP_CDB in FCP_CMND IU in QTCB
3607 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3609 /* FCP CMND IU length in QTCB */
3610 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3611 sizeof (struct fcp_cmnd_iu) +
3612 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3614 /* generate SBALEs from data buffer */
3615 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3616 if (unlikely(real_bytes < 0)) {
3617 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3619 "Data did not fit into available buffer(s), "
3620 "waiting for more...\n");
3623 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3624 "required. Shutting down unit "
3625 "(adapter %s, port 0x%016Lx, "
3627 zfcp_get_busid_by_unit(unit),
3630 zfcp_erp_unit_shutdown(unit, 0);
3636 /* set length of FCP data length in FCP_CMND IU in QTCB */
3637 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3639 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3640 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3641 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3644 * start QDIO request for this FSF request
3645 * covered by an SBALE)
3647 retval = zfcp_fsf_req_send(fsf_req, timer);
3648 if (unlikely(retval < 0)) {
3649 ZFCP_LOG_INFO("error: Could not send FCP command request "
3650 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3651 zfcp_get_busid_by_adapter(adapter),
3657 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3658 "port 0x%016Lx, unit 0x%016Lx)\n",
3659 zfcp_get_busid_by_adapter(adapter),
3667 zfcp_unit_put(unit);
3668 zfcp_fsf_req_free(fsf_req);
3670 scsi_cmnd->host_scribble = NULL;
3673 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3677 struct zfcp_fsf_req *
3678 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3679 struct zfcp_unit *unit,
3680 u8 tm_flags, int req_flags)
3682 struct zfcp_fsf_req *fsf_req = NULL;
3684 struct fcp_cmnd_iu *fcp_cmnd_iu;
3685 unsigned long lock_flags;
3686 volatile struct qdio_buffer_element *sbale;
3688 /* setup new FSF request */
3689 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3690 adapter->pool.fsf_req_scsi,
3691 &lock_flags, &fsf_req);
3693 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3694 "management) request for adapter %s, port "
3695 " 0x%016Lx, unit 0x%016Lx.\n",
3696 zfcp_get_busid_by_adapter(adapter),
3697 unit->port->wwpn, unit->fcp_lun);
3702 * Used to decide on proper handler in the return path,
3703 * could be either zfcp_fsf_send_fcp_command_task_handler or
3704 * zfcp_fsf_send_fcp_command_task_management_handler */
3706 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3709 * hold a pointer to the unit being target of this
3710 * task management request
3712 fsf_req->data = (unsigned long) unit;
3714 /* set FSF related fields in QTCB */
3715 fsf_req->qtcb->header.lun_handle = unit->handle;
3716 fsf_req->qtcb->header.port_handle = unit->port->handle;
3717 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3718 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3719 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3720 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3722 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3723 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3724 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3726 /* set FCP related fields in FCP_CMND IU in QTCB */
3727 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3728 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3729 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3730 fcp_cmnd_iu->task_management_flags = tm_flags;
3732 /* start QDIO request for this FSF request */
3733 zfcp_fsf_start_scsi_er_timer(adapter);
3734 retval = zfcp_fsf_req_send(fsf_req, NULL);
3736 del_timer(&adapter->scsi_er_timer);
3737 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3738 "management) on adapter %s, port 0x%016Lx for "
3739 "unit LUN 0x%016Lx\n",
3740 zfcp_get_busid_by_adapter(adapter),
3743 zfcp_fsf_req_free(fsf_req);
3748 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3749 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3751 zfcp_get_busid_by_adapter(adapter),
3756 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3761 * function: zfcp_fsf_send_fcp_command_handler
3763 * purpose: is called for finished Send FCP Command
3768 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3770 int retval = -EINVAL;
3771 struct zfcp_unit *unit;
3772 struct fsf_qtcb_header *header;
3773 u16 subtable, rule, counter;
3775 header = &fsf_req->qtcb->header;
3777 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3778 unit = (struct zfcp_unit *) fsf_req->data;
3780 unit = fsf_req->unit;
3782 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3783 /* go directly to calls of special handlers */
3784 goto skip_fsfstatus;
3787 /* evaluate FSF status in QTCB */
3788 switch (header->fsf_status) {
3790 case FSF_PORT_HANDLE_NOT_VALID:
3791 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3792 "0x%016Lx on adapter %s invalid\n",
3794 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3795 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3796 (char *) &header->fsf_status_qual,
3797 sizeof (union fsf_status_qual));
3798 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3800 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3801 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3804 case FSF_LUN_HANDLE_NOT_VALID:
3805 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3806 "0x%016Lx on port 0x%016Lx on adapter %s is "
3807 "invalid. This may happen occasionally.\n",
3811 zfcp_get_busid_by_unit(unit));
3812 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3813 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3814 (char *) &header->fsf_status_qual,
3815 sizeof (union fsf_status_qual));
3816 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3818 zfcp_erp_port_reopen(unit->port, 0);
3819 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3822 case FSF_HANDLE_MISMATCH:
3823 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3824 "unexpectedly. (adapter %s, port 0x%016Lx, "
3827 zfcp_get_busid_by_unit(unit),
3830 ZFCP_LOG_NORMAL("status qualifier:\n");
3831 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3832 (char *) &header->fsf_status_qual,
3833 sizeof (union fsf_status_qual));
3834 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3836 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3837 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3840 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3841 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3843 zfcp_get_busid_by_unit(unit),
3844 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3845 /* stop operation for this adapter */
3846 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3847 "fsf_s_class_nsup");
3848 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3849 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3852 case FSF_FCPLUN_NOT_VALID:
3853 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3854 "adapter %s does not have correct unit "
3858 zfcp_get_busid_by_unit(unit),
3860 ZFCP_LOG_DEBUG("status qualifier:\n");
3861 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3862 (char *) &header->fsf_status_qual,
3863 sizeof (union fsf_status_qual));
3864 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3865 "fsf_s_fcp_lun_nv");
3866 zfcp_erp_port_reopen(unit->port, 0);
3867 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3870 case FSF_ACCESS_DENIED:
3871 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3872 "unit 0x%016Lx on port 0x%016Lx on "
3873 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3874 zfcp_get_busid_by_unit(unit));
3875 for (counter = 0; counter < 2; counter++) {
3876 subtable = header->fsf_status_qual.halfword[counter * 2];
3877 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3879 case FSF_SQ_CFDC_SUBTABLE_OS:
3880 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3881 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3882 case FSF_SQ_CFDC_SUBTABLE_LUN:
3883 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3884 zfcp_act_subtable_type[subtable], rule);
3888 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3889 zfcp_erp_unit_access_denied(unit);
3890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3893 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3894 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3895 "0x%016Lx on port 0x%016Lx on adapter %s "
3896 "(debug info %d)\n",
3899 zfcp_get_busid_by_unit(unit),
3900 fsf_req->qtcb->bottom.io.data_direction);
3901 /* stop operation for this adapter */
3902 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3903 "fsf_s_dir_ind_nv");
3904 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3905 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3908 case FSF_CMND_LENGTH_NOT_VALID:
3910 ("bug: An invalid control-data-block length field "
3911 "was found in a command for unit 0x%016Lx on port "
3912 "0x%016Lx on adapter %s " "(debug info %d)\n",
3913 unit->fcp_lun, unit->port->wwpn,
3914 zfcp_get_busid_by_unit(unit),
3915 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3916 /* stop operation for this adapter */
3917 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3918 "fsf_s_cmd_len_nv");
3919 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3920 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3923 case FSF_PORT_BOXED:
3924 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3925 "needs to be reopened\n",
3926 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3927 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3928 zfcp_erp_port_boxed(unit->port);
3929 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3930 ZFCP_STATUS_FSFREQ_RETRY;
3934 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3935 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3936 zfcp_get_busid_by_unit(unit),
3937 unit->port->wwpn, unit->fcp_lun);
3938 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3939 zfcp_erp_unit_boxed(unit);
3940 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3941 | ZFCP_STATUS_FSFREQ_RETRY;
3944 case FSF_ADAPTER_STATUS_AVAILABLE:
3945 switch (header->fsf_status_qual.word[0]) {
3946 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3947 /* re-establish link to port */
3948 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3950 zfcp_test_link(unit->port);
3952 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3953 /* FIXME(hw) need proper specs for proper action */
3954 /* let scsi stack deal with retries and escalation */
3955 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3960 ("Unknown status qualifier 0x%x arrived.\n",
3961 header->fsf_status_qual.word[0]);
3962 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3964 debug_exception(fsf_req->adapter->erp_dbf, 0,
3965 &header->fsf_status_qual.word[0],
3969 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3975 case FSF_FCP_RSP_AVAILABLE:
3979 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3980 debug_exception(fsf_req->adapter->erp_dbf, 0,
3981 &header->fsf_status, sizeof(u32));
3986 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3988 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3990 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3991 fsf_req->unit = NULL;
3992 zfcp_unit_put(unit);
3998 * function: zfcp_fsf_send_fcp_command_task_handler
4000 * purpose: evaluates FCP_RSP IU
4005 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4008 struct scsi_cmnd *scpnt;
4009 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4010 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4011 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4012 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4014 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4015 unsigned long flags;
4016 struct zfcp_unit *unit = fsf_req->unit;
4018 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4019 scpnt = (struct scsi_cmnd *) fsf_req->data;
4020 if (unlikely(!scpnt)) {
4022 ("Command with fsf_req %p is not associated to "
4023 "a scsi command anymore. Aborted?\n", fsf_req);
4026 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4027 /* FIXME: (design) mid-layer should handle DID_ABORT like
4028 * DID_SOFT_ERROR by retrying the request for devices
4029 * that allow retries.
4031 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4032 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4033 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4034 goto skip_fsfstatus;
4037 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4038 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4039 set_host_byte(&scpnt->result, DID_ERROR);
4040 goto skip_fsfstatus;
4043 /* set message byte of result in SCSI command */
4044 scpnt->result |= COMMAND_COMPLETE << 8;
4047 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4048 * of result in SCSI command
4050 scpnt->result |= fcp_rsp_iu->scsi_status;
4051 if (unlikely(fcp_rsp_iu->scsi_status)) {
4053 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4054 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4055 scpnt->cmnd, scpnt->cmd_len);
4056 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4057 fcp_rsp_iu->scsi_status);
4058 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4059 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4060 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4061 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4062 fcp_rsp_iu->fcp_sns_len);
4065 /* check FCP_RSP_INFO */
4066 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4067 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4068 switch (fcp_rsp_info[3]) {
4071 ZFCP_LOG_TRACE("no failure or Task Management "
4072 "Function complete\n");
4073 set_host_byte(&scpnt->result, DID_OK);
4075 case RSP_CODE_LENGTH_MISMATCH:
4077 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4078 "that the fibrechannel protocol data "
4079 "length differs from the burst length. "
4080 "The problem occured on unit 0x%016Lx "
4081 "on port 0x%016Lx on adapter %s",
4084 zfcp_get_busid_by_unit(unit));
4085 /* dump SCSI CDB as prepared by zfcp */
4086 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4087 (char *) &fsf_req->qtcb->
4088 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4089 set_host_byte(&scpnt->result, DID_ERROR);
4090 goto skip_fsfstatus;
4091 case RSP_CODE_FIELD_INVALID:
4092 /* driver or hardware bug */
4093 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4094 "that the fibrechannel protocol data "
4095 "fields were incorrectly set up. "
4096 "The problem occured on the unit "
4097 "0x%016Lx on port 0x%016Lx on "
4101 zfcp_get_busid_by_unit(unit));
4102 /* dump SCSI CDB as prepared by zfcp */
4103 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4104 (char *) &fsf_req->qtcb->
4105 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4106 set_host_byte(&scpnt->result, DID_ERROR);
4107 goto skip_fsfstatus;
4108 case RSP_CODE_RO_MISMATCH:
4110 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4111 "that conflicting values for the "
4112 "fibrechannel payload offset from the "
4113 "header were found. "
4114 "The problem occured on unit 0x%016Lx "
4115 "on port 0x%016Lx on adapter %s.\n",
4118 zfcp_get_busid_by_unit(unit));
4119 /* dump SCSI CDB as prepared by zfcp */
4120 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4121 (char *) &fsf_req->qtcb->
4122 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4123 set_host_byte(&scpnt->result, DID_ERROR);
4124 goto skip_fsfstatus;
4126 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4127 "code was detected for a command. "
4128 "The problem occured on the unit "
4129 "0x%016Lx on port 0x%016Lx on "
4130 "adapter %s (debug info 0x%x)\n",
4133 zfcp_get_busid_by_unit(unit),
4135 /* dump SCSI CDB as prepared by zfcp */
4136 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4137 (char *) &fsf_req->qtcb->
4138 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4139 set_host_byte(&scpnt->result, DID_ERROR);
4140 goto skip_fsfstatus;
4144 /* check for sense data */
4145 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4146 sns_len = FSF_FCP_RSP_SIZE -
4147 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4148 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4150 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4151 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4152 SCSI_SENSE_BUFFERSIZE);
4153 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4154 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4156 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4157 (void *) &scpnt->cmnd, scpnt->cmd_len);
4159 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4160 fcp_rsp_iu->fcp_sns_len);
4161 memcpy(&scpnt->sense_buffer,
4162 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4163 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4164 (void *) &scpnt->sense_buffer, sns_len);
4167 /* check for overrun */
4168 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4169 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4170 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4171 "The response data length is "
4172 "%d, the original length was %d.\n",
4175 zfcp_get_busid_by_unit(unit),
4176 fcp_rsp_iu->fcp_resid,
4177 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4180 /* check for underrun */
4181 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4182 ZFCP_LOG_INFO("A data underrun 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));
4192 scpnt->resid = fcp_rsp_iu->fcp_resid;
4193 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4194 set_host_byte(&scpnt->result, DID_ERROR);
4198 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4200 if (scpnt->result != 0)
4201 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4202 else if (scpnt->retries > 0)
4203 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4205 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4207 /* cleanup pointer (need this especially for abort) */
4208 scpnt->host_scribble = NULL;
4210 /* always call back */
4211 (scpnt->scsi_done) (scpnt);
4214 * We must hold this lock until scsi_done has been called.
4215 * Otherwise we may call scsi_done after abort regarding this
4216 * command has completed.
4217 * Note: scsi_done must not block!
4220 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4225 * function: zfcp_fsf_send_fcp_command_task_management_handler
4227 * purpose: evaluates FCP_RSP IU
4232 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4235 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4236 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4237 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4238 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4240 del_timer(&fsf_req->adapter->scsi_er_timer);
4241 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4242 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4243 goto skip_fsfstatus;
4246 /* check FCP_RSP_INFO */
4247 switch (fcp_rsp_info[3]) {
4250 ZFCP_LOG_DEBUG("no failure or Task Management "
4251 "Function complete\n");
4253 case RSP_CODE_TASKMAN_UNSUPP:
4254 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4255 "is not supported on the target device "
4256 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4259 zfcp_get_busid_by_unit(unit));
4260 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4262 case RSP_CODE_TASKMAN_FAILED:
4263 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4264 "failed to complete successfully. "
4265 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4268 zfcp_get_busid_by_unit(unit));
4269 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4272 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4273 "code was detected for a command. "
4274 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4275 "(debug info 0x%x)\n",
4278 zfcp_get_busid_by_unit(unit),
4280 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4289 * function: zfcp_fsf_control_file
4291 * purpose: Initiator of the control file upload/download FSF requests
4293 * returns: 0 - FSF request is successfuly created and queued
4294 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4295 * -EINVAL - Invalid direction specified
4296 * -ENOMEM - Insufficient memory
4297 * -EPERM - Cannot create FSF request or place it in QDIO queue
4300 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4301 struct zfcp_fsf_req **fsf_req_ptr,
4304 struct zfcp_sg_list *sg_list)
4306 struct zfcp_fsf_req *fsf_req;
4307 struct fsf_qtcb_bottom_support *bottom;
4308 volatile struct qdio_buffer_element *sbale;
4309 struct timer_list *timer;
4310 unsigned long lock_flags;
4315 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4316 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4317 zfcp_get_busid_by_adapter(adapter));
4318 retval = -EOPNOTSUPP;
4322 switch (fsf_command) {
4324 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4325 direction = SBAL_FLAGS0_TYPE_WRITE;
4326 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4327 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4328 req_flags = ZFCP_WAIT_FOR_SBAL;
4331 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4332 direction = SBAL_FLAGS0_TYPE_READ;
4336 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4341 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4347 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4348 NULL, &lock_flags, &fsf_req);
4350 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4352 zfcp_get_busid_by_adapter(adapter));
4354 goto unlock_queue_lock;
4357 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4358 sbale[0].flags |= direction;
4360 bottom = &fsf_req->qtcb->bottom.support;
4361 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4362 bottom->option = option;
4364 if (sg_list->count > 0) {
4367 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4368 sg_list->sg, sg_list->count,
4369 ZFCP_MAX_SBALS_PER_REQ);
4370 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4372 "error: Could not create sufficient number of "
4373 "SBALS for an FSF request to the adapter %s\n",
4374 zfcp_get_busid_by_adapter(adapter));
4379 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4382 timer->function = zfcp_fsf_request_timeout_handler;
4383 timer->data = (unsigned long) adapter;
4384 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4386 retval = zfcp_fsf_req_send(fsf_req, timer);
4388 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4390 zfcp_get_busid_by_adapter(adapter));
4394 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4396 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4398 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4399 "download" : "upload",
4400 zfcp_get_busid_by_adapter(adapter));
4402 wait_event(fsf_req->completion_wq,
4403 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4405 *fsf_req_ptr = fsf_req;
4406 del_timer_sync(timer);
4410 zfcp_fsf_req_free(fsf_req);
4412 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4421 * function: zfcp_fsf_control_file_handler
4423 * purpose: Handler of the control file upload/download FSF requests
4425 * returns: 0 - FSF request successfuly processed
4426 * -EAGAIN - Operation has to be repeated because of a temporary problem
4427 * -EACCES - There is no permission to execute an operation
4428 * -EPERM - The control file is not in a right format
4429 * -EIO - There is a problem with the FCP adapter
4430 * -EINVAL - Invalid operation
4431 * -EFAULT - User space memory I/O operation fault
4434 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4436 struct zfcp_adapter *adapter = fsf_req->adapter;
4437 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4438 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4441 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4443 goto skip_fsfstatus;
4446 switch (header->fsf_status) {
4450 "The FSF request has been successfully completed "
4451 "on the adapter %s\n",
4452 zfcp_get_busid_by_adapter(adapter));
4455 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4456 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4457 switch (header->fsf_status_qual.word[0]) {
4459 case FSF_SQ_CFDC_HARDENED_ON_SE:
4461 "CFDC on the adapter %s has being "
4462 "hardened on primary and secondary SE\n",
4463 zfcp_get_busid_by_adapter(adapter));
4466 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4468 "CFDC of the adapter %s could not "
4469 "be saved on the SE\n",
4470 zfcp_get_busid_by_adapter(adapter));
4473 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4475 "CFDC of the adapter %s could not "
4476 "be copied to the secondary SE\n",
4477 zfcp_get_busid_by_adapter(adapter));
4482 "CFDC could not be hardened "
4483 "on the adapter %s\n",
4484 zfcp_get_busid_by_adapter(adapter));
4487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4491 case FSF_AUTHORIZATION_FAILURE:
4493 "Adapter %s does not accept privileged commands\n",
4494 zfcp_get_busid_by_adapter(adapter));
4495 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4499 case FSF_CFDC_ERROR_DETECTED:
4501 "Error at position %d in the CFDC, "
4502 "CFDC is discarded by the adapter %s\n",
4503 header->fsf_status_qual.word[0],
4504 zfcp_get_busid_by_adapter(adapter));
4505 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4509 case FSF_CONTROL_FILE_UPDATE_ERROR:
4511 "Adapter %s cannot harden the control file, "
4512 "file is discarded\n",
4513 zfcp_get_busid_by_adapter(adapter));
4514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4518 case FSF_CONTROL_FILE_TOO_LARGE:
4520 "Control file is too large, file is discarded "
4521 "by the adapter %s\n",
4522 zfcp_get_busid_by_adapter(adapter));
4523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4527 case FSF_ACCESS_CONFLICT_DETECTED:
4528 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4530 "CFDC has been discarded by the adapter %s, "
4531 "because activation would impact "
4532 "%d active connection(s)\n",
4533 zfcp_get_busid_by_adapter(adapter),
4534 header->fsf_status_qual.word[0]);
4535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4539 case FSF_CONFLICTS_OVERRULED:
4540 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4542 "CFDC has been activated on the adapter %s, "
4543 "but activation has impacted "
4544 "%d active connection(s)\n",
4545 zfcp_get_busid_by_adapter(adapter),
4546 header->fsf_status_qual.word[0]);
4547 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4551 case FSF_UNKNOWN_OP_SUBTYPE:
4552 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4553 "op_subtype=0x%x)\n",
4554 zfcp_get_busid_by_adapter(adapter),
4555 bottom->operation_subtype);
4556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4560 case FSF_INVALID_COMMAND_OPTION:
4562 "Invalid option 0x%x has been specified "
4563 "in QTCB bottom sent to the adapter %s\n",
4565 zfcp_get_busid_by_adapter(adapter));
4566 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4572 "bug: An unknown/unexpected FSF status 0x%08x "
4573 "was presented on the adapter %s\n",
4575 zfcp_get_busid_by_adapter(adapter));
4576 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4577 debug_exception(fsf_req->adapter->erp_dbf, 0,
4578 &header->fsf_status_qual.word[0], sizeof(u32));
4579 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4589 zfcp_fsf_req_sbal_check(unsigned long *flags,
4590 struct zfcp_qdio_queue *queue, int needed)
4592 write_lock_irqsave(&queue->queue_lock, *flags);
4593 if (likely(atomic_read(&queue->free_count) >= needed))
4595 write_unlock_irqrestore(&queue->queue_lock, *flags);
4600 * set qtcb pointer in fsf_req and initialize QTCB
4603 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4605 if (likely(fsf_req->qtcb != NULL)) {
4606 fsf_req->qtcb->prefix.req_seq_no =
4607 fsf_req->adapter->fsf_req_seq_no;
4608 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4609 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4610 fsf_req->qtcb->prefix.qtcb_type =
4611 fsf_qtcb_type[fsf_req->fsf_command];
4612 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4613 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4614 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4619 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4620 * @adapter: adapter for which request queue is examined
4621 * @req_flags: flags indicating whether to wait for needed SBAL or not
4622 * @lock_flags: lock_flags if queue_lock is taken
4623 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4624 * Locks: lock adapter->request_queue->queue_lock on success
4627 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4628 unsigned long *lock_flags)
4631 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4633 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4634 ret = wait_event_interruptible_timeout(adapter->request_wq,
4635 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4641 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4648 * function: zfcp_fsf_req_create
4650 * purpose: create an FSF request at the specified adapter and
4651 * setup common fields
4653 * returns: -ENOMEM if there was insufficient memory for a request
4654 * -EIO if no qdio buffers could be allocate to the request
4655 * -EINVAL/-EPERM on bug conditions in req_dequeue
4658 * note: The created request is returned by reference.
4660 * locks: lock of concerned request queue must not be held,
4661 * but is held on completion (write, irqsave)
4664 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4665 mempool_t *pool, unsigned long *lock_flags,
4666 struct zfcp_fsf_req **fsf_req_p)
4668 volatile struct qdio_buffer_element *sbale;
4669 struct zfcp_fsf_req *fsf_req = NULL;
4671 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4673 /* allocate new FSF request */
4674 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4675 if (unlikely(NULL == fsf_req)) {
4676 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4677 "the outbound (send) queue.\n");
4679 goto failed_fsf_req;
4682 fsf_req->adapter = adapter;
4683 fsf_req->fsf_command = fsf_cmd;
4684 INIT_LIST_HEAD(&fsf_req->list);
4686 /* this is serialized (we are holding req_queue-lock of adapter */
4687 if (adapter->req_no == 0)
4689 fsf_req->req_id = adapter->req_no++;
4691 zfcp_fsf_req_qtcb_init(fsf_req);
4693 /* initialize waitqueue which may be used to wait on
4694 this request completion */
4695 init_waitqueue_head(&fsf_req->completion_wq);
4697 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4703 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4704 * if it is not set (see also *_open_qdio and *_close_qdio).
4707 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4708 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4713 if (fsf_req->qtcb) {
4714 fsf_req->seq_no = adapter->fsf_req_seq_no;
4715 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4717 fsf_req->sbal_number = 1;
4718 fsf_req->sbal_first = req_queue->free_index;
4719 fsf_req->sbal_curr = req_queue->free_index;
4720 fsf_req->sbale_curr = 1;
4722 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4723 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4726 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4728 /* setup common SBALE fields */
4729 sbale[0].addr = (void *) fsf_req->req_id;
4730 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4731 if (likely(fsf_req->qtcb != NULL)) {
4732 sbale[1].addr = (void *) fsf_req->qtcb;
4733 sbale[1].length = sizeof(struct fsf_qtcb);
4736 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4737 fsf_req->sbal_number, fsf_req->sbal_first);
4742 /* dequeue new FSF request previously enqueued */
4743 zfcp_fsf_req_free(fsf_req);
4747 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4749 *fsf_req_p = fsf_req;
4754 * function: zfcp_fsf_req_send
4756 * purpose: start transfer of FSF request via QDIO
4758 * returns: 0 - request transfer succesfully started
4759 * !0 - start of request transfer failed
4762 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4764 struct zfcp_adapter *adapter;
4765 struct zfcp_qdio_queue *req_queue;
4766 volatile struct qdio_buffer_element *sbale;
4768 int new_distance_from_int;
4772 adapter = fsf_req->adapter;
4773 req_queue = &adapter->request_queue,
4776 /* FIXME(debug): remove it later */
4777 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4778 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4779 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4780 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4783 /* put allocated FSF request into hash table */
4784 spin_lock(&adapter->req_list_lock);
4785 zfcp_reqlist_add(adapter, fsf_req);
4786 spin_unlock(&adapter->req_list_lock);
4788 inc_seq_no = (fsf_req->qtcb != NULL);
4790 /* figure out expiration time of timeout and start timeout */
4791 if (unlikely(timer)) {
4792 timer->expires += jiffies;
4796 ZFCP_LOG_TRACE("request queue of adapter %s: "
4797 "next free SBAL is %i, %i free SBALs\n",
4798 zfcp_get_busid_by_adapter(adapter),
4799 req_queue->free_index,
4800 atomic_read(&req_queue->free_count));
4802 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4803 "index_in_queue=%i, count=%i, buffers=%p\n",
4804 zfcp_get_busid_by_adapter(adapter),
4805 QDIO_FLAG_SYNC_OUTPUT,
4806 0, fsf_req->sbal_first, fsf_req->sbal_number,
4807 &req_queue->buffer[fsf_req->sbal_first]);
4810 * adjust the number of free SBALs in request queue as well as
4811 * position of first one
4813 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4814 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4815 req_queue->free_index += fsf_req->sbal_number; /* increase */
4816 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4817 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4819 fsf_req->issued = get_clock();
4821 retval = do_QDIO(adapter->ccw_device,
4822 QDIO_FLAG_SYNC_OUTPUT,
4823 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4825 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4826 dbg_tmp[1] = (u64) retval;
4827 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4829 if (unlikely(retval)) {
4830 /* Queues are down..... */
4833 * FIXME(potential race):
4834 * timer might be expired (absolutely unlikely)
4838 spin_lock(&adapter->req_list_lock);
4839 zfcp_reqlist_remove(adapter, fsf_req->req_id);
4840 spin_unlock(&adapter->req_list_lock);
4841 /* undo changes in request queue made for this request */
4842 zfcp_qdio_zero_sbals(req_queue->buffer,
4843 fsf_req->sbal_first, fsf_req->sbal_number);
4844 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4845 req_queue->free_index -= fsf_req->sbal_number;
4846 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4847 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4848 zfcp_erp_adapter_reopen(adapter, 0);
4850 req_queue->distance_from_int = new_distance_from_int;
4852 * increase FSF sequence counter -
4853 * this must only be done for request successfully enqueued to
4854 * QDIO this rejected requests may be cleaned up by calling
4855 * routines resulting in missing sequence counter values
4859 /* Don't increase for unsolicited status */
4861 adapter->fsf_req_seq_no++;
4863 /* count FSF requests pending */
4864 atomic_inc(&adapter->reqs_active);
4869 #undef ZFCP_LOG_AREA