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, 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, 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, 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, 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, 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, NULL,
359 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, 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, 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, fsf_req);
427 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
430 case FSF_FCP_RSP_AVAILABLE:
431 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
435 case FSF_ADAPTER_STATUS_AVAILABLE:
436 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
442 * always call specific handlers to give them a chance to do
443 * something meaningful even in error cases
445 zfcp_fsf_req_dispatch(fsf_req);
451 * function: zfcp_fsf_fsfstatus_qual_eval
453 * purpose: evaluates FSF status-qualifier of completed FSF request
454 * and acts accordingly
459 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
463 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
464 case FSF_SQ_FCP_RSP_AVAILABLE:
466 case FSF_SQ_RETRY_IF_POSSIBLE:
467 /* The SCSI-stack may now issue retries or escalate */
468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
470 case FSF_SQ_COMMAND_ABORTED:
471 /* Carry the aborted state on to upper layer */
472 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
475 case FSF_SQ_NO_RECOM:
476 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
477 "problem on the adapter %s "
478 "Stopping all operations on this adapter. ",
479 zfcp_get_busid_by_adapter(fsf_req->adapter));
480 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
483 case FSF_SQ_ULP_PROGRAMMING_ERROR:
484 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
486 zfcp_get_busid_by_adapter(fsf_req->adapter));
487 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
489 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
490 case FSF_SQ_NO_RETRY_POSSIBLE:
491 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
492 /* dealt with in the respective functions */
495 ZFCP_LOG_NORMAL("bug: Additional status info could "
496 "not be interpreted properly.\n");
497 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
498 (char *) &fsf_req->qtcb->header.fsf_status_qual,
499 sizeof (union fsf_status_qual));
500 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
508 * zfcp_fsf_link_down_info_eval - evaluate link down information block
511 zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
512 struct fsf_link_down_info *link_down)
514 struct zfcp_adapter *adapter = fsf_req->adapter;
516 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
520 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
522 if (link_down == NULL)
525 switch (link_down->error_code) {
526 case FSF_PSQ_LINK_NO_LIGHT:
527 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
528 "(no light detected)\n",
529 zfcp_get_busid_by_adapter(adapter));
531 case FSF_PSQ_LINK_WRAP_PLUG:
532 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
533 "(wrap plug detected)\n",
534 zfcp_get_busid_by_adapter(adapter));
536 case FSF_PSQ_LINK_NO_FCP:
537 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
538 "(adjacent node on link does not support FCP)\n",
539 zfcp_get_busid_by_adapter(adapter));
541 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
542 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
543 "(firmware update in progress)\n",
544 zfcp_get_busid_by_adapter(adapter));
546 case FSF_PSQ_LINK_INVALID_WWPN:
547 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
548 "(duplicate or invalid WWPN detected)\n",
549 zfcp_get_busid_by_adapter(adapter));
551 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
552 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
553 "(no support for NPIV by Fabric)\n",
554 zfcp_get_busid_by_adapter(adapter));
556 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
557 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
558 "(out of resource in FCP daughtercard)\n",
559 zfcp_get_busid_by_adapter(adapter));
561 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
562 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
563 "(out of resource in Fabric)\n",
564 zfcp_get_busid_by_adapter(adapter));
566 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
567 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
568 "(unable to Fabric login)\n",
569 zfcp_get_busid_by_adapter(adapter));
571 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
572 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
573 zfcp_get_busid_by_adapter(adapter));
575 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
576 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
577 zfcp_get_busid_by_adapter(adapter));
579 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
580 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
581 zfcp_get_busid_by_adapter(adapter));
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(warning: unknown reason code %d)\n",
586 zfcp_get_busid_by_adapter(adapter),
587 link_down->error_code);
590 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
591 ZFCP_LOG_DEBUG("Debug information to link down: "
592 "primary_status=0x%02x "
594 "action_code=0x%02x "
595 "reason_code=0x%02x "
596 "explanation_code=0x%02x "
597 "vendor_specific_code=0x%02x\n",
598 link_down->primary_status,
599 link_down->ioerr_code,
600 link_down->action_code,
601 link_down->reason_code,
602 link_down->explanation_code,
603 link_down->vendor_specific_code);
606 zfcp_erp_adapter_failed(adapter, id, fsf_req);
610 * function: zfcp_fsf_req_dispatch
612 * purpose: calls the appropriate command specific handler
617 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
619 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
620 struct zfcp_adapter *adapter = fsf_req->adapter;
624 switch (fsf_req->fsf_command) {
626 case FSF_QTCB_FCP_CMND:
627 zfcp_fsf_send_fcp_command_handler(fsf_req);
630 case FSF_QTCB_ABORT_FCP_CMND:
631 zfcp_fsf_abort_fcp_command_handler(fsf_req);
634 case FSF_QTCB_SEND_GENERIC:
635 zfcp_fsf_send_ct_handler(fsf_req);
638 case FSF_QTCB_OPEN_PORT_WITH_DID:
639 zfcp_fsf_open_port_handler(fsf_req);
642 case FSF_QTCB_OPEN_LUN:
643 zfcp_fsf_open_unit_handler(fsf_req);
646 case FSF_QTCB_CLOSE_LUN:
647 zfcp_fsf_close_unit_handler(fsf_req);
650 case FSF_QTCB_CLOSE_PORT:
651 zfcp_fsf_close_port_handler(fsf_req);
654 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
655 zfcp_fsf_close_physical_port_handler(fsf_req);
658 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
659 zfcp_fsf_exchange_config_data_handler(fsf_req);
662 case FSF_QTCB_EXCHANGE_PORT_DATA:
663 zfcp_fsf_exchange_port_data_handler(fsf_req);
666 case FSF_QTCB_SEND_ELS:
667 zfcp_fsf_send_els_handler(fsf_req);
670 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
671 zfcp_fsf_control_file_handler(fsf_req);
674 case FSF_QTCB_UPLOAD_CONTROL_FILE:
675 zfcp_fsf_control_file_handler(fsf_req);
679 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
680 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
681 "not supported by the adapter %s\n",
682 zfcp_get_busid_by_adapter(adapter));
683 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
685 ("bug: Command issued by the device driver differs "
686 "from the command returned by the adapter %s "
687 "(debug info 0x%x, 0x%x).\n",
688 zfcp_get_busid_by_adapter(adapter),
689 fsf_req->fsf_command,
690 fsf_req->qtcb->header.fsf_command);
696 zfcp_erp_async_handler(erp_action, 0);
702 * function: zfcp_fsf_status_read
704 * purpose: initiates a Status Read command at the specified adapter
709 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
711 struct zfcp_fsf_req *fsf_req;
712 struct fsf_status_read_buffer *status_buffer;
713 unsigned long lock_flags;
714 volatile struct qdio_buffer_element *sbale;
717 /* setup new FSF request */
718 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
719 req_flags | ZFCP_REQ_NO_QTCB,
720 adapter->pool.fsf_req_status_read,
721 &lock_flags, &fsf_req);
723 ZFCP_LOG_INFO("error: Could not create unsolicited status "
724 "buffer for adapter %s.\n",
725 zfcp_get_busid_by_adapter(adapter));
726 goto failed_req_create;
729 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
730 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
731 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
732 fsf_req->sbale_curr = 2;
735 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
736 if (!status_buffer) {
737 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
740 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
741 fsf_req->data = (unsigned long) status_buffer;
743 /* insert pointer to respective buffer */
744 sbale = zfcp_qdio_sbale_curr(fsf_req);
745 sbale->addr = (void *) status_buffer;
746 sbale->length = sizeof(struct fsf_status_read_buffer);
748 retval = zfcp_fsf_req_send(fsf_req);
750 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
752 goto failed_req_send;
755 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
756 zfcp_get_busid_by_adapter(adapter));
760 mempool_free(status_buffer, adapter->pool.data_status_read);
763 zfcp_fsf_req_free(fsf_req);
765 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
767 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
772 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
774 struct fsf_status_read_buffer *status_buffer;
775 struct zfcp_adapter *adapter;
776 struct zfcp_port *port;
779 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
780 adapter = fsf_req->adapter;
782 read_lock_irqsave(&zfcp_data.config_lock, flags);
783 list_for_each_entry(port, &adapter->port_list_head, list)
784 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
786 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
788 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
789 ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
790 "nonexisting port with d_id 0x%06x on "
791 "adapter %s. Ignored.\n",
792 status_buffer->d_id & ZFCP_DID_MASK,
793 zfcp_get_busid_by_adapter(adapter));
797 switch (status_buffer->status_subtype) {
799 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
800 zfcp_erp_port_reopen(port, 0, 101, fsf_req);
803 case FSF_STATUS_READ_SUB_ERROR_PORT:
804 zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
808 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
809 "for a reopen indication on port with "
810 "d_id 0x%06x on the adapter %s. "
811 "Ignored. (debug info 0x%x)\n",
813 zfcp_get_busid_by_adapter(adapter),
814 status_buffer->status_subtype);
821 * function: zfcp_fsf_status_read_handler
823 * purpose: is called for finished Open Port command
828 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
831 struct zfcp_adapter *adapter = fsf_req->adapter;
832 struct fsf_status_read_buffer *status_buffer =
833 (struct fsf_status_read_buffer *) fsf_req->data;
834 struct fsf_bit_error_payload *fsf_bit_error;
836 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
837 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
838 mempool_free(status_buffer, adapter->pool.data_status_read);
839 zfcp_fsf_req_free(fsf_req);
843 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
845 switch (status_buffer->status_type) {
847 case FSF_STATUS_READ_PORT_CLOSED:
848 zfcp_fsf_status_read_port_closed(fsf_req);
851 case FSF_STATUS_READ_INCOMING_ELS:
852 zfcp_fsf_incoming_els(fsf_req);
855 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
856 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
857 zfcp_get_busid_by_adapter(adapter));
860 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
861 fsf_bit_error = (struct fsf_bit_error_payload *)
862 status_buffer->payload;
863 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
864 "received (adapter %s, "
865 "link failures = %i, loss of sync errors = %i, "
866 "loss of signal errors = %i, "
867 "primitive sequence errors = %i, "
868 "invalid transmission word errors = %i, "
869 "CRC errors = %i)\n",
870 zfcp_get_busid_by_adapter(adapter),
871 fsf_bit_error->link_failure_error_count,
872 fsf_bit_error->loss_of_sync_error_count,
873 fsf_bit_error->loss_of_signal_error_count,
874 fsf_bit_error->primitive_sequence_error_count,
875 fsf_bit_error->invalid_transmission_word_error_count,
876 fsf_bit_error->crc_error_count);
877 ZFCP_LOG_INFO("Additional bit error threshold data "
879 "primitive sequence event time-outs = %i, "
880 "elastic buffer overrun errors = %i, "
881 "advertised receive buffer-to-buffer credit = %i, "
882 "current receice buffer-to-buffer credit = %i, "
883 "advertised transmit buffer-to-buffer credit = %i, "
884 "current transmit buffer-to-buffer credit = %i)\n",
885 zfcp_get_busid_by_adapter(adapter),
886 fsf_bit_error->primitive_sequence_event_timeout_count,
887 fsf_bit_error->elastic_buffer_overrun_error_count,
888 fsf_bit_error->advertised_receive_b2b_credit,
889 fsf_bit_error->current_receive_b2b_credit,
890 fsf_bit_error->advertised_transmit_b2b_credit,
891 fsf_bit_error->current_transmit_b2b_credit);
894 case FSF_STATUS_READ_LINK_DOWN:
895 switch (status_buffer->status_subtype) {
896 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
897 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
898 zfcp_get_busid_by_adapter(adapter));
899 zfcp_fsf_link_down_info_eval(fsf_req, 38,
900 (struct fsf_link_down_info *)
901 &status_buffer->payload);
903 case FSF_STATUS_READ_SUB_FDISC_FAILED:
904 ZFCP_LOG_INFO("Local link to adapter %s is down "
905 "due to failed FDISC login\n",
906 zfcp_get_busid_by_adapter(adapter));
907 zfcp_fsf_link_down_info_eval(fsf_req, 39,
908 (struct fsf_link_down_info *)
909 &status_buffer->payload);
911 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
912 ZFCP_LOG_INFO("Local link to adapter %s is down "
913 "due to firmware update on adapter\n",
914 zfcp_get_busid_by_adapter(adapter));
915 zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
918 ZFCP_LOG_INFO("Local link to adapter %s is down "
919 "due to unknown reason\n",
920 zfcp_get_busid_by_adapter(adapter));
921 zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
925 case FSF_STATUS_READ_LINK_UP:
926 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
927 "Restarting operations on this adapter\n",
928 zfcp_get_busid_by_adapter(adapter));
929 /* All ports should be marked as ready to run again */
930 zfcp_erp_modify_adapter_status(adapter, 30, NULL,
931 ZFCP_STATUS_COMMON_RUNNING,
933 zfcp_erp_adapter_reopen(adapter,
934 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
935 | ZFCP_STATUS_COMMON_ERP_FAILED,
939 case FSF_STATUS_READ_NOTIFICATION_LOST:
940 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
941 "adapter %s%s%s%s%s%s%s%s%s\n",
942 zfcp_get_busid_by_adapter(adapter),
943 (status_buffer->status_subtype &
944 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
945 ", incoming ELS" : "",
946 (status_buffer->status_subtype &
947 FSF_STATUS_READ_SUB_SENSE_DATA) ?
949 (status_buffer->status_subtype &
950 FSF_STATUS_READ_SUB_LINK_STATUS) ?
951 ", link status change" : "",
952 (status_buffer->status_subtype &
953 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
955 (status_buffer->status_subtype &
956 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
957 ", bit error exception" : "",
958 (status_buffer->status_subtype &
959 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
961 (status_buffer->status_subtype &
962 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
963 ", ACT hardening" : "",
964 (status_buffer->status_subtype &
965 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
966 ", adapter feature change" : "");
968 if (status_buffer->status_subtype &
969 FSF_STATUS_READ_SUB_ACT_UPDATED)
970 zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
973 case FSF_STATUS_READ_CFDC_UPDATED:
974 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
975 zfcp_get_busid_by_adapter(adapter));
976 zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
979 case FSF_STATUS_READ_CFDC_HARDENED:
980 switch (status_buffer->status_subtype) {
981 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
982 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
983 zfcp_get_busid_by_adapter(adapter));
985 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
986 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
987 "to the secondary SE\n",
988 zfcp_get_busid_by_adapter(adapter));
991 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
992 zfcp_get_busid_by_adapter(adapter));
996 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
997 ZFCP_LOG_INFO("List of supported features on adapter %s has "
998 "been changed from 0x%08X to 0x%08X\n",
999 zfcp_get_busid_by_adapter(adapter),
1000 *(u32*) (status_buffer->payload + 4),
1001 *(u32*) (status_buffer->payload));
1002 adapter->adapter_features = *(u32*) status_buffer->payload;
1006 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1007 "type was received (debug info 0x%x)\n",
1008 status_buffer->status_type);
1009 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1012 (char *) status_buffer,
1013 sizeof (struct fsf_status_read_buffer));
1016 mempool_free(status_buffer, adapter->pool.data_status_read);
1017 zfcp_fsf_req_free(fsf_req);
1019 * recycle buffer and start new request repeat until outbound
1020 * queue is empty or adapter shutdown is requested
1024 * we may wait in the req_create for 5s during shutdown, so
1025 * qdio_cleanup will have to wait at least that long before returning
1026 * with failure to allow us a proper cleanup under all circumstances
1030 * allocation failure possible? (Is this code needed?)
1032 retval = zfcp_fsf_status_read(adapter, 0);
1034 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1035 "request for the adapter %s.\n",
1036 zfcp_get_busid_by_adapter(adapter));
1037 /* temporary fix to avoid status read buffer shortage */
1038 adapter->status_read_failed++;
1039 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1040 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1041 ZFCP_LOG_INFO("restart adapter %s due to status read "
1042 "buffer shortage\n",
1043 zfcp_get_busid_by_adapter(adapter));
1044 zfcp_erp_adapter_reopen(adapter, 0, 103, fsf_req);
1052 * function: zfcp_fsf_abort_fcp_command
1054 * purpose: tells FSF to abort a running SCSI command
1056 * returns: address of initiated FSF request
1057 * NULL - request could not be initiated
1059 * FIXME(design): should be watched by a timeout !!!
1060 * FIXME(design) shouldn't this be modified to return an int
1061 * also...don't know how though
1063 struct zfcp_fsf_req *
1064 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1065 struct zfcp_adapter *adapter,
1066 struct zfcp_unit *unit, int req_flags)
1068 volatile struct qdio_buffer_element *sbale;
1069 struct zfcp_fsf_req *fsf_req = NULL;
1070 unsigned long lock_flags;
1073 /* setup new FSF request */
1074 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1075 req_flags, adapter->pool.fsf_req_abort,
1076 &lock_flags, &fsf_req);
1078 ZFCP_LOG_INFO("error: Failed to create an abort command "
1079 "request for lun 0x%016Lx on port 0x%016Lx "
1083 zfcp_get_busid_by_adapter(adapter));
1087 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1091 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1092 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1093 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1095 fsf_req->data = (unsigned long) unit;
1097 /* set handles of unit and its parent port in QTCB */
1098 fsf_req->qtcb->header.lun_handle = unit->handle;
1099 fsf_req->qtcb->header.port_handle = unit->port->handle;
1101 /* set handle of request which should be aborted */
1102 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1104 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1105 retval = zfcp_fsf_req_send(fsf_req);
1110 zfcp_fsf_req_free(fsf_req);
1114 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1119 * function: zfcp_fsf_abort_fcp_command_handler
1121 * purpose: is called for finished Abort FCP Command request
1126 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1128 int retval = -EINVAL;
1129 struct zfcp_unit *unit;
1130 union fsf_status_qual *fsf_stat_qual =
1131 &new_fsf_req->qtcb->header.fsf_status_qual;
1133 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1134 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1135 goto skip_fsfstatus;
1138 unit = (struct zfcp_unit *) new_fsf_req->data;
1140 /* evaluate FSF status in QTCB */
1141 switch (new_fsf_req->qtcb->header.fsf_status) {
1143 case FSF_PORT_HANDLE_NOT_VALID:
1144 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1146 * In this case a command that was sent prior to a port
1147 * reopen was aborted (handles are different). This is
1151 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1152 "port 0x%016Lx on adapter %s invalid. "
1153 "This may happen occasionally.\n",
1156 zfcp_get_busid_by_unit(unit));
1157 ZFCP_LOG_INFO("status qualifier:\n");
1158 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1159 (char *) &new_fsf_req->qtcb->header.
1161 sizeof (union fsf_status_qual));
1162 /* Let's hope this sorts out the mess */
1163 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
1165 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1169 case FSF_LUN_HANDLE_NOT_VALID:
1170 if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
1172 * In this case a command that was sent prior to a unit
1173 * reopen was aborted (handles are different).
1178 ("Warning: Temporary LUN identifier 0x%x of LUN "
1179 "0x%016Lx on port 0x%016Lx on adapter %s is "
1180 "invalid. This may happen in rare cases. "
1181 "Trying to re-establish link.\n",
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1188 (char *) &new_fsf_req->qtcb->header.
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
1192 zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
1193 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1197 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1199 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1202 case FSF_PORT_BOXED:
1203 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1204 "be reopened\n", unit->port->wwpn,
1205 zfcp_get_busid_by_unit(unit));
1206 zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
1207 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1208 | ZFCP_STATUS_FSFREQ_RETRY;
1213 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1215 unit->fcp_lun, unit->port->wwpn,
1216 zfcp_get_busid_by_unit(unit));
1217 zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
1218 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1219 | ZFCP_STATUS_FSFREQ_RETRY;
1222 case FSF_ADAPTER_STATUS_AVAILABLE:
1223 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1224 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1225 zfcp_test_link(unit->port);
1226 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1228 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1229 /* SCSI stack will escalate */
1230 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1234 ("bug: Wrong status qualifier 0x%x arrived.\n",
1235 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1242 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1246 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1247 "(debug info 0x%x)\n",
1248 new_fsf_req->qtcb->header.fsf_status);
1256 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1258 * Two scatter-gather lists are passed, one for the reqeust and one for the
1262 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1263 struct scatterlist *resp, int resp_count)
1265 return ((req_count == 1) &&
1266 (resp_count == 1) &&
1267 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1269 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1270 req[0].length - 1) & PAGE_MASK)) &&
1271 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1273 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1274 resp[0].length - 1) & PAGE_MASK)));
1278 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1279 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1281 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1282 * a struct zfcp_fsf_req
1283 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1284 * is sent within error recovery
1287 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1288 struct zfcp_erp_action *erp_action)
1290 volatile struct qdio_buffer_element *sbale;
1291 struct zfcp_port *port;
1292 struct zfcp_adapter *adapter;
1293 struct zfcp_fsf_req *fsf_req;
1294 unsigned long lock_flags;
1299 adapter = port->adapter;
1301 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1302 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1303 pool, &lock_flags, &fsf_req);
1305 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1307 zfcp_get_busid_by_adapter(adapter));
1311 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1312 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1313 ct->resp, ct->resp_count)){
1314 /* both request buffer and response buffer
1315 fit into one sbale each */
1316 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1317 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1318 sbale[2].length = ct->req[0].length;
1319 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1320 sbale[3].length = ct->resp[0].length;
1321 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1322 } else if (adapter->adapter_features &
1323 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1324 /* try to use chained SBALs */
1325 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1326 SBAL_FLAGS0_TYPE_WRITE_READ,
1327 ct->req, ct->req_count,
1328 ZFCP_MAX_SBALS_PER_CT_REQ);
1330 ZFCP_LOG_INFO("error: creation of CT request failed "
1332 zfcp_get_busid_by_adapter(adapter));
1340 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1341 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1342 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1343 SBAL_FLAGS0_TYPE_WRITE_READ,
1344 ct->resp, ct->resp_count,
1345 ZFCP_MAX_SBALS_PER_CT_REQ);
1347 ZFCP_LOG_INFO("error: creation of CT request failed "
1349 zfcp_get_busid_by_adapter(adapter));
1357 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1359 /* reject send generic request */
1361 "error: microcode does not support chained SBALs,"
1362 "CT request too big (adapter %s)\n",
1363 zfcp_get_busid_by_adapter(adapter));
1368 /* settings in QTCB */
1369 fsf_req->qtcb->header.port_handle = port->handle;
1370 fsf_req->qtcb->bottom.support.service_class =
1371 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1372 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1373 fsf_req->data = (unsigned long) ct;
1375 zfcp_san_dbf_event_ct_request(fsf_req);
1378 erp_action->fsf_req = fsf_req;
1379 fsf_req->erp_action = erp_action;
1380 zfcp_erp_start_timer(fsf_req);
1382 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1384 ret = zfcp_fsf_req_send(fsf_req);
1386 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1387 "(adapter %s, port 0x%016Lx)\n",
1388 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1392 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1393 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1397 zfcp_fsf_req_free(fsf_req);
1398 if (erp_action != NULL) {
1399 erp_action->fsf_req = NULL;
1403 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1409 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1410 * @fsf_req: pointer to struct zfcp_fsf_req
1412 * Data specific for the Generic Service request is passed using
1413 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1414 * Usually a specific handler for the CT request is called which is
1415 * found in this structure.
1418 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1420 struct zfcp_port *port;
1421 struct zfcp_adapter *adapter;
1422 struct zfcp_send_ct *send_ct;
1423 struct fsf_qtcb_header *header;
1424 struct fsf_qtcb_bottom_support *bottom;
1425 int retval = -EINVAL;
1426 u16 subtable, rule, counter;
1428 adapter = fsf_req->adapter;
1429 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1430 port = send_ct->port;
1431 header = &fsf_req->qtcb->header;
1432 bottom = &fsf_req->qtcb->bottom.support;
1434 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1435 goto skip_fsfstatus;
1437 /* evaluate FSF status in QTCB */
1438 switch (header->fsf_status) {
1441 zfcp_san_dbf_event_ct_response(fsf_req);
1445 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1446 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1448 zfcp_get_busid_by_port(port),
1449 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1450 /* stop operation for this adapter */
1451 zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
1452 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1455 case FSF_ADAPTER_STATUS_AVAILABLE:
1456 switch (header->fsf_status_qual.word[0]){
1457 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1458 /* reopening link to port */
1459 zfcp_test_link(port);
1460 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1462 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1463 /* ERP strategy will escalate */
1464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1467 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1469 header->fsf_status_qual.word[0]);
1474 case FSF_ACCESS_DENIED:
1475 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1476 "command (adapter %s, port d_id=0x%06x)\n",
1477 zfcp_get_busid_by_port(port), port->d_id);
1478 for (counter = 0; counter < 2; counter++) {
1479 subtable = header->fsf_status_qual.halfword[counter * 2];
1480 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1482 case FSF_SQ_CFDC_SUBTABLE_OS:
1483 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1484 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1485 case FSF_SQ_CFDC_SUBTABLE_LUN:
1486 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1487 zfcp_act_subtable_type[subtable], rule);
1491 zfcp_erp_port_access_denied(port, 55, fsf_req);
1492 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1495 case FSF_GENERIC_COMMAND_REJECTED:
1496 ZFCP_LOG_INFO("generic service command rejected "
1497 "(adapter %s, port d_id=0x%06x)\n",
1498 zfcp_get_busid_by_port(port), port->d_id);
1499 ZFCP_LOG_INFO("status qualifier:\n");
1500 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1501 (char *) &header->fsf_status_qual,
1502 sizeof (union fsf_status_qual));
1503 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1506 case FSF_PORT_HANDLE_NOT_VALID:
1507 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1508 "0x%016Lx on adapter %s invalid. This may "
1509 "happen occasionally.\n", port->handle,
1510 port->wwpn, zfcp_get_busid_by_port(port));
1511 ZFCP_LOG_INFO("status qualifier:\n");
1512 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1513 (char *) &header->fsf_status_qual,
1514 sizeof (union fsf_status_qual));
1515 zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
1516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1519 case FSF_PORT_BOXED:
1520 ZFCP_LOG_INFO("port needs to be reopened "
1521 "(adapter %s, port d_id=0x%06x)\n",
1522 zfcp_get_busid_by_port(port), port->d_id);
1523 zfcp_erp_port_boxed(port, 49, fsf_req);
1524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1525 | ZFCP_STATUS_FSFREQ_RETRY;
1528 /* following states should never occure, all cases avoided
1529 in zfcp_fsf_send_ct - but who knows ... */
1530 case FSF_PAYLOAD_SIZE_MISMATCH:
1531 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1532 "req_buf_length=%d, resp_buf_length=%d)\n",
1533 zfcp_get_busid_by_adapter(adapter),
1534 bottom->req_buf_length, bottom->resp_buf_length);
1535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1537 case FSF_REQUEST_SIZE_TOO_LARGE:
1538 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1539 "req_buf_length=%d)\n",
1540 zfcp_get_busid_by_adapter(adapter),
1541 bottom->req_buf_length);
1542 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1544 case FSF_RESPONSE_SIZE_TOO_LARGE:
1545 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1546 "resp_buf_length=%d)\n",
1547 zfcp_get_busid_by_adapter(adapter),
1548 bottom->resp_buf_length);
1549 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1551 case FSF_SBAL_MISMATCH:
1552 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1553 "resp_buf_length=%d)\n",
1554 zfcp_get_busid_by_adapter(adapter),
1555 bottom->req_buf_length, bottom->resp_buf_length);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1560 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1561 "(debug info 0x%x)\n", header->fsf_status);
1566 send_ct->status = retval;
1568 if (send_ct->handler != NULL)
1569 send_ct->handler(send_ct->handler_data);
1575 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1576 * @els: pointer to struct zfcp_send_els which contains all needed data for
1580 zfcp_fsf_send_els(struct zfcp_send_els *els)
1582 volatile struct qdio_buffer_element *sbale;
1583 struct zfcp_fsf_req *fsf_req;
1585 struct zfcp_adapter *adapter;
1586 unsigned long lock_flags;
1591 adapter = els->adapter;
1593 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1594 ZFCP_REQ_AUTO_CLEANUP,
1595 NULL, &lock_flags, &fsf_req);
1597 ZFCP_LOG_INFO("error: creation of ELS request failed "
1598 "(adapter %s, port d_id: 0x%06x)\n",
1599 zfcp_get_busid_by_adapter(adapter), d_id);
1603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
1604 &els->port->status))) {
1609 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1610 if (zfcp_use_one_sbal(els->req, els->req_count,
1611 els->resp, els->resp_count)){
1612 /* both request buffer and response buffer
1613 fit into one sbale each */
1614 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1615 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1616 sbale[2].length = els->req[0].length;
1617 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1618 sbale[3].length = els->resp[0].length;
1619 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1620 } else if (adapter->adapter_features &
1621 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1622 /* try to use chained SBALs */
1623 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1624 SBAL_FLAGS0_TYPE_WRITE_READ,
1625 els->req, els->req_count,
1626 ZFCP_MAX_SBALS_PER_ELS_REQ);
1628 ZFCP_LOG_INFO("error: creation of ELS request failed "
1629 "(adapter %s, port d_id: 0x%06x)\n",
1630 zfcp_get_busid_by_adapter(adapter), d_id);
1638 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1639 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1640 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1641 SBAL_FLAGS0_TYPE_WRITE_READ,
1642 els->resp, els->resp_count,
1643 ZFCP_MAX_SBALS_PER_ELS_REQ);
1645 ZFCP_LOG_INFO("error: creation of ELS request failed "
1646 "(adapter %s, port d_id: 0x%06x)\n",
1647 zfcp_get_busid_by_adapter(adapter), d_id);
1655 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1657 /* reject request */
1658 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1659 ", ELS request too big (adapter %s, "
1660 "port d_id: 0x%06x)\n",
1661 zfcp_get_busid_by_adapter(adapter), d_id);
1666 /* settings in QTCB */
1667 fsf_req->qtcb->bottom.support.d_id = d_id;
1668 fsf_req->qtcb->bottom.support.service_class =
1669 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1670 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1671 fsf_req->data = (unsigned long) els;
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1675 zfcp_san_dbf_event_els_request(fsf_req);
1677 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1678 ret = zfcp_fsf_req_send(fsf_req);
1680 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1681 "(adapter %s, port d_id: 0x%06x)\n",
1682 zfcp_get_busid_by_adapter(adapter), d_id);
1686 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1687 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1692 zfcp_fsf_req_free(fsf_req);
1696 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1703 * zfcp_fsf_send_els_handler - handler for ELS commands
1704 * @fsf_req: pointer to struct zfcp_fsf_req
1706 * Data specific for the ELS command is passed using
1707 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1708 * Usually a specific handler for the ELS command is called which is
1709 * found in this structure.
1711 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1713 struct zfcp_adapter *adapter;
1714 struct zfcp_port *port;
1716 struct fsf_qtcb_header *header;
1717 struct fsf_qtcb_bottom_support *bottom;
1718 struct zfcp_send_els *send_els;
1719 int retval = -EINVAL;
1720 u16 subtable, rule, counter;
1722 send_els = (struct zfcp_send_els *) fsf_req->data;
1723 adapter = send_els->adapter;
1724 port = send_els->port;
1725 d_id = send_els->d_id;
1726 header = &fsf_req->qtcb->header;
1727 bottom = &fsf_req->qtcb->bottom.support;
1729 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1730 goto skip_fsfstatus;
1732 switch (header->fsf_status) {
1735 zfcp_san_dbf_event_els_response(fsf_req);
1739 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1740 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1742 zfcp_get_busid_by_adapter(adapter),
1743 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1744 /* stop operation for this adapter */
1745 zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
1746 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1749 case FSF_ADAPTER_STATUS_AVAILABLE:
1750 switch (header->fsf_status_qual.word[0]){
1751 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1752 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1753 zfcp_test_link(port);
1754 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1756 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1757 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1759 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1760 (struct zfcp_ls_rjt_par *)
1761 &header->fsf_status_qual.word[2]);
1763 case FSF_SQ_RETRY_IF_POSSIBLE:
1764 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1767 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1768 header->fsf_status_qual.word[0]);
1769 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1770 (char*)header->fsf_status_qual.word, 16);
1774 case FSF_ELS_COMMAND_REJECTED:
1775 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1776 "prohibited sending "
1777 "(adapter: %s, port d_id: 0x%06x)\n",
1778 zfcp_get_busid_by_adapter(adapter), d_id);
1782 case FSF_PAYLOAD_SIZE_MISMATCH:
1784 "ELS request size and ELS response size must be either "
1785 "both 0, or both greater than 0 "
1786 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1787 zfcp_get_busid_by_adapter(adapter),
1788 bottom->req_buf_length,
1789 bottom->resp_buf_length);
1792 case FSF_REQUEST_SIZE_TOO_LARGE:
1794 "Length of the ELS request buffer, "
1795 "specified in QTCB bottom, "
1796 "exceeds the size of the buffers "
1797 "that have been allocated for ELS request data "
1798 "(adapter: %s, req_buf_length=%d)\n",
1799 zfcp_get_busid_by_adapter(adapter),
1800 bottom->req_buf_length);
1803 case FSF_RESPONSE_SIZE_TOO_LARGE:
1805 "Length of the ELS response buffer, "
1806 "specified in QTCB bottom, "
1807 "exceeds the size of the buffers "
1808 "that have been allocated for ELS response data "
1809 "(adapter: %s, resp_buf_length=%d)\n",
1810 zfcp_get_busid_by_adapter(adapter),
1811 bottom->resp_buf_length);
1814 case FSF_SBAL_MISMATCH:
1815 /* should never occure, avoided in zfcp_fsf_send_els */
1816 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1817 "resp_buf_length=%d)\n",
1818 zfcp_get_busid_by_adapter(adapter),
1819 bottom->req_buf_length, bottom->resp_buf_length);
1820 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1823 case FSF_ACCESS_DENIED:
1824 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1825 "(adapter %s, port d_id=0x%06x)\n",
1826 zfcp_get_busid_by_adapter(adapter), d_id);
1827 for (counter = 0; counter < 2; counter++) {
1828 subtable = header->fsf_status_qual.halfword[counter * 2];
1829 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1831 case FSF_SQ_CFDC_SUBTABLE_OS:
1832 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1833 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1834 case FSF_SQ_CFDC_SUBTABLE_LUN:
1835 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1836 zfcp_act_subtable_type[subtable], rule);
1841 zfcp_erp_port_access_denied(port, 56, fsf_req);
1842 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1847 "bug: An unknown FSF Status was presented "
1848 "(adapter: %s, fsf_status=0x%08x)\n",
1849 zfcp_get_busid_by_adapter(adapter),
1850 header->fsf_status);
1851 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1856 send_els->status = retval;
1858 if (send_els->handler)
1859 send_els->handler(send_els->handler_data);
1865 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1867 volatile struct qdio_buffer_element *sbale;
1868 struct zfcp_fsf_req *fsf_req;
1869 struct zfcp_adapter *adapter = erp_action->adapter;
1870 unsigned long lock_flags;
1873 /* setup new FSF request */
1874 retval = zfcp_fsf_req_create(adapter,
1875 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1876 ZFCP_REQ_AUTO_CLEANUP,
1877 adapter->pool.fsf_req_erp,
1878 &lock_flags, &fsf_req);
1880 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1881 "data request for adapter %s.\n",
1882 zfcp_get_busid_by_adapter(adapter));
1883 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1888 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1889 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1890 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1892 fsf_req->qtcb->bottom.config.feature_selection =
1894 FSF_FEATURE_LUN_SHARING |
1895 FSF_FEATURE_NOTIFICATION_LOST |
1896 FSF_FEATURE_UPDATE_ALERT;
1897 fsf_req->erp_action = erp_action;
1898 erp_action->fsf_req = fsf_req;
1900 zfcp_erp_start_timer(fsf_req);
1901 retval = zfcp_fsf_req_send(fsf_req);
1902 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1905 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1906 "data command on the adapter %s\n",
1907 zfcp_get_busid_by_adapter(adapter));
1908 zfcp_fsf_req_free(fsf_req);
1909 erp_action->fsf_req = NULL;
1912 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1914 zfcp_get_busid_by_adapter(adapter));
1920 zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
1921 struct fsf_qtcb_bottom_config *data)
1923 volatile struct qdio_buffer_element *sbale;
1924 struct zfcp_fsf_req *fsf_req;
1925 unsigned long lock_flags;
1928 /* setup new FSF request */
1929 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
1930 ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
1933 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1934 "data request for adapter %s.\n",
1935 zfcp_get_busid_by_adapter(adapter));
1936 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1941 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1942 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1943 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1945 fsf_req->qtcb->bottom.config.feature_selection =
1947 FSF_FEATURE_LUN_SHARING |
1948 FSF_FEATURE_NOTIFICATION_LOST |
1949 FSF_FEATURE_UPDATE_ALERT;
1952 fsf_req->data = (unsigned long) data;
1954 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1955 retval = zfcp_fsf_req_send(fsf_req);
1956 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1959 ZFCP_LOG_INFO("error: Could not send exchange configuration "
1960 "data command on the adapter %s\n",
1961 zfcp_get_busid_by_adapter(adapter));
1963 wait_event(fsf_req->completion_wq,
1964 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
1966 zfcp_fsf_req_free(fsf_req);
1972 * zfcp_fsf_exchange_config_evaluate
1973 * @fsf_req: fsf_req which belongs to xchg config data request
1974 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1976 * returns: -EIO on error, 0 otherwise
1979 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
1981 struct fsf_qtcb_bottom_config *bottom;
1982 struct zfcp_adapter *adapter = fsf_req->adapter;
1983 struct Scsi_Host *shost = adapter->scsi_host;
1985 bottom = &fsf_req->qtcb->bottom.config;
1986 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
1987 bottom->low_qtcb_version, bottom->high_qtcb_version);
1988 adapter->fsf_lic_version = bottom->lic_version;
1989 adapter->adapter_features = bottom->adapter_features;
1990 adapter->connection_features = bottom->connection_features;
1991 adapter->peer_wwpn = 0;
1992 adapter->peer_wwnn = 0;
1993 adapter->peer_d_id = 0;
1998 memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
1999 bottom, sizeof (struct fsf_qtcb_bottom_config));
2001 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2002 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2003 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2004 fc_host_speed(shost) = bottom->fc_link_speed;
2005 fc_host_supported_classes(shost) =
2006 FC_COS_CLASS2 | FC_COS_CLASS3;
2007 adapter->hydra_version = bottom->adapter_type;
2008 if (fc_host_permanent_port_name(shost) == -1)
2009 fc_host_permanent_port_name(shost) =
2010 fc_host_port_name(shost);
2011 if (bottom->fc_topology == FSF_TOPO_P2P) {
2012 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2013 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2014 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2015 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2016 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2017 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2018 else if (bottom->fc_topology == FSF_TOPO_AL)
2019 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2021 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2023 fc_host_node_name(shost) = 0;
2024 fc_host_port_name(shost) = 0;
2025 fc_host_port_id(shost) = 0;
2026 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2027 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2028 adapter->hydra_version = 0;
2031 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2032 adapter->hardware_version = bottom->hardware_version;
2033 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2034 min(FC_SERIAL_NUMBER_SIZE, 17));
2035 EBCASC(fc_host_serial_number(shost),
2036 min(FC_SERIAL_NUMBER_SIZE, 17));
2039 if (fsf_req->erp_action)
2040 ZFCP_LOG_NORMAL("The adapter %s reported the following "
2041 "characteristics:\n"
2042 "WWNN 0x%016Lx, WWPN 0x%016Lx, "
2044 "adapter version 0x%x, "
2045 "LIC version 0x%x, "
2046 "FC link speed %d Gb/s\n",
2047 zfcp_get_busid_by_adapter(adapter),
2048 (wwn_t) fc_host_node_name(shost),
2049 (wwn_t) fc_host_port_name(shost),
2050 fc_host_port_id(shost),
2051 adapter->hydra_version,
2052 adapter->fsf_lic_version,
2053 fc_host_speed(shost));
2054 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2055 ZFCP_LOG_NORMAL("error: the adapter %s "
2056 "only supports newer control block "
2057 "versions in comparison to this device "
2058 "driver (try updated device driver)\n",
2059 zfcp_get_busid_by_adapter(adapter));
2060 zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
2063 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2064 ZFCP_LOG_NORMAL("error: the adapter %s "
2065 "only supports older control block "
2066 "versions than this device driver uses"
2067 "(consider a microcode upgrade)\n",
2068 zfcp_get_busid_by_adapter(adapter));
2069 zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
2076 * function: zfcp_fsf_exchange_config_data_handler
2078 * purpose: is called for finished Exchange Configuration Data command
2083 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2085 struct fsf_qtcb_bottom_config *bottom;
2086 struct zfcp_adapter *adapter = fsf_req->adapter;
2087 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2089 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2092 switch (qtcb->header.fsf_status) {
2095 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2098 switch (fc_host_port_type(adapter->scsi_host)) {
2099 case FC_PORTTYPE_PTP:
2100 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2101 "configuration detected at adapter %s\n"
2102 "Peer WWNN 0x%016llx, "
2103 "peer WWPN 0x%016llx, "
2104 "peer d_id 0x%06x\n",
2105 zfcp_get_busid_by_adapter(adapter),
2108 adapter->peer_d_id);
2110 case FC_PORTTYPE_NLPORT:
2111 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2112 "topology detected at adapter %s "
2113 "unsupported, shutting down adapter\n",
2114 zfcp_get_busid_by_adapter(adapter));
2115 zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
2117 case FC_PORTTYPE_NPORT:
2118 if (fsf_req->erp_action)
2119 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2120 "network detected at adapter "
2122 zfcp_get_busid_by_adapter(adapter));
2125 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2126 "reported by the exchange "
2127 "configuration command for "
2128 "the adapter %s is not "
2129 "of a type known to the zfcp "
2130 "driver, shutting down adapter\n",
2131 zfcp_get_busid_by_adapter(adapter));
2132 zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
2135 bottom = &qtcb->bottom.config;
2136 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2137 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2138 "allowed by the adapter %s "
2139 "is lower than the minimum "
2140 "required by the driver (%ld bytes).\n",
2141 bottom->max_qtcb_size,
2142 zfcp_get_busid_by_adapter(adapter),
2143 sizeof(struct fsf_qtcb));
2144 zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
2147 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2150 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2151 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2154 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2157 zfcp_fsf_link_down_info_eval(fsf_req, 42,
2158 &qtcb->header.fsf_status_qual.link_down_info);
2161 zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
2168 * zfcp_fsf_exchange_port_data - request information about local port
2169 * @erp_action: ERP action for the adapter for which port data is requested
2172 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
2174 volatile struct qdio_buffer_element *sbale;
2175 struct zfcp_fsf_req *fsf_req;
2176 struct zfcp_adapter *adapter = erp_action->adapter;
2177 unsigned long lock_flags;
2180 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2181 ZFCP_LOG_INFO("error: exchange port data "
2182 "command not supported by adapter %s\n",
2183 zfcp_get_busid_by_adapter(adapter));
2187 /* setup new FSF request */
2188 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2189 ZFCP_REQ_AUTO_CLEANUP,
2190 adapter->pool.fsf_req_erp,
2191 &lock_flags, &fsf_req);
2193 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2194 "exchange port data request for "
2195 "the adapter %s.\n",
2196 zfcp_get_busid_by_adapter(adapter));
2197 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2202 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2203 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2204 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2206 erp_action->fsf_req = fsf_req;
2207 fsf_req->erp_action = erp_action;
2208 zfcp_erp_start_timer(fsf_req);
2210 retval = zfcp_fsf_req_send(fsf_req);
2211 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2214 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2215 "command on the adapter %s\n",
2216 zfcp_get_busid_by_adapter(adapter));
2217 zfcp_fsf_req_free(fsf_req);
2218 erp_action->fsf_req = NULL;
2221 ZFCP_LOG_DEBUG("exchange port data request initiated "
2223 zfcp_get_busid_by_adapter(adapter));
2229 * zfcp_fsf_exchange_port_data_sync - request information about local port
2230 * and wait until information is ready
2233 zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
2234 struct fsf_qtcb_bottom_port *data)
2236 volatile struct qdio_buffer_element *sbale;
2237 struct zfcp_fsf_req *fsf_req;
2238 unsigned long lock_flags;
2241 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2242 ZFCP_LOG_INFO("error: exchange port data "
2243 "command not supported by adapter %s\n",
2244 zfcp_get_busid_by_adapter(adapter));
2248 /* setup new FSF request */
2249 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2250 0, NULL, &lock_flags, &fsf_req);
2252 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2253 "exchange port data request for "
2254 "the adapter %s.\n",
2255 zfcp_get_busid_by_adapter(adapter));
2256 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2262 fsf_req->data = (unsigned long) data;
2264 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2265 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2266 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2268 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2269 retval = zfcp_fsf_req_send(fsf_req);
2270 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2273 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2274 "command on the adapter %s\n",
2275 zfcp_get_busid_by_adapter(adapter));
2277 wait_event(fsf_req->completion_wq,
2278 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2280 zfcp_fsf_req_free(fsf_req);
2286 * zfcp_fsf_exchange_port_evaluate
2287 * @fsf_req: fsf_req which belongs to xchg port data request
2288 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2291 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2293 struct zfcp_adapter *adapter;
2294 struct fsf_qtcb_bottom_port *bottom;
2295 struct Scsi_Host *shost;
2297 adapter = fsf_req->adapter;
2298 bottom = &fsf_req->qtcb->bottom.port;
2299 shost = adapter->scsi_host;
2302 memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
2303 sizeof(struct fsf_qtcb_bottom_port));
2305 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2306 fc_host_permanent_port_name(shost) = bottom->wwpn;
2308 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2309 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2310 fc_host_supported_speeds(shost) = bottom->supported_speed;
2314 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2315 * @fsf_req: pointer to struct zfcp_fsf_req
2318 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2320 struct zfcp_adapter *adapter;
2321 struct fsf_qtcb *qtcb;
2323 adapter = fsf_req->adapter;
2324 qtcb = fsf_req->qtcb;
2326 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2329 switch (qtcb->header.fsf_status) {
2331 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2332 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2334 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2335 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2336 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2337 zfcp_fsf_link_down_info_eval(fsf_req, 43,
2338 &qtcb->header.fsf_status_qual.link_down_info);
2345 * function: zfcp_fsf_open_port
2349 * returns: address of initiated FSF request
2350 * NULL - request could not be initiated
2353 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2355 volatile struct qdio_buffer_element *sbale;
2356 struct zfcp_fsf_req *fsf_req;
2357 unsigned long lock_flags;
2360 /* setup new FSF request */
2361 retval = zfcp_fsf_req_create(erp_action->adapter,
2362 FSF_QTCB_OPEN_PORT_WITH_DID,
2363 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2364 erp_action->adapter->pool.fsf_req_erp,
2365 &lock_flags, &fsf_req);
2367 ZFCP_LOG_INFO("error: Could not create open port request "
2368 "for port 0x%016Lx on adapter %s.\n",
2369 erp_action->port->wwpn,
2370 zfcp_get_busid_by_adapter(erp_action->adapter));
2374 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2375 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2376 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2378 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2379 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2380 fsf_req->data = (unsigned long) erp_action->port;
2381 fsf_req->erp_action = erp_action;
2382 erp_action->fsf_req = fsf_req;
2384 zfcp_erp_start_timer(fsf_req);
2385 retval = zfcp_fsf_req_send(fsf_req);
2387 ZFCP_LOG_INFO("error: Could not send open port request for "
2388 "port 0x%016Lx on adapter %s.\n",
2389 erp_action->port->wwpn,
2390 zfcp_get_busid_by_adapter(erp_action->adapter));
2391 zfcp_fsf_req_free(fsf_req);
2392 erp_action->fsf_req = NULL;
2396 ZFCP_LOG_DEBUG("open port request initiated "
2397 "(adapter %s, port 0x%016Lx)\n",
2398 zfcp_get_busid_by_adapter(erp_action->adapter),
2399 erp_action->port->wwpn);
2401 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2407 * function: zfcp_fsf_open_port_handler
2409 * purpose: is called for finished Open Port command
2414 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2416 int retval = -EINVAL;
2417 struct zfcp_port *port;
2418 struct fsf_plogi *plogi;
2419 struct fsf_qtcb_header *header;
2420 u16 subtable, rule, counter;
2422 port = (struct zfcp_port *) fsf_req->data;
2423 header = &fsf_req->qtcb->header;
2425 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2426 /* don't change port status in our bookkeeping */
2427 goto skip_fsfstatus;
2430 /* evaluate FSF status in QTCB */
2431 switch (header->fsf_status) {
2433 case FSF_PORT_ALREADY_OPEN:
2434 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2435 "is already open.\n",
2436 port->wwpn, zfcp_get_busid_by_port(port));
2438 * This is a bug, however operation should continue normally
2439 * if it is simply ignored
2443 case FSF_ACCESS_DENIED:
2444 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2446 port->wwpn, zfcp_get_busid_by_port(port));
2447 for (counter = 0; counter < 2; counter++) {
2448 subtable = header->fsf_status_qual.halfword[counter * 2];
2449 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2451 case FSF_SQ_CFDC_SUBTABLE_OS:
2452 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2453 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2454 case FSF_SQ_CFDC_SUBTABLE_LUN:
2455 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2456 zfcp_act_subtable_type[subtable], rule);
2460 zfcp_erp_port_access_denied(port, 57, fsf_req);
2461 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2464 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2465 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2466 "The remote port 0x%016Lx on adapter %s "
2467 "could not be opened. Disabling it.\n",
2468 port->wwpn, zfcp_get_busid_by_port(port));
2469 zfcp_erp_port_failed(port, 31, fsf_req);
2470 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2473 case FSF_ADAPTER_STATUS_AVAILABLE:
2474 switch (header->fsf_status_qual.word[0]) {
2475 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2476 /* ERP strategy will escalate */
2477 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2479 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2480 /* ERP strategy will escalate */
2481 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2483 case FSF_SQ_NO_RETRY_POSSIBLE:
2484 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2485 "adapter %s could not be opened. "
2488 zfcp_get_busid_by_port(port));
2489 zfcp_erp_port_failed(port, 32, fsf_req);
2490 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2494 ("bug: Wrong status qualifier 0x%x arrived.\n",
2495 header->fsf_status_qual.word[0]);
2501 /* save port handle assigned by FSF */
2502 port->handle = header->port_handle;
2503 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2504 "was opened, it's port handle is 0x%x\n",
2505 port->wwpn, zfcp_get_busid_by_port(port),
2507 /* mark port as open */
2508 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2509 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2510 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2511 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2514 /* check whether D_ID has changed during open */
2516 * FIXME: This check is not airtight, as the FCP channel does
2517 * not monitor closures of target port connections caused on
2518 * the remote side. Thus, they might miss out on invalidating
2519 * locally cached WWPNs (and other N_Port parameters) of gone
2520 * target ports. So, our heroic attempt to make things safe
2521 * could be undermined by 'open port' response data tagged with
2522 * obsolete WWPNs. Another reason to monitor potential
2523 * connection closures ourself at least (by interpreting
2524 * incoming ELS' and unsolicited status). It just crosses my
2525 * mind that one should be able to cross-check by means of
2526 * another GID_PN straight after a port has been opened.
2527 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2529 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2530 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2532 if (fsf_req->qtcb->bottom.support.els1_length <
2533 sizeof (struct fsf_plogi)) {
2535 "warning: insufficient length of "
2536 "PLOGI payload (%i)\n",
2537 fsf_req->qtcb->bottom.support.els1_length);
2538 /* skip sanity check and assume wwpn is ok */
2540 if (plogi->serv_param.wwpn != port->wwpn) {
2541 ZFCP_LOG_INFO("warning: d_id of port "
2542 "0x%016Lx changed during "
2543 "open\n", port->wwpn);
2545 ZFCP_STATUS_PORT_DID_DID,
2548 port->wwnn = plogi->serv_param.wwnn;
2549 zfcp_plogi_evaluate(port, plogi);
2555 case FSF_UNKNOWN_OP_SUBTYPE:
2556 /* should never occure, subtype not set in zfcp_fsf_open_port */
2557 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2558 "op_subtype=0x%x)\n",
2559 zfcp_get_busid_by_port(port),
2560 fsf_req->qtcb->bottom.support.operation_subtype);
2561 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2565 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2566 "(debug info 0x%x)\n",
2567 header->fsf_status);
2572 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2577 * function: zfcp_fsf_close_port
2579 * purpose: submit FSF command "close port"
2581 * returns: address of initiated FSF request
2582 * NULL - request could not be initiated
2585 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2587 volatile struct qdio_buffer_element *sbale;
2588 struct zfcp_fsf_req *fsf_req;
2589 unsigned long lock_flags;
2592 /* setup new FSF request */
2593 retval = zfcp_fsf_req_create(erp_action->adapter,
2594 FSF_QTCB_CLOSE_PORT,
2595 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2596 erp_action->adapter->pool.fsf_req_erp,
2597 &lock_flags, &fsf_req);
2599 ZFCP_LOG_INFO("error: Could not create a close port request "
2600 "for port 0x%016Lx on adapter %s.\n",
2601 erp_action->port->wwpn,
2602 zfcp_get_busid_by_adapter(erp_action->adapter));
2606 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2607 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2608 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2610 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2611 fsf_req->data = (unsigned long) erp_action->port;
2612 fsf_req->erp_action = erp_action;
2613 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2614 fsf_req->erp_action = erp_action;
2615 erp_action->fsf_req = fsf_req;
2617 zfcp_erp_start_timer(fsf_req);
2618 retval = zfcp_fsf_req_send(fsf_req);
2620 ZFCP_LOG_INFO("error: Could not send a close port request for "
2621 "port 0x%016Lx on adapter %s.\n",
2622 erp_action->port->wwpn,
2623 zfcp_get_busid_by_adapter(erp_action->adapter));
2624 zfcp_fsf_req_free(fsf_req);
2625 erp_action->fsf_req = NULL;
2629 ZFCP_LOG_TRACE("close port request initiated "
2630 "(adapter %s, port 0x%016Lx)\n",
2631 zfcp_get_busid_by_adapter(erp_action->adapter),
2632 erp_action->port->wwpn);
2634 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2640 * function: zfcp_fsf_close_port_handler
2642 * purpose: is called for finished Close Port FSF command
2647 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2649 int retval = -EINVAL;
2650 struct zfcp_port *port;
2652 port = (struct zfcp_port *) fsf_req->data;
2654 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2655 /* don't change port status in our bookkeeping */
2656 goto skip_fsfstatus;
2659 /* evaluate FSF status in QTCB */
2660 switch (fsf_req->qtcb->header.fsf_status) {
2662 case FSF_PORT_HANDLE_NOT_VALID:
2663 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2664 "0x%016Lx on adapter %s invalid. This may happen "
2665 "occasionally.\n", port->handle,
2666 port->wwpn, zfcp_get_busid_by_port(port));
2667 ZFCP_LOG_DEBUG("status qualifier:\n");
2668 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2669 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2670 sizeof (union fsf_status_qual));
2671 zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
2672 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2675 case FSF_ADAPTER_STATUS_AVAILABLE:
2676 /* Note: FSF has actually closed the port in this case.
2677 * The status code is just daft. Fingers crossed for a change
2683 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2684 "port handle 0x%x\n", port->wwpn,
2685 zfcp_get_busid_by_port(port), port->handle);
2686 zfcp_erp_modify_port_status(port, 33, fsf_req,
2687 ZFCP_STATUS_COMMON_OPEN,
2693 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2694 "(debug info 0x%x)\n",
2695 fsf_req->qtcb->header.fsf_status);
2700 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2705 * function: zfcp_fsf_close_physical_port
2707 * purpose: submit FSF command "close physical port"
2709 * returns: address of initiated FSF request
2710 * NULL - request could not be initiated
2713 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2715 volatile struct qdio_buffer_element *sbale;
2716 struct zfcp_fsf_req *fsf_req;
2717 unsigned long lock_flags;
2720 /* setup new FSF request */
2721 retval = zfcp_fsf_req_create(erp_action->adapter,
2722 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2723 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2724 erp_action->adapter->pool.fsf_req_erp,
2725 &lock_flags, &fsf_req);
2727 ZFCP_LOG_INFO("error: Could not create close physical port "
2728 "request (adapter %s, port 0x%016Lx)\n",
2729 zfcp_get_busid_by_adapter(erp_action->adapter),
2730 erp_action->port->wwpn);
2735 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2736 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2737 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2739 /* mark port as being closed */
2740 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2741 &erp_action->port->status);
2742 /* save a pointer to this port */
2743 fsf_req->data = (unsigned long) erp_action->port;
2744 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2745 fsf_req->erp_action = erp_action;
2746 erp_action->fsf_req = fsf_req;
2748 zfcp_erp_start_timer(fsf_req);
2749 retval = zfcp_fsf_req_send(fsf_req);
2751 ZFCP_LOG_INFO("error: Could not send close physical port "
2752 "request (adapter %s, port 0x%016Lx)\n",
2753 zfcp_get_busid_by_adapter(erp_action->adapter),
2754 erp_action->port->wwpn);
2755 zfcp_fsf_req_free(fsf_req);
2756 erp_action->fsf_req = NULL;
2760 ZFCP_LOG_TRACE("close physical port request initiated "
2761 "(adapter %s, port 0x%016Lx)\n",
2762 zfcp_get_busid_by_adapter(erp_action->adapter),
2763 erp_action->port->wwpn);
2765 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2771 * function: zfcp_fsf_close_physical_port_handler
2773 * purpose: is called for finished Close Physical Port FSF command
2778 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2780 int retval = -EINVAL;
2781 struct zfcp_port *port;
2782 struct zfcp_unit *unit;
2783 struct fsf_qtcb_header *header;
2784 u16 subtable, rule, counter;
2786 port = (struct zfcp_port *) fsf_req->data;
2787 header = &fsf_req->qtcb->header;
2789 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2790 /* don't change port status in our bookkeeping */
2791 goto skip_fsfstatus;
2794 /* evaluate FSF status in QTCB */
2795 switch (header->fsf_status) {
2797 case FSF_PORT_HANDLE_NOT_VALID:
2798 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2799 "(adapter %s, port 0x%016Lx). "
2800 "This may happen occasionally.\n",
2802 zfcp_get_busid_by_port(port),
2804 ZFCP_LOG_DEBUG("status qualifier:\n");
2805 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2806 (char *) &header->fsf_status_qual,
2807 sizeof (union fsf_status_qual));
2808 zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
2809 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2812 case FSF_ACCESS_DENIED:
2813 ZFCP_LOG_NORMAL("Access denied, cannot close "
2814 "physical port 0x%016Lx on adapter %s\n",
2815 port->wwpn, zfcp_get_busid_by_port(port));
2816 for (counter = 0; counter < 2; counter++) {
2817 subtable = header->fsf_status_qual.halfword[counter * 2];
2818 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2820 case FSF_SQ_CFDC_SUBTABLE_OS:
2821 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2822 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2823 case FSF_SQ_CFDC_SUBTABLE_LUN:
2824 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2825 zfcp_act_subtable_type[subtable], rule);
2829 zfcp_erp_port_access_denied(port, 58, fsf_req);
2830 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2833 case FSF_PORT_BOXED:
2834 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2835 "%s needs to be reopened but it was attempted "
2836 "to close it physically.\n",
2838 zfcp_get_busid_by_port(port));
2839 zfcp_erp_port_boxed(port, 50, fsf_req);
2840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2841 ZFCP_STATUS_FSFREQ_RETRY;
2843 /* can't use generic zfcp_erp_modify_port_status because
2844 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
2845 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2846 list_for_each_entry(unit, &port->unit_list_head, list)
2847 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
2851 case FSF_ADAPTER_STATUS_AVAILABLE:
2852 switch (header->fsf_status_qual.word[0]) {
2853 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2854 /* This will now be escalated by ERP */
2855 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2857 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2858 /* ERP strategy will escalate */
2859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2863 ("bug: Wrong status qualifier 0x%x arrived.\n",
2864 header->fsf_status_qual.word[0]);
2870 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2871 "physically closed, port handle 0x%x\n",
2873 zfcp_get_busid_by_port(port), port->handle);
2874 /* can't use generic zfcp_erp_modify_port_status because
2875 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2877 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2878 list_for_each_entry(unit, &port->unit_list_head, list)
2879 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2884 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2885 "(debug info 0x%x)\n",
2886 header->fsf_status);
2891 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2896 * function: zfcp_fsf_open_unit
2902 * assumptions: This routine does not check whether the associated
2903 * remote port has already been opened. This should be
2904 * done by calling routines. Otherwise some status
2905 * may be presented by FSF
2908 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2910 volatile struct qdio_buffer_element *sbale;
2911 struct zfcp_fsf_req *fsf_req;
2912 unsigned long lock_flags;
2915 /* setup new FSF request */
2916 retval = zfcp_fsf_req_create(erp_action->adapter,
2918 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2919 erp_action->adapter->pool.fsf_req_erp,
2920 &lock_flags, &fsf_req);
2922 ZFCP_LOG_INFO("error: Could not create open unit request for "
2923 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2924 erp_action->unit->fcp_lun,
2925 erp_action->unit->port->wwpn,
2926 zfcp_get_busid_by_adapter(erp_action->adapter));
2930 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2931 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2932 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2934 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2935 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
2936 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2937 fsf_req->qtcb->bottom.support.option =
2938 FSF_OPEN_LUN_SUPPRESS_BOXING;
2939 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2940 fsf_req->data = (unsigned long) erp_action->unit;
2941 fsf_req->erp_action = erp_action;
2942 erp_action->fsf_req = fsf_req;
2944 zfcp_erp_start_timer(fsf_req);
2945 retval = zfcp_fsf_req_send(erp_action->fsf_req);
2947 ZFCP_LOG_INFO("error: Could not send an open unit request "
2948 "on the adapter %s, port 0x%016Lx for "
2950 zfcp_get_busid_by_adapter(erp_action->adapter),
2951 erp_action->port->wwpn,
2952 erp_action->unit->fcp_lun);
2953 zfcp_fsf_req_free(fsf_req);
2954 erp_action->fsf_req = NULL;
2958 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2959 "port 0x%016Lx, unit 0x%016Lx)\n",
2960 zfcp_get_busid_by_adapter(erp_action->adapter),
2961 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2963 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2969 * function: zfcp_fsf_open_unit_handler
2971 * purpose: is called for finished Open LUN command
2976 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2978 int retval = -EINVAL;
2979 struct zfcp_adapter *adapter;
2980 struct zfcp_unit *unit;
2981 struct fsf_qtcb_header *header;
2982 struct fsf_qtcb_bottom_support *bottom;
2983 struct fsf_queue_designator *queue_designator;
2984 u16 subtable, rule, counter;
2985 int exclusive, readwrite;
2987 unit = (struct zfcp_unit *) fsf_req->data;
2989 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2990 /* don't change unit status in our bookkeeping */
2991 goto skip_fsfstatus;
2994 adapter = fsf_req->adapter;
2995 header = &fsf_req->qtcb->header;
2996 bottom = &fsf_req->qtcb->bottom.support;
2997 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2999 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3000 ZFCP_STATUS_COMMON_ACCESS_BOXED |
3001 ZFCP_STATUS_UNIT_SHARED |
3002 ZFCP_STATUS_UNIT_READONLY,
3005 /* evaluate FSF status in QTCB */
3006 switch (header->fsf_status) {
3008 case FSF_PORT_HANDLE_NOT_VALID:
3009 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3010 "for port 0x%016Lx on adapter %s invalid "
3011 "This may happen occasionally\n",
3013 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3014 ZFCP_LOG_DEBUG("status qualifier:\n");
3015 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3016 (char *) &header->fsf_status_qual,
3017 sizeof (union fsf_status_qual));
3018 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
3019 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3022 case FSF_LUN_ALREADY_OPEN:
3023 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3024 "remote port 0x%016Lx on adapter %s twice.\n",
3026 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3027 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3030 case FSF_ACCESS_DENIED:
3031 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3032 "remote port 0x%016Lx on adapter %s\n",
3033 unit->fcp_lun, unit->port->wwpn,
3034 zfcp_get_busid_by_unit(unit));
3035 for (counter = 0; counter < 2; counter++) {
3036 subtable = header->fsf_status_qual.halfword[counter * 2];
3037 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3039 case FSF_SQ_CFDC_SUBTABLE_OS:
3040 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3041 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3042 case FSF_SQ_CFDC_SUBTABLE_LUN:
3043 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3044 zfcp_act_subtable_type[subtable], rule);
3048 zfcp_erp_unit_access_denied(unit, 59, fsf_req);
3049 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3051 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3054 case FSF_PORT_BOXED:
3055 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3056 "needs to be reopened\n",
3057 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3058 zfcp_erp_port_boxed(unit->port, 51, fsf_req);
3059 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3060 ZFCP_STATUS_FSFREQ_RETRY;
3063 case FSF_LUN_SHARING_VIOLATION:
3064 if (header->fsf_status_qual.word[0] != 0) {
3065 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3067 "connected to the adapter %s "
3068 "is already in use in LPAR%d, CSS%d\n",
3071 zfcp_get_busid_by_unit(unit),
3072 queue_designator->hla,
3073 queue_designator->cssid);
3075 subtable = header->fsf_status_qual.halfword[4];
3076 rule = header->fsf_status_qual.halfword[5];
3078 case FSF_SQ_CFDC_SUBTABLE_OS:
3079 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3080 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3081 case FSF_SQ_CFDC_SUBTABLE_LUN:
3082 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3083 "remote port with WWPN 0x%Lx "
3084 "connected to the adapter %s "
3085 "is denied (%s rule %d)\n",
3088 zfcp_get_busid_by_unit(unit),
3089 zfcp_act_subtable_type[subtable],
3094 ZFCP_LOG_DEBUG("status qualifier:\n");
3095 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3096 (char *) &header->fsf_status_qual,
3097 sizeof (union fsf_status_qual));
3098 zfcp_erp_unit_access_denied(unit, 60, fsf_req);
3099 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3100 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3101 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3104 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3105 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3106 "There is no handle (temporary port identifier) "
3107 "available for unit 0x%016Lx on port 0x%016Lx "
3111 zfcp_get_busid_by_unit(unit));
3112 zfcp_erp_unit_failed(unit, 34, fsf_req);
3113 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3116 case FSF_ADAPTER_STATUS_AVAILABLE:
3117 switch (header->fsf_status_qual.word[0]) {
3118 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3119 /* Re-establish link to port */
3120 zfcp_test_link(unit->port);
3121 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3123 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3124 /* ERP strategy will escalate */
3125 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3129 ("bug: Wrong status qualifier 0x%x arrived.\n",
3130 header->fsf_status_qual.word[0]);
3134 case FSF_INVALID_COMMAND_OPTION:
3136 "Invalid option 0x%x has been specified "
3137 "in QTCB bottom sent to the adapter %s\n",
3139 zfcp_get_busid_by_adapter(adapter));
3140 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3145 /* save LUN handle assigned by FSF */
3146 unit->handle = header->lun_handle;
3147 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3148 "adapter %s opened, port handle 0x%x\n",
3151 zfcp_get_busid_by_unit(unit),
3153 /* mark unit as open */
3154 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3156 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3157 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3158 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3159 exclusive = (bottom->lun_access_info &
3160 FSF_UNIT_ACCESS_EXCLUSIVE);
3161 readwrite = (bottom->lun_access_info &
3162 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3165 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3169 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3171 ZFCP_LOG_NORMAL("read-only access for unit "
3172 "(adapter %s, wwpn=0x%016Lx, "
3173 "fcp_lun=0x%016Lx)\n",
3174 zfcp_get_busid_by_unit(unit),
3179 if (exclusive && !readwrite) {
3180 ZFCP_LOG_NORMAL("exclusive access of read-only "
3181 "unit not supported\n");
3182 zfcp_erp_unit_failed(unit, 35, fsf_req);
3183 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3184 zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
3185 } else if (!exclusive && readwrite) {
3186 ZFCP_LOG_NORMAL("shared access of read-write "
3187 "unit not supported\n");
3188 zfcp_erp_unit_failed(unit, 36, fsf_req);
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3190 zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
3198 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3199 "(debug info 0x%x)\n",
3200 header->fsf_status);
3205 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3210 * function: zfcp_fsf_close_unit
3214 * returns: address of fsf_req - request successfully initiated
3217 * assumptions: This routine does not check whether the associated
3218 * remote port/lun has already been opened. This should be
3219 * done by calling routines. Otherwise some status
3220 * may be presented by FSF
3223 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3225 volatile struct qdio_buffer_element *sbale;
3226 struct zfcp_fsf_req *fsf_req;
3227 unsigned long lock_flags;
3230 /* setup new FSF request */
3231 retval = zfcp_fsf_req_create(erp_action->adapter,
3233 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3234 erp_action->adapter->pool.fsf_req_erp,
3235 &lock_flags, &fsf_req);
3237 ZFCP_LOG_INFO("error: Could not create close unit request for "
3238 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3239 erp_action->unit->fcp_lun,
3240 erp_action->port->wwpn,
3241 zfcp_get_busid_by_adapter(erp_action->adapter));
3245 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3246 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3247 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3249 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3250 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3251 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3252 fsf_req->data = (unsigned long) erp_action->unit;
3253 fsf_req->erp_action = erp_action;
3254 erp_action->fsf_req = fsf_req;
3256 zfcp_erp_start_timer(fsf_req);
3257 retval = zfcp_fsf_req_send(erp_action->fsf_req);
3259 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3260 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3261 erp_action->unit->fcp_lun,
3262 erp_action->port->wwpn,
3263 zfcp_get_busid_by_adapter(erp_action->adapter));
3264 zfcp_fsf_req_free(fsf_req);
3265 erp_action->fsf_req = NULL;
3269 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3270 "port 0x%016Lx, unit 0x%016Lx)\n",
3271 zfcp_get_busid_by_adapter(erp_action->adapter),
3272 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3274 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3280 * function: zfcp_fsf_close_unit_handler
3282 * purpose: is called for finished Close LUN FSF command
3287 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3289 int retval = -EINVAL;
3290 struct zfcp_unit *unit;
3292 unit = (struct zfcp_unit *) fsf_req->data;
3294 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3295 /* don't change unit status in our bookkeeping */
3296 goto skip_fsfstatus;
3299 /* evaluate FSF status in QTCB */
3300 switch (fsf_req->qtcb->header.fsf_status) {
3302 case FSF_PORT_HANDLE_NOT_VALID:
3303 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3304 "0x%016Lx on adapter %s invalid. This may "
3305 "happen in rare circumstances\n",
3308 zfcp_get_busid_by_unit(unit));
3309 ZFCP_LOG_DEBUG("status qualifier:\n");
3310 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3311 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3312 sizeof (union fsf_status_qual));
3313 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
3314 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3317 case FSF_LUN_HANDLE_NOT_VALID:
3318 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3319 "0x%016Lx on port 0x%016Lx on adapter %s is "
3320 "invalid. This may happen occasionally.\n",
3324 zfcp_get_busid_by_unit(unit));
3325 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3326 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3327 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3328 sizeof (union fsf_status_qual));
3329 zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
3330 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3333 case FSF_PORT_BOXED:
3334 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3335 "needs to be reopened\n",
3337 zfcp_get_busid_by_unit(unit));
3338 zfcp_erp_port_boxed(unit->port, 52, fsf_req);
3339 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3340 ZFCP_STATUS_FSFREQ_RETRY;
3343 case FSF_ADAPTER_STATUS_AVAILABLE:
3344 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3345 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3346 /* re-establish link to port */
3347 zfcp_test_link(unit->port);
3348 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3350 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3351 /* ERP strategy will escalate */
3352 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3356 ("bug: Wrong status qualifier 0x%x arrived.\n",
3357 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3363 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3364 "closed, port handle 0x%x\n",
3367 zfcp_get_busid_by_unit(unit),
3369 /* mark unit as closed */
3370 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3375 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3376 "(debug info 0x%x)\n",
3377 fsf_req->qtcb->header.fsf_status);
3382 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3387 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3388 * @adapter: adapter where scsi command is issued
3389 * @unit: unit where command is sent to
3390 * @scsi_cmnd: scsi command to be sent
3391 * @timer: timer to be started when request is initiated
3392 * @req_flags: flags for fsf_request
3395 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3396 struct zfcp_unit *unit,
3397 struct scsi_cmnd * scsi_cmnd,
3398 int use_timer, int req_flags)
3400 struct zfcp_fsf_req *fsf_req = NULL;
3401 struct fcp_cmnd_iu *fcp_cmnd_iu;
3402 unsigned int sbtype;
3403 unsigned long lock_flags;
3408 /* setup new FSF request */
3409 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3410 adapter->pool.fsf_req_scsi,
3411 &lock_flags, &fsf_req);
3412 if (unlikely(retval < 0)) {
3413 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3414 "for unit 0x%016Lx on port 0x%016Lx on "
3418 zfcp_get_busid_by_adapter(adapter));
3419 goto failed_req_create;
3422 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3428 zfcp_unit_get(unit);
3429 fsf_req->unit = unit;
3431 /* associate FSF request with SCSI request (for look up on abort) */
3432 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3434 /* associate SCSI command with FSF request */
3435 fsf_req->data = (unsigned long) scsi_cmnd;
3437 /* set handles of unit and its parent port in QTCB */
3438 fsf_req->qtcb->header.lun_handle = unit->handle;
3439 fsf_req->qtcb->header.port_handle = unit->port->handle;
3441 /* FSF does not define the structure of the FCP_CMND IU */
3442 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3443 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3446 * set depending on data direction:
3447 * data direction bits in SBALE (SB Type)
3448 * data direction bits in QTCB
3449 * data direction bits in FCP_CMND IU
3451 switch (scsi_cmnd->sc_data_direction) {
3453 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3456 * what is the correct type for commands
3457 * without 'real' data buffers?
3459 sbtype = SBAL_FLAGS0_TYPE_READ;
3461 case DMA_FROM_DEVICE:
3462 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3463 sbtype = SBAL_FLAGS0_TYPE_READ;
3464 fcp_cmnd_iu->rddata = 1;
3467 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3468 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3469 fcp_cmnd_iu->wddata = 1;
3471 case DMA_BIDIRECTIONAL:
3474 * dummy, catch this condition earlier
3475 * in zfcp_scsi_queuecommand
3477 goto failed_scsi_cmnd;
3480 /* set FC service class in QTCB (3 per default) */
3481 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3483 /* set FCP_LUN in FCP_CMND IU in QTCB */
3484 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3486 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3488 /* set task attributes in FCP_CMND IU in QTCB */
3489 if (likely((scsi_cmnd->device->simple_tags) ||
3490 (atomic_test_mask(mask, &unit->status))))
3491 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3493 fcp_cmnd_iu->task_attribute = UNTAGGED;
3495 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3496 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3497 fcp_cmnd_iu->add_fcp_cdb_length
3498 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3499 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3500 "additional FCP_CDB length is 0x%x "
3501 "(shifted right 2 bits)\n",
3503 fcp_cmnd_iu->add_fcp_cdb_length);
3506 * copy SCSI CDB (including additional length, if any) to
3507 * FCP_CDB in FCP_CMND IU in QTCB
3509 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3511 /* FCP CMND IU length in QTCB */
3512 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3513 sizeof (struct fcp_cmnd_iu) +
3514 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3516 /* generate SBALEs from data buffer */
3517 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3518 if (unlikely(real_bytes < 0)) {
3519 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3521 "Data did not fit into available buffer(s), "
3522 "waiting for more...\n");
3525 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3526 "required. Shutting down unit "
3527 "(adapter %s, port 0x%016Lx, "
3529 zfcp_get_busid_by_unit(unit),
3532 zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
3538 /* set length of FCP data length in FCP_CMND IU in QTCB */
3539 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3541 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3542 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3543 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3546 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3548 retval = zfcp_fsf_req_send(fsf_req);
3549 if (unlikely(retval < 0)) {
3550 ZFCP_LOG_INFO("error: Could not send FCP command request "
3551 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3552 zfcp_get_busid_by_adapter(adapter),
3558 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3559 "port 0x%016Lx, unit 0x%016Lx)\n",
3560 zfcp_get_busid_by_adapter(adapter),
3568 zfcp_unit_put(unit);
3570 zfcp_fsf_req_free(fsf_req);
3572 scsi_cmnd->host_scribble = NULL;
3575 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3579 struct zfcp_fsf_req *
3580 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3581 struct zfcp_unit *unit,
3582 u8 tm_flags, int req_flags)
3584 struct zfcp_fsf_req *fsf_req = NULL;
3586 struct fcp_cmnd_iu *fcp_cmnd_iu;
3587 unsigned long lock_flags;
3588 volatile struct qdio_buffer_element *sbale;
3590 /* setup new FSF request */
3591 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3592 adapter->pool.fsf_req_scsi,
3593 &lock_flags, &fsf_req);
3595 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3596 "management) request for adapter %s, port "
3597 " 0x%016Lx, unit 0x%016Lx.\n",
3598 zfcp_get_busid_by_adapter(adapter),
3599 unit->port->wwpn, unit->fcp_lun);
3603 if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
3608 * Used to decide on proper handler in the return path,
3609 * could be either zfcp_fsf_send_fcp_command_task_handler or
3610 * zfcp_fsf_send_fcp_command_task_management_handler */
3612 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3615 * hold a pointer to the unit being target of this
3616 * task management request
3618 fsf_req->data = (unsigned long) unit;
3620 /* set FSF related fields in QTCB */
3621 fsf_req->qtcb->header.lun_handle = unit->handle;
3622 fsf_req->qtcb->header.port_handle = unit->port->handle;
3623 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3624 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3625 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3626 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3628 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3629 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3630 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3632 /* set FCP related fields in FCP_CMND IU in QTCB */
3633 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3634 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3635 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3636 fcp_cmnd_iu->task_management_flags = tm_flags;
3638 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3639 retval = zfcp_fsf_req_send(fsf_req);
3644 zfcp_fsf_req_free(fsf_req);
3648 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3653 * function: zfcp_fsf_send_fcp_command_handler
3655 * purpose: is called for finished Send FCP Command
3660 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3662 int retval = -EINVAL;
3663 struct zfcp_unit *unit;
3664 struct fsf_qtcb_header *header;
3665 u16 subtable, rule, counter;
3667 header = &fsf_req->qtcb->header;
3669 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3670 unit = (struct zfcp_unit *) fsf_req->data;
3672 unit = fsf_req->unit;
3674 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3675 /* go directly to calls of special handlers */
3676 goto skip_fsfstatus;
3679 /* evaluate FSF status in QTCB */
3680 switch (header->fsf_status) {
3682 case FSF_PORT_HANDLE_NOT_VALID:
3683 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3684 "0x%016Lx on adapter %s invalid\n",
3686 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3687 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3688 (char *) &header->fsf_status_qual,
3689 sizeof (union fsf_status_qual));
3690 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
3691 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3694 case FSF_LUN_HANDLE_NOT_VALID:
3695 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3696 "0x%016Lx on port 0x%016Lx on adapter %s is "
3697 "invalid. This may happen occasionally.\n",
3701 zfcp_get_busid_by_unit(unit));
3702 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3703 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3704 (char *) &header->fsf_status_qual,
3705 sizeof (union fsf_status_qual));
3706 zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
3707 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3710 case FSF_HANDLE_MISMATCH:
3711 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3712 "unexpectedly. (adapter %s, port 0x%016Lx, "
3715 zfcp_get_busid_by_unit(unit),
3718 ZFCP_LOG_NORMAL("status qualifier:\n");
3719 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3720 (char *) &header->fsf_status_qual,
3721 sizeof (union fsf_status_qual));
3722 zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
3723 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3726 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3727 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3729 zfcp_get_busid_by_unit(unit),
3730 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3731 /* stop operation for this adapter */
3732 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
3733 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3736 case FSF_FCPLUN_NOT_VALID:
3737 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3738 "adapter %s does not have correct unit "
3742 zfcp_get_busid_by_unit(unit),
3744 ZFCP_LOG_DEBUG("status qualifier:\n");
3745 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3746 (char *) &header->fsf_status_qual,
3747 sizeof (union fsf_status_qual));
3748 zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
3749 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3752 case FSF_ACCESS_DENIED:
3753 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3754 "unit 0x%016Lx on port 0x%016Lx on "
3755 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3756 zfcp_get_busid_by_unit(unit));
3757 for (counter = 0; counter < 2; counter++) {
3758 subtable = header->fsf_status_qual.halfword[counter * 2];
3759 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3761 case FSF_SQ_CFDC_SUBTABLE_OS:
3762 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3763 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3764 case FSF_SQ_CFDC_SUBTABLE_LUN:
3765 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3766 zfcp_act_subtable_type[subtable], rule);
3770 zfcp_erp_unit_access_denied(unit, 61, fsf_req);
3771 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3774 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3775 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3776 "0x%016Lx on port 0x%016Lx on adapter %s "
3777 "(debug info %d)\n",
3780 zfcp_get_busid_by_unit(unit),
3781 fsf_req->qtcb->bottom.io.data_direction);
3782 /* stop operation for this adapter */
3783 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
3784 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3787 case FSF_CMND_LENGTH_NOT_VALID:
3789 ("bug: An invalid control-data-block length field "
3790 "was found in a command for unit 0x%016Lx on port "
3791 "0x%016Lx on adapter %s " "(debug info %d)\n",
3792 unit->fcp_lun, unit->port->wwpn,
3793 zfcp_get_busid_by_unit(unit),
3794 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3795 /* stop operation for this adapter */
3796 zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
3797 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3800 case FSF_PORT_BOXED:
3801 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3802 "needs to be reopened\n",
3803 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3804 zfcp_erp_port_boxed(unit->port, 53, fsf_req);
3805 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3806 ZFCP_STATUS_FSFREQ_RETRY;
3810 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3811 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3812 zfcp_get_busid_by_unit(unit),
3813 unit->port->wwpn, unit->fcp_lun);
3814 zfcp_erp_unit_boxed(unit, 54, fsf_req);
3815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3816 | ZFCP_STATUS_FSFREQ_RETRY;
3819 case FSF_ADAPTER_STATUS_AVAILABLE:
3820 switch (header->fsf_status_qual.word[0]) {
3821 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3822 /* re-establish link to port */
3823 zfcp_test_link(unit->port);
3825 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3826 /* FIXME(hw) need proper specs for proper action */
3827 /* let scsi stack deal with retries and escalation */
3831 ("Unknown status qualifier 0x%x arrived.\n",
3832 header->fsf_status_qual.word[0]);
3835 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3841 case FSF_FCP_RSP_AVAILABLE:
3846 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3848 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3850 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3851 fsf_req->unit = NULL;
3852 zfcp_unit_put(unit);
3858 * function: zfcp_fsf_send_fcp_command_task_handler
3860 * purpose: evaluates FCP_RSP IU
3865 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3868 struct scsi_cmnd *scpnt;
3869 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3870 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3871 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3872 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3874 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3875 unsigned long flags;
3876 struct zfcp_unit *unit = fsf_req->unit;
3878 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3879 scpnt = (struct scsi_cmnd *) fsf_req->data;
3880 if (unlikely(!scpnt)) {
3882 ("Command with fsf_req %p is not associated to "
3883 "a scsi command anymore. Aborted?\n", fsf_req);
3886 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3887 /* FIXME: (design) mid-layer should handle DID_ABORT like
3888 * DID_SOFT_ERROR by retrying the request for devices
3889 * that allow retries.
3891 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3892 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3893 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3894 goto skip_fsfstatus;
3897 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3898 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3899 set_host_byte(&scpnt->result, DID_ERROR);
3900 goto skip_fsfstatus;
3903 /* set message byte of result in SCSI command */
3904 scpnt->result |= COMMAND_COMPLETE << 8;
3907 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3908 * of result in SCSI command
3910 scpnt->result |= fcp_rsp_iu->scsi_status;
3911 if (unlikely(fcp_rsp_iu->scsi_status)) {
3913 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
3914 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3915 scpnt->cmnd, scpnt->cmd_len);
3916 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
3917 fcp_rsp_iu->scsi_status);
3918 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3919 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
3920 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3921 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
3922 fcp_rsp_iu->fcp_sns_len);
3925 /* check FCP_RSP_INFO */
3926 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
3927 ZFCP_LOG_DEBUG("rsp_len is valid\n");
3928 switch (fcp_rsp_info[3]) {
3931 ZFCP_LOG_TRACE("no failure or Task Management "
3932 "Function complete\n");
3933 set_host_byte(&scpnt->result, DID_OK);
3935 case RSP_CODE_LENGTH_MISMATCH:
3937 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3938 "that the fibrechannel protocol data "
3939 "length differs from the burst length. "
3940 "The problem occured on unit 0x%016Lx "
3941 "on port 0x%016Lx on adapter %s",
3944 zfcp_get_busid_by_unit(unit));
3945 /* dump SCSI CDB as prepared by zfcp */
3946 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3947 (char *) &fsf_req->qtcb->
3948 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3949 set_host_byte(&scpnt->result, DID_ERROR);
3950 goto skip_fsfstatus;
3951 case RSP_CODE_FIELD_INVALID:
3952 /* driver or hardware bug */
3953 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
3954 "that the fibrechannel protocol data "
3955 "fields were incorrectly set up. "
3956 "The problem occured on the unit "
3957 "0x%016Lx on port 0x%016Lx on "
3961 zfcp_get_busid_by_unit(unit));
3962 /* dump SCSI CDB as prepared by zfcp */
3963 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3964 (char *) &fsf_req->qtcb->
3965 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3966 set_host_byte(&scpnt->result, DID_ERROR);
3967 goto skip_fsfstatus;
3968 case RSP_CODE_RO_MISMATCH:
3970 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
3971 "that conflicting values for the "
3972 "fibrechannel payload offset from the "
3973 "header were found. "
3974 "The problem occured on unit 0x%016Lx "
3975 "on port 0x%016Lx on adapter %s.\n",
3978 zfcp_get_busid_by_unit(unit));
3979 /* dump SCSI CDB as prepared by zfcp */
3980 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3981 (char *) &fsf_req->qtcb->
3982 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3983 set_host_byte(&scpnt->result, DID_ERROR);
3984 goto skip_fsfstatus;
3986 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
3987 "code was detected for a command. "
3988 "The problem occured on the unit "
3989 "0x%016Lx on port 0x%016Lx on "
3990 "adapter %s (debug info 0x%x)\n",
3993 zfcp_get_busid_by_unit(unit),
3995 /* dump SCSI CDB as prepared by zfcp */
3996 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3997 (char *) &fsf_req->qtcb->
3998 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
3999 set_host_byte(&scpnt->result, DID_ERROR);
4000 goto skip_fsfstatus;
4004 /* check for sense data */
4005 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4006 sns_len = FSF_FCP_RSP_SIZE -
4007 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4008 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4010 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4011 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4012 SCSI_SENSE_BUFFERSIZE);
4013 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4014 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4016 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4017 (void *) &scpnt->cmnd, scpnt->cmd_len);
4019 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4020 fcp_rsp_iu->fcp_sns_len);
4021 memcpy(scpnt->sense_buffer,
4022 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4023 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4024 (void *)scpnt->sense_buffer, sns_len);
4027 /* check for overrun */
4028 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4029 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4030 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4031 "The response data length is "
4032 "%d, the original length was %d.\n",
4035 zfcp_get_busid_by_unit(unit),
4036 fcp_rsp_iu->fcp_resid,
4037 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4040 /* check for underrun */
4041 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4042 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4043 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4044 "The response data length is "
4045 "%d, the original length was %d.\n",
4048 zfcp_get_busid_by_unit(unit),
4049 fcp_rsp_iu->fcp_resid,
4050 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4052 scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
4053 if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
4055 set_host_byte(&scpnt->result, DID_ERROR);
4059 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4061 if (scpnt->result != 0)
4062 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4063 else if (scpnt->retries > 0)
4064 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4066 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4068 /* cleanup pointer (need this especially for abort) */
4069 scpnt->host_scribble = NULL;
4071 /* always call back */
4072 (scpnt->scsi_done) (scpnt);
4075 * We must hold this lock until scsi_done has been called.
4076 * Otherwise we may call scsi_done after abort regarding this
4077 * command has completed.
4078 * Note: scsi_done must not block!
4081 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4086 * function: zfcp_fsf_send_fcp_command_task_management_handler
4088 * purpose: evaluates FCP_RSP IU
4093 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4096 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4097 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4098 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4099 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4101 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4102 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4103 goto skip_fsfstatus;
4106 /* check FCP_RSP_INFO */
4107 switch (fcp_rsp_info[3]) {
4110 ZFCP_LOG_DEBUG("no failure or Task Management "
4111 "Function complete\n");
4113 case RSP_CODE_TASKMAN_UNSUPP:
4114 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4115 "is not supported on the target device "
4116 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4119 zfcp_get_busid_by_unit(unit));
4120 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4122 case RSP_CODE_TASKMAN_FAILED:
4123 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4124 "failed to complete successfully. "
4125 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4128 zfcp_get_busid_by_unit(unit));
4129 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4132 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4133 "code was detected for a command. "
4134 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4135 "(debug info 0x%x)\n",
4138 zfcp_get_busid_by_unit(unit),
4140 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4149 * function: zfcp_fsf_control_file
4151 * purpose: Initiator of the control file upload/download FSF requests
4153 * returns: 0 - FSF request is successfuly created and queued
4154 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4155 * -EINVAL - Invalid direction specified
4156 * -ENOMEM - Insufficient memory
4157 * -EPERM - Cannot create FSF request or place it in QDIO queue
4160 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4161 struct zfcp_fsf_req **fsf_req_ptr,
4164 struct zfcp_sg_list *sg_list)
4166 struct zfcp_fsf_req *fsf_req;
4167 struct fsf_qtcb_bottom_support *bottom;
4168 volatile struct qdio_buffer_element *sbale;
4169 unsigned long lock_flags;
4174 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4175 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4176 zfcp_get_busid_by_adapter(adapter));
4177 retval = -EOPNOTSUPP;
4181 switch (fsf_command) {
4183 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4184 direction = SBAL_FLAGS0_TYPE_WRITE;
4185 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4186 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4187 req_flags = ZFCP_WAIT_FOR_SBAL;
4190 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4191 direction = SBAL_FLAGS0_TYPE_READ;
4195 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4200 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4201 NULL, &lock_flags, &fsf_req);
4203 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4205 zfcp_get_busid_by_adapter(adapter));
4207 goto unlock_queue_lock;
4210 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4211 sbale[0].flags |= direction;
4213 bottom = &fsf_req->qtcb->bottom.support;
4214 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4215 bottom->option = option;
4217 if (sg_list->count > 0) {
4220 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4221 sg_list->sg, sg_list->count,
4222 ZFCP_MAX_SBALS_PER_REQ);
4223 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4225 "error: Could not create sufficient number of "
4226 "SBALS for an FSF request to the adapter %s\n",
4227 zfcp_get_busid_by_adapter(adapter));
4232 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4234 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4235 retval = zfcp_fsf_req_send(fsf_req);
4237 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4239 zfcp_get_busid_by_adapter(adapter));
4243 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4245 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4247 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4248 "download" : "upload",
4249 zfcp_get_busid_by_adapter(adapter));
4251 wait_event(fsf_req->completion_wq,
4252 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4254 *fsf_req_ptr = fsf_req;
4258 zfcp_fsf_req_free(fsf_req);
4260 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4267 * function: zfcp_fsf_control_file_handler
4269 * purpose: Handler of the control file upload/download FSF requests
4271 * returns: 0 - FSF request successfuly processed
4272 * -EAGAIN - Operation has to be repeated because of a temporary problem
4273 * -EACCES - There is no permission to execute an operation
4274 * -EPERM - The control file is not in a right format
4275 * -EIO - There is a problem with the FCP adapter
4276 * -EINVAL - Invalid operation
4277 * -EFAULT - User space memory I/O operation fault
4280 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4282 struct zfcp_adapter *adapter = fsf_req->adapter;
4283 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4284 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4287 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4289 goto skip_fsfstatus;
4292 switch (header->fsf_status) {
4296 "The FSF request has been successfully completed "
4297 "on the adapter %s\n",
4298 zfcp_get_busid_by_adapter(adapter));
4301 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4302 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4303 switch (header->fsf_status_qual.word[0]) {
4305 case FSF_SQ_CFDC_HARDENED_ON_SE:
4307 "CFDC on the adapter %s has being "
4308 "hardened on primary and secondary SE\n",
4309 zfcp_get_busid_by_adapter(adapter));
4312 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4314 "CFDC of the adapter %s could not "
4315 "be saved on the SE\n",
4316 zfcp_get_busid_by_adapter(adapter));
4319 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4321 "CFDC of the adapter %s could not "
4322 "be copied to the secondary SE\n",
4323 zfcp_get_busid_by_adapter(adapter));
4328 "CFDC could not be hardened "
4329 "on the adapter %s\n",
4330 zfcp_get_busid_by_adapter(adapter));
4333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4337 case FSF_AUTHORIZATION_FAILURE:
4339 "Adapter %s does not accept privileged commands\n",
4340 zfcp_get_busid_by_adapter(adapter));
4341 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4345 case FSF_CFDC_ERROR_DETECTED:
4347 "Error at position %d in the CFDC, "
4348 "CFDC is discarded by the adapter %s\n",
4349 header->fsf_status_qual.word[0],
4350 zfcp_get_busid_by_adapter(adapter));
4351 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4355 case FSF_CONTROL_FILE_UPDATE_ERROR:
4357 "Adapter %s cannot harden the control file, "
4358 "file is discarded\n",
4359 zfcp_get_busid_by_adapter(adapter));
4360 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4364 case FSF_CONTROL_FILE_TOO_LARGE:
4366 "Control file is too large, file is discarded "
4367 "by the adapter %s\n",
4368 zfcp_get_busid_by_adapter(adapter));
4369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4373 case FSF_ACCESS_CONFLICT_DETECTED:
4374 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4376 "CFDC has been discarded by the adapter %s, "
4377 "because activation would impact "
4378 "%d active connection(s)\n",
4379 zfcp_get_busid_by_adapter(adapter),
4380 header->fsf_status_qual.word[0]);
4381 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4385 case FSF_CONFLICTS_OVERRULED:
4386 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4388 "CFDC has been activated on the adapter %s, "
4389 "but activation has impacted "
4390 "%d active connection(s)\n",
4391 zfcp_get_busid_by_adapter(adapter),
4392 header->fsf_status_qual.word[0]);
4393 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4397 case FSF_UNKNOWN_OP_SUBTYPE:
4398 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4399 "op_subtype=0x%x)\n",
4400 zfcp_get_busid_by_adapter(adapter),
4401 bottom->operation_subtype);
4402 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4406 case FSF_INVALID_COMMAND_OPTION:
4408 "Invalid option 0x%x has been specified "
4409 "in QTCB bottom sent to the adapter %s\n",
4411 zfcp_get_busid_by_adapter(adapter));
4412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4418 "bug: An unknown/unexpected FSF status 0x%08x "
4419 "was presented on the adapter %s\n",
4421 zfcp_get_busid_by_adapter(adapter));
4422 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4432 zfcp_fsf_req_sbal_check(unsigned long *flags,
4433 struct zfcp_qdio_queue *queue, int needed)
4435 write_lock_irqsave(&queue->queue_lock, *flags);
4436 if (likely(atomic_read(&queue->free_count) >= needed))
4438 write_unlock_irqrestore(&queue->queue_lock, *flags);
4443 * set qtcb pointer in fsf_req and initialize QTCB
4446 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4448 if (likely(fsf_req->qtcb != NULL)) {
4449 fsf_req->qtcb->prefix.req_seq_no =
4450 fsf_req->adapter->fsf_req_seq_no;
4451 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4452 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4453 fsf_req->qtcb->prefix.qtcb_type =
4454 fsf_qtcb_type[fsf_req->fsf_command];
4455 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4456 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4457 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4462 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4463 * @adapter: adapter for which request queue is examined
4464 * @req_flags: flags indicating whether to wait for needed SBAL or not
4465 * @lock_flags: lock_flags if queue_lock is taken
4466 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4467 * Locks: lock adapter->request_queue->queue_lock on success
4470 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4471 unsigned long *lock_flags)
4474 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4476 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4477 ret = wait_event_interruptible_timeout(adapter->request_wq,
4478 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4484 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4491 * function: zfcp_fsf_req_create
4493 * purpose: create an FSF request at the specified adapter and
4494 * setup common fields
4496 * returns: -ENOMEM if there was insufficient memory for a request
4497 * -EIO if no qdio buffers could be allocate to the request
4498 * -EINVAL/-EPERM on bug conditions in req_dequeue
4501 * note: The created request is returned by reference.
4503 * locks: lock of concerned request queue must not be held,
4504 * but is held on completion (write, irqsave)
4507 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4508 mempool_t *pool, unsigned long *lock_flags,
4509 struct zfcp_fsf_req **fsf_req_p)
4511 volatile struct qdio_buffer_element *sbale;
4512 struct zfcp_fsf_req *fsf_req = NULL;
4514 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4516 /* allocate new FSF request */
4517 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4518 if (unlikely(NULL == fsf_req)) {
4519 ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
4520 "the outbound (send) queue.\n");
4522 goto failed_fsf_req;
4525 fsf_req->adapter = adapter;
4526 fsf_req->fsf_command = fsf_cmd;
4527 INIT_LIST_HEAD(&fsf_req->list);
4528 init_timer(&fsf_req->timer);
4530 /* initialize waitqueue which may be used to wait on
4531 this request completion */
4532 init_waitqueue_head(&fsf_req->completion_wq);
4534 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4538 /* this is serialized (we are holding req_queue-lock of adapter) */
4539 if (adapter->req_no == 0)
4541 fsf_req->req_id = adapter->req_no++;
4543 zfcp_fsf_req_qtcb_init(fsf_req);
4546 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4547 * if it is not set (see also *_open_qdio and *_close_qdio).
4550 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4551 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4556 if (fsf_req->qtcb) {
4557 fsf_req->seq_no = adapter->fsf_req_seq_no;
4558 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4560 fsf_req->sbal_number = 1;
4561 fsf_req->sbal_first = req_queue->free_index;
4562 fsf_req->sbal_curr = req_queue->free_index;
4563 fsf_req->sbale_curr = 1;
4565 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4566 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4569 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4571 /* setup common SBALE fields */
4572 sbale[0].addr = (void *) fsf_req->req_id;
4573 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4574 if (likely(fsf_req->qtcb != NULL)) {
4575 sbale[1].addr = (void *) fsf_req->qtcb;
4576 sbale[1].length = sizeof(struct fsf_qtcb);
4579 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4580 fsf_req->sbal_number, fsf_req->sbal_first);
4585 /* dequeue new FSF request previously enqueued */
4586 zfcp_fsf_req_free(fsf_req);
4590 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4592 *fsf_req_p = fsf_req;
4597 * function: zfcp_fsf_req_send
4599 * purpose: start transfer of FSF request via QDIO
4601 * returns: 0 - request transfer succesfully started
4602 * !0 - start of request transfer failed
4604 static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
4606 struct zfcp_adapter *adapter;
4607 struct zfcp_qdio_queue *req_queue;
4608 volatile struct qdio_buffer_element *sbale;
4610 int new_distance_from_int;
4613 adapter = fsf_req->adapter;
4614 req_queue = &adapter->request_queue,
4617 /* FIXME(debug): remove it later */
4618 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4619 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4620 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4621 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4624 /* put allocated FSF request into hash table */
4625 spin_lock(&adapter->req_list_lock);
4626 zfcp_reqlist_add(adapter, fsf_req);
4627 spin_unlock(&adapter->req_list_lock);
4629 inc_seq_no = (fsf_req->qtcb != NULL);
4631 ZFCP_LOG_TRACE("request queue of adapter %s: "
4632 "next free SBAL is %i, %i free SBALs\n",
4633 zfcp_get_busid_by_adapter(adapter),
4634 req_queue->free_index,
4635 atomic_read(&req_queue->free_count));
4637 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4638 "index_in_queue=%i, count=%i, buffers=%p\n",
4639 zfcp_get_busid_by_adapter(adapter),
4640 QDIO_FLAG_SYNC_OUTPUT,
4641 0, fsf_req->sbal_first, fsf_req->sbal_number,
4642 &req_queue->buffer[fsf_req->sbal_first]);
4645 * adjust the number of free SBALs in request queue as well as
4646 * position of first one
4648 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4649 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4650 req_queue->free_index += fsf_req->sbal_number; /* increase */
4651 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4652 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4654 fsf_req->issued = get_clock();
4656 retval = do_QDIO(adapter->ccw_device,
4657 QDIO_FLAG_SYNC_OUTPUT,
4658 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4660 if (unlikely(retval)) {
4661 /* Queues are down..... */
4663 del_timer(&fsf_req->timer);
4664 spin_lock(&adapter->req_list_lock);
4665 zfcp_reqlist_remove(adapter, fsf_req);
4666 spin_unlock(&adapter->req_list_lock);
4667 /* undo changes in request queue made for this request */
4668 zfcp_qdio_zero_sbals(req_queue->buffer,
4669 fsf_req->sbal_first, fsf_req->sbal_number);
4670 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4671 req_queue->free_index -= fsf_req->sbal_number;
4672 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4673 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4674 zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
4676 req_queue->distance_from_int = new_distance_from_int;
4678 * increase FSF sequence counter -
4679 * this must only be done for request successfully enqueued to
4680 * QDIO this rejected requests may be cleaned up by calling
4681 * routines resulting in missing sequence counter values
4685 /* Don't increase for unsolicited status */
4687 adapter->fsf_req_seq_no++;
4689 /* count FSF requests pending */
4690 atomic_inc(&adapter->reqs_active);
4695 #undef ZFCP_LOG_AREA