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_fsf_req *, u8,
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 * Never ever call this without shutting down the adapter first.
161 * Otherwise the adapter would continue using and corrupting s390 storage.
162 * Included BUG_ON() call to ensure this is done.
163 * ERP is supposed to be the only user of this function.
165 void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
167 struct zfcp_fsf_req *fsf_req, *tmp;
169 LIST_HEAD(remove_queue);
172 BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
173 spin_lock_irqsave(&adapter->req_list_lock, flags);
174 atomic_set(&adapter->reqs_active, 0);
175 for (i = 0; i < REQUEST_LIST_SIZE; i++)
176 list_splice_init(&adapter->req_list[i], &remove_queue);
177 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
179 list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
180 list_del(&fsf_req->list);
181 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
182 zfcp_fsf_req_complete(fsf_req);
187 * function: zfcp_fsf_req_complete
189 * purpose: Updates active counts and timers for openfcp-reqs
190 * May cleanup request after req_eval returns
192 * returns: 0 - success
198 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
203 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
204 ZFCP_LOG_DEBUG("Status read response received\n");
206 * Note: all cleanup handling is done in the callchain of
207 * the function call-chain below.
209 zfcp_fsf_status_read_handler(fsf_req);
212 del_timer(&fsf_req->timer);
213 zfcp_fsf_protstatus_eval(fsf_req);
217 * fsf_req may be deleted due to waking up functions, so
218 * cleanup is saved here and used later
220 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
225 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
227 /* cleanup request if requested by initiator */
228 if (likely(cleanup)) {
229 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
231 * lock must not be held here since it will be
232 * grabed by the called routine, too
234 zfcp_fsf_req_free(fsf_req);
236 /* notify initiator waiting for the requests completion */
237 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
239 * FIXME: Race! We must not access fsf_req here as it might have been
240 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
241 * flag. It's an improbable case. But, we have the same paranoia for
242 * the cleanup flag already.
243 * Might better be handled using complete()?
244 * (setting the flag and doing wakeup ought to be atomic
245 * with regard to checking the flag as long as waitqueue is
246 * part of the to be released structure)
248 wake_up(&fsf_req->completion_wq);
256 * function: zfcp_fsf_protstatus_eval
258 * purpose: evaluates the QTCB of the finished FSF request
259 * and initiates appropriate actions
260 * (usually calling FSF command specific handlers)
269 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
272 struct zfcp_adapter *adapter = fsf_req->adapter;
273 struct fsf_qtcb *qtcb = fsf_req->qtcb;
274 union fsf_prot_status_qual *prot_status_qual =
275 &qtcb->prefix.prot_status_qual;
277 zfcp_hba_dbf_event_fsf_response(fsf_req);
279 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
280 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
281 (unsigned long) fsf_req);
282 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
283 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
284 goto skip_protstatus;
287 /* evaluate FSF Protocol Status */
288 switch (qtcb->prefix.prot_status) {
291 case FSF_PROT_FSF_STATUS_PRESENTED:
294 case FSF_PROT_QTCB_VERSION_ERROR:
295 ZFCP_LOG_NORMAL("error: The adapter %s contains "
296 "microcode of version 0x%x, the device driver "
297 "only supports 0x%x. Aborting.\n",
298 zfcp_get_busid_by_adapter(adapter),
299 prot_status_qual->version_error.fsf_version,
301 zfcp_erp_adapter_shutdown(adapter, 0, 117, (u64)fsf_req);
302 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
305 case FSF_PROT_SEQ_NUMB_ERROR:
306 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
307 "driver (0x%x) and adapter %s (0x%x). "
308 "Restarting all operations on this adapter.\n",
309 qtcb->prefix.req_seq_no,
310 zfcp_get_busid_by_adapter(adapter),
311 prot_status_qual->sequence_error.exp_req_seq_no);
312 zfcp_erp_adapter_reopen(adapter, 0, 98, (u64)fsf_req);
313 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
314 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
317 case FSF_PROT_UNSUPP_QTCB_TYPE:
318 ZFCP_LOG_NORMAL("error: Packet header type used by the "
319 "device driver is incompatible with "
320 "that used on adapter %s. "
321 "Stopping all operations on this adapter.\n",
322 zfcp_get_busid_by_adapter(adapter));
323 zfcp_erp_adapter_shutdown(adapter, 0, 118, (u64)fsf_req);
324 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
327 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
328 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
329 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
333 case FSF_PROT_DUPLICATE_REQUEST_ID:
334 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
335 "to the adapter %s is ambiguous. "
336 "Stopping all operations on this adapter.\n",
337 *(unsigned long long*)
338 (&qtcb->bottom.support.req_handle),
339 zfcp_get_busid_by_adapter(adapter));
340 zfcp_erp_adapter_shutdown(adapter, 0, 78, (u64)fsf_req);
341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
344 case FSF_PROT_LINK_DOWN:
345 zfcp_fsf_link_down_info_eval(fsf_req, 37,
346 &prot_status_qual->link_down_info);
347 /* FIXME: reopening adapter now? better wait for link up */
348 zfcp_erp_adapter_reopen(adapter, 0, 79, (u64)fsf_req);
349 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
352 case FSF_PROT_REEST_QUEUE:
353 ZFCP_LOG_NORMAL("The local link to adapter with "
354 "%s was re-plugged. "
355 "Re-starting operations on this adapter.\n",
356 zfcp_get_busid_by_adapter(adapter));
357 /* All ports should be marked as ready to run again */
358 zfcp_erp_modify_adapter_status(adapter, 28,
359 0, ZFCP_STATUS_COMMON_RUNNING,
361 zfcp_erp_adapter_reopen(adapter,
362 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
363 | ZFCP_STATUS_COMMON_ERP_FAILED,
365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
368 case FSF_PROT_ERROR_STATE:
369 ZFCP_LOG_NORMAL("error: The adapter %s "
370 "has entered the error state. "
371 "Restarting all operations on this "
373 zfcp_get_busid_by_adapter(adapter));
374 zfcp_erp_adapter_reopen(adapter, 0, 100, (u64)fsf_req);
375 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
376 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
380 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
381 "provided by the adapter %s "
382 "is not compatible with the device driver. "
383 "Stopping all operations on this adapter. "
384 "(debug info 0x%x).\n",
385 zfcp_get_busid_by_adapter(adapter),
386 qtcb->prefix.prot_status);
387 zfcp_erp_adapter_shutdown(adapter, 0, 119, (u64)fsf_req);
388 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
393 * always call specific handlers to give them a chance to do
394 * something meaningful even in error cases
396 zfcp_fsf_fsfstatus_eval(fsf_req);
401 * function: zfcp_fsf_fsfstatus_eval
403 * purpose: evaluates FSF status of completed FSF request
404 * and acts accordingly
409 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
413 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
417 /* evaluate FSF Status */
418 switch (fsf_req->qtcb->header.fsf_status) {
419 case FSF_UNKNOWN_COMMAND:
420 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
421 "not known by the adapter %s "
422 "Stopping all operations on this adapter. "
423 "(debug info 0x%x).\n",
424 zfcp_get_busid_by_adapter(fsf_req->adapter),
425 fsf_req->qtcb->header.fsf_command);
426 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120,
428 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
431 case FSF_FCP_RSP_AVAILABLE:
432 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
436 case FSF_ADAPTER_STATUS_AVAILABLE:
437 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
443 * always call specific handlers to give them a chance to do
444 * something meaningful even in error cases
446 zfcp_fsf_req_dispatch(fsf_req);
452 * function: zfcp_fsf_fsfstatus_qual_eval
454 * purpose: evaluates FSF status-qualifier of completed FSF request
455 * and acts accordingly
460 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
464 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
465 case FSF_SQ_FCP_RSP_AVAILABLE:
467 case FSF_SQ_RETRY_IF_POSSIBLE:
468 /* The SCSI-stack may now issue retries or escalate */
469 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
471 case FSF_SQ_COMMAND_ABORTED:
472 /* Carry the aborted state on to upper layer */
473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
474 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
476 case FSF_SQ_NO_RECOM:
477 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
478 "problem on the adapter %s "
479 "Stopping all operations on this adapter. ",
480 zfcp_get_busid_by_adapter(fsf_req->adapter));
481 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121,
483 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
485 case FSF_SQ_ULP_PROGRAMMING_ERROR:
486 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
488 zfcp_get_busid_by_adapter(fsf_req->adapter));
489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
491 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
492 case FSF_SQ_NO_RETRY_POSSIBLE:
493 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
494 /* dealt with in the respective functions */
497 ZFCP_LOG_NORMAL("bug: Additional status info could "
498 "not be interpreted properly.\n");
499 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
500 (char *) &fsf_req->qtcb->header.fsf_status_qual,
501 sizeof (union fsf_status_qual));
502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
510 * zfcp_fsf_link_down_info_eval - evaluate link down information block
513 zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
514 struct fsf_link_down_info *link_down)
516 struct zfcp_adapter *adapter = fsf_req->adapter;
518 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
522 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
524 if (link_down == NULL)
527 switch (link_down->error_code) {
528 case FSF_PSQ_LINK_NO_LIGHT:
529 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
530 "(no light detected)\n",
531 zfcp_get_busid_by_adapter(adapter));
533 case FSF_PSQ_LINK_WRAP_PLUG:
534 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
535 "(wrap plug detected)\n",
536 zfcp_get_busid_by_adapter(adapter));
538 case FSF_PSQ_LINK_NO_FCP:
539 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
540 "(adjacent node on link does not support FCP)\n",
541 zfcp_get_busid_by_adapter(adapter));
543 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
544 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
545 "(firmware update in progress)\n",
546 zfcp_get_busid_by_adapter(adapter));
548 case FSF_PSQ_LINK_INVALID_WWPN:
549 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
550 "(duplicate or invalid WWPN detected)\n",
551 zfcp_get_busid_by_adapter(adapter));
553 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
554 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
555 "(no support for NPIV by Fabric)\n",
556 zfcp_get_busid_by_adapter(adapter));
558 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(out of resource in FCP daughtercard)\n",
561 zfcp_get_busid_by_adapter(adapter));
563 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(out of resource in Fabric)\n",
566 zfcp_get_busid_by_adapter(adapter));
568 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(unable to Fabric login)\n",
571 zfcp_get_busid_by_adapter(adapter));
573 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
574 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
575 zfcp_get_busid_by_adapter(adapter));
577 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
578 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
579 zfcp_get_busid_by_adapter(adapter));
581 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
582 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
583 zfcp_get_busid_by_adapter(adapter));
586 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
587 "(warning: unknown reason code %d)\n",
588 zfcp_get_busid_by_adapter(adapter),
589 link_down->error_code);
592 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
593 ZFCP_LOG_DEBUG("Debug information to link down: "
594 "primary_status=0x%02x "
596 "action_code=0x%02x "
597 "reason_code=0x%02x "
598 "explanation_code=0x%02x "
599 "vendor_specific_code=0x%02x\n",
600 link_down->primary_status,
601 link_down->ioerr_code,
602 link_down->action_code,
603 link_down->reason_code,
604 link_down->explanation_code,
605 link_down->vendor_specific_code);
608 zfcp_erp_adapter_failed(adapter, id, (u64)fsf_req);
612 * function: zfcp_fsf_req_dispatch
614 * purpose: calls the appropriate command specific handler
619 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
621 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
622 struct zfcp_adapter *adapter = fsf_req->adapter;
626 switch (fsf_req->fsf_command) {
628 case FSF_QTCB_FCP_CMND:
629 zfcp_fsf_send_fcp_command_handler(fsf_req);
632 case FSF_QTCB_ABORT_FCP_CMND:
633 zfcp_fsf_abort_fcp_command_handler(fsf_req);
636 case FSF_QTCB_SEND_GENERIC:
637 zfcp_fsf_send_ct_handler(fsf_req);
640 case FSF_QTCB_OPEN_PORT_WITH_DID:
641 zfcp_fsf_open_port_handler(fsf_req);
644 case FSF_QTCB_OPEN_LUN:
645 zfcp_fsf_open_unit_handler(fsf_req);
648 case FSF_QTCB_CLOSE_LUN:
649 zfcp_fsf_close_unit_handler(fsf_req);
652 case FSF_QTCB_CLOSE_PORT:
653 zfcp_fsf_close_port_handler(fsf_req);
656 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
657 zfcp_fsf_close_physical_port_handler(fsf_req);
660 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
661 zfcp_fsf_exchange_config_data_handler(fsf_req);
664 case FSF_QTCB_EXCHANGE_PORT_DATA:
665 zfcp_fsf_exchange_port_data_handler(fsf_req);
668 case FSF_QTCB_SEND_ELS:
669 zfcp_fsf_send_els_handler(fsf_req);
672 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
673 zfcp_fsf_control_file_handler(fsf_req);
676 case FSF_QTCB_UPLOAD_CONTROL_FILE:
677 zfcp_fsf_control_file_handler(fsf_req);
681 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
682 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
683 "not supported by the adapter %s\n",
684 zfcp_get_busid_by_adapter(adapter));
685 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
687 ("bug: Command issued by the device driver differs "
688 "from the command returned by the adapter %s "
689 "(debug info 0x%x, 0x%x).\n",
690 zfcp_get_busid_by_adapter(adapter),
691 fsf_req->fsf_command,
692 fsf_req->qtcb->header.fsf_command);
698 zfcp_erp_async_handler(erp_action, 0);
704 * function: zfcp_fsf_status_read
706 * purpose: initiates a Status Read command at the specified adapter
711 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
713 struct zfcp_fsf_req *fsf_req;
714 struct fsf_status_read_buffer *status_buffer;
715 unsigned long lock_flags;
716 volatile struct qdio_buffer_element *sbale;
719 /* setup new FSF request */
720 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
721 req_flags | ZFCP_REQ_NO_QTCB,
722 adapter->pool.fsf_req_status_read,
723 &lock_flags, &fsf_req);
725 ZFCP_LOG_INFO("error: Could not create unsolicited status "
726 "buffer for adapter %s.\n",
727 zfcp_get_busid_by_adapter(adapter));
728 goto failed_req_create;
731 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
732 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
733 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
734 fsf_req->sbale_curr = 2;
737 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
738 if (!status_buffer) {
739 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
742 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
743 fsf_req->data = (unsigned long) status_buffer;
745 /* insert pointer to respective buffer */
746 sbale = zfcp_qdio_sbale_curr(fsf_req);
747 sbale->addr = (void *) status_buffer;
748 sbale->length = sizeof(struct fsf_status_read_buffer);
750 retval = zfcp_fsf_req_send(fsf_req);
752 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
754 goto failed_req_send;
757 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
758 zfcp_get_busid_by_adapter(adapter));
762 mempool_free(status_buffer, adapter->pool.data_status_read);
765 zfcp_fsf_req_free(fsf_req);
767 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
769 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
774 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
776 struct fsf_status_read_buffer *status_buffer;
777 struct zfcp_adapter *adapter;
778 struct zfcp_port *port;
781 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
782 adapter = fsf_req->adapter;
784 read_lock_irqsave(&zfcp_data.config_lock, flags);
785 list_for_each_entry(port, &adapter->port_list_head, list)
786 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
788 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
790 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
791 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
792 "nonexisting port with d_id 0x%06x on "
793 "adapter %s. Ignored.\n",
794 status_buffer->d_id & ZFCP_DID_MASK,
795 zfcp_get_busid_by_adapter(adapter));
799 switch (status_buffer->status_subtype) {
801 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
802 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
803 zfcp_erp_port_reopen(port, 0, 101, (u64)fsf_req);
806 case FSF_STATUS_READ_SUB_ERROR_PORT:
807 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
808 zfcp_erp_port_shutdown(port, 0, 122, (u64)fsf_req);
812 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
813 debug_exception(adapter->erp_dbf, 0,
814 &status_buffer->status_subtype, sizeof (u32));
815 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
816 "for a reopen indication on port with "
817 "d_id 0x%06x on the adapter %s. "
818 "Ignored. (debug info 0x%x)\n",
820 zfcp_get_busid_by_adapter(adapter),
821 status_buffer->status_subtype);
828 * function: zfcp_fsf_status_read_handler
830 * purpose: is called for finished Open Port command
835 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
838 struct zfcp_adapter *adapter = fsf_req->adapter;
839 struct fsf_status_read_buffer *status_buffer =
840 (struct fsf_status_read_buffer *) fsf_req->data;
841 struct fsf_bit_error_payload *fsf_bit_error;
843 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
844 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
845 mempool_free(status_buffer, adapter->pool.data_status_read);
846 zfcp_fsf_req_free(fsf_req);
850 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
852 switch (status_buffer->status_type) {
854 case FSF_STATUS_READ_PORT_CLOSED:
855 zfcp_fsf_status_read_port_closed(fsf_req);
858 case FSF_STATUS_READ_INCOMING_ELS:
859 zfcp_fsf_incoming_els(fsf_req);
862 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
863 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
864 zfcp_get_busid_by_adapter(adapter));
867 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
868 fsf_bit_error = (struct fsf_bit_error_payload *)
869 status_buffer->payload;
870 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
871 "received (adapter %s, "
872 "link failures = %i, loss of sync errors = %i, "
873 "loss of signal errors = %i, "
874 "primitive sequence errors = %i, "
875 "invalid transmission word errors = %i, "
876 "CRC errors = %i)\n",
877 zfcp_get_busid_by_adapter(adapter),
878 fsf_bit_error->link_failure_error_count,
879 fsf_bit_error->loss_of_sync_error_count,
880 fsf_bit_error->loss_of_signal_error_count,
881 fsf_bit_error->primitive_sequence_error_count,
882 fsf_bit_error->invalid_transmission_word_error_count,
883 fsf_bit_error->crc_error_count);
884 ZFCP_LOG_INFO("Additional bit error threshold data "
886 "primitive sequence event time-outs = %i, "
887 "elastic buffer overrun errors = %i, "
888 "advertised receive buffer-to-buffer credit = %i, "
889 "current receice buffer-to-buffer credit = %i, "
890 "advertised transmit buffer-to-buffer credit = %i, "
891 "current transmit buffer-to-buffer credit = %i)\n",
892 zfcp_get_busid_by_adapter(adapter),
893 fsf_bit_error->primitive_sequence_event_timeout_count,
894 fsf_bit_error->elastic_buffer_overrun_error_count,
895 fsf_bit_error->advertised_receive_b2b_credit,
896 fsf_bit_error->current_receive_b2b_credit,
897 fsf_bit_error->advertised_transmit_b2b_credit,
898 fsf_bit_error->current_transmit_b2b_credit);
901 case FSF_STATUS_READ_LINK_DOWN:
902 switch (status_buffer->status_subtype) {
903 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
904 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
905 zfcp_get_busid_by_adapter(adapter));
906 zfcp_fsf_link_down_info_eval(fsf_req, 38,
907 (struct fsf_link_down_info *)
908 &status_buffer->payload);
910 case FSF_STATUS_READ_SUB_FDISC_FAILED:
911 ZFCP_LOG_INFO("Local link to adapter %s is down "
912 "due to failed FDISC login\n",
913 zfcp_get_busid_by_adapter(adapter));
914 zfcp_fsf_link_down_info_eval(fsf_req, 39,
915 (struct fsf_link_down_info *)
916 &status_buffer->payload);
918 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
919 ZFCP_LOG_INFO("Local link to adapter %s is down "
920 "due to firmware update on adapter\n",
921 zfcp_get_busid_by_adapter(adapter));
922 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
925 ZFCP_LOG_INFO("Local link to adapter %s is down "
926 "due to unknown reason\n",
927 zfcp_get_busid_by_adapter(adapter));
928 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
932 case FSF_STATUS_READ_LINK_UP:
933 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
934 "Restarting operations on this adapter\n",
935 zfcp_get_busid_by_adapter(adapter));
936 /* All ports should be marked as ready to run again */
937 zfcp_erp_modify_adapter_status(adapter, 30, 0,
938 ZFCP_STATUS_COMMON_RUNNING,
940 zfcp_erp_adapter_reopen(adapter,
941 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
942 | ZFCP_STATUS_COMMON_ERP_FAILED,
946 case FSF_STATUS_READ_NOTIFICATION_LOST:
947 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
948 "adapter %s%s%s%s%s%s%s%s%s\n",
949 zfcp_get_busid_by_adapter(adapter),
950 (status_buffer->status_subtype &
951 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
952 ", incoming ELS" : "",
953 (status_buffer->status_subtype &
954 FSF_STATUS_READ_SUB_SENSE_DATA) ?
956 (status_buffer->status_subtype &
957 FSF_STATUS_READ_SUB_LINK_STATUS) ?
958 ", link status change" : "",
959 (status_buffer->status_subtype &
960 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
962 (status_buffer->status_subtype &
963 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
964 ", bit error exception" : "",
965 (status_buffer->status_subtype &
966 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
968 (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
970 ", ACT hardening" : "",
971 (status_buffer->status_subtype &
972 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
973 ", adapter feature change" : "");
975 if (status_buffer->status_subtype &
976 FSF_STATUS_READ_SUB_ACT_UPDATED)
977 zfcp_erp_adapter_access_changed(adapter, 135,
981 case FSF_STATUS_READ_CFDC_UPDATED:
982 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
983 zfcp_get_busid_by_adapter(adapter));
984 zfcp_erp_adapter_access_changed(adapter, 136, (u64)fsf_req);
987 case FSF_STATUS_READ_CFDC_HARDENED:
988 switch (status_buffer->status_subtype) {
989 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
990 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
991 zfcp_get_busid_by_adapter(adapter));
993 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
994 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
995 "to the secondary SE\n",
996 zfcp_get_busid_by_adapter(adapter));
999 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1000 zfcp_get_busid_by_adapter(adapter));
1004 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1005 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1006 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1007 "been changed from 0x%08X to 0x%08X\n",
1008 zfcp_get_busid_by_adapter(adapter),
1009 *(u32*) (status_buffer->payload + 4),
1010 *(u32*) (status_buffer->payload));
1011 adapter->adapter_features = *(u32*) status_buffer->payload;
1015 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1016 "type was received (debug info 0x%x)\n",
1017 status_buffer->status_type);
1018 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1020 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1021 (char *) status_buffer,
1022 sizeof (struct fsf_status_read_buffer));
1025 mempool_free(status_buffer, adapter->pool.data_status_read);
1026 zfcp_fsf_req_free(fsf_req);
1028 * recycle buffer and start new request repeat until outbound
1029 * queue is empty or adapter shutdown is requested
1033 * we may wait in the req_create for 5s during shutdown, so
1034 * qdio_cleanup will have to wait at least that long before returning
1035 * with failure to allow us a proper cleanup under all circumstances
1039 * allocation failure possible? (Is this code needed?)
1041 retval = zfcp_fsf_status_read(adapter, 0);
1043 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1044 "request for the adapter %s.\n",
1045 zfcp_get_busid_by_adapter(adapter));
1046 /* temporary fix to avoid status read buffer shortage */
1047 adapter->status_read_failed++;
1048 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1049 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1050 ZFCP_LOG_INFO("restart adapter %s due to status read "
1051 "buffer shortage\n",
1052 zfcp_get_busid_by_adapter(adapter));
1053 zfcp_erp_adapter_reopen(adapter, 0, 103, (u64)fsf_req);
1061 * function: zfcp_fsf_abort_fcp_command
1063 * purpose: tells FSF to abort a running SCSI command
1065 * returns: address of initiated FSF request
1066 * NULL - request could not be initiated
1068 * FIXME(design): should be watched by a timeout !!!
1069 * FIXME(design) shouldn't this be modified to return an int
1070 * also...don't know how though
1072 struct zfcp_fsf_req *
1073 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1074 struct zfcp_adapter *adapter,
1075 struct zfcp_unit *unit, int req_flags)
1077 volatile struct qdio_buffer_element *sbale;
1078 struct zfcp_fsf_req *fsf_req = NULL;
1079 unsigned long lock_flags;
1082 /* setup new FSF request */
1083 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1084 req_flags, adapter->pool.fsf_req_abort,
1085 &lock_flags, &fsf_req);
1087 ZFCP_LOG_INFO("error: Failed to create an abort command "
1088 "request for lun 0x%016Lx on port 0x%016Lx "
1092 zfcp_get_busid_by_adapter(adapter));
1096 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1100 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1101 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1102 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1104 fsf_req->data = (unsigned long) unit;
1106 /* set handles of unit and its parent port in QTCB */
1107 fsf_req->qtcb->header.lun_handle = unit->handle;
1108 fsf_req->qtcb->header.port_handle = unit->port->handle;
1110 /* set handle of request which should be aborted */
1111 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1113 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1114 retval = zfcp_fsf_req_send(fsf_req);
1119 zfcp_fsf_req_free(fsf_req);
1123 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1128 * function: zfcp_fsf_abort_fcp_command_handler
1130 * purpose: is called for finished Abort FCP Command request
1135 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1137 int retval = -EINVAL;
1138 struct zfcp_unit *unit;
1139 union fsf_status_qual *fsf_stat_qual =
1140 &new_fsf_req->qtcb->header.fsf_status_qual;
1142 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1143 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1144 goto skip_fsfstatus;
1147 unit = (struct zfcp_unit *) new_fsf_req->data;
1149 /* evaluate FSF status in QTCB */
1150 switch (new_fsf_req->qtcb->header.fsf_status) {
1152 case FSF_PORT_HANDLE_NOT_VALID:
1153 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1154 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1157 * In this case a command that was sent prior to a port
1158 * reopen was aborted (handles are different). This is
1162 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1163 "port 0x%016Lx on adapter %s invalid. "
1164 "This may happen occasionally.\n",
1167 zfcp_get_busid_by_unit(unit));
1168 ZFCP_LOG_INFO("status qualifier:\n");
1169 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1170 (char *) &new_fsf_req->qtcb->header.
1172 sizeof (union fsf_status_qual));
1173 /* Let's hope this sorts out the mess */
1174 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1176 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
1178 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1182 case FSF_LUN_HANDLE_NOT_VALID:
1183 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1184 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1187 * In this case a command that was sent prior to a unit
1188 * reopen was aborted (handles are different).
1193 ("Warning: Temporary LUN identifier 0x%x of LUN "
1194 "0x%016Lx on port 0x%016Lx on adapter %s is "
1195 "invalid. This may happen in rare cases. "
1196 "Trying to re-establish link.\n",
1200 zfcp_get_busid_by_unit(unit));
1201 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1202 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1203 (char *) &new_fsf_req->qtcb->header.
1205 sizeof (union fsf_status_qual));
1206 /* Let's hope this sorts out the mess */
1207 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1209 zfcp_erp_port_reopen(unit->port, 0, 105,
1211 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1215 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1217 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1219 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1222 case FSF_PORT_BOXED:
1223 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1224 "be reopened\n", unit->port->wwpn,
1225 zfcp_get_busid_by_unit(unit));
1226 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1228 zfcp_erp_port_boxed(unit->port, 47, (u64)new_fsf_req);
1229 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1230 | ZFCP_STATUS_FSFREQ_RETRY;
1235 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1237 unit->fcp_lun, unit->port->wwpn,
1238 zfcp_get_busid_by_unit(unit));
1239 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1240 zfcp_erp_unit_boxed(unit, 48, (u64)new_fsf_req);
1241 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1242 | ZFCP_STATUS_FSFREQ_RETRY;
1245 case FSF_ADAPTER_STATUS_AVAILABLE:
1246 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1247 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1248 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1250 zfcp_test_link(unit->port);
1251 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1253 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1254 /* SCSI stack will escalate */
1255 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1257 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1261 ("bug: Wrong status qualifier 0x%x arrived.\n",
1262 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1263 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1265 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1266 &new_fsf_req->qtcb->header.
1267 fsf_status_qual.word[0], sizeof (u32));
1274 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1278 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1279 "(debug info 0x%x)\n",
1280 new_fsf_req->qtcb->header.fsf_status);
1281 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1283 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1284 &new_fsf_req->qtcb->header.fsf_status,
1293 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1295 * Two scatter-gather lists are passed, one for the reqeust and one for the
1299 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1300 struct scatterlist *resp, int resp_count)
1302 return ((req_count == 1) &&
1303 (resp_count == 1) &&
1304 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1306 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1307 req[0].length - 1) & PAGE_MASK)) &&
1308 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1310 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1311 resp[0].length - 1) & PAGE_MASK)));
1315 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1316 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1318 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1319 * a struct zfcp_fsf_req
1320 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1321 * is sent within error recovery
1324 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1325 struct zfcp_erp_action *erp_action)
1327 volatile struct qdio_buffer_element *sbale;
1328 struct zfcp_port *port;
1329 struct zfcp_adapter *adapter;
1330 struct zfcp_fsf_req *fsf_req;
1331 unsigned long lock_flags;
1336 adapter = port->adapter;
1338 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1339 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1340 pool, &lock_flags, &fsf_req);
1342 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1344 zfcp_get_busid_by_adapter(adapter));
1348 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1349 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1350 ct->resp, ct->resp_count)){
1351 /* both request buffer and response buffer
1352 fit into one sbale each */
1353 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1354 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1355 sbale[2].length = ct->req[0].length;
1356 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1357 sbale[3].length = ct->resp[0].length;
1358 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1359 } else if (adapter->adapter_features &
1360 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1361 /* try to use chained SBALs */
1362 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1363 SBAL_FLAGS0_TYPE_WRITE_READ,
1364 ct->req, ct->req_count,
1365 ZFCP_MAX_SBALS_PER_CT_REQ);
1367 ZFCP_LOG_INFO("error: creation of CT request failed "
1369 zfcp_get_busid_by_adapter(adapter));
1377 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1378 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1379 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1380 SBAL_FLAGS0_TYPE_WRITE_READ,
1381 ct->resp, ct->resp_count,
1382 ZFCP_MAX_SBALS_PER_CT_REQ);
1384 ZFCP_LOG_INFO("error: creation of CT request failed "
1386 zfcp_get_busid_by_adapter(adapter));
1394 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1396 /* reject send generic request */
1398 "error: microcode does not support chained SBALs,"
1399 "CT request too big (adapter %s)\n",
1400 zfcp_get_busid_by_adapter(adapter));
1405 /* settings in QTCB */
1406 fsf_req->qtcb->header.port_handle = port->handle;
1407 fsf_req->qtcb->bottom.support.service_class =
1408 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1409 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1410 fsf_req->data = (unsigned long) ct;
1412 zfcp_san_dbf_event_ct_request(fsf_req);
1415 erp_action->fsf_req = fsf_req;
1416 fsf_req->erp_action = erp_action;
1417 zfcp_erp_start_timer(fsf_req);
1419 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1421 ret = zfcp_fsf_req_send(fsf_req);
1423 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1424 "(adapter %s, port 0x%016Lx)\n",
1425 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1429 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1430 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1434 zfcp_fsf_req_free(fsf_req);
1435 if (erp_action != NULL) {
1436 erp_action->fsf_req = NULL;
1440 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1446 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1447 * @fsf_req: pointer to struct zfcp_fsf_req
1449 * Data specific for the Generic Service request is passed using
1450 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1451 * Usually a specific handler for the CT request is called which is
1452 * found in this structure.
1455 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1457 struct zfcp_port *port;
1458 struct zfcp_adapter *adapter;
1459 struct zfcp_send_ct *send_ct;
1460 struct fsf_qtcb_header *header;
1461 struct fsf_qtcb_bottom_support *bottom;
1462 int retval = -EINVAL;
1463 u16 subtable, rule, counter;
1465 adapter = fsf_req->adapter;
1466 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1467 port = send_ct->port;
1468 header = &fsf_req->qtcb->header;
1469 bottom = &fsf_req->qtcb->bottom.support;
1471 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1472 goto skip_fsfstatus;
1474 /* evaluate FSF status in QTCB */
1475 switch (header->fsf_status) {
1478 zfcp_san_dbf_event_ct_response(fsf_req);
1482 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1483 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1485 zfcp_get_busid_by_port(port),
1486 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1487 /* stop operation for this adapter */
1488 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1489 zfcp_erp_adapter_shutdown(adapter, 0, 123, (u64)fsf_req);
1490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1493 case FSF_ADAPTER_STATUS_AVAILABLE:
1494 switch (header->fsf_status_qual.word[0]){
1495 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1496 /* reopening link to port */
1497 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1498 zfcp_test_link(port);
1499 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1501 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1502 /* ERP strategy will escalate */
1503 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1504 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1507 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1509 header->fsf_status_qual.word[0]);
1514 case FSF_ACCESS_DENIED:
1515 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1516 "command (adapter %s, port d_id=0x%06x)\n",
1517 zfcp_get_busid_by_port(port), port->d_id);
1518 for (counter = 0; counter < 2; counter++) {
1519 subtable = header->fsf_status_qual.halfword[counter * 2];
1520 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1522 case FSF_SQ_CFDC_SUBTABLE_OS:
1523 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1524 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1525 case FSF_SQ_CFDC_SUBTABLE_LUN:
1526 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1527 zfcp_act_subtable_type[subtable], rule);
1531 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1532 zfcp_erp_port_access_denied(port, 55, (u64)fsf_req);
1533 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1536 case FSF_GENERIC_COMMAND_REJECTED:
1537 ZFCP_LOG_INFO("generic service command rejected "
1538 "(adapter %s, port d_id=0x%06x)\n",
1539 zfcp_get_busid_by_port(port), port->d_id);
1540 ZFCP_LOG_INFO("status qualifier:\n");
1541 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1542 (char *) &header->fsf_status_qual,
1543 sizeof (union fsf_status_qual));
1544 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1545 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1548 case FSF_PORT_HANDLE_NOT_VALID:
1549 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1550 "0x%016Lx on adapter %s invalid. This may "
1551 "happen occasionally.\n", port->handle,
1552 port->wwpn, zfcp_get_busid_by_port(port));
1553 ZFCP_LOG_INFO("status qualifier:\n");
1554 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1555 (char *) &header->fsf_status_qual,
1556 sizeof (union fsf_status_qual));
1557 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1558 zfcp_erp_adapter_reopen(adapter, 0, 106, (u64)fsf_req);
1559 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1562 case FSF_PORT_BOXED:
1563 ZFCP_LOG_INFO("port needs to be reopened "
1564 "(adapter %s, port d_id=0x%06x)\n",
1565 zfcp_get_busid_by_port(port), port->d_id);
1566 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1567 zfcp_erp_port_boxed(port, 49, (u64)fsf_req);
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1569 | ZFCP_STATUS_FSFREQ_RETRY;
1572 /* following states should never occure, all cases avoided
1573 in zfcp_fsf_send_ct - but who knows ... */
1574 case FSF_PAYLOAD_SIZE_MISMATCH:
1575 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1576 "req_buf_length=%d, resp_buf_length=%d)\n",
1577 zfcp_get_busid_by_adapter(adapter),
1578 bottom->req_buf_length, bottom->resp_buf_length);
1579 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1581 case FSF_REQUEST_SIZE_TOO_LARGE:
1582 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1583 "req_buf_length=%d)\n",
1584 zfcp_get_busid_by_adapter(adapter),
1585 bottom->req_buf_length);
1586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1588 case FSF_RESPONSE_SIZE_TOO_LARGE:
1589 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1590 "resp_buf_length=%d)\n",
1591 zfcp_get_busid_by_adapter(adapter),
1592 bottom->resp_buf_length);
1593 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1595 case FSF_SBAL_MISMATCH:
1596 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1597 "resp_buf_length=%d)\n",
1598 zfcp_get_busid_by_adapter(adapter),
1599 bottom->req_buf_length, bottom->resp_buf_length);
1600 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1604 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1605 "(debug info 0x%x)\n", header->fsf_status);
1606 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1607 debug_exception(adapter->erp_dbf, 0,
1608 &header->fsf_status_qual.word[0], sizeof (u32));
1613 send_ct->status = retval;
1615 if (send_ct->handler != NULL)
1616 send_ct->handler(send_ct->handler_data);
1622 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1623 * @els: pointer to struct zfcp_send_els which contains all needed data for
1627 zfcp_fsf_send_els(struct zfcp_send_els *els)
1629 volatile struct qdio_buffer_element *sbale;
1630 struct zfcp_fsf_req *fsf_req;
1632 struct zfcp_adapter *adapter;
1633 unsigned long lock_flags;
1638 adapter = els->adapter;
1640 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1641 ZFCP_REQ_AUTO_CLEANUP,
1642 NULL, &lock_flags, &fsf_req);
1644 ZFCP_LOG_INFO("error: creation of ELS request failed "
1645 "(adapter %s, port d_id: 0x%06x)\n",
1646 zfcp_get_busid_by_adapter(adapter), d_id);
1650 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1651 &els->port->status))) {
1656 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1657 if (zfcp_use_one_sbal(els->req, els->req_count,
1658 els->resp, els->resp_count)){
1659 /* both request buffer and response buffer
1660 fit into one sbale each */
1661 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1662 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1663 sbale[2].length = els->req[0].length;
1664 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1665 sbale[3].length = els->resp[0].length;
1666 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1667 } else if (adapter->adapter_features &
1668 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1669 /* try to use chained SBALs */
1670 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1671 SBAL_FLAGS0_TYPE_WRITE_READ,
1672 els->req, els->req_count,
1673 ZFCP_MAX_SBALS_PER_ELS_REQ);
1675 ZFCP_LOG_INFO("error: creation of ELS request failed "
1676 "(adapter %s, port d_id: 0x%06x)\n",
1677 zfcp_get_busid_by_adapter(adapter), d_id);
1685 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1686 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1687 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1688 SBAL_FLAGS0_TYPE_WRITE_READ,
1689 els->resp, els->resp_count,
1690 ZFCP_MAX_SBALS_PER_ELS_REQ);
1692 ZFCP_LOG_INFO("error: creation of ELS request failed "
1693 "(adapter %s, port d_id: 0x%06x)\n",
1694 zfcp_get_busid_by_adapter(adapter), d_id);
1702 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1704 /* reject request */
1705 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1706 ", ELS request too big (adapter %s, "
1707 "port d_id: 0x%06x)\n",
1708 zfcp_get_busid_by_adapter(adapter), d_id);
1713 /* settings in QTCB */
1714 fsf_req->qtcb->bottom.support.d_id = d_id;
1715 fsf_req->qtcb->bottom.support.service_class =
1716 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1717 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1718 fsf_req->data = (unsigned long) els;
1720 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1722 zfcp_san_dbf_event_els_request(fsf_req);
1724 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1725 ret = zfcp_fsf_req_send(fsf_req);
1727 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1728 "(adapter %s, port d_id: 0x%06x)\n",
1729 zfcp_get_busid_by_adapter(adapter), d_id);
1733 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1734 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1739 zfcp_fsf_req_free(fsf_req);
1743 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1750 * zfcp_fsf_send_els_handler - handler for ELS commands
1751 * @fsf_req: pointer to struct zfcp_fsf_req
1753 * Data specific for the ELS command is passed using
1754 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1755 * Usually a specific handler for the ELS command is called which is
1756 * found in this structure.
1758 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1760 struct zfcp_adapter *adapter;
1761 struct zfcp_port *port;
1763 struct fsf_qtcb_header *header;
1764 struct fsf_qtcb_bottom_support *bottom;
1765 struct zfcp_send_els *send_els;
1766 int retval = -EINVAL;
1767 u16 subtable, rule, counter;
1769 send_els = (struct zfcp_send_els *) fsf_req->data;
1770 adapter = send_els->adapter;
1771 port = send_els->port;
1772 d_id = send_els->d_id;
1773 header = &fsf_req->qtcb->header;
1774 bottom = &fsf_req->qtcb->bottom.support;
1776 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1777 goto skip_fsfstatus;
1779 switch (header->fsf_status) {
1782 zfcp_san_dbf_event_els_response(fsf_req);
1786 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1787 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1789 zfcp_get_busid_by_adapter(adapter),
1790 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1791 /* stop operation for this adapter */
1792 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1793 zfcp_erp_adapter_shutdown(adapter, 0, 124, (u64)fsf_req);
1794 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1797 case FSF_ADAPTER_STATUS_AVAILABLE:
1798 switch (header->fsf_status_qual.word[0]){
1799 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1800 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1801 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1802 zfcp_test_link(port);
1803 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1805 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1806 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1809 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1810 (struct zfcp_ls_rjt_par *)
1811 &header->fsf_status_qual.word[2]);
1813 case FSF_SQ_RETRY_IF_POSSIBLE:
1814 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1818 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1819 header->fsf_status_qual.word[0]);
1820 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1821 (char*)header->fsf_status_qual.word, 16);
1825 case FSF_ELS_COMMAND_REJECTED:
1826 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1827 "prohibited sending "
1828 "(adapter: %s, port d_id: 0x%06x)\n",
1829 zfcp_get_busid_by_adapter(adapter), d_id);
1833 case FSF_PAYLOAD_SIZE_MISMATCH:
1835 "ELS request size and ELS response size must be either "
1836 "both 0, or both greater than 0 "
1837 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1838 zfcp_get_busid_by_adapter(adapter),
1839 bottom->req_buf_length,
1840 bottom->resp_buf_length);
1843 case FSF_REQUEST_SIZE_TOO_LARGE:
1845 "Length of the ELS request buffer, "
1846 "specified in QTCB bottom, "
1847 "exceeds the size of the buffers "
1848 "that have been allocated for ELS request data "
1849 "(adapter: %s, req_buf_length=%d)\n",
1850 zfcp_get_busid_by_adapter(adapter),
1851 bottom->req_buf_length);
1854 case FSF_RESPONSE_SIZE_TOO_LARGE:
1856 "Length of the ELS response buffer, "
1857 "specified in QTCB bottom, "
1858 "exceeds the size of the buffers "
1859 "that have been allocated for ELS response data "
1860 "(adapter: %s, resp_buf_length=%d)\n",
1861 zfcp_get_busid_by_adapter(adapter),
1862 bottom->resp_buf_length);
1865 case FSF_SBAL_MISMATCH:
1866 /* should never occure, avoided in zfcp_fsf_send_els */
1867 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1868 "resp_buf_length=%d)\n",
1869 zfcp_get_busid_by_adapter(adapter),
1870 bottom->req_buf_length, bottom->resp_buf_length);
1871 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1874 case FSF_ACCESS_DENIED:
1875 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1876 "(adapter %s, port d_id=0x%06x)\n",
1877 zfcp_get_busid_by_adapter(adapter), d_id);
1878 for (counter = 0; counter < 2; counter++) {
1879 subtable = header->fsf_status_qual.halfword[counter * 2];
1880 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1882 case FSF_SQ_CFDC_SUBTABLE_OS:
1883 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1884 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1885 case FSF_SQ_CFDC_SUBTABLE_LUN:
1886 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1887 zfcp_act_subtable_type[subtable], rule);
1891 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1893 zfcp_erp_port_access_denied(port, 56, (u64)fsf_req);
1894 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1899 "bug: An unknown FSF Status was presented "
1900 "(adapter: %s, fsf_status=0x%08x)\n",
1901 zfcp_get_busid_by_adapter(adapter),
1902 header->fsf_status);
1903 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1904 debug_exception(adapter->erp_dbf, 0,
1905 &header->fsf_status_qual.word[0], sizeof(u32));
1906 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1911 send_els->status = retval;
1913 if (send_els->handler)
1914 send_els->handler(send_els->handler_data);
1920 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1922 volatile struct qdio_buffer_element *sbale;
1923 struct zfcp_fsf_req *fsf_req;
1924 struct zfcp_adapter *adapter = erp_action->adapter;
1925 unsigned long lock_flags;
1928 /* setup new FSF request */
1929 retval = zfcp_fsf_req_create(adapter,
1930 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1931 ZFCP_REQ_AUTO_CLEANUP,
1932 adapter->pool.fsf_req_erp,
1933 &lock_flags, &fsf_req);
1935 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1936 "data request for adapter %s.\n",
1937 zfcp_get_busid_by_adapter(adapter));
1938 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1943 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1944 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1945 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1947 fsf_req->qtcb->bottom.config.feature_selection =
1949 FSF_FEATURE_LUN_SHARING |
1950 FSF_FEATURE_NOTIFICATION_LOST |
1951 FSF_FEATURE_UPDATE_ALERT;
1952 fsf_req->erp_action = erp_action;
1953 erp_action->fsf_req = fsf_req;
1955 zfcp_erp_start_timer(fsf_req);
1956 retval = zfcp_fsf_req_send(fsf_req);
1957 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1960 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1961 "data command on the adapter %s\n",
1962 zfcp_get_busid_by_adapter(adapter));
1963 zfcp_fsf_req_free(fsf_req);
1964 erp_action->fsf_req = NULL;
1967 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1969 zfcp_get_busid_by_adapter(adapter));
1975 zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1976 struct fsf_qtcb_bottom_config *data)
1978 volatile struct qdio_buffer_element *sbale;
1979 struct zfcp_fsf_req *fsf_req;
1980 unsigned long lock_flags;
1983 /* setup new FSF request */
1984 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1985 0, NULL, &lock_flags, &fsf_req);
1987 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1988 "data request for adapter %s.\n",
1989 zfcp_get_busid_by_adapter(adapter));
1990 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1995 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1996 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1997 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1999 fsf_req->qtcb->bottom.config.feature_selection =
2001 FSF_FEATURE_LUN_SHARING |
2002 FSF_FEATURE_NOTIFICATION_LOST |
2003 FSF_FEATURE_UPDATE_ALERT;
2006 fsf_req->data = (unsigned long) data;
2008 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2009 retval = zfcp_fsf_req_send(fsf_req);
2010 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2013 ZFCP_LOG_INFO("error: Could not send exchange configuration "
2014 "data command on the adapter %s\n",
2015 zfcp_get_busid_by_adapter(adapter));
2017 wait_event(fsf_req->completion_wq,
2018 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2020 zfcp_fsf_req_free(fsf_req);
2026 * zfcp_fsf_exchange_config_evaluate
2027 * @fsf_req: fsf_req which belongs to xchg config data request
2028 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2030 * returns: -EIO on error, 0 otherwise
2033 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2035 struct fsf_qtcb_bottom_config *bottom;
2036 struct zfcp_adapter *adapter = fsf_req->adapter;
2037 struct Scsi_Host *shost = adapter->scsi_host;
2039 bottom = &fsf_req->qtcb->bottom.config;
2040 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2041 bottom->low_qtcb_version, bottom->high_qtcb_version);
2042 adapter->fsf_lic_version = bottom->lic_version;
2043 adapter->adapter_features = bottom->adapter_features;
2044 adapter->connection_features = bottom->connection_features;
2045 adapter->peer_wwpn = 0;
2046 adapter->peer_wwnn = 0;
2047 adapter->peer_d_id = 0;
2052 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
2053 bottom, sizeof (struct fsf_qtcb_bottom_config));
2055 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2056 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2057 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2058 fc_host_speed(shost) = bottom->fc_link_speed;
2059 fc_host_supported_classes(shost) =
2060 FC_COS_CLASS2 | FC_COS_CLASS3;
2061 adapter->hydra_version = bottom->adapter_type;
2062 if (fc_host_permanent_port_name(shost) == -1)
2063 fc_host_permanent_port_name(shost) =
2064 fc_host_port_name(shost);
2065 if (bottom->fc_topology == FSF_TOPO_P2P) {
2066 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2067 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2068 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2069 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2070 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2071 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2072 else if (bottom->fc_topology == FSF_TOPO_AL)
2073 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2075 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2077 fc_host_node_name(shost) = 0;
2078 fc_host_port_name(shost) = 0;
2079 fc_host_port_id(shost) = 0;
2080 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2081 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2082 adapter->hydra_version = 0;
2085 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2086 adapter->hardware_version = bottom->hardware_version;
2087 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2088 min(FC_SERIAL_NUMBER_SIZE, 17));
2089 EBCASC(fc_host_serial_number(shost),
2090 min(FC_SERIAL_NUMBER_SIZE, 17));
2093 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2094 "characteristics:\n"
2098 "adapter version 0x%x, "
2099 "LIC version 0x%x, "
2100 "FC link speed %d Gb/s\n",
2101 zfcp_get_busid_by_adapter(adapter),
2102 (wwn_t) fc_host_node_name(shost),
2103 (wwn_t) fc_host_port_name(shost),
2104 fc_host_port_id(shost),
2105 adapter->hydra_version,
2106 adapter->fsf_lic_version,
2107 fc_host_speed(shost));
2108 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2109 ZFCP_LOG_NORMAL("error: the adapter %s "
2110 "only supports newer control block "
2111 "versions in comparison to this device "
2112 "driver (try updated device driver)\n",
2113 zfcp_get_busid_by_adapter(adapter));
2114 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2115 zfcp_erp_adapter_shutdown(adapter, 0, 125, (u64)fsf_req);
2118 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2119 ZFCP_LOG_NORMAL("error: the adapter %s "
2120 "only supports older control block "
2121 "versions than this device driver uses"
2122 "(consider a microcode upgrade)\n",
2123 zfcp_get_busid_by_adapter(adapter));
2124 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2125 zfcp_erp_adapter_shutdown(adapter, 0, 126, (u64)fsf_req);
2132 * function: zfcp_fsf_exchange_config_data_handler
2134 * purpose: is called for finished Exchange Configuration Data command
2139 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2141 struct fsf_qtcb_bottom_config *bottom;
2142 struct zfcp_adapter *adapter = fsf_req->adapter;
2143 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2145 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2148 switch (qtcb->header.fsf_status) {
2151 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2154 switch (fc_host_port_type(adapter->scsi_host)) {
2155 case FC_PORTTYPE_PTP:
2156 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2157 "configuration detected at adapter %s\n"
2158 "Peer WWNN 0x%016llx, "
2159 "peer WWPN 0x%016llx, "
2160 "peer d_id 0x%06x\n",
2161 zfcp_get_busid_by_adapter(adapter),
2164 adapter->peer_d_id);
2165 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2168 case FC_PORTTYPE_NLPORT:
2169 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2170 "topology detected at adapter %s "
2171 "unsupported, shutting down adapter\n",
2172 zfcp_get_busid_by_adapter(adapter));
2173 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2175 zfcp_erp_adapter_shutdown(adapter, 0, 127, (u64)fsf_req);
2177 case FC_PORTTYPE_NPORT:
2178 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2179 "network detected at adapter %s.\n",
2180 zfcp_get_busid_by_adapter(adapter));
2183 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2184 "reported by the exchange "
2185 "configuration command for "
2186 "the adapter %s is not "
2187 "of a type known to the zfcp "
2188 "driver, shutting down adapter\n",
2189 zfcp_get_busid_by_adapter(adapter));
2190 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2192 zfcp_erp_adapter_shutdown(adapter, 0, 128, (u64)fsf_req);
2195 bottom = &qtcb->bottom.config;
2196 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2197 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2198 "allowed by the adapter %s "
2199 "is lower than the minimum "
2200 "required by the driver (%ld bytes).\n",
2201 bottom->max_qtcb_size,
2202 zfcp_get_busid_by_adapter(adapter),
2203 sizeof(struct fsf_qtcb));
2204 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2206 debug_event(fsf_req->adapter->erp_dbf, 0,
2207 &bottom->max_qtcb_size, sizeof (u32));
2208 zfcp_erp_adapter_shutdown(adapter, 0, 129, (u64)fsf_req);
2211 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2214 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2215 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2217 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2220 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2223 zfcp_fsf_link_down_info_eval(fsf_req, 42,
2224 &qtcb->header.fsf_status_qual.link_down_info);
2227 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2228 debug_event(fsf_req->adapter->erp_dbf, 0,
2229 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2230 zfcp_erp_adapter_shutdown(adapter, 0, 130, (u64)fsf_req);
2237 * zfcp_fsf_exchange_port_data - request information about local port
2238 * @erp_action: ERP action for the adapter for which port data is requested
2241 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
2243 volatile struct qdio_buffer_element *sbale;
2244 struct zfcp_fsf_req *fsf_req;
2245 struct zfcp_adapter *adapter = erp_action->adapter;
2246 unsigned long lock_flags;
2249 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2250 ZFCP_LOG_INFO("error: exchange port data "
2251 "command not supported by adapter %s\n",
2252 zfcp_get_busid_by_adapter(adapter));
2256 /* setup new FSF request */
2257 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2258 ZFCP_REQ_AUTO_CLEANUP,
2259 adapter->pool.fsf_req_erp,
2260 &lock_flags, &fsf_req);
2262 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2263 "exchange port data request for "
2264 "the adapter %s.\n",
2265 zfcp_get_busid_by_adapter(adapter));
2266 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2271 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2272 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2273 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2275 erp_action->fsf_req = fsf_req;
2276 fsf_req->erp_action = erp_action;
2277 zfcp_erp_start_timer(fsf_req);
2279 retval = zfcp_fsf_req_send(fsf_req);
2280 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2283 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2284 "command on the adapter %s\n",
2285 zfcp_get_busid_by_adapter(adapter));
2286 zfcp_fsf_req_free(fsf_req);
2287 erp_action->fsf_req = NULL;
2290 ZFCP_LOG_DEBUG("exchange port data request initiated "
2292 zfcp_get_busid_by_adapter(adapter));
2298 * zfcp_fsf_exchange_port_data_sync - request information about local port
2299 * and wait until information is ready
2302 zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2303 struct fsf_qtcb_bottom_port *data)
2305 volatile struct qdio_buffer_element *sbale;
2306 struct zfcp_fsf_req *fsf_req;
2307 unsigned long lock_flags;
2310 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2311 ZFCP_LOG_INFO("error: exchange port data "
2312 "command not supported by adapter %s\n",
2313 zfcp_get_busid_by_adapter(adapter));
2317 /* setup new FSF request */
2318 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2319 0, NULL, &lock_flags, &fsf_req);
2321 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2322 "exchange port data request for "
2323 "the adapter %s.\n",
2324 zfcp_get_busid_by_adapter(adapter));
2325 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2331 fsf_req->data = (unsigned long) data;
2333 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2334 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2335 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2337 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2338 retval = zfcp_fsf_req_send(fsf_req);
2339 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2342 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2343 "command on the adapter %s\n",
2344 zfcp_get_busid_by_adapter(adapter));
2346 wait_event(fsf_req->completion_wq,
2347 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2349 zfcp_fsf_req_free(fsf_req);
2355 * zfcp_fsf_exchange_port_evaluate
2356 * @fsf_req: fsf_req which belongs to xchg port data request
2357 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2360 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2362 struct zfcp_adapter *adapter;
2363 struct fsf_qtcb_bottom_port *bottom;
2364 struct Scsi_Host *shost;
2366 adapter = fsf_req->adapter;
2367 bottom = &fsf_req->qtcb->bottom.port;
2368 shost = adapter->scsi_host;
2371 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2372 sizeof(struct fsf_qtcb_bottom_port));
2374 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2375 fc_host_permanent_port_name(shost) = bottom->wwpn;
2377 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2378 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2379 fc_host_supported_speeds(shost) = bottom->supported_speed;
2383 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2384 * @fsf_req: pointer to struct zfcp_fsf_req
2387 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2389 struct zfcp_adapter *adapter;
2390 struct fsf_qtcb *qtcb;
2392 adapter = fsf_req->adapter;
2393 qtcb = fsf_req->qtcb;
2395 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2398 switch (qtcb->header.fsf_status) {
2400 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2401 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2403 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2404 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2405 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2406 zfcp_fsf_link_down_info_eval(fsf_req, 43,
2407 &qtcb->header.fsf_status_qual.link_down_info);
2410 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2411 debug_event(adapter->erp_dbf, 0,
2412 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2418 * function: zfcp_fsf_open_port
2422 * returns: address of initiated FSF request
2423 * NULL - request could not be initiated
2426 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2428 volatile struct qdio_buffer_element *sbale;
2429 struct zfcp_fsf_req *fsf_req;
2430 unsigned long lock_flags;
2433 /* setup new FSF request */
2434 retval = zfcp_fsf_req_create(erp_action->adapter,
2435 FSF_QTCB_OPEN_PORT_WITH_DID,
2436 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2437 erp_action->adapter->pool.fsf_req_erp,
2438 &lock_flags, &fsf_req);
2440 ZFCP_LOG_INFO("error: Could not create open port request "
2441 "for port 0x%016Lx on adapter %s.\n",
2442 erp_action->port->wwpn,
2443 zfcp_get_busid_by_adapter(erp_action->adapter));
2447 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2448 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2449 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2451 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2452 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2453 fsf_req->data = (unsigned long) erp_action->port;
2454 fsf_req->erp_action = erp_action;
2455 erp_action->fsf_req = fsf_req;
2457 zfcp_erp_start_timer(fsf_req);
2458 retval = zfcp_fsf_req_send(fsf_req);
2460 ZFCP_LOG_INFO("error: Could not send open port request for "
2461 "port 0x%016Lx on adapter %s.\n",
2462 erp_action->port->wwpn,
2463 zfcp_get_busid_by_adapter(erp_action->adapter));
2464 zfcp_fsf_req_free(fsf_req);
2465 erp_action->fsf_req = NULL;
2469 ZFCP_LOG_DEBUG("open port request initiated "
2470 "(adapter %s, port 0x%016Lx)\n",
2471 zfcp_get_busid_by_adapter(erp_action->adapter),
2472 erp_action->port->wwpn);
2474 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2480 * function: zfcp_fsf_open_port_handler
2482 * purpose: is called for finished Open Port command
2487 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2489 int retval = -EINVAL;
2490 struct zfcp_port *port;
2491 struct fsf_plogi *plogi;
2492 struct fsf_qtcb_header *header;
2493 u16 subtable, rule, counter;
2495 port = (struct zfcp_port *) fsf_req->data;
2496 header = &fsf_req->qtcb->header;
2498 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2499 /* don't change port status in our bookkeeping */
2500 goto skip_fsfstatus;
2503 /* evaluate FSF status in QTCB */
2504 switch (header->fsf_status) {
2506 case FSF_PORT_ALREADY_OPEN:
2507 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2508 "is already open.\n",
2509 port->wwpn, zfcp_get_busid_by_port(port));
2510 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2513 * This is a bug, however operation should continue normally
2514 * if it is simply ignored
2518 case FSF_ACCESS_DENIED:
2519 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2521 port->wwpn, zfcp_get_busid_by_port(port));
2522 for (counter = 0; counter < 2; counter++) {
2523 subtable = header->fsf_status_qual.halfword[counter * 2];
2524 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2526 case FSF_SQ_CFDC_SUBTABLE_OS:
2527 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2528 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2529 case FSF_SQ_CFDC_SUBTABLE_LUN:
2530 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2531 zfcp_act_subtable_type[subtable], rule);
2535 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2536 zfcp_erp_port_access_denied(port, 57, (u64)fsf_req);
2537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2540 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2541 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2542 "The remote port 0x%016Lx on adapter %s "
2543 "could not be opened. Disabling it.\n",
2544 port->wwpn, zfcp_get_busid_by_port(port));
2545 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2547 zfcp_erp_port_failed(port, 31, (u64)fsf_req);
2548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2551 case FSF_ADAPTER_STATUS_AVAILABLE:
2552 switch (header->fsf_status_qual.word[0]) {
2553 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2554 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2556 /* ERP strategy will escalate */
2557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2559 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2560 /* ERP strategy will escalate */
2561 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2563 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2565 case FSF_SQ_NO_RETRY_POSSIBLE:
2566 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2567 "adapter %s could not be opened. "
2570 zfcp_get_busid_by_port(port));
2571 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2573 zfcp_erp_port_failed(port, 32, (u64)fsf_req);
2574 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2578 ("bug: Wrong status qualifier 0x%x arrived.\n",
2579 header->fsf_status_qual.word[0]);
2580 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2583 fsf_req->adapter->erp_dbf, 0,
2584 &header->fsf_status_qual.word[0],
2591 /* save port handle assigned by FSF */
2592 port->handle = header->port_handle;
2593 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2594 "was opened, it's port handle is 0x%x\n",
2595 port->wwpn, zfcp_get_busid_by_port(port),
2597 /* mark port as open */
2598 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2599 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2600 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2601 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2604 /* check whether D_ID has changed during open */
2606 * FIXME: This check is not airtight, as the FCP channel does
2607 * not monitor closures of target port connections caused on
2608 * the remote side. Thus, they might miss out on invalidating
2609 * locally cached WWPNs (and other N_Port parameters) of gone
2610 * target ports. So, our heroic attempt to make things safe
2611 * could be undermined by 'open port' response data tagged with
2612 * obsolete WWPNs. Another reason to monitor potential
2613 * connection closures ourself at least (by interpreting
2614 * incoming ELS' and unsolicited status). It just crosses my
2615 * mind that one should be able to cross-check by means of
2616 * another GID_PN straight after a port has been opened.
2617 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2619 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2620 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2622 if (fsf_req->qtcb->bottom.support.els1_length <
2623 sizeof (struct fsf_plogi)) {
2625 "warning: insufficient length of "
2626 "PLOGI payload (%i)\n",
2627 fsf_req->qtcb->bottom.support.els1_length);
2628 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2629 "fsf_s_short_plogi:");
2630 /* skip sanity check and assume wwpn is ok */
2632 if (plogi->serv_param.wwpn != port->wwpn) {
2633 ZFCP_LOG_INFO("warning: d_id of port "
2634 "0x%016Lx changed during "
2635 "open\n", port->wwpn);
2637 fsf_req->adapter->erp_dbf, 0,
2638 "fsf_s_did_change:");
2640 ZFCP_STATUS_PORT_DID_DID,
2643 port->wwnn = plogi->serv_param.wwnn;
2644 zfcp_plogi_evaluate(port, plogi);
2650 case FSF_UNKNOWN_OP_SUBTYPE:
2651 /* should never occure, subtype not set in zfcp_fsf_open_port */
2652 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2653 "op_subtype=0x%x)\n",
2654 zfcp_get_busid_by_port(port),
2655 fsf_req->qtcb->bottom.support.operation_subtype);
2656 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2660 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2661 "(debug info 0x%x)\n",
2662 header->fsf_status);
2663 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2664 debug_exception(fsf_req->adapter->erp_dbf, 0,
2665 &header->fsf_status, sizeof (u32));
2670 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2675 * function: zfcp_fsf_close_port
2677 * purpose: submit FSF command "close port"
2679 * returns: address of initiated FSF request
2680 * NULL - request could not be initiated
2683 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2685 volatile struct qdio_buffer_element *sbale;
2686 struct zfcp_fsf_req *fsf_req;
2687 unsigned long lock_flags;
2690 /* setup new FSF request */
2691 retval = zfcp_fsf_req_create(erp_action->adapter,
2692 FSF_QTCB_CLOSE_PORT,
2693 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2694 erp_action->adapter->pool.fsf_req_erp,
2695 &lock_flags, &fsf_req);
2697 ZFCP_LOG_INFO("error: Could not create a close port request "
2698 "for port 0x%016Lx on adapter %s.\n",
2699 erp_action->port->wwpn,
2700 zfcp_get_busid_by_adapter(erp_action->adapter));
2704 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2705 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2706 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2708 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2709 fsf_req->data = (unsigned long) erp_action->port;
2710 fsf_req->erp_action = erp_action;
2711 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2712 fsf_req->erp_action = erp_action;
2713 erp_action->fsf_req = fsf_req;
2715 zfcp_erp_start_timer(fsf_req);
2716 retval = zfcp_fsf_req_send(fsf_req);
2718 ZFCP_LOG_INFO("error: Could not send a close port request for "
2719 "port 0x%016Lx on adapter %s.\n",
2720 erp_action->port->wwpn,
2721 zfcp_get_busid_by_adapter(erp_action->adapter));
2722 zfcp_fsf_req_free(fsf_req);
2723 erp_action->fsf_req = NULL;
2727 ZFCP_LOG_TRACE("close port request initiated "
2728 "(adapter %s, port 0x%016Lx)\n",
2729 zfcp_get_busid_by_adapter(erp_action->adapter),
2730 erp_action->port->wwpn);
2732 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2738 * function: zfcp_fsf_close_port_handler
2740 * purpose: is called for finished Close Port FSF command
2745 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2747 int retval = -EINVAL;
2748 struct zfcp_port *port;
2750 port = (struct zfcp_port *) fsf_req->data;
2752 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2753 /* don't change port status in our bookkeeping */
2754 goto skip_fsfstatus;
2757 /* evaluate FSF status in QTCB */
2758 switch (fsf_req->qtcb->header.fsf_status) {
2760 case FSF_PORT_HANDLE_NOT_VALID:
2761 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2762 "0x%016Lx on adapter %s invalid. This may happen "
2763 "occasionally.\n", port->handle,
2764 port->wwpn, zfcp_get_busid_by_port(port));
2765 ZFCP_LOG_DEBUG("status qualifier:\n");
2766 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2767 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2768 sizeof (union fsf_status_qual));
2769 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2771 zfcp_erp_adapter_reopen(port->adapter, 0, 107, (u64)fsf_req);
2772 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2775 case FSF_ADAPTER_STATUS_AVAILABLE:
2776 /* Note: FSF has actually closed the port in this case.
2777 * The status code is just daft. Fingers crossed for a change
2783 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2784 "port handle 0x%x\n", port->wwpn,
2785 zfcp_get_busid_by_port(port), port->handle);
2786 zfcp_erp_modify_port_status(port, 33, (u64)fsf_req,
2787 ZFCP_STATUS_COMMON_OPEN,
2793 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2794 "(debug info 0x%x)\n",
2795 fsf_req->qtcb->header.fsf_status);
2796 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2797 debug_exception(fsf_req->adapter->erp_dbf, 0,
2798 &fsf_req->qtcb->header.fsf_status,
2804 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2809 * function: zfcp_fsf_close_physical_port
2811 * purpose: submit FSF command "close physical port"
2813 * returns: address of initiated FSF request
2814 * NULL - request could not be initiated
2817 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2819 volatile struct qdio_buffer_element *sbale;
2820 struct zfcp_fsf_req *fsf_req;
2821 unsigned long lock_flags;
2824 /* setup new FSF request */
2825 retval = zfcp_fsf_req_create(erp_action->adapter,
2826 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2827 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2828 erp_action->adapter->pool.fsf_req_erp,
2829 &lock_flags, &fsf_req);
2831 ZFCP_LOG_INFO("error: Could not create close physical port "
2832 "request (adapter %s, port 0x%016Lx)\n",
2833 zfcp_get_busid_by_adapter(erp_action->adapter),
2834 erp_action->port->wwpn);
2839 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2840 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2841 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2843 /* mark port as being closed */
2844 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2845 &erp_action->port->status);
2846 /* save a pointer to this port */
2847 fsf_req->data = (unsigned long) erp_action->port;
2848 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2849 fsf_req->erp_action = erp_action;
2850 erp_action->fsf_req = fsf_req;
2852 zfcp_erp_start_timer(fsf_req);
2853 retval = zfcp_fsf_req_send(fsf_req);
2855 ZFCP_LOG_INFO("error: Could not send close physical port "
2856 "request (adapter %s, port 0x%016Lx)\n",
2857 zfcp_get_busid_by_adapter(erp_action->adapter),
2858 erp_action->port->wwpn);
2859 zfcp_fsf_req_free(fsf_req);
2860 erp_action->fsf_req = NULL;
2864 ZFCP_LOG_TRACE("close physical port request initiated "
2865 "(adapter %s, port 0x%016Lx)\n",
2866 zfcp_get_busid_by_adapter(erp_action->adapter),
2867 erp_action->port->wwpn);
2869 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2875 * function: zfcp_fsf_close_physical_port_handler
2877 * purpose: is called for finished Close Physical Port FSF command
2882 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2884 int retval = -EINVAL;
2885 struct zfcp_port *port;
2886 struct zfcp_unit *unit;
2887 struct fsf_qtcb_header *header;
2888 u16 subtable, rule, counter;
2890 port = (struct zfcp_port *) fsf_req->data;
2891 header = &fsf_req->qtcb->header;
2893 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2894 /* don't change port status in our bookkeeping */
2895 goto skip_fsfstatus;
2898 /* evaluate FSF status in QTCB */
2899 switch (header->fsf_status) {
2901 case FSF_PORT_HANDLE_NOT_VALID:
2902 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2903 "(adapter %s, port 0x%016Lx). "
2904 "This may happen occasionally.\n",
2906 zfcp_get_busid_by_port(port),
2908 ZFCP_LOG_DEBUG("status qualifier:\n");
2909 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2910 (char *) &header->fsf_status_qual,
2911 sizeof (union fsf_status_qual));
2912 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2914 zfcp_erp_adapter_reopen(port->adapter, 0, 108, (u64)fsf_req);
2915 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2918 case FSF_ACCESS_DENIED:
2919 ZFCP_LOG_NORMAL("Access denied, cannot close "
2920 "physical port 0x%016Lx on adapter %s\n",
2921 port->wwpn, zfcp_get_busid_by_port(port));
2922 for (counter = 0; counter < 2; counter++) {
2923 subtable = header->fsf_status_qual.halfword[counter * 2];
2924 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2926 case FSF_SQ_CFDC_SUBTABLE_OS:
2927 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2928 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2929 case FSF_SQ_CFDC_SUBTABLE_LUN:
2930 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2931 zfcp_act_subtable_type[subtable], rule);
2935 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2936 zfcp_erp_port_access_denied(port, 58, (u64)fsf_req);
2937 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2940 case FSF_PORT_BOXED:
2941 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2942 "%s needs to be reopened but it was attempted "
2943 "to close it physically.\n",
2945 zfcp_get_busid_by_port(port));
2946 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2947 zfcp_erp_port_boxed(port, 50, (u64)fsf_req);
2948 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2949 ZFCP_STATUS_FSFREQ_RETRY;
2951 /* can't use generic zfcp_erp_modify_port_status because
2952 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2953 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2954 list_for_each_entry(unit, &port->unit_list_head, list)
2955 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2959 case FSF_ADAPTER_STATUS_AVAILABLE:
2960 switch (header->fsf_status_qual.word[0]) {
2961 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2962 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2964 /* This will now be escalated by ERP */
2965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2967 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2968 /* ERP strategy will escalate */
2969 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2971 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2975 ("bug: Wrong status qualifier 0x%x arrived.\n",
2976 header->fsf_status_qual.word[0]);
2977 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2980 fsf_req->adapter->erp_dbf, 0,
2981 &header->fsf_status_qual.word[0], sizeof (u32));
2987 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2988 "physically closed, port handle 0x%x\n",
2990 zfcp_get_busid_by_port(port), port->handle);
2991 /* can't use generic zfcp_erp_modify_port_status because
2992 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2994 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2995 list_for_each_entry(unit, &port->unit_list_head, list)
2996 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3001 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3002 "(debug info 0x%x)\n",
3003 header->fsf_status);
3004 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3005 debug_exception(fsf_req->adapter->erp_dbf, 0,
3006 &header->fsf_status, sizeof (u32));
3011 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
3016 * function: zfcp_fsf_open_unit
3022 * assumptions: This routine does not check whether the associated
3023 * remote port has already been opened. This should be
3024 * done by calling routines. Otherwise some status
3025 * may be presented by FSF
3028 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
3030 volatile struct qdio_buffer_element *sbale;
3031 struct zfcp_fsf_req *fsf_req;
3032 unsigned long lock_flags;
3035 /* setup new FSF request */
3036 retval = zfcp_fsf_req_create(erp_action->adapter,
3038 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3039 erp_action->adapter->pool.fsf_req_erp,
3040 &lock_flags, &fsf_req);
3042 ZFCP_LOG_INFO("error: Could not create open unit request for "
3043 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3044 erp_action->unit->fcp_lun,
3045 erp_action->unit->port->wwpn,
3046 zfcp_get_busid_by_adapter(erp_action->adapter));
3050 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3051 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3052 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3054 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3055 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
3056 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
3057 fsf_req->qtcb->bottom.support.option =
3058 FSF_OPEN_LUN_SUPPRESS_BOXING;
3059 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
3060 fsf_req->data = (unsigned long) erp_action->unit;
3061 fsf_req->erp_action = erp_action;
3062 erp_action->fsf_req = fsf_req;
3064 zfcp_erp_start_timer(fsf_req);
3065 retval = zfcp_fsf_req_send(erp_action->fsf_req);
3067 ZFCP_LOG_INFO("error: Could not send an open unit request "
3068 "on the adapter %s, port 0x%016Lx for "
3070 zfcp_get_busid_by_adapter(erp_action->adapter),
3071 erp_action->port->wwpn,
3072 erp_action->unit->fcp_lun);
3073 zfcp_fsf_req_free(fsf_req);
3074 erp_action->fsf_req = NULL;
3078 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
3079 "port 0x%016Lx, unit 0x%016Lx)\n",
3080 zfcp_get_busid_by_adapter(erp_action->adapter),
3081 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3083 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3089 * function: zfcp_fsf_open_unit_handler
3091 * purpose: is called for finished Open LUN command
3096 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3098 int retval = -EINVAL;
3099 struct zfcp_adapter *adapter;
3100 struct zfcp_unit *unit;
3101 struct fsf_qtcb_header *header;
3102 struct fsf_qtcb_bottom_support *bottom;
3103 struct fsf_queue_designator *queue_designator;
3104 u16 subtable, rule, counter;
3105 int exclusive, readwrite;
3107 unit = (struct zfcp_unit *) fsf_req->data;
3109 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3110 /* don't change unit status in our bookkeeping */
3111 goto skip_fsfstatus;
3114 adapter = fsf_req->adapter;
3115 header = &fsf_req->qtcb->header;
3116 bottom = &fsf_req->qtcb->bottom.support;
3117 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3119 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3120 ZFCP_STATUS_COMMON_ACCESS_BOXED |
3121 ZFCP_STATUS_UNIT_SHARED |
3122 ZFCP_STATUS_UNIT_READONLY,
3125 /* evaluate FSF status in QTCB */
3126 switch (header->fsf_status) {
3128 case FSF_PORT_HANDLE_NOT_VALID:
3129 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3130 "for port 0x%016Lx on adapter %s invalid "
3131 "This may happen occasionally\n",
3133 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3134 ZFCP_LOG_DEBUG("status qualifier:\n");
3135 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3136 (char *) &header->fsf_status_qual,
3137 sizeof (union fsf_status_qual));
3138 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3139 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109,
3141 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3144 case FSF_LUN_ALREADY_OPEN:
3145 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3146 "remote port 0x%016Lx on adapter %s twice.\n",
3148 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3149 debug_text_exception(adapter->erp_dbf, 0,
3151 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3154 case FSF_ACCESS_DENIED:
3155 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3156 "remote port 0x%016Lx on adapter %s\n",
3157 unit->fcp_lun, unit->port->wwpn,
3158 zfcp_get_busid_by_unit(unit));
3159 for (counter = 0; counter < 2; counter++) {
3160 subtable = header->fsf_status_qual.halfword[counter * 2];
3161 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3163 case FSF_SQ_CFDC_SUBTABLE_OS:
3164 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3165 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3166 case FSF_SQ_CFDC_SUBTABLE_LUN:
3167 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3168 zfcp_act_subtable_type[subtable], rule);
3172 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3173 zfcp_erp_unit_access_denied(unit, 59, (u64)fsf_req);
3174 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3175 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3176 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3179 case FSF_PORT_BOXED:
3180 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3181 "needs to be reopened\n",
3182 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3183 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3184 zfcp_erp_port_boxed(unit->port, 51, (u64)fsf_req);
3185 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3186 ZFCP_STATUS_FSFREQ_RETRY;
3189 case FSF_LUN_SHARING_VIOLATION:
3190 if (header->fsf_status_qual.word[0] != 0) {
3191 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3193 "connected to the adapter %s "
3194 "is already in use in LPAR%d, CSS%d\n",
3197 zfcp_get_busid_by_unit(unit),
3198 queue_designator->hla,
3199 queue_designator->cssid);
3201 subtable = header->fsf_status_qual.halfword[4];
3202 rule = header->fsf_status_qual.halfword[5];
3204 case FSF_SQ_CFDC_SUBTABLE_OS:
3205 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3206 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3207 case FSF_SQ_CFDC_SUBTABLE_LUN:
3208 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3209 "remote port with WWPN 0x%Lx "
3210 "connected to the adapter %s "
3211 "is denied (%s rule %d)\n",
3214 zfcp_get_busid_by_unit(unit),
3215 zfcp_act_subtable_type[subtable],
3220 ZFCP_LOG_DEBUG("status qualifier:\n");
3221 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3222 (char *) &header->fsf_status_qual,
3223 sizeof (union fsf_status_qual));
3224 debug_text_event(adapter->erp_dbf, 2,
3226 zfcp_erp_unit_access_denied(unit, 60, (u64)fsf_req);
3227 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3228 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3229 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3232 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3233 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3234 "There is no handle (temporary port identifier) "
3235 "available for unit 0x%016Lx on port 0x%016Lx "
3239 zfcp_get_busid_by_unit(unit));
3240 debug_text_event(adapter->erp_dbf, 1,
3242 zfcp_erp_unit_failed(unit, 34, (u64)fsf_req);
3243 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3246 case FSF_ADAPTER_STATUS_AVAILABLE:
3247 switch (header->fsf_status_qual.word[0]) {
3248 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3249 /* Re-establish link to port */
3250 debug_text_event(adapter->erp_dbf, 1,
3252 zfcp_test_link(unit->port);
3253 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3255 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3256 /* ERP strategy will escalate */
3257 debug_text_event(adapter->erp_dbf, 1,
3259 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3263 ("bug: Wrong status qualifier 0x%x arrived.\n",
3264 header->fsf_status_qual.word[0]);
3265 debug_text_event(adapter->erp_dbf, 0,
3267 debug_exception(adapter->erp_dbf, 0,
3268 &header->fsf_status_qual.word[0],
3273 case FSF_INVALID_COMMAND_OPTION:
3275 "Invalid option 0x%x has been specified "
3276 "in QTCB bottom sent to the adapter %s\n",
3278 zfcp_get_busid_by_adapter(adapter));
3279 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3284 /* save LUN handle assigned by FSF */
3285 unit->handle = header->lun_handle;
3286 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3287 "adapter %s opened, port handle 0x%x\n",
3290 zfcp_get_busid_by_unit(unit),
3292 /* mark unit as open */
3293 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3295 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3296 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3297 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3298 exclusive = (bottom->lun_access_info &
3299 FSF_UNIT_ACCESS_EXCLUSIVE);
3300 readwrite = (bottom->lun_access_info &
3301 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3304 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3308 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3310 ZFCP_LOG_NORMAL("read-only access for unit "
3311 "(adapter %s, wwpn=0x%016Lx, "
3312 "fcp_lun=0x%016Lx)\n",
3313 zfcp_get_busid_by_unit(unit),
3318 if (exclusive && !readwrite) {
3319 ZFCP_LOG_NORMAL("exclusive access of read-only "
3320 "unit not supported\n");
3321 zfcp_erp_unit_failed(unit, 35, (u64)fsf_req);
3322 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3323 zfcp_erp_unit_shutdown(unit, 0, 80,
3325 } else if (!exclusive && readwrite) {
3326 ZFCP_LOG_NORMAL("shared access of read-write "
3327 "unit not supported\n");
3328 zfcp_erp_unit_failed(unit, 36, (u64)fsf_req);
3329 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3330 zfcp_erp_unit_shutdown(unit, 0, 81,
3339 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3340 "(debug info 0x%x)\n",
3341 header->fsf_status);
3342 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3343 debug_exception(adapter->erp_dbf, 0,
3344 &header->fsf_status, sizeof (u32));
3349 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3354 * function: zfcp_fsf_close_unit
3358 * returns: address of fsf_req - request successfully initiated
3361 * assumptions: This routine does not check whether the associated
3362 * remote port/lun has already been opened. This should be
3363 * done by calling routines. Otherwise some status
3364 * may be presented by FSF
3367 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3369 volatile struct qdio_buffer_element *sbale;
3370 struct zfcp_fsf_req *fsf_req;
3371 unsigned long lock_flags;
3374 /* setup new FSF request */
3375 retval = zfcp_fsf_req_create(erp_action->adapter,
3377 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3378 erp_action->adapter->pool.fsf_req_erp,
3379 &lock_flags, &fsf_req);
3381 ZFCP_LOG_INFO("error: Could not create close unit request for "
3382 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3383 erp_action->unit->fcp_lun,
3384 erp_action->port->wwpn,
3385 zfcp_get_busid_by_adapter(erp_action->adapter));
3389 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3390 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3391 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3393 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3394 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3395 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3396 fsf_req->data = (unsigned long) erp_action->unit;
3397 fsf_req->erp_action = erp_action;
3398 erp_action->fsf_req = fsf_req;
3400 zfcp_erp_start_timer(fsf_req);
3401 retval = zfcp_fsf_req_send(erp_action->fsf_req);
3403 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3404 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3405 erp_action->unit->fcp_lun,
3406 erp_action->port->wwpn,
3407 zfcp_get_busid_by_adapter(erp_action->adapter));
3408 zfcp_fsf_req_free(fsf_req);
3409 erp_action->fsf_req = NULL;
3413 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3414 "port 0x%016Lx, unit 0x%016Lx)\n",
3415 zfcp_get_busid_by_adapter(erp_action->adapter),
3416 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3418 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3424 * function: zfcp_fsf_close_unit_handler
3426 * purpose: is called for finished Close LUN FSF command
3431 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3433 int retval = -EINVAL;
3434 struct zfcp_unit *unit;
3436 unit = (struct zfcp_unit *) fsf_req->data;
3438 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3439 /* don't change unit status in our bookkeeping */
3440 goto skip_fsfstatus;
3443 /* evaluate FSF status in QTCB */
3444 switch (fsf_req->qtcb->header.fsf_status) {
3446 case FSF_PORT_HANDLE_NOT_VALID:
3447 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3448 "0x%016Lx on adapter %s invalid. This may "
3449 "happen in rare circumstances\n",
3452 zfcp_get_busid_by_unit(unit));
3453 ZFCP_LOG_DEBUG("status qualifier:\n");
3454 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3455 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3456 sizeof (union fsf_status_qual));
3457 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3459 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110,
3461 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3464 case FSF_LUN_HANDLE_NOT_VALID:
3465 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3466 "0x%016Lx on port 0x%016Lx on adapter %s is "
3467 "invalid. This may happen occasionally.\n",
3471 zfcp_get_busid_by_unit(unit));
3472 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3473 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3474 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3475 sizeof (union fsf_status_qual));
3476 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3478 zfcp_erp_port_reopen(unit->port, 0, 111, (u64)fsf_req);
3479 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3482 case FSF_PORT_BOXED:
3483 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3484 "needs to be reopened\n",
3486 zfcp_get_busid_by_unit(unit));
3487 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3488 zfcp_erp_port_boxed(unit->port, 52, (u64)fsf_req);
3489 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3490 ZFCP_STATUS_FSFREQ_RETRY;
3493 case FSF_ADAPTER_STATUS_AVAILABLE:
3494 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3495 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3496 /* re-establish link to port */
3497 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3499 zfcp_test_link(unit->port);
3500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3502 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3503 /* ERP strategy will escalate */
3504 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3510 ("bug: Wrong status qualifier 0x%x arrived.\n",
3511 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3512 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3515 fsf_req->adapter->erp_dbf, 0,
3516 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3523 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3524 "closed, port handle 0x%x\n",
3527 zfcp_get_busid_by_unit(unit),
3529 /* mark unit as closed */
3530 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3535 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3536 "(debug info 0x%x)\n",
3537 fsf_req->qtcb->header.fsf_status);
3538 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3539 debug_exception(fsf_req->adapter->erp_dbf, 0,
3540 &fsf_req->qtcb->header.fsf_status,
3546 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3551 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3552 * @adapter: adapter where scsi command is issued
3553 * @unit: unit where command is sent to
3554 * @scsi_cmnd: scsi command to be sent
3555 * @timer: timer to be started when request is initiated
3556 * @req_flags: flags for fsf_request
3559 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3560 struct zfcp_unit *unit,
3561 struct scsi_cmnd * scsi_cmnd,
3562 int use_timer, int req_flags)
3564 struct zfcp_fsf_req *fsf_req = NULL;
3565 struct fcp_cmnd_iu *fcp_cmnd_iu;
3566 unsigned int sbtype;
3567 unsigned long lock_flags;
3572 /* setup new FSF request */
3573 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3574 adapter->pool.fsf_req_scsi,
3575 &lock_flags, &fsf_req);
3576 if (unlikely(retval < 0)) {
3577 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3578 "for unit 0x%016Lx on port 0x%016Lx on "
3582 zfcp_get_busid_by_adapter(adapter));
3583 goto failed_req_create;
3586 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3592 zfcp_unit_get(unit);
3593 fsf_req->unit = unit;
3595 /* associate FSF request with SCSI request (for look up on abort) */
3596 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3598 /* associate SCSI command with FSF request */
3599 fsf_req->data = (unsigned long) scsi_cmnd;
3601 /* set handles of unit and its parent port in QTCB */
3602 fsf_req->qtcb->header.lun_handle = unit->handle;
3603 fsf_req->qtcb->header.port_handle = unit->port->handle;
3605 /* FSF does not define the structure of the FCP_CMND IU */
3606 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3607 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3610 * set depending on data direction:
3611 * data direction bits in SBALE (SB Type)
3612 * data direction bits in QTCB
3613 * data direction bits in FCP_CMND IU
3615 switch (scsi_cmnd->sc_data_direction) {
3617 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3620 * what is the correct type for commands
3621 * without 'real' data buffers?
3623 sbtype = SBAL_FLAGS0_TYPE_READ;
3625 case DMA_FROM_DEVICE:
3626 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3627 sbtype = SBAL_FLAGS0_TYPE_READ;
3628 fcp_cmnd_iu->rddata = 1;
3631 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3632 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3633 fcp_cmnd_iu->wddata = 1;
3635 case DMA_BIDIRECTIONAL:
3638 * dummy, catch this condition earlier
3639 * in zfcp_scsi_queuecommand
3641 goto failed_scsi_cmnd;
3644 /* set FC service class in QTCB (3 per default) */
3645 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3647 /* set FCP_LUN in FCP_CMND IU in QTCB */
3648 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3650 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3652 /* set task attributes in FCP_CMND IU in QTCB */
3653 if (likely((scsi_cmnd->device->simple_tags) ||
3654 (atomic_test_mask(mask, &unit->status))))
3655 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3657 fcp_cmnd_iu->task_attribute = UNTAGGED;
3659 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3660 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3661 fcp_cmnd_iu->add_fcp_cdb_length
3662 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3663 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3664 "additional FCP_CDB length is 0x%x "
3665 "(shifted right 2 bits)\n",
3667 fcp_cmnd_iu->add_fcp_cdb_length);
3670 * copy SCSI CDB (including additional length, if any) to
3671 * FCP_CDB in FCP_CMND IU in QTCB
3673 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3675 /* FCP CMND IU length in QTCB */
3676 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3677 sizeof (struct fcp_cmnd_iu) +
3678 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3680 /* generate SBALEs from data buffer */
3681 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3682 if (unlikely(real_bytes < 0)) {
3683 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3685 "Data did not fit into available buffer(s), "
3686 "waiting for more...\n");
3689 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3690 "required. Shutting down unit "
3691 "(adapter %s, port 0x%016Lx, "
3693 zfcp_get_busid_by_unit(unit),
3696 zfcp_erp_unit_shutdown(unit, 0, 131, (u64)fsf_req);
3702 /* set length of FCP data length in FCP_CMND IU in QTCB */
3703 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3705 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3706 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3707 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3710 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3712 retval = zfcp_fsf_req_send(fsf_req);
3713 if (unlikely(retval < 0)) {
3714 ZFCP_LOG_INFO("error: Could not send FCP command request "
3715 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3716 zfcp_get_busid_by_adapter(adapter),
3722 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3723 "port 0x%016Lx, unit 0x%016Lx)\n",
3724 zfcp_get_busid_by_adapter(adapter),
3733 zfcp_unit_put(unit);
3734 zfcp_fsf_req_free(fsf_req);
3736 scsi_cmnd->host_scribble = NULL;
3739 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3743 struct zfcp_fsf_req *
3744 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3745 struct zfcp_unit *unit,
3746 u8 tm_flags, int req_flags)
3748 struct zfcp_fsf_req *fsf_req = NULL;
3750 struct fcp_cmnd_iu *fcp_cmnd_iu;
3751 unsigned long lock_flags;
3752 volatile struct qdio_buffer_element *sbale;
3754 /* setup new FSF request */
3755 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3756 adapter->pool.fsf_req_scsi,
3757 &lock_flags, &fsf_req);
3759 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3760 "management) request for adapter %s, port "
3761 " 0x%016Lx, unit 0x%016Lx.\n",
3762 zfcp_get_busid_by_adapter(adapter),
3763 unit->port->wwpn, unit->fcp_lun);
3767 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3772 * Used to decide on proper handler in the return path,
3773 * could be either zfcp_fsf_send_fcp_command_task_handler or
3774 * zfcp_fsf_send_fcp_command_task_management_handler */
3776 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3779 * hold a pointer to the unit being target of this
3780 * task management request
3782 fsf_req->data = (unsigned long) unit;
3784 /* set FSF related fields in QTCB */
3785 fsf_req->qtcb->header.lun_handle = unit->handle;
3786 fsf_req->qtcb->header.port_handle = unit->port->handle;
3787 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3788 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3789 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3790 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3792 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3793 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3794 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3796 /* set FCP related fields in FCP_CMND IU in QTCB */
3797 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3798 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3799 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3800 fcp_cmnd_iu->task_management_flags = tm_flags;
3802 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3803 retval = zfcp_fsf_req_send(fsf_req);
3808 zfcp_fsf_req_free(fsf_req);
3812 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3817 * function: zfcp_fsf_send_fcp_command_handler
3819 * purpose: is called for finished Send FCP Command
3824 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3826 int retval = -EINVAL;
3827 struct zfcp_unit *unit;
3828 struct fsf_qtcb_header *header;
3829 u16 subtable, rule, counter;
3831 header = &fsf_req->qtcb->header;
3833 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3834 unit = (struct zfcp_unit *) fsf_req->data;
3836 unit = fsf_req->unit;
3838 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3839 /* go directly to calls of special handlers */
3840 goto skip_fsfstatus;
3843 /* evaluate FSF status in QTCB */
3844 switch (header->fsf_status) {
3846 case FSF_PORT_HANDLE_NOT_VALID:
3847 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3848 "0x%016Lx on adapter %s invalid\n",
3850 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3851 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3852 (char *) &header->fsf_status_qual,
3853 sizeof (union fsf_status_qual));
3854 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3856 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112,
3858 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3861 case FSF_LUN_HANDLE_NOT_VALID:
3862 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3863 "0x%016Lx on port 0x%016Lx on adapter %s is "
3864 "invalid. This may happen occasionally.\n",
3868 zfcp_get_busid_by_unit(unit));
3869 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3870 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3871 (char *) &header->fsf_status_qual,
3872 sizeof (union fsf_status_qual));
3873 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3875 zfcp_erp_port_reopen(unit->port, 0, 113, (u64)fsf_req);
3876 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3879 case FSF_HANDLE_MISMATCH:
3880 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3881 "unexpectedly. (adapter %s, port 0x%016Lx, "
3884 zfcp_get_busid_by_unit(unit),
3887 ZFCP_LOG_NORMAL("status qualifier:\n");
3888 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3889 (char *) &header->fsf_status_qual,
3890 sizeof (union fsf_status_qual));
3891 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3893 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114,
3895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3898 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3899 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3901 zfcp_get_busid_by_unit(unit),
3902 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3903 /* stop operation for this adapter */
3904 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3905 "fsf_s_class_nsup");
3906 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132,
3908 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3911 case FSF_FCPLUN_NOT_VALID:
3912 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3913 "adapter %s does not have correct unit "
3917 zfcp_get_busid_by_unit(unit),
3919 ZFCP_LOG_DEBUG("status qualifier:\n");
3920 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3921 (char *) &header->fsf_status_qual,
3922 sizeof (union fsf_status_qual));
3923 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3924 "fsf_s_fcp_lun_nv");
3925 zfcp_erp_port_reopen(unit->port, 0, 115, (u64)fsf_req);
3926 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3929 case FSF_ACCESS_DENIED:
3930 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3931 "unit 0x%016Lx on port 0x%016Lx on "
3932 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3933 zfcp_get_busid_by_unit(unit));
3934 for (counter = 0; counter < 2; counter++) {
3935 subtable = header->fsf_status_qual.halfword[counter * 2];
3936 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3938 case FSF_SQ_CFDC_SUBTABLE_OS:
3939 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3940 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3941 case FSF_SQ_CFDC_SUBTABLE_LUN:
3942 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3943 zfcp_act_subtable_type[subtable], rule);
3947 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3948 zfcp_erp_unit_access_denied(unit, 61, (u64)fsf_req);
3949 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3952 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3953 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3954 "0x%016Lx on port 0x%016Lx on adapter %s "
3955 "(debug info %d)\n",
3958 zfcp_get_busid_by_unit(unit),
3959 fsf_req->qtcb->bottom.io.data_direction);
3960 /* stop operation for this adapter */
3961 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3962 "fsf_s_dir_ind_nv");
3963 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133,
3965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3968 case FSF_CMND_LENGTH_NOT_VALID:
3970 ("bug: An invalid control-data-block length field "
3971 "was found in a command for unit 0x%016Lx on port "
3972 "0x%016Lx on adapter %s " "(debug info %d)\n",
3973 unit->fcp_lun, unit->port->wwpn,
3974 zfcp_get_busid_by_unit(unit),
3975 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3976 /* stop operation for this adapter */
3977 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3978 "fsf_s_cmd_len_nv");
3979 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134,
3981 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3984 case FSF_PORT_BOXED:
3985 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3986 "needs to be reopened\n",
3987 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3988 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3989 zfcp_erp_port_boxed(unit->port, 53, (u64)fsf_req);
3990 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3991 ZFCP_STATUS_FSFREQ_RETRY;
3995 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3996 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3997 zfcp_get_busid_by_unit(unit),
3998 unit->port->wwpn, unit->fcp_lun);
3999 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
4000 zfcp_erp_unit_boxed(unit, 54, (u64)fsf_req);
4001 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
4002 | ZFCP_STATUS_FSFREQ_RETRY;
4005 case FSF_ADAPTER_STATUS_AVAILABLE:
4006 switch (header->fsf_status_qual.word[0]) {
4007 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
4008 /* re-establish link to port */
4009 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4011 zfcp_test_link(unit->port);
4013 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
4014 /* FIXME(hw) need proper specs for proper action */
4015 /* let scsi stack deal with retries and escalation */
4016 debug_text_event(fsf_req->adapter->erp_dbf, 1,
4021 ("Unknown status qualifier 0x%x arrived.\n",
4022 header->fsf_status_qual.word[0]);
4023 debug_text_event(fsf_req->adapter->erp_dbf, 0,
4025 debug_exception(fsf_req->adapter->erp_dbf, 0,
4026 &header->fsf_status_qual.word[0],
4030 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4036 case FSF_FCP_RSP_AVAILABLE:
4040 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
4041 debug_exception(fsf_req->adapter->erp_dbf, 0,
4042 &header->fsf_status, sizeof(u32));
4047 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
4049 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
4051 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
4052 fsf_req->unit = NULL;
4053 zfcp_unit_put(unit);
4059 * function: zfcp_fsf_send_fcp_command_task_handler
4061 * purpose: evaluates FCP_RSP IU
4066 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4069 struct scsi_cmnd *scpnt;
4070 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4071 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4072 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4073 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4075 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4076 unsigned long flags;
4077 struct zfcp_unit *unit = fsf_req->unit;
4079 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4080 scpnt = (struct scsi_cmnd *) fsf_req->data;
4081 if (unlikely(!scpnt)) {
4083 ("Command with fsf_req %p is not associated to "
4084 "a scsi command anymore. Aborted?\n", fsf_req);
4087 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4088 /* FIXME: (design) mid-layer should handle DID_ABORT like
4089 * DID_SOFT_ERROR by retrying the request for devices
4090 * that allow retries.
4092 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4093 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4094 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4095 goto skip_fsfstatus;
4098 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4099 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4100 set_host_byte(&scpnt->result, DID_ERROR);
4101 goto skip_fsfstatus;
4104 /* set message byte of result in SCSI command */
4105 scpnt->result |= COMMAND_COMPLETE << 8;
4108 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4109 * of result in SCSI command
4111 scpnt->result |= fcp_rsp_iu->scsi_status;
4112 if (unlikely(fcp_rsp_iu->scsi_status)) {
4114 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4115 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4116 scpnt->cmnd, scpnt->cmd_len);
4117 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4118 fcp_rsp_iu->scsi_status);
4119 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4120 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4121 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4122 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4123 fcp_rsp_iu->fcp_sns_len);
4126 /* check FCP_RSP_INFO */
4127 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4128 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4129 switch (fcp_rsp_info[3]) {
4132 ZFCP_LOG_TRACE("no failure or Task Management "
4133 "Function complete\n");
4134 set_host_byte(&scpnt->result, DID_OK);
4136 case RSP_CODE_LENGTH_MISMATCH:
4138 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4139 "that the fibrechannel protocol data "
4140 "length differs from the burst length. "
4141 "The problem occured on unit 0x%016Lx "
4142 "on port 0x%016Lx on adapter %s",
4145 zfcp_get_busid_by_unit(unit));
4146 /* dump SCSI CDB as prepared by zfcp */
4147 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4148 (char *) &fsf_req->qtcb->
4149 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4150 set_host_byte(&scpnt->result, DID_ERROR);
4151 goto skip_fsfstatus;
4152 case RSP_CODE_FIELD_INVALID:
4153 /* driver or hardware bug */
4154 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4155 "that the fibrechannel protocol data "
4156 "fields were incorrectly set up. "
4157 "The problem occured on the unit "
4158 "0x%016Lx on port 0x%016Lx on "
4162 zfcp_get_busid_by_unit(unit));
4163 /* dump SCSI CDB as prepared by zfcp */
4164 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4165 (char *) &fsf_req->qtcb->
4166 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4167 set_host_byte(&scpnt->result, DID_ERROR);
4168 goto skip_fsfstatus;
4169 case RSP_CODE_RO_MISMATCH:
4171 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4172 "that conflicting values for the "
4173 "fibrechannel payload offset from the "
4174 "header were found. "
4175 "The problem occured on unit 0x%016Lx "
4176 "on port 0x%016Lx on adapter %s.\n",
4179 zfcp_get_busid_by_unit(unit));
4180 /* dump SCSI CDB as prepared by zfcp */
4181 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4182 (char *) &fsf_req->qtcb->
4183 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4184 set_host_byte(&scpnt->result, DID_ERROR);
4185 goto skip_fsfstatus;
4187 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4188 "code was detected for a command. "
4189 "The problem occured on the unit "
4190 "0x%016Lx on port 0x%016Lx on "
4191 "adapter %s (debug info 0x%x)\n",
4194 zfcp_get_busid_by_unit(unit),
4196 /* dump SCSI CDB as prepared by zfcp */
4197 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4198 (char *) &fsf_req->qtcb->
4199 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4200 set_host_byte(&scpnt->result, DID_ERROR);
4201 goto skip_fsfstatus;
4205 /* check for sense data */
4206 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4207 sns_len = FSF_FCP_RSP_SIZE -
4208 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4209 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4211 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4212 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4213 SCSI_SENSE_BUFFERSIZE);
4214 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4215 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4217 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4218 (void *) &scpnt->cmnd, scpnt->cmd_len);
4220 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4221 fcp_rsp_iu->fcp_sns_len);
4222 memcpy(scpnt->sense_buffer,
4223 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4224 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4225 (void *)scpnt->sense_buffer, sns_len);
4228 /* check for overrun */
4229 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4230 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4231 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4232 "The response data length is "
4233 "%d, the original length was %d.\n",
4236 zfcp_get_busid_by_unit(unit),
4237 fcp_rsp_iu->fcp_resid,
4238 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4241 /* check for underrun */
4242 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4243 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4244 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4245 "The response data length is "
4246 "%d, the original length was %d.\n",
4249 zfcp_get_busid_by_unit(unit),
4250 fcp_rsp_iu->fcp_resid,
4251 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4253 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4254 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4256 set_host_byte(&scpnt->result, DID_ERROR);
4260 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4262 if (scpnt->result != 0)
4263 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4264 else if (scpnt->retries > 0)
4265 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4267 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4269 /* cleanup pointer (need this especially for abort) */
4270 scpnt->host_scribble = NULL;
4272 /* always call back */
4273 (scpnt->scsi_done) (scpnt);
4276 * We must hold this lock until scsi_done has been called.
4277 * Otherwise we may call scsi_done after abort regarding this
4278 * command has completed.
4279 * Note: scsi_done must not block!
4282 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4287 * function: zfcp_fsf_send_fcp_command_task_management_handler
4289 * purpose: evaluates FCP_RSP IU
4294 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4297 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4298 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4299 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4300 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4302 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4303 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4304 goto skip_fsfstatus;
4307 /* check FCP_RSP_INFO */
4308 switch (fcp_rsp_info[3]) {
4311 ZFCP_LOG_DEBUG("no failure or Task Management "
4312 "Function complete\n");
4314 case RSP_CODE_TASKMAN_UNSUPP:
4315 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4316 "is not supported on the target device "
4317 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4320 zfcp_get_busid_by_unit(unit));
4321 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4323 case RSP_CODE_TASKMAN_FAILED:
4324 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4325 "failed to complete successfully. "
4326 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4329 zfcp_get_busid_by_unit(unit));
4330 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4333 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4334 "code was detected for a command. "
4335 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4336 "(debug info 0x%x)\n",
4339 zfcp_get_busid_by_unit(unit),
4341 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4350 * function: zfcp_fsf_control_file
4352 * purpose: Initiator of the control file upload/download FSF requests
4354 * returns: 0 - FSF request is successfuly created and queued
4355 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4356 * -EINVAL - Invalid direction specified
4357 * -ENOMEM - Insufficient memory
4358 * -EPERM - Cannot create FSF request or place it in QDIO queue
4361 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4362 struct zfcp_fsf_req **fsf_req_ptr,
4365 struct zfcp_sg_list *sg_list)
4367 struct zfcp_fsf_req *fsf_req;
4368 struct fsf_qtcb_bottom_support *bottom;
4369 volatile struct qdio_buffer_element *sbale;
4370 unsigned long lock_flags;
4375 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4376 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4377 zfcp_get_busid_by_adapter(adapter));
4378 retval = -EOPNOTSUPP;
4382 switch (fsf_command) {
4384 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4385 direction = SBAL_FLAGS0_TYPE_WRITE;
4386 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4387 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4388 req_flags = ZFCP_WAIT_FOR_SBAL;
4391 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4392 direction = SBAL_FLAGS0_TYPE_READ;
4396 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4401 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4402 NULL, &lock_flags, &fsf_req);
4404 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4406 zfcp_get_busid_by_adapter(adapter));
4408 goto unlock_queue_lock;
4411 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4412 sbale[0].flags |= direction;
4414 bottom = &fsf_req->qtcb->bottom.support;
4415 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4416 bottom->option = option;
4418 if (sg_list->count > 0) {
4421 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4422 sg_list->sg, sg_list->count,
4423 ZFCP_MAX_SBALS_PER_REQ);
4424 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4426 "error: Could not create sufficient number of "
4427 "SBALS for an FSF request to the adapter %s\n",
4428 zfcp_get_busid_by_adapter(adapter));
4433 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4435 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4436 retval = zfcp_fsf_req_send(fsf_req);
4438 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4440 zfcp_get_busid_by_adapter(adapter));
4444 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4446 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4448 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4449 "download" : "upload",
4450 zfcp_get_busid_by_adapter(adapter));
4452 wait_event(fsf_req->completion_wq,
4453 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4455 *fsf_req_ptr = fsf_req;
4459 zfcp_fsf_req_free(fsf_req);
4461 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4468 * function: zfcp_fsf_control_file_handler
4470 * purpose: Handler of the control file upload/download FSF requests
4472 * returns: 0 - FSF request successfuly processed
4473 * -EAGAIN - Operation has to be repeated because of a temporary problem
4474 * -EACCES - There is no permission to execute an operation
4475 * -EPERM - The control file is not in a right format
4476 * -EIO - There is a problem with the FCP adapter
4477 * -EINVAL - Invalid operation
4478 * -EFAULT - User space memory I/O operation fault
4481 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4483 struct zfcp_adapter *adapter = fsf_req->adapter;
4484 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4485 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4488 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4490 goto skip_fsfstatus;
4493 switch (header->fsf_status) {
4497 "The FSF request has been successfully completed "
4498 "on the adapter %s\n",
4499 zfcp_get_busid_by_adapter(adapter));
4502 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4503 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4504 switch (header->fsf_status_qual.word[0]) {
4506 case FSF_SQ_CFDC_HARDENED_ON_SE:
4508 "CFDC on the adapter %s has being "
4509 "hardened on primary and secondary SE\n",
4510 zfcp_get_busid_by_adapter(adapter));
4513 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4515 "CFDC of the adapter %s could not "
4516 "be saved on the SE\n",
4517 zfcp_get_busid_by_adapter(adapter));
4520 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4522 "CFDC of the adapter %s could not "
4523 "be copied to the secondary SE\n",
4524 zfcp_get_busid_by_adapter(adapter));
4529 "CFDC could not be hardened "
4530 "on the adapter %s\n",
4531 zfcp_get_busid_by_adapter(adapter));
4534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4538 case FSF_AUTHORIZATION_FAILURE:
4540 "Adapter %s does not accept privileged commands\n",
4541 zfcp_get_busid_by_adapter(adapter));
4542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4546 case FSF_CFDC_ERROR_DETECTED:
4548 "Error at position %d in the CFDC, "
4549 "CFDC is discarded by the adapter %s\n",
4550 header->fsf_status_qual.word[0],
4551 zfcp_get_busid_by_adapter(adapter));
4552 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4556 case FSF_CONTROL_FILE_UPDATE_ERROR:
4558 "Adapter %s cannot harden the control file, "
4559 "file is discarded\n",
4560 zfcp_get_busid_by_adapter(adapter));
4561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4565 case FSF_CONTROL_FILE_TOO_LARGE:
4567 "Control file is too large, file is discarded "
4568 "by the adapter %s\n",
4569 zfcp_get_busid_by_adapter(adapter));
4570 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4574 case FSF_ACCESS_CONFLICT_DETECTED:
4575 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4577 "CFDC has been discarded by the adapter %s, "
4578 "because activation would impact "
4579 "%d active connection(s)\n",
4580 zfcp_get_busid_by_adapter(adapter),
4581 header->fsf_status_qual.word[0]);
4582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4586 case FSF_CONFLICTS_OVERRULED:
4587 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4589 "CFDC has been activated on the adapter %s, "
4590 "but activation has impacted "
4591 "%d active connection(s)\n",
4592 zfcp_get_busid_by_adapter(adapter),
4593 header->fsf_status_qual.word[0]);
4594 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4598 case FSF_UNKNOWN_OP_SUBTYPE:
4599 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4600 "op_subtype=0x%x)\n",
4601 zfcp_get_busid_by_adapter(adapter),
4602 bottom->operation_subtype);
4603 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4607 case FSF_INVALID_COMMAND_OPTION:
4609 "Invalid option 0x%x has been specified "
4610 "in QTCB bottom sent to the adapter %s\n",
4612 zfcp_get_busid_by_adapter(adapter));
4613 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4619 "bug: An unknown/unexpected FSF status 0x%08x "
4620 "was presented on the adapter %s\n",
4622 zfcp_get_busid_by_adapter(adapter));
4623 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4624 debug_exception(fsf_req->adapter->erp_dbf, 0,
4625 &header->fsf_status_qual.word[0], sizeof(u32));
4626 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4636 zfcp_fsf_req_sbal_check(unsigned long *flags,
4637 struct zfcp_qdio_queue *queue, int needed)
4639 write_lock_irqsave(&queue->queue_lock, *flags);
4640 if (likely(atomic_read(&queue->free_count) >= needed))
4642 write_unlock_irqrestore(&queue->queue_lock, *flags);
4647 * set qtcb pointer in fsf_req and initialize QTCB
4650 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4652 if (likely(fsf_req->qtcb != NULL)) {
4653 fsf_req->qtcb->prefix.req_seq_no =
4654 fsf_req->adapter->fsf_req_seq_no;
4655 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4656 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4657 fsf_req->qtcb->prefix.qtcb_type =
4658 fsf_qtcb_type[fsf_req->fsf_command];
4659 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4660 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4661 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4666 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4667 * @adapter: adapter for which request queue is examined
4668 * @req_flags: flags indicating whether to wait for needed SBAL or not
4669 * @lock_flags: lock_flags if queue_lock is taken
4670 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4671 * Locks: lock adapter->request_queue->queue_lock on success
4674 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4675 unsigned long *lock_flags)
4678 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4680 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4681 ret = wait_event_interruptible_timeout(adapter->request_wq,
4682 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4688 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4695 * function: zfcp_fsf_req_create
4697 * purpose: create an FSF request at the specified adapter and
4698 * setup common fields
4700 * returns: -ENOMEM if there was insufficient memory for a request
4701 * -EIO if no qdio buffers could be allocate to the request
4702 * -EINVAL/-EPERM on bug conditions in req_dequeue
4705 * note: The created request is returned by reference.
4707 * locks: lock of concerned request queue must not be held,
4708 * but is held on completion (write, irqsave)
4711 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4712 mempool_t *pool, unsigned long *lock_flags,
4713 struct zfcp_fsf_req **fsf_req_p)
4715 volatile struct qdio_buffer_element *sbale;
4716 struct zfcp_fsf_req *fsf_req = NULL;
4718 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4720 /* allocate new FSF request */
4721 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4722 if (unlikely(NULL == fsf_req)) {
4723 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
4724 "the outbound (send) queue.\n");
4726 goto failed_fsf_req;
4729 fsf_req->adapter = adapter;
4730 fsf_req->fsf_command = fsf_cmd;
4731 INIT_LIST_HEAD(&fsf_req->list);
4732 init_timer(&fsf_req->timer);
4734 /* initialize waitqueue which may be used to wait on
4735 this request completion */
4736 init_waitqueue_head(&fsf_req->completion_wq);
4738 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4742 /* this is serialized (we are holding req_queue-lock of adapter) */
4743 if (adapter->req_no == 0)
4745 fsf_req->req_id = adapter->req_no++;
4747 zfcp_fsf_req_qtcb_init(fsf_req);
4750 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4751 * if it is not set (see also *_open_qdio and *_close_qdio).
4754 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4755 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4760 if (fsf_req->qtcb) {
4761 fsf_req->seq_no = adapter->fsf_req_seq_no;
4762 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4764 fsf_req->sbal_number = 1;
4765 fsf_req->sbal_first = req_queue->free_index;
4766 fsf_req->sbal_curr = req_queue->free_index;
4767 fsf_req->sbale_curr = 1;
4769 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4770 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4773 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4775 /* setup common SBALE fields */
4776 sbale[0].addr = (void *) fsf_req->req_id;
4777 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4778 if (likely(fsf_req->qtcb != NULL)) {
4779 sbale[1].addr = (void *) fsf_req->qtcb;
4780 sbale[1].length = sizeof(struct fsf_qtcb);
4783 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4784 fsf_req->sbal_number, fsf_req->sbal_first);
4789 /* dequeue new FSF request previously enqueued */
4790 zfcp_fsf_req_free(fsf_req);
4794 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4796 *fsf_req_p = fsf_req;
4801 * function: zfcp_fsf_req_send
4803 * purpose: start transfer of FSF request via QDIO
4805 * returns: 0 - request transfer succesfully started
4806 * !0 - start of request transfer failed
4808 static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
4810 struct zfcp_adapter *adapter;
4811 struct zfcp_qdio_queue *req_queue;
4812 volatile struct qdio_buffer_element *sbale;
4814 int new_distance_from_int;
4818 adapter = fsf_req->adapter;
4819 req_queue = &adapter->request_queue,
4822 /* FIXME(debug): remove it later */
4823 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4824 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4825 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4829 /* put allocated FSF request into hash table */
4830 spin_lock(&adapter->req_list_lock);
4831 zfcp_reqlist_add(adapter, fsf_req);
4832 spin_unlock(&adapter->req_list_lock);
4834 inc_seq_no = (fsf_req->qtcb != NULL);
4836 ZFCP_LOG_TRACE("request queue of adapter %s: "
4837 "next free SBAL is %i, %i free SBALs\n",
4838 zfcp_get_busid_by_adapter(adapter),
4839 req_queue->free_index,
4840 atomic_read(&req_queue->free_count));
4842 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4843 "index_in_queue=%i, count=%i, buffers=%p\n",
4844 zfcp_get_busid_by_adapter(adapter),
4845 QDIO_FLAG_SYNC_OUTPUT,
4846 0, fsf_req->sbal_first, fsf_req->sbal_number,
4847 &req_queue->buffer[fsf_req->sbal_first]);
4850 * adjust the number of free SBALs in request queue as well as
4851 * position of first one
4853 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4854 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4855 req_queue->free_index += fsf_req->sbal_number; /* increase */
4856 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4857 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4859 fsf_req->issued = get_clock();
4861 retval = do_QDIO(adapter->ccw_device,
4862 QDIO_FLAG_SYNC_OUTPUT,
4863 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4865 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4866 dbg_tmp[1] = (u64) retval;
4867 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4869 if (unlikely(retval)) {
4870 /* Queues are down..... */
4872 del_timer(&fsf_req->timer);
4873 spin_lock(&adapter->req_list_lock);
4874 zfcp_reqlist_remove(adapter, fsf_req);
4875 spin_unlock(&adapter->req_list_lock);
4876 /* undo changes in request queue made for this request */
4877 zfcp_qdio_zero_sbals(req_queue->buffer,
4878 fsf_req->sbal_first, fsf_req->sbal_number);
4879 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4880 req_queue->free_index -= fsf_req->sbal_number;
4881 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4882 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4883 zfcp_erp_adapter_reopen(adapter, 0, 116, (u64)fsf_req);
4885 req_queue->distance_from_int = new_distance_from_int;
4887 * increase FSF sequence counter -
4888 * this must only be done for request successfully enqueued to
4889 * QDIO this rejected requests may be cleaned up by calling
4890 * routines resulting in missing sequence counter values
4894 /* Don't increase for unsolicited status */
4896 adapter->fsf_req_seq_no++;
4898 /* count FSF requests pending */
4899 atomic_inc(&adapter->reqs_active);
4904 #undef ZFCP_LOG_AREA