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;
1775 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 d_id = send_els->d_id;
1785 header = &fsf_req->qtcb->header;
1786 bottom = &fsf_req->qtcb->bottom.support;
1788 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1789 goto skip_fsfstatus;
1791 switch (header->fsf_status) {
1797 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1798 if (adapter->fc_service_class <= 3) {
1799 ZFCP_LOG_INFO("error: adapter %s does "
1800 "not support fibrechannel class %d.\n",
1801 zfcp_get_busid_by_adapter(adapter),
1802 adapter->fc_service_class);
1804 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1805 "adapter %s is invalid. "
1806 "(debug info %d)\n",
1807 zfcp_get_busid_by_adapter(adapter),
1808 adapter->fc_service_class);
1810 /* stop operation for this adapter */
1811 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1812 zfcp_erp_adapter_shutdown(adapter, 0);
1813 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1816 case FSF_ADAPTER_STATUS_AVAILABLE:
1817 switch (header->fsf_status_qual.word[0]){
1818 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1819 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1820 if (send_els->ls_code != ZFCP_LS_ADISC) {
1821 read_lock(&zfcp_data.config_lock);
1822 port = zfcp_get_port_by_did(adapter, d_id);
1824 zfcp_test_link(port);
1825 read_unlock(&zfcp_data.config_lock);
1827 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1829 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1830 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1831 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1833 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1834 (struct zfcp_ls_rjt_par *)
1835 &header->fsf_status_qual.word[2]);
1837 case FSF_SQ_RETRY_IF_POSSIBLE:
1838 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1842 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1843 header->fsf_status_qual.word[0]);
1844 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1845 (char*)header->fsf_status_qual.word, 16);
1849 case FSF_ELS_COMMAND_REJECTED:
1850 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1851 "prohibited sending "
1852 "(adapter: %s, port d_id: 0x%08x)\n",
1853 zfcp_get_busid_by_adapter(adapter), d_id);
1857 case FSF_PAYLOAD_SIZE_MISMATCH:
1859 "ELS request size and ELS response size must be either "
1860 "both 0, or both greater than 0 "
1861 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1862 zfcp_get_busid_by_adapter(adapter),
1863 bottom->req_buf_length,
1864 bottom->resp_buf_length);
1867 case FSF_REQUEST_SIZE_TOO_LARGE:
1869 "Length of the ELS request buffer, "
1870 "specified in QTCB bottom, "
1871 "exceeds the size of the buffers "
1872 "that have been allocated for ELS request data "
1873 "(adapter: %s, req_buf_length=%d)\n",
1874 zfcp_get_busid_by_adapter(adapter),
1875 bottom->req_buf_length);
1878 case FSF_RESPONSE_SIZE_TOO_LARGE:
1880 "Length of the ELS response buffer, "
1881 "specified in QTCB bottom, "
1882 "exceeds the size of the buffers "
1883 "that have been allocated for ELS response data "
1884 "(adapter: %s, resp_buf_length=%d)\n",
1885 zfcp_get_busid_by_adapter(adapter),
1886 bottom->resp_buf_length);
1889 case FSF_SBAL_MISMATCH:
1890 /* should never occure, avoided in zfcp_fsf_send_els */
1891 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1892 "resp_buf_length=%d)\n",
1893 zfcp_get_busid_by_adapter(adapter),
1894 bottom->req_buf_length, bottom->resp_buf_length);
1895 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1898 case FSF_ACCESS_DENIED:
1899 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1900 "(adapter %s, port d_id=0x%08x)\n",
1901 zfcp_get_busid_by_adapter(adapter), d_id);
1902 for (counter = 0; counter < 2; counter++) {
1903 subtable = header->fsf_status_qual.halfword[counter * 2];
1904 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1906 case FSF_SQ_CFDC_SUBTABLE_OS:
1907 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1908 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1909 case FSF_SQ_CFDC_SUBTABLE_LUN:
1910 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1911 zfcp_act_subtable_type[subtable], rule);
1915 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1916 read_lock(&zfcp_data.config_lock);
1917 port = zfcp_get_port_by_did(adapter, d_id);
1919 zfcp_erp_port_access_denied(port);
1920 read_unlock(&zfcp_data.config_lock);
1921 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1926 "bug: An unknown FSF Status was presented "
1927 "(adapter: %s, fsf_status=0x%08x)\n",
1928 zfcp_get_busid_by_adapter(adapter),
1929 header->fsf_status);
1930 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1931 debug_exception(adapter->erp_dbf, 0,
1932 &header->fsf_status_qual.word[0], sizeof(u32));
1933 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1938 send_els->status = retval;
1940 if (send_els->handler != 0)
1941 send_els->handler(send_els->handler_data);
1951 * returns: address of initiated FSF request
1952 * NULL - request could not be initiated
1955 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1957 volatile struct qdio_buffer_element *sbale;
1958 unsigned long lock_flags;
1961 /* setup new FSF request */
1962 retval = zfcp_fsf_req_create(erp_action->adapter,
1963 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1964 ZFCP_REQ_AUTO_CLEANUP,
1965 erp_action->adapter->pool.fsf_req_erp,
1966 &lock_flags, &(erp_action->fsf_req));
1968 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1969 "data request for adapter %s.\n",
1970 zfcp_get_busid_by_adapter(erp_action->adapter));
1974 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1975 erp_action->fsf_req->sbal_curr, 0);
1976 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1977 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1979 erp_action->fsf_req->erp_action = erp_action;
1980 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1981 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
1983 /* start QDIO request for this FSF request */
1984 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1987 ("error: Could not send exchange configuration data "
1988 "command on the adapter %s\n",
1989 zfcp_get_busid_by_adapter(erp_action->adapter));
1990 zfcp_fsf_req_free(erp_action->fsf_req);
1991 erp_action->fsf_req = NULL;
1995 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1997 zfcp_get_busid_by_adapter(erp_action->adapter));
2000 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2006 * zfcp_fsf_exchange_config_evaluate
2007 * @fsf_req: fsf_req which belongs to xchg config data request
2008 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2010 * returns: -EIO on error, 0 otherwise
2013 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2015 struct fsf_qtcb_bottom_config *bottom;
2016 struct zfcp_adapter *adapter = fsf_req->adapter;
2018 bottom = &fsf_req->qtcb->bottom.config;
2019 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2020 bottom->low_qtcb_version, bottom->high_qtcb_version);
2021 adapter->fsf_lic_version = bottom->lic_version;
2022 adapter->supported_features = bottom->supported_features;
2023 adapter->peer_wwpn = 0;
2024 adapter->peer_wwnn = 0;
2025 adapter->peer_d_id = 0;
2028 adapter->wwnn = bottom->nport_serv_param.wwnn;
2029 adapter->wwpn = bottom->nport_serv_param.wwpn;
2030 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2031 adapter->fc_topology = bottom->fc_topology;
2032 adapter->fc_link_speed = bottom->fc_link_speed;
2033 adapter->hydra_version = bottom->adapter_type;
2038 adapter->fc_topology = 0;
2039 adapter->fc_link_speed = 0;
2040 adapter->hydra_version = 0;
2043 if (adapter->fc_topology == FSF_TOPO_P2P) {
2044 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2045 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2046 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2049 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2050 adapter->hardware_version = bottom->hardware_version;
2051 memcpy(adapter->serial_number, bottom->serial_number, 17);
2052 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2055 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2059 "adapter version 0x%x, "
2060 "LIC version 0x%x, "
2061 "FC link speed %d Gb/s\n",
2062 zfcp_get_busid_by_adapter(adapter),
2065 (unsigned int) adapter->s_id,
2066 adapter->hydra_version,
2067 adapter->fsf_lic_version,
2068 adapter->fc_link_speed);
2069 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2070 ZFCP_LOG_NORMAL("error: the adapter %s "
2071 "only supports newer control block "
2072 "versions in comparison to this device "
2073 "driver (try updated device driver)\n",
2074 zfcp_get_busid_by_adapter(adapter));
2075 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2076 zfcp_erp_adapter_shutdown(adapter, 0);
2079 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2080 ZFCP_LOG_NORMAL("error: the adapter %s "
2081 "only supports older control block "
2082 "versions than this device driver uses"
2083 "(consider a microcode upgrade)\n",
2084 zfcp_get_busid_by_adapter(adapter));
2085 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2086 zfcp_erp_adapter_shutdown(adapter, 0);
2093 * function: zfcp_fsf_exchange_config_data_handler
2095 * purpose: is called for finished Exchange Configuration Data command
2100 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2102 struct fsf_qtcb_bottom_config *bottom;
2103 struct zfcp_adapter *adapter = fsf_req->adapter;
2105 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2108 switch (fsf_req->qtcb->header.fsf_status) {
2111 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2114 switch (adapter->fc_topology) {
2116 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2117 "configuration detected at adapter %s\n"
2118 "Peer WWNN 0x%016llx, "
2119 "peer WWPN 0x%016llx, "
2120 "peer d_id 0x%06x\n",
2121 zfcp_get_busid_by_adapter(adapter),
2124 adapter->peer_d_id);
2125 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2129 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2130 "topology detected at adapter %s "
2131 "unsupported, shutting down adapter\n",
2132 zfcp_get_busid_by_adapter(adapter));
2133 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2135 zfcp_erp_adapter_shutdown(adapter, 0);
2137 case FSF_TOPO_FABRIC:
2138 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2139 "network detected at adapter %s.\n",
2140 zfcp_get_busid_by_adapter(adapter));
2143 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2144 "reported by the exchange "
2145 "configuration command for "
2146 "the adapter %s is not "
2147 "of a type known to the zfcp "
2148 "driver, shutting down adapter\n",
2149 zfcp_get_busid_by_adapter(adapter));
2150 adapter->fc_topology = FSF_TOPO_ERROR;
2151 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2153 zfcp_erp_adapter_shutdown(adapter, 0);
2156 bottom = &fsf_req->qtcb->bottom.config;
2157 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2158 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2159 "allowed by the adapter %s "
2160 "is lower than the minimum "
2161 "required by the driver (%ld bytes).\n",
2162 bottom->max_qtcb_size,
2163 zfcp_get_busid_by_adapter(adapter),
2164 sizeof(struct fsf_qtcb));
2165 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2167 debug_event(fsf_req->adapter->erp_dbf, 0,
2168 &bottom->max_qtcb_size, sizeof (u32));
2169 zfcp_erp_adapter_shutdown(adapter, 0);
2172 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2175 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2176 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2178 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2181 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2182 zfcp_get_busid_by_adapter(adapter));
2183 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2184 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2186 zfcp_erp_adapter_failed(adapter);
2189 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2190 debug_event(fsf_req->adapter->erp_dbf, 0,
2191 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2192 zfcp_erp_adapter_shutdown(adapter, 0);
2199 * zfcp_fsf_exchange_port_data - request information about local port
2200 * @adapter: for which port data is requested
2201 * @data: response to exchange port data request
2204 zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2205 struct fsf_qtcb_bottom_port *data)
2207 volatile struct qdio_buffer_element *sbale;
2209 unsigned long lock_flags;
2210 struct zfcp_fsf_req *fsf_req;
2211 struct timer_list *timer;
2213 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2214 ZFCP_LOG_INFO("error: exchange port data "
2215 "command not supported by adapter %s\n",
2216 zfcp_get_busid_by_adapter(adapter));
2220 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2224 /* setup new FSF request */
2225 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2226 0, 0, &lock_flags, &fsf_req);
2228 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2229 "exchange port data request for"
2230 "the adapter %s.\n",
2231 zfcp_get_busid_by_adapter(adapter));
2232 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2237 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2238 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2239 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2241 fsf_req->data.port_data = data;
2244 timer->function = zfcp_fsf_request_timeout_handler;
2245 timer->data = (unsigned long) adapter;
2246 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2248 retval = zfcp_fsf_req_send(fsf_req, timer);
2250 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2251 "command on the adapter %s\n",
2252 zfcp_get_busid_by_adapter(adapter));
2253 zfcp_fsf_req_free(fsf_req);
2254 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2259 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2260 zfcp_get_busid_by_adapter(adapter));
2262 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2265 wait_event(fsf_req->completion_wq,
2266 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2267 del_timer_sync(timer);
2268 zfcp_fsf_req_cleanup(fsf_req);
2276 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2277 * @fsf_req: pointer to struct zfcp_fsf_req
2280 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2282 struct fsf_qtcb_bottom_port *bottom;
2283 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2285 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2288 switch (fsf_req->qtcb->header.fsf_status) {
2290 bottom = &fsf_req->qtcb->bottom.port;
2291 memcpy(data, bottom, sizeof(*data));
2295 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2296 debug_event(fsf_req->adapter->erp_dbf, 0,
2297 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2303 * function: zfcp_fsf_open_port
2307 * returns: address of initiated FSF request
2308 * NULL - request could not be initiated
2311 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2313 volatile struct qdio_buffer_element *sbale;
2314 unsigned long lock_flags;
2317 /* setup new FSF request */
2318 retval = zfcp_fsf_req_create(erp_action->adapter,
2319 FSF_QTCB_OPEN_PORT_WITH_DID,
2320 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2321 erp_action->adapter->pool.fsf_req_erp,
2322 &lock_flags, &(erp_action->fsf_req));
2324 ZFCP_LOG_INFO("error: Could not create open port request "
2325 "for port 0x%016Lx on adapter %s.\n",
2326 erp_action->port->wwpn,
2327 zfcp_get_busid_by_adapter(erp_action->adapter));
2331 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2332 erp_action->fsf_req->sbal_curr, 0);
2333 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2334 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2336 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2337 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2338 erp_action->fsf_req->data.open_port.port = erp_action->port;
2339 erp_action->fsf_req->erp_action = erp_action;
2341 /* start QDIO request for this FSF request */
2342 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2344 ZFCP_LOG_INFO("error: Could not send open port request for "
2345 "port 0x%016Lx on adapter %s.\n",
2346 erp_action->port->wwpn,
2347 zfcp_get_busid_by_adapter(erp_action->adapter));
2348 zfcp_fsf_req_free(erp_action->fsf_req);
2349 erp_action->fsf_req = NULL;
2353 ZFCP_LOG_DEBUG("open port request initiated "
2354 "(adapter %s, port 0x%016Lx)\n",
2355 zfcp_get_busid_by_adapter(erp_action->adapter),
2356 erp_action->port->wwpn);
2358 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2364 * function: zfcp_fsf_open_port_handler
2366 * purpose: is called for finished Open Port command
2371 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2373 int retval = -EINVAL;
2374 struct zfcp_port *port;
2375 struct fsf_plogi *plogi;
2376 struct fsf_qtcb_header *header;
2377 u16 subtable, rule, counter;
2379 port = fsf_req->data.open_port.port;
2380 header = &fsf_req->qtcb->header;
2382 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2383 /* don't change port status in our bookkeeping */
2384 goto skip_fsfstatus;
2387 /* evaluate FSF status in QTCB */
2388 switch (header->fsf_status) {
2390 case FSF_PORT_ALREADY_OPEN:
2391 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2392 "is already open.\n",
2393 port->wwpn, zfcp_get_busid_by_port(port));
2394 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2397 * This is a bug, however operation should continue normally
2398 * if it is simply ignored
2402 case FSF_ACCESS_DENIED:
2403 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2405 port->wwpn, zfcp_get_busid_by_port(port));
2406 for (counter = 0; counter < 2; counter++) {
2407 subtable = header->fsf_status_qual.halfword[counter * 2];
2408 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2410 case FSF_SQ_CFDC_SUBTABLE_OS:
2411 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2412 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2413 case FSF_SQ_CFDC_SUBTABLE_LUN:
2414 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2415 zfcp_act_subtable_type[subtable], rule);
2419 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2420 zfcp_erp_port_access_denied(port);
2421 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2424 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2425 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2426 "The remote port 0x%016Lx on adapter %s "
2427 "could not be opened. Disabling it.\n",
2428 port->wwpn, zfcp_get_busid_by_port(port));
2429 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2431 zfcp_erp_port_failed(port);
2432 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2435 case FSF_ADAPTER_STATUS_AVAILABLE:
2436 switch (header->fsf_status_qual.word[0]) {
2437 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2438 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2440 /* ERP strategy will escalate */
2441 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2443 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2444 /* ERP strategy will escalate */
2445 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2447 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2449 case FSF_SQ_NO_RETRY_POSSIBLE:
2450 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2451 "adapter %s could not be opened. "
2454 zfcp_get_busid_by_port(port));
2455 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2457 zfcp_erp_port_failed(port);
2458 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2462 ("bug: Wrong status qualifier 0x%x arrived.\n",
2463 header->fsf_status_qual.word[0]);
2464 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2467 fsf_req->adapter->erp_dbf, 0,
2468 &header->fsf_status_qual.word[0],
2475 /* save port handle assigned by FSF */
2476 port->handle = header->port_handle;
2477 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2478 "was opened, it's port handle is 0x%x\n",
2479 port->wwpn, zfcp_get_busid_by_port(port),
2481 /* mark port as open */
2482 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2483 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2485 /* check whether D_ID has changed during open */
2487 * FIXME: This check is not airtight, as the FCP channel does
2488 * not monitor closures of target port connections caused on
2489 * the remote side. Thus, they might miss out on invalidating
2490 * locally cached WWPNs (and other N_Port parameters) of gone
2491 * target ports. So, our heroic attempt to make things safe
2492 * could be undermined by 'open port' response data tagged with
2493 * obsolete WWPNs. Another reason to monitor potential
2494 * connection closures ourself at least (by interpreting
2495 * incoming ELS' and unsolicited status). It just crosses my
2496 * mind that one should be able to cross-check by means of
2497 * another GID_PN straight after a port has been opened.
2498 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2500 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2501 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2503 if (fsf_req->qtcb->bottom.support.els1_length <
2504 ((((unsigned long) &plogi->serv_param.wwpn) -
2505 ((unsigned long) plogi)) + sizeof (u64))) {
2507 "warning: insufficient length of "
2508 "PLOGI payload (%i)\n",
2509 fsf_req->qtcb->bottom.support.els1_length);
2510 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2511 "fsf_s_short_plogi:");
2512 /* skip sanity check and assume wwpn is ok */
2514 if (plogi->serv_param.wwpn != port->wwpn) {
2515 ZFCP_LOG_INFO("warning: d_id of port "
2516 "0x%016Lx changed during "
2517 "open\n", port->wwpn);
2519 fsf_req->adapter->erp_dbf, 0,
2520 "fsf_s_did_change:");
2522 ZFCP_STATUS_PORT_DID_DID,
2525 port->wwnn = plogi->serv_param.wwnn;
2530 case FSF_UNKNOWN_OP_SUBTYPE:
2531 /* should never occure, subtype not set in zfcp_fsf_open_port */
2532 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2533 "op_subtype=0x%x)\n",
2534 zfcp_get_busid_by_port(port),
2535 fsf_req->qtcb->bottom.support.operation_subtype);
2536 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2540 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2541 "(debug info 0x%x)\n",
2542 header->fsf_status);
2543 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2544 debug_exception(fsf_req->adapter->erp_dbf, 0,
2545 &header->fsf_status, sizeof (u32));
2550 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2555 * function: zfcp_fsf_close_port
2557 * purpose: submit FSF command "close port"
2559 * returns: address of initiated FSF request
2560 * NULL - request could not be initiated
2563 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2565 volatile struct qdio_buffer_element *sbale;
2566 unsigned long lock_flags;
2569 /* setup new FSF request */
2570 retval = zfcp_fsf_req_create(erp_action->adapter,
2571 FSF_QTCB_CLOSE_PORT,
2572 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2573 erp_action->adapter->pool.fsf_req_erp,
2574 &lock_flags, &(erp_action->fsf_req));
2576 ZFCP_LOG_INFO("error: Could not create a close port request "
2577 "for port 0x%016Lx on adapter %s.\n",
2578 erp_action->port->wwpn,
2579 zfcp_get_busid_by_adapter(erp_action->adapter));
2583 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2584 erp_action->fsf_req->sbal_curr, 0);
2585 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2586 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2588 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2589 erp_action->fsf_req->data.close_port.port = erp_action->port;
2590 erp_action->fsf_req->erp_action = erp_action;
2591 erp_action->fsf_req->qtcb->header.port_handle =
2592 erp_action->port->handle;
2594 /* start QDIO request for this FSF request */
2595 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2597 ZFCP_LOG_INFO("error: Could not send a close port request for "
2598 "port 0x%016Lx on adapter %s.\n",
2599 erp_action->port->wwpn,
2600 zfcp_get_busid_by_adapter(erp_action->adapter));
2601 zfcp_fsf_req_free(erp_action->fsf_req);
2602 erp_action->fsf_req = NULL;
2606 ZFCP_LOG_TRACE("close port request initiated "
2607 "(adapter %s, port 0x%016Lx)\n",
2608 zfcp_get_busid_by_adapter(erp_action->adapter),
2609 erp_action->port->wwpn);
2611 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2617 * function: zfcp_fsf_close_port_handler
2619 * purpose: is called for finished Close Port FSF command
2624 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2626 int retval = -EINVAL;
2627 struct zfcp_port *port;
2629 port = fsf_req->data.close_port.port;
2631 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2632 /* don't change port status in our bookkeeping */
2633 goto skip_fsfstatus;
2636 /* evaluate FSF status in QTCB */
2637 switch (fsf_req->qtcb->header.fsf_status) {
2639 case FSF_PORT_HANDLE_NOT_VALID:
2640 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2641 "0x%016Lx on adapter %s invalid. This may happen "
2642 "occasionally.\n", port->handle,
2643 port->wwpn, zfcp_get_busid_by_port(port));
2644 ZFCP_LOG_DEBUG("status qualifier:\n");
2645 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2646 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2647 sizeof (union fsf_status_qual));
2648 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2650 zfcp_erp_adapter_reopen(port->adapter, 0);
2651 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2654 case FSF_ADAPTER_STATUS_AVAILABLE:
2655 /* Note: FSF has actually closed the port in this case.
2656 * The status code is just daft. Fingers crossed for a change
2662 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2663 "port handle 0x%x\n", port->wwpn,
2664 zfcp_get_busid_by_port(port), port->handle);
2665 zfcp_erp_modify_port_status(port,
2666 ZFCP_STATUS_COMMON_OPEN,
2672 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2673 "(debug info 0x%x)\n",
2674 fsf_req->qtcb->header.fsf_status);
2675 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2676 debug_exception(fsf_req->adapter->erp_dbf, 0,
2677 &fsf_req->qtcb->header.fsf_status,
2683 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2688 * function: zfcp_fsf_close_physical_port
2690 * purpose: submit FSF command "close physical port"
2692 * returns: address of initiated FSF request
2693 * NULL - request could not be initiated
2696 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2699 unsigned long lock_flags;
2700 volatile struct qdio_buffer_element *sbale;
2702 /* setup new FSF request */
2703 retval = zfcp_fsf_req_create(erp_action->adapter,
2704 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2705 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2706 erp_action->adapter->pool.fsf_req_erp,
2707 &lock_flags, &erp_action->fsf_req);
2709 ZFCP_LOG_INFO("error: Could not create close physical port "
2710 "request (adapter %s, port 0x%016Lx)\n",
2711 zfcp_get_busid_by_adapter(erp_action->adapter),
2712 erp_action->port->wwpn);
2717 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2718 erp_action->fsf_req->sbal_curr, 0);
2719 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2720 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2722 /* mark port as being closed */
2723 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2724 &erp_action->port->status);
2725 /* save a pointer to this port */
2726 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2727 /* port to be closeed */
2728 erp_action->fsf_req->qtcb->header.port_handle =
2729 erp_action->port->handle;
2730 erp_action->fsf_req->erp_action = erp_action;
2732 /* start QDIO request for this FSF request */
2733 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2735 ZFCP_LOG_INFO("error: Could not send close physical port "
2736 "request (adapter %s, port 0x%016Lx)\n",
2737 zfcp_get_busid_by_adapter(erp_action->adapter),
2738 erp_action->port->wwpn);
2739 zfcp_fsf_req_free(erp_action->fsf_req);
2740 erp_action->fsf_req = NULL;
2744 ZFCP_LOG_TRACE("close physical port request initiated "
2745 "(adapter %s, port 0x%016Lx)\n",
2746 zfcp_get_busid_by_adapter(erp_action->adapter),
2747 erp_action->port->wwpn);
2749 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2755 * function: zfcp_fsf_close_physical_port_handler
2757 * purpose: is called for finished Close Physical Port FSF command
2762 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2764 int retval = -EINVAL;
2765 struct zfcp_port *port;
2766 struct zfcp_unit *unit;
2767 struct fsf_qtcb_header *header;
2768 u16 subtable, rule, counter;
2770 port = fsf_req->data.close_physical_port.port;
2771 header = &fsf_req->qtcb->header;
2773 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2774 /* don't change port status in our bookkeeping */
2775 goto skip_fsfstatus;
2778 /* evaluate FSF status in QTCB */
2779 switch (header->fsf_status) {
2781 case FSF_PORT_HANDLE_NOT_VALID:
2782 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2783 "(adapter %s, port 0x%016Lx). "
2784 "This may happen occasionally.\n",
2786 zfcp_get_busid_by_port(port),
2788 ZFCP_LOG_DEBUG("status qualifier:\n");
2789 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2790 (char *) &header->fsf_status_qual,
2791 sizeof (union fsf_status_qual));
2792 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2794 zfcp_erp_adapter_reopen(port->adapter, 0);
2795 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2798 case FSF_ACCESS_DENIED:
2799 ZFCP_LOG_NORMAL("Access denied, cannot close "
2800 "physical port 0x%016Lx on adapter %s\n",
2801 port->wwpn, zfcp_get_busid_by_port(port));
2802 for (counter = 0; counter < 2; counter++) {
2803 subtable = header->fsf_status_qual.halfword[counter * 2];
2804 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2806 case FSF_SQ_CFDC_SUBTABLE_OS:
2807 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2808 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2809 case FSF_SQ_CFDC_SUBTABLE_LUN:
2810 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2811 zfcp_act_subtable_type[subtable], rule);
2815 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2816 zfcp_erp_port_access_denied(port);
2817 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2820 case FSF_PORT_BOXED:
2821 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2822 "%s needs to be reopened but it was attempted "
2823 "to close it physically.\n",
2825 zfcp_get_busid_by_port(port));
2826 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2827 zfcp_erp_port_reopen(port, 0);
2828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2829 ZFCP_STATUS_FSFREQ_RETRY;
2832 case FSF_ADAPTER_STATUS_AVAILABLE:
2833 switch (header->fsf_status_qual.word[0]) {
2834 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2835 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2837 /* This will now be escalated by ERP */
2838 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2840 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2841 /* ERP strategy will escalate */
2842 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2844 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2848 ("bug: Wrong status qualifier 0x%x arrived.\n",
2849 header->fsf_status_qual.word[0]);
2850 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2853 fsf_req->adapter->erp_dbf, 0,
2854 &header->fsf_status_qual.word[0], sizeof (u32));
2860 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2861 "physically closed, port handle 0x%x\n",
2863 zfcp_get_busid_by_port(port), port->handle);
2864 /* can't use generic zfcp_erp_modify_port_status because
2865 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2867 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2868 list_for_each_entry(unit, &port->unit_list_head, list)
2869 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2874 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2875 "(debug info 0x%x)\n",
2876 header->fsf_status);
2877 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2878 debug_exception(fsf_req->adapter->erp_dbf, 0,
2879 &header->fsf_status, sizeof (u32));
2884 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2889 * function: zfcp_fsf_open_unit
2895 * assumptions: This routine does not check whether the associated
2896 * remote port has already been opened. This should be
2897 * done by calling routines. Otherwise some status
2898 * may be presented by FSF
2901 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2903 volatile struct qdio_buffer_element *sbale;
2904 unsigned long lock_flags;
2907 /* setup new FSF request */
2908 retval = zfcp_fsf_req_create(erp_action->adapter,
2910 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2911 erp_action->adapter->pool.fsf_req_erp,
2912 &lock_flags, &(erp_action->fsf_req));
2914 ZFCP_LOG_INFO("error: Could not create open unit request for "
2915 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2916 erp_action->unit->fcp_lun,
2917 erp_action->unit->port->wwpn,
2918 zfcp_get_busid_by_adapter(erp_action->adapter));
2922 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2923 erp_action->fsf_req->sbal_curr, 0);
2924 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2925 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2927 erp_action->fsf_req->qtcb->header.port_handle =
2928 erp_action->port->handle;
2929 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2930 erp_action->unit->fcp_lun;
2931 erp_action->fsf_req->qtcb->bottom.support.option =
2932 FSF_OPEN_LUN_SUPPRESS_BOXING;
2933 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2934 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2935 erp_action->fsf_req->erp_action = erp_action;
2937 /* start QDIO request for this FSF request */
2938 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2940 ZFCP_LOG_INFO("error: Could not send an open unit request "
2941 "on the adapter %s, port 0x%016Lx for "
2943 zfcp_get_busid_by_adapter(erp_action->adapter),
2944 erp_action->port->wwpn,
2945 erp_action->unit->fcp_lun);
2946 zfcp_fsf_req_free(erp_action->fsf_req);
2947 erp_action->fsf_req = NULL;
2951 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2952 "port 0x%016Lx, unit 0x%016Lx)\n",
2953 zfcp_get_busid_by_adapter(erp_action->adapter),
2954 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2956 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2962 * function: zfcp_fsf_open_unit_handler
2964 * purpose: is called for finished Open LUN command
2969 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2971 int retval = -EINVAL;
2972 struct zfcp_adapter *adapter;
2973 struct zfcp_unit *unit;
2974 struct fsf_qtcb_header *header;
2975 struct fsf_qtcb_bottom_support *bottom;
2976 struct fsf_queue_designator *queue_designator;
2977 u16 subtable, rule, counter;
2978 u32 allowed, exclusive, readwrite;
2980 unit = fsf_req->data.open_unit.unit;
2982 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2983 /* don't change unit status in our bookkeeping */
2984 goto skip_fsfstatus;
2987 adapter = fsf_req->adapter;
2988 header = &fsf_req->qtcb->header;
2989 bottom = &fsf_req->qtcb->bottom.support;
2990 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2992 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
2993 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
2994 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
2996 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2997 ZFCP_STATUS_UNIT_SHARED |
2998 ZFCP_STATUS_UNIT_READONLY,
3001 /* evaluate FSF status in QTCB */
3002 switch (header->fsf_status) {
3004 case FSF_PORT_HANDLE_NOT_VALID:
3005 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3006 "for port 0x%016Lx on adapter %s invalid "
3007 "This may happen occasionally\n",
3009 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3010 ZFCP_LOG_DEBUG("status qualifier:\n");
3011 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3012 (char *) &header->fsf_status_qual,
3013 sizeof (union fsf_status_qual));
3014 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3015 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3016 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3019 case FSF_LUN_ALREADY_OPEN:
3020 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3021 "remote port 0x%016Lx on adapter %s twice.\n",
3023 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3024 debug_text_exception(adapter->erp_dbf, 0,
3026 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3029 case FSF_ACCESS_DENIED:
3030 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3031 "remote port 0x%016Lx on adapter %s\n",
3032 unit->fcp_lun, unit->port->wwpn,
3033 zfcp_get_busid_by_unit(unit));
3034 for (counter = 0; counter < 2; counter++) {
3035 subtable = header->fsf_status_qual.halfword[counter * 2];
3036 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3038 case FSF_SQ_CFDC_SUBTABLE_OS:
3039 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3040 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3041 case FSF_SQ_CFDC_SUBTABLE_LUN:
3042 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3043 zfcp_act_subtable_type[subtable], rule);
3047 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3048 zfcp_erp_unit_access_denied(unit);
3049 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3051 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3054 case FSF_PORT_BOXED:
3055 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3056 "needs to be reopened\n",
3057 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3058 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3059 zfcp_erp_port_reopen(unit->port, 0);
3060 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3061 ZFCP_STATUS_FSFREQ_RETRY;
3064 case FSF_LUN_SHARING_VIOLATION:
3065 if (header->fsf_status_qual.word[0] != 0) {
3066 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3068 "connected to the adapter %s "
3069 "is already in use in LPAR%d, CSS%d\n",
3072 zfcp_get_busid_by_unit(unit),
3073 queue_designator->hla,
3074 queue_designator->cssid);
3076 subtable = header->fsf_status_qual.halfword[4];
3077 rule = header->fsf_status_qual.halfword[5];
3079 case FSF_SQ_CFDC_SUBTABLE_OS:
3080 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3081 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3082 case FSF_SQ_CFDC_SUBTABLE_LUN:
3083 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3084 "remote port with WWPN 0x%Lx "
3085 "connected to the adapter %s "
3086 "is denied (%s rule %d)\n",
3089 zfcp_get_busid_by_unit(unit),
3090 zfcp_act_subtable_type[subtable],
3095 ZFCP_LOG_DEBUG("status qualifier:\n");
3096 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3097 (char *) &header->fsf_status_qual,
3098 sizeof (union fsf_status_qual));
3099 debug_text_event(adapter->erp_dbf, 2,
3101 zfcp_erp_unit_access_denied(unit);
3102 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3103 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3104 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3107 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3108 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3109 "There is no handle (temporary port identifier) "
3110 "available for unit 0x%016Lx on port 0x%016Lx "
3114 zfcp_get_busid_by_unit(unit));
3115 debug_text_event(adapter->erp_dbf, 1,
3117 zfcp_erp_unit_failed(unit);
3118 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3121 case FSF_ADAPTER_STATUS_AVAILABLE:
3122 switch (header->fsf_status_qual.word[0]) {
3123 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3124 /* Re-establish link to port */
3125 debug_text_event(adapter->erp_dbf, 1,
3127 zfcp_test_link(unit->port);
3128 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3130 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3131 /* ERP strategy will escalate */
3132 debug_text_event(adapter->erp_dbf, 1,
3134 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3138 ("bug: Wrong status qualifier 0x%x arrived.\n",
3139 header->fsf_status_qual.word[0]);
3140 debug_text_event(adapter->erp_dbf, 0,
3142 debug_exception(adapter->erp_dbf, 0,
3143 &header->fsf_status_qual.word[0],
3148 case FSF_INVALID_COMMAND_OPTION:
3150 "Invalid option 0x%x has been specified "
3151 "in QTCB bottom sent to the adapter %s\n",
3153 zfcp_get_busid_by_adapter(adapter));
3154 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3159 /* save LUN handle assigned by FSF */
3160 unit->handle = header->lun_handle;
3161 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3162 "adapter %s opened, port handle 0x%x\n",
3165 zfcp_get_busid_by_unit(unit),
3167 /* mark unit as open */
3168 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3170 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3172 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3176 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3178 ZFCP_LOG_NORMAL("read-only access for unit "
3179 "(adapter %s, wwpn=0x%016Lx, "
3180 "fcp_lun=0x%016Lx)\n",
3181 zfcp_get_busid_by_unit(unit),
3186 if (exclusive && !readwrite) {
3187 ZFCP_LOG_NORMAL("exclusive access of read-only "
3188 "unit not supported\n");
3189 zfcp_erp_unit_failed(unit);
3190 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3191 zfcp_erp_unit_shutdown(unit, 0);
3192 } else if (!exclusive && readwrite) {
3193 ZFCP_LOG_NORMAL("shared access of read-write "
3194 "unit not supported\n");
3195 zfcp_erp_unit_failed(unit);
3196 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3197 zfcp_erp_unit_shutdown(unit, 0);
3205 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3206 "(debug info 0x%x)\n",
3207 header->fsf_status);
3208 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3209 debug_exception(adapter->erp_dbf, 0,
3210 &header->fsf_status, sizeof (u32));
3215 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3220 * function: zfcp_fsf_close_unit
3224 * returns: address of fsf_req - request successfully initiated
3227 * assumptions: This routine does not check whether the associated
3228 * remote port/lun has already been opened. This should be
3229 * done by calling routines. Otherwise some status
3230 * may be presented by FSF
3233 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3235 volatile struct qdio_buffer_element *sbale;
3236 unsigned long lock_flags;
3239 /* setup new FSF request */
3240 retval = zfcp_fsf_req_create(erp_action->adapter,
3242 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3243 erp_action->adapter->pool.fsf_req_erp,
3244 &lock_flags, &(erp_action->fsf_req));
3246 ZFCP_LOG_INFO("error: Could not create close unit request for "
3247 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3248 erp_action->unit->fcp_lun,
3249 erp_action->port->wwpn,
3250 zfcp_get_busid_by_adapter(erp_action->adapter));
3254 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3255 erp_action->fsf_req->sbal_curr, 0);
3256 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3257 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3259 erp_action->fsf_req->qtcb->header.port_handle =
3260 erp_action->port->handle;
3261 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3262 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3263 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3264 erp_action->fsf_req->erp_action = erp_action;
3266 /* start QDIO request for this FSF request */
3267 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3269 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3270 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3271 erp_action->unit->fcp_lun,
3272 erp_action->port->wwpn,
3273 zfcp_get_busid_by_adapter(erp_action->adapter));
3274 zfcp_fsf_req_free(erp_action->fsf_req);
3275 erp_action->fsf_req = NULL;
3279 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3280 "port 0x%016Lx, unit 0x%016Lx)\n",
3281 zfcp_get_busid_by_adapter(erp_action->adapter),
3282 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3284 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3290 * function: zfcp_fsf_close_unit_handler
3292 * purpose: is called for finished Close LUN FSF command
3297 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3299 int retval = -EINVAL;
3300 struct zfcp_unit *unit;
3302 unit = fsf_req->data.close_unit.unit; /* restore unit */
3304 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3305 /* don't change unit status in our bookkeeping */
3306 goto skip_fsfstatus;
3309 /* evaluate FSF status in QTCB */
3310 switch (fsf_req->qtcb->header.fsf_status) {
3312 case FSF_PORT_HANDLE_NOT_VALID:
3313 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3314 "0x%016Lx on adapter %s invalid. This may "
3315 "happen in rare circumstances\n",
3318 zfcp_get_busid_by_unit(unit));
3319 ZFCP_LOG_DEBUG("status qualifier:\n");
3320 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3321 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3322 sizeof (union fsf_status_qual));
3323 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3325 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3326 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3327 &fsf_req->qtcb->header.fsf_status_qual,
3328 sizeof (union fsf_status_qual));
3329 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3332 case FSF_LUN_HANDLE_NOT_VALID:
3333 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3334 "0x%016Lx on port 0x%016Lx on adapter %s is "
3335 "invalid. This may happen occasionally.\n",
3339 zfcp_get_busid_by_unit(unit));
3340 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3341 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3342 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3343 sizeof (union fsf_status_qual));
3344 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3346 zfcp_erp_port_reopen(unit->port, 0);
3347 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3348 &fsf_req->qtcb->header.fsf_status_qual,
3349 sizeof (union fsf_status_qual));
3350 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3353 case FSF_PORT_BOXED:
3354 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3355 "needs to be reopened\n",
3357 zfcp_get_busid_by_unit(unit));
3358 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3359 zfcp_erp_port_reopen(unit->port, 0);
3360 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3361 ZFCP_STATUS_FSFREQ_RETRY;
3364 case FSF_ADAPTER_STATUS_AVAILABLE:
3365 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3366 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3367 /* re-establish link to port */
3368 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3370 zfcp_test_link(unit->port);
3371 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3373 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3374 /* ERP strategy will escalate */
3375 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3377 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3381 ("bug: Wrong status qualifier 0x%x arrived.\n",
3382 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3383 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3386 fsf_req->adapter->erp_dbf, 0,
3387 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3394 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3395 "closed, port handle 0x%x\n",
3398 zfcp_get_busid_by_unit(unit),
3400 /* mark unit as closed */
3401 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3406 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3407 "(debug info 0x%x)\n",
3408 fsf_req->qtcb->header.fsf_status);
3409 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3410 debug_exception(fsf_req->adapter->erp_dbf, 0,
3411 &fsf_req->qtcb->header.fsf_status,
3417 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3422 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3423 * @adapter: adapter where scsi command is issued
3424 * @unit: unit where command is sent to
3425 * @scsi_cmnd: scsi command to be sent
3426 * @timer: timer to be started when request is initiated
3427 * @req_flags: flags for fsf_request
3430 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3431 struct zfcp_unit *unit,
3432 struct scsi_cmnd * scsi_cmnd,
3433 struct timer_list *timer, int req_flags)
3435 struct zfcp_fsf_req *fsf_req = NULL;
3436 struct fcp_cmnd_iu *fcp_cmnd_iu;
3437 unsigned int sbtype;
3438 unsigned long lock_flags;
3443 /* setup new FSF request */
3444 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3445 adapter->pool.fsf_req_scsi,
3446 &lock_flags, &fsf_req);
3447 if (unlikely(retval < 0)) {
3448 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3449 "for unit 0x%016Lx on port 0x%016Lx on "
3453 zfcp_get_busid_by_adapter(adapter));
3454 goto failed_req_create;
3458 * associate FSF request with SCSI request
3459 * (need this for look up on abort)
3461 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3462 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3465 * associate SCSI command with FSF request
3466 * (need this for look up on normal command completion)
3468 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3469 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3470 fsf_req->data.send_fcp_command_task.unit = unit;
3471 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3473 /* set handles of unit and its parent port in QTCB */
3474 fsf_req->qtcb->header.lun_handle = unit->handle;
3475 fsf_req->qtcb->header.port_handle = unit->port->handle;
3477 /* FSF does not define the structure of the FCP_CMND IU */
3478 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3479 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3482 * set depending on data direction:
3483 * data direction bits in SBALE (SB Type)
3484 * data direction bits in QTCB
3485 * data direction bits in FCP_CMND IU
3487 switch (scsi_cmnd->sc_data_direction) {
3489 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3492 * what is the correct type for commands
3493 * without 'real' data buffers?
3495 sbtype = SBAL_FLAGS0_TYPE_READ;
3497 case DMA_FROM_DEVICE:
3498 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3499 sbtype = SBAL_FLAGS0_TYPE_READ;
3500 fcp_cmnd_iu->rddata = 1;
3503 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3504 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3505 fcp_cmnd_iu->wddata = 1;
3507 case DMA_BIDIRECTIONAL:
3510 * dummy, catch this condition earlier
3511 * in zfcp_scsi_queuecommand
3513 goto failed_scsi_cmnd;
3516 /* set FC service class in QTCB (3 per default) */
3517 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3519 /* set FCP_LUN in FCP_CMND IU in QTCB */
3520 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3522 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3524 /* set task attributes in FCP_CMND IU in QTCB */
3525 if (likely((scsi_cmnd->device->simple_tags) ||
3526 (atomic_test_mask(mask, &unit->status))))
3527 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3529 fcp_cmnd_iu->task_attribute = UNTAGGED;
3531 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3532 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3533 fcp_cmnd_iu->add_fcp_cdb_length
3534 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3535 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3536 "additional FCP_CDB length is 0x%x "
3537 "(shifted right 2 bits)\n",
3539 fcp_cmnd_iu->add_fcp_cdb_length);
3542 * copy SCSI CDB (including additional length, if any) to
3543 * FCP_CDB in FCP_CMND IU in QTCB
3545 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3547 /* FCP CMND IU length in QTCB */
3548 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3549 sizeof (struct fcp_cmnd_iu) +
3550 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3552 /* generate SBALEs from data buffer */
3553 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3554 if (unlikely(real_bytes < 0)) {
3555 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3557 "Data did not fit into available buffer(s), "
3558 "waiting for more...\n");
3561 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3562 "required. Shutting down unit "
3563 "(adapter %s, port 0x%016Lx, "
3565 zfcp_get_busid_by_unit(unit),
3568 zfcp_erp_unit_shutdown(unit, 0);
3574 /* set length of FCP data length in FCP_CMND IU in QTCB */
3575 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3577 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3578 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3579 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3582 * start QDIO request for this FSF request
3583 * covered by an SBALE)
3585 retval = zfcp_fsf_req_send(fsf_req, timer);
3586 if (unlikely(retval < 0)) {
3587 ZFCP_LOG_INFO("error: Could not send FCP command request "
3588 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3589 zfcp_get_busid_by_adapter(adapter),
3595 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3596 "port 0x%016Lx, unit 0x%016Lx)\n",
3597 zfcp_get_busid_by_adapter(adapter),
3605 zfcp_fsf_req_free(fsf_req);
3607 scsi_cmnd->host_scribble = NULL;
3610 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3615 * function: zfcp_fsf_send_fcp_command_task_management
3621 * FIXME(design): should be watched by a timeout!!!
3622 * FIXME(design) shouldn't this be modified to return an int
3623 * also...don't know how though
3626 struct zfcp_fsf_req *
3627 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3628 struct zfcp_unit *unit,
3629 u8 tm_flags, int req_flags)
3631 struct zfcp_fsf_req *fsf_req = NULL;
3633 struct fcp_cmnd_iu *fcp_cmnd_iu;
3634 unsigned long lock_flags;
3635 volatile struct qdio_buffer_element *sbale;
3637 /* setup new FSF request */
3638 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3639 adapter->pool.fsf_req_scsi,
3640 &lock_flags, &fsf_req);
3642 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3643 "management) request for adapter %s, port "
3644 " 0x%016Lx, unit 0x%016Lx.\n",
3645 zfcp_get_busid_by_adapter(adapter),
3646 unit->port->wwpn, unit->fcp_lun);
3651 * Used to decide on proper handler in the return path,
3652 * could be either zfcp_fsf_send_fcp_command_task_handler or
3653 * zfcp_fsf_send_fcp_command_task_management_handler */
3655 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3658 * hold a pointer to the unit being target of this
3659 * task management request
3661 fsf_req->data.send_fcp_command_task_management.unit = unit;
3663 /* set FSF related fields in QTCB */
3664 fsf_req->qtcb->header.lun_handle = unit->handle;
3665 fsf_req->qtcb->header.port_handle = unit->port->handle;
3666 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3667 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3668 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3669 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3671 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3672 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3673 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3675 /* set FCP related fields in FCP_CMND IU in QTCB */
3676 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3677 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3678 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3679 fcp_cmnd_iu->task_management_flags = tm_flags;
3681 /* start QDIO request for this FSF request */
3682 zfcp_fsf_start_scsi_er_timer(adapter);
3683 retval = zfcp_fsf_req_send(fsf_req, NULL);
3685 del_timer(&adapter->scsi_er_timer);
3686 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3687 "management) on adapter %s, port 0x%016Lx for "
3688 "unit LUN 0x%016Lx\n",
3689 zfcp_get_busid_by_adapter(adapter),
3692 zfcp_fsf_req_free(fsf_req);
3697 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3698 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3700 zfcp_get_busid_by_adapter(adapter),
3705 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3710 * function: zfcp_fsf_send_fcp_command_handler
3712 * purpose: is called for finished Send FCP Command
3717 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3719 int retval = -EINVAL;
3720 struct zfcp_unit *unit;
3721 struct fsf_qtcb_header *header;
3722 u16 subtable, rule, counter;
3724 header = &fsf_req->qtcb->header;
3726 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3727 unit = fsf_req->data.send_fcp_command_task_management.unit;
3729 unit = fsf_req->data.send_fcp_command_task.unit;
3731 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3732 /* go directly to calls of special handlers */
3733 goto skip_fsfstatus;
3736 /* evaluate FSF status in QTCB */
3737 switch (header->fsf_status) {
3739 case FSF_PORT_HANDLE_NOT_VALID:
3740 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3741 "0x%016Lx on adapter %s invalid\n",
3743 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3744 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3745 (char *) &header->fsf_status_qual,
3746 sizeof (union fsf_status_qual));
3747 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3749 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3750 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3753 case FSF_LUN_HANDLE_NOT_VALID:
3754 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3755 "0x%016Lx on port 0x%016Lx on adapter %s is "
3756 "invalid. This may happen occasionally.\n",
3760 zfcp_get_busid_by_unit(unit));
3761 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3762 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3763 (char *) &header->fsf_status_qual,
3764 sizeof (union fsf_status_qual));
3765 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3767 zfcp_erp_port_reopen(unit->port, 0);
3768 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3771 case FSF_HANDLE_MISMATCH:
3772 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3773 "unexpectedly. (adapter %s, port 0x%016Lx, "
3776 zfcp_get_busid_by_unit(unit),
3779 ZFCP_LOG_NORMAL("status qualifier:\n");
3780 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3781 (char *) &header->fsf_status_qual,
3782 sizeof (union fsf_status_qual));
3783 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3785 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3786 zfcp_cmd_dbf_event_fsf("handmism",
3788 &header->fsf_status_qual,
3789 sizeof (union fsf_status_qual));
3790 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3793 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3794 if (fsf_req->adapter->fc_service_class <= 3) {
3795 ZFCP_LOG_NORMAL("error: The adapter %s does "
3796 "not support fibrechannel class %d.\n",
3797 zfcp_get_busid_by_unit(unit),
3798 fsf_req->adapter->fc_service_class);
3800 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3801 "adapter %s is invalid. "
3802 "(debug info %d)\n",
3803 zfcp_get_busid_by_unit(unit),
3804 fsf_req->adapter->fc_service_class);
3806 /* stop operation for this adapter */
3807 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3808 "fsf_s_class_nsup");
3809 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3810 zfcp_cmd_dbf_event_fsf("unsclass",
3812 &header->fsf_status_qual,
3813 sizeof (union fsf_status_qual));
3814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3817 case FSF_FCPLUN_NOT_VALID:
3818 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3819 "adapter %s does not have correct unit "
3823 zfcp_get_busid_by_unit(unit),
3825 ZFCP_LOG_DEBUG("status qualifier:\n");
3826 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3827 (char *) &header->fsf_status_qual,
3828 sizeof (union fsf_status_qual));
3829 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3830 "fsf_s_fcp_lun_nv");
3831 zfcp_erp_port_reopen(unit->port, 0);
3832 zfcp_cmd_dbf_event_fsf("fluninv",
3834 &header->fsf_status_qual,
3835 sizeof (union fsf_status_qual));
3836 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3839 case FSF_ACCESS_DENIED:
3840 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3841 "unit 0x%016Lx on port 0x%016Lx on "
3842 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3843 zfcp_get_busid_by_unit(unit));
3844 for (counter = 0; counter < 2; counter++) {
3845 subtable = header->fsf_status_qual.halfword[counter * 2];
3846 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3848 case FSF_SQ_CFDC_SUBTABLE_OS:
3849 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3850 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3851 case FSF_SQ_CFDC_SUBTABLE_LUN:
3852 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3853 zfcp_act_subtable_type[subtable], rule);
3857 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3858 zfcp_erp_unit_access_denied(unit);
3859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3862 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3863 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3864 "0x%016Lx on port 0x%016Lx on adapter %s "
3865 "(debug info %d)\n",
3868 zfcp_get_busid_by_unit(unit),
3869 fsf_req->qtcb->bottom.io.data_direction);
3870 /* stop operation for this adapter */
3871 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3872 "fsf_s_dir_ind_nv");
3873 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3874 zfcp_cmd_dbf_event_fsf("dirinv",
3876 &header->fsf_status_qual,
3877 sizeof (union fsf_status_qual));
3878 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3881 case FSF_CMND_LENGTH_NOT_VALID:
3883 ("bug: An invalid control-data-block length field "
3884 "was found in a command for unit 0x%016Lx on port "
3885 "0x%016Lx on adapter %s " "(debug info %d)\n",
3886 unit->fcp_lun, unit->port->wwpn,
3887 zfcp_get_busid_by_unit(unit),
3888 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3889 /* stop operation for this adapter */
3890 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3891 "fsf_s_cmd_len_nv");
3892 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3893 zfcp_cmd_dbf_event_fsf("cleninv",
3895 &header->fsf_status_qual,
3896 sizeof (union fsf_status_qual));
3897 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3900 case FSF_PORT_BOXED:
3901 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3902 "needs to be reopened\n",
3903 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3904 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3905 zfcp_erp_port_reopen(unit->port, 0);
3906 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3907 &header->fsf_status_qual,
3908 sizeof (union fsf_status_qual));
3909 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3910 ZFCP_STATUS_FSFREQ_RETRY;
3914 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3915 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3916 zfcp_get_busid_by_unit(unit),
3917 unit->port->wwpn, unit->fcp_lun);
3918 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3919 zfcp_erp_unit_reopen(unit, 0);
3920 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3921 &header->fsf_status_qual,
3922 sizeof(union fsf_status_qual));
3923 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3924 | ZFCP_STATUS_FSFREQ_RETRY;
3927 case FSF_ADAPTER_STATUS_AVAILABLE:
3928 switch (header->fsf_status_qual.word[0]) {
3929 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3930 /* re-establish link to port */
3931 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3933 zfcp_test_link(unit->port);
3935 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3936 /* FIXME(hw) need proper specs for proper action */
3937 /* let scsi stack deal with retries and escalation */
3938 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3943 ("Unknown status qualifier 0x%x arrived.\n",
3944 header->fsf_status_qual.word[0]);
3945 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3947 debug_exception(fsf_req->adapter->erp_dbf, 0,
3948 &header->fsf_status_qual.word[0],
3952 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3958 case FSF_FCP_RSP_AVAILABLE:
3962 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3963 debug_exception(fsf_req->adapter->erp_dbf, 0,
3964 &header->fsf_status, sizeof(u32));
3969 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3971 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3973 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3979 * function: zfcp_fsf_send_fcp_command_task_handler
3981 * purpose: evaluates FCP_RSP IU
3986 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3989 struct scsi_cmnd *scpnt;
3990 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3991 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3992 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3993 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3995 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3996 unsigned long flags;
3997 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3999 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4000 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
4001 if (unlikely(!scpnt)) {
4003 ("Command with fsf_req %p is not associated to "
4004 "a scsi command anymore. Aborted?\n", fsf_req);
4007 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4008 /* FIXME: (design) mid-layer should handle DID_ABORT like
4009 * DID_SOFT_ERROR by retrying the request for devices
4010 * that allow retries.
4012 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4013 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4014 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4015 goto skip_fsfstatus;
4018 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4019 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4020 set_host_byte(&scpnt->result, DID_ERROR);
4021 goto skip_fsfstatus;
4024 /* set message byte of result in SCSI command */
4025 scpnt->result |= COMMAND_COMPLETE << 8;
4028 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4029 * of result in SCSI command
4031 scpnt->result |= fcp_rsp_iu->scsi_status;
4032 if (unlikely(fcp_rsp_iu->scsi_status)) {
4034 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4035 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4036 scpnt->cmnd, scpnt->cmd_len);
4037 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4038 fcp_rsp_iu->scsi_status);
4039 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4040 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4041 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4042 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4043 fcp_rsp_iu->fcp_sns_len);
4046 /* check FCP_RSP_INFO */
4047 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4048 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4049 switch (fcp_rsp_info[3]) {
4052 ZFCP_LOG_TRACE("no failure or Task Management "
4053 "Function complete\n");
4054 set_host_byte(&scpnt->result, DID_OK);
4056 case RSP_CODE_LENGTH_MISMATCH:
4058 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4059 "that the fibrechannel protocol data "
4060 "length differs from the burst length. "
4061 "The problem occured on unit 0x%016Lx "
4062 "on port 0x%016Lx on adapter %s",
4065 zfcp_get_busid_by_unit(unit));
4066 /* dump SCSI CDB as prepared by zfcp */
4067 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4068 (char *) &fsf_req->qtcb->
4069 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4070 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4071 set_host_byte(&scpnt->result, DID_ERROR);
4072 goto skip_fsfstatus;
4073 case RSP_CODE_FIELD_INVALID:
4074 /* driver or hardware bug */
4075 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4076 "that the fibrechannel protocol data "
4077 "fields were incorrectly set up. "
4078 "The problem occured on the unit "
4079 "0x%016Lx on port 0x%016Lx on "
4083 zfcp_get_busid_by_unit(unit));
4084 /* dump SCSI CDB as prepared by zfcp */
4085 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4086 (char *) &fsf_req->qtcb->
4087 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4088 set_host_byte(&scpnt->result, DID_ERROR);
4089 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4090 goto skip_fsfstatus;
4091 case RSP_CODE_RO_MISMATCH:
4093 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4094 "that conflicting values for the "
4095 "fibrechannel payload offset from the "
4096 "header were found. "
4097 "The problem occured on unit 0x%016Lx "
4098 "on port 0x%016Lx on adapter %s.\n",
4101 zfcp_get_busid_by_unit(unit));
4102 /* dump SCSI CDB as prepared by zfcp */
4103 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4104 (char *) &fsf_req->qtcb->
4105 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4106 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4107 set_host_byte(&scpnt->result, DID_ERROR);
4108 goto skip_fsfstatus;
4110 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4111 "code was detected for a command. "
4112 "The problem occured on the unit "
4113 "0x%016Lx on port 0x%016Lx on "
4114 "adapter %s (debug info 0x%x)\n",
4117 zfcp_get_busid_by_unit(unit),
4119 /* dump SCSI CDB as prepared by zfcp */
4120 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4121 (char *) &fsf_req->qtcb->
4122 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4123 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4124 set_host_byte(&scpnt->result, DID_ERROR);
4125 goto skip_fsfstatus;
4129 /* check for sense data */
4130 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4131 sns_len = FSF_FCP_RSP_SIZE -
4132 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4133 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4135 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4136 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4137 SCSI_SENSE_BUFFERSIZE);
4138 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4139 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4141 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4142 (void *) &scpnt->cmnd, scpnt->cmd_len);
4144 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4145 fcp_rsp_iu->fcp_sns_len);
4146 memcpy(&scpnt->sense_buffer,
4147 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4148 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4149 (void *) &scpnt->sense_buffer, sns_len);
4152 /* check for overrun */
4153 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4154 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4155 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4156 "The response data length is "
4157 "%d, the original length was %d.\n",
4160 zfcp_get_busid_by_unit(unit),
4161 fcp_rsp_iu->fcp_resid,
4162 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4165 /* check for underrun */
4166 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4167 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4168 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4169 "The response data length is "
4170 "%d, the original length was %d.\n",
4173 zfcp_get_busid_by_unit(unit),
4174 fcp_rsp_iu->fcp_resid,
4175 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4177 scpnt->resid = fcp_rsp_iu->fcp_resid;
4178 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4179 set_host_byte(&scpnt->result, DID_ERROR);
4183 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4185 zfcp_cmd_dbf_event_scsi("response", scpnt);
4187 /* cleanup pointer (need this especially for abort) */
4188 scpnt->host_scribble = NULL;
4192 * according to the outcome of a discussion on linux-scsi we
4193 * don't need to grab the io_request_lock here since we use
4196 /* always call back */
4198 (scpnt->scsi_done) (scpnt);
4201 * We must hold this lock until scsi_done has been called.
4202 * Otherwise we may call scsi_done after abort regarding this
4203 * command has completed.
4204 * Note: scsi_done must not block!
4207 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4212 * function: zfcp_fsf_send_fcp_command_task_management_handler
4214 * purpose: evaluates FCP_RSP IU
4219 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4222 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4223 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4224 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4225 struct zfcp_unit *unit =
4226 fsf_req->data.send_fcp_command_task_management.unit;
4228 del_timer(&fsf_req->adapter->scsi_er_timer);
4229 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4230 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4231 goto skip_fsfstatus;
4234 /* check FCP_RSP_INFO */
4235 switch (fcp_rsp_info[3]) {
4238 ZFCP_LOG_DEBUG("no failure or Task Management "
4239 "Function complete\n");
4241 case RSP_CODE_TASKMAN_UNSUPP:
4242 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4243 "is not supported on the target device "
4244 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4247 zfcp_get_busid_by_unit(unit));
4248 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4250 case RSP_CODE_TASKMAN_FAILED:
4251 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4252 "failed to complete successfully. "
4253 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4256 zfcp_get_busid_by_unit(unit));
4257 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4260 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4261 "code was detected for a command. "
4262 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4263 "(debug info 0x%x)\n",
4266 zfcp_get_busid_by_unit(unit),
4268 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4277 * function: zfcp_fsf_control_file
4279 * purpose: Initiator of the control file upload/download FSF requests
4281 * returns: 0 - FSF request is successfuly created and queued
4282 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4283 * -EINVAL - Invalid direction specified
4284 * -ENOMEM - Insufficient memory
4285 * -EPERM - Cannot create FSF request or place it in QDIO queue
4288 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4289 struct zfcp_fsf_req **fsf_req_ptr,
4292 struct zfcp_sg_list *sg_list)
4294 struct zfcp_fsf_req *fsf_req;
4295 struct fsf_qtcb_bottom_support *bottom;
4296 volatile struct qdio_buffer_element *sbale;
4297 struct timer_list *timer;
4298 unsigned long lock_flags;
4303 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4304 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4305 zfcp_get_busid_by_adapter(adapter));
4306 retval = -EOPNOTSUPP;
4310 switch (fsf_command) {
4312 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4313 direction = SBAL_FLAGS0_TYPE_WRITE;
4314 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4315 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4316 req_flags = ZFCP_WAIT_FOR_SBAL;
4319 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4320 direction = SBAL_FLAGS0_TYPE_READ;
4324 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4329 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4335 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4336 NULL, &lock_flags, &fsf_req);
4338 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4340 zfcp_get_busid_by_adapter(adapter));
4342 goto unlock_queue_lock;
4345 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4346 sbale[0].flags |= direction;
4348 bottom = &fsf_req->qtcb->bottom.support;
4349 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4350 bottom->option = option;
4352 if (sg_list->count > 0) {
4355 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4356 sg_list->sg, sg_list->count,
4357 ZFCP_MAX_SBALS_PER_REQ);
4358 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4360 "error: Could not create sufficient number of "
4361 "SBALS for an FSF request to the adapter %s\n",
4362 zfcp_get_busid_by_adapter(adapter));
4367 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4370 timer->function = zfcp_fsf_request_timeout_handler;
4371 timer->data = (unsigned long) adapter;
4372 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4374 retval = zfcp_fsf_req_send(fsf_req, timer);
4376 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4378 zfcp_get_busid_by_adapter(adapter));
4382 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4384 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4386 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4387 "download" : "upload",
4388 zfcp_get_busid_by_adapter(adapter));
4390 wait_event(fsf_req->completion_wq,
4391 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4393 *fsf_req_ptr = fsf_req;
4394 del_timer_sync(timer);
4398 zfcp_fsf_req_free(fsf_req);
4400 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4409 * function: zfcp_fsf_control_file_handler
4411 * purpose: Handler of the control file upload/download FSF requests
4413 * returns: 0 - FSF request successfuly processed
4414 * -EAGAIN - Operation has to be repeated because of a temporary problem
4415 * -EACCES - There is no permission to execute an operation
4416 * -EPERM - The control file is not in a right format
4417 * -EIO - There is a problem with the FCP adapter
4418 * -EINVAL - Invalid operation
4419 * -EFAULT - User space memory I/O operation fault
4422 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4424 struct zfcp_adapter *adapter = fsf_req->adapter;
4425 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4426 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4429 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4431 goto skip_fsfstatus;
4434 switch (header->fsf_status) {
4438 "The FSF request has been successfully completed "
4439 "on the adapter %s\n",
4440 zfcp_get_busid_by_adapter(adapter));
4443 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4444 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4445 switch (header->fsf_status_qual.word[0]) {
4447 case FSF_SQ_CFDC_HARDENED_ON_SE:
4449 "CFDC on the adapter %s has being "
4450 "hardened on primary and secondary SE\n",
4451 zfcp_get_busid_by_adapter(adapter));
4454 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4456 "CFDC of the adapter %s could not "
4457 "be saved on the SE\n",
4458 zfcp_get_busid_by_adapter(adapter));
4461 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4463 "CFDC of the adapter %s could not "
4464 "be copied to the secondary SE\n",
4465 zfcp_get_busid_by_adapter(adapter));
4470 "CFDC could not be hardened "
4471 "on the adapter %s\n",
4472 zfcp_get_busid_by_adapter(adapter));
4475 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4479 case FSF_AUTHORIZATION_FAILURE:
4481 "Adapter %s does not accept privileged commands\n",
4482 zfcp_get_busid_by_adapter(adapter));
4483 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4487 case FSF_CFDC_ERROR_DETECTED:
4489 "Error at position %d in the CFDC, "
4490 "CFDC is discarded by the adapter %s\n",
4491 header->fsf_status_qual.word[0],
4492 zfcp_get_busid_by_adapter(adapter));
4493 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4497 case FSF_CONTROL_FILE_UPDATE_ERROR:
4499 "Adapter %s cannot harden the control file, "
4500 "file is discarded\n",
4501 zfcp_get_busid_by_adapter(adapter));
4502 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4506 case FSF_CONTROL_FILE_TOO_LARGE:
4508 "Control file is too large, file is discarded "
4509 "by the adapter %s\n",
4510 zfcp_get_busid_by_adapter(adapter));
4511 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4515 case FSF_ACCESS_CONFLICT_DETECTED:
4516 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4518 "CFDC has been discarded by the adapter %s, "
4519 "because activation would impact "
4520 "%d active connection(s)\n",
4521 zfcp_get_busid_by_adapter(adapter),
4522 header->fsf_status_qual.word[0]);
4523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4527 case FSF_CONFLICTS_OVERRULED:
4528 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4530 "CFDC has been activated on the adapter %s, "
4531 "but activation has impacted "
4532 "%d active connection(s)\n",
4533 zfcp_get_busid_by_adapter(adapter),
4534 header->fsf_status_qual.word[0]);
4535 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4539 case FSF_UNKNOWN_OP_SUBTYPE:
4540 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4541 "op_subtype=0x%x)\n",
4542 zfcp_get_busid_by_adapter(adapter),
4543 bottom->operation_subtype);
4544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4548 case FSF_INVALID_COMMAND_OPTION:
4550 "Invalid option 0x%x has been specified "
4551 "in QTCB bottom sent to the adapter %s\n",
4553 zfcp_get_busid_by_adapter(adapter));
4554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4560 "bug: An unknown/unexpected FSF status 0x%08x "
4561 "was presented on the adapter %s\n",
4563 zfcp_get_busid_by_adapter(adapter));
4564 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4565 debug_exception(fsf_req->adapter->erp_dbf, 0,
4566 &header->fsf_status_qual.word[0], sizeof(u32));
4567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4578 * function: zfcp_fsf_req_wait_and_cleanup
4582 * FIXME(design): signal seems to be <0 !!!
4583 * returns: 0 - request completed (*status is valid), cleanup succ.
4584 * <0 - request completed (*status is valid), cleanup failed
4585 * >0 - signal which interrupted waiting (*status invalid),
4586 * request not completed, no cleanup
4588 * *status is a copy of status of completed fsf_req
4591 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4592 int interruptible, u32 * status)
4597 if (interruptible) {
4598 __wait_event_interruptible(fsf_req->completion_wq,
4600 ZFCP_STATUS_FSFREQ_COMPLETED,
4603 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4604 "completion of the request at %p\n",
4610 __wait_event(fsf_req->completion_wq,
4611 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4614 *status = fsf_req->status;
4616 /* cleanup request */
4617 zfcp_fsf_req_cleanup(fsf_req);
4623 zfcp_fsf_req_sbal_check(unsigned long *flags,
4624 struct zfcp_qdio_queue *queue, int needed)
4626 write_lock_irqsave(&queue->queue_lock, *flags);
4627 if (likely(atomic_read(&queue->free_count) >= needed))
4629 write_unlock_irqrestore(&queue->queue_lock, *flags);
4634 * set qtcb pointer in fsf_req and initialize QTCB
4637 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4639 if (likely(fsf_req->qtcb != NULL)) {
4640 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4641 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4642 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4643 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4644 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4645 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4650 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4651 * @adapter: adapter for which request queue is examined
4652 * @req_flags: flags indicating whether to wait for needed SBAL or not
4653 * @lock_flags: lock_flags if queue_lock is taken
4654 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4655 * Locks: lock adapter->request_queue->queue_lock on success
4658 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4659 unsigned long *lock_flags)
4662 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4664 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4665 ret = wait_event_interruptible_timeout(adapter->request_wq,
4666 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4672 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4679 * function: zfcp_fsf_req_create
4681 * purpose: create an FSF request at the specified adapter and
4682 * setup common fields
4684 * returns: -ENOMEM if there was insufficient memory for a request
4685 * -EIO if no qdio buffers could be allocate to the request
4686 * -EINVAL/-EPERM on bug conditions in req_dequeue
4689 * note: The created request is returned by reference.
4691 * locks: lock of concerned request queue must not be held,
4692 * but is held on completion (write, irqsave)
4695 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4696 mempool_t *pool, unsigned long *lock_flags,
4697 struct zfcp_fsf_req **fsf_req_p)
4699 volatile struct qdio_buffer_element *sbale;
4700 struct zfcp_fsf_req *fsf_req = NULL;
4702 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4704 /* allocate new FSF request */
4705 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4706 if (unlikely(NULL == fsf_req)) {
4707 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4708 "the outbound (send) queue.\n");
4710 goto failed_fsf_req;
4713 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4715 /* initialize waitqueue which may be used to wait on
4716 this request completion */
4717 init_waitqueue_head(&fsf_req->completion_wq);
4719 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4725 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4726 * if it is not set (see also *_open_qdio and *_close_qdio).
4729 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4730 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4735 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4736 fsf_req->fsf_command = fsf_cmd;
4737 fsf_req->sbal_number = 1;
4738 fsf_req->sbal_first = req_queue->free_index;
4739 fsf_req->sbal_curr = req_queue->free_index;
4740 fsf_req->sbale_curr = 1;
4742 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4743 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4746 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4748 /* setup common SBALE fields */
4749 sbale[0].addr = fsf_req;
4750 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4751 if (likely(fsf_req->qtcb != NULL)) {
4752 sbale[1].addr = (void *) fsf_req->qtcb;
4753 sbale[1].length = sizeof(struct fsf_qtcb);
4756 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4757 fsf_req->sbal_number, fsf_req->sbal_first);
4762 /* dequeue new FSF request previously enqueued */
4763 zfcp_fsf_req_free(fsf_req);
4767 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4769 *fsf_req_p = fsf_req;
4774 * function: zfcp_fsf_req_send
4776 * purpose: start transfer of FSF request via QDIO
4778 * returns: 0 - request transfer succesfully started
4779 * !0 - start of request transfer failed
4782 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4784 struct zfcp_adapter *adapter;
4785 struct zfcp_qdio_queue *req_queue;
4786 volatile struct qdio_buffer_element *sbale;
4787 int new_distance_from_int;
4788 unsigned long flags;
4792 adapter = fsf_req->adapter;
4793 req_queue = &adapter->request_queue,
4796 /* FIXME(debug): remove it later */
4797 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4798 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4799 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4800 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4803 /* set sequence counter in QTCB */
4804 if (likely(fsf_req->qtcb)) {
4805 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4806 fsf_req->seq_no = adapter->fsf_req_seq_no;
4807 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4808 "FSF sequence counter value of %i\n",
4810 zfcp_get_busid_by_adapter(adapter),
4811 fsf_req->qtcb->prefix.req_seq_no);
4815 /* put allocated FSF request at list tail */
4816 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4817 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4818 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4820 /* figure out expiration time of timeout and start timeout */
4821 if (unlikely(timer)) {
4822 timer->expires += jiffies;
4826 ZFCP_LOG_TRACE("request queue of adapter %s: "
4827 "next free SBAL is %i, %i free SBALs\n",
4828 zfcp_get_busid_by_adapter(adapter),
4829 req_queue->free_index,
4830 atomic_read(&req_queue->free_count));
4832 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4833 "index_in_queue=%i, count=%i, buffers=%p\n",
4834 zfcp_get_busid_by_adapter(adapter),
4835 QDIO_FLAG_SYNC_OUTPUT,
4836 0, fsf_req->sbal_first, fsf_req->sbal_number,
4837 &req_queue->buffer[fsf_req->sbal_first]);
4840 * adjust the number of free SBALs in request queue as well as
4841 * position of first one
4843 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4844 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4845 req_queue->free_index += fsf_req->sbal_number; /* increase */
4846 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4847 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4849 retval = do_QDIO(adapter->ccw_device,
4850 QDIO_FLAG_SYNC_OUTPUT,
4851 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4853 if (unlikely(retval)) {
4854 /* Queues are down..... */
4857 * FIXME(potential race):
4858 * timer might be expired (absolutely unlikely)
4862 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4863 list_del(&fsf_req->list);
4864 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4866 * adjust the number of free SBALs in request queue as well as
4867 * position of first one
4869 zfcp_qdio_zero_sbals(req_queue->buffer,
4870 fsf_req->sbal_first, fsf_req->sbal_number);
4871 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4872 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4873 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4874 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4876 ("error: do_QDIO failed. Buffers could not be enqueued "
4877 "to request queue.\n");
4879 req_queue->distance_from_int = new_distance_from_int;
4881 * increase FSF sequence counter -
4882 * this must only be done for request successfully enqueued to
4883 * QDIO this rejected requests may be cleaned up by calling
4884 * routines resulting in missing sequence counter values
4887 /* Don't increase for unsolicited status */
4888 if (likely(inc_seq_no)) {
4889 adapter->fsf_req_seq_no++;
4891 ("FSF sequence counter value of adapter %s "
4892 "increased to %i\n",
4893 zfcp_get_busid_by_adapter(adapter),
4894 adapter->fsf_req_seq_no);
4896 /* count FSF requests pending */
4897 atomic_inc(&adapter->fsf_reqs_active);
4903 * function: zfcp_fsf_req_cleanup
4905 * purpose: cleans up an FSF request and removes it from the specified list
4909 * assumption: no pending SB in SBALEs other than QTCB
4912 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4914 struct zfcp_adapter *adapter = fsf_req->adapter;
4915 unsigned long flags;
4917 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4918 list_del(&fsf_req->list);
4919 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4920 zfcp_fsf_req_free(fsf_req);
4923 #undef ZFCP_LOG_AREA