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 *);
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 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
181 struct zfcp_fsf_req *request, *tmp;
183 LIST_HEAD(remove_queue);
184 unsigned int i, counter;
186 spin_lock_irqsave(&adapter->req_list_lock, flags);
187 atomic_set(&adapter->reqs_active, 0);
188 for (i=0; i<REQUEST_LIST_SIZE; i++)
189 list_splice_init(&adapter->req_list[i], &remove_queue);
191 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
194 list_for_each_entry_safe(request, tmp, &remove_queue, list) {
195 zfcp_fsf_req_dismiss(adapter, request, counter);
201 * function: zfcp_fsf_req_complete
203 * purpose: Updates active counts and timers for openfcp-reqs
204 * May cleanup request after req_eval returns
206 * returns: 0 - success
212 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
217 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
218 ZFCP_LOG_DEBUG("Status read response received\n");
220 * Note: all cleanup handling is done in the callchain of
221 * the function call-chain below.
223 zfcp_fsf_status_read_handler(fsf_req);
226 del_timer(&fsf_req->timer);
227 zfcp_fsf_protstatus_eval(fsf_req);
231 * fsf_req may be deleted due to waking up functions, so
232 * cleanup is saved here and used later
234 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
239 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
241 /* cleanup request if requested by initiator */
242 if (likely(cleanup)) {
243 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
245 * lock must not be held here since it will be
246 * grabed by the called routine, too
248 zfcp_fsf_req_free(fsf_req);
250 /* notify initiator waiting for the requests completion */
251 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
253 * FIXME: Race! We must not access fsf_req here as it might have been
254 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
255 * flag. It's an improbable case. But, we have the same paranoia for
256 * the cleanup flag already.
257 * Might better be handled using complete()?
258 * (setting the flag and doing wakeup ought to be atomic
259 * with regard to checking the flag as long as waitqueue is
260 * part of the to be released structure)
262 wake_up(&fsf_req->completion_wq);
270 * function: zfcp_fsf_protstatus_eval
272 * purpose: evaluates the QTCB of the finished FSF request
273 * and initiates appropriate actions
274 * (usually calling FSF command specific handlers)
283 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
286 struct zfcp_adapter *adapter = fsf_req->adapter;
287 struct fsf_qtcb *qtcb = fsf_req->qtcb;
288 union fsf_prot_status_qual *prot_status_qual =
289 &qtcb->prefix.prot_status_qual;
291 zfcp_hba_dbf_event_fsf_response(fsf_req);
293 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
294 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
295 (unsigned long) fsf_req);
296 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
297 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
298 goto skip_protstatus;
301 /* log additional information provided by FSF (if any) */
302 if (unlikely(qtcb->header.log_length)) {
303 /* do not trust them ;-) */
304 if (qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
306 ("bug: ULP (FSF logging) log data starts "
307 "beyond end of packet header. Ignored. "
308 "(start=%i, size=%li)\n",
309 qtcb->header.log_start,
310 sizeof(struct fsf_qtcb));
313 if ((size_t) (qtcb->header.log_start + qtcb->header.log_length)
314 > sizeof(struct fsf_qtcb)) {
315 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
316 "beyond end of packet header. Ignored. "
317 "(start=%i, length=%i, size=%li)\n",
318 qtcb->header.log_start,
319 qtcb->header.log_length,
320 sizeof(struct fsf_qtcb));
323 ZFCP_LOG_TRACE("ULP log data: \n");
324 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
325 (char *) qtcb + qtcb->header.log_start,
326 qtcb->header.log_length);
330 /* evaluate FSF Protocol Status */
331 switch (qtcb->prefix.prot_status) {
334 case FSF_PROT_FSF_STATUS_PRESENTED:
337 case FSF_PROT_QTCB_VERSION_ERROR:
338 ZFCP_LOG_NORMAL("error: The adapter %s contains "
339 "microcode of version 0x%x, the device driver "
340 "only supports 0x%x. Aborting.\n",
341 zfcp_get_busid_by_adapter(adapter),
342 prot_status_qual->version_error.fsf_version,
344 zfcp_erp_adapter_shutdown(adapter, 0);
345 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 case FSF_PROT_SEQ_NUMB_ERROR:
349 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
350 "driver (0x%x) and adapter %s (0x%x). "
351 "Restarting all operations on this adapter.\n",
352 qtcb->prefix.req_seq_no,
353 zfcp_get_busid_by_adapter(adapter),
354 prot_status_qual->sequence_error.exp_req_seq_no);
355 zfcp_erp_adapter_reopen(adapter, 0);
356 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
357 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
360 case FSF_PROT_UNSUPP_QTCB_TYPE:
361 ZFCP_LOG_NORMAL("error: Packet header type used by the "
362 "device driver is incompatible with "
363 "that used on adapter %s. "
364 "Stopping all operations on this adapter.\n",
365 zfcp_get_busid_by_adapter(adapter));
366 zfcp_erp_adapter_shutdown(adapter, 0);
367 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
370 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
371 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
372 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
376 case FSF_PROT_DUPLICATE_REQUEST_ID:
377 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
378 "to the adapter %s is ambiguous. "
379 "Stopping all operations on this adapter.\n",
380 *(unsigned long long*)
381 (&qtcb->bottom.support.req_handle),
382 zfcp_get_busid_by_adapter(adapter));
383 zfcp_erp_adapter_shutdown(adapter, 0);
384 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
387 case FSF_PROT_LINK_DOWN:
388 zfcp_fsf_link_down_info_eval(adapter,
389 &prot_status_qual->link_down_info);
390 zfcp_erp_adapter_reopen(adapter, 0);
391 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
394 case FSF_PROT_REEST_QUEUE:
395 ZFCP_LOG_NORMAL("The local link to adapter with "
396 "%s was re-plugged. "
397 "Re-starting operations on this adapter.\n",
398 zfcp_get_busid_by_adapter(adapter));
399 /* All ports should be marked as ready to run again */
400 zfcp_erp_modify_adapter_status(adapter,
401 ZFCP_STATUS_COMMON_RUNNING,
403 zfcp_erp_adapter_reopen(adapter,
404 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
405 | ZFCP_STATUS_COMMON_ERP_FAILED);
406 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
409 case FSF_PROT_ERROR_STATE:
410 ZFCP_LOG_NORMAL("error: The adapter %s "
411 "has entered the error state. "
412 "Restarting all operations on this "
414 zfcp_get_busid_by_adapter(adapter));
415 zfcp_erp_adapter_reopen(adapter, 0);
416 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
421 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
422 "provided by the adapter %s "
423 "is not compatible with the device driver. "
424 "Stopping all operations on this adapter. "
425 "(debug info 0x%x).\n",
426 zfcp_get_busid_by_adapter(adapter),
427 qtcb->prefix.prot_status);
428 zfcp_erp_adapter_shutdown(adapter, 0);
429 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
434 * always call specific handlers to give them a chance to do
435 * something meaningful even in error cases
437 zfcp_fsf_fsfstatus_eval(fsf_req);
442 * function: zfcp_fsf_fsfstatus_eval
444 * purpose: evaluates FSF status of completed FSF request
445 * and acts accordingly
450 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
454 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
458 /* evaluate FSF Status */
459 switch (fsf_req->qtcb->header.fsf_status) {
460 case FSF_UNKNOWN_COMMAND:
461 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
462 "not known by the adapter %s "
463 "Stopping all operations on this adapter. "
464 "(debug info 0x%x).\n",
465 zfcp_get_busid_by_adapter(fsf_req->adapter),
466 fsf_req->qtcb->header.fsf_command);
467 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
471 case FSF_FCP_RSP_AVAILABLE:
472 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
476 case FSF_ADAPTER_STATUS_AVAILABLE:
477 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
483 * always call specific handlers to give them a chance to do
484 * something meaningful even in error cases
486 zfcp_fsf_req_dispatch(fsf_req);
492 * function: zfcp_fsf_fsfstatus_qual_eval
494 * purpose: evaluates FSF status-qualifier of completed FSF request
495 * and acts accordingly
500 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
504 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
505 case FSF_SQ_FCP_RSP_AVAILABLE:
507 case FSF_SQ_RETRY_IF_POSSIBLE:
508 /* The SCSI-stack may now issue retries or escalate */
509 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
511 case FSF_SQ_COMMAND_ABORTED:
512 /* Carry the aborted state on to upper layer */
513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
516 case FSF_SQ_NO_RECOM:
517 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
518 "problem on the adapter %s "
519 "Stopping all operations on this adapter. ",
520 zfcp_get_busid_by_adapter(fsf_req->adapter));
521 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
524 case FSF_SQ_ULP_PROGRAMMING_ERROR:
525 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
527 zfcp_get_busid_by_adapter(fsf_req->adapter));
528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
530 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
531 case FSF_SQ_NO_RETRY_POSSIBLE:
532 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
533 /* dealt with in the respective functions */
536 ZFCP_LOG_NORMAL("bug: Additional status info could "
537 "not be interpreted properly.\n");
538 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
539 (char *) &fsf_req->qtcb->header.fsf_status_qual,
540 sizeof (union fsf_status_qual));
541 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
549 * zfcp_fsf_link_down_info_eval - evaluate link down information block
552 zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
553 struct fsf_link_down_info *link_down)
555 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
559 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
561 if (link_down == NULL)
564 switch (link_down->error_code) {
565 case FSF_PSQ_LINK_NO_LIGHT:
566 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
567 "(no light detected)\n",
568 zfcp_get_busid_by_adapter(adapter));
570 case FSF_PSQ_LINK_WRAP_PLUG:
571 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
572 "(wrap plug detected)\n",
573 zfcp_get_busid_by_adapter(adapter));
575 case FSF_PSQ_LINK_NO_FCP:
576 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
577 "(adjacent node on link does not support FCP)\n",
578 zfcp_get_busid_by_adapter(adapter));
580 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
581 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
582 "(firmware update in progress)\n",
583 zfcp_get_busid_by_adapter(adapter));
585 case FSF_PSQ_LINK_INVALID_WWPN:
586 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
587 "(duplicate or invalid WWPN detected)\n",
588 zfcp_get_busid_by_adapter(adapter));
590 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
591 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
592 "(no support for NPIV by Fabric)\n",
593 zfcp_get_busid_by_adapter(adapter));
595 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
596 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
597 "(out of resource in FCP daughtercard)\n",
598 zfcp_get_busid_by_adapter(adapter));
600 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
601 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
602 "(out of resource in Fabric)\n",
603 zfcp_get_busid_by_adapter(adapter));
605 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
606 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
607 "(unable to Fabric login)\n",
608 zfcp_get_busid_by_adapter(adapter));
610 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
611 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
612 zfcp_get_busid_by_adapter(adapter));
614 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
615 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
616 zfcp_get_busid_by_adapter(adapter));
618 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
619 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
620 zfcp_get_busid_by_adapter(adapter));
623 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
624 "(warning: unknown reason code %d)\n",
625 zfcp_get_busid_by_adapter(adapter),
626 link_down->error_code);
629 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
630 ZFCP_LOG_DEBUG("Debug information to link down: "
631 "primary_status=0x%02x "
633 "action_code=0x%02x "
634 "reason_code=0x%02x "
635 "explanation_code=0x%02x "
636 "vendor_specific_code=0x%02x\n",
637 link_down->primary_status,
638 link_down->ioerr_code,
639 link_down->action_code,
640 link_down->reason_code,
641 link_down->explanation_code,
642 link_down->vendor_specific_code);
645 zfcp_erp_adapter_failed(adapter);
649 * function: zfcp_fsf_req_dispatch
651 * purpose: calls the appropriate command specific handler
656 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
658 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
659 struct zfcp_adapter *adapter = fsf_req->adapter;
663 switch (fsf_req->fsf_command) {
665 case FSF_QTCB_FCP_CMND:
666 zfcp_fsf_send_fcp_command_handler(fsf_req);
669 case FSF_QTCB_ABORT_FCP_CMND:
670 zfcp_fsf_abort_fcp_command_handler(fsf_req);
673 case FSF_QTCB_SEND_GENERIC:
674 zfcp_fsf_send_ct_handler(fsf_req);
677 case FSF_QTCB_OPEN_PORT_WITH_DID:
678 zfcp_fsf_open_port_handler(fsf_req);
681 case FSF_QTCB_OPEN_LUN:
682 zfcp_fsf_open_unit_handler(fsf_req);
685 case FSF_QTCB_CLOSE_LUN:
686 zfcp_fsf_close_unit_handler(fsf_req);
689 case FSF_QTCB_CLOSE_PORT:
690 zfcp_fsf_close_port_handler(fsf_req);
693 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
694 zfcp_fsf_close_physical_port_handler(fsf_req);
697 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
698 zfcp_fsf_exchange_config_data_handler(fsf_req);
701 case FSF_QTCB_EXCHANGE_PORT_DATA:
702 zfcp_fsf_exchange_port_data_handler(fsf_req);
705 case FSF_QTCB_SEND_ELS:
706 zfcp_fsf_send_els_handler(fsf_req);
709 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
710 zfcp_fsf_control_file_handler(fsf_req);
713 case FSF_QTCB_UPLOAD_CONTROL_FILE:
714 zfcp_fsf_control_file_handler(fsf_req);
718 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
719 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
720 "not supported by the adapter %s\n",
721 zfcp_get_busid_by_adapter(adapter));
722 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
724 ("bug: Command issued by the device driver differs "
725 "from the command returned by the adapter %s "
726 "(debug info 0x%x, 0x%x).\n",
727 zfcp_get_busid_by_adapter(adapter),
728 fsf_req->fsf_command,
729 fsf_req->qtcb->header.fsf_command);
735 zfcp_erp_async_handler(erp_action, 0);
741 * function: zfcp_fsf_status_read
743 * purpose: initiates a Status Read command at the specified adapter
748 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
750 struct zfcp_fsf_req *fsf_req;
751 struct fsf_status_read_buffer *status_buffer;
752 unsigned long lock_flags;
753 volatile struct qdio_buffer_element *sbale;
756 /* setup new FSF request */
757 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
758 req_flags | ZFCP_REQ_NO_QTCB,
759 adapter->pool.fsf_req_status_read,
760 &lock_flags, &fsf_req);
762 ZFCP_LOG_INFO("error: Could not create unsolicited status "
763 "buffer for adapter %s.\n",
764 zfcp_get_busid_by_adapter(adapter));
765 goto failed_req_create;
768 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
769 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
770 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
771 fsf_req->sbale_curr = 2;
774 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
775 if (!status_buffer) {
776 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
779 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
780 fsf_req->data = (unsigned long) status_buffer;
782 /* insert pointer to respective buffer */
783 sbale = zfcp_qdio_sbale_curr(fsf_req);
784 sbale->addr = (void *) status_buffer;
785 sbale->length = sizeof(struct fsf_status_read_buffer);
787 retval = zfcp_fsf_req_send(fsf_req);
789 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
791 goto failed_req_send;
794 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
795 zfcp_get_busid_by_adapter(adapter));
799 mempool_free(status_buffer, adapter->pool.data_status_read);
802 zfcp_fsf_req_free(fsf_req);
804 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
806 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
811 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
813 struct fsf_status_read_buffer *status_buffer;
814 struct zfcp_adapter *adapter;
815 struct zfcp_port *port;
818 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
819 adapter = fsf_req->adapter;
821 read_lock_irqsave(&zfcp_data.config_lock, flags);
822 list_for_each_entry(port, &adapter->port_list_head, list)
823 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
825 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
827 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
828 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
829 "nonexisting port with d_id 0x%08x on "
830 "adapter %s. Ignored.\n",
831 status_buffer->d_id & ZFCP_DID_MASK,
832 zfcp_get_busid_by_adapter(adapter));
836 switch (status_buffer->status_subtype) {
838 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
839 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
840 zfcp_erp_port_reopen(port, 0);
843 case FSF_STATUS_READ_SUB_ERROR_PORT:
844 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
845 zfcp_erp_port_shutdown(port, 0);
849 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
850 debug_exception(adapter->erp_dbf, 0,
851 &status_buffer->status_subtype, sizeof (u32));
852 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
853 "for a reopen indication on port with "
854 "d_id 0x%08x on the adapter %s. "
855 "Ignored. (debug info 0x%x)\n",
857 zfcp_get_busid_by_adapter(adapter),
858 status_buffer->status_subtype);
865 * function: zfcp_fsf_status_read_handler
867 * purpose: is called for finished Open Port command
872 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
875 struct zfcp_adapter *adapter = fsf_req->adapter;
876 struct fsf_status_read_buffer *status_buffer =
877 (struct fsf_status_read_buffer *) fsf_req->data;
878 struct fsf_bit_error_payload *fsf_bit_error;
880 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
881 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
882 mempool_free(status_buffer, adapter->pool.data_status_read);
883 zfcp_fsf_req_free(fsf_req);
887 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
889 switch (status_buffer->status_type) {
891 case FSF_STATUS_READ_PORT_CLOSED:
892 zfcp_fsf_status_read_port_closed(fsf_req);
895 case FSF_STATUS_READ_INCOMING_ELS:
896 zfcp_fsf_incoming_els(fsf_req);
899 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
900 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
901 zfcp_get_busid_by_adapter(adapter));
904 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
905 fsf_bit_error = (struct fsf_bit_error_payload *)
906 status_buffer->payload;
907 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
908 "received (adapter %s, "
909 "link failures = %i, loss of sync errors = %i, "
910 "loss of signal errors = %i, "
911 "primitive sequence errors = %i, "
912 "invalid transmission word errors = %i, "
913 "CRC errors = %i)\n",
914 zfcp_get_busid_by_adapter(adapter),
915 fsf_bit_error->link_failure_error_count,
916 fsf_bit_error->loss_of_sync_error_count,
917 fsf_bit_error->loss_of_signal_error_count,
918 fsf_bit_error->primitive_sequence_error_count,
919 fsf_bit_error->invalid_transmission_word_error_count,
920 fsf_bit_error->crc_error_count);
921 ZFCP_LOG_INFO("Additional bit error threshold data "
923 "primitive sequence event time-outs = %i, "
924 "elastic buffer overrun errors = %i, "
925 "advertised receive buffer-to-buffer credit = %i, "
926 "current receice buffer-to-buffer credit = %i, "
927 "advertised transmit buffer-to-buffer credit = %i, "
928 "current transmit buffer-to-buffer credit = %i)\n",
929 zfcp_get_busid_by_adapter(adapter),
930 fsf_bit_error->primitive_sequence_event_timeout_count,
931 fsf_bit_error->elastic_buffer_overrun_error_count,
932 fsf_bit_error->advertised_receive_b2b_credit,
933 fsf_bit_error->current_receive_b2b_credit,
934 fsf_bit_error->advertised_transmit_b2b_credit,
935 fsf_bit_error->current_transmit_b2b_credit);
938 case FSF_STATUS_READ_LINK_DOWN:
939 switch (status_buffer->status_subtype) {
940 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
941 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
942 zfcp_get_busid_by_adapter(adapter));
943 zfcp_fsf_link_down_info_eval(adapter,
944 (struct fsf_link_down_info *)
945 &status_buffer->payload);
947 case FSF_STATUS_READ_SUB_FDISC_FAILED:
948 ZFCP_LOG_INFO("Local link to adapter %s is down "
949 "due to failed FDISC login\n",
950 zfcp_get_busid_by_adapter(adapter));
951 zfcp_fsf_link_down_info_eval(adapter,
952 (struct fsf_link_down_info *)
953 &status_buffer->payload);
955 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
956 ZFCP_LOG_INFO("Local link to adapter %s is down "
957 "due to firmware update on adapter\n",
958 zfcp_get_busid_by_adapter(adapter));
959 zfcp_fsf_link_down_info_eval(adapter, NULL);
962 ZFCP_LOG_INFO("Local link to adapter %s is down "
963 "due to unknown reason\n",
964 zfcp_get_busid_by_adapter(adapter));
965 zfcp_fsf_link_down_info_eval(adapter, NULL);
969 case FSF_STATUS_READ_LINK_UP:
970 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
971 "Restarting operations on this adapter\n",
972 zfcp_get_busid_by_adapter(adapter));
973 /* All ports should be marked as ready to run again */
974 zfcp_erp_modify_adapter_status(adapter,
975 ZFCP_STATUS_COMMON_RUNNING,
977 zfcp_erp_adapter_reopen(adapter,
978 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
979 | ZFCP_STATUS_COMMON_ERP_FAILED);
982 case FSF_STATUS_READ_NOTIFICATION_LOST:
983 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
984 "adapter %s%s%s%s%s%s%s%s%s\n",
985 zfcp_get_busid_by_adapter(adapter),
986 (status_buffer->status_subtype &
987 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
988 ", incoming ELS" : "",
989 (status_buffer->status_subtype &
990 FSF_STATUS_READ_SUB_SENSE_DATA) ?
992 (status_buffer->status_subtype &
993 FSF_STATUS_READ_SUB_LINK_STATUS) ?
994 ", link status change" : "",
995 (status_buffer->status_subtype &
996 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
998 (status_buffer->status_subtype &
999 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
1000 ", bit error exception" : "",
1001 (status_buffer->status_subtype &
1002 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
1003 ", ACT update" : "",
1004 (status_buffer->status_subtype &
1005 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
1006 ", ACT hardening" : "",
1007 (status_buffer->status_subtype &
1008 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
1009 ", adapter feature change" : "");
1011 if (status_buffer->status_subtype &
1012 FSF_STATUS_READ_SUB_ACT_UPDATED)
1013 zfcp_erp_adapter_access_changed(adapter);
1016 case FSF_STATUS_READ_CFDC_UPDATED:
1017 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1018 zfcp_get_busid_by_adapter(adapter));
1019 zfcp_erp_adapter_access_changed(adapter);
1022 case FSF_STATUS_READ_CFDC_HARDENED:
1023 switch (status_buffer->status_subtype) {
1024 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1025 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1026 zfcp_get_busid_by_adapter(adapter));
1028 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1029 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1030 "to the secondary SE\n",
1031 zfcp_get_busid_by_adapter(adapter));
1034 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1035 zfcp_get_busid_by_adapter(adapter));
1039 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1040 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1041 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1042 "been changed from 0x%08X to 0x%08X\n",
1043 zfcp_get_busid_by_adapter(adapter),
1044 *(u32*) (status_buffer->payload + 4),
1045 *(u32*) (status_buffer->payload));
1046 adapter->adapter_features = *(u32*) status_buffer->payload;
1050 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1051 "type was received (debug info 0x%x)\n",
1052 status_buffer->status_type);
1053 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1055 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1056 (char *) status_buffer,
1057 sizeof (struct fsf_status_read_buffer));
1060 mempool_free(status_buffer, adapter->pool.data_status_read);
1061 zfcp_fsf_req_free(fsf_req);
1063 * recycle buffer and start new request repeat until outbound
1064 * queue is empty or adapter shutdown is requested
1068 * we may wait in the req_create for 5s during shutdown, so
1069 * qdio_cleanup will have to wait at least that long before returning
1070 * with failure to allow us a proper cleanup under all circumstances
1074 * allocation failure possible? (Is this code needed?)
1076 retval = zfcp_fsf_status_read(adapter, 0);
1078 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1079 "request for the adapter %s.\n",
1080 zfcp_get_busid_by_adapter(adapter));
1081 /* temporary fix to avoid status read buffer shortage */
1082 adapter->status_read_failed++;
1083 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1084 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1085 ZFCP_LOG_INFO("restart adapter %s due to status read "
1086 "buffer shortage\n",
1087 zfcp_get_busid_by_adapter(adapter));
1088 zfcp_erp_adapter_reopen(adapter, 0);
1096 * function: zfcp_fsf_abort_fcp_command
1098 * purpose: tells FSF to abort a running SCSI command
1100 * returns: address of initiated FSF request
1101 * NULL - request could not be initiated
1103 * FIXME(design): should be watched by a timeout !!!
1104 * FIXME(design) shouldn't this be modified to return an int
1105 * also...don't know how though
1107 struct zfcp_fsf_req *
1108 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1109 struct zfcp_adapter *adapter,
1110 struct zfcp_unit *unit, int req_flags)
1112 volatile struct qdio_buffer_element *sbale;
1113 struct zfcp_fsf_req *fsf_req = NULL;
1114 unsigned long lock_flags;
1117 /* setup new FSF request */
1118 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1119 req_flags, adapter->pool.fsf_req_abort,
1120 &lock_flags, &fsf_req);
1122 ZFCP_LOG_INFO("error: Failed to create an abort command "
1123 "request for lun 0x%016Lx on port 0x%016Lx "
1127 zfcp_get_busid_by_adapter(adapter));
1131 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1132 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1133 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1135 fsf_req->data = (unsigned long) unit;
1137 /* set handles of unit and its parent port in QTCB */
1138 fsf_req->qtcb->header.lun_handle = unit->handle;
1139 fsf_req->qtcb->header.port_handle = unit->port->handle;
1141 /* set handle of request which should be aborted */
1142 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1144 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1145 retval = zfcp_fsf_req_send(fsf_req);
1147 ZFCP_LOG_INFO("error: Failed to send abort command request "
1148 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1149 zfcp_get_busid_by_adapter(adapter),
1150 unit->port->wwpn, unit->fcp_lun);
1151 zfcp_fsf_req_free(fsf_req);
1156 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1157 "(adapter%s, port d_id=0x%08x, "
1158 "unit x%016Lx, old_req_id=0x%lx)\n",
1159 zfcp_get_busid_by_adapter(adapter),
1161 unit->fcp_lun, old_req_id);
1163 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1168 * function: zfcp_fsf_abort_fcp_command_handler
1170 * purpose: is called for finished Abort FCP Command request
1175 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1177 int retval = -EINVAL;
1178 struct zfcp_unit *unit;
1179 unsigned char status_qual =
1180 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1182 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1183 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1184 goto skip_fsfstatus;
1187 unit = (struct zfcp_unit *) new_fsf_req->data;
1189 /* evaluate FSF status in QTCB */
1190 switch (new_fsf_req->qtcb->header.fsf_status) {
1192 case FSF_PORT_HANDLE_NOT_VALID:
1193 if (status_qual >> 4 != status_qual % 0xf) {
1194 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1197 * In this case a command that was sent prior to a port
1198 * reopen was aborted (handles are different). This is
1202 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1203 "port 0x%016Lx on adapter %s invalid. "
1204 "This may happen occasionally.\n",
1207 zfcp_get_busid_by_unit(unit));
1208 ZFCP_LOG_INFO("status qualifier:\n");
1209 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1210 (char *) &new_fsf_req->qtcb->header.
1212 sizeof (union fsf_status_qual));
1213 /* Let's hope this sorts out the mess */
1214 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1216 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1217 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1221 case FSF_LUN_HANDLE_NOT_VALID:
1222 if (status_qual >> 4 != status_qual % 0xf) {
1224 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1227 * In this case a command that was sent prior to a unit
1228 * reopen was aborted (handles are different).
1233 ("Warning: Temporary LUN identifier 0x%x of LUN "
1234 "0x%016Lx on port 0x%016Lx on adapter %s is "
1235 "invalid. This may happen in rare cases. "
1236 "Trying to re-establish link.\n",
1240 zfcp_get_busid_by_unit(unit));
1241 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1242 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1243 (char *) &new_fsf_req->qtcb->header.
1245 sizeof (union fsf_status_qual));
1246 /* Let's hope this sorts out the mess */
1247 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1249 zfcp_erp_port_reopen(unit->port, 0);
1250 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1254 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1256 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1258 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1261 case FSF_PORT_BOXED:
1262 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1263 "be reopened\n", unit->port->wwpn,
1264 zfcp_get_busid_by_unit(unit));
1265 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1267 zfcp_erp_port_boxed(unit->port);
1268 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1269 | ZFCP_STATUS_FSFREQ_RETRY;
1274 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1276 unit->fcp_lun, unit->port->wwpn,
1277 zfcp_get_busid_by_unit(unit));
1278 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1279 zfcp_erp_unit_boxed(unit);
1280 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1281 | ZFCP_STATUS_FSFREQ_RETRY;
1284 case FSF_ADAPTER_STATUS_AVAILABLE:
1285 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1286 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1287 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1289 zfcp_test_link(unit->port);
1290 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1292 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1293 /* SCSI stack will escalate */
1294 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1296 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1300 ("bug: Wrong status qualifier 0x%x arrived.\n",
1301 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1302 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1304 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1305 &new_fsf_req->qtcb->header.
1306 fsf_status_qual.word[0], sizeof (u32));
1313 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1317 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1318 "(debug info 0x%x)\n",
1319 new_fsf_req->qtcb->header.fsf_status);
1320 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1322 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1323 &new_fsf_req->qtcb->header.fsf_status,
1332 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1334 * Two scatter-gather lists are passed, one for the reqeust and one for the
1338 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1339 struct scatterlist *resp, int resp_count)
1341 return ((req_count == 1) &&
1342 (resp_count == 1) &&
1343 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1345 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1346 req[0].length - 1) & PAGE_MASK)) &&
1347 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1349 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1350 resp[0].length - 1) & PAGE_MASK)));
1354 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1355 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1357 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1358 * a struct zfcp_fsf_req
1359 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1360 * is sent within error recovery
1363 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1364 struct zfcp_erp_action *erp_action)
1366 volatile struct qdio_buffer_element *sbale;
1367 struct zfcp_port *port;
1368 struct zfcp_adapter *adapter;
1369 struct zfcp_fsf_req *fsf_req;
1370 unsigned long lock_flags;
1375 adapter = port->adapter;
1377 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1378 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1379 pool, &lock_flags, &fsf_req);
1381 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1383 zfcp_get_busid_by_adapter(adapter));
1387 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1388 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1389 ct->resp, ct->resp_count)){
1390 /* both request buffer and response buffer
1391 fit into one sbale each */
1392 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1393 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1394 sbale[2].length = ct->req[0].length;
1395 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1396 sbale[3].length = ct->resp[0].length;
1397 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1398 } else if (adapter->adapter_features &
1399 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1400 /* try to use chained SBALs */
1401 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1402 SBAL_FLAGS0_TYPE_WRITE_READ,
1403 ct->req, ct->req_count,
1404 ZFCP_MAX_SBALS_PER_CT_REQ);
1406 ZFCP_LOG_INFO("error: creation of CT request failed "
1408 zfcp_get_busid_by_adapter(adapter));
1416 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1417 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1418 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1419 SBAL_FLAGS0_TYPE_WRITE_READ,
1420 ct->resp, ct->resp_count,
1421 ZFCP_MAX_SBALS_PER_CT_REQ);
1423 ZFCP_LOG_INFO("error: creation of CT request failed "
1425 zfcp_get_busid_by_adapter(adapter));
1433 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1435 /* reject send generic request */
1437 "error: microcode does not support chained SBALs,"
1438 "CT request too big (adapter %s)\n",
1439 zfcp_get_busid_by_adapter(adapter));
1444 /* settings in QTCB */
1445 fsf_req->qtcb->header.port_handle = port->handle;
1446 fsf_req->qtcb->bottom.support.service_class =
1447 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1448 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1449 fsf_req->data = (unsigned long) ct;
1451 zfcp_san_dbf_event_ct_request(fsf_req);
1454 erp_action->fsf_req = fsf_req;
1455 fsf_req->erp_action = erp_action;
1456 zfcp_erp_start_timer(fsf_req);
1458 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1460 ret = zfcp_fsf_req_send(fsf_req);
1462 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1463 "(adapter %s, port 0x%016Lx)\n",
1464 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1468 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1469 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1473 zfcp_fsf_req_free(fsf_req);
1474 if (erp_action != NULL) {
1475 erp_action->fsf_req = NULL;
1479 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1485 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1486 * @fsf_req: pointer to struct zfcp_fsf_req
1488 * Data specific for the Generic Service request is passed using
1489 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1490 * Usually a specific handler for the CT request is called which is
1491 * found in this structure.
1494 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1496 struct zfcp_port *port;
1497 struct zfcp_adapter *adapter;
1498 struct zfcp_send_ct *send_ct;
1499 struct fsf_qtcb_header *header;
1500 struct fsf_qtcb_bottom_support *bottom;
1501 int retval = -EINVAL;
1502 u16 subtable, rule, counter;
1504 adapter = fsf_req->adapter;
1505 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1506 port = send_ct->port;
1507 header = &fsf_req->qtcb->header;
1508 bottom = &fsf_req->qtcb->bottom.support;
1510 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1511 goto skip_fsfstatus;
1513 /* evaluate FSF status in QTCB */
1514 switch (header->fsf_status) {
1517 zfcp_san_dbf_event_ct_response(fsf_req);
1521 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1522 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1524 zfcp_get_busid_by_port(port),
1525 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1526 /* stop operation for this adapter */
1527 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1528 zfcp_erp_adapter_shutdown(adapter, 0);
1529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1532 case FSF_ADAPTER_STATUS_AVAILABLE:
1533 switch (header->fsf_status_qual.word[0]){
1534 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1535 /* reopening link to port */
1536 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1537 zfcp_test_link(port);
1538 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1540 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1541 /* ERP strategy will escalate */
1542 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1543 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1546 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1548 header->fsf_status_qual.word[0]);
1553 case FSF_ACCESS_DENIED:
1554 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1555 "command (adapter %s, port d_id=0x%08x)\n",
1556 zfcp_get_busid_by_port(port), port->d_id);
1557 for (counter = 0; counter < 2; counter++) {
1558 subtable = header->fsf_status_qual.halfword[counter * 2];
1559 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1561 case FSF_SQ_CFDC_SUBTABLE_OS:
1562 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1563 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1564 case FSF_SQ_CFDC_SUBTABLE_LUN:
1565 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1566 zfcp_act_subtable_type[subtable], rule);
1570 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1571 zfcp_erp_port_access_denied(port);
1572 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1575 case FSF_GENERIC_COMMAND_REJECTED:
1576 ZFCP_LOG_INFO("generic service command rejected "
1577 "(adapter %s, port d_id=0x%08x)\n",
1578 zfcp_get_busid_by_port(port), port->d_id);
1579 ZFCP_LOG_INFO("status qualifier:\n");
1580 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1581 (char *) &header->fsf_status_qual,
1582 sizeof (union fsf_status_qual));
1583 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1584 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1587 case FSF_PORT_HANDLE_NOT_VALID:
1588 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1589 "0x%016Lx on adapter %s invalid. This may "
1590 "happen occasionally.\n", port->handle,
1591 port->wwpn, zfcp_get_busid_by_port(port));
1592 ZFCP_LOG_INFO("status qualifier:\n");
1593 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1594 (char *) &header->fsf_status_qual,
1595 sizeof (union fsf_status_qual));
1596 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1597 zfcp_erp_adapter_reopen(adapter, 0);
1598 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1601 case FSF_PORT_BOXED:
1602 ZFCP_LOG_INFO("port needs to be reopened "
1603 "(adapter %s, port d_id=0x%08x)\n",
1604 zfcp_get_busid_by_port(port), port->d_id);
1605 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1606 zfcp_erp_port_boxed(port);
1607 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1608 | ZFCP_STATUS_FSFREQ_RETRY;
1611 /* following states should never occure, all cases avoided
1612 in zfcp_fsf_send_ct - but who knows ... */
1613 case FSF_PAYLOAD_SIZE_MISMATCH:
1614 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1615 "req_buf_length=%d, resp_buf_length=%d)\n",
1616 zfcp_get_busid_by_adapter(adapter),
1617 bottom->req_buf_length, bottom->resp_buf_length);
1618 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1620 case FSF_REQUEST_SIZE_TOO_LARGE:
1621 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1622 "req_buf_length=%d)\n",
1623 zfcp_get_busid_by_adapter(adapter),
1624 bottom->req_buf_length);
1625 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1627 case FSF_RESPONSE_SIZE_TOO_LARGE:
1628 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1629 "resp_buf_length=%d)\n",
1630 zfcp_get_busid_by_adapter(adapter),
1631 bottom->resp_buf_length);
1632 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1634 case FSF_SBAL_MISMATCH:
1635 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1636 "resp_buf_length=%d)\n",
1637 zfcp_get_busid_by_adapter(adapter),
1638 bottom->req_buf_length, bottom->resp_buf_length);
1639 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1643 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1644 "(debug info 0x%x)\n", header->fsf_status);
1645 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1646 debug_exception(adapter->erp_dbf, 0,
1647 &header->fsf_status_qual.word[0], sizeof (u32));
1652 send_ct->status = retval;
1654 if (send_ct->handler != NULL)
1655 send_ct->handler(send_ct->handler_data);
1661 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1662 * @els: pointer to struct zfcp_send_els which contains all needed data for
1666 zfcp_fsf_send_els(struct zfcp_send_els *els)
1668 volatile struct qdio_buffer_element *sbale;
1669 struct zfcp_fsf_req *fsf_req;
1671 struct zfcp_adapter *adapter;
1672 unsigned long lock_flags;
1677 adapter = els->adapter;
1679 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1680 ZFCP_REQ_AUTO_CLEANUP,
1681 NULL, &lock_flags, &fsf_req);
1683 ZFCP_LOG_INFO("error: creation of ELS request failed "
1684 "(adapter %s, port d_id: 0x%08x)\n",
1685 zfcp_get_busid_by_adapter(adapter), d_id);
1689 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1690 if (zfcp_use_one_sbal(els->req, els->req_count,
1691 els->resp, els->resp_count)){
1692 /* both request buffer and response buffer
1693 fit into one sbale each */
1694 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1695 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1696 sbale[2].length = els->req[0].length;
1697 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1698 sbale[3].length = els->resp[0].length;
1699 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1700 } else if (adapter->adapter_features &
1701 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1702 /* try to use chained SBALs */
1703 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1704 SBAL_FLAGS0_TYPE_WRITE_READ,
1705 els->req, els->req_count,
1706 ZFCP_MAX_SBALS_PER_ELS_REQ);
1708 ZFCP_LOG_INFO("error: creation of ELS request failed "
1709 "(adapter %s, port d_id: 0x%08x)\n",
1710 zfcp_get_busid_by_adapter(adapter), d_id);
1718 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1719 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1720 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1721 SBAL_FLAGS0_TYPE_WRITE_READ,
1722 els->resp, els->resp_count,
1723 ZFCP_MAX_SBALS_PER_ELS_REQ);
1725 ZFCP_LOG_INFO("error: creation of ELS request failed "
1726 "(adapter %s, port d_id: 0x%08x)\n",
1727 zfcp_get_busid_by_adapter(adapter), d_id);
1735 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1737 /* reject request */
1738 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1739 ", ELS request too big (adapter %s, "
1740 "port d_id: 0x%08x)\n",
1741 zfcp_get_busid_by_adapter(adapter), d_id);
1746 /* settings in QTCB */
1747 fsf_req->qtcb->bottom.support.d_id = d_id;
1748 fsf_req->qtcb->bottom.support.service_class =
1749 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1750 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1751 fsf_req->data = (unsigned long) els;
1753 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1755 zfcp_san_dbf_event_els_request(fsf_req);
1757 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1758 ret = zfcp_fsf_req_send(fsf_req);
1760 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1761 "(adapter %s, port d_id: 0x%08x)\n",
1762 zfcp_get_busid_by_adapter(adapter), d_id);
1766 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1767 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1771 zfcp_fsf_req_free(fsf_req);
1775 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1782 * zfcp_fsf_send_els_handler - handler for ELS commands
1783 * @fsf_req: pointer to struct zfcp_fsf_req
1785 * Data specific for the ELS command is passed using
1786 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1787 * Usually a specific handler for the ELS command is called which is
1788 * found in this structure.
1790 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1792 struct zfcp_adapter *adapter;
1793 struct zfcp_port *port;
1795 struct fsf_qtcb_header *header;
1796 struct fsf_qtcb_bottom_support *bottom;
1797 struct zfcp_send_els *send_els;
1798 int retval = -EINVAL;
1799 u16 subtable, rule, counter;
1801 send_els = (struct zfcp_send_els *) fsf_req->data;
1802 adapter = send_els->adapter;
1803 port = send_els->port;
1804 d_id = send_els->d_id;
1805 header = &fsf_req->qtcb->header;
1806 bottom = &fsf_req->qtcb->bottom.support;
1808 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1809 goto skip_fsfstatus;
1811 switch (header->fsf_status) {
1814 zfcp_san_dbf_event_els_response(fsf_req);
1818 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1819 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1821 zfcp_get_busid_by_adapter(adapter),
1822 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1823 /* stop operation for this adapter */
1824 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1825 zfcp_erp_adapter_shutdown(adapter, 0);
1826 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 case FSF_ADAPTER_STATUS_AVAILABLE:
1830 switch (header->fsf_status_qual.word[0]){
1831 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1832 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1833 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1834 zfcp_test_link(port);
1835 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1837 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1838 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1841 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1842 (struct zfcp_ls_rjt_par *)
1843 &header->fsf_status_qual.word[2]);
1845 case FSF_SQ_RETRY_IF_POSSIBLE:
1846 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1847 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1850 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1851 header->fsf_status_qual.word[0]);
1852 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1853 (char*)header->fsf_status_qual.word, 16);
1857 case FSF_ELS_COMMAND_REJECTED:
1858 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1859 "prohibited sending "
1860 "(adapter: %s, port d_id: 0x%08x)\n",
1861 zfcp_get_busid_by_adapter(adapter), d_id);
1865 case FSF_PAYLOAD_SIZE_MISMATCH:
1867 "ELS request size and ELS response size must be either "
1868 "both 0, or both greater than 0 "
1869 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1870 zfcp_get_busid_by_adapter(adapter),
1871 bottom->req_buf_length,
1872 bottom->resp_buf_length);
1875 case FSF_REQUEST_SIZE_TOO_LARGE:
1877 "Length of the ELS request buffer, "
1878 "specified in QTCB bottom, "
1879 "exceeds the size of the buffers "
1880 "that have been allocated for ELS request data "
1881 "(adapter: %s, req_buf_length=%d)\n",
1882 zfcp_get_busid_by_adapter(adapter),
1883 bottom->req_buf_length);
1886 case FSF_RESPONSE_SIZE_TOO_LARGE:
1888 "Length of the ELS response buffer, "
1889 "specified in QTCB bottom, "
1890 "exceeds the size of the buffers "
1891 "that have been allocated for ELS response data "
1892 "(adapter: %s, resp_buf_length=%d)\n",
1893 zfcp_get_busid_by_adapter(adapter),
1894 bottom->resp_buf_length);
1897 case FSF_SBAL_MISMATCH:
1898 /* should never occure, avoided in zfcp_fsf_send_els */
1899 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1900 "resp_buf_length=%d)\n",
1901 zfcp_get_busid_by_adapter(adapter),
1902 bottom->req_buf_length, bottom->resp_buf_length);
1903 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1906 case FSF_ACCESS_DENIED:
1907 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1908 "(adapter %s, port d_id=0x%08x)\n",
1909 zfcp_get_busid_by_adapter(adapter), d_id);
1910 for (counter = 0; counter < 2; counter++) {
1911 subtable = header->fsf_status_qual.halfword[counter * 2];
1912 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1914 case FSF_SQ_CFDC_SUBTABLE_OS:
1915 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1916 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1917 case FSF_SQ_CFDC_SUBTABLE_LUN:
1918 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1919 zfcp_act_subtable_type[subtable], rule);
1923 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1925 zfcp_erp_port_access_denied(port);
1926 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1931 "bug: An unknown FSF Status was presented "
1932 "(adapter: %s, fsf_status=0x%08x)\n",
1933 zfcp_get_busid_by_adapter(adapter),
1934 header->fsf_status);
1935 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1936 debug_exception(adapter->erp_dbf, 0,
1937 &header->fsf_status_qual.word[0], sizeof(u32));
1938 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1943 send_els->status = retval;
1945 if (send_els->handler != 0)
1946 send_els->handler(send_els->handler_data);
1952 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1954 volatile struct qdio_buffer_element *sbale;
1955 struct zfcp_fsf_req *fsf_req;
1956 unsigned long lock_flags;
1959 /* setup new FSF request */
1960 retval = zfcp_fsf_req_create(erp_action->adapter,
1961 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1962 ZFCP_REQ_AUTO_CLEANUP,
1963 erp_action->adapter->pool.fsf_req_erp,
1964 &lock_flags, &fsf_req);
1966 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1967 "data request for adapter %s.\n",
1968 zfcp_get_busid_by_adapter(erp_action->adapter));
1972 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1973 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1974 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1976 fsf_req->qtcb->bottom.config.feature_selection =
1978 FSF_FEATURE_LUN_SHARING |
1979 FSF_FEATURE_NOTIFICATION_LOST |
1980 FSF_FEATURE_UPDATE_ALERT;
1981 fsf_req->erp_action = erp_action;
1982 erp_action->fsf_req = fsf_req;
1984 zfcp_erp_start_timer(fsf_req);
1985 retval = zfcp_fsf_req_send(fsf_req);
1988 ("error: Could not send exchange configuration data "
1989 "command on the adapter %s\n",
1990 zfcp_get_busid_by_adapter(erp_action->adapter));
1991 zfcp_fsf_req_free(fsf_req);
1992 erp_action->fsf_req = NULL;
1996 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1998 zfcp_get_busid_by_adapter(erp_action->adapter));
2001 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2007 * zfcp_fsf_exchange_config_evaluate
2008 * @fsf_req: fsf_req which belongs to xchg config data request
2009 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2011 * returns: -EIO on error, 0 otherwise
2014 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2016 struct fsf_qtcb_bottom_config *bottom;
2017 struct zfcp_adapter *adapter = fsf_req->adapter;
2018 struct Scsi_Host *shost = adapter->scsi_host;
2020 bottom = &fsf_req->qtcb->bottom.config;
2021 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2022 bottom->low_qtcb_version, bottom->high_qtcb_version);
2023 adapter->fsf_lic_version = bottom->lic_version;
2024 adapter->adapter_features = bottom->adapter_features;
2025 adapter->connection_features = bottom->connection_features;
2026 adapter->peer_wwpn = 0;
2027 adapter->peer_wwnn = 0;
2028 adapter->peer_d_id = 0;
2031 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2032 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2033 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2034 fc_host_speed(shost) = bottom->fc_link_speed;
2035 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2036 adapter->hydra_version = bottom->adapter_type;
2037 if (fc_host_permanent_port_name(shost) == -1)
2038 fc_host_permanent_port_name(shost) =
2039 fc_host_port_name(shost);
2040 if (bottom->fc_topology == FSF_TOPO_P2P) {
2041 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2042 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2043 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2044 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2045 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2046 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2047 else if (bottom->fc_topology == FSF_TOPO_AL)
2048 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2050 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2052 fc_host_node_name(shost) = 0;
2053 fc_host_port_name(shost) = 0;
2054 fc_host_port_id(shost) = 0;
2055 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2056 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2057 adapter->hydra_version = 0;
2060 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2061 adapter->hardware_version = bottom->hardware_version;
2062 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2063 min(FC_SERIAL_NUMBER_SIZE, 17));
2064 EBCASC(fc_host_serial_number(shost),
2065 min(FC_SERIAL_NUMBER_SIZE, 17));
2068 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2072 "adapter version 0x%x, "
2073 "LIC version 0x%x, "
2074 "FC link speed %d Gb/s\n",
2075 zfcp_get_busid_by_adapter(adapter),
2076 (wwn_t) fc_host_node_name(shost),
2077 (wwn_t) fc_host_port_name(shost),
2078 fc_host_port_id(shost),
2079 adapter->hydra_version,
2080 adapter->fsf_lic_version,
2081 fc_host_speed(shost));
2082 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2083 ZFCP_LOG_NORMAL("error: the adapter %s "
2084 "only supports newer control block "
2085 "versions in comparison to this device "
2086 "driver (try updated device driver)\n",
2087 zfcp_get_busid_by_adapter(adapter));
2088 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2089 zfcp_erp_adapter_shutdown(adapter, 0);
2092 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2093 ZFCP_LOG_NORMAL("error: the adapter %s "
2094 "only supports older control block "
2095 "versions than this device driver uses"
2096 "(consider a microcode upgrade)\n",
2097 zfcp_get_busid_by_adapter(adapter));
2098 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2099 zfcp_erp_adapter_shutdown(adapter, 0);
2106 * function: zfcp_fsf_exchange_config_data_handler
2108 * purpose: is called for finished Exchange Configuration Data command
2113 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2115 struct fsf_qtcb_bottom_config *bottom;
2116 struct zfcp_adapter *adapter = fsf_req->adapter;
2117 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2119 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2122 switch (qtcb->header.fsf_status) {
2125 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2128 switch (fc_host_port_type(adapter->scsi_host)) {
2129 case FC_PORTTYPE_PTP:
2130 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2131 "configuration detected at adapter %s\n"
2132 "Peer WWNN 0x%016llx, "
2133 "peer WWPN 0x%016llx, "
2134 "peer d_id 0x%06x\n",
2135 zfcp_get_busid_by_adapter(adapter),
2138 adapter->peer_d_id);
2139 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2142 case FC_PORTTYPE_NLPORT:
2143 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2144 "topology detected at adapter %s "
2145 "unsupported, shutting down adapter\n",
2146 zfcp_get_busid_by_adapter(adapter));
2147 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2149 zfcp_erp_adapter_shutdown(adapter, 0);
2151 case FC_PORTTYPE_NPORT:
2152 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2153 "network detected at adapter %s.\n",
2154 zfcp_get_busid_by_adapter(adapter));
2157 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2158 "reported by the exchange "
2159 "configuration command for "
2160 "the adapter %s is not "
2161 "of a type known to the zfcp "
2162 "driver, shutting down adapter\n",
2163 zfcp_get_busid_by_adapter(adapter));
2164 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2166 zfcp_erp_adapter_shutdown(adapter, 0);
2169 bottom = &qtcb->bottom.config;
2170 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2171 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2172 "allowed by the adapter %s "
2173 "is lower than the minimum "
2174 "required by the driver (%ld bytes).\n",
2175 bottom->max_qtcb_size,
2176 zfcp_get_busid_by_adapter(adapter),
2177 sizeof(struct fsf_qtcb));
2178 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2180 debug_event(fsf_req->adapter->erp_dbf, 0,
2181 &bottom->max_qtcb_size, sizeof (u32));
2182 zfcp_erp_adapter_shutdown(adapter, 0);
2185 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2188 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2189 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2191 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2194 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2196 zfcp_fsf_link_down_info_eval(adapter,
2197 &qtcb->header.fsf_status_qual.link_down_info);
2200 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2201 debug_event(fsf_req->adapter->erp_dbf, 0,
2202 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2203 zfcp_erp_adapter_shutdown(adapter, 0);
2210 * zfcp_fsf_exchange_port_data - request information about local port
2211 * @erp_action: ERP action for the adapter for which port data is requested
2212 * @adapter: for which port data is requested
2213 * @data: response to exchange port data request
2216 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2217 struct zfcp_adapter *adapter,
2218 struct fsf_qtcb_bottom_port *data)
2220 volatile struct qdio_buffer_element *sbale;
2221 struct zfcp_fsf_req *fsf_req;
2222 unsigned long lock_flags;
2225 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2226 ZFCP_LOG_INFO("error: exchange port data "
2227 "command not supported by adapter %s\n",
2228 zfcp_get_busid_by_adapter(adapter));
2232 /* setup new FSF request */
2233 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2234 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2235 NULL, &lock_flags, &fsf_req);
2237 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2238 "exchange port data request for"
2239 "the adapter %s.\n",
2240 zfcp_get_busid_by_adapter(adapter));
2241 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2247 fsf_req->data = (unsigned long) data;
2249 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2250 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2251 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2254 erp_action->fsf_req = fsf_req;
2255 fsf_req->erp_action = erp_action;
2256 zfcp_erp_start_timer(fsf_req);
2258 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2260 retval = zfcp_fsf_req_send(fsf_req);
2262 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2263 "command on the adapter %s\n",
2264 zfcp_get_busid_by_adapter(adapter));
2265 zfcp_fsf_req_free(fsf_req);
2267 erp_action->fsf_req = NULL;
2268 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2273 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2276 wait_event(fsf_req->completion_wq,
2277 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2278 zfcp_fsf_req_free(fsf_req);
2284 * zfcp_fsf_exchange_port_evaluate
2285 * @fsf_req: fsf_req which belongs to xchg port data request
2286 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2289 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2291 struct zfcp_adapter *adapter;
2292 struct fsf_qtcb *qtcb;
2293 struct fsf_qtcb_bottom_port *bottom, *data;
2294 struct Scsi_Host *shost;
2296 adapter = fsf_req->adapter;
2297 qtcb = fsf_req->qtcb;
2298 bottom = &qtcb->bottom.port;
2299 shost = adapter->scsi_host;
2301 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2303 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2305 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2306 fc_host_permanent_port_name(shost) = bottom->wwpn;
2308 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2309 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2310 fc_host_supported_speeds(shost) = bottom->supported_speed;
2314 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2315 * @fsf_req: pointer to struct zfcp_fsf_req
2318 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2320 struct zfcp_adapter *adapter;
2321 struct fsf_qtcb *qtcb;
2323 adapter = fsf_req->adapter;
2324 qtcb = fsf_req->qtcb;
2326 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2329 switch (qtcb->header.fsf_status) {
2331 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2332 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2334 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2335 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2336 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2337 zfcp_fsf_link_down_info_eval(adapter,
2338 &qtcb->header.fsf_status_qual.link_down_info);
2341 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2342 debug_event(adapter->erp_dbf, 0,
2343 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2349 * function: zfcp_fsf_open_port
2353 * returns: address of initiated FSF request
2354 * NULL - request could not be initiated
2357 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2359 volatile struct qdio_buffer_element *sbale;
2360 struct zfcp_fsf_req *fsf_req;
2361 unsigned long lock_flags;
2364 /* setup new FSF request */
2365 retval = zfcp_fsf_req_create(erp_action->adapter,
2366 FSF_QTCB_OPEN_PORT_WITH_DID,
2367 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2368 erp_action->adapter->pool.fsf_req_erp,
2369 &lock_flags, &fsf_req);
2371 ZFCP_LOG_INFO("error: Could not create open port request "
2372 "for port 0x%016Lx on adapter %s.\n",
2373 erp_action->port->wwpn,
2374 zfcp_get_busid_by_adapter(erp_action->adapter));
2378 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2379 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2380 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2382 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2383 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2384 fsf_req->data = (unsigned long) erp_action->port;
2385 fsf_req->erp_action = erp_action;
2386 erp_action->fsf_req = fsf_req;
2388 zfcp_erp_start_timer(fsf_req);
2389 retval = zfcp_fsf_req_send(fsf_req);
2391 ZFCP_LOG_INFO("error: Could not send open port request for "
2392 "port 0x%016Lx on adapter %s.\n",
2393 erp_action->port->wwpn,
2394 zfcp_get_busid_by_adapter(erp_action->adapter));
2395 zfcp_fsf_req_free(fsf_req);
2396 erp_action->fsf_req = NULL;
2400 ZFCP_LOG_DEBUG("open port request initiated "
2401 "(adapter %s, port 0x%016Lx)\n",
2402 zfcp_get_busid_by_adapter(erp_action->adapter),
2403 erp_action->port->wwpn);
2405 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2411 * function: zfcp_fsf_open_port_handler
2413 * purpose: is called for finished Open Port command
2418 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2420 int retval = -EINVAL;
2421 struct zfcp_port *port;
2422 struct fsf_plogi *plogi;
2423 struct fsf_qtcb_header *header;
2424 u16 subtable, rule, counter;
2426 port = (struct zfcp_port *) fsf_req->data;
2427 header = &fsf_req->qtcb->header;
2429 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2430 /* don't change port status in our bookkeeping */
2431 goto skip_fsfstatus;
2434 /* evaluate FSF status in QTCB */
2435 switch (header->fsf_status) {
2437 case FSF_PORT_ALREADY_OPEN:
2438 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2439 "is already open.\n",
2440 port->wwpn, zfcp_get_busid_by_port(port));
2441 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2444 * This is a bug, however operation should continue normally
2445 * if it is simply ignored
2449 case FSF_ACCESS_DENIED:
2450 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2452 port->wwpn, zfcp_get_busid_by_port(port));
2453 for (counter = 0; counter < 2; counter++) {
2454 subtable = header->fsf_status_qual.halfword[counter * 2];
2455 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2457 case FSF_SQ_CFDC_SUBTABLE_OS:
2458 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2459 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2460 case FSF_SQ_CFDC_SUBTABLE_LUN:
2461 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2462 zfcp_act_subtable_type[subtable], rule);
2466 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2467 zfcp_erp_port_access_denied(port);
2468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2471 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2472 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2473 "The remote port 0x%016Lx on adapter %s "
2474 "could not be opened. Disabling it.\n",
2475 port->wwpn, zfcp_get_busid_by_port(port));
2476 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2478 zfcp_erp_port_failed(port);
2479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2482 case FSF_ADAPTER_STATUS_AVAILABLE:
2483 switch (header->fsf_status_qual.word[0]) {
2484 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2485 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2487 /* ERP strategy will escalate */
2488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2490 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2491 /* ERP strategy will escalate */
2492 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2494 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2496 case FSF_SQ_NO_RETRY_POSSIBLE:
2497 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2498 "adapter %s could not be opened. "
2501 zfcp_get_busid_by_port(port));
2502 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2504 zfcp_erp_port_failed(port);
2505 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2509 ("bug: Wrong status qualifier 0x%x arrived.\n",
2510 header->fsf_status_qual.word[0]);
2511 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2514 fsf_req->adapter->erp_dbf, 0,
2515 &header->fsf_status_qual.word[0],
2522 /* save port handle assigned by FSF */
2523 port->handle = header->port_handle;
2524 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2525 "was opened, it's port handle is 0x%x\n",
2526 port->wwpn, zfcp_get_busid_by_port(port),
2528 /* mark port as open */
2529 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2530 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2531 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2532 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2535 /* check whether D_ID has changed during open */
2537 * FIXME: This check is not airtight, as the FCP channel does
2538 * not monitor closures of target port connections caused on
2539 * the remote side. Thus, they might miss out on invalidating
2540 * locally cached WWPNs (and other N_Port parameters) of gone
2541 * target ports. So, our heroic attempt to make things safe
2542 * could be undermined by 'open port' response data tagged with
2543 * obsolete WWPNs. Another reason to monitor potential
2544 * connection closures ourself at least (by interpreting
2545 * incoming ELS' and unsolicited status). It just crosses my
2546 * mind that one should be able to cross-check by means of
2547 * another GID_PN straight after a port has been opened.
2548 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2550 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2551 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2553 if (fsf_req->qtcb->bottom.support.els1_length <
2554 sizeof (struct fsf_plogi)) {
2556 "warning: insufficient length of "
2557 "PLOGI payload (%i)\n",
2558 fsf_req->qtcb->bottom.support.els1_length);
2559 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2560 "fsf_s_short_plogi:");
2561 /* skip sanity check and assume wwpn is ok */
2563 if (plogi->serv_param.wwpn != port->wwpn) {
2564 ZFCP_LOG_INFO("warning: d_id of port "
2565 "0x%016Lx changed during "
2566 "open\n", port->wwpn);
2568 fsf_req->adapter->erp_dbf, 0,
2569 "fsf_s_did_change:");
2571 ZFCP_STATUS_PORT_DID_DID,
2574 port->wwnn = plogi->serv_param.wwnn;
2575 zfcp_plogi_evaluate(port, plogi);
2581 case FSF_UNKNOWN_OP_SUBTYPE:
2582 /* should never occure, subtype not set in zfcp_fsf_open_port */
2583 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2584 "op_subtype=0x%x)\n",
2585 zfcp_get_busid_by_port(port),
2586 fsf_req->qtcb->bottom.support.operation_subtype);
2587 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2591 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2592 "(debug info 0x%x)\n",
2593 header->fsf_status);
2594 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2595 debug_exception(fsf_req->adapter->erp_dbf, 0,
2596 &header->fsf_status, sizeof (u32));
2601 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2606 * function: zfcp_fsf_close_port
2608 * purpose: submit FSF command "close port"
2610 * returns: address of initiated FSF request
2611 * NULL - request could not be initiated
2614 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2616 volatile struct qdio_buffer_element *sbale;
2617 struct zfcp_fsf_req *fsf_req;
2618 unsigned long lock_flags;
2621 /* setup new FSF request */
2622 retval = zfcp_fsf_req_create(erp_action->adapter,
2623 FSF_QTCB_CLOSE_PORT,
2624 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2625 erp_action->adapter->pool.fsf_req_erp,
2626 &lock_flags, &fsf_req);
2628 ZFCP_LOG_INFO("error: Could not create a close port request "
2629 "for port 0x%016Lx on adapter %s.\n",
2630 erp_action->port->wwpn,
2631 zfcp_get_busid_by_adapter(erp_action->adapter));
2635 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2636 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2637 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2639 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2640 fsf_req->data = (unsigned long) erp_action->port;
2641 fsf_req->erp_action = erp_action;
2642 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2643 fsf_req->erp_action = erp_action;
2644 erp_action->fsf_req = fsf_req;
2646 zfcp_erp_start_timer(fsf_req);
2647 retval = zfcp_fsf_req_send(fsf_req);
2649 ZFCP_LOG_INFO("error: Could not send a close port request for "
2650 "port 0x%016Lx on adapter %s.\n",
2651 erp_action->port->wwpn,
2652 zfcp_get_busid_by_adapter(erp_action->adapter));
2653 zfcp_fsf_req_free(fsf_req);
2654 erp_action->fsf_req = NULL;
2658 ZFCP_LOG_TRACE("close port request initiated "
2659 "(adapter %s, port 0x%016Lx)\n",
2660 zfcp_get_busid_by_adapter(erp_action->adapter),
2661 erp_action->port->wwpn);
2663 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2669 * function: zfcp_fsf_close_port_handler
2671 * purpose: is called for finished Close Port FSF command
2676 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2678 int retval = -EINVAL;
2679 struct zfcp_port *port;
2681 port = (struct zfcp_port *) fsf_req->data;
2683 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2684 /* don't change port status in our bookkeeping */
2685 goto skip_fsfstatus;
2688 /* evaluate FSF status in QTCB */
2689 switch (fsf_req->qtcb->header.fsf_status) {
2691 case FSF_PORT_HANDLE_NOT_VALID:
2692 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2693 "0x%016Lx on adapter %s invalid. This may happen "
2694 "occasionally.\n", port->handle,
2695 port->wwpn, zfcp_get_busid_by_port(port));
2696 ZFCP_LOG_DEBUG("status qualifier:\n");
2697 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2698 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2699 sizeof (union fsf_status_qual));
2700 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2702 zfcp_erp_adapter_reopen(port->adapter, 0);
2703 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2706 case FSF_ADAPTER_STATUS_AVAILABLE:
2707 /* Note: FSF has actually closed the port in this case.
2708 * The status code is just daft. Fingers crossed for a change
2714 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2715 "port handle 0x%x\n", port->wwpn,
2716 zfcp_get_busid_by_port(port), port->handle);
2717 zfcp_erp_modify_port_status(port,
2718 ZFCP_STATUS_COMMON_OPEN,
2724 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2725 "(debug info 0x%x)\n",
2726 fsf_req->qtcb->header.fsf_status);
2727 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2728 debug_exception(fsf_req->adapter->erp_dbf, 0,
2729 &fsf_req->qtcb->header.fsf_status,
2735 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2740 * function: zfcp_fsf_close_physical_port
2742 * purpose: submit FSF command "close physical port"
2744 * returns: address of initiated FSF request
2745 * NULL - request could not be initiated
2748 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2750 volatile struct qdio_buffer_element *sbale;
2751 struct zfcp_fsf_req *fsf_req;
2752 unsigned long lock_flags;
2755 /* setup new FSF request */
2756 retval = zfcp_fsf_req_create(erp_action->adapter,
2757 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2758 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2759 erp_action->adapter->pool.fsf_req_erp,
2760 &lock_flags, &fsf_req);
2762 ZFCP_LOG_INFO("error: Could not create close physical port "
2763 "request (adapter %s, port 0x%016Lx)\n",
2764 zfcp_get_busid_by_adapter(erp_action->adapter),
2765 erp_action->port->wwpn);
2770 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2771 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2772 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2774 /* mark port as being closed */
2775 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2776 &erp_action->port->status);
2777 /* save a pointer to this port */
2778 fsf_req->data = (unsigned long) erp_action->port;
2779 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2780 fsf_req->erp_action = erp_action;
2781 erp_action->fsf_req = fsf_req;
2783 zfcp_erp_start_timer(fsf_req);
2784 retval = zfcp_fsf_req_send(fsf_req);
2786 ZFCP_LOG_INFO("error: Could not send close physical port "
2787 "request (adapter %s, port 0x%016Lx)\n",
2788 zfcp_get_busid_by_adapter(erp_action->adapter),
2789 erp_action->port->wwpn);
2790 zfcp_fsf_req_free(fsf_req);
2791 erp_action->fsf_req = NULL;
2795 ZFCP_LOG_TRACE("close physical port request initiated "
2796 "(adapter %s, port 0x%016Lx)\n",
2797 zfcp_get_busid_by_adapter(erp_action->adapter),
2798 erp_action->port->wwpn);
2800 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2806 * function: zfcp_fsf_close_physical_port_handler
2808 * purpose: is called for finished Close Physical Port FSF command
2813 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2815 int retval = -EINVAL;
2816 struct zfcp_port *port;
2817 struct zfcp_unit *unit;
2818 struct fsf_qtcb_header *header;
2819 u16 subtable, rule, counter;
2821 port = (struct zfcp_port *) fsf_req->data;
2822 header = &fsf_req->qtcb->header;
2824 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2825 /* don't change port status in our bookkeeping */
2826 goto skip_fsfstatus;
2829 /* evaluate FSF status in QTCB */
2830 switch (header->fsf_status) {
2832 case FSF_PORT_HANDLE_NOT_VALID:
2833 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2834 "(adapter %s, port 0x%016Lx). "
2835 "This may happen occasionally.\n",
2837 zfcp_get_busid_by_port(port),
2839 ZFCP_LOG_DEBUG("status qualifier:\n");
2840 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2841 (char *) &header->fsf_status_qual,
2842 sizeof (union fsf_status_qual));
2843 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2845 zfcp_erp_adapter_reopen(port->adapter, 0);
2846 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2849 case FSF_ACCESS_DENIED:
2850 ZFCP_LOG_NORMAL("Access denied, cannot close "
2851 "physical port 0x%016Lx on adapter %s\n",
2852 port->wwpn, zfcp_get_busid_by_port(port));
2853 for (counter = 0; counter < 2; counter++) {
2854 subtable = header->fsf_status_qual.halfword[counter * 2];
2855 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2857 case FSF_SQ_CFDC_SUBTABLE_OS:
2858 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2859 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2860 case FSF_SQ_CFDC_SUBTABLE_LUN:
2861 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2862 zfcp_act_subtable_type[subtable], rule);
2866 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2867 zfcp_erp_port_access_denied(port);
2868 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2871 case FSF_PORT_BOXED:
2872 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2873 "%s needs to be reopened but it was attempted "
2874 "to close it physically.\n",
2876 zfcp_get_busid_by_port(port));
2877 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2878 zfcp_erp_port_boxed(port);
2879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2880 ZFCP_STATUS_FSFREQ_RETRY;
2883 case FSF_ADAPTER_STATUS_AVAILABLE:
2884 switch (header->fsf_status_qual.word[0]) {
2885 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2886 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2888 /* This will now be escalated by ERP */
2889 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2891 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2892 /* ERP strategy will escalate */
2893 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2899 ("bug: Wrong status qualifier 0x%x arrived.\n",
2900 header->fsf_status_qual.word[0]);
2901 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2904 fsf_req->adapter->erp_dbf, 0,
2905 &header->fsf_status_qual.word[0], sizeof (u32));
2911 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2912 "physically closed, port handle 0x%x\n",
2914 zfcp_get_busid_by_port(port), port->handle);
2915 /* can't use generic zfcp_erp_modify_port_status because
2916 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2918 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2919 list_for_each_entry(unit, &port->unit_list_head, list)
2920 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2925 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2926 "(debug info 0x%x)\n",
2927 header->fsf_status);
2928 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2929 debug_exception(fsf_req->adapter->erp_dbf, 0,
2930 &header->fsf_status, sizeof (u32));
2935 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2940 * function: zfcp_fsf_open_unit
2946 * assumptions: This routine does not check whether the associated
2947 * remote port has already been opened. This should be
2948 * done by calling routines. Otherwise some status
2949 * may be presented by FSF
2952 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2954 volatile struct qdio_buffer_element *sbale;
2955 struct zfcp_fsf_req *fsf_req;
2956 unsigned long lock_flags;
2959 /* setup new FSF request */
2960 retval = zfcp_fsf_req_create(erp_action->adapter,
2962 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2963 erp_action->adapter->pool.fsf_req_erp,
2964 &lock_flags, &fsf_req);
2966 ZFCP_LOG_INFO("error: Could not create open unit request for "
2967 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2968 erp_action->unit->fcp_lun,
2969 erp_action->unit->port->wwpn,
2970 zfcp_get_busid_by_adapter(erp_action->adapter));
2974 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2975 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2976 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2978 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2979 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
2980 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2981 fsf_req->qtcb->bottom.support.option =
2982 FSF_OPEN_LUN_SUPPRESS_BOXING;
2983 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2984 fsf_req->data = (unsigned long) erp_action->unit;
2985 fsf_req->erp_action = erp_action;
2986 erp_action->fsf_req = fsf_req;
2988 zfcp_erp_start_timer(fsf_req);
2989 retval = zfcp_fsf_req_send(erp_action->fsf_req);
2991 ZFCP_LOG_INFO("error: Could not send an open unit request "
2992 "on the adapter %s, port 0x%016Lx for "
2994 zfcp_get_busid_by_adapter(erp_action->adapter),
2995 erp_action->port->wwpn,
2996 erp_action->unit->fcp_lun);
2997 zfcp_fsf_req_free(fsf_req);
2998 erp_action->fsf_req = NULL;
3002 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3003 "port 0x%016Lx, unit 0x%016Lx)\n",
3004 zfcp_get_busid_by_adapter(erp_action->adapter),
3005 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3007 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3013 * function: zfcp_fsf_open_unit_handler
3015 * purpose: is called for finished Open LUN command
3020 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3022 int retval = -EINVAL;
3023 struct zfcp_adapter *adapter;
3024 struct zfcp_unit *unit;
3025 struct fsf_qtcb_header *header;
3026 struct fsf_qtcb_bottom_support *bottom;
3027 struct fsf_queue_designator *queue_designator;
3028 u16 subtable, rule, counter;
3029 int exclusive, readwrite;
3031 unit = (struct zfcp_unit *) fsf_req->data;
3033 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3034 /* don't change unit status in our bookkeeping */
3035 goto skip_fsfstatus;
3038 adapter = fsf_req->adapter;
3039 header = &fsf_req->qtcb->header;
3040 bottom = &fsf_req->qtcb->bottom.support;
3041 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3043 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3044 ZFCP_STATUS_UNIT_SHARED |
3045 ZFCP_STATUS_UNIT_READONLY,
3048 /* evaluate FSF status in QTCB */
3049 switch (header->fsf_status) {
3051 case FSF_PORT_HANDLE_NOT_VALID:
3052 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3053 "for port 0x%016Lx on adapter %s invalid "
3054 "This may happen occasionally\n",
3056 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3057 ZFCP_LOG_DEBUG("status qualifier:\n");
3058 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3059 (char *) &header->fsf_status_qual,
3060 sizeof (union fsf_status_qual));
3061 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3062 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3063 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3066 case FSF_LUN_ALREADY_OPEN:
3067 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3068 "remote port 0x%016Lx on adapter %s twice.\n",
3070 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3071 debug_text_exception(adapter->erp_dbf, 0,
3073 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3076 case FSF_ACCESS_DENIED:
3077 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3078 "remote port 0x%016Lx on adapter %s\n",
3079 unit->fcp_lun, unit->port->wwpn,
3080 zfcp_get_busid_by_unit(unit));
3081 for (counter = 0; counter < 2; counter++) {
3082 subtable = header->fsf_status_qual.halfword[counter * 2];
3083 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3085 case FSF_SQ_CFDC_SUBTABLE_OS:
3086 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3087 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3088 case FSF_SQ_CFDC_SUBTABLE_LUN:
3089 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3090 zfcp_act_subtable_type[subtable], rule);
3094 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3095 zfcp_erp_unit_access_denied(unit);
3096 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3097 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3098 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3101 case FSF_PORT_BOXED:
3102 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3103 "needs to be reopened\n",
3104 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3105 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3106 zfcp_erp_port_boxed(unit->port);
3107 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3108 ZFCP_STATUS_FSFREQ_RETRY;
3111 case FSF_LUN_SHARING_VIOLATION:
3112 if (header->fsf_status_qual.word[0] != 0) {
3113 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3115 "connected to the adapter %s "
3116 "is already in use in LPAR%d, CSS%d\n",
3119 zfcp_get_busid_by_unit(unit),
3120 queue_designator->hla,
3121 queue_designator->cssid);
3123 subtable = header->fsf_status_qual.halfword[4];
3124 rule = header->fsf_status_qual.halfword[5];
3126 case FSF_SQ_CFDC_SUBTABLE_OS:
3127 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3128 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3129 case FSF_SQ_CFDC_SUBTABLE_LUN:
3130 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3131 "remote port with WWPN 0x%Lx "
3132 "connected to the adapter %s "
3133 "is denied (%s rule %d)\n",
3136 zfcp_get_busid_by_unit(unit),
3137 zfcp_act_subtable_type[subtable],
3142 ZFCP_LOG_DEBUG("status qualifier:\n");
3143 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3144 (char *) &header->fsf_status_qual,
3145 sizeof (union fsf_status_qual));
3146 debug_text_event(adapter->erp_dbf, 2,
3148 zfcp_erp_unit_access_denied(unit);
3149 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3150 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3151 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3154 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3155 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3156 "There is no handle (temporary port identifier) "
3157 "available for unit 0x%016Lx on port 0x%016Lx "
3161 zfcp_get_busid_by_unit(unit));
3162 debug_text_event(adapter->erp_dbf, 1,
3164 zfcp_erp_unit_failed(unit);
3165 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3168 case FSF_ADAPTER_STATUS_AVAILABLE:
3169 switch (header->fsf_status_qual.word[0]) {
3170 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3171 /* Re-establish link to port */
3172 debug_text_event(adapter->erp_dbf, 1,
3174 zfcp_test_link(unit->port);
3175 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3177 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3178 /* ERP strategy will escalate */
3179 debug_text_event(adapter->erp_dbf, 1,
3181 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3185 ("bug: Wrong status qualifier 0x%x arrived.\n",
3186 header->fsf_status_qual.word[0]);
3187 debug_text_event(adapter->erp_dbf, 0,
3189 debug_exception(adapter->erp_dbf, 0,
3190 &header->fsf_status_qual.word[0],
3195 case FSF_INVALID_COMMAND_OPTION:
3197 "Invalid option 0x%x has been specified "
3198 "in QTCB bottom sent to the adapter %s\n",
3200 zfcp_get_busid_by_adapter(adapter));
3201 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3206 /* save LUN handle assigned by FSF */
3207 unit->handle = header->lun_handle;
3208 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3209 "adapter %s opened, port handle 0x%x\n",
3212 zfcp_get_busid_by_unit(unit),
3214 /* mark unit as open */
3215 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3217 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3218 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3219 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3220 exclusive = (bottom->lun_access_info &
3221 FSF_UNIT_ACCESS_EXCLUSIVE);
3222 readwrite = (bottom->lun_access_info &
3223 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3226 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3230 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3232 ZFCP_LOG_NORMAL("read-only access for unit "
3233 "(adapter %s, wwpn=0x%016Lx, "
3234 "fcp_lun=0x%016Lx)\n",
3235 zfcp_get_busid_by_unit(unit),
3240 if (exclusive && !readwrite) {
3241 ZFCP_LOG_NORMAL("exclusive access of read-only "
3242 "unit not supported\n");
3243 zfcp_erp_unit_failed(unit);
3244 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3245 zfcp_erp_unit_shutdown(unit, 0);
3246 } else if (!exclusive && readwrite) {
3247 ZFCP_LOG_NORMAL("shared access of read-write "
3248 "unit not supported\n");
3249 zfcp_erp_unit_failed(unit);
3250 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3251 zfcp_erp_unit_shutdown(unit, 0);
3259 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3260 "(debug info 0x%x)\n",
3261 header->fsf_status);
3262 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3263 debug_exception(adapter->erp_dbf, 0,
3264 &header->fsf_status, sizeof (u32));
3269 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3274 * function: zfcp_fsf_close_unit
3278 * returns: address of fsf_req - request successfully initiated
3281 * assumptions: This routine does not check whether the associated
3282 * remote port/lun has already been opened. This should be
3283 * done by calling routines. Otherwise some status
3284 * may be presented by FSF
3287 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3289 volatile struct qdio_buffer_element *sbale;
3290 struct zfcp_fsf_req *fsf_req;
3291 unsigned long lock_flags;
3294 /* setup new FSF request */
3295 retval = zfcp_fsf_req_create(erp_action->adapter,
3297 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3298 erp_action->adapter->pool.fsf_req_erp,
3299 &lock_flags, &fsf_req);
3301 ZFCP_LOG_INFO("error: Could not create close unit request for "
3302 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3303 erp_action->unit->fcp_lun,
3304 erp_action->port->wwpn,
3305 zfcp_get_busid_by_adapter(erp_action->adapter));
3309 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3310 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3311 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3313 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3314 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3315 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3316 fsf_req->data = (unsigned long) erp_action->unit;
3317 fsf_req->erp_action = erp_action;
3318 erp_action->fsf_req = fsf_req;
3320 zfcp_erp_start_timer(fsf_req);
3321 retval = zfcp_fsf_req_send(erp_action->fsf_req);
3323 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3324 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3325 erp_action->unit->fcp_lun,
3326 erp_action->port->wwpn,
3327 zfcp_get_busid_by_adapter(erp_action->adapter));
3328 zfcp_fsf_req_free(fsf_req);
3329 erp_action->fsf_req = NULL;
3333 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3334 "port 0x%016Lx, unit 0x%016Lx)\n",
3335 zfcp_get_busid_by_adapter(erp_action->adapter),
3336 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3338 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3344 * function: zfcp_fsf_close_unit_handler
3346 * purpose: is called for finished Close LUN FSF command
3351 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3353 int retval = -EINVAL;
3354 struct zfcp_unit *unit;
3356 unit = (struct zfcp_unit *) fsf_req->data;
3358 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3359 /* don't change unit status in our bookkeeping */
3360 goto skip_fsfstatus;
3363 /* evaluate FSF status in QTCB */
3364 switch (fsf_req->qtcb->header.fsf_status) {
3366 case FSF_PORT_HANDLE_NOT_VALID:
3367 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3368 "0x%016Lx on adapter %s invalid. This may "
3369 "happen in rare circumstances\n",
3372 zfcp_get_busid_by_unit(unit));
3373 ZFCP_LOG_DEBUG("status qualifier:\n");
3374 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3375 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3376 sizeof (union fsf_status_qual));
3377 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3379 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3380 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3383 case FSF_LUN_HANDLE_NOT_VALID:
3384 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3385 "0x%016Lx on port 0x%016Lx on adapter %s is "
3386 "invalid. This may happen occasionally.\n",
3390 zfcp_get_busid_by_unit(unit));
3391 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3392 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3393 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3394 sizeof (union fsf_status_qual));
3395 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3397 zfcp_erp_port_reopen(unit->port, 0);
3398 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3401 case FSF_PORT_BOXED:
3402 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3403 "needs to be reopened\n",
3405 zfcp_get_busid_by_unit(unit));
3406 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3407 zfcp_erp_port_boxed(unit->port);
3408 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3409 ZFCP_STATUS_FSFREQ_RETRY;
3412 case FSF_ADAPTER_STATUS_AVAILABLE:
3413 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3414 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3415 /* re-establish link to port */
3416 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3418 zfcp_test_link(unit->port);
3419 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3421 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3422 /* ERP strategy will escalate */
3423 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3425 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3429 ("bug: Wrong status qualifier 0x%x arrived.\n",
3430 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3431 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3434 fsf_req->adapter->erp_dbf, 0,
3435 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3442 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3443 "closed, port handle 0x%x\n",
3446 zfcp_get_busid_by_unit(unit),
3448 /* mark unit as closed */
3449 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3454 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3455 "(debug info 0x%x)\n",
3456 fsf_req->qtcb->header.fsf_status);
3457 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3458 debug_exception(fsf_req->adapter->erp_dbf, 0,
3459 &fsf_req->qtcb->header.fsf_status,
3465 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3470 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3471 * @adapter: adapter where scsi command is issued
3472 * @unit: unit where command is sent to
3473 * @scsi_cmnd: scsi command to be sent
3474 * @timer: timer to be started when request is initiated
3475 * @req_flags: flags for fsf_request
3478 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3479 struct zfcp_unit *unit,
3480 struct scsi_cmnd * scsi_cmnd,
3481 int use_timer, int req_flags)
3483 struct zfcp_fsf_req *fsf_req = NULL;
3484 struct fcp_cmnd_iu *fcp_cmnd_iu;
3485 unsigned int sbtype;
3486 unsigned long lock_flags;
3491 /* setup new FSF request */
3492 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3493 adapter->pool.fsf_req_scsi,
3494 &lock_flags, &fsf_req);
3495 if (unlikely(retval < 0)) {
3496 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3497 "for unit 0x%016Lx on port 0x%016Lx on "
3501 zfcp_get_busid_by_adapter(adapter));
3502 goto failed_req_create;
3505 zfcp_unit_get(unit);
3506 fsf_req->unit = unit;
3508 /* associate FSF request with SCSI request (for look up on abort) */
3509 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3511 /* associate SCSI command with FSF request */
3512 fsf_req->data = (unsigned long) scsi_cmnd;
3514 /* set handles of unit and its parent port in QTCB */
3515 fsf_req->qtcb->header.lun_handle = unit->handle;
3516 fsf_req->qtcb->header.port_handle = unit->port->handle;
3518 /* FSF does not define the structure of the FCP_CMND IU */
3519 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3520 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3523 * set depending on data direction:
3524 * data direction bits in SBALE (SB Type)
3525 * data direction bits in QTCB
3526 * data direction bits in FCP_CMND IU
3528 switch (scsi_cmnd->sc_data_direction) {
3530 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3533 * what is the correct type for commands
3534 * without 'real' data buffers?
3536 sbtype = SBAL_FLAGS0_TYPE_READ;
3538 case DMA_FROM_DEVICE:
3539 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3540 sbtype = SBAL_FLAGS0_TYPE_READ;
3541 fcp_cmnd_iu->rddata = 1;
3544 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3545 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3546 fcp_cmnd_iu->wddata = 1;
3548 case DMA_BIDIRECTIONAL:
3551 * dummy, catch this condition earlier
3552 * in zfcp_scsi_queuecommand
3554 goto failed_scsi_cmnd;
3557 /* set FC service class in QTCB (3 per default) */
3558 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3560 /* set FCP_LUN in FCP_CMND IU in QTCB */
3561 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3563 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3565 /* set task attributes in FCP_CMND IU in QTCB */
3566 if (likely((scsi_cmnd->device->simple_tags) ||
3567 (atomic_test_mask(mask, &unit->status))))
3568 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3570 fcp_cmnd_iu->task_attribute = UNTAGGED;
3572 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3573 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3574 fcp_cmnd_iu->add_fcp_cdb_length
3575 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3576 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3577 "additional FCP_CDB length is 0x%x "
3578 "(shifted right 2 bits)\n",
3580 fcp_cmnd_iu->add_fcp_cdb_length);
3583 * copy SCSI CDB (including additional length, if any) to
3584 * FCP_CDB in FCP_CMND IU in QTCB
3586 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3588 /* FCP CMND IU length in QTCB */
3589 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3590 sizeof (struct fcp_cmnd_iu) +
3591 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3593 /* generate SBALEs from data buffer */
3594 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3595 if (unlikely(real_bytes < 0)) {
3596 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3598 "Data did not fit into available buffer(s), "
3599 "waiting for more...\n");
3602 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3603 "required. Shutting down unit "
3604 "(adapter %s, port 0x%016Lx, "
3606 zfcp_get_busid_by_unit(unit),
3609 zfcp_erp_unit_shutdown(unit, 0);
3615 /* set length of FCP data length in FCP_CMND IU in QTCB */
3616 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3618 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3619 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3620 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3623 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3625 retval = zfcp_fsf_req_send(fsf_req);
3626 if (unlikely(retval < 0)) {
3627 ZFCP_LOG_INFO("error: Could not send FCP command request "
3628 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3629 zfcp_get_busid_by_adapter(adapter),
3635 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3636 "port 0x%016Lx, unit 0x%016Lx)\n",
3637 zfcp_get_busid_by_adapter(adapter),
3645 zfcp_unit_put(unit);
3646 zfcp_fsf_req_free(fsf_req);
3648 scsi_cmnd->host_scribble = NULL;
3651 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3655 struct zfcp_fsf_req *
3656 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3657 struct zfcp_unit *unit,
3658 u8 tm_flags, int req_flags)
3660 struct zfcp_fsf_req *fsf_req = NULL;
3662 struct fcp_cmnd_iu *fcp_cmnd_iu;
3663 unsigned long lock_flags;
3664 volatile struct qdio_buffer_element *sbale;
3666 /* setup new FSF request */
3667 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3668 adapter->pool.fsf_req_scsi,
3669 &lock_flags, &fsf_req);
3671 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3672 "management) request for adapter %s, port "
3673 " 0x%016Lx, unit 0x%016Lx.\n",
3674 zfcp_get_busid_by_adapter(adapter),
3675 unit->port->wwpn, unit->fcp_lun);
3680 * Used to decide on proper handler in the return path,
3681 * could be either zfcp_fsf_send_fcp_command_task_handler or
3682 * zfcp_fsf_send_fcp_command_task_management_handler */
3684 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3687 * hold a pointer to the unit being target of this
3688 * task management request
3690 fsf_req->data = (unsigned long) unit;
3692 /* set FSF related fields in QTCB */
3693 fsf_req->qtcb->header.lun_handle = unit->handle;
3694 fsf_req->qtcb->header.port_handle = unit->port->handle;
3695 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3696 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3697 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3698 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3700 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3701 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3702 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3704 /* set FCP related fields in FCP_CMND IU in QTCB */
3705 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3706 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3707 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3708 fcp_cmnd_iu->task_management_flags = tm_flags;
3710 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3711 retval = zfcp_fsf_req_send(fsf_req);
3713 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3714 "management) on adapter %s, port 0x%016Lx for "
3715 "unit LUN 0x%016Lx\n",
3716 zfcp_get_busid_by_adapter(adapter),
3719 zfcp_fsf_req_free(fsf_req);
3724 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3725 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3727 zfcp_get_busid_by_adapter(adapter),
3732 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3737 * function: zfcp_fsf_send_fcp_command_handler
3739 * purpose: is called for finished Send FCP Command
3744 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3746 int retval = -EINVAL;
3747 struct zfcp_unit *unit;
3748 struct fsf_qtcb_header *header;
3749 u16 subtable, rule, counter;
3751 header = &fsf_req->qtcb->header;
3753 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3754 unit = (struct zfcp_unit *) fsf_req->data;
3756 unit = fsf_req->unit;
3758 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3759 /* go directly to calls of special handlers */
3760 goto skip_fsfstatus;
3763 /* evaluate FSF status in QTCB */
3764 switch (header->fsf_status) {
3766 case FSF_PORT_HANDLE_NOT_VALID:
3767 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3768 "0x%016Lx on adapter %s invalid\n",
3770 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3771 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3772 (char *) &header->fsf_status_qual,
3773 sizeof (union fsf_status_qual));
3774 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3776 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3777 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3780 case FSF_LUN_HANDLE_NOT_VALID:
3781 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3782 "0x%016Lx on port 0x%016Lx on adapter %s is "
3783 "invalid. This may happen occasionally.\n",
3787 zfcp_get_busid_by_unit(unit));
3788 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3789 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3790 (char *) &header->fsf_status_qual,
3791 sizeof (union fsf_status_qual));
3792 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3794 zfcp_erp_port_reopen(unit->port, 0);
3795 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3798 case FSF_HANDLE_MISMATCH:
3799 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3800 "unexpectedly. (adapter %s, port 0x%016Lx, "
3803 zfcp_get_busid_by_unit(unit),
3806 ZFCP_LOG_NORMAL("status qualifier:\n");
3807 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3808 (char *) &header->fsf_status_qual,
3809 sizeof (union fsf_status_qual));
3810 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3812 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3813 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3816 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3817 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3819 zfcp_get_busid_by_unit(unit),
3820 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3821 /* stop operation for this adapter */
3822 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3823 "fsf_s_class_nsup");
3824 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3825 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3828 case FSF_FCPLUN_NOT_VALID:
3829 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3830 "adapter %s does not have correct unit "
3834 zfcp_get_busid_by_unit(unit),
3836 ZFCP_LOG_DEBUG("status qualifier:\n");
3837 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3838 (char *) &header->fsf_status_qual,
3839 sizeof (union fsf_status_qual));
3840 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3841 "fsf_s_fcp_lun_nv");
3842 zfcp_erp_port_reopen(unit->port, 0);
3843 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3846 case FSF_ACCESS_DENIED:
3847 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3848 "unit 0x%016Lx on port 0x%016Lx on "
3849 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3850 zfcp_get_busid_by_unit(unit));
3851 for (counter = 0; counter < 2; counter++) {
3852 subtable = header->fsf_status_qual.halfword[counter * 2];
3853 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3855 case FSF_SQ_CFDC_SUBTABLE_OS:
3856 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3857 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3858 case FSF_SQ_CFDC_SUBTABLE_LUN:
3859 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3860 zfcp_act_subtable_type[subtable], rule);
3864 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3865 zfcp_erp_unit_access_denied(unit);
3866 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3869 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3870 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3871 "0x%016Lx on port 0x%016Lx on adapter %s "
3872 "(debug info %d)\n",
3875 zfcp_get_busid_by_unit(unit),
3876 fsf_req->qtcb->bottom.io.data_direction);
3877 /* stop operation for this adapter */
3878 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3879 "fsf_s_dir_ind_nv");
3880 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3881 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3884 case FSF_CMND_LENGTH_NOT_VALID:
3886 ("bug: An invalid control-data-block length field "
3887 "was found in a command for unit 0x%016Lx on port "
3888 "0x%016Lx on adapter %s " "(debug info %d)\n",
3889 unit->fcp_lun, unit->port->wwpn,
3890 zfcp_get_busid_by_unit(unit),
3891 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3892 /* stop operation for this adapter */
3893 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3894 "fsf_s_cmd_len_nv");
3895 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3896 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3899 case FSF_PORT_BOXED:
3900 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3901 "needs to be reopened\n",
3902 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3903 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3904 zfcp_erp_port_boxed(unit->port);
3905 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3906 ZFCP_STATUS_FSFREQ_RETRY;
3910 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3911 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3912 zfcp_get_busid_by_unit(unit),
3913 unit->port->wwpn, unit->fcp_lun);
3914 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3915 zfcp_erp_unit_boxed(unit);
3916 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3917 | ZFCP_STATUS_FSFREQ_RETRY;
3920 case FSF_ADAPTER_STATUS_AVAILABLE:
3921 switch (header->fsf_status_qual.word[0]) {
3922 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3923 /* re-establish link to port */
3924 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3926 zfcp_test_link(unit->port);
3928 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3929 /* FIXME(hw) need proper specs for proper action */
3930 /* let scsi stack deal with retries and escalation */
3931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3936 ("Unknown status qualifier 0x%x arrived.\n",
3937 header->fsf_status_qual.word[0]);
3938 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3940 debug_exception(fsf_req->adapter->erp_dbf, 0,
3941 &header->fsf_status_qual.word[0],
3945 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3951 case FSF_FCP_RSP_AVAILABLE:
3955 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3956 debug_exception(fsf_req->adapter->erp_dbf, 0,
3957 &header->fsf_status, sizeof(u32));
3962 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3964 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3966 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3967 fsf_req->unit = NULL;
3968 zfcp_unit_put(unit);
3974 * function: zfcp_fsf_send_fcp_command_task_handler
3976 * purpose: evaluates FCP_RSP IU
3981 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3984 struct scsi_cmnd *scpnt;
3985 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3986 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3987 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3988 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3990 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3991 unsigned long flags;
3992 struct zfcp_unit *unit = fsf_req->unit;
3994 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3995 scpnt = (struct scsi_cmnd *) fsf_req->data;
3996 if (unlikely(!scpnt)) {
3998 ("Command with fsf_req %p is not associated to "
3999 "a scsi command anymore. Aborted?\n", fsf_req);
4002 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4003 /* FIXME: (design) mid-layer should handle DID_ABORT like
4004 * DID_SOFT_ERROR by retrying the request for devices
4005 * that allow retries.
4007 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4008 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4009 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4010 goto skip_fsfstatus;
4013 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4014 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4015 set_host_byte(&scpnt->result, DID_ERROR);
4016 goto skip_fsfstatus;
4019 /* set message byte of result in SCSI command */
4020 scpnt->result |= COMMAND_COMPLETE << 8;
4023 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4024 * of result in SCSI command
4026 scpnt->result |= fcp_rsp_iu->scsi_status;
4027 if (unlikely(fcp_rsp_iu->scsi_status)) {
4029 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4030 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4031 scpnt->cmnd, scpnt->cmd_len);
4032 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4033 fcp_rsp_iu->scsi_status);
4034 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4035 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4036 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4037 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4038 fcp_rsp_iu->fcp_sns_len);
4041 /* check FCP_RSP_INFO */
4042 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4043 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4044 switch (fcp_rsp_info[3]) {
4047 ZFCP_LOG_TRACE("no failure or Task Management "
4048 "Function complete\n");
4049 set_host_byte(&scpnt->result, DID_OK);
4051 case RSP_CODE_LENGTH_MISMATCH:
4053 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4054 "that the fibrechannel protocol data "
4055 "length differs from the burst length. "
4056 "The problem occured on unit 0x%016Lx "
4057 "on port 0x%016Lx on adapter %s",
4060 zfcp_get_busid_by_unit(unit));
4061 /* dump SCSI CDB as prepared by zfcp */
4062 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4063 (char *) &fsf_req->qtcb->
4064 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4065 set_host_byte(&scpnt->result, DID_ERROR);
4066 goto skip_fsfstatus;
4067 case RSP_CODE_FIELD_INVALID:
4068 /* driver or hardware bug */
4069 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4070 "that the fibrechannel protocol data "
4071 "fields were incorrectly set up. "
4072 "The problem occured on the unit "
4073 "0x%016Lx on port 0x%016Lx on "
4077 zfcp_get_busid_by_unit(unit));
4078 /* dump SCSI CDB as prepared by zfcp */
4079 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4080 (char *) &fsf_req->qtcb->
4081 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4082 set_host_byte(&scpnt->result, DID_ERROR);
4083 goto skip_fsfstatus;
4084 case RSP_CODE_RO_MISMATCH:
4086 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4087 "that conflicting values for the "
4088 "fibrechannel payload offset from the "
4089 "header were found. "
4090 "The problem occured on unit 0x%016Lx "
4091 "on port 0x%016Lx on adapter %s.\n",
4094 zfcp_get_busid_by_unit(unit));
4095 /* dump SCSI CDB as prepared by zfcp */
4096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4097 (char *) &fsf_req->qtcb->
4098 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4099 set_host_byte(&scpnt->result, DID_ERROR);
4100 goto skip_fsfstatus;
4102 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4103 "code was detected for a command. "
4104 "The problem occured on the unit "
4105 "0x%016Lx on port 0x%016Lx on "
4106 "adapter %s (debug info 0x%x)\n",
4109 zfcp_get_busid_by_unit(unit),
4111 /* dump SCSI CDB as prepared by zfcp */
4112 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4113 (char *) &fsf_req->qtcb->
4114 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4115 set_host_byte(&scpnt->result, DID_ERROR);
4116 goto skip_fsfstatus;
4120 /* check for sense data */
4121 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4122 sns_len = FSF_FCP_RSP_SIZE -
4123 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4124 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4126 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4127 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4128 SCSI_SENSE_BUFFERSIZE);
4129 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4130 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4132 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4133 (void *) &scpnt->cmnd, scpnt->cmd_len);
4135 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4136 fcp_rsp_iu->fcp_sns_len);
4137 memcpy(&scpnt->sense_buffer,
4138 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4139 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4140 (void *) &scpnt->sense_buffer, sns_len);
4143 /* check for overrun */
4144 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4145 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4146 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4147 "The response data length is "
4148 "%d, the original length was %d.\n",
4151 zfcp_get_busid_by_unit(unit),
4152 fcp_rsp_iu->fcp_resid,
4153 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4156 /* check for underrun */
4157 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4158 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4159 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4160 "The response data length is "
4161 "%d, the original length was %d.\n",
4164 zfcp_get_busid_by_unit(unit),
4165 fcp_rsp_iu->fcp_resid,
4166 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4168 scpnt->resid = fcp_rsp_iu->fcp_resid;
4169 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4170 set_host_byte(&scpnt->result, DID_ERROR);
4174 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4176 if (scpnt->result != 0)
4177 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4178 else if (scpnt->retries > 0)
4179 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4181 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4183 /* cleanup pointer (need this especially for abort) */
4184 scpnt->host_scribble = NULL;
4186 /* always call back */
4187 (scpnt->scsi_done) (scpnt);
4190 * We must hold this lock until scsi_done has been called.
4191 * Otherwise we may call scsi_done after abort regarding this
4192 * command has completed.
4193 * Note: scsi_done must not block!
4196 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4201 * function: zfcp_fsf_send_fcp_command_task_management_handler
4203 * purpose: evaluates FCP_RSP IU
4208 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4211 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4212 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4213 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4214 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4216 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4217 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4218 goto skip_fsfstatus;
4221 /* check FCP_RSP_INFO */
4222 switch (fcp_rsp_info[3]) {
4225 ZFCP_LOG_DEBUG("no failure or Task Management "
4226 "Function complete\n");
4228 case RSP_CODE_TASKMAN_UNSUPP:
4229 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4230 "is not supported on the target device "
4231 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4234 zfcp_get_busid_by_unit(unit));
4235 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4237 case RSP_CODE_TASKMAN_FAILED:
4238 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4239 "failed to complete successfully. "
4240 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4243 zfcp_get_busid_by_unit(unit));
4244 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4247 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4248 "code was detected for a command. "
4249 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4250 "(debug info 0x%x)\n",
4253 zfcp_get_busid_by_unit(unit),
4255 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4264 * function: zfcp_fsf_control_file
4266 * purpose: Initiator of the control file upload/download FSF requests
4268 * returns: 0 - FSF request is successfuly created and queued
4269 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4270 * -EINVAL - Invalid direction specified
4271 * -ENOMEM - Insufficient memory
4272 * -EPERM - Cannot create FSF request or place it in QDIO queue
4275 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4276 struct zfcp_fsf_req **fsf_req_ptr,
4279 struct zfcp_sg_list *sg_list)
4281 struct zfcp_fsf_req *fsf_req;
4282 struct fsf_qtcb_bottom_support *bottom;
4283 volatile struct qdio_buffer_element *sbale;
4284 unsigned long lock_flags;
4289 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4290 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4291 zfcp_get_busid_by_adapter(adapter));
4292 retval = -EOPNOTSUPP;
4296 switch (fsf_command) {
4298 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4299 direction = SBAL_FLAGS0_TYPE_WRITE;
4300 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4301 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4302 req_flags = ZFCP_WAIT_FOR_SBAL;
4305 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4306 direction = SBAL_FLAGS0_TYPE_READ;
4310 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4315 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4316 NULL, &lock_flags, &fsf_req);
4318 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4320 zfcp_get_busid_by_adapter(adapter));
4322 goto unlock_queue_lock;
4325 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4326 sbale[0].flags |= direction;
4328 bottom = &fsf_req->qtcb->bottom.support;
4329 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4330 bottom->option = option;
4332 if (sg_list->count > 0) {
4335 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4336 sg_list->sg, sg_list->count,
4337 ZFCP_MAX_SBALS_PER_REQ);
4338 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4340 "error: Could not create sufficient number of "
4341 "SBALS for an FSF request to the adapter %s\n",
4342 zfcp_get_busid_by_adapter(adapter));
4347 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4349 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4350 retval = zfcp_fsf_req_send(fsf_req);
4352 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4354 zfcp_get_busid_by_adapter(adapter));
4358 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4360 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4362 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4363 "download" : "upload",
4364 zfcp_get_busid_by_adapter(adapter));
4366 wait_event(fsf_req->completion_wq,
4367 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4369 *fsf_req_ptr = fsf_req;
4373 zfcp_fsf_req_free(fsf_req);
4375 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4382 * function: zfcp_fsf_control_file_handler
4384 * purpose: Handler of the control file upload/download FSF requests
4386 * returns: 0 - FSF request successfuly processed
4387 * -EAGAIN - Operation has to be repeated because of a temporary problem
4388 * -EACCES - There is no permission to execute an operation
4389 * -EPERM - The control file is not in a right format
4390 * -EIO - There is a problem with the FCP adapter
4391 * -EINVAL - Invalid operation
4392 * -EFAULT - User space memory I/O operation fault
4395 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4397 struct zfcp_adapter *adapter = fsf_req->adapter;
4398 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4399 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4402 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4404 goto skip_fsfstatus;
4407 switch (header->fsf_status) {
4411 "The FSF request has been successfully completed "
4412 "on the adapter %s\n",
4413 zfcp_get_busid_by_adapter(adapter));
4416 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4417 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4418 switch (header->fsf_status_qual.word[0]) {
4420 case FSF_SQ_CFDC_HARDENED_ON_SE:
4422 "CFDC on the adapter %s has being "
4423 "hardened on primary and secondary SE\n",
4424 zfcp_get_busid_by_adapter(adapter));
4427 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4429 "CFDC of the adapter %s could not "
4430 "be saved on the SE\n",
4431 zfcp_get_busid_by_adapter(adapter));
4434 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4436 "CFDC of the adapter %s could not "
4437 "be copied to the secondary SE\n",
4438 zfcp_get_busid_by_adapter(adapter));
4443 "CFDC could not be hardened "
4444 "on the adapter %s\n",
4445 zfcp_get_busid_by_adapter(adapter));
4448 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4452 case FSF_AUTHORIZATION_FAILURE:
4454 "Adapter %s does not accept privileged commands\n",
4455 zfcp_get_busid_by_adapter(adapter));
4456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4460 case FSF_CFDC_ERROR_DETECTED:
4462 "Error at position %d in the CFDC, "
4463 "CFDC is discarded by the adapter %s\n",
4464 header->fsf_status_qual.word[0],
4465 zfcp_get_busid_by_adapter(adapter));
4466 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4470 case FSF_CONTROL_FILE_UPDATE_ERROR:
4472 "Adapter %s cannot harden the control file, "
4473 "file is discarded\n",
4474 zfcp_get_busid_by_adapter(adapter));
4475 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4479 case FSF_CONTROL_FILE_TOO_LARGE:
4481 "Control file is too large, file is discarded "
4482 "by the adapter %s\n",
4483 zfcp_get_busid_by_adapter(adapter));
4484 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4488 case FSF_ACCESS_CONFLICT_DETECTED:
4489 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4491 "CFDC has been discarded by the adapter %s, "
4492 "because activation would impact "
4493 "%d active connection(s)\n",
4494 zfcp_get_busid_by_adapter(adapter),
4495 header->fsf_status_qual.word[0]);
4496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4500 case FSF_CONFLICTS_OVERRULED:
4501 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4503 "CFDC has been activated on the adapter %s, "
4504 "but activation has impacted "
4505 "%d active connection(s)\n",
4506 zfcp_get_busid_by_adapter(adapter),
4507 header->fsf_status_qual.word[0]);
4508 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4512 case FSF_UNKNOWN_OP_SUBTYPE:
4513 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4514 "op_subtype=0x%x)\n",
4515 zfcp_get_busid_by_adapter(adapter),
4516 bottom->operation_subtype);
4517 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4521 case FSF_INVALID_COMMAND_OPTION:
4523 "Invalid option 0x%x has been specified "
4524 "in QTCB bottom sent to the adapter %s\n",
4526 zfcp_get_busid_by_adapter(adapter));
4527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4533 "bug: An unknown/unexpected FSF status 0x%08x "
4534 "was presented on the adapter %s\n",
4536 zfcp_get_busid_by_adapter(adapter));
4537 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4538 debug_exception(fsf_req->adapter->erp_dbf, 0,
4539 &header->fsf_status_qual.word[0], sizeof(u32));
4540 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4550 zfcp_fsf_req_sbal_check(unsigned long *flags,
4551 struct zfcp_qdio_queue *queue, int needed)
4553 write_lock_irqsave(&queue->queue_lock, *flags);
4554 if (likely(atomic_read(&queue->free_count) >= needed))
4556 write_unlock_irqrestore(&queue->queue_lock, *flags);
4561 * set qtcb pointer in fsf_req and initialize QTCB
4564 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4566 if (likely(fsf_req->qtcb != NULL)) {
4567 fsf_req->qtcb->prefix.req_seq_no =
4568 fsf_req->adapter->fsf_req_seq_no;
4569 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4570 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4571 fsf_req->qtcb->prefix.qtcb_type =
4572 fsf_qtcb_type[fsf_req->fsf_command];
4573 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4574 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4575 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4580 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4581 * @adapter: adapter for which request queue is examined
4582 * @req_flags: flags indicating whether to wait for needed SBAL or not
4583 * @lock_flags: lock_flags if queue_lock is taken
4584 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4585 * Locks: lock adapter->request_queue->queue_lock on success
4588 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4589 unsigned long *lock_flags)
4592 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4594 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4595 ret = wait_event_interruptible_timeout(adapter->request_wq,
4596 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4602 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4609 * function: zfcp_fsf_req_create
4611 * purpose: create an FSF request at the specified adapter and
4612 * setup common fields
4614 * returns: -ENOMEM if there was insufficient memory for a request
4615 * -EIO if no qdio buffers could be allocate to the request
4616 * -EINVAL/-EPERM on bug conditions in req_dequeue
4619 * note: The created request is returned by reference.
4621 * locks: lock of concerned request queue must not be held,
4622 * but is held on completion (write, irqsave)
4625 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4626 mempool_t *pool, unsigned long *lock_flags,
4627 struct zfcp_fsf_req **fsf_req_p)
4629 volatile struct qdio_buffer_element *sbale;
4630 struct zfcp_fsf_req *fsf_req = NULL;
4632 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4634 /* allocate new FSF request */
4635 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4636 if (unlikely(NULL == fsf_req)) {
4637 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4638 "the outbound (send) queue.\n");
4640 goto failed_fsf_req;
4643 fsf_req->adapter = adapter;
4644 fsf_req->fsf_command = fsf_cmd;
4645 INIT_LIST_HEAD(&fsf_req->list);
4647 /* this is serialized (we are holding req_queue-lock of adapter */
4648 if (adapter->req_no == 0)
4650 fsf_req->req_id = adapter->req_no++;
4652 init_timer(&fsf_req->timer);
4653 zfcp_fsf_req_qtcb_init(fsf_req);
4655 /* initialize waitqueue which may be used to wait on
4656 this request completion */
4657 init_waitqueue_head(&fsf_req->completion_wq);
4659 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4665 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4666 * if it is not set (see also *_open_qdio and *_close_qdio).
4669 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4670 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4675 if (fsf_req->qtcb) {
4676 fsf_req->seq_no = adapter->fsf_req_seq_no;
4677 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4679 fsf_req->sbal_number = 1;
4680 fsf_req->sbal_first = req_queue->free_index;
4681 fsf_req->sbal_curr = req_queue->free_index;
4682 fsf_req->sbale_curr = 1;
4684 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4685 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4688 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4690 /* setup common SBALE fields */
4691 sbale[0].addr = (void *) fsf_req->req_id;
4692 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4693 if (likely(fsf_req->qtcb != NULL)) {
4694 sbale[1].addr = (void *) fsf_req->qtcb;
4695 sbale[1].length = sizeof(struct fsf_qtcb);
4698 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4699 fsf_req->sbal_number, fsf_req->sbal_first);
4704 /* dequeue new FSF request previously enqueued */
4705 zfcp_fsf_req_free(fsf_req);
4709 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4711 *fsf_req_p = fsf_req;
4716 * function: zfcp_fsf_req_send
4718 * purpose: start transfer of FSF request via QDIO
4720 * returns: 0 - request transfer succesfully started
4721 * !0 - start of request transfer failed
4723 static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
4725 struct zfcp_adapter *adapter;
4726 struct zfcp_qdio_queue *req_queue;
4727 volatile struct qdio_buffer_element *sbale;
4729 int new_distance_from_int;
4733 adapter = fsf_req->adapter;
4734 req_queue = &adapter->request_queue,
4737 /* FIXME(debug): remove it later */
4738 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4739 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4740 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4741 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4744 /* put allocated FSF request into hash table */
4745 spin_lock(&adapter->req_list_lock);
4746 zfcp_reqlist_add(adapter, fsf_req);
4747 spin_unlock(&adapter->req_list_lock);
4749 inc_seq_no = (fsf_req->qtcb != NULL);
4751 ZFCP_LOG_TRACE("request queue of adapter %s: "
4752 "next free SBAL is %i, %i free SBALs\n",
4753 zfcp_get_busid_by_adapter(adapter),
4754 req_queue->free_index,
4755 atomic_read(&req_queue->free_count));
4757 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4758 "index_in_queue=%i, count=%i, buffers=%p\n",
4759 zfcp_get_busid_by_adapter(adapter),
4760 QDIO_FLAG_SYNC_OUTPUT,
4761 0, fsf_req->sbal_first, fsf_req->sbal_number,
4762 &req_queue->buffer[fsf_req->sbal_first]);
4765 * adjust the number of free SBALs in request queue as well as
4766 * position of first one
4768 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4769 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4770 req_queue->free_index += fsf_req->sbal_number; /* increase */
4771 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4772 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4774 fsf_req->issued = get_clock();
4776 retval = do_QDIO(adapter->ccw_device,
4777 QDIO_FLAG_SYNC_OUTPUT,
4778 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4780 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4781 dbg_tmp[1] = (u64) retval;
4782 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4784 if (unlikely(retval)) {
4785 /* Queues are down..... */
4787 del_timer(&fsf_req->timer);
4788 spin_lock(&adapter->req_list_lock);
4789 zfcp_reqlist_remove(adapter, fsf_req->req_id);
4790 spin_unlock(&adapter->req_list_lock);
4791 /* undo changes in request queue made for this request */
4792 zfcp_qdio_zero_sbals(req_queue->buffer,
4793 fsf_req->sbal_first, fsf_req->sbal_number);
4794 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4795 req_queue->free_index -= fsf_req->sbal_number;
4796 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4797 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4798 zfcp_erp_adapter_reopen(adapter, 0);
4800 req_queue->distance_from_int = new_distance_from_int;
4802 * increase FSF sequence counter -
4803 * this must only be done for request successfully enqueued to
4804 * QDIO this rejected requests may be cleaned up by calling
4805 * routines resulting in missing sequence counter values
4809 /* Don't increase for unsolicited status */
4811 adapter->fsf_req_seq_no++;
4813 /* count FSF requests pending */
4814 atomic_inc(&adapter->reqs_active);
4819 #undef ZFCP_LOG_AREA