3 * linux/drivers/s390/scsi/zfcp_fsf.c
5 * FCP adapter driver for IBM eServer zSeries
7 * (C) Copyright IBM Corp. 2002, 2004
9 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
10 * Raimund Schroeder <raimund.schroeder@de.ibm.com>
13 * Stefan Bader <stefan.bader@de.ibm.com>
14 * Heiko Carstens <heiko.carstens@de.ibm.com>
15 * Andreas Herrmann <aherrman@de.ibm.com>
16 * Volker Sameske <sameske@de.ibm.com>
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #define ZFCP_FSF_C_REVISION "$Revision: 1.92 $"
37 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
38 static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
45 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
46 static int zfcp_fsf_send_fcp_command_task_management_handler(
47 struct zfcp_fsf_req *);
48 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
51 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
52 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
53 static inline int zfcp_fsf_req_sbal_check(
54 unsigned long *, struct zfcp_qdio_queue *, int);
55 static inline int zfcp_use_one_sbal(
56 struct scatterlist *, int, struct scatterlist *, int);
57 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
58 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
59 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
60 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
61 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
62 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
63 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
64 static void zfcp_fsf_req_free(struct zfcp_fsf_req *);
66 /* association between FSF command and FSF QTCB type */
67 static u32 fsf_qtcb_type[] = {
68 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
69 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
76 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
77 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
78 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
79 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
80 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
83 static const char zfcp_act_subtable_type[5][8] = {
84 "unknown", "OS", "WWPN", "DID", "LUN"
87 /****************************************************************/
88 /*************** FSF related Functions *************************/
89 /****************************************************************/
91 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
94 * function: zfcp_fsf_req_alloc
96 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
97 * unsolicited requests) via helper functions
98 * Does some initial fsf request set-up.
100 * returns: pointer to allocated fsf_req if successfull
106 static struct zfcp_fsf_req *
107 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
111 struct zfcp_fsf_req *fsf_req = NULL;
113 if (req_flags & ZFCP_REQ_NO_QTCB)
114 size = sizeof(struct zfcp_fsf_req);
116 size = sizeof(struct zfcp_fsf_req_pool_element);
118 if (likely(pool != NULL))
119 ptr = mempool_alloc(pool, GFP_ATOMIC);
121 ptr = kmalloc(size, GFP_ATOMIC);
123 if (unlikely(NULL == ptr))
126 memset(ptr, 0, size);
128 if (req_flags & ZFCP_REQ_NO_QTCB) {
129 fsf_req = (struct zfcp_fsf_req *) ptr;
131 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
133 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
136 fsf_req->pool = pool;
143 * function: zfcp_fsf_req_free
145 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
146 * returns it into the pool via helper functions.
153 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
155 if (likely(fsf_req->pool != NULL))
156 mempool_free(fsf_req, fsf_req->pool);
168 * note: qdio queues shall be down (no ongoing inbound processing)
171 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
174 struct zfcp_fsf_req *fsf_req, *tmp;
176 list_for_each_entry_safe(fsf_req, tmp, &adapter->fsf_req_list_head,
178 zfcp_fsf_req_dismiss(fsf_req);
179 /* wait_event_timeout? */
180 while (!list_empty(&adapter->fsf_req_list_head)) {
181 ZFCP_LOG_DEBUG("fsf req list of adapter %s not yet empty\n",
182 zfcp_get_busid_by_adapter(adapter));
183 /* wait for woken intiators to clean up their requests */
184 msleep(jiffies_to_msecs(ZFCP_FSFREQ_CLEANUP_TIMEOUT));
187 /* consistency check */
188 if (atomic_read(&adapter->fsf_reqs_active)) {
189 ZFCP_LOG_NORMAL("bug: There are still %d FSF requests pending "
190 "on adapter %s after cleanup.\n",
191 atomic_read(&adapter->fsf_reqs_active),
192 zfcp_get_busid_by_adapter(adapter));
193 atomic_set(&adapter->fsf_reqs_active, 0);
207 zfcp_fsf_req_dismiss(struct zfcp_fsf_req *fsf_req)
209 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
210 zfcp_fsf_req_complete(fsf_req);
214 * function: zfcp_fsf_req_complete
216 * purpose: Updates active counts and timers for openfcp-reqs
217 * May cleanup request after req_eval returns
219 * returns: 0 - success
225 zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
229 struct zfcp_adapter *adapter = fsf_req->adapter;
231 /* do some statistics */
232 atomic_dec(&adapter->fsf_reqs_active);
234 if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
235 ZFCP_LOG_DEBUG("Status read response received\n");
237 * Note: all cleanup handling is done in the callchain of
238 * the function call-chain below.
240 zfcp_fsf_status_read_handler(fsf_req);
243 zfcp_fsf_protstatus_eval(fsf_req);
246 * fsf_req may be deleted due to waking up functions, so
247 * cleanup is saved here and used later
249 if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
254 fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
256 /* cleanup request if requested by initiator */
257 if (likely(cleanup)) {
258 ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
260 * lock must not be held here since it will be
261 * grabed by the called routine, too
263 zfcp_fsf_req_cleanup(fsf_req);
265 /* notify initiator waiting for the requests completion */
266 ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
268 * FIXME: Race! We must not access fsf_req here as it might have been
269 * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
270 * flag. It's an improbable case. But, we have the same paranoia for
271 * the cleanup flag already.
272 * Might better be handled using complete()?
273 * (setting the flag and doing wakeup ought to be atomic
274 * with regard to checking the flag as long as waitqueue is
275 * part of the to be released structure)
277 wake_up(&fsf_req->completion_wq);
285 * function: zfcp_fsf_protstatus_eval
287 * purpose: evaluates the QTCB of the finished FSF request
288 * and initiates appropriate actions
289 * (usually calling FSF command specific handlers)
298 zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
301 struct zfcp_adapter *adapter = fsf_req->adapter;
303 ZFCP_LOG_DEBUG("QTCB is at %p\n", fsf_req->qtcb);
305 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
306 ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
307 (unsigned long) fsf_req);
308 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
309 ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
310 zfcp_cmd_dbf_event_fsf("dismiss", fsf_req, NULL, 0);
311 goto skip_protstatus;
314 /* log additional information provided by FSF (if any) */
315 if (unlikely(fsf_req->qtcb->header.log_length)) {
316 /* do not trust them ;-) */
317 if (fsf_req->qtcb->header.log_start > sizeof(struct fsf_qtcb)) {
319 ("bug: ULP (FSF logging) log data starts "
320 "beyond end of packet header. Ignored. "
321 "(start=%i, size=%li)\n",
322 fsf_req->qtcb->header.log_start,
323 sizeof(struct fsf_qtcb));
326 if ((size_t) (fsf_req->qtcb->header.log_start +
327 fsf_req->qtcb->header.log_length)
328 > sizeof(struct fsf_qtcb)) {
329 ZFCP_LOG_NORMAL("bug: ULP (FSF logging) log data ends "
330 "beyond end of packet header. Ignored. "
331 "(start=%i, length=%i, size=%li)\n",
332 fsf_req->qtcb->header.log_start,
333 fsf_req->qtcb->header.log_length,
334 sizeof(struct fsf_qtcb));
337 ZFCP_LOG_TRACE("ULP log data: \n");
338 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
339 (char *) fsf_req->qtcb +
340 fsf_req->qtcb->header.log_start,
341 fsf_req->qtcb->header.log_length);
345 /* evaluate FSF Protocol Status */
346 switch (fsf_req->qtcb->prefix.prot_status) {
349 case FSF_PROT_FSF_STATUS_PRESENTED:
352 case FSF_PROT_QTCB_VERSION_ERROR:
353 ZFCP_LOG_NORMAL("error: The adapter %s contains "
354 "microcode of version 0x%x, the device driver "
355 "only supports 0x%x. Aborting.\n",
356 zfcp_get_busid_by_adapter(adapter),
357 fsf_req->qtcb->prefix.prot_status_qual.
358 version_error.fsf_version, ZFCP_QTCB_VERSION);
359 /* stop operation for this adapter */
360 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
361 zfcp_erp_adapter_shutdown(adapter, 0);
362 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
363 &fsf_req->qtcb->prefix.prot_status_qual,
364 sizeof (union fsf_prot_status_qual));
365 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
368 case FSF_PROT_SEQ_NUMB_ERROR:
369 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
370 "driver (0x%x) and adapter %s (0x%x). "
371 "Restarting all operations on this adapter.\n",
372 fsf_req->qtcb->prefix.req_seq_no,
373 zfcp_get_busid_by_adapter(adapter),
374 fsf_req->qtcb->prefix.prot_status_qual.
375 sequence_error.exp_req_seq_no);
376 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
377 /* restart operation on this adapter */
378 zfcp_erp_adapter_reopen(adapter, 0);
379 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
380 &fsf_req->qtcb->prefix.prot_status_qual,
381 sizeof (union fsf_prot_status_qual));
382 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
383 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
386 case FSF_PROT_UNSUPP_QTCB_TYPE:
387 ZFCP_LOG_NORMAL("error: Packet header type used by the "
388 "device driver is incompatible with "
389 "that used on adapter %s. "
390 "Stopping all operations on this adapter.\n",
391 zfcp_get_busid_by_adapter(adapter));
392 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
393 zfcp_erp_adapter_shutdown(adapter, 0);
394 zfcp_cmd_dbf_event_fsf("unsqtcbt", fsf_req,
395 &fsf_req->qtcb->prefix.prot_status_qual,
396 sizeof (union fsf_prot_status_qual));
397 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
400 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
401 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
402 &fsf_req->qtcb->prefix.prot_status_qual,
403 sizeof (union fsf_prot_status_qual));
404 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
405 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
407 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
410 case FSF_PROT_DUPLICATE_REQUEST_ID:
412 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
413 "to the adapter %s is ambiguous. "
414 "Stopping all operations on this "
416 *(unsigned long long *)
417 (&fsf_req->qtcb->bottom.support.
419 zfcp_get_busid_by_adapter(adapter));
421 ZFCP_LOG_NORMAL("bug: The request identifier %p "
422 "to the adapter %s is ambiguous. "
423 "Stopping all operations on this "
425 "(bug: got this for an unsolicited "
426 "status read request)\n",
428 zfcp_get_busid_by_adapter(adapter));
430 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
431 zfcp_erp_adapter_shutdown(adapter, 0);
432 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
433 &fsf_req->qtcb->prefix.prot_status_qual,
434 sizeof (union fsf_prot_status_qual));
435 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
438 case FSF_PROT_LINK_DOWN:
440 * 'test and set' is not atomic here -
441 * it's ok as long as calls to our response queue handler
442 * (and thus execution of this code here) are serialized
445 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
447 switch (fsf_req->qtcb->prefix.prot_status_qual.
448 locallink_error.code) {
449 case FSF_PSQ_LINK_NOLIGHT:
450 ZFCP_LOG_INFO("The local link to adapter %s "
451 "is down (no light detected).\n",
452 zfcp_get_busid_by_adapter(
455 case FSF_PSQ_LINK_WRAPPLUG:
456 ZFCP_LOG_INFO("The local link to adapter %s "
457 "is down (wrap plug detected).\n",
458 zfcp_get_busid_by_adapter(
461 case FSF_PSQ_LINK_NOFCP:
462 ZFCP_LOG_INFO("The local link to adapter %s "
463 "is down (adjacent node on "
464 "link does not support FCP).\n",
465 zfcp_get_busid_by_adapter(
469 ZFCP_LOG_INFO("The local link to adapter %s "
471 "(warning: unknown reason "
473 zfcp_get_busid_by_adapter(
479 * Due to the 'erp failed' flag the adapter won't
480 * be recovered but will be just set to 'blocked'
481 * state. All subordinary devices will have state
482 * 'blocked' and 'erp failed', too.
483 * Thus the adapter is still able to provide
484 * 'link up' status without being flooded with
486 * (note: even 'close port' is not permitted)
488 ZFCP_LOG_INFO("Stopping all operations for adapter "
490 zfcp_get_busid_by_adapter(adapter));
491 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
492 ZFCP_STATUS_COMMON_ERP_FAILED,
494 zfcp_erp_adapter_reopen(adapter, 0);
496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
499 case FSF_PROT_REEST_QUEUE:
500 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
501 ZFCP_LOG_INFO("The local link to adapter with "
502 "%s was re-plugged. "
503 "Re-starting operations on this adapter.\n",
504 zfcp_get_busid_by_adapter(adapter));
505 /* All ports should be marked as ready to run again */
506 zfcp_erp_modify_adapter_status(adapter,
507 ZFCP_STATUS_COMMON_RUNNING,
509 zfcp_erp_adapter_reopen(adapter,
510 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
511 | ZFCP_STATUS_COMMON_ERP_FAILED);
512 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
513 &fsf_req->qtcb->prefix.prot_status_qual,
514 sizeof (union fsf_prot_status_qual));
515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
518 case FSF_PROT_ERROR_STATE:
519 ZFCP_LOG_NORMAL("error: The adapter %s "
520 "has entered the error state. "
521 "Restarting all operations on this "
523 zfcp_get_busid_by_adapter(adapter));
524 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
525 /* restart operation on this adapter */
526 zfcp_erp_adapter_reopen(adapter, 0);
527 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
528 &fsf_req->qtcb->prefix.prot_status_qual,
529 sizeof (union fsf_prot_status_qual));
530 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
531 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
535 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
536 "provided by the adapter %s "
537 "is not compatible with the device driver. "
538 "Stopping all operations on this adapter. "
539 "(debug info 0x%x).\n",
540 zfcp_get_busid_by_adapter(adapter),
541 fsf_req->qtcb->prefix.prot_status);
542 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
543 debug_exception(adapter->erp_dbf, 0,
544 &fsf_req->qtcb->prefix.prot_status,
546 zfcp_erp_adapter_shutdown(adapter, 0);
547 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
552 * always call specific handlers to give them a chance to do
553 * something meaningful even in error cases
555 zfcp_fsf_fsfstatus_eval(fsf_req);
560 * function: zfcp_fsf_fsfstatus_eval
562 * purpose: evaluates FSF status of completed FSF request
563 * and acts accordingly
568 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
572 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
576 /* evaluate FSF Status */
577 switch (fsf_req->qtcb->header.fsf_status) {
578 case FSF_UNKNOWN_COMMAND:
579 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
580 "not known by the adapter %s "
581 "Stopping all operations on this adapter. "
582 "(debug info 0x%x).\n",
583 zfcp_get_busid_by_adapter(fsf_req->adapter),
584 fsf_req->qtcb->header.fsf_command);
585 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
587 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
588 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
589 &fsf_req->qtcb->header.fsf_status_qual,
590 sizeof (union fsf_status_qual));
591 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
594 case FSF_FCP_RSP_AVAILABLE:
595 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
597 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
600 case FSF_ADAPTER_STATUS_AVAILABLE:
601 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
602 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
611 * always call specific handlers to give them a chance to do
612 * something meaningful even in error cases
614 zfcp_fsf_req_dispatch(fsf_req);
620 * function: zfcp_fsf_fsfstatus_qual_eval
622 * purpose: evaluates FSF status-qualifier of completed FSF request
623 * and acts accordingly
628 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
632 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
633 case FSF_SQ_FCP_RSP_AVAILABLE:
634 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
636 case FSF_SQ_RETRY_IF_POSSIBLE:
637 /* The SCSI-stack may now issue retries or escalate */
638 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
639 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
640 &fsf_req->qtcb->header.fsf_status_qual,
641 sizeof (union fsf_status_qual));
642 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
644 case FSF_SQ_COMMAND_ABORTED:
645 /* Carry the aborted state on to upper layer */
646 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
647 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
648 &fsf_req->qtcb->header.fsf_status_qual,
649 sizeof (union fsf_status_qual));
650 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
651 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
653 case FSF_SQ_NO_RECOM:
654 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
656 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
657 "problem on the adapter %s "
658 "Stopping all operations on this adapter. ",
659 zfcp_get_busid_by_adapter(fsf_req->adapter));
660 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
661 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
662 &fsf_req->qtcb->header.fsf_status_qual,
663 sizeof (union fsf_status_qual));
664 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
666 case FSF_SQ_ULP_PROGRAMMING_ERROR:
667 ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
669 zfcp_get_busid_by_adapter(fsf_req->adapter));
670 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
672 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
674 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
675 case FSF_SQ_NO_RETRY_POSSIBLE:
676 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
677 /* dealt with in the respective functions */
680 ZFCP_LOG_NORMAL("bug: Additional status info could "
681 "not be interpreted properly.\n");
682 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
683 (char *) &fsf_req->qtcb->header.fsf_status_qual,
684 sizeof (union fsf_status_qual));
685 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
686 debug_exception(fsf_req->adapter->erp_dbf, 0,
687 &fsf_req->qtcb->header.fsf_status_qual.word[0],
689 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
690 &fsf_req->qtcb->header.fsf_status_qual,
691 sizeof (union fsf_status_qual));
692 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
700 * function: zfcp_fsf_req_dispatch
702 * purpose: calls the appropriate command specific handler
707 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
709 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
710 struct zfcp_adapter *adapter = fsf_req->adapter;
713 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
714 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
715 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
716 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
719 switch (fsf_req->fsf_command) {
721 case FSF_QTCB_FCP_CMND:
722 zfcp_fsf_send_fcp_command_handler(fsf_req);
725 case FSF_QTCB_ABORT_FCP_CMND:
726 zfcp_fsf_abort_fcp_command_handler(fsf_req);
729 case FSF_QTCB_SEND_GENERIC:
730 zfcp_fsf_send_ct_handler(fsf_req);
733 case FSF_QTCB_OPEN_PORT_WITH_DID:
734 zfcp_fsf_open_port_handler(fsf_req);
737 case FSF_QTCB_OPEN_LUN:
738 zfcp_fsf_open_unit_handler(fsf_req);
741 case FSF_QTCB_CLOSE_LUN:
742 zfcp_fsf_close_unit_handler(fsf_req);
745 case FSF_QTCB_CLOSE_PORT:
746 zfcp_fsf_close_port_handler(fsf_req);
749 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
750 zfcp_fsf_close_physical_port_handler(fsf_req);
753 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
754 zfcp_fsf_exchange_config_data_handler(fsf_req);
757 case FSF_QTCB_EXCHANGE_PORT_DATA:
758 zfcp_fsf_exchange_port_data_handler(fsf_req);
761 case FSF_QTCB_SEND_ELS:
762 zfcp_fsf_send_els_handler(fsf_req);
765 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
766 zfcp_fsf_control_file_handler(fsf_req);
769 case FSF_QTCB_UPLOAD_CONTROL_FILE:
770 zfcp_fsf_control_file_handler(fsf_req);
774 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
775 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
776 "not supported by the adapter %s\n",
777 zfcp_get_busid_by_adapter(fsf_req->adapter));
778 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
780 ("bug: Command issued by the device driver differs "
781 "from the command returned by the adapter %s "
782 "(debug info 0x%x, 0x%x).\n",
783 zfcp_get_busid_by_adapter(fsf_req->adapter),
784 fsf_req->fsf_command,
785 fsf_req->qtcb->header.fsf_command);
791 debug_text_event(adapter->erp_dbf, 3, "a_frh");
792 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
793 zfcp_erp_async_handler(erp_action, 0);
799 * function: zfcp_fsf_status_read
801 * purpose: initiates a Status Read command at the specified adapter
806 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
808 struct zfcp_fsf_req *fsf_req;
809 struct fsf_status_read_buffer *status_buffer;
810 unsigned long lock_flags;
811 volatile struct qdio_buffer_element *sbale;
814 /* setup new FSF request */
815 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
816 req_flags | ZFCP_REQ_NO_QTCB,
817 adapter->pool.fsf_req_status_read,
818 &lock_flags, &fsf_req);
820 ZFCP_LOG_INFO("error: Could not create unsolicited status "
821 "buffer for adapter %s.\n",
822 zfcp_get_busid_by_adapter(adapter));
823 goto failed_req_create;
826 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
827 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
828 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
829 fsf_req->sbale_curr = 2;
832 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
833 if (!status_buffer) {
834 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
837 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
838 fsf_req->data.status_read.buffer = status_buffer;
840 /* insert pointer to respective buffer */
841 sbale = zfcp_qdio_sbale_curr(fsf_req);
842 sbale->addr = (void *) status_buffer;
843 sbale->length = sizeof(struct fsf_status_read_buffer);
845 /* start QDIO request for this FSF request */
846 retval = zfcp_fsf_req_send(fsf_req, NULL);
848 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
850 goto failed_req_send;
853 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
854 zfcp_get_busid_by_adapter(adapter));
858 mempool_free(status_buffer, adapter->pool.data_status_read);
861 zfcp_fsf_req_free(fsf_req);
864 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
869 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
871 struct fsf_status_read_buffer *status_buffer;
872 struct zfcp_adapter *adapter;
873 struct zfcp_port *port;
876 status_buffer = fsf_req->data.status_read.buffer;
877 adapter = fsf_req->adapter;
879 read_lock_irqsave(&zfcp_data.config_lock, flags);
880 list_for_each_entry(port, &adapter->port_list_head, list)
881 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
883 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
885 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
886 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
887 "nonexisting port with d_id 0x%08x on "
888 "adapter %s. Ignored.\n",
889 status_buffer->d_id & ZFCP_DID_MASK,
890 zfcp_get_busid_by_adapter(adapter));
894 switch (status_buffer->status_subtype) {
896 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
897 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
898 zfcp_erp_port_reopen(port, 0);
901 case FSF_STATUS_READ_SUB_ERROR_PORT:
902 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
903 zfcp_erp_port_shutdown(port, 0);
907 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
908 debug_exception(adapter->erp_dbf, 0,
909 &status_buffer->status_subtype, sizeof (u32));
910 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
911 "for a reopen indication on port with "
912 "d_id 0x%08x on the adapter %s. "
913 "Ignored. (debug info 0x%x)\n",
915 zfcp_get_busid_by_adapter(adapter),
916 status_buffer->status_subtype);
923 * function: zfcp_fsf_status_read_handler
925 * purpose: is called for finished Open Port command
930 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
933 struct zfcp_adapter *adapter = fsf_req->adapter;
934 struct fsf_status_read_buffer *status_buffer =
935 fsf_req->data.status_read.buffer;
937 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
938 mempool_free(status_buffer, adapter->pool.data_status_read);
939 zfcp_fsf_req_cleanup(fsf_req);
943 switch (status_buffer->status_type) {
945 case FSF_STATUS_READ_PORT_CLOSED:
946 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
947 debug_event(adapter->erp_dbf, 3,
948 &status_buffer->d_id, sizeof (u32));
949 zfcp_fsf_status_read_port_closed(fsf_req);
952 case FSF_STATUS_READ_INCOMING_ELS:
953 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
954 zfcp_fsf_incoming_els(fsf_req);
957 case FSF_STATUS_READ_SENSE_DATA_AVAIL:
958 debug_text_event(adapter->erp_dbf, 3, "unsol_sense:");
959 ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
960 zfcp_get_busid_by_adapter(adapter));
961 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL, (char *) status_buffer,
962 sizeof(struct fsf_status_read_buffer));
965 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
966 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
967 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
968 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
969 (char *) status_buffer,
970 sizeof (struct fsf_status_read_buffer));
973 case FSF_STATUS_READ_LINK_DOWN:
974 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
975 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
976 zfcp_get_busid_by_adapter(adapter));
977 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
979 zfcp_erp_adapter_failed(adapter);
982 case FSF_STATUS_READ_LINK_UP:
983 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
984 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
985 "Restarting operations on this adapter\n",
986 zfcp_get_busid_by_adapter(adapter));
987 /* All ports should be marked as ready to run again */
988 zfcp_erp_modify_adapter_status(adapter,
989 ZFCP_STATUS_COMMON_RUNNING,
991 zfcp_erp_adapter_reopen(adapter,
992 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
993 | ZFCP_STATUS_COMMON_ERP_FAILED);
996 case FSF_STATUS_READ_CFDC_UPDATED:
997 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
998 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
999 zfcp_get_busid_by_adapter(adapter));
1000 zfcp_erp_adapter_access_changed(adapter);
1003 case FSF_STATUS_READ_CFDC_HARDENED:
1004 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
1005 switch (status_buffer->status_subtype) {
1006 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1007 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
1008 zfcp_get_busid_by_adapter(adapter));
1010 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1011 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
1012 "to the secondary SE\n",
1013 zfcp_get_busid_by_adapter(adapter));
1016 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1017 zfcp_get_busid_by_adapter(adapter));
1022 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1023 debug_exception(adapter->erp_dbf, 0,
1024 &status_buffer->status_type, sizeof (u32));
1025 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1026 "type was received (debug info 0x%x)\n",
1027 status_buffer->status_type);
1028 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1030 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1031 (char *) status_buffer,
1032 sizeof (struct fsf_status_read_buffer));
1035 mempool_free(status_buffer, adapter->pool.data_status_read);
1036 zfcp_fsf_req_cleanup(fsf_req);
1038 * recycle buffer and start new request repeat until outbound
1039 * queue is empty or adapter shutdown is requested
1043 * we may wait in the req_create for 5s during shutdown, so
1044 * qdio_cleanup will have to wait at least that long before returning
1045 * with failure to allow us a proper cleanup under all circumstances
1049 * allocation failure possible? (Is this code needed?)
1051 retval = zfcp_fsf_status_read(adapter, 0);
1053 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1054 "request for the adapter %s.\n",
1055 zfcp_get_busid_by_adapter(adapter));
1056 /* temporary fix to avoid status read buffer shortage */
1057 adapter->status_read_failed++;
1058 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1059 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1060 ZFCP_LOG_INFO("restart adapter %s due to status read "
1061 "buffer shortage\n",
1062 zfcp_get_busid_by_adapter(adapter));
1063 zfcp_erp_adapter_reopen(adapter, 0);
1071 * function: zfcp_fsf_abort_fcp_command
1073 * purpose: tells FSF to abort a running SCSI command
1075 * returns: address of initiated FSF request
1076 * NULL - request could not be initiated
1078 * FIXME(design): should be watched by a timeout !!!
1079 * FIXME(design) shouldn't this be modified to return an int
1080 * also...don't know how though
1082 struct zfcp_fsf_req *
1083 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1084 struct zfcp_adapter *adapter,
1085 struct zfcp_unit *unit, int req_flags)
1087 volatile struct qdio_buffer_element *sbale;
1088 unsigned long lock_flags;
1089 struct zfcp_fsf_req *fsf_req = NULL;
1092 /* setup new FSF request */
1093 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1094 req_flags, adapter->pool.fsf_req_abort,
1095 &lock_flags, &fsf_req);
1097 ZFCP_LOG_INFO("error: Failed to create an abort command "
1098 "request for lun 0x%016Lx on port 0x%016Lx "
1102 zfcp_get_busid_by_adapter(adapter));
1106 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1107 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1108 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1110 fsf_req->data.abort_fcp_command.unit = unit;
1112 /* set handles of unit and its parent port in QTCB */
1113 fsf_req->qtcb->header.lun_handle = unit->handle;
1114 fsf_req->qtcb->header.port_handle = unit->port->handle;
1116 /* set handle of request which should be aborted */
1117 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1119 /* start QDIO request for this FSF request */
1121 zfcp_fsf_start_scsi_er_timer(adapter);
1122 retval = zfcp_fsf_req_send(fsf_req, NULL);
1124 del_timer(&adapter->scsi_er_timer);
1125 ZFCP_LOG_INFO("error: Failed to send abort command request "
1126 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1127 zfcp_get_busid_by_adapter(adapter),
1128 unit->port->wwpn, unit->fcp_lun);
1129 zfcp_fsf_req_free(fsf_req);
1134 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1135 "(adapter%s, port d_id=0x%08x, "
1136 "unit x%016Lx, old_req_id=0x%lx)\n",
1137 zfcp_get_busid_by_adapter(adapter),
1139 unit->fcp_lun, old_req_id);
1141 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1146 * function: zfcp_fsf_abort_fcp_command_handler
1148 * purpose: is called for finished Abort FCP Command request
1153 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1155 int retval = -EINVAL;
1156 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1157 unsigned char status_qual =
1158 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1160 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1162 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1163 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1164 goto skip_fsfstatus;
1167 /* evaluate FSF status in QTCB */
1168 switch (new_fsf_req->qtcb->header.fsf_status) {
1170 case FSF_PORT_HANDLE_NOT_VALID:
1171 if (status_qual >> 4 != status_qual % 0xf) {
1172 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1175 * In this case a command that was sent prior to a port
1176 * reopen was aborted (handles are different). This is
1180 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1181 "port 0x%016Lx on adapter %s invalid. "
1182 "This may happen occasionally.\n",
1185 zfcp_get_busid_by_unit(unit));
1186 ZFCP_LOG_INFO("status qualifier:\n");
1187 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1188 (char *) &new_fsf_req->qtcb->header.
1190 sizeof (union fsf_status_qual));
1191 /* Let's hope this sorts out the mess */
1192 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1194 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1195 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1199 case FSF_LUN_HANDLE_NOT_VALID:
1200 if (status_qual >> 4 != status_qual % 0xf) {
1202 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1205 * In this case a command that was sent prior to a unit
1206 * reopen was aborted (handles are different).
1211 ("Warning: Temporary LUN identifier 0x%x of LUN "
1212 "0x%016Lx on port 0x%016Lx on adapter %s is "
1213 "invalid. This may happen in rare cases. "
1214 "Trying to re-establish link.\n",
1218 zfcp_get_busid_by_unit(unit));
1219 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1220 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1221 (char *) &new_fsf_req->qtcb->header.
1223 sizeof (union fsf_status_qual));
1224 /* Let's hope this sorts out the mess */
1225 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1227 zfcp_erp_port_reopen(unit->port, 0);
1228 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1232 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1234 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1236 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1239 case FSF_PORT_BOXED:
1240 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1241 "be reopened\n", unit->port->wwpn,
1242 zfcp_get_busid_by_unit(unit));
1243 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1245 zfcp_erp_port_reopen(unit->port, 0);
1246 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1247 | ZFCP_STATUS_FSFREQ_RETRY;
1252 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
1254 unit->fcp_lun, unit->port->wwpn,
1255 zfcp_get_busid_by_unit(unit));
1256 debug_text_event(new_fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
1257 zfcp_erp_unit_reopen(unit, 0);
1258 zfcp_cmd_dbf_event_fsf("unitbox", new_fsf_req,
1259 &new_fsf_req->qtcb->header.fsf_status_qual,
1260 sizeof(union fsf_status_qual));
1261 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1262 | ZFCP_STATUS_FSFREQ_RETRY;
1265 case FSF_ADAPTER_STATUS_AVAILABLE:
1266 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1267 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1268 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1270 zfcp_test_link(unit->port);
1271 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1273 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1274 /* SCSI stack will escalate */
1275 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1277 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1281 ("bug: Wrong status qualifier 0x%x arrived.\n",
1282 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1283 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1285 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1286 &new_fsf_req->qtcb->header.
1287 fsf_status_qual.word[0], sizeof (u32));
1294 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1298 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1299 "(debug info 0x%x)\n",
1300 new_fsf_req->qtcb->header.fsf_status);
1301 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1303 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1304 &new_fsf_req->qtcb->header.fsf_status,
1313 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1315 * Two scatter-gather lists are passed, one for the reqeust and one for the
1319 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1320 struct scatterlist *resp, int resp_count)
1322 return ((req_count == 1) &&
1323 (resp_count == 1) &&
1324 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1326 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1327 req[0].length - 1) & PAGE_MASK)) &&
1328 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1330 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1331 resp[0].length - 1) & PAGE_MASK)));
1335 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1336 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1338 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1339 * a struct zfcp_fsf_req
1340 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1341 * is sent within error recovery
1344 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1345 struct zfcp_erp_action *erp_action)
1347 volatile struct qdio_buffer_element *sbale;
1348 struct zfcp_port *port;
1349 struct zfcp_adapter *adapter;
1350 struct zfcp_fsf_req *fsf_req;
1351 unsigned long lock_flags;
1356 adapter = port->adapter;
1358 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1359 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1360 pool, &lock_flags, &fsf_req);
1362 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1364 zfcp_get_busid_by_adapter(adapter));
1368 if (erp_action != NULL) {
1369 erp_action->fsf_req = fsf_req;
1370 fsf_req->erp_action = erp_action;
1373 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1374 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1375 ct->resp, ct->resp_count)){
1376 /* both request buffer and response buffer
1377 fit into one sbale each */
1378 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1379 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1380 sbale[2].length = ct->req[0].length;
1381 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1382 sbale[3].length = ct->resp[0].length;
1383 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1384 } else if (adapter->supported_features &
1385 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1386 /* try to use chained SBALs */
1387 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1388 SBAL_FLAGS0_TYPE_WRITE_READ,
1389 ct->req, ct->req_count,
1390 ZFCP_MAX_SBALS_PER_CT_REQ);
1392 ZFCP_LOG_INFO("error: creation of CT request failed "
1394 zfcp_get_busid_by_adapter(adapter));
1402 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1403 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1404 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1405 SBAL_FLAGS0_TYPE_WRITE_READ,
1406 ct->resp, ct->resp_count,
1407 ZFCP_MAX_SBALS_PER_CT_REQ);
1409 ZFCP_LOG_INFO("error: creation of CT request failed "
1411 zfcp_get_busid_by_adapter(adapter));
1419 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1421 /* reject send generic request */
1423 "error: microcode does not support chained SBALs,"
1424 "CT request too big (adapter %s)\n",
1425 zfcp_get_busid_by_adapter(adapter));
1430 /* settings in QTCB */
1431 fsf_req->qtcb->header.port_handle = port->handle;
1432 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1433 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1434 fsf_req->data.send_ct = ct;
1436 /* start QDIO request for this FSF request */
1437 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1439 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1440 "(adapter %s, port 0x%016Lx)\n",
1441 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1445 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1446 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1450 zfcp_fsf_req_free(fsf_req);
1451 if (erp_action != NULL) {
1452 erp_action->fsf_req = NULL;
1456 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1462 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1463 * @fsf_req: pointer to struct zfcp_fsf_req
1465 * Data specific for the Generic Service request is passed by
1466 * fsf_req->data.send_ct
1467 * Usually a specific handler for the request is called via
1468 * fsf_req->data.send_ct->handler at end of this function.
1471 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1473 struct zfcp_port *port;
1474 struct zfcp_adapter *adapter;
1475 struct zfcp_send_ct *send_ct;
1476 struct fsf_qtcb_header *header;
1477 struct fsf_qtcb_bottom_support *bottom;
1478 int retval = -EINVAL;
1479 u16 subtable, rule, counter;
1481 adapter = fsf_req->adapter;
1482 send_ct = fsf_req->data.send_ct;
1483 port = send_ct->port;
1484 header = &fsf_req->qtcb->header;
1485 bottom = &fsf_req->qtcb->bottom.support;
1487 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1488 goto skip_fsfstatus;
1490 /* evaluate FSF status in QTCB */
1491 switch (header->fsf_status) {
1497 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1498 if (adapter->fc_service_class <= 3) {
1499 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1501 zfcp_get_busid_by_port(port),
1502 adapter->fc_service_class);
1504 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1505 "adapter %s is invalid. "
1506 "(debug info %d)\n",
1507 zfcp_get_busid_by_port(port),
1508 adapter->fc_service_class);
1510 /* stop operation for this adapter */
1511 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1512 zfcp_erp_adapter_shutdown(adapter, 0);
1513 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1516 case FSF_ADAPTER_STATUS_AVAILABLE:
1517 switch (header->fsf_status_qual.word[0]){
1518 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1519 /* reopening link to port */
1520 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1521 zfcp_test_link(port);
1522 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1524 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1525 /* ERP strategy will escalate */
1526 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1530 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1532 header->fsf_status_qual.word[0]);
1537 case FSF_ACCESS_DENIED:
1538 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1539 "command (adapter %s, port d_id=0x%08x)\n",
1540 zfcp_get_busid_by_port(port), port->d_id);
1541 for (counter = 0; counter < 2; counter++) {
1542 subtable = header->fsf_status_qual.halfword[counter * 2];
1543 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1545 case FSF_SQ_CFDC_SUBTABLE_OS:
1546 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1547 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1548 case FSF_SQ_CFDC_SUBTABLE_LUN:
1549 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1550 zfcp_act_subtable_type[subtable], rule);
1554 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1555 zfcp_erp_port_access_denied(port);
1556 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1559 case FSF_GENERIC_COMMAND_REJECTED:
1560 ZFCP_LOG_INFO("generic service command rejected "
1561 "(adapter %s, port d_id=0x%08x)\n",
1562 zfcp_get_busid_by_port(port), port->d_id);
1563 ZFCP_LOG_INFO("status qualifier:\n");
1564 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1565 (char *) &header->fsf_status_qual,
1566 sizeof (union fsf_status_qual));
1567 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1571 case FSF_PORT_HANDLE_NOT_VALID:
1572 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1573 "0x%016Lx on adapter %s invalid. This may "
1574 "happen occasionally.\n", port->handle,
1575 port->wwpn, zfcp_get_busid_by_port(port));
1576 ZFCP_LOG_INFO("status qualifier:\n");
1577 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1578 (char *) &header->fsf_status_qual,
1579 sizeof (union fsf_status_qual));
1580 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1581 zfcp_erp_adapter_reopen(adapter, 0);
1582 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1585 case FSF_PORT_BOXED:
1586 ZFCP_LOG_INFO("port needs to be reopened "
1587 "(adapter %s, port d_id=0x%08x)\n",
1588 zfcp_get_busid_by_port(port), port->d_id);
1589 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1590 zfcp_erp_port_reopen(port, 0);
1591 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1592 | ZFCP_STATUS_FSFREQ_RETRY;
1595 /* following states should never occure, all cases avoided
1596 in zfcp_fsf_send_ct - but who knows ... */
1597 case FSF_PAYLOAD_SIZE_MISMATCH:
1598 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1599 "req_buf_length=%d, resp_buf_length=%d)\n",
1600 zfcp_get_busid_by_adapter(adapter),
1601 bottom->req_buf_length, bottom->resp_buf_length);
1602 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1604 case FSF_REQUEST_SIZE_TOO_LARGE:
1605 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1606 "req_buf_length=%d)\n",
1607 zfcp_get_busid_by_adapter(adapter),
1608 bottom->req_buf_length);
1609 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1611 case FSF_RESPONSE_SIZE_TOO_LARGE:
1612 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1613 "resp_buf_length=%d)\n",
1614 zfcp_get_busid_by_adapter(adapter),
1615 bottom->resp_buf_length);
1616 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1618 case FSF_SBAL_MISMATCH:
1619 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1620 "resp_buf_length=%d)\n",
1621 zfcp_get_busid_by_adapter(adapter),
1622 bottom->req_buf_length, bottom->resp_buf_length);
1623 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1627 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1628 "(debug info 0x%x)\n", header->fsf_status);
1629 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1630 debug_exception(adapter->erp_dbf, 0,
1631 &header->fsf_status_qual.word[0], sizeof (u32));
1636 send_ct->status = retval;
1638 if (send_ct->handler != NULL)
1639 send_ct->handler(send_ct->handler_data);
1645 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1646 * @els: pointer to struct zfcp_send_els which contains all needed data for
1650 zfcp_fsf_send_els(struct zfcp_send_els *els)
1652 volatile struct qdio_buffer_element *sbale;
1653 struct zfcp_fsf_req *fsf_req;
1655 struct zfcp_adapter *adapter;
1656 unsigned long lock_flags;
1661 adapter = els->adapter;
1663 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1664 ZFCP_REQ_AUTO_CLEANUP,
1665 NULL, &lock_flags, &fsf_req);
1667 ZFCP_LOG_INFO("error: creation of ELS request failed "
1668 "(adapter %s, port d_id: 0x%08x)\n",
1669 zfcp_get_busid_by_adapter(adapter), d_id);
1673 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1674 if (zfcp_use_one_sbal(els->req, els->req_count,
1675 els->resp, els->resp_count)){
1676 /* both request buffer and response buffer
1677 fit into one sbale each */
1678 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1679 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1680 sbale[2].length = els->req[0].length;
1681 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1682 sbale[3].length = els->resp[0].length;
1683 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1684 } else if (adapter->supported_features &
1685 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1686 /* try to use chained SBALs */
1687 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1688 SBAL_FLAGS0_TYPE_WRITE_READ,
1689 els->req, els->req_count,
1690 ZFCP_MAX_SBALS_PER_ELS_REQ);
1692 ZFCP_LOG_INFO("error: creation of ELS request failed "
1693 "(adapter %s, port d_id: 0x%08x)\n",
1694 zfcp_get_busid_by_adapter(adapter), d_id);
1702 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1703 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1704 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1705 SBAL_FLAGS0_TYPE_WRITE_READ,
1706 els->resp, els->resp_count,
1707 ZFCP_MAX_SBALS_PER_ELS_REQ);
1709 ZFCP_LOG_INFO("error: creation of ELS request failed "
1710 "(adapter %s, port d_id: 0x%08x)\n",
1711 zfcp_get_busid_by_adapter(adapter), d_id);
1719 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1721 /* reject request */
1722 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1723 ", ELS request too big (adapter %s, "
1724 "port d_id: 0x%08x)\n",
1725 zfcp_get_busid_by_adapter(adapter), d_id);
1730 /* settings in QTCB */
1731 fsf_req->qtcb->bottom.support.d_id = d_id;
1732 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1733 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1734 fsf_req->data.send_els = els;
1736 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1738 /* start QDIO request for this FSF request */
1739 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1741 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1742 "(adapter %s, port d_id: 0x%08x)\n",
1743 zfcp_get_busid_by_adapter(adapter), d_id);
1747 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1748 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1752 zfcp_fsf_req_free(fsf_req);
1756 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1763 * zfcp_fsf_send_els_handler - handler for ELS commands
1764 * @fsf_req: pointer to struct zfcp_fsf_req
1766 * Data specific for the ELS command is passed by
1767 * fsf_req->data.send_els
1768 * Usually a specific handler for the command is called via
1769 * fsf_req->data.send_els->handler at end of this function.
1771 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1773 struct zfcp_adapter *adapter;
1774 struct zfcp_port *port;
1776 struct fsf_qtcb_header *header;
1777 struct fsf_qtcb_bottom_support *bottom;
1778 struct zfcp_send_els *send_els;
1779 int retval = -EINVAL;
1780 u16 subtable, rule, counter;
1782 send_els = fsf_req->data.send_els;
1783 adapter = send_els->adapter;
1784 port = send_els->port;
1785 d_id = send_els->d_id;
1786 header = &fsf_req->qtcb->header;
1787 bottom = &fsf_req->qtcb->bottom.support;
1789 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1790 goto skip_fsfstatus;
1792 switch (header->fsf_status) {
1798 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1799 if (adapter->fc_service_class <= 3) {
1800 ZFCP_LOG_INFO("error: adapter %s does "
1801 "not support fibrechannel class %d.\n",
1802 zfcp_get_busid_by_adapter(adapter),
1803 adapter->fc_service_class);
1805 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1806 "adapter %s is invalid. "
1807 "(debug info %d)\n",
1808 zfcp_get_busid_by_adapter(adapter),
1809 adapter->fc_service_class);
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%08x)\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%08x)\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);
1944 * returns: address of initiated FSF request
1945 * NULL - request could not be initiated
1948 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1950 volatile struct qdio_buffer_element *sbale;
1951 unsigned long lock_flags;
1954 /* setup new FSF request */
1955 retval = zfcp_fsf_req_create(erp_action->adapter,
1956 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1957 ZFCP_REQ_AUTO_CLEANUP,
1958 erp_action->adapter->pool.fsf_req_erp,
1959 &lock_flags, &(erp_action->fsf_req));
1961 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1962 "data request for adapter %s.\n",
1963 zfcp_get_busid_by_adapter(erp_action->adapter));
1967 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1968 erp_action->fsf_req->sbal_curr, 0);
1969 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1970 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1972 erp_action->fsf_req->erp_action = erp_action;
1973 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1974 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
1976 /* start QDIO request for this FSF request */
1977 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1980 ("error: Could not send exchange configuration data "
1981 "command on the adapter %s\n",
1982 zfcp_get_busid_by_adapter(erp_action->adapter));
1983 zfcp_fsf_req_free(erp_action->fsf_req);
1984 erp_action->fsf_req = NULL;
1988 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1990 zfcp_get_busid_by_adapter(erp_action->adapter));
1993 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
1999 * zfcp_fsf_exchange_config_evaluate
2000 * @fsf_req: fsf_req which belongs to xchg config data request
2001 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2003 * returns: -EIO on error, 0 otherwise
2006 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2008 struct fsf_qtcb_bottom_config *bottom;
2009 struct zfcp_adapter *adapter = fsf_req->adapter;
2011 bottom = &fsf_req->qtcb->bottom.config;
2012 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2013 bottom->low_qtcb_version, bottom->high_qtcb_version);
2014 adapter->fsf_lic_version = bottom->lic_version;
2015 adapter->supported_features = bottom->supported_features;
2016 adapter->peer_wwpn = 0;
2017 adapter->peer_wwnn = 0;
2018 adapter->peer_d_id = 0;
2021 adapter->wwnn = bottom->nport_serv_param.wwnn;
2022 adapter->wwpn = bottom->nport_serv_param.wwpn;
2023 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2024 adapter->fc_topology = bottom->fc_topology;
2025 adapter->fc_link_speed = bottom->fc_link_speed;
2026 adapter->hydra_version = bottom->adapter_type;
2031 adapter->fc_topology = 0;
2032 adapter->fc_link_speed = 0;
2033 adapter->hydra_version = 0;
2036 if (adapter->fc_topology == FSF_TOPO_P2P) {
2037 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2038 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2039 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2042 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2043 adapter->hardware_version = bottom->hardware_version;
2044 memcpy(adapter->serial_number, bottom->serial_number, 17);
2045 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2048 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2052 "adapter version 0x%x, "
2053 "LIC version 0x%x, "
2054 "FC link speed %d Gb/s\n",
2055 zfcp_get_busid_by_adapter(adapter),
2058 (unsigned int) adapter->s_id,
2059 adapter->hydra_version,
2060 adapter->fsf_lic_version,
2061 adapter->fc_link_speed);
2062 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2063 ZFCP_LOG_NORMAL("error: the adapter %s "
2064 "only supports newer control block "
2065 "versions in comparison to this device "
2066 "driver (try updated device driver)\n",
2067 zfcp_get_busid_by_adapter(adapter));
2068 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2069 zfcp_erp_adapter_shutdown(adapter, 0);
2072 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2073 ZFCP_LOG_NORMAL("error: the adapter %s "
2074 "only supports older control block "
2075 "versions than this device driver uses"
2076 "(consider a microcode upgrade)\n",
2077 zfcp_get_busid_by_adapter(adapter));
2078 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2079 zfcp_erp_adapter_shutdown(adapter, 0);
2086 * function: zfcp_fsf_exchange_config_data_handler
2088 * purpose: is called for finished Exchange Configuration Data command
2093 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2095 struct fsf_qtcb_bottom_config *bottom;
2096 struct zfcp_adapter *adapter = fsf_req->adapter;
2098 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2101 switch (fsf_req->qtcb->header.fsf_status) {
2104 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2107 switch (adapter->fc_topology) {
2109 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2110 "configuration detected at adapter %s\n"
2111 "Peer WWNN 0x%016llx, "
2112 "peer WWPN 0x%016llx, "
2113 "peer d_id 0x%06x\n",
2114 zfcp_get_busid_by_adapter(adapter),
2117 adapter->peer_d_id);
2118 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2122 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2123 "topology detected at adapter %s "
2124 "unsupported, shutting down adapter\n",
2125 zfcp_get_busid_by_adapter(adapter));
2126 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2128 zfcp_erp_adapter_shutdown(adapter, 0);
2130 case FSF_TOPO_FABRIC:
2131 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2132 "network detected at adapter %s.\n",
2133 zfcp_get_busid_by_adapter(adapter));
2136 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2137 "reported by the exchange "
2138 "configuration command for "
2139 "the adapter %s is not "
2140 "of a type known to the zfcp "
2141 "driver, shutting down adapter\n",
2142 zfcp_get_busid_by_adapter(adapter));
2143 adapter->fc_topology = FSF_TOPO_ERROR;
2144 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2146 zfcp_erp_adapter_shutdown(adapter, 0);
2149 bottom = &fsf_req->qtcb->bottom.config;
2150 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2151 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2152 "allowed by the adapter %s "
2153 "is lower than the minimum "
2154 "required by the driver (%ld bytes).\n",
2155 bottom->max_qtcb_size,
2156 zfcp_get_busid_by_adapter(adapter),
2157 sizeof(struct fsf_qtcb));
2158 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2160 debug_event(fsf_req->adapter->erp_dbf, 0,
2161 &bottom->max_qtcb_size, sizeof (u32));
2162 zfcp_erp_adapter_shutdown(adapter, 0);
2165 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2168 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2169 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2171 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2174 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2175 zfcp_get_busid_by_adapter(adapter));
2176 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2177 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2179 zfcp_erp_adapter_failed(adapter);
2182 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2183 debug_event(fsf_req->adapter->erp_dbf, 0,
2184 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2185 zfcp_erp_adapter_shutdown(adapter, 0);
2192 * zfcp_fsf_exchange_port_data - request information about local port
2193 * @adapter: for which port data is requested
2194 * @data: response to exchange port data request
2197 zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2198 struct fsf_qtcb_bottom_port *data)
2200 volatile struct qdio_buffer_element *sbale;
2202 unsigned long lock_flags;
2203 struct zfcp_fsf_req *fsf_req;
2204 struct timer_list *timer;
2206 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2207 ZFCP_LOG_INFO("error: exchange port data "
2208 "command not supported by adapter %s\n",
2209 zfcp_get_busid_by_adapter(adapter));
2213 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2217 /* setup new FSF request */
2218 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2219 0, 0, &lock_flags, &fsf_req);
2221 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2222 "exchange port data request for"
2223 "the adapter %s.\n",
2224 zfcp_get_busid_by_adapter(adapter));
2225 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2230 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2231 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2232 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2234 fsf_req->data.port_data = data;
2237 timer->function = zfcp_fsf_request_timeout_handler;
2238 timer->data = (unsigned long) adapter;
2239 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2241 retval = zfcp_fsf_req_send(fsf_req, timer);
2243 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2244 "command on the adapter %s\n",
2245 zfcp_get_busid_by_adapter(adapter));
2246 zfcp_fsf_req_free(fsf_req);
2247 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2252 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2253 zfcp_get_busid_by_adapter(adapter));
2255 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2258 wait_event(fsf_req->completion_wq,
2259 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2260 del_timer_sync(timer);
2261 zfcp_fsf_req_cleanup(fsf_req);
2269 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2270 * @fsf_req: pointer to struct zfcp_fsf_req
2273 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2275 struct fsf_qtcb_bottom_port *bottom;
2276 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2278 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2281 switch (fsf_req->qtcb->header.fsf_status) {
2283 bottom = &fsf_req->qtcb->bottom.port;
2284 memcpy(data, bottom, sizeof(*data));
2288 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2289 debug_event(fsf_req->adapter->erp_dbf, 0,
2290 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2296 * function: zfcp_fsf_open_port
2300 * returns: address of initiated FSF request
2301 * NULL - request could not be initiated
2304 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2306 volatile struct qdio_buffer_element *sbale;
2307 unsigned long lock_flags;
2310 /* setup new FSF request */
2311 retval = zfcp_fsf_req_create(erp_action->adapter,
2312 FSF_QTCB_OPEN_PORT_WITH_DID,
2313 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2314 erp_action->adapter->pool.fsf_req_erp,
2315 &lock_flags, &(erp_action->fsf_req));
2317 ZFCP_LOG_INFO("error: Could not create open port request "
2318 "for port 0x%016Lx on adapter %s.\n",
2319 erp_action->port->wwpn,
2320 zfcp_get_busid_by_adapter(erp_action->adapter));
2324 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2325 erp_action->fsf_req->sbal_curr, 0);
2326 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2327 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2329 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2330 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2331 erp_action->fsf_req->data.open_port.port = erp_action->port;
2332 erp_action->fsf_req->erp_action = erp_action;
2334 /* start QDIO request for this FSF request */
2335 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2337 ZFCP_LOG_INFO("error: Could not send open port request for "
2338 "port 0x%016Lx on adapter %s.\n",
2339 erp_action->port->wwpn,
2340 zfcp_get_busid_by_adapter(erp_action->adapter));
2341 zfcp_fsf_req_free(erp_action->fsf_req);
2342 erp_action->fsf_req = NULL;
2346 ZFCP_LOG_DEBUG("open port request initiated "
2347 "(adapter %s, port 0x%016Lx)\n",
2348 zfcp_get_busid_by_adapter(erp_action->adapter),
2349 erp_action->port->wwpn);
2351 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2357 * function: zfcp_fsf_open_port_handler
2359 * purpose: is called for finished Open Port command
2364 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2366 int retval = -EINVAL;
2367 struct zfcp_port *port;
2368 struct fsf_plogi *plogi;
2369 struct fsf_qtcb_header *header;
2370 u16 subtable, rule, counter;
2372 port = fsf_req->data.open_port.port;
2373 header = &fsf_req->qtcb->header;
2375 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2376 /* don't change port status in our bookkeeping */
2377 goto skip_fsfstatus;
2380 /* evaluate FSF status in QTCB */
2381 switch (header->fsf_status) {
2383 case FSF_PORT_ALREADY_OPEN:
2384 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2385 "is already open.\n",
2386 port->wwpn, zfcp_get_busid_by_port(port));
2387 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2390 * This is a bug, however operation should continue normally
2391 * if it is simply ignored
2395 case FSF_ACCESS_DENIED:
2396 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2398 port->wwpn, zfcp_get_busid_by_port(port));
2399 for (counter = 0; counter < 2; counter++) {
2400 subtable = header->fsf_status_qual.halfword[counter * 2];
2401 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2403 case FSF_SQ_CFDC_SUBTABLE_OS:
2404 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2405 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2406 case FSF_SQ_CFDC_SUBTABLE_LUN:
2407 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2408 zfcp_act_subtable_type[subtable], rule);
2412 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2413 zfcp_erp_port_access_denied(port);
2414 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2417 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2418 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2419 "The remote port 0x%016Lx on adapter %s "
2420 "could not be opened. Disabling it.\n",
2421 port->wwpn, zfcp_get_busid_by_port(port));
2422 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2424 zfcp_erp_port_failed(port);
2425 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2428 case FSF_ADAPTER_STATUS_AVAILABLE:
2429 switch (header->fsf_status_qual.word[0]) {
2430 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2431 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2433 /* ERP strategy will escalate */
2434 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2436 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2437 /* ERP strategy will escalate */
2438 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2440 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2442 case FSF_SQ_NO_RETRY_POSSIBLE:
2443 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2444 "adapter %s could not be opened. "
2447 zfcp_get_busid_by_port(port));
2448 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2450 zfcp_erp_port_failed(port);
2451 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2455 ("bug: Wrong status qualifier 0x%x arrived.\n",
2456 header->fsf_status_qual.word[0]);
2457 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2460 fsf_req->adapter->erp_dbf, 0,
2461 &header->fsf_status_qual.word[0],
2468 /* save port handle assigned by FSF */
2469 port->handle = header->port_handle;
2470 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2471 "was opened, it's port handle is 0x%x\n",
2472 port->wwpn, zfcp_get_busid_by_port(port),
2474 /* mark port as open */
2475 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2476 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2478 /* check whether D_ID has changed during open */
2480 * FIXME: This check is not airtight, as the FCP channel does
2481 * not monitor closures of target port connections caused on
2482 * the remote side. Thus, they might miss out on invalidating
2483 * locally cached WWPNs (and other N_Port parameters) of gone
2484 * target ports. So, our heroic attempt to make things safe
2485 * could be undermined by 'open port' response data tagged with
2486 * obsolete WWPNs. Another reason to monitor potential
2487 * connection closures ourself at least (by interpreting
2488 * incoming ELS' and unsolicited status). It just crosses my
2489 * mind that one should be able to cross-check by means of
2490 * another GID_PN straight after a port has been opened.
2491 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2493 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2494 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2496 if (fsf_req->qtcb->bottom.support.els1_length <
2497 ((((unsigned long) &plogi->serv_param.wwpn) -
2498 ((unsigned long) plogi)) + sizeof (u64))) {
2500 "warning: insufficient length of "
2501 "PLOGI payload (%i)\n",
2502 fsf_req->qtcb->bottom.support.els1_length);
2503 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2504 "fsf_s_short_plogi:");
2505 /* skip sanity check and assume wwpn is ok */
2507 if (plogi->serv_param.wwpn != port->wwpn) {
2508 ZFCP_LOG_INFO("warning: d_id of port "
2509 "0x%016Lx changed during "
2510 "open\n", port->wwpn);
2512 fsf_req->adapter->erp_dbf, 0,
2513 "fsf_s_did_change:");
2515 ZFCP_STATUS_PORT_DID_DID,
2518 port->wwnn = plogi->serv_param.wwnn;
2523 case FSF_UNKNOWN_OP_SUBTYPE:
2524 /* should never occure, subtype not set in zfcp_fsf_open_port */
2525 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2526 "op_subtype=0x%x)\n",
2527 zfcp_get_busid_by_port(port),
2528 fsf_req->qtcb->bottom.support.operation_subtype);
2529 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2533 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2534 "(debug info 0x%x)\n",
2535 header->fsf_status);
2536 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2537 debug_exception(fsf_req->adapter->erp_dbf, 0,
2538 &header->fsf_status, sizeof (u32));
2543 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2548 * function: zfcp_fsf_close_port
2550 * purpose: submit FSF command "close port"
2552 * returns: address of initiated FSF request
2553 * NULL - request could not be initiated
2556 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2558 volatile struct qdio_buffer_element *sbale;
2559 unsigned long lock_flags;
2562 /* setup new FSF request */
2563 retval = zfcp_fsf_req_create(erp_action->adapter,
2564 FSF_QTCB_CLOSE_PORT,
2565 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2566 erp_action->adapter->pool.fsf_req_erp,
2567 &lock_flags, &(erp_action->fsf_req));
2569 ZFCP_LOG_INFO("error: Could not create a close port request "
2570 "for port 0x%016Lx on adapter %s.\n",
2571 erp_action->port->wwpn,
2572 zfcp_get_busid_by_adapter(erp_action->adapter));
2576 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2577 erp_action->fsf_req->sbal_curr, 0);
2578 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2579 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2581 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2582 erp_action->fsf_req->data.close_port.port = erp_action->port;
2583 erp_action->fsf_req->erp_action = erp_action;
2584 erp_action->fsf_req->qtcb->header.port_handle =
2585 erp_action->port->handle;
2587 /* start QDIO request for this FSF request */
2588 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2590 ZFCP_LOG_INFO("error: Could not send a close port request for "
2591 "port 0x%016Lx on adapter %s.\n",
2592 erp_action->port->wwpn,
2593 zfcp_get_busid_by_adapter(erp_action->adapter));
2594 zfcp_fsf_req_free(erp_action->fsf_req);
2595 erp_action->fsf_req = NULL;
2599 ZFCP_LOG_TRACE("close port request initiated "
2600 "(adapter %s, port 0x%016Lx)\n",
2601 zfcp_get_busid_by_adapter(erp_action->adapter),
2602 erp_action->port->wwpn);
2604 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2610 * function: zfcp_fsf_close_port_handler
2612 * purpose: is called for finished Close Port FSF command
2617 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2619 int retval = -EINVAL;
2620 struct zfcp_port *port;
2622 port = fsf_req->data.close_port.port;
2624 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2625 /* don't change port status in our bookkeeping */
2626 goto skip_fsfstatus;
2629 /* evaluate FSF status in QTCB */
2630 switch (fsf_req->qtcb->header.fsf_status) {
2632 case FSF_PORT_HANDLE_NOT_VALID:
2633 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2634 "0x%016Lx on adapter %s invalid. This may happen "
2635 "occasionally.\n", port->handle,
2636 port->wwpn, zfcp_get_busid_by_port(port));
2637 ZFCP_LOG_DEBUG("status qualifier:\n");
2638 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2639 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2640 sizeof (union fsf_status_qual));
2641 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2643 zfcp_erp_adapter_reopen(port->adapter, 0);
2644 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2647 case FSF_ADAPTER_STATUS_AVAILABLE:
2648 /* Note: FSF has actually closed the port in this case.
2649 * The status code is just daft. Fingers crossed for a change
2655 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2656 "port handle 0x%x\n", port->wwpn,
2657 zfcp_get_busid_by_port(port), port->handle);
2658 zfcp_erp_modify_port_status(port,
2659 ZFCP_STATUS_COMMON_OPEN,
2665 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2666 "(debug info 0x%x)\n",
2667 fsf_req->qtcb->header.fsf_status);
2668 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2669 debug_exception(fsf_req->adapter->erp_dbf, 0,
2670 &fsf_req->qtcb->header.fsf_status,
2676 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2681 * function: zfcp_fsf_close_physical_port
2683 * purpose: submit FSF command "close physical port"
2685 * returns: address of initiated FSF request
2686 * NULL - request could not be initiated
2689 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2692 unsigned long lock_flags;
2693 volatile struct qdio_buffer_element *sbale;
2695 /* setup new FSF request */
2696 retval = zfcp_fsf_req_create(erp_action->adapter,
2697 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2698 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2699 erp_action->adapter->pool.fsf_req_erp,
2700 &lock_flags, &erp_action->fsf_req);
2702 ZFCP_LOG_INFO("error: Could not create close physical port "
2703 "request (adapter %s, port 0x%016Lx)\n",
2704 zfcp_get_busid_by_adapter(erp_action->adapter),
2705 erp_action->port->wwpn);
2710 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2711 erp_action->fsf_req->sbal_curr, 0);
2712 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2713 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2715 /* mark port as being closed */
2716 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2717 &erp_action->port->status);
2718 /* save a pointer to this port */
2719 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2720 /* port to be closeed */
2721 erp_action->fsf_req->qtcb->header.port_handle =
2722 erp_action->port->handle;
2723 erp_action->fsf_req->erp_action = erp_action;
2725 /* start QDIO request for this FSF request */
2726 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2728 ZFCP_LOG_INFO("error: Could not send close physical port "
2729 "request (adapter %s, port 0x%016Lx)\n",
2730 zfcp_get_busid_by_adapter(erp_action->adapter),
2731 erp_action->port->wwpn);
2732 zfcp_fsf_req_free(erp_action->fsf_req);
2733 erp_action->fsf_req = NULL;
2737 ZFCP_LOG_TRACE("close physical port request initiated "
2738 "(adapter %s, port 0x%016Lx)\n",
2739 zfcp_get_busid_by_adapter(erp_action->adapter),
2740 erp_action->port->wwpn);
2742 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2748 * function: zfcp_fsf_close_physical_port_handler
2750 * purpose: is called for finished Close Physical Port FSF command
2755 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2757 int retval = -EINVAL;
2758 struct zfcp_port *port;
2759 struct zfcp_unit *unit;
2760 struct fsf_qtcb_header *header;
2761 u16 subtable, rule, counter;
2763 port = fsf_req->data.close_physical_port.port;
2764 header = &fsf_req->qtcb->header;
2766 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2767 /* don't change port status in our bookkeeping */
2768 goto skip_fsfstatus;
2771 /* evaluate FSF status in QTCB */
2772 switch (header->fsf_status) {
2774 case FSF_PORT_HANDLE_NOT_VALID:
2775 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2776 "(adapter %s, port 0x%016Lx). "
2777 "This may happen occasionally.\n",
2779 zfcp_get_busid_by_port(port),
2781 ZFCP_LOG_DEBUG("status qualifier:\n");
2782 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2783 (char *) &header->fsf_status_qual,
2784 sizeof (union fsf_status_qual));
2785 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2787 zfcp_erp_adapter_reopen(port->adapter, 0);
2788 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2791 case FSF_ACCESS_DENIED:
2792 ZFCP_LOG_NORMAL("Access denied, cannot close "
2793 "physical port 0x%016Lx on adapter %s\n",
2794 port->wwpn, zfcp_get_busid_by_port(port));
2795 for (counter = 0; counter < 2; counter++) {
2796 subtable = header->fsf_status_qual.halfword[counter * 2];
2797 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2799 case FSF_SQ_CFDC_SUBTABLE_OS:
2800 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2801 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2802 case FSF_SQ_CFDC_SUBTABLE_LUN:
2803 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2804 zfcp_act_subtable_type[subtable], rule);
2808 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2809 zfcp_erp_port_access_denied(port);
2810 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2813 case FSF_PORT_BOXED:
2814 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2815 "%s needs to be reopened but it was attempted "
2816 "to close it physically.\n",
2818 zfcp_get_busid_by_port(port));
2819 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2820 zfcp_erp_port_reopen(port, 0);
2821 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2822 ZFCP_STATUS_FSFREQ_RETRY;
2825 case FSF_ADAPTER_STATUS_AVAILABLE:
2826 switch (header->fsf_status_qual.word[0]) {
2827 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2828 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2830 /* This will now be escalated by ERP */
2831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2833 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2834 /* ERP strategy will escalate */
2835 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2837 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2841 ("bug: Wrong status qualifier 0x%x arrived.\n",
2842 header->fsf_status_qual.word[0]);
2843 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2846 fsf_req->adapter->erp_dbf, 0,
2847 &header->fsf_status_qual.word[0], sizeof (u32));
2853 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2854 "physically closed, port handle 0x%x\n",
2856 zfcp_get_busid_by_port(port), port->handle);
2857 /* can't use generic zfcp_erp_modify_port_status because
2858 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2860 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2861 list_for_each_entry(unit, &port->unit_list_head, list)
2862 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2867 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2868 "(debug info 0x%x)\n",
2869 header->fsf_status);
2870 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2871 debug_exception(fsf_req->adapter->erp_dbf, 0,
2872 &header->fsf_status, sizeof (u32));
2877 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2882 * function: zfcp_fsf_open_unit
2888 * assumptions: This routine does not check whether the associated
2889 * remote port has already been opened. This should be
2890 * done by calling routines. Otherwise some status
2891 * may be presented by FSF
2894 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2896 volatile struct qdio_buffer_element *sbale;
2897 unsigned long lock_flags;
2900 /* setup new FSF request */
2901 retval = zfcp_fsf_req_create(erp_action->adapter,
2903 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2904 erp_action->adapter->pool.fsf_req_erp,
2905 &lock_flags, &(erp_action->fsf_req));
2907 ZFCP_LOG_INFO("error: Could not create open unit request for "
2908 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2909 erp_action->unit->fcp_lun,
2910 erp_action->unit->port->wwpn,
2911 zfcp_get_busid_by_adapter(erp_action->adapter));
2915 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2916 erp_action->fsf_req->sbal_curr, 0);
2917 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2918 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2920 erp_action->fsf_req->qtcb->header.port_handle =
2921 erp_action->port->handle;
2922 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2923 erp_action->unit->fcp_lun;
2924 erp_action->fsf_req->qtcb->bottom.support.option =
2925 FSF_OPEN_LUN_SUPPRESS_BOXING;
2926 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2927 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2928 erp_action->fsf_req->erp_action = erp_action;
2930 /* start QDIO request for this FSF request */
2931 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2933 ZFCP_LOG_INFO("error: Could not send an open unit request "
2934 "on the adapter %s, port 0x%016Lx for "
2936 zfcp_get_busid_by_adapter(erp_action->adapter),
2937 erp_action->port->wwpn,
2938 erp_action->unit->fcp_lun);
2939 zfcp_fsf_req_free(erp_action->fsf_req);
2940 erp_action->fsf_req = NULL;
2944 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2945 "port 0x%016Lx, unit 0x%016Lx)\n",
2946 zfcp_get_busid_by_adapter(erp_action->adapter),
2947 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2949 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2955 * function: zfcp_fsf_open_unit_handler
2957 * purpose: is called for finished Open LUN command
2962 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2964 int retval = -EINVAL;
2965 struct zfcp_adapter *adapter;
2966 struct zfcp_unit *unit;
2967 struct fsf_qtcb_header *header;
2968 struct fsf_qtcb_bottom_support *bottom;
2969 struct fsf_queue_designator *queue_designator;
2970 u16 subtable, rule, counter;
2971 u32 allowed, exclusive, readwrite;
2973 unit = fsf_req->data.open_unit.unit;
2975 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2976 /* don't change unit status in our bookkeeping */
2977 goto skip_fsfstatus;
2980 adapter = fsf_req->adapter;
2981 header = &fsf_req->qtcb->header;
2982 bottom = &fsf_req->qtcb->bottom.support;
2983 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2985 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
2986 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
2987 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
2989 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2990 ZFCP_STATUS_UNIT_SHARED |
2991 ZFCP_STATUS_UNIT_READONLY,
2994 /* evaluate FSF status in QTCB */
2995 switch (header->fsf_status) {
2997 case FSF_PORT_HANDLE_NOT_VALID:
2998 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2999 "for port 0x%016Lx on adapter %s invalid "
3000 "This may happen occasionally\n",
3002 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3003 ZFCP_LOG_DEBUG("status qualifier:\n");
3004 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3005 (char *) &header->fsf_status_qual,
3006 sizeof (union fsf_status_qual));
3007 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3008 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3009 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3012 case FSF_LUN_ALREADY_OPEN:
3013 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3014 "remote port 0x%016Lx on adapter %s twice.\n",
3016 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3017 debug_text_exception(adapter->erp_dbf, 0,
3019 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3022 case FSF_ACCESS_DENIED:
3023 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3024 "remote port 0x%016Lx on adapter %s\n",
3025 unit->fcp_lun, unit->port->wwpn,
3026 zfcp_get_busid_by_unit(unit));
3027 for (counter = 0; counter < 2; counter++) {
3028 subtable = header->fsf_status_qual.halfword[counter * 2];
3029 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3031 case FSF_SQ_CFDC_SUBTABLE_OS:
3032 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3033 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3034 case FSF_SQ_CFDC_SUBTABLE_LUN:
3035 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3036 zfcp_act_subtable_type[subtable], rule);
3040 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3041 zfcp_erp_unit_access_denied(unit);
3042 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3043 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3044 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3047 case FSF_PORT_BOXED:
3048 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3049 "needs to be reopened\n",
3050 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3051 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3052 zfcp_erp_port_reopen(unit->port, 0);
3053 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3054 ZFCP_STATUS_FSFREQ_RETRY;
3057 case FSF_LUN_SHARING_VIOLATION:
3058 if (header->fsf_status_qual.word[0] != 0) {
3059 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3061 "connected to the adapter %s "
3062 "is already in use in LPAR%d, CSS%d\n",
3065 zfcp_get_busid_by_unit(unit),
3066 queue_designator->hla,
3067 queue_designator->cssid);
3069 subtable = header->fsf_status_qual.halfword[4];
3070 rule = header->fsf_status_qual.halfword[5];
3072 case FSF_SQ_CFDC_SUBTABLE_OS:
3073 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3074 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3075 case FSF_SQ_CFDC_SUBTABLE_LUN:
3076 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3077 "remote port with WWPN 0x%Lx "
3078 "connected to the adapter %s "
3079 "is denied (%s rule %d)\n",
3082 zfcp_get_busid_by_unit(unit),
3083 zfcp_act_subtable_type[subtable],
3088 ZFCP_LOG_DEBUG("status qualifier:\n");
3089 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3090 (char *) &header->fsf_status_qual,
3091 sizeof (union fsf_status_qual));
3092 debug_text_event(adapter->erp_dbf, 2,
3094 zfcp_erp_unit_access_denied(unit);
3095 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3096 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3097 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3100 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3101 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3102 "There is no handle (temporary port identifier) "
3103 "available for unit 0x%016Lx on port 0x%016Lx "
3107 zfcp_get_busid_by_unit(unit));
3108 debug_text_event(adapter->erp_dbf, 1,
3110 zfcp_erp_unit_failed(unit);
3111 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3114 case FSF_ADAPTER_STATUS_AVAILABLE:
3115 switch (header->fsf_status_qual.word[0]) {
3116 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3117 /* Re-establish link to port */
3118 debug_text_event(adapter->erp_dbf, 1,
3120 zfcp_test_link(unit->port);
3121 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3123 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3124 /* ERP strategy will escalate */
3125 debug_text_event(adapter->erp_dbf, 1,
3127 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3131 ("bug: Wrong status qualifier 0x%x arrived.\n",
3132 header->fsf_status_qual.word[0]);
3133 debug_text_event(adapter->erp_dbf, 0,
3135 debug_exception(adapter->erp_dbf, 0,
3136 &header->fsf_status_qual.word[0],
3141 case FSF_INVALID_COMMAND_OPTION:
3143 "Invalid option 0x%x has been specified "
3144 "in QTCB bottom sent to the adapter %s\n",
3146 zfcp_get_busid_by_adapter(adapter));
3147 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3152 /* save LUN handle assigned by FSF */
3153 unit->handle = header->lun_handle;
3154 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3155 "adapter %s opened, port handle 0x%x\n",
3158 zfcp_get_busid_by_unit(unit),
3160 /* mark unit as open */
3161 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3163 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3165 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3169 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3171 ZFCP_LOG_NORMAL("read-only access for unit "
3172 "(adapter %s, wwpn=0x%016Lx, "
3173 "fcp_lun=0x%016Lx)\n",
3174 zfcp_get_busid_by_unit(unit),
3179 if (exclusive && !readwrite) {
3180 ZFCP_LOG_NORMAL("exclusive access of read-only "
3181 "unit not supported\n");
3182 zfcp_erp_unit_failed(unit);
3183 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3184 zfcp_erp_unit_shutdown(unit, 0);
3185 } else if (!exclusive && readwrite) {
3186 ZFCP_LOG_NORMAL("shared access of read-write "
3187 "unit not supported\n");
3188 zfcp_erp_unit_failed(unit);
3189 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3190 zfcp_erp_unit_shutdown(unit, 0);
3198 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3199 "(debug info 0x%x)\n",
3200 header->fsf_status);
3201 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3202 debug_exception(adapter->erp_dbf, 0,
3203 &header->fsf_status, sizeof (u32));
3208 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3213 * function: zfcp_fsf_close_unit
3217 * returns: address of fsf_req - request successfully initiated
3220 * assumptions: This routine does not check whether the associated
3221 * remote port/lun has already been opened. This should be
3222 * done by calling routines. Otherwise some status
3223 * may be presented by FSF
3226 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3228 volatile struct qdio_buffer_element *sbale;
3229 unsigned long lock_flags;
3232 /* setup new FSF request */
3233 retval = zfcp_fsf_req_create(erp_action->adapter,
3235 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3236 erp_action->adapter->pool.fsf_req_erp,
3237 &lock_flags, &(erp_action->fsf_req));
3239 ZFCP_LOG_INFO("error: Could not create close unit request for "
3240 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3241 erp_action->unit->fcp_lun,
3242 erp_action->port->wwpn,
3243 zfcp_get_busid_by_adapter(erp_action->adapter));
3247 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3248 erp_action->fsf_req->sbal_curr, 0);
3249 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3250 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3252 erp_action->fsf_req->qtcb->header.port_handle =
3253 erp_action->port->handle;
3254 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3255 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3256 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3257 erp_action->fsf_req->erp_action = erp_action;
3259 /* start QDIO request for this FSF request */
3260 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3262 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3263 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3264 erp_action->unit->fcp_lun,
3265 erp_action->port->wwpn,
3266 zfcp_get_busid_by_adapter(erp_action->adapter));
3267 zfcp_fsf_req_free(erp_action->fsf_req);
3268 erp_action->fsf_req = NULL;
3272 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3273 "port 0x%016Lx, unit 0x%016Lx)\n",
3274 zfcp_get_busid_by_adapter(erp_action->adapter),
3275 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3277 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3283 * function: zfcp_fsf_close_unit_handler
3285 * purpose: is called for finished Close LUN FSF command
3290 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3292 int retval = -EINVAL;
3293 struct zfcp_unit *unit;
3295 unit = fsf_req->data.close_unit.unit; /* restore unit */
3297 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3298 /* don't change unit status in our bookkeeping */
3299 goto skip_fsfstatus;
3302 /* evaluate FSF status in QTCB */
3303 switch (fsf_req->qtcb->header.fsf_status) {
3305 case FSF_PORT_HANDLE_NOT_VALID:
3306 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3307 "0x%016Lx on adapter %s invalid. This may "
3308 "happen in rare circumstances\n",
3311 zfcp_get_busid_by_unit(unit));
3312 ZFCP_LOG_DEBUG("status qualifier:\n");
3313 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3314 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3315 sizeof (union fsf_status_qual));
3316 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3318 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3319 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3320 &fsf_req->qtcb->header.fsf_status_qual,
3321 sizeof (union fsf_status_qual));
3322 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3325 case FSF_LUN_HANDLE_NOT_VALID:
3326 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3327 "0x%016Lx on port 0x%016Lx on adapter %s is "
3328 "invalid. This may happen occasionally.\n",
3332 zfcp_get_busid_by_unit(unit));
3333 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3334 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3335 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3336 sizeof (union fsf_status_qual));
3337 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3339 zfcp_erp_port_reopen(unit->port, 0);
3340 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3341 &fsf_req->qtcb->header.fsf_status_qual,
3342 sizeof (union fsf_status_qual));
3343 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3346 case FSF_PORT_BOXED:
3347 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3348 "needs to be reopened\n",
3350 zfcp_get_busid_by_unit(unit));
3351 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3352 zfcp_erp_port_reopen(unit->port, 0);
3353 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3354 ZFCP_STATUS_FSFREQ_RETRY;
3357 case FSF_ADAPTER_STATUS_AVAILABLE:
3358 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3359 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3360 /* re-establish link to port */
3361 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3363 zfcp_test_link(unit->port);
3364 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3366 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3367 /* ERP strategy will escalate */
3368 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3374 ("bug: Wrong status qualifier 0x%x arrived.\n",
3375 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3376 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3379 fsf_req->adapter->erp_dbf, 0,
3380 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3387 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3388 "closed, port handle 0x%x\n",
3391 zfcp_get_busid_by_unit(unit),
3393 /* mark unit as closed */
3394 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3399 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3400 "(debug info 0x%x)\n",
3401 fsf_req->qtcb->header.fsf_status);
3402 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3403 debug_exception(fsf_req->adapter->erp_dbf, 0,
3404 &fsf_req->qtcb->header.fsf_status,
3410 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3415 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3416 * @adapter: adapter where scsi command is issued
3417 * @unit: unit where command is sent to
3418 * @scsi_cmnd: scsi command to be sent
3419 * @timer: timer to be started when request is initiated
3420 * @req_flags: flags for fsf_request
3423 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3424 struct zfcp_unit *unit,
3425 struct scsi_cmnd * scsi_cmnd,
3426 struct timer_list *timer, int req_flags)
3428 struct zfcp_fsf_req *fsf_req = NULL;
3429 struct fcp_cmnd_iu *fcp_cmnd_iu;
3430 unsigned int sbtype;
3431 unsigned long lock_flags;
3436 /* setup new FSF request */
3437 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3438 adapter->pool.fsf_req_scsi,
3439 &lock_flags, &fsf_req);
3440 if (unlikely(retval < 0)) {
3441 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3442 "for unit 0x%016Lx on port 0x%016Lx on "
3446 zfcp_get_busid_by_adapter(adapter));
3447 goto failed_req_create;
3451 * associate FSF request with SCSI request
3452 * (need this for look up on abort)
3454 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3455 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3458 * associate SCSI command with FSF request
3459 * (need this for look up on normal command completion)
3461 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3462 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3463 fsf_req->data.send_fcp_command_task.unit = unit;
3464 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3466 /* set handles of unit and its parent port in QTCB */
3467 fsf_req->qtcb->header.lun_handle = unit->handle;
3468 fsf_req->qtcb->header.port_handle = unit->port->handle;
3470 /* FSF does not define the structure of the FCP_CMND IU */
3471 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3472 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3475 * set depending on data direction:
3476 * data direction bits in SBALE (SB Type)
3477 * data direction bits in QTCB
3478 * data direction bits in FCP_CMND IU
3480 switch (scsi_cmnd->sc_data_direction) {
3482 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3485 * what is the correct type for commands
3486 * without 'real' data buffers?
3488 sbtype = SBAL_FLAGS0_TYPE_READ;
3490 case DMA_FROM_DEVICE:
3491 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3492 sbtype = SBAL_FLAGS0_TYPE_READ;
3493 fcp_cmnd_iu->rddata = 1;
3496 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3497 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3498 fcp_cmnd_iu->wddata = 1;
3500 case DMA_BIDIRECTIONAL:
3503 * dummy, catch this condition earlier
3504 * in zfcp_scsi_queuecommand
3506 goto failed_scsi_cmnd;
3509 /* set FC service class in QTCB (3 per default) */
3510 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3512 /* set FCP_LUN in FCP_CMND IU in QTCB */
3513 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3515 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3517 /* set task attributes in FCP_CMND IU in QTCB */
3518 if (likely((scsi_cmnd->device->simple_tags) ||
3519 (atomic_test_mask(mask, &unit->status))))
3520 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3522 fcp_cmnd_iu->task_attribute = UNTAGGED;
3524 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3525 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3526 fcp_cmnd_iu->add_fcp_cdb_length
3527 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3528 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3529 "additional FCP_CDB length is 0x%x "
3530 "(shifted right 2 bits)\n",
3532 fcp_cmnd_iu->add_fcp_cdb_length);
3535 * copy SCSI CDB (including additional length, if any) to
3536 * FCP_CDB in FCP_CMND IU in QTCB
3538 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3540 /* FCP CMND IU length in QTCB */
3541 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3542 sizeof (struct fcp_cmnd_iu) +
3543 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3545 /* generate SBALEs from data buffer */
3546 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3547 if (unlikely(real_bytes < 0)) {
3548 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3550 "Data did not fit into available buffer(s), "
3551 "waiting for more...\n");
3554 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3555 "required. Shutting down unit "
3556 "(adapter %s, port 0x%016Lx, "
3558 zfcp_get_busid_by_unit(unit),
3561 zfcp_erp_unit_shutdown(unit, 0);
3567 /* set length of FCP data length in FCP_CMND IU in QTCB */
3568 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3570 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3571 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3572 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3575 * start QDIO request for this FSF request
3576 * covered by an SBALE)
3578 retval = zfcp_fsf_req_send(fsf_req, timer);
3579 if (unlikely(retval < 0)) {
3580 ZFCP_LOG_INFO("error: Could not send FCP command request "
3581 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3582 zfcp_get_busid_by_adapter(adapter),
3588 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3589 "port 0x%016Lx, unit 0x%016Lx)\n",
3590 zfcp_get_busid_by_adapter(adapter),
3598 zfcp_fsf_req_free(fsf_req);
3600 scsi_cmnd->host_scribble = NULL;
3603 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3608 * function: zfcp_fsf_send_fcp_command_task_management
3614 * FIXME(design): should be watched by a timeout!!!
3615 * FIXME(design) shouldn't this be modified to return an int
3616 * also...don't know how though
3619 struct zfcp_fsf_req *
3620 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3621 struct zfcp_unit *unit,
3622 u8 tm_flags, int req_flags)
3624 struct zfcp_fsf_req *fsf_req = NULL;
3626 struct fcp_cmnd_iu *fcp_cmnd_iu;
3627 unsigned long lock_flags;
3628 volatile struct qdio_buffer_element *sbale;
3630 /* setup new FSF request */
3631 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3632 adapter->pool.fsf_req_scsi,
3633 &lock_flags, &fsf_req);
3635 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3636 "management) request for adapter %s, port "
3637 " 0x%016Lx, unit 0x%016Lx.\n",
3638 zfcp_get_busid_by_adapter(adapter),
3639 unit->port->wwpn, unit->fcp_lun);
3644 * Used to decide on proper handler in the return path,
3645 * could be either zfcp_fsf_send_fcp_command_task_handler or
3646 * zfcp_fsf_send_fcp_command_task_management_handler */
3648 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3651 * hold a pointer to the unit being target of this
3652 * task management request
3654 fsf_req->data.send_fcp_command_task_management.unit = unit;
3656 /* set FSF related fields in QTCB */
3657 fsf_req->qtcb->header.lun_handle = unit->handle;
3658 fsf_req->qtcb->header.port_handle = unit->port->handle;
3659 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3660 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3661 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3662 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3664 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3665 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3666 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3668 /* set FCP related fields in FCP_CMND IU in QTCB */
3669 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3670 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3671 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3672 fcp_cmnd_iu->task_management_flags = tm_flags;
3674 /* start QDIO request for this FSF request */
3675 zfcp_fsf_start_scsi_er_timer(adapter);
3676 retval = zfcp_fsf_req_send(fsf_req, NULL);
3678 del_timer(&adapter->scsi_er_timer);
3679 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3680 "management) on adapter %s, port 0x%016Lx for "
3681 "unit LUN 0x%016Lx\n",
3682 zfcp_get_busid_by_adapter(adapter),
3685 zfcp_fsf_req_free(fsf_req);
3690 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3691 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3693 zfcp_get_busid_by_adapter(adapter),
3698 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3703 * function: zfcp_fsf_send_fcp_command_handler
3705 * purpose: is called for finished Send FCP Command
3710 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3712 int retval = -EINVAL;
3713 struct zfcp_unit *unit;
3714 struct fsf_qtcb_header *header;
3715 u16 subtable, rule, counter;
3717 header = &fsf_req->qtcb->header;
3719 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3720 unit = fsf_req->data.send_fcp_command_task_management.unit;
3722 unit = fsf_req->data.send_fcp_command_task.unit;
3724 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3725 /* go directly to calls of special handlers */
3726 goto skip_fsfstatus;
3729 /* evaluate FSF status in QTCB */
3730 switch (header->fsf_status) {
3732 case FSF_PORT_HANDLE_NOT_VALID:
3733 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3734 "0x%016Lx on adapter %s invalid\n",
3736 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3737 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3738 (char *) &header->fsf_status_qual,
3739 sizeof (union fsf_status_qual));
3740 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3742 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3743 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3746 case FSF_LUN_HANDLE_NOT_VALID:
3747 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3748 "0x%016Lx on port 0x%016Lx on adapter %s is "
3749 "invalid. This may happen occasionally.\n",
3753 zfcp_get_busid_by_unit(unit));
3754 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3755 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3756 (char *) &header->fsf_status_qual,
3757 sizeof (union fsf_status_qual));
3758 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3760 zfcp_erp_port_reopen(unit->port, 0);
3761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3764 case FSF_HANDLE_MISMATCH:
3765 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3766 "unexpectedly. (adapter %s, port 0x%016Lx, "
3769 zfcp_get_busid_by_unit(unit),
3772 ZFCP_LOG_NORMAL("status qualifier:\n");
3773 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3774 (char *) &header->fsf_status_qual,
3775 sizeof (union fsf_status_qual));
3776 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3778 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3779 zfcp_cmd_dbf_event_fsf("handmism",
3781 &header->fsf_status_qual,
3782 sizeof (union fsf_status_qual));
3783 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3786 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3787 if (fsf_req->adapter->fc_service_class <= 3) {
3788 ZFCP_LOG_NORMAL("error: The adapter %s does "
3789 "not support fibrechannel class %d.\n",
3790 zfcp_get_busid_by_unit(unit),
3791 fsf_req->adapter->fc_service_class);
3793 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3794 "adapter %s is invalid. "
3795 "(debug info %d)\n",
3796 zfcp_get_busid_by_unit(unit),
3797 fsf_req->adapter->fc_service_class);
3799 /* stop operation for this adapter */
3800 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3801 "fsf_s_class_nsup");
3802 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3803 zfcp_cmd_dbf_event_fsf("unsclass",
3805 &header->fsf_status_qual,
3806 sizeof (union fsf_status_qual));
3807 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3810 case FSF_FCPLUN_NOT_VALID:
3811 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3812 "adapter %s does not have correct unit "
3816 zfcp_get_busid_by_unit(unit),
3818 ZFCP_LOG_DEBUG("status qualifier:\n");
3819 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3820 (char *) &header->fsf_status_qual,
3821 sizeof (union fsf_status_qual));
3822 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3823 "fsf_s_fcp_lun_nv");
3824 zfcp_erp_port_reopen(unit->port, 0);
3825 zfcp_cmd_dbf_event_fsf("fluninv",
3827 &header->fsf_status_qual,
3828 sizeof (union fsf_status_qual));
3829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3832 case FSF_ACCESS_DENIED:
3833 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3834 "unit 0x%016Lx on port 0x%016Lx on "
3835 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3836 zfcp_get_busid_by_unit(unit));
3837 for (counter = 0; counter < 2; counter++) {
3838 subtable = header->fsf_status_qual.halfword[counter * 2];
3839 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3841 case FSF_SQ_CFDC_SUBTABLE_OS:
3842 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3843 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3844 case FSF_SQ_CFDC_SUBTABLE_LUN:
3845 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3846 zfcp_act_subtable_type[subtable], rule);
3850 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3851 zfcp_erp_unit_access_denied(unit);
3852 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3855 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3856 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3857 "0x%016Lx on port 0x%016Lx on adapter %s "
3858 "(debug info %d)\n",
3861 zfcp_get_busid_by_unit(unit),
3862 fsf_req->qtcb->bottom.io.data_direction);
3863 /* stop operation for this adapter */
3864 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3865 "fsf_s_dir_ind_nv");
3866 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3867 zfcp_cmd_dbf_event_fsf("dirinv",
3869 &header->fsf_status_qual,
3870 sizeof (union fsf_status_qual));
3871 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3874 case FSF_CMND_LENGTH_NOT_VALID:
3876 ("bug: An invalid control-data-block length field "
3877 "was found in a command for unit 0x%016Lx on port "
3878 "0x%016Lx on adapter %s " "(debug info %d)\n",
3879 unit->fcp_lun, unit->port->wwpn,
3880 zfcp_get_busid_by_unit(unit),
3881 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3882 /* stop operation for this adapter */
3883 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3884 "fsf_s_cmd_len_nv");
3885 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3886 zfcp_cmd_dbf_event_fsf("cleninv",
3888 &header->fsf_status_qual,
3889 sizeof (union fsf_status_qual));
3890 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3893 case FSF_PORT_BOXED:
3894 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3895 "needs to be reopened\n",
3896 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3897 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3898 zfcp_erp_port_reopen(unit->port, 0);
3899 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3900 &header->fsf_status_qual,
3901 sizeof (union fsf_status_qual));
3902 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3903 ZFCP_STATUS_FSFREQ_RETRY;
3907 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3908 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3909 zfcp_get_busid_by_unit(unit),
3910 unit->port->wwpn, unit->fcp_lun);
3911 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3912 zfcp_erp_unit_reopen(unit, 0);
3913 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3914 &header->fsf_status_qual,
3915 sizeof(union fsf_status_qual));
3916 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3917 | ZFCP_STATUS_FSFREQ_RETRY;
3920 case FSF_ADAPTER_STATUS_AVAILABLE:
3921 switch (header->fsf_status_qual.word[0]) {
3922 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3923 /* re-establish link to port */
3924 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3926 zfcp_test_link(unit->port);
3928 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3929 /* FIXME(hw) need proper specs for proper action */
3930 /* let scsi stack deal with retries and escalation */
3931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3936 ("Unknown status qualifier 0x%x arrived.\n",
3937 header->fsf_status_qual.word[0]);
3938 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3940 debug_exception(fsf_req->adapter->erp_dbf, 0,
3941 &header->fsf_status_qual.word[0],
3945 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3951 case FSF_FCP_RSP_AVAILABLE:
3955 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3956 debug_exception(fsf_req->adapter->erp_dbf, 0,
3957 &header->fsf_status, sizeof(u32));
3962 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3964 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3966 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3972 * function: zfcp_fsf_send_fcp_command_task_handler
3974 * purpose: evaluates FCP_RSP IU
3979 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3982 struct scsi_cmnd *scpnt;
3983 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3984 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3985 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3986 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3988 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3989 unsigned long flags;
3990 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3992 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3993 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
3994 if (unlikely(!scpnt)) {
3996 ("Command with fsf_req %p is not associated to "
3997 "a scsi command anymore. Aborted?\n", fsf_req);
4000 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4001 /* FIXME: (design) mid-layer should handle DID_ABORT like
4002 * DID_SOFT_ERROR by retrying the request for devices
4003 * that allow retries.
4005 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4006 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4007 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4008 goto skip_fsfstatus;
4011 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4012 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4013 set_host_byte(&scpnt->result, DID_ERROR);
4014 goto skip_fsfstatus;
4017 /* set message byte of result in SCSI command */
4018 scpnt->result |= COMMAND_COMPLETE << 8;
4021 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4022 * of result in SCSI command
4024 scpnt->result |= fcp_rsp_iu->scsi_status;
4025 if (unlikely(fcp_rsp_iu->scsi_status)) {
4027 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4028 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4029 scpnt->cmnd, scpnt->cmd_len);
4030 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4031 fcp_rsp_iu->scsi_status);
4032 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4033 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4034 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4035 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4036 fcp_rsp_iu->fcp_sns_len);
4039 /* check FCP_RSP_INFO */
4040 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4041 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4042 switch (fcp_rsp_info[3]) {
4045 ZFCP_LOG_TRACE("no failure or Task Management "
4046 "Function complete\n");
4047 set_host_byte(&scpnt->result, DID_OK);
4049 case RSP_CODE_LENGTH_MISMATCH:
4051 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4052 "that the fibrechannel protocol data "
4053 "length differs from the burst length. "
4054 "The problem occured on unit 0x%016Lx "
4055 "on port 0x%016Lx on adapter %s",
4058 zfcp_get_busid_by_unit(unit));
4059 /* dump SCSI CDB as prepared by zfcp */
4060 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4061 (char *) &fsf_req->qtcb->
4062 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4063 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4064 set_host_byte(&scpnt->result, DID_ERROR);
4065 goto skip_fsfstatus;
4066 case RSP_CODE_FIELD_INVALID:
4067 /* driver or hardware bug */
4068 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4069 "that the fibrechannel protocol data "
4070 "fields were incorrectly set up. "
4071 "The problem occured on the unit "
4072 "0x%016Lx on port 0x%016Lx on "
4076 zfcp_get_busid_by_unit(unit));
4077 /* dump SCSI CDB as prepared by zfcp */
4078 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4079 (char *) &fsf_req->qtcb->
4080 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4081 set_host_byte(&scpnt->result, DID_ERROR);
4082 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4083 goto skip_fsfstatus;
4084 case RSP_CODE_RO_MISMATCH:
4086 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4087 "that conflicting values for the "
4088 "fibrechannel payload offset from the "
4089 "header were found. "
4090 "The problem occured on unit 0x%016Lx "
4091 "on port 0x%016Lx on adapter %s.\n",
4094 zfcp_get_busid_by_unit(unit));
4095 /* dump SCSI CDB as prepared by zfcp */
4096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4097 (char *) &fsf_req->qtcb->
4098 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4099 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4100 set_host_byte(&scpnt->result, DID_ERROR);
4101 goto skip_fsfstatus;
4103 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4104 "code was detected for a command. "
4105 "The problem occured on the unit "
4106 "0x%016Lx on port 0x%016Lx on "
4107 "adapter %s (debug info 0x%x)\n",
4110 zfcp_get_busid_by_unit(unit),
4112 /* dump SCSI CDB as prepared by zfcp */
4113 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4114 (char *) &fsf_req->qtcb->
4115 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4116 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4117 set_host_byte(&scpnt->result, DID_ERROR);
4118 goto skip_fsfstatus;
4122 /* check for sense data */
4123 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4124 sns_len = FSF_FCP_RSP_SIZE -
4125 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4126 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4128 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4129 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4130 SCSI_SENSE_BUFFERSIZE);
4131 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4132 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4134 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4135 (void *) &scpnt->cmnd, scpnt->cmd_len);
4137 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4138 fcp_rsp_iu->fcp_sns_len);
4139 memcpy(&scpnt->sense_buffer,
4140 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4141 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4142 (void *) &scpnt->sense_buffer, sns_len);
4145 /* check for overrun */
4146 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4147 ZFCP_LOG_INFO("A data overrun 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));
4158 /* check for underrun */
4159 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4160 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4161 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4162 "The response data length is "
4163 "%d, the original length was %d.\n",
4166 zfcp_get_busid_by_unit(unit),
4167 fcp_rsp_iu->fcp_resid,
4168 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4170 scpnt->resid = fcp_rsp_iu->fcp_resid;
4171 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4172 set_host_byte(&scpnt->result, DID_ERROR);
4176 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4178 zfcp_cmd_dbf_event_scsi("response", scpnt);
4180 /* cleanup pointer (need this especially for abort) */
4181 scpnt->host_scribble = NULL;
4185 * according to the outcome of a discussion on linux-scsi we
4186 * don't need to grab the io_request_lock here since we use
4189 /* always call back */
4191 (scpnt->scsi_done) (scpnt);
4194 * We must hold this lock until scsi_done has been called.
4195 * Otherwise we may call scsi_done after abort regarding this
4196 * command has completed.
4197 * Note: scsi_done must not block!
4200 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4205 * function: zfcp_fsf_send_fcp_command_task_management_handler
4207 * purpose: evaluates FCP_RSP IU
4212 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4215 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4216 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4217 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4218 struct zfcp_unit *unit =
4219 fsf_req->data.send_fcp_command_task_management.unit;
4221 del_timer(&fsf_req->adapter->scsi_er_timer);
4222 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4223 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4224 goto skip_fsfstatus;
4227 /* check FCP_RSP_INFO */
4228 switch (fcp_rsp_info[3]) {
4231 ZFCP_LOG_DEBUG("no failure or Task Management "
4232 "Function complete\n");
4234 case RSP_CODE_TASKMAN_UNSUPP:
4235 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4236 "is not supported on the target device "
4237 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4240 zfcp_get_busid_by_unit(unit));
4241 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4243 case RSP_CODE_TASKMAN_FAILED:
4244 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4245 "failed to complete successfully. "
4246 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4249 zfcp_get_busid_by_unit(unit));
4250 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4253 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4254 "code was detected for a command. "
4255 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4256 "(debug info 0x%x)\n",
4259 zfcp_get_busid_by_unit(unit),
4261 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4270 * function: zfcp_fsf_control_file
4272 * purpose: Initiator of the control file upload/download FSF requests
4274 * returns: 0 - FSF request is successfuly created and queued
4275 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4276 * -EINVAL - Invalid direction specified
4277 * -ENOMEM - Insufficient memory
4278 * -EPERM - Cannot create FSF request or place it in QDIO queue
4281 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4282 struct zfcp_fsf_req **fsf_req_ptr,
4285 struct zfcp_sg_list *sg_list)
4287 struct zfcp_fsf_req *fsf_req;
4288 struct fsf_qtcb_bottom_support *bottom;
4289 volatile struct qdio_buffer_element *sbale;
4290 struct timer_list *timer;
4291 unsigned long lock_flags;
4296 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4297 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4298 zfcp_get_busid_by_adapter(adapter));
4299 retval = -EOPNOTSUPP;
4303 switch (fsf_command) {
4305 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4306 direction = SBAL_FLAGS0_TYPE_WRITE;
4307 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4308 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4309 req_flags = ZFCP_WAIT_FOR_SBAL;
4312 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4313 direction = SBAL_FLAGS0_TYPE_READ;
4317 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4322 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4328 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4329 NULL, &lock_flags, &fsf_req);
4331 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4333 zfcp_get_busid_by_adapter(adapter));
4335 goto unlock_queue_lock;
4338 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4339 sbale[0].flags |= direction;
4341 bottom = &fsf_req->qtcb->bottom.support;
4342 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4343 bottom->option = option;
4345 if (sg_list->count > 0) {
4348 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4349 sg_list->sg, sg_list->count,
4350 ZFCP_MAX_SBALS_PER_REQ);
4351 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4353 "error: Could not create sufficient number of "
4354 "SBALS for an FSF request to the adapter %s\n",
4355 zfcp_get_busid_by_adapter(adapter));
4360 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4363 timer->function = zfcp_fsf_request_timeout_handler;
4364 timer->data = (unsigned long) adapter;
4365 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4367 retval = zfcp_fsf_req_send(fsf_req, timer);
4369 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4371 zfcp_get_busid_by_adapter(adapter));
4375 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4377 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4379 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4380 "download" : "upload",
4381 zfcp_get_busid_by_adapter(adapter));
4383 wait_event(fsf_req->completion_wq,
4384 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4386 *fsf_req_ptr = fsf_req;
4387 del_timer_sync(timer);
4391 zfcp_fsf_req_free(fsf_req);
4393 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4402 * function: zfcp_fsf_control_file_handler
4404 * purpose: Handler of the control file upload/download FSF requests
4406 * returns: 0 - FSF request successfuly processed
4407 * -EAGAIN - Operation has to be repeated because of a temporary problem
4408 * -EACCES - There is no permission to execute an operation
4409 * -EPERM - The control file is not in a right format
4410 * -EIO - There is a problem with the FCP adapter
4411 * -EINVAL - Invalid operation
4412 * -EFAULT - User space memory I/O operation fault
4415 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4417 struct zfcp_adapter *adapter = fsf_req->adapter;
4418 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4419 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4422 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4424 goto skip_fsfstatus;
4427 switch (header->fsf_status) {
4431 "The FSF request has been successfully completed "
4432 "on the adapter %s\n",
4433 zfcp_get_busid_by_adapter(adapter));
4436 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4437 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4438 switch (header->fsf_status_qual.word[0]) {
4440 case FSF_SQ_CFDC_HARDENED_ON_SE:
4442 "CFDC on the adapter %s has being "
4443 "hardened on primary and secondary SE\n",
4444 zfcp_get_busid_by_adapter(adapter));
4447 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4449 "CFDC of the adapter %s could not "
4450 "be saved on the SE\n",
4451 zfcp_get_busid_by_adapter(adapter));
4454 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4456 "CFDC of the adapter %s could not "
4457 "be copied to the secondary SE\n",
4458 zfcp_get_busid_by_adapter(adapter));
4463 "CFDC could not be hardened "
4464 "on the adapter %s\n",
4465 zfcp_get_busid_by_adapter(adapter));
4468 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4472 case FSF_AUTHORIZATION_FAILURE:
4474 "Adapter %s does not accept privileged commands\n",
4475 zfcp_get_busid_by_adapter(adapter));
4476 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4480 case FSF_CFDC_ERROR_DETECTED:
4482 "Error at position %d in the CFDC, "
4483 "CFDC is discarded by the adapter %s\n",
4484 header->fsf_status_qual.word[0],
4485 zfcp_get_busid_by_adapter(adapter));
4486 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4490 case FSF_CONTROL_FILE_UPDATE_ERROR:
4492 "Adapter %s cannot harden the control file, "
4493 "file is discarded\n",
4494 zfcp_get_busid_by_adapter(adapter));
4495 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4499 case FSF_CONTROL_FILE_TOO_LARGE:
4501 "Control file is too large, file is discarded "
4502 "by the adapter %s\n",
4503 zfcp_get_busid_by_adapter(adapter));
4504 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4508 case FSF_ACCESS_CONFLICT_DETECTED:
4509 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4511 "CFDC has been discarded by the adapter %s, "
4512 "because activation would impact "
4513 "%d active connection(s)\n",
4514 zfcp_get_busid_by_adapter(adapter),
4515 header->fsf_status_qual.word[0]);
4516 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4520 case FSF_CONFLICTS_OVERRULED:
4521 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4523 "CFDC has been activated on the adapter %s, "
4524 "but activation has impacted "
4525 "%d active connection(s)\n",
4526 zfcp_get_busid_by_adapter(adapter),
4527 header->fsf_status_qual.word[0]);
4528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4532 case FSF_UNKNOWN_OP_SUBTYPE:
4533 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4534 "op_subtype=0x%x)\n",
4535 zfcp_get_busid_by_adapter(adapter),
4536 bottom->operation_subtype);
4537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4541 case FSF_INVALID_COMMAND_OPTION:
4543 "Invalid option 0x%x has been specified "
4544 "in QTCB bottom sent to the adapter %s\n",
4546 zfcp_get_busid_by_adapter(adapter));
4547 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4553 "bug: An unknown/unexpected FSF status 0x%08x "
4554 "was presented on the adapter %s\n",
4556 zfcp_get_busid_by_adapter(adapter));
4557 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4558 debug_exception(fsf_req->adapter->erp_dbf, 0,
4559 &header->fsf_status_qual.word[0], sizeof(u32));
4560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4571 * function: zfcp_fsf_req_wait_and_cleanup
4575 * FIXME(design): signal seems to be <0 !!!
4576 * returns: 0 - request completed (*status is valid), cleanup succ.
4577 * <0 - request completed (*status is valid), cleanup failed
4578 * >0 - signal which interrupted waiting (*status invalid),
4579 * request not completed, no cleanup
4581 * *status is a copy of status of completed fsf_req
4584 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4585 int interruptible, u32 * status)
4590 if (interruptible) {
4591 __wait_event_interruptible(fsf_req->completion_wq,
4593 ZFCP_STATUS_FSFREQ_COMPLETED,
4596 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4597 "completion of the request at %p\n",
4603 __wait_event(fsf_req->completion_wq,
4604 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4607 *status = fsf_req->status;
4609 /* cleanup request */
4610 zfcp_fsf_req_cleanup(fsf_req);
4616 zfcp_fsf_req_sbal_check(unsigned long *flags,
4617 struct zfcp_qdio_queue *queue, int needed)
4619 write_lock_irqsave(&queue->queue_lock, *flags);
4620 if (likely(atomic_read(&queue->free_count) >= needed))
4622 write_unlock_irqrestore(&queue->queue_lock, *flags);
4627 * set qtcb pointer in fsf_req and initialize QTCB
4630 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4632 if (likely(fsf_req->qtcb != NULL)) {
4633 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4634 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4635 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4636 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4637 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4638 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4643 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4644 * @adapter: adapter for which request queue is examined
4645 * @req_flags: flags indicating whether to wait for needed SBAL or not
4646 * @lock_flags: lock_flags if queue_lock is taken
4647 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4648 * Locks: lock adapter->request_queue->queue_lock on success
4651 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4652 unsigned long *lock_flags)
4655 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4657 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4658 ret = wait_event_interruptible_timeout(adapter->request_wq,
4659 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4665 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4672 * function: zfcp_fsf_req_create
4674 * purpose: create an FSF request at the specified adapter and
4675 * setup common fields
4677 * returns: -ENOMEM if there was insufficient memory for a request
4678 * -EIO if no qdio buffers could be allocate to the request
4679 * -EINVAL/-EPERM on bug conditions in req_dequeue
4682 * note: The created request is returned by reference.
4684 * locks: lock of concerned request queue must not be held,
4685 * but is held on completion (write, irqsave)
4688 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4689 mempool_t *pool, unsigned long *lock_flags,
4690 struct zfcp_fsf_req **fsf_req_p)
4692 volatile struct qdio_buffer_element *sbale;
4693 struct zfcp_fsf_req *fsf_req = NULL;
4695 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4697 /* allocate new FSF request */
4698 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4699 if (unlikely(NULL == fsf_req)) {
4700 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4701 "the outbound (send) queue.\n");
4703 goto failed_fsf_req;
4706 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4708 /* initialize waitqueue which may be used to wait on
4709 this request completion */
4710 init_waitqueue_head(&fsf_req->completion_wq);
4712 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4718 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4719 * if it is not set (see also *_open_qdio and *_close_qdio).
4722 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4723 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4728 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4729 fsf_req->fsf_command = fsf_cmd;
4730 fsf_req->sbal_number = 1;
4731 fsf_req->sbal_first = req_queue->free_index;
4732 fsf_req->sbal_curr = req_queue->free_index;
4733 fsf_req->sbale_curr = 1;
4735 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4736 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4739 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4741 /* setup common SBALE fields */
4742 sbale[0].addr = fsf_req;
4743 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4744 if (likely(fsf_req->qtcb != NULL)) {
4745 sbale[1].addr = (void *) fsf_req->qtcb;
4746 sbale[1].length = sizeof(struct fsf_qtcb);
4749 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4750 fsf_req->sbal_number, fsf_req->sbal_first);
4755 /* dequeue new FSF request previously enqueued */
4756 zfcp_fsf_req_free(fsf_req);
4760 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4762 *fsf_req_p = fsf_req;
4767 * function: zfcp_fsf_req_send
4769 * purpose: start transfer of FSF request via QDIO
4771 * returns: 0 - request transfer succesfully started
4772 * !0 - start of request transfer failed
4775 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4777 struct zfcp_adapter *adapter;
4778 struct zfcp_qdio_queue *req_queue;
4779 volatile struct qdio_buffer_element *sbale;
4780 int new_distance_from_int;
4781 unsigned long flags;
4785 adapter = fsf_req->adapter;
4786 req_queue = &adapter->request_queue,
4789 /* FIXME(debug): remove it later */
4790 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4791 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4792 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4793 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4796 /* set sequence counter in QTCB */
4797 if (likely(fsf_req->qtcb)) {
4798 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4799 fsf_req->seq_no = adapter->fsf_req_seq_no;
4800 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4801 "FSF sequence counter value of %i\n",
4803 zfcp_get_busid_by_adapter(adapter),
4804 fsf_req->qtcb->prefix.req_seq_no);
4808 /* put allocated FSF request at list tail */
4809 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4810 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4811 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4813 /* figure out expiration time of timeout and start timeout */
4814 if (unlikely(timer)) {
4815 timer->expires += jiffies;
4819 ZFCP_LOG_TRACE("request queue of adapter %s: "
4820 "next free SBAL is %i, %i free SBALs\n",
4821 zfcp_get_busid_by_adapter(adapter),
4822 req_queue->free_index,
4823 atomic_read(&req_queue->free_count));
4825 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4826 "index_in_queue=%i, count=%i, buffers=%p\n",
4827 zfcp_get_busid_by_adapter(adapter),
4828 QDIO_FLAG_SYNC_OUTPUT,
4829 0, fsf_req->sbal_first, fsf_req->sbal_number,
4830 &req_queue->buffer[fsf_req->sbal_first]);
4833 * adjust the number of free SBALs in request queue as well as
4834 * position of first one
4836 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4837 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4838 req_queue->free_index += fsf_req->sbal_number; /* increase */
4839 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4840 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4842 retval = do_QDIO(adapter->ccw_device,
4843 QDIO_FLAG_SYNC_OUTPUT,
4844 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4846 if (unlikely(retval)) {
4847 /* Queues are down..... */
4850 * FIXME(potential race):
4851 * timer might be expired (absolutely unlikely)
4855 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4856 list_del(&fsf_req->list);
4857 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4859 * adjust the number of free SBALs in request queue as well as
4860 * position of first one
4862 zfcp_qdio_zero_sbals(req_queue->buffer,
4863 fsf_req->sbal_first, fsf_req->sbal_number);
4864 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4865 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4866 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4867 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4869 ("error: do_QDIO failed. Buffers could not be enqueued "
4870 "to request queue.\n");
4872 req_queue->distance_from_int = new_distance_from_int;
4874 * increase FSF sequence counter -
4875 * this must only be done for request successfully enqueued to
4876 * QDIO this rejected requests may be cleaned up by calling
4877 * routines resulting in missing sequence counter values
4880 /* Don't increase for unsolicited status */
4881 if (likely(inc_seq_no)) {
4882 adapter->fsf_req_seq_no++;
4884 ("FSF sequence counter value of adapter %s "
4885 "increased to %i\n",
4886 zfcp_get_busid_by_adapter(adapter),
4887 adapter->fsf_req_seq_no);
4889 /* count FSF requests pending */
4890 atomic_inc(&adapter->fsf_reqs_active);
4896 * function: zfcp_fsf_req_cleanup
4898 * purpose: cleans up an FSF request and removes it from the specified list
4902 * assumption: no pending SB in SBALEs other than QTCB
4905 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4907 struct zfcp_adapter *adapter = fsf_req->adapter;
4908 unsigned long flags;
4910 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4911 list_del(&fsf_req->list);
4912 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4913 zfcp_fsf_req_free(fsf_req);
4916 #undef ZFCP_LOG_AREA