2 * This file is part of the zfcp device driver for
3 * FCP adapters for IBM System z9 and zSeries.
5 * (C) Copyright IBM Corp. 2002, 2006
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
25 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
26 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
27 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
28 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
29 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
30 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
31 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
32 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
33 static int zfcp_fsf_send_fcp_command_task_management_handler(
34 struct zfcp_fsf_req *);
35 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
36 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
37 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
38 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
40 static inline int zfcp_fsf_req_sbal_check(
41 unsigned long *, struct zfcp_qdio_queue *, int);
42 static inline int zfcp_use_one_sbal(
43 struct scatterlist *, int, struct scatterlist *, int);
44 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
45 static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
46 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
47 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
48 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
49 static void zfcp_fsf_link_down_info_eval(struct zfcp_adapter *,
50 struct fsf_link_down_info *);
51 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
53 /* association between FSF command and FSF QTCB type */
54 static u32 fsf_qtcb_type[] = {
55 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
56 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
57 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
58 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
59 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
60 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
61 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
62 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
63 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
64 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
65 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
66 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
67 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
70 static const char zfcp_act_subtable_type[5][8] = {
71 "unknown", "OS", "WWPN", "DID", "LUN"
74 /****************************************************************/
75 /*************** FSF related Functions *************************/
76 /****************************************************************/
78 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
81 * function: zfcp_fsf_req_alloc
83 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
84 * unsolicited requests) via helper functions
85 * Does some initial fsf request set-up.
87 * returns: pointer to allocated fsf_req if successfull
93 static struct zfcp_fsf_req *
94 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
98 struct zfcp_fsf_req *fsf_req = NULL;
100 if (req_flags & ZFCP_REQ_NO_QTCB)
101 size = sizeof(struct zfcp_fsf_req);
103 size = sizeof(struct zfcp_fsf_req_qtcb);
106 ptr = mempool_alloc(pool, GFP_ATOMIC);
108 if (req_flags & ZFCP_REQ_NO_QTCB)
109 ptr = kmalloc(size, GFP_ATOMIC);
111 ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
118 memset(ptr, 0, size);
120 if (req_flags & ZFCP_REQ_NO_QTCB) {
121 fsf_req = (struct zfcp_fsf_req *) ptr;
123 fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
124 fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
127 fsf_req->pool = pool;
134 * function: zfcp_fsf_req_free
136 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
137 * returns it into the pool via helper functions.
144 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
146 if (likely(fsf_req->pool)) {
147 mempool_free(fsf_req, fsf_req->pool);
152 kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
160 * 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 /* log additional information provided by FSF (if any) */
288 if (likely(qtcb->header.log_length)) {
289 /* do not trust them ;-) */
290 if (unlikely(qtcb->header.log_start >
291 sizeof(struct fsf_qtcb))) {
293 ("bug: ULP (FSF logging) log data starts "
294 "beyond end of packet header. Ignored. "
295 "(start=%i, size=%li)\n",
296 qtcb->header.log_start,
297 sizeof(struct fsf_qtcb));
300 if (unlikely((size_t) (qtcb->header.log_start +
301 qtcb->header.log_length) >
302 sizeof(struct fsf_qtcb))) {
303 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
304 "beyond end of packet header. Ignored. "
305 "(start=%i, length=%i, size=%li)\n",
306 qtcb->header.log_start,
307 qtcb->header.log_length,
308 sizeof(struct fsf_qtcb));
311 ZFCP_LOG_TRACE("ULP log data: \n");
312 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
313 (char *) qtcb + qtcb->header.log_start,
314 qtcb->header.log_length);
318 /* evaluate FSF Protocol Status */
319 switch (qtcb->prefix.prot_status) {
322 case FSF_PROT_FSF_STATUS_PRESENTED:
325 case FSF_PROT_QTCB_VERSION_ERROR:
326 ZFCP_LOG_NORMAL("error: The adapter %s contains "
327 "microcode of version 0x%x, the device driver "
328 "only supports 0x%x. Aborting.\n",
329 zfcp_get_busid_by_adapter(adapter),
330 prot_status_qual->version_error.fsf_version,
332 zfcp_erp_adapter_shutdown(adapter, 0);
333 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
336 case FSF_PROT_SEQ_NUMB_ERROR:
337 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
338 "driver (0x%x) and adapter %s (0x%x). "
339 "Restarting all operations on this adapter.\n",
340 qtcb->prefix.req_seq_no,
341 zfcp_get_busid_by_adapter(adapter),
342 prot_status_qual->sequence_error.exp_req_seq_no);
343 zfcp_erp_adapter_reopen(adapter, 0);
344 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
345 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
348 case FSF_PROT_UNSUPP_QTCB_TYPE:
349 ZFCP_LOG_NORMAL("error: Packet header type used by the "
350 "device driver is incompatible with "
351 "that used on adapter %s. "
352 "Stopping all operations on this adapter.\n",
353 zfcp_get_busid_by_adapter(adapter));
354 zfcp_erp_adapter_shutdown(adapter, 0);
355 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
358 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
359 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
360 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
364 case FSF_PROT_DUPLICATE_REQUEST_ID:
365 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
366 "to the adapter %s is ambiguous. "
367 "Stopping all operations on this adapter.\n",
368 *(unsigned long long*)
369 (&qtcb->bottom.support.req_handle),
370 zfcp_get_busid_by_adapter(adapter));
371 zfcp_erp_adapter_shutdown(adapter, 0);
372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
375 case FSF_PROT_LINK_DOWN:
376 zfcp_fsf_link_down_info_eval(adapter,
377 &prot_status_qual->link_down_info);
378 zfcp_erp_adapter_reopen(adapter, 0);
379 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
382 case FSF_PROT_REEST_QUEUE:
383 ZFCP_LOG_NORMAL("The local link to adapter with "
384 "%s was re-plugged. "
385 "Re-starting operations on this adapter.\n",
386 zfcp_get_busid_by_adapter(adapter));
387 /* All ports should be marked as ready to run again */
388 zfcp_erp_modify_adapter_status(adapter,
389 ZFCP_STATUS_COMMON_RUNNING,
391 zfcp_erp_adapter_reopen(adapter,
392 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
393 | ZFCP_STATUS_COMMON_ERP_FAILED);
394 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
397 case FSF_PROT_ERROR_STATE:
398 ZFCP_LOG_NORMAL("error: The adapter %s "
399 "has entered the error state. "
400 "Restarting all operations on this "
402 zfcp_get_busid_by_adapter(adapter));
403 zfcp_erp_adapter_reopen(adapter, 0);
404 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
405 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
409 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
410 "provided by the adapter %s "
411 "is not compatible with the device driver. "
412 "Stopping all operations on this adapter. "
413 "(debug info 0x%x).\n",
414 zfcp_get_busid_by_adapter(adapter),
415 qtcb->prefix.prot_status);
416 zfcp_erp_adapter_shutdown(adapter, 0);
417 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
422 * always call specific handlers to give them a chance to do
423 * something meaningful even in error cases
425 zfcp_fsf_fsfstatus_eval(fsf_req);
430 * function: zfcp_fsf_fsfstatus_eval
432 * purpose: evaluates FSF status of completed FSF request
433 * and acts accordingly
438 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
442 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
446 /* evaluate FSF Status */
447 switch (fsf_req->qtcb->header.fsf_status) {
448 case FSF_UNKNOWN_COMMAND:
449 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
450 "not known by the adapter %s "
451 "Stopping all operations on this adapter. "
452 "(debug info 0x%x).\n",
453 zfcp_get_busid_by_adapter(fsf_req->adapter),
454 fsf_req->qtcb->header.fsf_command);
455 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
459 case FSF_FCP_RSP_AVAILABLE:
460 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
464 case FSF_ADAPTER_STATUS_AVAILABLE:
465 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
471 * always call specific handlers to give them a chance to do
472 * something meaningful even in error cases
474 zfcp_fsf_req_dispatch(fsf_req);
480 * function: zfcp_fsf_fsfstatus_qual_eval
482 * purpose: evaluates FSF status-qualifier of completed FSF request
483 * and acts accordingly
488 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
492 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
493 case FSF_SQ_FCP_RSP_AVAILABLE:
495 case FSF_SQ_RETRY_IF_POSSIBLE:
496 /* The SCSI-stack may now issue retries or escalate */
497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
499 case FSF_SQ_COMMAND_ABORTED:
500 /* Carry the aborted state on to upper layer */
501 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
504 case FSF_SQ_NO_RECOM:
505 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
506 "problem on the adapter %s "
507 "Stopping all operations on this adapter. ",
508 zfcp_get_busid_by_adapter(fsf_req->adapter));
509 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
510 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
512 case FSF_SQ_ULP_PROGRAMMING_ERROR:
513 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
515 zfcp_get_busid_by_adapter(fsf_req->adapter));
516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
518 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
519 case FSF_SQ_NO_RETRY_POSSIBLE:
520 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
521 /* dealt with in the respective functions */
524 ZFCP_LOG_NORMAL("bug: Additional status info could "
525 "not be interpreted properly.\n");
526 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
527 (char *) &fsf_req->qtcb->header.fsf_status_qual,
528 sizeof (union fsf_status_qual));
529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
537 * zfcp_fsf_link_down_info_eval - evaluate link down information block
540 zfcp_fsf_link_down_info_eval(struct zfcp_adapter *adapter,
541 struct fsf_link_down_info *link_down)
543 if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
547 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
549 if (link_down == NULL)
552 switch (link_down->error_code) {
553 case FSF_PSQ_LINK_NO_LIGHT:
554 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
555 "(no light detected)\n",
556 zfcp_get_busid_by_adapter(adapter));
558 case FSF_PSQ_LINK_WRAP_PLUG:
559 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
560 "(wrap plug detected)\n",
561 zfcp_get_busid_by_adapter(adapter));
563 case FSF_PSQ_LINK_NO_FCP:
564 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
565 "(adjacent node on link does not support FCP)\n",
566 zfcp_get_busid_by_adapter(adapter));
568 case FSF_PSQ_LINK_FIRMWARE_UPDATE:
569 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
570 "(firmware update in progress)\n",
571 zfcp_get_busid_by_adapter(adapter));
573 case FSF_PSQ_LINK_INVALID_WWPN:
574 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
575 "(duplicate or invalid WWPN detected)\n",
576 zfcp_get_busid_by_adapter(adapter));
578 case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
579 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
580 "(no support for NPIV by Fabric)\n",
581 zfcp_get_busid_by_adapter(adapter));
583 case FSF_PSQ_LINK_NO_FCP_RESOURCES:
584 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
585 "(out of resource in FCP daughtercard)\n",
586 zfcp_get_busid_by_adapter(adapter));
588 case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
589 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
590 "(out of resource in Fabric)\n",
591 zfcp_get_busid_by_adapter(adapter));
593 case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
594 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
595 "(unable to Fabric login)\n",
596 zfcp_get_busid_by_adapter(adapter));
598 case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
599 ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
600 zfcp_get_busid_by_adapter(adapter));
602 case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
603 ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
604 zfcp_get_busid_by_adapter(adapter));
606 case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
607 ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
608 zfcp_get_busid_by_adapter(adapter));
611 ZFCP_LOG_NORMAL("The local link to adapter %s is down "
612 "(warning: unknown reason code %d)\n",
613 zfcp_get_busid_by_adapter(adapter),
614 link_down->error_code);
617 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
618 ZFCP_LOG_DEBUG("Debug information to link down: "
619 "primary_status=0x%02x "
621 "action_code=0x%02x "
622 "reason_code=0x%02x "
623 "explanation_code=0x%02x "
624 "vendor_specific_code=0x%02x\n",
625 link_down->primary_status,
626 link_down->ioerr_code,
627 link_down->action_code,
628 link_down->reason_code,
629 link_down->explanation_code,
630 link_down->vendor_specific_code);
633 zfcp_erp_adapter_failed(adapter);
637 * function: zfcp_fsf_req_dispatch
639 * purpose: calls the appropriate command specific handler
644 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
646 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
647 struct zfcp_adapter *adapter = fsf_req->adapter;
651 switch (fsf_req->fsf_command) {
653 case FSF_QTCB_FCP_CMND:
654 zfcp_fsf_send_fcp_command_handler(fsf_req);
657 case FSF_QTCB_ABORT_FCP_CMND:
658 zfcp_fsf_abort_fcp_command_handler(fsf_req);
661 case FSF_QTCB_SEND_GENERIC:
662 zfcp_fsf_send_ct_handler(fsf_req);
665 case FSF_QTCB_OPEN_PORT_WITH_DID:
666 zfcp_fsf_open_port_handler(fsf_req);
669 case FSF_QTCB_OPEN_LUN:
670 zfcp_fsf_open_unit_handler(fsf_req);
673 case FSF_QTCB_CLOSE_LUN:
674 zfcp_fsf_close_unit_handler(fsf_req);
677 case FSF_QTCB_CLOSE_PORT:
678 zfcp_fsf_close_port_handler(fsf_req);
681 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
682 zfcp_fsf_close_physical_port_handler(fsf_req);
685 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
686 zfcp_fsf_exchange_config_data_handler(fsf_req);
689 case FSF_QTCB_EXCHANGE_PORT_DATA:
690 zfcp_fsf_exchange_port_data_handler(fsf_req);
693 case FSF_QTCB_SEND_ELS:
694 zfcp_fsf_send_els_handler(fsf_req);
697 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
698 zfcp_fsf_control_file_handler(fsf_req);
701 case FSF_QTCB_UPLOAD_CONTROL_FILE:
702 zfcp_fsf_control_file_handler(fsf_req);
706 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
707 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
708 "not supported by the adapter %s\n",
709 zfcp_get_busid_by_adapter(adapter));
710 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
712 ("bug: Command issued by the device driver differs "
713 "from the command returned by the adapter %s "
714 "(debug info 0x%x, 0x%x).\n",
715 zfcp_get_busid_by_adapter(adapter),
716 fsf_req->fsf_command,
717 fsf_req->qtcb->header.fsf_command);
723 zfcp_erp_async_handler(erp_action, 0);
729 * function: zfcp_fsf_status_read
731 * purpose: initiates a Status Read command at the specified adapter
736 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
738 struct zfcp_fsf_req *fsf_req;
739 struct fsf_status_read_buffer *status_buffer;
740 unsigned long lock_flags;
741 volatile struct qdio_buffer_element *sbale;
744 /* setup new FSF request */
745 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
746 req_flags | ZFCP_REQ_NO_QTCB,
747 adapter->pool.fsf_req_status_read,
748 &lock_flags, &fsf_req);
750 ZFCP_LOG_INFO("error: Could not create unsolicited status "
751 "buffer for adapter %s.\n",
752 zfcp_get_busid_by_adapter(adapter));
753 goto failed_req_create;
756 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
757 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
758 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
759 fsf_req->sbale_curr = 2;
762 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
763 if (!status_buffer) {
764 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
767 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
768 fsf_req->data = (unsigned long) status_buffer;
770 /* insert pointer to respective buffer */
771 sbale = zfcp_qdio_sbale_curr(fsf_req);
772 sbale->addr = (void *) status_buffer;
773 sbale->length = sizeof(struct fsf_status_read_buffer);
775 retval = zfcp_fsf_req_send(fsf_req);
777 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
779 goto failed_req_send;
782 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
783 zfcp_get_busid_by_adapter(adapter));
787 mempool_free(status_buffer, adapter->pool.data_status_read);
790 zfcp_fsf_req_free(fsf_req);
792 zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
794 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
799 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
801 struct fsf_status_read_buffer *status_buffer;
802 struct zfcp_adapter *adapter;
803 struct zfcp_port *port;
806 status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
807 adapter = fsf_req->adapter;
809 read_lock_irqsave(&zfcp_data.config_lock, flags);
810 list_for_each_entry(port, &adapter->port_list_head, list)
811 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
813 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
815 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
816 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
817 "nonexisting port with d_id 0x%06x on "
818 "adapter %s. Ignored.\n",
819 status_buffer->d_id & ZFCP_DID_MASK,
820 zfcp_get_busid_by_adapter(adapter));
824 switch (status_buffer->status_subtype) {
826 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
827 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
828 zfcp_erp_port_reopen(port, 0);
831 case FSF_STATUS_READ_SUB_ERROR_PORT:
832 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
833 zfcp_erp_port_shutdown(port, 0);
837 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
838 debug_exception(adapter->erp_dbf, 0,
839 &status_buffer->status_subtype, sizeof (u32));
840 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
841 "for a reopen indication on port with "
842 "d_id 0x%06x on the adapter %s. "
843 "Ignored. (debug info 0x%x)\n",
845 zfcp_get_busid_by_adapter(adapter),
846 status_buffer->status_subtype);
853 * function: zfcp_fsf_status_read_handler
855 * purpose: is called for finished Open Port command
860 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
863 struct zfcp_adapter *adapter = fsf_req->adapter;
864 struct fsf_status_read_buffer *status_buffer =
865 (struct fsf_status_read_buffer *) fsf_req->data;
866 struct fsf_bit_error_payload *fsf_bit_error;
868 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
869 zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
870 mempool_free(status_buffer, adapter->pool.data_status_read);
871 zfcp_fsf_req_free(fsf_req);
875 zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
877 switch (status_buffer->status_type) {
879 case FSF_STATUS_READ_PORT_CLOSED:
880 zfcp_fsf_status_read_port_closed(fsf_req);
883 case FSF_STATUS_READ_INCOMING_ELS:
884 zfcp_fsf_incoming_els(fsf_req);
887 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
888 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
889 zfcp_get_busid_by_adapter(adapter));
892 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
893 fsf_bit_error = (struct fsf_bit_error_payload *)
894 status_buffer->payload;
895 ZFCP_LOG_NORMAL("Warning: bit error threshold data "
896 "received (adapter %s, "
897 "link failures = %i, loss of sync errors = %i, "
898 "loss of signal errors = %i, "
899 "primitive sequence errors = %i, "
900 "invalid transmission word errors = %i, "
901 "CRC errors = %i)\n",
902 zfcp_get_busid_by_adapter(adapter),
903 fsf_bit_error->link_failure_error_count,
904 fsf_bit_error->loss_of_sync_error_count,
905 fsf_bit_error->loss_of_signal_error_count,
906 fsf_bit_error->primitive_sequence_error_count,
907 fsf_bit_error->invalid_transmission_word_error_count,
908 fsf_bit_error->crc_error_count);
909 ZFCP_LOG_INFO("Additional bit error threshold data "
911 "primitive sequence event time-outs = %i, "
912 "elastic buffer overrun errors = %i, "
913 "advertised receive buffer-to-buffer credit = %i, "
914 "current receice buffer-to-buffer credit = %i, "
915 "advertised transmit buffer-to-buffer credit = %i, "
916 "current transmit buffer-to-buffer credit = %i)\n",
917 zfcp_get_busid_by_adapter(adapter),
918 fsf_bit_error->primitive_sequence_event_timeout_count,
919 fsf_bit_error->elastic_buffer_overrun_error_count,
920 fsf_bit_error->advertised_receive_b2b_credit,
921 fsf_bit_error->current_receive_b2b_credit,
922 fsf_bit_error->advertised_transmit_b2b_credit,
923 fsf_bit_error->current_transmit_b2b_credit);
926 case FSF_STATUS_READ_LINK_DOWN:
927 switch (status_buffer->status_subtype) {
928 case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
929 ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
930 zfcp_get_busid_by_adapter(adapter));
931 zfcp_fsf_link_down_info_eval(adapter,
932 (struct fsf_link_down_info *)
933 &status_buffer->payload);
935 case FSF_STATUS_READ_SUB_FDISC_FAILED:
936 ZFCP_LOG_INFO("Local link to adapter %s is down "
937 "due to failed FDISC login\n",
938 zfcp_get_busid_by_adapter(adapter));
939 zfcp_fsf_link_down_info_eval(adapter,
940 (struct fsf_link_down_info *)
941 &status_buffer->payload);
943 case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
944 ZFCP_LOG_INFO("Local link to adapter %s is down "
945 "due to firmware update on adapter\n",
946 zfcp_get_busid_by_adapter(adapter));
947 zfcp_fsf_link_down_info_eval(adapter, NULL);
950 ZFCP_LOG_INFO("Local link to adapter %s is down "
951 "due to unknown reason\n",
952 zfcp_get_busid_by_adapter(adapter));
953 zfcp_fsf_link_down_info_eval(adapter, NULL);
957 case FSF_STATUS_READ_LINK_UP:
958 ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
959 "Restarting operations on this adapter\n",
960 zfcp_get_busid_by_adapter(adapter));
961 /* All ports should be marked as ready to run again */
962 zfcp_erp_modify_adapter_status(adapter,
963 ZFCP_STATUS_COMMON_RUNNING,
965 zfcp_erp_adapter_reopen(adapter,
966 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
967 | ZFCP_STATUS_COMMON_ERP_FAILED);
970 case FSF_STATUS_READ_NOTIFICATION_LOST:
971 ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
972 "adapter %s%s%s%s%s%s%s%s%s\n",
973 zfcp_get_busid_by_adapter(adapter),
974 (status_buffer->status_subtype &
975 FSF_STATUS_READ_SUB_INCOMING_ELS) ?
976 ", incoming ELS" : "",
977 (status_buffer->status_subtype &
978 FSF_STATUS_READ_SUB_SENSE_DATA) ?
980 (status_buffer->status_subtype &
981 FSF_STATUS_READ_SUB_LINK_STATUS) ?
982 ", link status change" : "",
983 (status_buffer->status_subtype &
984 FSF_STATUS_READ_SUB_PORT_CLOSED) ?
986 (status_buffer->status_subtype &
987 FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
988 ", bit error exception" : "",
989 (status_buffer->status_subtype &
990 FSF_STATUS_READ_SUB_ACT_UPDATED) ?
992 (status_buffer->status_subtype &
993 FSF_STATUS_READ_SUB_ACT_HARDENED) ?
994 ", ACT hardening" : "",
995 (status_buffer->status_subtype &
996 FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
997 ", adapter feature change" : "");
999 if (status_buffer->status_subtype &
1000 FSF_STATUS_READ_SUB_ACT_UPDATED)
1001 zfcp_erp_adapter_access_changed(adapter);
1004 case FSF_STATUS_READ_CFDC_UPDATED:
1005 ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
1006 zfcp_get_busid_by_adapter(adapter));
1007 zfcp_erp_adapter_access_changed(adapter);
1010 case FSF_STATUS_READ_CFDC_HARDENED:
1011 switch (status_buffer->status_subtype) {
1012 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1013 ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
1014 zfcp_get_busid_by_adapter(adapter));
1016 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1017 ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
1018 "to the secondary SE\n",
1019 zfcp_get_busid_by_adapter(adapter));
1022 ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
1023 zfcp_get_busid_by_adapter(adapter));
1027 case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
1028 debug_text_event(adapter->erp_dbf, 2, "unsol_features:");
1029 ZFCP_LOG_INFO("List of supported features on adapter %s has "
1030 "been changed from 0x%08X to 0x%08X\n",
1031 zfcp_get_busid_by_adapter(adapter),
1032 *(u32*) (status_buffer->payload + 4),
1033 *(u32*) (status_buffer->payload));
1034 adapter->adapter_features = *(u32*) status_buffer->payload;
1038 ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
1039 "type was received (debug info 0x%x)\n",
1040 status_buffer->status_type);
1041 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1043 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1044 (char *) status_buffer,
1045 sizeof (struct fsf_status_read_buffer));
1048 mempool_free(status_buffer, adapter->pool.data_status_read);
1049 zfcp_fsf_req_free(fsf_req);
1051 * recycle buffer and start new request repeat until outbound
1052 * queue is empty or adapter shutdown is requested
1056 * we may wait in the req_create for 5s during shutdown, so
1057 * qdio_cleanup will have to wait at least that long before returning
1058 * with failure to allow us a proper cleanup under all circumstances
1062 * allocation failure possible? (Is this code needed?)
1064 retval = zfcp_fsf_status_read(adapter, 0);
1066 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1067 "request for the adapter %s.\n",
1068 zfcp_get_busid_by_adapter(adapter));
1069 /* temporary fix to avoid status read buffer shortage */
1070 adapter->status_read_failed++;
1071 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1072 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1073 ZFCP_LOG_INFO("restart adapter %s due to status read "
1074 "buffer shortage\n",
1075 zfcp_get_busid_by_adapter(adapter));
1076 zfcp_erp_adapter_reopen(adapter, 0);
1084 * function: zfcp_fsf_abort_fcp_command
1086 * purpose: tells FSF to abort a running SCSI command
1088 * returns: address of initiated FSF request
1089 * NULL - request could not be initiated
1091 * FIXME(design): should be watched by a timeout !!!
1092 * FIXME(design) shouldn't this be modified to return an int
1093 * also...don't know how though
1095 struct zfcp_fsf_req *
1096 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1097 struct zfcp_adapter *adapter,
1098 struct zfcp_unit *unit, int req_flags)
1100 volatile struct qdio_buffer_element *sbale;
1101 struct zfcp_fsf_req *fsf_req = NULL;
1102 unsigned long lock_flags;
1105 /* setup new FSF request */
1106 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1107 req_flags, adapter->pool.fsf_req_abort,
1108 &lock_flags, &fsf_req);
1110 ZFCP_LOG_INFO("error: Failed to create an abort command "
1111 "request for lun 0x%016Lx on port 0x%016Lx "
1115 zfcp_get_busid_by_adapter(adapter));
1119 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1120 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1121 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1123 fsf_req->data = (unsigned long) unit;
1125 /* set handles of unit and its parent port in QTCB */
1126 fsf_req->qtcb->header.lun_handle = unit->handle;
1127 fsf_req->qtcb->header.port_handle = unit->port->handle;
1129 /* set handle of request which should be aborted */
1130 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1132 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
1133 retval = zfcp_fsf_req_send(fsf_req);
1135 ZFCP_LOG_INFO("error: Failed to send abort command request "
1136 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1137 zfcp_get_busid_by_adapter(adapter),
1138 unit->port->wwpn, unit->fcp_lun);
1139 zfcp_fsf_req_free(fsf_req);
1144 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1145 "(adapter%s, port d_id=0x%06x, "
1146 "unit x%016Lx, old_req_id=0x%lx)\n",
1147 zfcp_get_busid_by_adapter(adapter),
1149 unit->fcp_lun, old_req_id);
1151 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1156 * function: zfcp_fsf_abort_fcp_command_handler
1158 * purpose: is called for finished Abort FCP Command request
1163 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1165 int retval = -EINVAL;
1166 struct zfcp_unit *unit;
1167 unsigned char status_qual =
1168 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1170 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1171 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1172 goto skip_fsfstatus;
1175 unit = (struct zfcp_unit *) new_fsf_req->data;
1177 /* evaluate FSF status in QTCB */
1178 switch (new_fsf_req->qtcb->header.fsf_status) {
1180 case FSF_PORT_HANDLE_NOT_VALID:
1181 if (status_qual >> 4 != status_qual % 0xf) {
1182 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1185 * In this case a command that was sent prior to a port
1186 * reopen was aborted (handles are different). This is
1190 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1191 "port 0x%016Lx on adapter %s invalid. "
1192 "This may happen occasionally.\n",
1195 zfcp_get_busid_by_unit(unit));
1196 ZFCP_LOG_INFO("status qualifier:\n");
1197 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1198 (char *) &new_fsf_req->qtcb->header.
1200 sizeof (union fsf_status_qual));
1201 /* Let's hope this sorts out the mess */
1202 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1204 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1205 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1209 case FSF_LUN_HANDLE_NOT_VALID:
1210 if (status_qual >> 4 != status_qual % 0xf) {
1212 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1215 * In this case a command that was sent prior to a unit
1216 * reopen was aborted (handles are different).
1221 ("Warning: Temporary LUN identifier 0x%x of LUN "
1222 "0x%016Lx on port 0x%016Lx on adapter %s is "
1223 "invalid. This may happen in rare cases. "
1224 "Trying to re-establish link.\n",
1228 zfcp_get_busid_by_unit(unit));
1229 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1230 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1231 (char *) &new_fsf_req->qtcb->header.
1233 sizeof (union fsf_status_qual));
1234 /* Let's hope this sorts out the mess */
1235 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1237 zfcp_erp_port_reopen(unit->port, 0);
1238 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1242 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1244 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1246 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1249 case FSF_PORT_BOXED:
1250 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1251 "be reopened\n", unit->port->wwpn,
1252 zfcp_get_busid_by_unit(unit));
1253 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1255 zfcp_erp_port_boxed(unit->port);
1256 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1257 | ZFCP_STATUS_FSFREQ_RETRY;
1262 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1264 unit->fcp_lun, unit->port->wwpn,
1265 zfcp_get_busid_by_unit(unit));
1266 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1267 zfcp_erp_unit_boxed(unit);
1268 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1269 | ZFCP_STATUS_FSFREQ_RETRY;
1272 case FSF_ADAPTER_STATUS_AVAILABLE:
1273 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1274 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1275 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1277 zfcp_test_link(unit->port);
1278 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1280 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1281 /* SCSI stack will escalate */
1282 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1284 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1288 ("bug: Wrong status qualifier 0x%x arrived.\n",
1289 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1290 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1292 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1293 &new_fsf_req->qtcb->header.
1294 fsf_status_qual.word[0], sizeof (u32));
1301 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1305 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1306 "(debug info 0x%x)\n",
1307 new_fsf_req->qtcb->header.fsf_status);
1308 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1310 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1311 &new_fsf_req->qtcb->header.fsf_status,
1320 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1322 * Two scatter-gather lists are passed, one for the reqeust and one for the
1326 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1327 struct scatterlist *resp, int resp_count)
1329 return ((req_count == 1) &&
1330 (resp_count == 1) &&
1331 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1333 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1334 req[0].length - 1) & PAGE_MASK)) &&
1335 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1337 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1338 resp[0].length - 1) & PAGE_MASK)));
1342 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1343 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1345 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1346 * a struct zfcp_fsf_req
1347 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1348 * is sent within error recovery
1351 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1352 struct zfcp_erp_action *erp_action)
1354 volatile struct qdio_buffer_element *sbale;
1355 struct zfcp_port *port;
1356 struct zfcp_adapter *adapter;
1357 struct zfcp_fsf_req *fsf_req;
1358 unsigned long lock_flags;
1363 adapter = port->adapter;
1365 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1366 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1367 pool, &lock_flags, &fsf_req);
1369 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1371 zfcp_get_busid_by_adapter(adapter));
1375 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1376 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1377 ct->resp, ct->resp_count)){
1378 /* both request buffer and response buffer
1379 fit into one sbale each */
1380 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1381 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1382 sbale[2].length = ct->req[0].length;
1383 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1384 sbale[3].length = ct->resp[0].length;
1385 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1386 } else if (adapter->adapter_features &
1387 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1388 /* try to use chained SBALs */
1389 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1390 SBAL_FLAGS0_TYPE_WRITE_READ,
1391 ct->req, ct->req_count,
1392 ZFCP_MAX_SBALS_PER_CT_REQ);
1394 ZFCP_LOG_INFO("error: creation of CT request failed "
1396 zfcp_get_busid_by_adapter(adapter));
1404 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1405 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1406 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1407 SBAL_FLAGS0_TYPE_WRITE_READ,
1408 ct->resp, ct->resp_count,
1409 ZFCP_MAX_SBALS_PER_CT_REQ);
1411 ZFCP_LOG_INFO("error: creation of CT request failed "
1413 zfcp_get_busid_by_adapter(adapter));
1421 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1423 /* reject send generic request */
1425 "error: microcode does not support chained SBALs,"
1426 "CT request too big (adapter %s)\n",
1427 zfcp_get_busid_by_adapter(adapter));
1432 /* settings in QTCB */
1433 fsf_req->qtcb->header.port_handle = port->handle;
1434 fsf_req->qtcb->bottom.support.service_class =
1435 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1436 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1437 fsf_req->data = (unsigned long) ct;
1439 zfcp_san_dbf_event_ct_request(fsf_req);
1442 erp_action->fsf_req = fsf_req;
1443 fsf_req->erp_action = erp_action;
1444 zfcp_erp_start_timer(fsf_req);
1446 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1448 ret = zfcp_fsf_req_send(fsf_req);
1450 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1451 "(adapter %s, port 0x%016Lx)\n",
1452 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1456 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1457 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1461 zfcp_fsf_req_free(fsf_req);
1462 if (erp_action != NULL) {
1463 erp_action->fsf_req = NULL;
1467 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1473 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1474 * @fsf_req: pointer to struct zfcp_fsf_req
1476 * Data specific for the Generic Service request is passed using
1477 * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
1478 * Usually a specific handler for the CT request is called which is
1479 * found in this structure.
1482 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1484 struct zfcp_port *port;
1485 struct zfcp_adapter *adapter;
1486 struct zfcp_send_ct *send_ct;
1487 struct fsf_qtcb_header *header;
1488 struct fsf_qtcb_bottom_support *bottom;
1489 int retval = -EINVAL;
1490 u16 subtable, rule, counter;
1492 adapter = fsf_req->adapter;
1493 send_ct = (struct zfcp_send_ct *) fsf_req->data;
1494 port = send_ct->port;
1495 header = &fsf_req->qtcb->header;
1496 bottom = &fsf_req->qtcb->bottom.support;
1498 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1499 goto skip_fsfstatus;
1501 /* evaluate FSF status in QTCB */
1502 switch (header->fsf_status) {
1505 zfcp_san_dbf_event_ct_response(fsf_req);
1509 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1510 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1512 zfcp_get_busid_by_port(port),
1513 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1514 /* stop operation for this adapter */
1515 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1516 zfcp_erp_adapter_shutdown(adapter, 0);
1517 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1520 case FSF_ADAPTER_STATUS_AVAILABLE:
1521 switch (header->fsf_status_qual.word[0]){
1522 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1523 /* reopening link to port */
1524 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1525 zfcp_test_link(port);
1526 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1528 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1529 /* ERP strategy will escalate */
1530 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1531 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1534 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1536 header->fsf_status_qual.word[0]);
1541 case FSF_ACCESS_DENIED:
1542 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1543 "command (adapter %s, port d_id=0x%06x)\n",
1544 zfcp_get_busid_by_port(port), port->d_id);
1545 for (counter = 0; counter < 2; counter++) {
1546 subtable = header->fsf_status_qual.halfword[counter * 2];
1547 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1549 case FSF_SQ_CFDC_SUBTABLE_OS:
1550 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1551 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1552 case FSF_SQ_CFDC_SUBTABLE_LUN:
1553 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1554 zfcp_act_subtable_type[subtable], rule);
1558 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1559 zfcp_erp_port_access_denied(port);
1560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1563 case FSF_GENERIC_COMMAND_REJECTED:
1564 ZFCP_LOG_INFO("generic service command rejected "
1565 "(adapter %s, port d_id=0x%06x)\n",
1566 zfcp_get_busid_by_port(port), port->d_id);
1567 ZFCP_LOG_INFO("status qualifier:\n");
1568 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1569 (char *) &header->fsf_status_qual,
1570 sizeof (union fsf_status_qual));
1571 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1572 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1575 case FSF_PORT_HANDLE_NOT_VALID:
1576 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1577 "0x%016Lx on adapter %s invalid. This may "
1578 "happen occasionally.\n", port->handle,
1579 port->wwpn, zfcp_get_busid_by_port(port));
1580 ZFCP_LOG_INFO("status qualifier:\n");
1581 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1582 (char *) &header->fsf_status_qual,
1583 sizeof (union fsf_status_qual));
1584 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1585 zfcp_erp_adapter_reopen(adapter, 0);
1586 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1589 case FSF_PORT_BOXED:
1590 ZFCP_LOG_INFO("port needs to be reopened "
1591 "(adapter %s, port d_id=0x%06x)\n",
1592 zfcp_get_busid_by_port(port), port->d_id);
1593 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1594 zfcp_erp_port_boxed(port);
1595 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1596 | ZFCP_STATUS_FSFREQ_RETRY;
1599 /* following states should never occure, all cases avoided
1600 in zfcp_fsf_send_ct - but who knows ... */
1601 case FSF_PAYLOAD_SIZE_MISMATCH:
1602 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1603 "req_buf_length=%d, resp_buf_length=%d)\n",
1604 zfcp_get_busid_by_adapter(adapter),
1605 bottom->req_buf_length, bottom->resp_buf_length);
1606 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1608 case FSF_REQUEST_SIZE_TOO_LARGE:
1609 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1610 "req_buf_length=%d)\n",
1611 zfcp_get_busid_by_adapter(adapter),
1612 bottom->req_buf_length);
1613 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1615 case FSF_RESPONSE_SIZE_TOO_LARGE:
1616 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1617 "resp_buf_length=%d)\n",
1618 zfcp_get_busid_by_adapter(adapter),
1619 bottom->resp_buf_length);
1620 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1622 case FSF_SBAL_MISMATCH:
1623 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1624 "resp_buf_length=%d)\n",
1625 zfcp_get_busid_by_adapter(adapter),
1626 bottom->req_buf_length, bottom->resp_buf_length);
1627 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1631 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1632 "(debug info 0x%x)\n", header->fsf_status);
1633 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1634 debug_exception(adapter->erp_dbf, 0,
1635 &header->fsf_status_qual.word[0], sizeof (u32));
1640 send_ct->status = retval;
1642 if (send_ct->handler != NULL)
1643 send_ct->handler(send_ct->handler_data);
1649 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1650 * @els: pointer to struct zfcp_send_els which contains all needed data for
1654 zfcp_fsf_send_els(struct zfcp_send_els *els)
1656 volatile struct qdio_buffer_element *sbale;
1657 struct zfcp_fsf_req *fsf_req;
1659 struct zfcp_adapter *adapter;
1660 unsigned long lock_flags;
1665 adapter = els->adapter;
1667 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1668 ZFCP_REQ_AUTO_CLEANUP,
1669 NULL, &lock_flags, &fsf_req);
1671 ZFCP_LOG_INFO("error: creation of ELS request failed "
1672 "(adapter %s, port d_id: 0x%06x)\n",
1673 zfcp_get_busid_by_adapter(adapter), d_id);
1677 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1678 if (zfcp_use_one_sbal(els->req, els->req_count,
1679 els->resp, els->resp_count)){
1680 /* both request buffer and response buffer
1681 fit into one sbale each */
1682 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1683 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1684 sbale[2].length = els->req[0].length;
1685 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1686 sbale[3].length = els->resp[0].length;
1687 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1688 } else if (adapter->adapter_features &
1689 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1690 /* try to use chained SBALs */
1691 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1692 SBAL_FLAGS0_TYPE_WRITE_READ,
1693 els->req, els->req_count,
1694 ZFCP_MAX_SBALS_PER_ELS_REQ);
1696 ZFCP_LOG_INFO("error: creation of ELS request failed "
1697 "(adapter %s, port d_id: 0x%06x)\n",
1698 zfcp_get_busid_by_adapter(adapter), d_id);
1706 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1707 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1708 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1709 SBAL_FLAGS0_TYPE_WRITE_READ,
1710 els->resp, els->resp_count,
1711 ZFCP_MAX_SBALS_PER_ELS_REQ);
1713 ZFCP_LOG_INFO("error: creation of ELS request failed "
1714 "(adapter %s, port d_id: 0x%06x)\n",
1715 zfcp_get_busid_by_adapter(adapter), d_id);
1723 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1725 /* reject request */
1726 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1727 ", ELS request too big (adapter %s, "
1728 "port d_id: 0x%06x)\n",
1729 zfcp_get_busid_by_adapter(adapter), d_id);
1734 /* settings in QTCB */
1735 fsf_req->qtcb->bottom.support.d_id = d_id;
1736 fsf_req->qtcb->bottom.support.service_class =
1737 ZFCP_FC_SERVICE_CLASS_DEFAULT;
1738 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1739 fsf_req->data = (unsigned long) els;
1741 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1743 zfcp_san_dbf_event_els_request(fsf_req);
1745 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
1746 ret = zfcp_fsf_req_send(fsf_req);
1748 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1749 "(adapter %s, port d_id: 0x%06x)\n",
1750 zfcp_get_busid_by_adapter(adapter), d_id);
1754 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1755 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1759 zfcp_fsf_req_free(fsf_req);
1763 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1770 * zfcp_fsf_send_els_handler - handler for ELS commands
1771 * @fsf_req: pointer to struct zfcp_fsf_req
1773 * Data specific for the ELS command is passed using
1774 * fsf_req->data. There we find the pointer to struct zfcp_send_els.
1775 * Usually a specific handler for the ELS command is called which is
1776 * found in this structure.
1778 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1780 struct zfcp_adapter *adapter;
1781 struct zfcp_port *port;
1783 struct fsf_qtcb_header *header;
1784 struct fsf_qtcb_bottom_support *bottom;
1785 struct zfcp_send_els *send_els;
1786 int retval = -EINVAL;
1787 u16 subtable, rule, counter;
1789 send_els = (struct zfcp_send_els *) fsf_req->data;
1790 adapter = send_els->adapter;
1791 port = send_els->port;
1792 d_id = send_els->d_id;
1793 header = &fsf_req->qtcb->header;
1794 bottom = &fsf_req->qtcb->bottom.support;
1796 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1797 goto skip_fsfstatus;
1799 switch (header->fsf_status) {
1802 zfcp_san_dbf_event_els_response(fsf_req);
1806 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1807 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1809 zfcp_get_busid_by_adapter(adapter),
1810 ZFCP_FC_SERVICE_CLASS_DEFAULT);
1811 /* stop operation for this adapter */
1812 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1813 zfcp_erp_adapter_shutdown(adapter, 0);
1814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1817 case FSF_ADAPTER_STATUS_AVAILABLE:
1818 switch (header->fsf_status_qual.word[0]){
1819 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1820 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1821 if (port && (send_els->ls_code != ZFCP_LS_ADISC))
1822 zfcp_test_link(port);
1823 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1825 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1826 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1830 (struct zfcp_ls_rjt_par *)
1831 &header->fsf_status_qual.word[2]);
1833 case FSF_SQ_RETRY_IF_POSSIBLE:
1834 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1835 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1838 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1839 header->fsf_status_qual.word[0]);
1840 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1841 (char*)header->fsf_status_qual.word, 16);
1845 case FSF_ELS_COMMAND_REJECTED:
1846 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1847 "prohibited sending "
1848 "(adapter: %s, port d_id: 0x%06x)\n",
1849 zfcp_get_busid_by_adapter(adapter), d_id);
1853 case FSF_PAYLOAD_SIZE_MISMATCH:
1855 "ELS request size and ELS response size must be either "
1856 "both 0, or both greater than 0 "
1857 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1858 zfcp_get_busid_by_adapter(adapter),
1859 bottom->req_buf_length,
1860 bottom->resp_buf_length);
1863 case FSF_REQUEST_SIZE_TOO_LARGE:
1865 "Length of the ELS request buffer, "
1866 "specified in QTCB bottom, "
1867 "exceeds the size of the buffers "
1868 "that have been allocated for ELS request data "
1869 "(adapter: %s, req_buf_length=%d)\n",
1870 zfcp_get_busid_by_adapter(adapter),
1871 bottom->req_buf_length);
1874 case FSF_RESPONSE_SIZE_TOO_LARGE:
1876 "Length of the ELS response buffer, "
1877 "specified in QTCB bottom, "
1878 "exceeds the size of the buffers "
1879 "that have been allocated for ELS response data "
1880 "(adapter: %s, resp_buf_length=%d)\n",
1881 zfcp_get_busid_by_adapter(adapter),
1882 bottom->resp_buf_length);
1885 case FSF_SBAL_MISMATCH:
1886 /* should never occure, avoided in zfcp_fsf_send_els */
1887 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1888 "resp_buf_length=%d)\n",
1889 zfcp_get_busid_by_adapter(adapter),
1890 bottom->req_buf_length, bottom->resp_buf_length);
1891 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1894 case FSF_ACCESS_DENIED:
1895 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1896 "(adapter %s, port d_id=0x%06x)\n",
1897 zfcp_get_busid_by_adapter(adapter), d_id);
1898 for (counter = 0; counter < 2; counter++) {
1899 subtable = header->fsf_status_qual.halfword[counter * 2];
1900 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1902 case FSF_SQ_CFDC_SUBTABLE_OS:
1903 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1904 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1905 case FSF_SQ_CFDC_SUBTABLE_LUN:
1906 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1907 zfcp_act_subtable_type[subtable], rule);
1911 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1913 zfcp_erp_port_access_denied(port);
1914 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1919 "bug: An unknown FSF Status was presented "
1920 "(adapter: %s, fsf_status=0x%08x)\n",
1921 zfcp_get_busid_by_adapter(adapter),
1922 header->fsf_status);
1923 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1924 debug_exception(adapter->erp_dbf, 0,
1925 &header->fsf_status_qual.word[0], sizeof(u32));
1926 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1931 send_els->status = retval;
1933 if (send_els->handler != 0)
1934 send_els->handler(send_els->handler_data);
1940 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1942 volatile struct qdio_buffer_element *sbale;
1943 struct zfcp_fsf_req *fsf_req;
1944 unsigned long lock_flags;
1947 /* setup new FSF request */
1948 retval = zfcp_fsf_req_create(erp_action->adapter,
1949 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1950 ZFCP_REQ_AUTO_CLEANUP,
1951 erp_action->adapter->pool.fsf_req_erp,
1952 &lock_flags, &fsf_req);
1954 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1955 "data request for adapter %s.\n",
1956 zfcp_get_busid_by_adapter(erp_action->adapter));
1960 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1961 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1962 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1964 fsf_req->qtcb->bottom.config.feature_selection =
1966 FSF_FEATURE_LUN_SHARING |
1967 FSF_FEATURE_NOTIFICATION_LOST |
1968 FSF_FEATURE_UPDATE_ALERT;
1969 fsf_req->erp_action = erp_action;
1970 erp_action->fsf_req = fsf_req;
1972 zfcp_erp_start_timer(fsf_req);
1973 retval = zfcp_fsf_req_send(fsf_req);
1976 ("error: Could not send exchange configuration data "
1977 "command on the adapter %s\n",
1978 zfcp_get_busid_by_adapter(erp_action->adapter));
1979 zfcp_fsf_req_free(fsf_req);
1980 erp_action->fsf_req = NULL;
1984 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1986 zfcp_get_busid_by_adapter(erp_action->adapter));
1989 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
1995 * zfcp_fsf_exchange_config_evaluate
1996 * @fsf_req: fsf_req which belongs to xchg config data request
1997 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
1999 * returns: -EIO on error, 0 otherwise
2002 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2004 struct fsf_qtcb_bottom_config *bottom;
2005 struct zfcp_adapter *adapter = fsf_req->adapter;
2006 struct Scsi_Host *shost = adapter->scsi_host;
2008 bottom = &fsf_req->qtcb->bottom.config;
2009 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2010 bottom->low_qtcb_version, bottom->high_qtcb_version);
2011 adapter->fsf_lic_version = bottom->lic_version;
2012 adapter->adapter_features = bottom->adapter_features;
2013 adapter->connection_features = bottom->connection_features;
2014 adapter->peer_wwpn = 0;
2015 adapter->peer_wwnn = 0;
2016 adapter->peer_d_id = 0;
2019 fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
2020 fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
2021 fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
2022 fc_host_speed(shost) = bottom->fc_link_speed;
2023 fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
2024 adapter->hydra_version = bottom->adapter_type;
2025 if (fc_host_permanent_port_name(shost) == -1)
2026 fc_host_permanent_port_name(shost) =
2027 fc_host_port_name(shost);
2028 if (bottom->fc_topology == FSF_TOPO_P2P) {
2029 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2030 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2031 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2032 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
2033 } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
2034 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
2035 else if (bottom->fc_topology == FSF_TOPO_AL)
2036 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
2038 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2040 fc_host_node_name(shost) = 0;
2041 fc_host_port_name(shost) = 0;
2042 fc_host_port_id(shost) = 0;
2043 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2044 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
2045 adapter->hydra_version = 0;
2048 if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
2049 adapter->hardware_version = bottom->hardware_version;
2050 memcpy(fc_host_serial_number(shost), bottom->serial_number,
2051 min(FC_SERIAL_NUMBER_SIZE, 17));
2052 EBCASC(fc_host_serial_number(shost),
2053 min(FC_SERIAL_NUMBER_SIZE, 17));
2056 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2060 "adapter version 0x%x, "
2061 "LIC version 0x%x, "
2062 "FC link speed %d Gb/s\n",
2063 zfcp_get_busid_by_adapter(adapter),
2064 (wwn_t) fc_host_node_name(shost),
2065 (wwn_t) fc_host_port_name(shost),
2066 fc_host_port_id(shost),
2067 adapter->hydra_version,
2068 adapter->fsf_lic_version,
2069 fc_host_speed(shost));
2070 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2071 ZFCP_LOG_NORMAL("error: the adapter %s "
2072 "only supports newer control block "
2073 "versions in comparison to this device "
2074 "driver (try updated device driver)\n",
2075 zfcp_get_busid_by_adapter(adapter));
2076 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2077 zfcp_erp_adapter_shutdown(adapter, 0);
2080 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2081 ZFCP_LOG_NORMAL("error: the adapter %s "
2082 "only supports older control block "
2083 "versions than this device driver uses"
2084 "(consider a microcode upgrade)\n",
2085 zfcp_get_busid_by_adapter(adapter));
2086 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2087 zfcp_erp_adapter_shutdown(adapter, 0);
2094 * function: zfcp_fsf_exchange_config_data_handler
2096 * purpose: is called for finished Exchange Configuration Data command
2101 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2103 struct fsf_qtcb_bottom_config *bottom;
2104 struct zfcp_adapter *adapter = fsf_req->adapter;
2105 struct fsf_qtcb *qtcb = fsf_req->qtcb;
2107 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2110 switch (qtcb->header.fsf_status) {
2113 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2116 switch (fc_host_port_type(adapter->scsi_host)) {
2117 case FC_PORTTYPE_PTP:
2118 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2119 "configuration detected at adapter %s\n"
2120 "Peer WWNN 0x%016llx, "
2121 "peer WWPN 0x%016llx, "
2122 "peer d_id 0x%06x\n",
2123 zfcp_get_busid_by_adapter(adapter),
2126 adapter->peer_d_id);
2127 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2130 case FC_PORTTYPE_NLPORT:
2131 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2132 "topology detected at adapter %s "
2133 "unsupported, shutting down adapter\n",
2134 zfcp_get_busid_by_adapter(adapter));
2135 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2137 zfcp_erp_adapter_shutdown(adapter, 0);
2139 case FC_PORTTYPE_NPORT:
2140 ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
2141 "network detected at adapter %s.\n",
2142 zfcp_get_busid_by_adapter(adapter));
2145 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2146 "reported by the exchange "
2147 "configuration command for "
2148 "the adapter %s is not "
2149 "of a type known to the zfcp "
2150 "driver, shutting down adapter\n",
2151 zfcp_get_busid_by_adapter(adapter));
2152 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2154 zfcp_erp_adapter_shutdown(adapter, 0);
2157 bottom = &qtcb->bottom.config;
2158 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2159 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2160 "allowed by the adapter %s "
2161 "is lower than the minimum "
2162 "required by the driver (%ld bytes).\n",
2163 bottom->max_qtcb_size,
2164 zfcp_get_busid_by_adapter(adapter),
2165 sizeof(struct fsf_qtcb));
2166 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2168 debug_event(fsf_req->adapter->erp_dbf, 0,
2169 &bottom->max_qtcb_size, sizeof (u32));
2170 zfcp_erp_adapter_shutdown(adapter, 0);
2173 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2176 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2177 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2179 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2182 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
2184 zfcp_fsf_link_down_info_eval(adapter,
2185 &qtcb->header.fsf_status_qual.link_down_info);
2188 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2189 debug_event(fsf_req->adapter->erp_dbf, 0,
2190 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2191 zfcp_erp_adapter_shutdown(adapter, 0);
2198 * zfcp_fsf_exchange_port_data - request information about local port
2199 * @erp_action: ERP action for the adapter for which port data is requested
2200 * @adapter: for which port data is requested
2201 * @data: response to exchange port data request
2204 zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action,
2205 struct zfcp_adapter *adapter,
2206 struct fsf_qtcb_bottom_port *data)
2208 volatile struct qdio_buffer_element *sbale;
2209 struct zfcp_fsf_req *fsf_req;
2210 unsigned long lock_flags;
2213 if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
2214 ZFCP_LOG_INFO("error: exchange port data "
2215 "command not supported by adapter %s\n",
2216 zfcp_get_busid_by_adapter(adapter));
2220 /* setup new FSF request */
2221 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2222 erp_action ? ZFCP_REQ_AUTO_CLEANUP : 0,
2223 NULL, &lock_flags, &fsf_req);
2225 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2226 "exchange port data request for"
2227 "the adapter %s.\n",
2228 zfcp_get_busid_by_adapter(adapter));
2229 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2235 fsf_req->data = (unsigned long) data;
2237 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2238 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2239 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2242 erp_action->fsf_req = fsf_req;
2243 fsf_req->erp_action = erp_action;
2244 zfcp_erp_start_timer(fsf_req);
2246 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
2248 retval = zfcp_fsf_req_send(fsf_req);
2250 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2251 "command on the adapter %s\n",
2252 zfcp_get_busid_by_adapter(adapter));
2253 zfcp_fsf_req_free(fsf_req);
2255 erp_action->fsf_req = NULL;
2256 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2261 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
2264 wait_event(fsf_req->completion_wq,
2265 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2266 zfcp_fsf_req_free(fsf_req);
2272 * zfcp_fsf_exchange_port_evaluate
2273 * @fsf_req: fsf_req which belongs to xchg port data request
2274 * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
2277 zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2279 struct zfcp_adapter *adapter;
2280 struct fsf_qtcb *qtcb;
2281 struct fsf_qtcb_bottom_port *bottom, *data;
2282 struct Scsi_Host *shost;
2284 adapter = fsf_req->adapter;
2285 qtcb = fsf_req->qtcb;
2286 bottom = &qtcb->bottom.port;
2287 shost = adapter->scsi_host;
2289 data = (struct fsf_qtcb_bottom_port*) fsf_req->data;
2291 memcpy(data, bottom, sizeof(struct fsf_qtcb_bottom_port));
2293 if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
2294 fc_host_permanent_port_name(shost) = bottom->wwpn;
2296 fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
2297 fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
2298 fc_host_supported_speeds(shost) = bottom->supported_speed;
2302 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2303 * @fsf_req: pointer to struct zfcp_fsf_req
2306 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2308 struct zfcp_adapter *adapter;
2309 struct fsf_qtcb *qtcb;
2311 adapter = fsf_req->adapter;
2312 qtcb = fsf_req->qtcb;
2314 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2317 switch (qtcb->header.fsf_status) {
2319 zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
2320 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2322 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2323 zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
2324 atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
2325 zfcp_fsf_link_down_info_eval(adapter,
2326 &qtcb->header.fsf_status_qual.link_down_info);
2329 debug_text_event(adapter->erp_dbf, 0, "xchg-port-ng");
2330 debug_event(adapter->erp_dbf, 0,
2331 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2337 * function: zfcp_fsf_open_port
2341 * returns: address of initiated FSF request
2342 * NULL - request could not be initiated
2345 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2347 volatile struct qdio_buffer_element *sbale;
2348 struct zfcp_fsf_req *fsf_req;
2349 unsigned long lock_flags;
2352 /* setup new FSF request */
2353 retval = zfcp_fsf_req_create(erp_action->adapter,
2354 FSF_QTCB_OPEN_PORT_WITH_DID,
2355 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2356 erp_action->adapter->pool.fsf_req_erp,
2357 &lock_flags, &fsf_req);
2359 ZFCP_LOG_INFO("error: Could not create open port request "
2360 "for port 0x%016Lx on adapter %s.\n",
2361 erp_action->port->wwpn,
2362 zfcp_get_busid_by_adapter(erp_action->adapter));
2366 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2367 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2368 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2370 fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2371 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2372 fsf_req->data = (unsigned long) erp_action->port;
2373 fsf_req->erp_action = erp_action;
2374 erp_action->fsf_req = fsf_req;
2376 zfcp_erp_start_timer(fsf_req);
2377 retval = zfcp_fsf_req_send(fsf_req);
2379 ZFCP_LOG_INFO("error: Could not send open port request for "
2380 "port 0x%016Lx on adapter %s.\n",
2381 erp_action->port->wwpn,
2382 zfcp_get_busid_by_adapter(erp_action->adapter));
2383 zfcp_fsf_req_free(fsf_req);
2384 erp_action->fsf_req = NULL;
2388 ZFCP_LOG_DEBUG("open port request initiated "
2389 "(adapter %s, port 0x%016Lx)\n",
2390 zfcp_get_busid_by_adapter(erp_action->adapter),
2391 erp_action->port->wwpn);
2393 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2399 * function: zfcp_fsf_open_port_handler
2401 * purpose: is called for finished Open Port command
2406 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2408 int retval = -EINVAL;
2409 struct zfcp_port *port;
2410 struct fsf_plogi *plogi;
2411 struct fsf_qtcb_header *header;
2412 u16 subtable, rule, counter;
2414 port = (struct zfcp_port *) fsf_req->data;
2415 header = &fsf_req->qtcb->header;
2417 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2418 /* don't change port status in our bookkeeping */
2419 goto skip_fsfstatus;
2422 /* evaluate FSF status in QTCB */
2423 switch (header->fsf_status) {
2425 case FSF_PORT_ALREADY_OPEN:
2426 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2427 "is already open.\n",
2428 port->wwpn, zfcp_get_busid_by_port(port));
2429 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2432 * This is a bug, however operation should continue normally
2433 * if it is simply ignored
2437 case FSF_ACCESS_DENIED:
2438 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2440 port->wwpn, zfcp_get_busid_by_port(port));
2441 for (counter = 0; counter < 2; counter++) {
2442 subtable = header->fsf_status_qual.halfword[counter * 2];
2443 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2445 case FSF_SQ_CFDC_SUBTABLE_OS:
2446 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2447 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2448 case FSF_SQ_CFDC_SUBTABLE_LUN:
2449 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2450 zfcp_act_subtable_type[subtable], rule);
2454 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2455 zfcp_erp_port_access_denied(port);
2456 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2459 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2460 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2461 "The remote port 0x%016Lx on adapter %s "
2462 "could not be opened. Disabling it.\n",
2463 port->wwpn, zfcp_get_busid_by_port(port));
2464 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2466 zfcp_erp_port_failed(port);
2467 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2470 case FSF_ADAPTER_STATUS_AVAILABLE:
2471 switch (header->fsf_status_qual.word[0]) {
2472 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2473 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2475 /* ERP strategy will escalate */
2476 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2478 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2479 /* ERP strategy will escalate */
2480 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2482 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2484 case FSF_SQ_NO_RETRY_POSSIBLE:
2485 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2486 "adapter %s could not be opened. "
2489 zfcp_get_busid_by_port(port));
2490 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2492 zfcp_erp_port_failed(port);
2493 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2497 ("bug: Wrong status qualifier 0x%x arrived.\n",
2498 header->fsf_status_qual.word[0]);
2499 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2502 fsf_req->adapter->erp_dbf, 0,
2503 &header->fsf_status_qual.word[0],
2510 /* save port handle assigned by FSF */
2511 port->handle = header->port_handle;
2512 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2513 "was opened, it's port handle is 0x%x\n",
2514 port->wwpn, zfcp_get_busid_by_port(port),
2516 /* mark port as open */
2517 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2518 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2519 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2520 ZFCP_STATUS_COMMON_ACCESS_BOXED,
2523 /* check whether D_ID has changed during open */
2525 * FIXME: This check is not airtight, as the FCP channel does
2526 * not monitor closures of target port connections caused on
2527 * the remote side. Thus, they might miss out on invalidating
2528 * locally cached WWPNs (and other N_Port parameters) of gone
2529 * target ports. So, our heroic attempt to make things safe
2530 * could be undermined by 'open port' response data tagged with
2531 * obsolete WWPNs. Another reason to monitor potential
2532 * connection closures ourself at least (by interpreting
2533 * incoming ELS' and unsolicited status). It just crosses my
2534 * mind that one should be able to cross-check by means of
2535 * another GID_PN straight after a port has been opened.
2536 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2538 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2539 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2541 if (fsf_req->qtcb->bottom.support.els1_length <
2542 sizeof (struct fsf_plogi)) {
2544 "warning: insufficient length of "
2545 "PLOGI payload (%i)\n",
2546 fsf_req->qtcb->bottom.support.els1_length);
2547 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2548 "fsf_s_short_plogi:");
2549 /* skip sanity check and assume wwpn is ok */
2551 if (plogi->serv_param.wwpn != port->wwpn) {
2552 ZFCP_LOG_INFO("warning: d_id of port "
2553 "0x%016Lx changed during "
2554 "open\n", port->wwpn);
2556 fsf_req->adapter->erp_dbf, 0,
2557 "fsf_s_did_change:");
2559 ZFCP_STATUS_PORT_DID_DID,
2562 port->wwnn = plogi->serv_param.wwnn;
2563 zfcp_plogi_evaluate(port, plogi);
2569 case FSF_UNKNOWN_OP_SUBTYPE:
2570 /* should never occure, subtype not set in zfcp_fsf_open_port */
2571 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2572 "op_subtype=0x%x)\n",
2573 zfcp_get_busid_by_port(port),
2574 fsf_req->qtcb->bottom.support.operation_subtype);
2575 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2579 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2580 "(debug info 0x%x)\n",
2581 header->fsf_status);
2582 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2583 debug_exception(fsf_req->adapter->erp_dbf, 0,
2584 &header->fsf_status, sizeof (u32));
2589 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2594 * function: zfcp_fsf_close_port
2596 * purpose: submit FSF command "close port"
2598 * returns: address of initiated FSF request
2599 * NULL - request could not be initiated
2602 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2604 volatile struct qdio_buffer_element *sbale;
2605 struct zfcp_fsf_req *fsf_req;
2606 unsigned long lock_flags;
2609 /* setup new FSF request */
2610 retval = zfcp_fsf_req_create(erp_action->adapter,
2611 FSF_QTCB_CLOSE_PORT,
2612 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2613 erp_action->adapter->pool.fsf_req_erp,
2614 &lock_flags, &fsf_req);
2616 ZFCP_LOG_INFO("error: Could not create a close port request "
2617 "for port 0x%016Lx on adapter %s.\n",
2618 erp_action->port->wwpn,
2619 zfcp_get_busid_by_adapter(erp_action->adapter));
2623 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2624 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2625 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2627 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2628 fsf_req->data = (unsigned long) erp_action->port;
2629 fsf_req->erp_action = erp_action;
2630 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2631 fsf_req->erp_action = erp_action;
2632 erp_action->fsf_req = fsf_req;
2634 zfcp_erp_start_timer(fsf_req);
2635 retval = zfcp_fsf_req_send(fsf_req);
2637 ZFCP_LOG_INFO("error: Could not send a close port request for "
2638 "port 0x%016Lx on adapter %s.\n",
2639 erp_action->port->wwpn,
2640 zfcp_get_busid_by_adapter(erp_action->adapter));
2641 zfcp_fsf_req_free(fsf_req);
2642 erp_action->fsf_req = NULL;
2646 ZFCP_LOG_TRACE("close port request initiated "
2647 "(adapter %s, port 0x%016Lx)\n",
2648 zfcp_get_busid_by_adapter(erp_action->adapter),
2649 erp_action->port->wwpn);
2651 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2657 * function: zfcp_fsf_close_port_handler
2659 * purpose: is called for finished Close Port FSF command
2664 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2666 int retval = -EINVAL;
2667 struct zfcp_port *port;
2669 port = (struct zfcp_port *) fsf_req->data;
2671 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2672 /* don't change port status in our bookkeeping */
2673 goto skip_fsfstatus;
2676 /* evaluate FSF status in QTCB */
2677 switch (fsf_req->qtcb->header.fsf_status) {
2679 case FSF_PORT_HANDLE_NOT_VALID:
2680 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2681 "0x%016Lx on adapter %s invalid. This may happen "
2682 "occasionally.\n", port->handle,
2683 port->wwpn, zfcp_get_busid_by_port(port));
2684 ZFCP_LOG_DEBUG("status qualifier:\n");
2685 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2686 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2687 sizeof (union fsf_status_qual));
2688 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2690 zfcp_erp_adapter_reopen(port->adapter, 0);
2691 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2694 case FSF_ADAPTER_STATUS_AVAILABLE:
2695 /* Note: FSF has actually closed the port in this case.
2696 * The status code is just daft. Fingers crossed for a change
2702 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2703 "port handle 0x%x\n", port->wwpn,
2704 zfcp_get_busid_by_port(port), port->handle);
2705 zfcp_erp_modify_port_status(port,
2706 ZFCP_STATUS_COMMON_OPEN,
2712 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2713 "(debug info 0x%x)\n",
2714 fsf_req->qtcb->header.fsf_status);
2715 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2716 debug_exception(fsf_req->adapter->erp_dbf, 0,
2717 &fsf_req->qtcb->header.fsf_status,
2723 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2728 * function: zfcp_fsf_close_physical_port
2730 * purpose: submit FSF command "close physical port"
2732 * returns: address of initiated FSF request
2733 * NULL - request could not be initiated
2736 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2738 volatile struct qdio_buffer_element *sbale;
2739 struct zfcp_fsf_req *fsf_req;
2740 unsigned long lock_flags;
2743 /* setup new FSF request */
2744 retval = zfcp_fsf_req_create(erp_action->adapter,
2745 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2746 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2747 erp_action->adapter->pool.fsf_req_erp,
2748 &lock_flags, &fsf_req);
2750 ZFCP_LOG_INFO("error: Could not create close physical port "
2751 "request (adapter %s, port 0x%016Lx)\n",
2752 zfcp_get_busid_by_adapter(erp_action->adapter),
2753 erp_action->port->wwpn);
2758 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2759 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2760 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2762 /* mark port as being closed */
2763 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2764 &erp_action->port->status);
2765 /* save a pointer to this port */
2766 fsf_req->data = (unsigned long) erp_action->port;
2767 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2768 fsf_req->erp_action = erp_action;
2769 erp_action->fsf_req = fsf_req;
2771 zfcp_erp_start_timer(fsf_req);
2772 retval = zfcp_fsf_req_send(fsf_req);
2774 ZFCP_LOG_INFO("error: Could not send close physical port "
2775 "request (adapter %s, port 0x%016Lx)\n",
2776 zfcp_get_busid_by_adapter(erp_action->adapter),
2777 erp_action->port->wwpn);
2778 zfcp_fsf_req_free(fsf_req);
2779 erp_action->fsf_req = NULL;
2783 ZFCP_LOG_TRACE("close physical port request initiated "
2784 "(adapter %s, port 0x%016Lx)\n",
2785 zfcp_get_busid_by_adapter(erp_action->adapter),
2786 erp_action->port->wwpn);
2788 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2794 * function: zfcp_fsf_close_physical_port_handler
2796 * purpose: is called for finished Close Physical Port FSF command
2801 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2803 int retval = -EINVAL;
2804 struct zfcp_port *port;
2805 struct zfcp_unit *unit;
2806 struct fsf_qtcb_header *header;
2807 u16 subtable, rule, counter;
2809 port = (struct zfcp_port *) fsf_req->data;
2810 header = &fsf_req->qtcb->header;
2812 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2813 /* don't change port status in our bookkeeping */
2814 goto skip_fsfstatus;
2817 /* evaluate FSF status in QTCB */
2818 switch (header->fsf_status) {
2820 case FSF_PORT_HANDLE_NOT_VALID:
2821 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2822 "(adapter %s, port 0x%016Lx). "
2823 "This may happen occasionally.\n",
2825 zfcp_get_busid_by_port(port),
2827 ZFCP_LOG_DEBUG("status qualifier:\n");
2828 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2829 (char *) &header->fsf_status_qual,
2830 sizeof (union fsf_status_qual));
2831 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2833 zfcp_erp_adapter_reopen(port->adapter, 0);
2834 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2837 case FSF_ACCESS_DENIED:
2838 ZFCP_LOG_NORMAL("Access denied, cannot close "
2839 "physical port 0x%016Lx on adapter %s\n",
2840 port->wwpn, zfcp_get_busid_by_port(port));
2841 for (counter = 0; counter < 2; counter++) {
2842 subtable = header->fsf_status_qual.halfword[counter * 2];
2843 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2845 case FSF_SQ_CFDC_SUBTABLE_OS:
2846 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2847 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2848 case FSF_SQ_CFDC_SUBTABLE_LUN:
2849 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2850 zfcp_act_subtable_type[subtable], rule);
2854 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2855 zfcp_erp_port_access_denied(port);
2856 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2859 case FSF_PORT_BOXED:
2860 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2861 "%s needs to be reopened but it was attempted "
2862 "to close it physically.\n",
2864 zfcp_get_busid_by_port(port));
2865 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2866 zfcp_erp_port_boxed(port);
2867 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2868 ZFCP_STATUS_FSFREQ_RETRY;
2871 case FSF_ADAPTER_STATUS_AVAILABLE:
2872 switch (header->fsf_status_qual.word[0]) {
2873 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2874 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2876 /* This will now be escalated by ERP */
2877 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2879 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2880 /* ERP strategy will escalate */
2881 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2883 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2887 ("bug: Wrong status qualifier 0x%x arrived.\n",
2888 header->fsf_status_qual.word[0]);
2889 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2892 fsf_req->adapter->erp_dbf, 0,
2893 &header->fsf_status_qual.word[0], sizeof (u32));
2899 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2900 "physically closed, port handle 0x%x\n",
2902 zfcp_get_busid_by_port(port), port->handle);
2903 /* can't use generic zfcp_erp_modify_port_status because
2904 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2906 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2907 list_for_each_entry(unit, &port->unit_list_head, list)
2908 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2913 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2914 "(debug info 0x%x)\n",
2915 header->fsf_status);
2916 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2917 debug_exception(fsf_req->adapter->erp_dbf, 0,
2918 &header->fsf_status, sizeof (u32));
2923 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2928 * function: zfcp_fsf_open_unit
2934 * assumptions: This routine does not check whether the associated
2935 * remote port has already been opened. This should be
2936 * done by calling routines. Otherwise some status
2937 * may be presented by FSF
2940 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2942 volatile struct qdio_buffer_element *sbale;
2943 struct zfcp_fsf_req *fsf_req;
2944 unsigned long lock_flags;
2947 /* setup new FSF request */
2948 retval = zfcp_fsf_req_create(erp_action->adapter,
2950 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2951 erp_action->adapter->pool.fsf_req_erp,
2952 &lock_flags, &fsf_req);
2954 ZFCP_LOG_INFO("error: Could not create open unit request for "
2955 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2956 erp_action->unit->fcp_lun,
2957 erp_action->unit->port->wwpn,
2958 zfcp_get_busid_by_adapter(erp_action->adapter));
2962 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2963 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2964 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2966 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
2967 fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
2968 if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
2969 fsf_req->qtcb->bottom.support.option =
2970 FSF_OPEN_LUN_SUPPRESS_BOXING;
2971 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2972 fsf_req->data = (unsigned long) erp_action->unit;
2973 fsf_req->erp_action = erp_action;
2974 erp_action->fsf_req = fsf_req;
2976 zfcp_erp_start_timer(fsf_req);
2977 retval = zfcp_fsf_req_send(erp_action->fsf_req);
2979 ZFCP_LOG_INFO("error: Could not send an open unit request "
2980 "on the adapter %s, port 0x%016Lx for "
2982 zfcp_get_busid_by_adapter(erp_action->adapter),
2983 erp_action->port->wwpn,
2984 erp_action->unit->fcp_lun);
2985 zfcp_fsf_req_free(fsf_req);
2986 erp_action->fsf_req = NULL;
2990 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2991 "port 0x%016Lx, unit 0x%016Lx)\n",
2992 zfcp_get_busid_by_adapter(erp_action->adapter),
2993 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2995 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3001 * function: zfcp_fsf_open_unit_handler
3003 * purpose: is called for finished Open LUN command
3008 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3010 int retval = -EINVAL;
3011 struct zfcp_adapter *adapter;
3012 struct zfcp_unit *unit;
3013 struct fsf_qtcb_header *header;
3014 struct fsf_qtcb_bottom_support *bottom;
3015 struct fsf_queue_designator *queue_designator;
3016 u16 subtable, rule, counter;
3017 int exclusive, readwrite;
3019 unit = (struct zfcp_unit *) fsf_req->data;
3021 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3022 /* don't change unit status in our bookkeeping */
3023 goto skip_fsfstatus;
3026 adapter = fsf_req->adapter;
3027 header = &fsf_req->qtcb->header;
3028 bottom = &fsf_req->qtcb->bottom.support;
3029 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3031 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3032 ZFCP_STATUS_COMMON_ACCESS_BOXED |
3033 ZFCP_STATUS_UNIT_SHARED |
3034 ZFCP_STATUS_UNIT_READONLY,
3037 /* evaluate FSF status in QTCB */
3038 switch (header->fsf_status) {
3040 case FSF_PORT_HANDLE_NOT_VALID:
3041 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3042 "for port 0x%016Lx on adapter %s invalid "
3043 "This may happen occasionally\n",
3045 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3046 ZFCP_LOG_DEBUG("status qualifier:\n");
3047 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3048 (char *) &header->fsf_status_qual,
3049 sizeof (union fsf_status_qual));
3050 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3051 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3052 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3055 case FSF_LUN_ALREADY_OPEN:
3056 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3057 "remote port 0x%016Lx on adapter %s twice.\n",
3059 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3060 debug_text_exception(adapter->erp_dbf, 0,
3062 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3065 case FSF_ACCESS_DENIED:
3066 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3067 "remote port 0x%016Lx on adapter %s\n",
3068 unit->fcp_lun, unit->port->wwpn,
3069 zfcp_get_busid_by_unit(unit));
3070 for (counter = 0; counter < 2; counter++) {
3071 subtable = header->fsf_status_qual.halfword[counter * 2];
3072 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3074 case FSF_SQ_CFDC_SUBTABLE_OS:
3075 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3076 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3077 case FSF_SQ_CFDC_SUBTABLE_LUN:
3078 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3079 zfcp_act_subtable_type[subtable], rule);
3083 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3084 zfcp_erp_unit_access_denied(unit);
3085 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3086 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3087 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3090 case FSF_PORT_BOXED:
3091 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3092 "needs to be reopened\n",
3093 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3094 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3095 zfcp_erp_port_boxed(unit->port);
3096 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3097 ZFCP_STATUS_FSFREQ_RETRY;
3100 case FSF_LUN_SHARING_VIOLATION:
3101 if (header->fsf_status_qual.word[0] != 0) {
3102 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3104 "connected to the adapter %s "
3105 "is already in use in LPAR%d, CSS%d\n",
3108 zfcp_get_busid_by_unit(unit),
3109 queue_designator->hla,
3110 queue_designator->cssid);
3112 subtable = header->fsf_status_qual.halfword[4];
3113 rule = header->fsf_status_qual.halfword[5];
3115 case FSF_SQ_CFDC_SUBTABLE_OS:
3116 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3117 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3118 case FSF_SQ_CFDC_SUBTABLE_LUN:
3119 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3120 "remote port with WWPN 0x%Lx "
3121 "connected to the adapter %s "
3122 "is denied (%s rule %d)\n",
3125 zfcp_get_busid_by_unit(unit),
3126 zfcp_act_subtable_type[subtable],
3131 ZFCP_LOG_DEBUG("status qualifier:\n");
3132 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3133 (char *) &header->fsf_status_qual,
3134 sizeof (union fsf_status_qual));
3135 debug_text_event(adapter->erp_dbf, 2,
3137 zfcp_erp_unit_access_denied(unit);
3138 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3139 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3140 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3143 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3144 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3145 "There is no handle (temporary port identifier) "
3146 "available for unit 0x%016Lx on port 0x%016Lx "
3150 zfcp_get_busid_by_unit(unit));
3151 debug_text_event(adapter->erp_dbf, 1,
3153 zfcp_erp_unit_failed(unit);
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3157 case FSF_ADAPTER_STATUS_AVAILABLE:
3158 switch (header->fsf_status_qual.word[0]) {
3159 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3160 /* Re-establish link to port */
3161 debug_text_event(adapter->erp_dbf, 1,
3163 zfcp_test_link(unit->port);
3164 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3166 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3167 /* ERP strategy will escalate */
3168 debug_text_event(adapter->erp_dbf, 1,
3170 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3174 ("bug: Wrong status qualifier 0x%x arrived.\n",
3175 header->fsf_status_qual.word[0]);
3176 debug_text_event(adapter->erp_dbf, 0,
3178 debug_exception(adapter->erp_dbf, 0,
3179 &header->fsf_status_qual.word[0],
3184 case FSF_INVALID_COMMAND_OPTION:
3186 "Invalid option 0x%x has been specified "
3187 "in QTCB bottom sent to the adapter %s\n",
3189 zfcp_get_busid_by_adapter(adapter));
3190 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3195 /* save LUN handle assigned by FSF */
3196 unit->handle = header->lun_handle;
3197 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3198 "adapter %s opened, port handle 0x%x\n",
3201 zfcp_get_busid_by_unit(unit),
3203 /* mark unit as open */
3204 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3206 if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
3207 (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
3208 (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
3209 exclusive = (bottom->lun_access_info &
3210 FSF_UNIT_ACCESS_EXCLUSIVE);
3211 readwrite = (bottom->lun_access_info &
3212 FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
3215 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3219 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3221 ZFCP_LOG_NORMAL("read-only access for unit "
3222 "(adapter %s, wwpn=0x%016Lx, "
3223 "fcp_lun=0x%016Lx)\n",
3224 zfcp_get_busid_by_unit(unit),
3229 if (exclusive && !readwrite) {
3230 ZFCP_LOG_NORMAL("exclusive access of read-only "
3231 "unit not supported\n");
3232 zfcp_erp_unit_failed(unit);
3233 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3234 zfcp_erp_unit_shutdown(unit, 0);
3235 } else if (!exclusive && readwrite) {
3236 ZFCP_LOG_NORMAL("shared access of read-write "
3237 "unit not supported\n");
3238 zfcp_erp_unit_failed(unit);
3239 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3240 zfcp_erp_unit_shutdown(unit, 0);
3248 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3249 "(debug info 0x%x)\n",
3250 header->fsf_status);
3251 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3252 debug_exception(adapter->erp_dbf, 0,
3253 &header->fsf_status, sizeof (u32));
3258 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3263 * function: zfcp_fsf_close_unit
3267 * returns: address of fsf_req - request successfully initiated
3270 * assumptions: This routine does not check whether the associated
3271 * remote port/lun has already been opened. This should be
3272 * done by calling routines. Otherwise some status
3273 * may be presented by FSF
3276 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3278 volatile struct qdio_buffer_element *sbale;
3279 struct zfcp_fsf_req *fsf_req;
3280 unsigned long lock_flags;
3283 /* setup new FSF request */
3284 retval = zfcp_fsf_req_create(erp_action->adapter,
3286 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3287 erp_action->adapter->pool.fsf_req_erp,
3288 &lock_flags, &fsf_req);
3290 ZFCP_LOG_INFO("error: Could not create close unit request for "
3291 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3292 erp_action->unit->fcp_lun,
3293 erp_action->port->wwpn,
3294 zfcp_get_busid_by_adapter(erp_action->adapter));
3298 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3299 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3300 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3302 fsf_req->qtcb->header.port_handle = erp_action->port->handle;
3303 fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3304 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3305 fsf_req->data = (unsigned long) erp_action->unit;
3306 fsf_req->erp_action = erp_action;
3307 erp_action->fsf_req = fsf_req;
3309 zfcp_erp_start_timer(fsf_req);
3310 retval = zfcp_fsf_req_send(erp_action->fsf_req);
3312 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3313 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3314 erp_action->unit->fcp_lun,
3315 erp_action->port->wwpn,
3316 zfcp_get_busid_by_adapter(erp_action->adapter));
3317 zfcp_fsf_req_free(fsf_req);
3318 erp_action->fsf_req = NULL;
3322 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3323 "port 0x%016Lx, unit 0x%016Lx)\n",
3324 zfcp_get_busid_by_adapter(erp_action->adapter),
3325 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3327 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3333 * function: zfcp_fsf_close_unit_handler
3335 * purpose: is called for finished Close LUN FSF command
3340 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3342 int retval = -EINVAL;
3343 struct zfcp_unit *unit;
3345 unit = (struct zfcp_unit *) fsf_req->data;
3347 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3348 /* don't change unit status in our bookkeeping */
3349 goto skip_fsfstatus;
3352 /* evaluate FSF status in QTCB */
3353 switch (fsf_req->qtcb->header.fsf_status) {
3355 case FSF_PORT_HANDLE_NOT_VALID:
3356 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3357 "0x%016Lx on adapter %s invalid. This may "
3358 "happen in rare circumstances\n",
3361 zfcp_get_busid_by_unit(unit));
3362 ZFCP_LOG_DEBUG("status qualifier:\n");
3363 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3364 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3365 sizeof (union fsf_status_qual));
3366 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3368 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3369 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3372 case FSF_LUN_HANDLE_NOT_VALID:
3373 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3374 "0x%016Lx on port 0x%016Lx on adapter %s is "
3375 "invalid. This may happen occasionally.\n",
3379 zfcp_get_busid_by_unit(unit));
3380 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3381 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3382 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3383 sizeof (union fsf_status_qual));
3384 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3386 zfcp_erp_port_reopen(unit->port, 0);
3387 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3390 case FSF_PORT_BOXED:
3391 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3392 "needs to be reopened\n",
3394 zfcp_get_busid_by_unit(unit));
3395 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3396 zfcp_erp_port_boxed(unit->port);
3397 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3398 ZFCP_STATUS_FSFREQ_RETRY;
3401 case FSF_ADAPTER_STATUS_AVAILABLE:
3402 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3403 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3404 /* re-establish link to port */
3405 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3407 zfcp_test_link(unit->port);
3408 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3410 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3411 /* ERP strategy will escalate */
3412 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3414 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3418 ("bug: Wrong status qualifier 0x%x arrived.\n",
3419 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3420 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3423 fsf_req->adapter->erp_dbf, 0,
3424 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3431 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3432 "closed, port handle 0x%x\n",
3435 zfcp_get_busid_by_unit(unit),
3437 /* mark unit as closed */
3438 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3443 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3444 "(debug info 0x%x)\n",
3445 fsf_req->qtcb->header.fsf_status);
3446 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3447 debug_exception(fsf_req->adapter->erp_dbf, 0,
3448 &fsf_req->qtcb->header.fsf_status,
3454 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3459 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3460 * @adapter: adapter where scsi command is issued
3461 * @unit: unit where command is sent to
3462 * @scsi_cmnd: scsi command to be sent
3463 * @timer: timer to be started when request is initiated
3464 * @req_flags: flags for fsf_request
3467 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3468 struct zfcp_unit *unit,
3469 struct scsi_cmnd * scsi_cmnd,
3470 int use_timer, int req_flags)
3472 struct zfcp_fsf_req *fsf_req = NULL;
3473 struct fcp_cmnd_iu *fcp_cmnd_iu;
3474 unsigned int sbtype;
3475 unsigned long lock_flags;
3480 /* setup new FSF request */
3481 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3482 adapter->pool.fsf_req_scsi,
3483 &lock_flags, &fsf_req);
3484 if (unlikely(retval < 0)) {
3485 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3486 "for unit 0x%016Lx on port 0x%016Lx on "
3490 zfcp_get_busid_by_adapter(adapter));
3491 goto failed_req_create;
3494 zfcp_unit_get(unit);
3495 fsf_req->unit = unit;
3497 /* associate FSF request with SCSI request (for look up on abort) */
3498 scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
3500 /* associate SCSI command with FSF request */
3501 fsf_req->data = (unsigned long) scsi_cmnd;
3503 /* set handles of unit and its parent port in QTCB */
3504 fsf_req->qtcb->header.lun_handle = unit->handle;
3505 fsf_req->qtcb->header.port_handle = unit->port->handle;
3507 /* FSF does not define the structure of the FCP_CMND IU */
3508 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3509 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3512 * set depending on data direction:
3513 * data direction bits in SBALE (SB Type)
3514 * data direction bits in QTCB
3515 * data direction bits in FCP_CMND IU
3517 switch (scsi_cmnd->sc_data_direction) {
3519 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3522 * what is the correct type for commands
3523 * without 'real' data buffers?
3525 sbtype = SBAL_FLAGS0_TYPE_READ;
3527 case DMA_FROM_DEVICE:
3528 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3529 sbtype = SBAL_FLAGS0_TYPE_READ;
3530 fcp_cmnd_iu->rddata = 1;
3533 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3534 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3535 fcp_cmnd_iu->wddata = 1;
3537 case DMA_BIDIRECTIONAL:
3540 * dummy, catch this condition earlier
3541 * in zfcp_scsi_queuecommand
3543 goto failed_scsi_cmnd;
3546 /* set FC service class in QTCB (3 per default) */
3547 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3549 /* set FCP_LUN in FCP_CMND IU in QTCB */
3550 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3552 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3554 /* set task attributes in FCP_CMND IU in QTCB */
3555 if (likely((scsi_cmnd->device->simple_tags) ||
3556 (atomic_test_mask(mask, &unit->status))))
3557 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3559 fcp_cmnd_iu->task_attribute = UNTAGGED;
3561 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3562 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3563 fcp_cmnd_iu->add_fcp_cdb_length
3564 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3565 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3566 "additional FCP_CDB length is 0x%x "
3567 "(shifted right 2 bits)\n",
3569 fcp_cmnd_iu->add_fcp_cdb_length);
3572 * copy SCSI CDB (including additional length, if any) to
3573 * FCP_CDB in FCP_CMND IU in QTCB
3575 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3577 /* FCP CMND IU length in QTCB */
3578 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3579 sizeof (struct fcp_cmnd_iu) +
3580 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3582 /* generate SBALEs from data buffer */
3583 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3584 if (unlikely(real_bytes < 0)) {
3585 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3587 "Data did not fit into available buffer(s), "
3588 "waiting for more...\n");
3591 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3592 "required. Shutting down unit "
3593 "(adapter %s, port 0x%016Lx, "
3595 zfcp_get_busid_by_unit(unit),
3598 zfcp_erp_unit_shutdown(unit, 0);
3604 /* set length of FCP data length in FCP_CMND IU in QTCB */
3605 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3607 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3608 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3609 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3612 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
3614 retval = zfcp_fsf_req_send(fsf_req);
3615 if (unlikely(retval < 0)) {
3616 ZFCP_LOG_INFO("error: Could not send FCP command request "
3617 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3618 zfcp_get_busid_by_adapter(adapter),
3624 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3625 "port 0x%016Lx, unit 0x%016Lx)\n",
3626 zfcp_get_busid_by_adapter(adapter),
3634 zfcp_unit_put(unit);
3635 zfcp_fsf_req_free(fsf_req);
3637 scsi_cmnd->host_scribble = NULL;
3640 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3644 struct zfcp_fsf_req *
3645 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3646 struct zfcp_unit *unit,
3647 u8 tm_flags, int req_flags)
3649 struct zfcp_fsf_req *fsf_req = NULL;
3651 struct fcp_cmnd_iu *fcp_cmnd_iu;
3652 unsigned long lock_flags;
3653 volatile struct qdio_buffer_element *sbale;
3655 /* setup new FSF request */
3656 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3657 adapter->pool.fsf_req_scsi,
3658 &lock_flags, &fsf_req);
3660 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3661 "management) request for adapter %s, port "
3662 " 0x%016Lx, unit 0x%016Lx.\n",
3663 zfcp_get_busid_by_adapter(adapter),
3664 unit->port->wwpn, unit->fcp_lun);
3669 * Used to decide on proper handler in the return path,
3670 * could be either zfcp_fsf_send_fcp_command_task_handler or
3671 * zfcp_fsf_send_fcp_command_task_management_handler */
3673 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3676 * hold a pointer to the unit being target of this
3677 * task management request
3679 fsf_req->data = (unsigned long) unit;
3681 /* set FSF related fields in QTCB */
3682 fsf_req->qtcb->header.lun_handle = unit->handle;
3683 fsf_req->qtcb->header.port_handle = unit->port->handle;
3684 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3685 fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
3686 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3687 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3689 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3690 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3691 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3693 /* set FCP related fields in FCP_CMND IU in QTCB */
3694 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3695 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3696 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3697 fcp_cmnd_iu->task_management_flags = tm_flags;
3699 zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
3700 retval = zfcp_fsf_req_send(fsf_req);
3702 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3703 "management) on adapter %s, port 0x%016Lx for "
3704 "unit LUN 0x%016Lx\n",
3705 zfcp_get_busid_by_adapter(adapter),
3708 zfcp_fsf_req_free(fsf_req);
3713 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3714 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3716 zfcp_get_busid_by_adapter(adapter),
3721 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3726 * function: zfcp_fsf_send_fcp_command_handler
3728 * purpose: is called for finished Send FCP Command
3733 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3735 int retval = -EINVAL;
3736 struct zfcp_unit *unit;
3737 struct fsf_qtcb_header *header;
3738 u16 subtable, rule, counter;
3740 header = &fsf_req->qtcb->header;
3742 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3743 unit = (struct zfcp_unit *) fsf_req->data;
3745 unit = fsf_req->unit;
3747 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3748 /* go directly to calls of special handlers */
3749 goto skip_fsfstatus;
3752 /* evaluate FSF status in QTCB */
3753 switch (header->fsf_status) {
3755 case FSF_PORT_HANDLE_NOT_VALID:
3756 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3757 "0x%016Lx on adapter %s invalid\n",
3759 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3760 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3761 (char *) &header->fsf_status_qual,
3762 sizeof (union fsf_status_qual));
3763 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3765 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3766 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3769 case FSF_LUN_HANDLE_NOT_VALID:
3770 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3771 "0x%016Lx on port 0x%016Lx on adapter %s is "
3772 "invalid. This may happen occasionally.\n",
3776 zfcp_get_busid_by_unit(unit));
3777 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3778 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3779 (char *) &header->fsf_status_qual,
3780 sizeof (union fsf_status_qual));
3781 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3783 zfcp_erp_port_reopen(unit->port, 0);
3784 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3787 case FSF_HANDLE_MISMATCH:
3788 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3789 "unexpectedly. (adapter %s, port 0x%016Lx, "
3792 zfcp_get_busid_by_unit(unit),
3795 ZFCP_LOG_NORMAL("status qualifier:\n");
3796 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3797 (char *) &header->fsf_status_qual,
3798 sizeof (union fsf_status_qual));
3799 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3801 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3802 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3805 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3806 ZFCP_LOG_INFO("error: adapter %s does not support fc "
3808 zfcp_get_busid_by_unit(unit),
3809 ZFCP_FC_SERVICE_CLASS_DEFAULT);
3810 /* stop operation for this adapter */
3811 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3812 "fsf_s_class_nsup");
3813 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3817 case FSF_FCPLUN_NOT_VALID:
3818 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3819 "adapter %s does not have correct unit "
3823 zfcp_get_busid_by_unit(unit),
3825 ZFCP_LOG_DEBUG("status qualifier:\n");
3826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3827 (char *) &header->fsf_status_qual,
3828 sizeof (union fsf_status_qual));
3829 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3830 "fsf_s_fcp_lun_nv");
3831 zfcp_erp_port_reopen(unit->port, 0);
3832 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3835 case FSF_ACCESS_DENIED:
3836 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3837 "unit 0x%016Lx on port 0x%016Lx on "
3838 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3839 zfcp_get_busid_by_unit(unit));
3840 for (counter = 0; counter < 2; counter++) {
3841 subtable = header->fsf_status_qual.halfword[counter * 2];
3842 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3844 case FSF_SQ_CFDC_SUBTABLE_OS:
3845 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3846 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3847 case FSF_SQ_CFDC_SUBTABLE_LUN:
3848 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3849 zfcp_act_subtable_type[subtable], rule);
3853 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3854 zfcp_erp_unit_access_denied(unit);
3855 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3858 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3859 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3860 "0x%016Lx on port 0x%016Lx on adapter %s "
3861 "(debug info %d)\n",
3864 zfcp_get_busid_by_unit(unit),
3865 fsf_req->qtcb->bottom.io.data_direction);
3866 /* stop operation for this adapter */
3867 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3868 "fsf_s_dir_ind_nv");
3869 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3873 case FSF_CMND_LENGTH_NOT_VALID:
3875 ("bug: An invalid control-data-block length field "
3876 "was found in a command for unit 0x%016Lx on port "
3877 "0x%016Lx on adapter %s " "(debug info %d)\n",
3878 unit->fcp_lun, unit->port->wwpn,
3879 zfcp_get_busid_by_unit(unit),
3880 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3881 /* stop operation for this adapter */
3882 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3883 "fsf_s_cmd_len_nv");
3884 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3885 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3888 case FSF_PORT_BOXED:
3889 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3890 "needs to be reopened\n",
3891 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3892 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3893 zfcp_erp_port_boxed(unit->port);
3894 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3895 ZFCP_STATUS_FSFREQ_RETRY;
3899 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3900 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3901 zfcp_get_busid_by_unit(unit),
3902 unit->port->wwpn, unit->fcp_lun);
3903 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3904 zfcp_erp_unit_boxed(unit);
3905 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3906 | ZFCP_STATUS_FSFREQ_RETRY;
3909 case FSF_ADAPTER_STATUS_AVAILABLE:
3910 switch (header->fsf_status_qual.word[0]) {
3911 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3912 /* re-establish link to port */
3913 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3915 zfcp_test_link(unit->port);
3917 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3918 /* FIXME(hw) need proper specs for proper action */
3919 /* let scsi stack deal with retries and escalation */
3920 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3925 ("Unknown status qualifier 0x%x arrived.\n",
3926 header->fsf_status_qual.word[0]);
3927 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3929 debug_exception(fsf_req->adapter->erp_dbf, 0,
3930 &header->fsf_status_qual.word[0],
3934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3940 case FSF_FCP_RSP_AVAILABLE:
3944 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3945 debug_exception(fsf_req->adapter->erp_dbf, 0,
3946 &header->fsf_status, sizeof(u32));
3951 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3953 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3955 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3956 fsf_req->unit = NULL;
3957 zfcp_unit_put(unit);
3963 * function: zfcp_fsf_send_fcp_command_task_handler
3965 * purpose: evaluates FCP_RSP IU
3970 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3973 struct scsi_cmnd *scpnt;
3974 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3975 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3976 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3977 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3979 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3980 unsigned long flags;
3981 struct zfcp_unit *unit = fsf_req->unit;
3983 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3984 scpnt = (struct scsi_cmnd *) fsf_req->data;
3985 if (unlikely(!scpnt)) {
3987 ("Command with fsf_req %p is not associated to "
3988 "a scsi command anymore. Aborted?\n", fsf_req);
3991 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3992 /* FIXME: (design) mid-layer should handle DID_ABORT like
3993 * DID_SOFT_ERROR by retrying the request for devices
3994 * that allow retries.
3996 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3997 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3998 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3999 goto skip_fsfstatus;
4002 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4003 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4004 set_host_byte(&scpnt->result, DID_ERROR);
4005 goto skip_fsfstatus;
4008 /* set message byte of result in SCSI command */
4009 scpnt->result |= COMMAND_COMPLETE << 8;
4012 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4013 * of result in SCSI command
4015 scpnt->result |= fcp_rsp_iu->scsi_status;
4016 if (unlikely(fcp_rsp_iu->scsi_status)) {
4018 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4019 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4020 scpnt->cmnd, scpnt->cmd_len);
4021 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4022 fcp_rsp_iu->scsi_status);
4023 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4024 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4025 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4026 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4027 fcp_rsp_iu->fcp_sns_len);
4030 /* check FCP_RSP_INFO */
4031 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4032 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4033 switch (fcp_rsp_info[3]) {
4036 ZFCP_LOG_TRACE("no failure or Task Management "
4037 "Function complete\n");
4038 set_host_byte(&scpnt->result, DID_OK);
4040 case RSP_CODE_LENGTH_MISMATCH:
4042 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4043 "that the fibrechannel protocol data "
4044 "length differs from the burst length. "
4045 "The problem occured on unit 0x%016Lx "
4046 "on port 0x%016Lx on adapter %s",
4049 zfcp_get_busid_by_unit(unit));
4050 /* dump SCSI CDB as prepared by zfcp */
4051 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4052 (char *) &fsf_req->qtcb->
4053 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4054 set_host_byte(&scpnt->result, DID_ERROR);
4055 goto skip_fsfstatus;
4056 case RSP_CODE_FIELD_INVALID:
4057 /* driver or hardware bug */
4058 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4059 "that the fibrechannel protocol data "
4060 "fields were incorrectly set up. "
4061 "The problem occured on the unit "
4062 "0x%016Lx on port 0x%016Lx on "
4066 zfcp_get_busid_by_unit(unit));
4067 /* dump SCSI CDB as prepared by zfcp */
4068 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4069 (char *) &fsf_req->qtcb->
4070 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4071 set_host_byte(&scpnt->result, DID_ERROR);
4072 goto skip_fsfstatus;
4073 case RSP_CODE_RO_MISMATCH:
4075 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4076 "that conflicting values for the "
4077 "fibrechannel payload offset from the "
4078 "header were found. "
4079 "The problem occured on unit 0x%016Lx "
4080 "on port 0x%016Lx on adapter %s.\n",
4083 zfcp_get_busid_by_unit(unit));
4084 /* dump SCSI CDB as prepared by zfcp */
4085 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4086 (char *) &fsf_req->qtcb->
4087 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4088 set_host_byte(&scpnt->result, DID_ERROR);
4089 goto skip_fsfstatus;
4091 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4092 "code was detected for a command. "
4093 "The problem occured on the unit "
4094 "0x%016Lx on port 0x%016Lx on "
4095 "adapter %s (debug info 0x%x)\n",
4098 zfcp_get_busid_by_unit(unit),
4100 /* dump SCSI CDB as prepared by zfcp */
4101 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4102 (char *) &fsf_req->qtcb->
4103 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4104 set_host_byte(&scpnt->result, DID_ERROR);
4105 goto skip_fsfstatus;
4109 /* check for sense data */
4110 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4111 sns_len = FSF_FCP_RSP_SIZE -
4112 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4113 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4115 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4116 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4117 SCSI_SENSE_BUFFERSIZE);
4118 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4119 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4121 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4122 (void *) &scpnt->cmnd, scpnt->cmd_len);
4124 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4125 fcp_rsp_iu->fcp_sns_len);
4126 memcpy(&scpnt->sense_buffer,
4127 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4128 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4129 (void *) &scpnt->sense_buffer, sns_len);
4132 /* check for overrun */
4133 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4134 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4135 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4136 "The response data length is "
4137 "%d, the original length was %d.\n",
4140 zfcp_get_busid_by_unit(unit),
4141 fcp_rsp_iu->fcp_resid,
4142 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4145 /* check for underrun */
4146 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4147 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4148 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4149 "The response data length is "
4150 "%d, the original length was %d.\n",
4153 zfcp_get_busid_by_unit(unit),
4154 fcp_rsp_iu->fcp_resid,
4155 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4157 scpnt->resid = fcp_rsp_iu->fcp_resid;
4158 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4159 set_host_byte(&scpnt->result, DID_ERROR);
4163 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4165 if (scpnt->result != 0)
4166 zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
4167 else if (scpnt->retries > 0)
4168 zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
4170 zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
4172 /* cleanup pointer (need this especially for abort) */
4173 scpnt->host_scribble = NULL;
4175 /* always call back */
4176 (scpnt->scsi_done) (scpnt);
4179 * We must hold this lock until scsi_done has been called.
4180 * Otherwise we may call scsi_done after abort regarding this
4181 * command has completed.
4182 * Note: scsi_done must not block!
4185 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4190 * function: zfcp_fsf_send_fcp_command_task_management_handler
4192 * purpose: evaluates FCP_RSP IU
4197 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4200 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4201 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4202 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4203 struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
4205 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4206 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4207 goto skip_fsfstatus;
4210 /* check FCP_RSP_INFO */
4211 switch (fcp_rsp_info[3]) {
4214 ZFCP_LOG_DEBUG("no failure or Task Management "
4215 "Function complete\n");
4217 case RSP_CODE_TASKMAN_UNSUPP:
4218 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4219 "is not supported on the target device "
4220 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4223 zfcp_get_busid_by_unit(unit));
4224 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4226 case RSP_CODE_TASKMAN_FAILED:
4227 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4228 "failed to complete successfully. "
4229 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4232 zfcp_get_busid_by_unit(unit));
4233 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4236 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4237 "code was detected for a command. "
4238 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4239 "(debug info 0x%x)\n",
4242 zfcp_get_busid_by_unit(unit),
4244 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4253 * function: zfcp_fsf_control_file
4255 * purpose: Initiator of the control file upload/download FSF requests
4257 * returns: 0 - FSF request is successfuly created and queued
4258 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4259 * -EINVAL - Invalid direction specified
4260 * -ENOMEM - Insufficient memory
4261 * -EPERM - Cannot create FSF request or place it in QDIO queue
4264 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4265 struct zfcp_fsf_req **fsf_req_ptr,
4268 struct zfcp_sg_list *sg_list)
4270 struct zfcp_fsf_req *fsf_req;
4271 struct fsf_qtcb_bottom_support *bottom;
4272 volatile struct qdio_buffer_element *sbale;
4273 unsigned long lock_flags;
4278 if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
4279 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4280 zfcp_get_busid_by_adapter(adapter));
4281 retval = -EOPNOTSUPP;
4285 switch (fsf_command) {
4287 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4288 direction = SBAL_FLAGS0_TYPE_WRITE;
4289 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4290 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4291 req_flags = ZFCP_WAIT_FOR_SBAL;
4294 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4295 direction = SBAL_FLAGS0_TYPE_READ;
4299 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4304 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4305 NULL, &lock_flags, &fsf_req);
4307 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4309 zfcp_get_busid_by_adapter(adapter));
4311 goto unlock_queue_lock;
4314 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4315 sbale[0].flags |= direction;
4317 bottom = &fsf_req->qtcb->bottom.support;
4318 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4319 bottom->option = option;
4321 if (sg_list->count > 0) {
4324 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4325 sg_list->sg, sg_list->count,
4326 ZFCP_MAX_SBALS_PER_REQ);
4327 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4329 "error: Could not create sufficient number of "
4330 "SBALS for an FSF request to the adapter %s\n",
4331 zfcp_get_busid_by_adapter(adapter));
4336 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4338 zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
4339 retval = zfcp_fsf_req_send(fsf_req);
4341 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4343 zfcp_get_busid_by_adapter(adapter));
4347 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4349 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4351 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4352 "download" : "upload",
4353 zfcp_get_busid_by_adapter(adapter));
4355 wait_event(fsf_req->completion_wq,
4356 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4358 *fsf_req_ptr = fsf_req;
4362 zfcp_fsf_req_free(fsf_req);
4364 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4371 * function: zfcp_fsf_control_file_handler
4373 * purpose: Handler of the control file upload/download FSF requests
4375 * returns: 0 - FSF request successfuly processed
4376 * -EAGAIN - Operation has to be repeated because of a temporary problem
4377 * -EACCES - There is no permission to execute an operation
4378 * -EPERM - The control file is not in a right format
4379 * -EIO - There is a problem with the FCP adapter
4380 * -EINVAL - Invalid operation
4381 * -EFAULT - User space memory I/O operation fault
4384 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4386 struct zfcp_adapter *adapter = fsf_req->adapter;
4387 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4388 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4391 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4393 goto skip_fsfstatus;
4396 switch (header->fsf_status) {
4400 "The FSF request has been successfully completed "
4401 "on the adapter %s\n",
4402 zfcp_get_busid_by_adapter(adapter));
4405 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4406 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4407 switch (header->fsf_status_qual.word[0]) {
4409 case FSF_SQ_CFDC_HARDENED_ON_SE:
4411 "CFDC on the adapter %s has being "
4412 "hardened on primary and secondary SE\n",
4413 zfcp_get_busid_by_adapter(adapter));
4416 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4418 "CFDC of the adapter %s could not "
4419 "be saved on the SE\n",
4420 zfcp_get_busid_by_adapter(adapter));
4423 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4425 "CFDC of the adapter %s could not "
4426 "be copied to the secondary SE\n",
4427 zfcp_get_busid_by_adapter(adapter));
4432 "CFDC could not be hardened "
4433 "on the adapter %s\n",
4434 zfcp_get_busid_by_adapter(adapter));
4437 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4441 case FSF_AUTHORIZATION_FAILURE:
4443 "Adapter %s does not accept privileged commands\n",
4444 zfcp_get_busid_by_adapter(adapter));
4445 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4449 case FSF_CFDC_ERROR_DETECTED:
4451 "Error at position %d in the CFDC, "
4452 "CFDC is discarded by the adapter %s\n",
4453 header->fsf_status_qual.word[0],
4454 zfcp_get_busid_by_adapter(adapter));
4455 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4459 case FSF_CONTROL_FILE_UPDATE_ERROR:
4461 "Adapter %s cannot harden the control file, "
4462 "file is discarded\n",
4463 zfcp_get_busid_by_adapter(adapter));
4464 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4468 case FSF_CONTROL_FILE_TOO_LARGE:
4470 "Control file is too large, file is discarded "
4471 "by the adapter %s\n",
4472 zfcp_get_busid_by_adapter(adapter));
4473 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4477 case FSF_ACCESS_CONFLICT_DETECTED:
4478 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4480 "CFDC has been discarded by the adapter %s, "
4481 "because activation would impact "
4482 "%d active connection(s)\n",
4483 zfcp_get_busid_by_adapter(adapter),
4484 header->fsf_status_qual.word[0]);
4485 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4489 case FSF_CONFLICTS_OVERRULED:
4490 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4492 "CFDC has been activated on the adapter %s, "
4493 "but activation has impacted "
4494 "%d active connection(s)\n",
4495 zfcp_get_busid_by_adapter(adapter),
4496 header->fsf_status_qual.word[0]);
4497 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4501 case FSF_UNKNOWN_OP_SUBTYPE:
4502 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4503 "op_subtype=0x%x)\n",
4504 zfcp_get_busid_by_adapter(adapter),
4505 bottom->operation_subtype);
4506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4510 case FSF_INVALID_COMMAND_OPTION:
4512 "Invalid option 0x%x has been specified "
4513 "in QTCB bottom sent to the adapter %s\n",
4515 zfcp_get_busid_by_adapter(adapter));
4516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4522 "bug: An unknown/unexpected FSF status 0x%08x "
4523 "was presented on the adapter %s\n",
4525 zfcp_get_busid_by_adapter(adapter));
4526 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4527 debug_exception(fsf_req->adapter->erp_dbf, 0,
4528 &header->fsf_status_qual.word[0], sizeof(u32));
4529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4539 zfcp_fsf_req_sbal_check(unsigned long *flags,
4540 struct zfcp_qdio_queue *queue, int needed)
4542 write_lock_irqsave(&queue->queue_lock, *flags);
4543 if (likely(atomic_read(&queue->free_count) >= needed))
4545 write_unlock_irqrestore(&queue->queue_lock, *flags);
4550 * set qtcb pointer in fsf_req and initialize QTCB
4553 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
4555 if (likely(fsf_req->qtcb != NULL)) {
4556 fsf_req->qtcb->prefix.req_seq_no =
4557 fsf_req->adapter->fsf_req_seq_no;
4558 fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
4559 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4560 fsf_req->qtcb->prefix.qtcb_type =
4561 fsf_qtcb_type[fsf_req->fsf_command];
4562 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4563 fsf_req->qtcb->header.req_handle = fsf_req->req_id;
4564 fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
4569 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4570 * @adapter: adapter for which request queue is examined
4571 * @req_flags: flags indicating whether to wait for needed SBAL or not
4572 * @lock_flags: lock_flags if queue_lock is taken
4573 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4574 * Locks: lock adapter->request_queue->queue_lock on success
4577 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4578 unsigned long *lock_flags)
4581 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4583 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4584 ret = wait_event_interruptible_timeout(adapter->request_wq,
4585 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4591 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4598 * function: zfcp_fsf_req_create
4600 * purpose: create an FSF request at the specified adapter and
4601 * setup common fields
4603 * returns: -ENOMEM if there was insufficient memory for a request
4604 * -EIO if no qdio buffers could be allocate to the request
4605 * -EINVAL/-EPERM on bug conditions in req_dequeue
4608 * note: The created request is returned by reference.
4610 * locks: lock of concerned request queue must not be held,
4611 * but is held on completion (write, irqsave)
4614 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4615 mempool_t *pool, unsigned long *lock_flags,
4616 struct zfcp_fsf_req **fsf_req_p)
4618 volatile struct qdio_buffer_element *sbale;
4619 struct zfcp_fsf_req *fsf_req = NULL;
4621 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4623 /* allocate new FSF request */
4624 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4625 if (unlikely(NULL == fsf_req)) {
4626 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4627 "the outbound (send) queue.\n");
4629 goto failed_fsf_req;
4632 fsf_req->adapter = adapter;
4633 fsf_req->fsf_command = fsf_cmd;
4634 INIT_LIST_HEAD(&fsf_req->list);
4635 init_timer(&fsf_req->timer);
4637 /* initialize waitqueue which may be used to wait on
4638 this request completion */
4639 init_waitqueue_head(&fsf_req->completion_wq);
4641 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4645 /* this is serialized (we are holding req_queue-lock of adapter) */
4646 if (adapter->req_no == 0)
4648 fsf_req->req_id = adapter->req_no++;
4650 zfcp_fsf_req_qtcb_init(fsf_req);
4653 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4654 * if it is not set (see also *_open_qdio and *_close_qdio).
4657 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4658 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4663 if (fsf_req->qtcb) {
4664 fsf_req->seq_no = adapter->fsf_req_seq_no;
4665 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4667 fsf_req->sbal_number = 1;
4668 fsf_req->sbal_first = req_queue->free_index;
4669 fsf_req->sbal_curr = req_queue->free_index;
4670 fsf_req->sbale_curr = 1;
4672 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4673 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4676 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4678 /* setup common SBALE fields */
4679 sbale[0].addr = (void *) fsf_req->req_id;
4680 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4681 if (likely(fsf_req->qtcb != NULL)) {
4682 sbale[1].addr = (void *) fsf_req->qtcb;
4683 sbale[1].length = sizeof(struct fsf_qtcb);
4686 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4687 fsf_req->sbal_number, fsf_req->sbal_first);
4692 /* dequeue new FSF request previously enqueued */
4693 zfcp_fsf_req_free(fsf_req);
4697 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4699 *fsf_req_p = fsf_req;
4704 * function: zfcp_fsf_req_send
4706 * purpose: start transfer of FSF request via QDIO
4708 * returns: 0 - request transfer succesfully started
4709 * !0 - start of request transfer failed
4711 static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
4713 struct zfcp_adapter *adapter;
4714 struct zfcp_qdio_queue *req_queue;
4715 volatile struct qdio_buffer_element *sbale;
4717 int new_distance_from_int;
4721 adapter = fsf_req->adapter;
4722 req_queue = &adapter->request_queue,
4725 /* FIXME(debug): remove it later */
4726 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4727 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4728 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4729 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4732 /* put allocated FSF request into hash table */
4733 spin_lock(&adapter->req_list_lock);
4734 zfcp_reqlist_add(adapter, fsf_req);
4735 spin_unlock(&adapter->req_list_lock);
4737 inc_seq_no = (fsf_req->qtcb != NULL);
4739 ZFCP_LOG_TRACE("request queue of adapter %s: "
4740 "next free SBAL is %i, %i free SBALs\n",
4741 zfcp_get_busid_by_adapter(adapter),
4742 req_queue->free_index,
4743 atomic_read(&req_queue->free_count));
4745 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4746 "index_in_queue=%i, count=%i, buffers=%p\n",
4747 zfcp_get_busid_by_adapter(adapter),
4748 QDIO_FLAG_SYNC_OUTPUT,
4749 0, fsf_req->sbal_first, fsf_req->sbal_number,
4750 &req_queue->buffer[fsf_req->sbal_first]);
4753 * adjust the number of free SBALs in request queue as well as
4754 * position of first one
4756 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4757 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4758 req_queue->free_index += fsf_req->sbal_number; /* increase */
4759 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4760 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4762 fsf_req->issued = get_clock();
4764 retval = do_QDIO(adapter->ccw_device,
4765 QDIO_FLAG_SYNC_OUTPUT,
4766 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4768 dbg_tmp[0] = (unsigned long) sbale[0].addr;
4769 dbg_tmp[1] = (u64) retval;
4770 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
4772 if (unlikely(retval)) {
4773 /* Queues are down..... */
4775 del_timer(&fsf_req->timer);
4776 spin_lock(&adapter->req_list_lock);
4777 zfcp_reqlist_remove(adapter, fsf_req);
4778 spin_unlock(&adapter->req_list_lock);
4779 /* undo changes in request queue made for this request */
4780 zfcp_qdio_zero_sbals(req_queue->buffer,
4781 fsf_req->sbal_first, fsf_req->sbal_number);
4782 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4783 req_queue->free_index -= fsf_req->sbal_number;
4784 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4785 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4786 zfcp_erp_adapter_reopen(adapter, 0);
4788 req_queue->distance_from_int = new_distance_from_int;
4790 * increase FSF sequence counter -
4791 * this must only be done for request successfully enqueued to
4792 * QDIO this rejected requests may be cleaned up by calling
4793 * routines resulting in missing sequence counter values
4797 /* Don't increase for unsolicited status */
4799 adapter->fsf_req_seq_no++;
4801 /* count FSF requests pending */
4802 atomic_inc(&adapter->reqs_active);
4807 #undef ZFCP_LOG_AREA