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 /* reopening link to port */
1271 zfcp_erp_port_reopen(unit->port, 0);
1272 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1274 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1275 /* SCSI stack will escalate */
1276 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1278 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1282 ("bug: Wrong status qualifier 0x%x arrived.\n",
1283 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1284 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1286 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1287 &new_fsf_req->qtcb->header.
1288 fsf_status_qual.word[0], sizeof (u32));
1295 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1299 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1300 "(debug info 0x%x)\n",
1301 new_fsf_req->qtcb->header.fsf_status);
1302 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1304 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1305 &new_fsf_req->qtcb->header.fsf_status,
1314 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1316 * Two scatter-gather lists are passed, one for the reqeust and one for the
1320 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1321 struct scatterlist *resp, int resp_count)
1323 return ((req_count == 1) &&
1324 (resp_count == 1) &&
1325 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1327 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1328 req[0].length - 1) & PAGE_MASK)) &&
1329 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1331 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1332 resp[0].length - 1) & PAGE_MASK)));
1336 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1337 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1339 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1340 * a struct zfcp_fsf_req
1341 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1342 * is sent within error recovery
1345 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1346 struct zfcp_erp_action *erp_action)
1348 volatile struct qdio_buffer_element *sbale;
1349 struct zfcp_port *port;
1350 struct zfcp_adapter *adapter;
1351 struct zfcp_fsf_req *fsf_req;
1352 unsigned long lock_flags;
1357 adapter = port->adapter;
1359 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1360 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1361 pool, &lock_flags, &fsf_req);
1363 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1365 zfcp_get_busid_by_adapter(adapter));
1369 if (erp_action != NULL) {
1370 erp_action->fsf_req = fsf_req;
1371 fsf_req->erp_action = erp_action;
1374 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1375 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1376 ct->resp, ct->resp_count)){
1377 /* both request buffer and response buffer
1378 fit into one sbale each */
1379 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1380 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1381 sbale[2].length = ct->req[0].length;
1382 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1383 sbale[3].length = ct->resp[0].length;
1384 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1385 } else if (adapter->supported_features &
1386 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1387 /* try to use chained SBALs */
1388 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1389 SBAL_FLAGS0_TYPE_WRITE_READ,
1390 ct->req, ct->req_count,
1391 ZFCP_MAX_SBALS_PER_CT_REQ);
1393 ZFCP_LOG_INFO("error: creation of CT request failed "
1395 zfcp_get_busid_by_adapter(adapter));
1403 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1404 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1405 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1406 SBAL_FLAGS0_TYPE_WRITE_READ,
1407 ct->resp, ct->resp_count,
1408 ZFCP_MAX_SBALS_PER_CT_REQ);
1410 ZFCP_LOG_INFO("error: creation of CT request failed "
1412 zfcp_get_busid_by_adapter(adapter));
1420 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1422 /* reject send generic request */
1424 "error: microcode does not support chained SBALs,"
1425 "CT request too big (adapter %s)\n",
1426 zfcp_get_busid_by_adapter(adapter));
1431 /* settings in QTCB */
1432 fsf_req->qtcb->header.port_handle = port->handle;
1433 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1434 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1435 fsf_req->data.send_ct = ct;
1437 /* start QDIO request for this FSF request */
1438 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1440 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1441 "(adapter %s, port 0x%016Lx)\n",
1442 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1446 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1447 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1451 zfcp_fsf_req_free(fsf_req);
1452 if (erp_action != NULL) {
1453 erp_action->fsf_req = NULL;
1457 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1463 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1464 * @fsf_req: pointer to struct zfcp_fsf_req
1466 * Data specific for the Generic Service request is passed by
1467 * fsf_req->data.send_ct
1468 * Usually a specific handler for the request is called via
1469 * fsf_req->data.send_ct->handler at end of this function.
1472 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1474 struct zfcp_port *port;
1475 struct zfcp_adapter *adapter;
1476 struct zfcp_send_ct *send_ct;
1477 struct fsf_qtcb_header *header;
1478 struct fsf_qtcb_bottom_support *bottom;
1479 int retval = -EINVAL;
1480 u16 subtable, rule, counter;
1482 adapter = fsf_req->adapter;
1483 send_ct = fsf_req->data.send_ct;
1484 port = send_ct->port;
1485 header = &fsf_req->qtcb->header;
1486 bottom = &fsf_req->qtcb->bottom.support;
1488 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1489 goto skip_fsfstatus;
1491 /* evaluate FSF status in QTCB */
1492 switch (header->fsf_status) {
1498 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1499 if (adapter->fc_service_class <= 3) {
1500 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1502 zfcp_get_busid_by_port(port),
1503 adapter->fc_service_class);
1505 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1506 "adapter %s is invalid. "
1507 "(debug info %d)\n",
1508 zfcp_get_busid_by_port(port),
1509 adapter->fc_service_class);
1511 /* stop operation for this adapter */
1512 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1513 zfcp_erp_adapter_shutdown(adapter, 0);
1514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1517 case FSF_ADAPTER_STATUS_AVAILABLE:
1518 switch (header->fsf_status_qual.word[0]){
1519 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1520 /* reopening link to port */
1521 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1522 zfcp_test_link(port);
1523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1525 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1526 /* ERP strategy will escalate */
1527 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1528 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1531 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1533 header->fsf_status_qual.word[0]);
1538 case FSF_ACCESS_DENIED:
1539 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1540 "command (adapter %s, port d_id=0x%08x)\n",
1541 zfcp_get_busid_by_port(port), port->d_id);
1542 for (counter = 0; counter < 2; counter++) {
1543 subtable = header->fsf_status_qual.halfword[counter * 2];
1544 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1546 case FSF_SQ_CFDC_SUBTABLE_OS:
1547 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1548 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1549 case FSF_SQ_CFDC_SUBTABLE_LUN:
1550 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1551 zfcp_act_subtable_type[subtable], rule);
1555 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1556 zfcp_erp_port_access_denied(port);
1557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1560 case FSF_GENERIC_COMMAND_REJECTED:
1561 ZFCP_LOG_INFO("generic service command rejected "
1562 "(adapter %s, port d_id=0x%08x)\n",
1563 zfcp_get_busid_by_port(port), port->d_id);
1564 ZFCP_LOG_INFO("status qualifier:\n");
1565 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1566 (char *) &header->fsf_status_qual,
1567 sizeof (union fsf_status_qual));
1568 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1569 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1572 case FSF_PORT_HANDLE_NOT_VALID:
1573 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1574 "0x%016Lx on adapter %s invalid. This may "
1575 "happen occasionally.\n", port->handle,
1576 port->wwpn, zfcp_get_busid_by_port(port));
1577 ZFCP_LOG_INFO("status qualifier:\n");
1578 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1579 (char *) &header->fsf_status_qual,
1580 sizeof (union fsf_status_qual));
1581 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1582 zfcp_erp_adapter_reopen(adapter, 0);
1583 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1586 case FSF_PORT_BOXED:
1587 ZFCP_LOG_INFO("port needs to be reopened "
1588 "(adapter %s, port d_id=0x%08x)\n",
1589 zfcp_get_busid_by_port(port), port->d_id);
1590 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1591 zfcp_erp_port_reopen(port, 0);
1592 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1593 | ZFCP_STATUS_FSFREQ_RETRY;
1596 /* following states should never occure, all cases avoided
1597 in zfcp_fsf_send_ct - but who knows ... */
1598 case FSF_PAYLOAD_SIZE_MISMATCH:
1599 ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
1600 "req_buf_length=%d, resp_buf_length=%d)\n",
1601 zfcp_get_busid_by_adapter(adapter),
1602 bottom->req_buf_length, bottom->resp_buf_length);
1603 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1605 case FSF_REQUEST_SIZE_TOO_LARGE:
1606 ZFCP_LOG_INFO("request size too large (adapter: %s, "
1607 "req_buf_length=%d)\n",
1608 zfcp_get_busid_by_adapter(adapter),
1609 bottom->req_buf_length);
1610 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1612 case FSF_RESPONSE_SIZE_TOO_LARGE:
1613 ZFCP_LOG_INFO("response size too large (adapter: %s, "
1614 "resp_buf_length=%d)\n",
1615 zfcp_get_busid_by_adapter(adapter),
1616 bottom->resp_buf_length);
1617 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1619 case FSF_SBAL_MISMATCH:
1620 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1621 "resp_buf_length=%d)\n",
1622 zfcp_get_busid_by_adapter(adapter),
1623 bottom->req_buf_length, bottom->resp_buf_length);
1624 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1628 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1629 "(debug info 0x%x)\n", header->fsf_status);
1630 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1631 debug_exception(adapter->erp_dbf, 0,
1632 &header->fsf_status_qual.word[0], sizeof (u32));
1637 send_ct->status = retval;
1639 if (send_ct->handler != NULL)
1640 send_ct->handler(send_ct->handler_data);
1646 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1647 * @els: pointer to struct zfcp_send_els which contains all needed data for
1651 zfcp_fsf_send_els(struct zfcp_send_els *els)
1653 volatile struct qdio_buffer_element *sbale;
1654 struct zfcp_fsf_req *fsf_req;
1656 struct zfcp_adapter *adapter;
1657 unsigned long lock_flags;
1662 adapter = els->adapter;
1664 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1665 ZFCP_REQ_AUTO_CLEANUP,
1666 NULL, &lock_flags, &fsf_req);
1668 ZFCP_LOG_INFO("error: creation of ELS request failed "
1669 "(adapter %s, port d_id: 0x%08x)\n",
1670 zfcp_get_busid_by_adapter(adapter), d_id);
1674 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1675 if (zfcp_use_one_sbal(els->req, els->req_count,
1676 els->resp, els->resp_count)){
1677 /* both request buffer and response buffer
1678 fit into one sbale each */
1679 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1680 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1681 sbale[2].length = els->req[0].length;
1682 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1683 sbale[3].length = els->resp[0].length;
1684 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1685 } else if (adapter->supported_features &
1686 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1687 /* try to use chained SBALs */
1688 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1689 SBAL_FLAGS0_TYPE_WRITE_READ,
1690 els->req, els->req_count,
1691 ZFCP_MAX_SBALS_PER_ELS_REQ);
1693 ZFCP_LOG_INFO("error: creation of ELS request failed "
1694 "(adapter %s, port d_id: 0x%08x)\n",
1695 zfcp_get_busid_by_adapter(adapter), d_id);
1703 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1704 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1705 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1706 SBAL_FLAGS0_TYPE_WRITE_READ,
1707 els->resp, els->resp_count,
1708 ZFCP_MAX_SBALS_PER_ELS_REQ);
1710 ZFCP_LOG_INFO("error: creation of ELS request failed "
1711 "(adapter %s, port d_id: 0x%08x)\n",
1712 zfcp_get_busid_by_adapter(adapter), d_id);
1720 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1722 /* reject request */
1723 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1724 ", ELS request too big (adapter %s, "
1725 "port d_id: 0x%08x)\n",
1726 zfcp_get_busid_by_adapter(adapter), d_id);
1731 /* settings in QTCB */
1732 fsf_req->qtcb->bottom.support.d_id = d_id;
1733 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1734 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1735 fsf_req->data.send_els = els;
1737 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1739 /* start QDIO request for this FSF request */
1740 ret = zfcp_fsf_req_send(fsf_req, els->timer);
1742 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1743 "(adapter %s, port d_id: 0x%08x)\n",
1744 zfcp_get_busid_by_adapter(adapter), d_id);
1748 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1749 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1753 zfcp_fsf_req_free(fsf_req);
1757 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1764 * zfcp_fsf_send_els_handler - handler for ELS commands
1765 * @fsf_req: pointer to struct zfcp_fsf_req
1767 * Data specific for the ELS command is passed by
1768 * fsf_req->data.send_els
1769 * Usually a specific handler for the command is called via
1770 * fsf_req->data.send_els->handler at end of this function.
1772 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1774 struct zfcp_adapter *adapter;
1776 struct zfcp_port *port;
1777 struct fsf_qtcb_header *header;
1778 struct fsf_qtcb_bottom_support *bottom;
1779 struct zfcp_send_els *send_els;
1780 int retval = -EINVAL;
1781 u16 subtable, rule, counter;
1783 send_els = fsf_req->data.send_els;
1784 adapter = send_els->adapter;
1785 d_id = send_els->d_id;
1786 header = &fsf_req->qtcb->header;
1787 bottom = &fsf_req->qtcb->bottom.support;
1789 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1790 goto skip_fsfstatus;
1792 switch (header->fsf_status) {
1798 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1799 if (adapter->fc_service_class <= 3) {
1800 ZFCP_LOG_INFO("error: adapter %s does "
1801 "not support fibrechannel class %d.\n",
1802 zfcp_get_busid_by_adapter(adapter),
1803 adapter->fc_service_class);
1805 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1806 "adapter %s is invalid. "
1807 "(debug info %d)\n",
1808 zfcp_get_busid_by_adapter(adapter),
1809 adapter->fc_service_class);
1811 /* stop operation for this adapter */
1812 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1813 zfcp_erp_adapter_shutdown(adapter, 0);
1814 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1817 case FSF_ADAPTER_STATUS_AVAILABLE:
1818 switch (header->fsf_status_qual.word[0]){
1819 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1820 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1821 if (send_els->ls_code != ZFCP_LS_ADISC) {
1822 read_lock(&zfcp_data.config_lock);
1823 port = zfcp_get_port_by_did(adapter, d_id);
1825 zfcp_test_link(port);
1826 read_unlock(&zfcp_data.config_lock);
1828 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1830 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1831 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1832 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1834 zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
1835 (struct zfcp_ls_rjt_par *)
1836 &header->fsf_status_qual.word[2]);
1838 case FSF_SQ_RETRY_IF_POSSIBLE:
1839 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1840 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1843 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1844 header->fsf_status_qual.word[0]);
1845 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1846 (char*)header->fsf_status_qual.word, 16);
1850 case FSF_ELS_COMMAND_REJECTED:
1851 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1852 "prohibited sending "
1853 "(adapter: %s, port d_id: 0x%08x)\n",
1854 zfcp_get_busid_by_adapter(adapter), d_id);
1858 case FSF_PAYLOAD_SIZE_MISMATCH:
1860 "ELS request size and ELS response size must be either "
1861 "both 0, or both greater than 0 "
1862 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1863 zfcp_get_busid_by_adapter(adapter),
1864 bottom->req_buf_length,
1865 bottom->resp_buf_length);
1868 case FSF_REQUEST_SIZE_TOO_LARGE:
1870 "Length of the ELS request buffer, "
1871 "specified in QTCB bottom, "
1872 "exceeds the size of the buffers "
1873 "that have been allocated for ELS request data "
1874 "(adapter: %s, req_buf_length=%d)\n",
1875 zfcp_get_busid_by_adapter(adapter),
1876 bottom->req_buf_length);
1879 case FSF_RESPONSE_SIZE_TOO_LARGE:
1881 "Length of the ELS response buffer, "
1882 "specified in QTCB bottom, "
1883 "exceeds the size of the buffers "
1884 "that have been allocated for ELS response data "
1885 "(adapter: %s, resp_buf_length=%d)\n",
1886 zfcp_get_busid_by_adapter(adapter),
1887 bottom->resp_buf_length);
1890 case FSF_SBAL_MISMATCH:
1891 /* should never occure, avoided in zfcp_fsf_send_els */
1892 ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
1893 "resp_buf_length=%d)\n",
1894 zfcp_get_busid_by_adapter(adapter),
1895 bottom->req_buf_length, bottom->resp_buf_length);
1896 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1899 case FSF_ACCESS_DENIED:
1900 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1901 "(adapter %s, port d_id=0x%08x)\n",
1902 zfcp_get_busid_by_adapter(adapter), d_id);
1903 for (counter = 0; counter < 2; counter++) {
1904 subtable = header->fsf_status_qual.halfword[counter * 2];
1905 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1907 case FSF_SQ_CFDC_SUBTABLE_OS:
1908 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1909 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1910 case FSF_SQ_CFDC_SUBTABLE_LUN:
1911 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1912 zfcp_act_subtable_type[subtable], rule);
1916 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1917 read_lock(&zfcp_data.config_lock);
1918 port = zfcp_get_port_by_did(adapter, d_id);
1920 zfcp_erp_port_access_denied(port);
1921 read_unlock(&zfcp_data.config_lock);
1922 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1927 "bug: An unknown FSF Status was presented "
1928 "(adapter: %s, fsf_status=0x%08x)\n",
1929 zfcp_get_busid_by_adapter(adapter),
1930 header->fsf_status);
1931 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1932 debug_exception(adapter->erp_dbf, 0,
1933 &header->fsf_status_qual.word[0], sizeof(u32));
1934 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1939 send_els->status = retval;
1941 if (send_els->handler != 0)
1942 send_els->handler(send_els->handler_data);
1952 * returns: address of initiated FSF request
1953 * NULL - request could not be initiated
1956 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1958 volatile struct qdio_buffer_element *sbale;
1959 unsigned long lock_flags;
1962 /* setup new FSF request */
1963 retval = zfcp_fsf_req_create(erp_action->adapter,
1964 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1965 ZFCP_REQ_AUTO_CLEANUP,
1966 erp_action->adapter->pool.fsf_req_erp,
1967 &lock_flags, &(erp_action->fsf_req));
1969 ZFCP_LOG_INFO("error: Could not create exchange configuration "
1970 "data request for adapter %s.\n",
1971 zfcp_get_busid_by_adapter(erp_action->adapter));
1975 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
1976 erp_action->fsf_req->sbal_curr, 0);
1977 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1978 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1980 erp_action->fsf_req->erp_action = erp_action;
1981 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
1982 (FSF_FEATURE_CFDC | FSF_FEATURE_LUN_SHARING);
1984 /* start QDIO request for this FSF request */
1985 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
1988 ("error: Could not send exchange configuration data "
1989 "command on the adapter %s\n",
1990 zfcp_get_busid_by_adapter(erp_action->adapter));
1991 zfcp_fsf_req_free(erp_action->fsf_req);
1992 erp_action->fsf_req = NULL;
1996 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
1998 zfcp_get_busid_by_adapter(erp_action->adapter));
2001 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2007 * zfcp_fsf_exchange_config_evaluate
2008 * @fsf_req: fsf_req which belongs to xchg config data request
2009 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2011 * returns: -EIO on error, 0 otherwise
2014 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2016 struct fsf_qtcb_bottom_config *bottom;
2017 struct zfcp_adapter *adapter = fsf_req->adapter;
2019 bottom = &fsf_req->qtcb->bottom.config;
2020 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2021 bottom->low_qtcb_version, bottom->high_qtcb_version);
2022 adapter->fsf_lic_version = bottom->lic_version;
2023 adapter->supported_features = bottom->supported_features;
2024 adapter->peer_wwpn = 0;
2025 adapter->peer_wwnn = 0;
2026 adapter->peer_d_id = 0;
2029 adapter->wwnn = bottom->nport_serv_param.wwnn;
2030 adapter->wwpn = bottom->nport_serv_param.wwpn;
2031 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2032 adapter->fc_topology = bottom->fc_topology;
2033 adapter->fc_link_speed = bottom->fc_link_speed;
2034 adapter->hydra_version = bottom->adapter_type;
2039 adapter->fc_topology = 0;
2040 adapter->fc_link_speed = 0;
2041 adapter->hydra_version = 0;
2044 if (adapter->fc_topology == FSF_TOPO_P2P) {
2045 adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
2046 adapter->peer_wwpn = bottom->plogi_payload.wwpn;
2047 adapter->peer_wwnn = bottom->plogi_payload.wwnn;
2050 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2051 adapter->hardware_version = bottom->hardware_version;
2052 memcpy(adapter->serial_number, bottom->serial_number, 17);
2053 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2056 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2060 "adapter version 0x%x, "
2061 "LIC version 0x%x, "
2062 "FC link speed %d Gb/s\n",
2063 zfcp_get_busid_by_adapter(adapter),
2066 (unsigned int) adapter->s_id,
2067 adapter->hydra_version,
2068 adapter->fsf_lic_version,
2069 adapter->fc_link_speed);
2070 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2071 ZFCP_LOG_NORMAL("error: the adapter %s "
2072 "only supports newer control block "
2073 "versions in comparison to this device "
2074 "driver (try updated device driver)\n",
2075 zfcp_get_busid_by_adapter(adapter));
2076 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2077 zfcp_erp_adapter_shutdown(adapter, 0);
2080 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2081 ZFCP_LOG_NORMAL("error: the adapter %s "
2082 "only supports older control block "
2083 "versions than this device driver uses"
2084 "(consider a microcode upgrade)\n",
2085 zfcp_get_busid_by_adapter(adapter));
2086 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2087 zfcp_erp_adapter_shutdown(adapter, 0);
2094 * function: zfcp_fsf_exchange_config_data_handler
2096 * purpose: is called for finished Exchange Configuration Data command
2101 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2103 struct fsf_qtcb_bottom_config *bottom;
2104 struct zfcp_adapter *adapter = fsf_req->adapter;
2106 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2109 switch (fsf_req->qtcb->header.fsf_status) {
2112 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2115 switch (adapter->fc_topology) {
2117 ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
2118 "configuration detected at adapter %s\n"
2119 "Peer WWNN 0x%016llx, "
2120 "peer WWPN 0x%016llx, "
2121 "peer d_id 0x%06x\n",
2122 zfcp_get_busid_by_adapter(adapter),
2125 adapter->peer_d_id);
2126 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2130 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2131 "topology detected at adapter %s "
2132 "unsupported, shutting down adapter\n",
2133 zfcp_get_busid_by_adapter(adapter));
2134 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2136 zfcp_erp_adapter_shutdown(adapter, 0);
2138 case FSF_TOPO_FABRIC:
2139 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2140 "network detected at adapter %s.\n",
2141 zfcp_get_busid_by_adapter(adapter));
2144 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2145 "reported by the exchange "
2146 "configuration command for "
2147 "the adapter %s is not "
2148 "of a type known to the zfcp "
2149 "driver, shutting down adapter\n",
2150 zfcp_get_busid_by_adapter(adapter));
2151 adapter->fc_topology = FSF_TOPO_ERROR;
2152 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2154 zfcp_erp_adapter_shutdown(adapter, 0);
2157 bottom = &fsf_req->qtcb->bottom.config;
2158 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2159 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2160 "allowed by the adapter %s "
2161 "is lower than the minimum "
2162 "required by the driver (%ld bytes).\n",
2163 bottom->max_qtcb_size,
2164 zfcp_get_busid_by_adapter(adapter),
2165 sizeof(struct fsf_qtcb));
2166 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2168 debug_event(fsf_req->adapter->erp_dbf, 0,
2169 &bottom->max_qtcb_size, sizeof (u32));
2170 zfcp_erp_adapter_shutdown(adapter, 0);
2173 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2176 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2177 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2179 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2182 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2183 zfcp_get_busid_by_adapter(adapter));
2184 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2185 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2187 zfcp_erp_adapter_failed(adapter);
2190 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2191 debug_event(fsf_req->adapter->erp_dbf, 0,
2192 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2193 zfcp_erp_adapter_shutdown(adapter, 0);
2200 * zfcp_fsf_exchange_port_data - request information about local port
2201 * @adapter: for which port data is requested
2202 * @data: response to exchange port data request
2205 zfcp_fsf_exchange_port_data(struct zfcp_adapter *adapter,
2206 struct fsf_qtcb_bottom_port *data)
2208 volatile struct qdio_buffer_element *sbale;
2210 unsigned long lock_flags;
2211 struct zfcp_fsf_req *fsf_req;
2212 struct timer_list *timer;
2214 if(!(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT)){
2215 ZFCP_LOG_INFO("error: exchange port data "
2216 "command not supported by adapter %s\n",
2217 zfcp_get_busid_by_adapter(adapter));
2221 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
2225 /* setup new FSF request */
2226 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
2227 0, 0, &lock_flags, &fsf_req);
2229 ZFCP_LOG_INFO("error: Out of resources. Could not create an "
2230 "exchange port data request for"
2231 "the adapter %s.\n",
2232 zfcp_get_busid_by_adapter(adapter));
2233 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2238 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
2239 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2240 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2242 fsf_req->data.port_data = data;
2245 timer->function = zfcp_fsf_request_timeout_handler;
2246 timer->data = (unsigned long) adapter;
2247 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
2249 retval = zfcp_fsf_req_send(fsf_req, timer);
2251 ZFCP_LOG_INFO("error: Could not send an exchange port data "
2252 "command on the adapter %s\n",
2253 zfcp_get_busid_by_adapter(adapter));
2254 zfcp_fsf_req_free(fsf_req);
2255 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2260 ZFCP_LOG_DEBUG("Exchange Port Data request initiated (adapter %s)\n",
2261 zfcp_get_busid_by_adapter(adapter));
2263 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
2266 wait_event(fsf_req->completion_wq,
2267 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
2268 del_timer_sync(timer);
2269 zfcp_fsf_req_cleanup(fsf_req);
2277 * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
2278 * @fsf_req: pointer to struct zfcp_fsf_req
2281 zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
2283 struct fsf_qtcb_bottom_port *bottom;
2284 struct fsf_qtcb_bottom_port *data = fsf_req->data.port_data;
2286 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2289 switch (fsf_req->qtcb->header.fsf_status) {
2291 bottom = &fsf_req->qtcb->bottom.port;
2292 memcpy(data, bottom, sizeof(*data));
2296 debug_text_event(fsf_req->adapter->erp_dbf, 0, "xchg-port-ng");
2297 debug_event(fsf_req->adapter->erp_dbf, 0,
2298 &fsf_req->qtcb->header.fsf_status, sizeof(u32));
2304 * function: zfcp_fsf_open_port
2308 * returns: address of initiated FSF request
2309 * NULL - request could not be initiated
2312 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2314 volatile struct qdio_buffer_element *sbale;
2315 unsigned long lock_flags;
2318 /* setup new FSF request */
2319 retval = zfcp_fsf_req_create(erp_action->adapter,
2320 FSF_QTCB_OPEN_PORT_WITH_DID,
2321 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2322 erp_action->adapter->pool.fsf_req_erp,
2323 &lock_flags, &(erp_action->fsf_req));
2325 ZFCP_LOG_INFO("error: Could not create open port request "
2326 "for port 0x%016Lx on adapter %s.\n",
2327 erp_action->port->wwpn,
2328 zfcp_get_busid_by_adapter(erp_action->adapter));
2332 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2333 erp_action->fsf_req->sbal_curr, 0);
2334 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2335 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2337 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2338 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2339 erp_action->fsf_req->data.open_port.port = erp_action->port;
2340 erp_action->fsf_req->erp_action = erp_action;
2342 /* start QDIO request for this FSF request */
2343 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2345 ZFCP_LOG_INFO("error: Could not send open port request for "
2346 "port 0x%016Lx on adapter %s.\n",
2347 erp_action->port->wwpn,
2348 zfcp_get_busid_by_adapter(erp_action->adapter));
2349 zfcp_fsf_req_free(erp_action->fsf_req);
2350 erp_action->fsf_req = NULL;
2354 ZFCP_LOG_DEBUG("open port request initiated "
2355 "(adapter %s, port 0x%016Lx)\n",
2356 zfcp_get_busid_by_adapter(erp_action->adapter),
2357 erp_action->port->wwpn);
2359 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2365 * function: zfcp_fsf_open_port_handler
2367 * purpose: is called for finished Open Port command
2372 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2374 int retval = -EINVAL;
2375 struct zfcp_port *port;
2376 struct fsf_plogi *plogi;
2377 struct fsf_qtcb_header *header;
2378 u16 subtable, rule, counter;
2380 port = fsf_req->data.open_port.port;
2381 header = &fsf_req->qtcb->header;
2383 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2384 /* don't change port status in our bookkeeping */
2385 goto skip_fsfstatus;
2388 /* evaluate FSF status in QTCB */
2389 switch (header->fsf_status) {
2391 case FSF_PORT_ALREADY_OPEN:
2392 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2393 "is already open.\n",
2394 port->wwpn, zfcp_get_busid_by_port(port));
2395 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2398 * This is a bug, however operation should continue normally
2399 * if it is simply ignored
2403 case FSF_ACCESS_DENIED:
2404 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2406 port->wwpn, zfcp_get_busid_by_port(port));
2407 for (counter = 0; counter < 2; counter++) {
2408 subtable = header->fsf_status_qual.halfword[counter * 2];
2409 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2411 case FSF_SQ_CFDC_SUBTABLE_OS:
2412 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2413 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2414 case FSF_SQ_CFDC_SUBTABLE_LUN:
2415 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2416 zfcp_act_subtable_type[subtable], rule);
2420 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2421 zfcp_erp_port_access_denied(port);
2422 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2425 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2426 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2427 "The remote port 0x%016Lx on adapter %s "
2428 "could not be opened. Disabling it.\n",
2429 port->wwpn, zfcp_get_busid_by_port(port));
2430 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2432 zfcp_erp_port_failed(port);
2433 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2436 case FSF_ADAPTER_STATUS_AVAILABLE:
2437 switch (header->fsf_status_qual.word[0]) {
2438 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2439 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2441 /* ERP strategy will escalate */
2442 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2444 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2445 /* ERP strategy will escalate */
2446 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2448 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2450 case FSF_SQ_NO_RETRY_POSSIBLE:
2451 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2452 "adapter %s could not be opened. "
2455 zfcp_get_busid_by_port(port));
2456 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2458 zfcp_erp_port_failed(port);
2459 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2463 ("bug: Wrong status qualifier 0x%x arrived.\n",
2464 header->fsf_status_qual.word[0]);
2465 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2468 fsf_req->adapter->erp_dbf, 0,
2469 &header->fsf_status_qual.word[0],
2476 /* save port handle assigned by FSF */
2477 port->handle = header->port_handle;
2478 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2479 "was opened, it's port handle is 0x%x\n",
2480 port->wwpn, zfcp_get_busid_by_port(port),
2482 /* mark port as open */
2483 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2484 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2486 /* check whether D_ID has changed during open */
2488 * FIXME: This check is not airtight, as the FCP channel does
2489 * not monitor closures of target port connections caused on
2490 * the remote side. Thus, they might miss out on invalidating
2491 * locally cached WWPNs (and other N_Port parameters) of gone
2492 * target ports. So, our heroic attempt to make things safe
2493 * could be undermined by 'open port' response data tagged with
2494 * obsolete WWPNs. Another reason to monitor potential
2495 * connection closures ourself at least (by interpreting
2496 * incoming ELS' and unsolicited status). It just crosses my
2497 * mind that one should be able to cross-check by means of
2498 * another GID_PN straight after a port has been opened.
2499 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2501 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2502 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2504 if (fsf_req->qtcb->bottom.support.els1_length <
2505 ((((unsigned long) &plogi->serv_param.wwpn) -
2506 ((unsigned long) plogi)) + sizeof (u64))) {
2508 "warning: insufficient length of "
2509 "PLOGI payload (%i)\n",
2510 fsf_req->qtcb->bottom.support.els1_length);
2511 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2512 "fsf_s_short_plogi:");
2513 /* skip sanity check and assume wwpn is ok */
2515 if (plogi->serv_param.wwpn != port->wwpn) {
2516 ZFCP_LOG_INFO("warning: d_id of port "
2517 "0x%016Lx changed during "
2518 "open\n", port->wwpn);
2520 fsf_req->adapter->erp_dbf, 0,
2521 "fsf_s_did_change:");
2523 ZFCP_STATUS_PORT_DID_DID,
2526 port->wwnn = plogi->serv_param.wwnn;
2531 case FSF_UNKNOWN_OP_SUBTYPE:
2532 /* should never occure, subtype not set in zfcp_fsf_open_port */
2533 ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
2534 "op_subtype=0x%x)\n",
2535 zfcp_get_busid_by_port(port),
2536 fsf_req->qtcb->bottom.support.operation_subtype);
2537 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2541 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2542 "(debug info 0x%x)\n",
2543 header->fsf_status);
2544 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2545 debug_exception(fsf_req->adapter->erp_dbf, 0,
2546 &header->fsf_status, sizeof (u32));
2551 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2556 * function: zfcp_fsf_close_port
2558 * purpose: submit FSF command "close port"
2560 * returns: address of initiated FSF request
2561 * NULL - request could not be initiated
2564 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2566 volatile struct qdio_buffer_element *sbale;
2567 unsigned long lock_flags;
2570 /* setup new FSF request */
2571 retval = zfcp_fsf_req_create(erp_action->adapter,
2572 FSF_QTCB_CLOSE_PORT,
2573 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2574 erp_action->adapter->pool.fsf_req_erp,
2575 &lock_flags, &(erp_action->fsf_req));
2577 ZFCP_LOG_INFO("error: Could not create a close port request "
2578 "for port 0x%016Lx on adapter %s.\n",
2579 erp_action->port->wwpn,
2580 zfcp_get_busid_by_adapter(erp_action->adapter));
2584 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2585 erp_action->fsf_req->sbal_curr, 0);
2586 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2587 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2589 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2590 erp_action->fsf_req->data.close_port.port = erp_action->port;
2591 erp_action->fsf_req->erp_action = erp_action;
2592 erp_action->fsf_req->qtcb->header.port_handle =
2593 erp_action->port->handle;
2595 /* start QDIO request for this FSF request */
2596 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2598 ZFCP_LOG_INFO("error: Could not send a close port request for "
2599 "port 0x%016Lx on adapter %s.\n",
2600 erp_action->port->wwpn,
2601 zfcp_get_busid_by_adapter(erp_action->adapter));
2602 zfcp_fsf_req_free(erp_action->fsf_req);
2603 erp_action->fsf_req = NULL;
2607 ZFCP_LOG_TRACE("close port request initiated "
2608 "(adapter %s, port 0x%016Lx)\n",
2609 zfcp_get_busid_by_adapter(erp_action->adapter),
2610 erp_action->port->wwpn);
2612 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2618 * function: zfcp_fsf_close_port_handler
2620 * purpose: is called for finished Close Port FSF command
2625 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2627 int retval = -EINVAL;
2628 struct zfcp_port *port;
2630 port = fsf_req->data.close_port.port;
2632 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2633 /* don't change port status in our bookkeeping */
2634 goto skip_fsfstatus;
2637 /* evaluate FSF status in QTCB */
2638 switch (fsf_req->qtcb->header.fsf_status) {
2640 case FSF_PORT_HANDLE_NOT_VALID:
2641 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2642 "0x%016Lx on adapter %s invalid. This may happen "
2643 "occasionally.\n", port->handle,
2644 port->wwpn, zfcp_get_busid_by_port(port));
2645 ZFCP_LOG_DEBUG("status qualifier:\n");
2646 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2647 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2648 sizeof (union fsf_status_qual));
2649 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2651 zfcp_erp_adapter_reopen(port->adapter, 0);
2652 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2655 case FSF_ADAPTER_STATUS_AVAILABLE:
2656 /* Note: FSF has actually closed the port in this case.
2657 * The status code is just daft. Fingers crossed for a change
2663 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2664 "port handle 0x%x\n", port->wwpn,
2665 zfcp_get_busid_by_port(port), port->handle);
2666 zfcp_erp_modify_port_status(port,
2667 ZFCP_STATUS_COMMON_OPEN,
2673 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2674 "(debug info 0x%x)\n",
2675 fsf_req->qtcb->header.fsf_status);
2676 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2677 debug_exception(fsf_req->adapter->erp_dbf, 0,
2678 &fsf_req->qtcb->header.fsf_status,
2684 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2689 * function: zfcp_fsf_close_physical_port
2691 * purpose: submit FSF command "close physical port"
2693 * returns: address of initiated FSF request
2694 * NULL - request could not be initiated
2697 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2700 unsigned long lock_flags;
2701 volatile struct qdio_buffer_element *sbale;
2703 /* setup new FSF request */
2704 retval = zfcp_fsf_req_create(erp_action->adapter,
2705 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2706 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2707 erp_action->adapter->pool.fsf_req_erp,
2708 &lock_flags, &erp_action->fsf_req);
2710 ZFCP_LOG_INFO("error: Could not create close physical port "
2711 "request (adapter %s, port 0x%016Lx)\n",
2712 zfcp_get_busid_by_adapter(erp_action->adapter),
2713 erp_action->port->wwpn);
2718 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2719 erp_action->fsf_req->sbal_curr, 0);
2720 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2721 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2723 /* mark port as being closed */
2724 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2725 &erp_action->port->status);
2726 /* save a pointer to this port */
2727 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2728 /* port to be closeed */
2729 erp_action->fsf_req->qtcb->header.port_handle =
2730 erp_action->port->handle;
2731 erp_action->fsf_req->erp_action = erp_action;
2733 /* start QDIO request for this FSF request */
2734 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2736 ZFCP_LOG_INFO("error: Could not send close physical port "
2737 "request (adapter %s, port 0x%016Lx)\n",
2738 zfcp_get_busid_by_adapter(erp_action->adapter),
2739 erp_action->port->wwpn);
2740 zfcp_fsf_req_free(erp_action->fsf_req);
2741 erp_action->fsf_req = NULL;
2745 ZFCP_LOG_TRACE("close physical port request initiated "
2746 "(adapter %s, port 0x%016Lx)\n",
2747 zfcp_get_busid_by_adapter(erp_action->adapter),
2748 erp_action->port->wwpn);
2750 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2756 * function: zfcp_fsf_close_physical_port_handler
2758 * purpose: is called for finished Close Physical Port FSF command
2763 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2765 int retval = -EINVAL;
2766 struct zfcp_port *port;
2767 struct zfcp_unit *unit;
2768 struct fsf_qtcb_header *header;
2769 u16 subtable, rule, counter;
2771 port = fsf_req->data.close_physical_port.port;
2772 header = &fsf_req->qtcb->header;
2774 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2775 /* don't change port status in our bookkeeping */
2776 goto skip_fsfstatus;
2779 /* evaluate FSF status in QTCB */
2780 switch (header->fsf_status) {
2782 case FSF_PORT_HANDLE_NOT_VALID:
2783 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2784 "(adapter %s, port 0x%016Lx). "
2785 "This may happen occasionally.\n",
2787 zfcp_get_busid_by_port(port),
2789 ZFCP_LOG_DEBUG("status qualifier:\n");
2790 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2791 (char *) &header->fsf_status_qual,
2792 sizeof (union fsf_status_qual));
2793 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2795 zfcp_erp_adapter_reopen(port->adapter, 0);
2796 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2799 case FSF_ACCESS_DENIED:
2800 ZFCP_LOG_NORMAL("Access denied, cannot close "
2801 "physical port 0x%016Lx on adapter %s\n",
2802 port->wwpn, zfcp_get_busid_by_port(port));
2803 for (counter = 0; counter < 2; counter++) {
2804 subtable = header->fsf_status_qual.halfword[counter * 2];
2805 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2807 case FSF_SQ_CFDC_SUBTABLE_OS:
2808 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2809 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2810 case FSF_SQ_CFDC_SUBTABLE_LUN:
2811 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2812 zfcp_act_subtable_type[subtable], rule);
2816 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2817 zfcp_erp_port_access_denied(port);
2818 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2821 case FSF_PORT_BOXED:
2822 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2823 "%s needs to be reopened but it was attempted "
2824 "to close it physically.\n",
2826 zfcp_get_busid_by_port(port));
2827 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2828 zfcp_erp_port_reopen(port, 0);
2829 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2830 ZFCP_STATUS_FSFREQ_RETRY;
2833 case FSF_ADAPTER_STATUS_AVAILABLE:
2834 switch (header->fsf_status_qual.word[0]) {
2835 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2836 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2838 /* This will now be escalated by ERP */
2839 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2841 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2842 /* ERP strategy will escalate */
2843 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2845 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2849 ("bug: Wrong status qualifier 0x%x arrived.\n",
2850 header->fsf_status_qual.word[0]);
2851 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2854 fsf_req->adapter->erp_dbf, 0,
2855 &header->fsf_status_qual.word[0], sizeof (u32));
2861 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2862 "physically closed, port handle 0x%x\n",
2864 zfcp_get_busid_by_port(port), port->handle);
2865 /* can't use generic zfcp_erp_modify_port_status because
2866 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2868 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2869 list_for_each_entry(unit, &port->unit_list_head, list)
2870 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2875 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2876 "(debug info 0x%x)\n",
2877 header->fsf_status);
2878 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2879 debug_exception(fsf_req->adapter->erp_dbf, 0,
2880 &header->fsf_status, sizeof (u32));
2885 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2890 * function: zfcp_fsf_open_unit
2896 * assumptions: This routine does not check whether the associated
2897 * remote port has already been opened. This should be
2898 * done by calling routines. Otherwise some status
2899 * may be presented by FSF
2902 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2904 volatile struct qdio_buffer_element *sbale;
2905 unsigned long lock_flags;
2908 /* setup new FSF request */
2909 retval = zfcp_fsf_req_create(erp_action->adapter,
2911 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2912 erp_action->adapter->pool.fsf_req_erp,
2913 &lock_flags, &(erp_action->fsf_req));
2915 ZFCP_LOG_INFO("error: Could not create open unit request for "
2916 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2917 erp_action->unit->fcp_lun,
2918 erp_action->unit->port->wwpn,
2919 zfcp_get_busid_by_adapter(erp_action->adapter));
2923 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2924 erp_action->fsf_req->sbal_curr, 0);
2925 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2926 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2928 erp_action->fsf_req->qtcb->header.port_handle =
2929 erp_action->port->handle;
2930 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2931 erp_action->unit->fcp_lun;
2932 erp_action->fsf_req->qtcb->bottom.support.option =
2933 FSF_OPEN_LUN_SUPPRESS_BOXING;
2934 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2935 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2936 erp_action->fsf_req->erp_action = erp_action;
2938 /* start QDIO request for this FSF request */
2939 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2941 ZFCP_LOG_INFO("error: Could not send an open unit request "
2942 "on the adapter %s, port 0x%016Lx for "
2944 zfcp_get_busid_by_adapter(erp_action->adapter),
2945 erp_action->port->wwpn,
2946 erp_action->unit->fcp_lun);
2947 zfcp_fsf_req_free(erp_action->fsf_req);
2948 erp_action->fsf_req = NULL;
2952 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2953 "port 0x%016Lx, unit 0x%016Lx)\n",
2954 zfcp_get_busid_by_adapter(erp_action->adapter),
2955 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2957 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2963 * function: zfcp_fsf_open_unit_handler
2965 * purpose: is called for finished Open LUN command
2970 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2972 int retval = -EINVAL;
2973 struct zfcp_adapter *adapter;
2974 struct zfcp_unit *unit;
2975 struct fsf_qtcb_header *header;
2976 struct fsf_qtcb_bottom_support *bottom;
2977 struct fsf_queue_designator *queue_designator;
2978 u16 subtable, rule, counter;
2979 u32 allowed, exclusive, readwrite;
2981 unit = fsf_req->data.open_unit.unit;
2983 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2984 /* don't change unit status in our bookkeeping */
2985 goto skip_fsfstatus;
2988 adapter = fsf_req->adapter;
2989 header = &fsf_req->qtcb->header;
2990 bottom = &fsf_req->qtcb->bottom.support;
2991 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
2993 allowed = bottom->lun_access_info & FSF_UNIT_ACCESS_OPEN_LUN_ALLOWED;
2994 exclusive = bottom->lun_access_info & FSF_UNIT_ACCESS_EXCLUSIVE;
2995 readwrite = bottom->lun_access_info & FSF_UNIT_ACCESS_OUTBOUND_TRANSFER;
2997 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
2998 ZFCP_STATUS_UNIT_SHARED |
2999 ZFCP_STATUS_UNIT_READONLY,
3002 /* evaluate FSF status in QTCB */
3003 switch (header->fsf_status) {
3005 case FSF_PORT_HANDLE_NOT_VALID:
3006 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
3007 "for port 0x%016Lx on adapter %s invalid "
3008 "This may happen occasionally\n",
3010 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3011 ZFCP_LOG_DEBUG("status qualifier:\n");
3012 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3013 (char *) &header->fsf_status_qual,
3014 sizeof (union fsf_status_qual));
3015 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
3016 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3017 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3020 case FSF_LUN_ALREADY_OPEN:
3021 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
3022 "remote port 0x%016Lx on adapter %s twice.\n",
3024 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3025 debug_text_exception(adapter->erp_dbf, 0,
3027 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3030 case FSF_ACCESS_DENIED:
3031 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
3032 "remote port 0x%016Lx on adapter %s\n",
3033 unit->fcp_lun, unit->port->wwpn,
3034 zfcp_get_busid_by_unit(unit));
3035 for (counter = 0; counter < 2; counter++) {
3036 subtable = header->fsf_status_qual.halfword[counter * 2];
3037 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3039 case FSF_SQ_CFDC_SUBTABLE_OS:
3040 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3041 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3042 case FSF_SQ_CFDC_SUBTABLE_LUN:
3043 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3044 zfcp_act_subtable_type[subtable], rule);
3048 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
3049 zfcp_erp_unit_access_denied(unit);
3050 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3051 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3052 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3055 case FSF_PORT_BOXED:
3056 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3057 "needs to be reopened\n",
3058 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3059 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
3060 zfcp_erp_port_reopen(unit->port, 0);
3061 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3062 ZFCP_STATUS_FSFREQ_RETRY;
3065 case FSF_LUN_SHARING_VIOLATION:
3066 if (header->fsf_status_qual.word[0] != 0) {
3067 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
3069 "connected to the adapter %s "
3070 "is already in use in LPAR%d, CSS%d\n",
3073 zfcp_get_busid_by_unit(unit),
3074 queue_designator->hla,
3075 queue_designator->cssid);
3077 subtable = header->fsf_status_qual.halfword[4];
3078 rule = header->fsf_status_qual.halfword[5];
3080 case FSF_SQ_CFDC_SUBTABLE_OS:
3081 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3082 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3083 case FSF_SQ_CFDC_SUBTABLE_LUN:
3084 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
3085 "remote port with WWPN 0x%Lx "
3086 "connected to the adapter %s "
3087 "is denied (%s rule %d)\n",
3090 zfcp_get_busid_by_unit(unit),
3091 zfcp_act_subtable_type[subtable],
3096 ZFCP_LOG_DEBUG("status qualifier:\n");
3097 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3098 (char *) &header->fsf_status_qual,
3099 sizeof (union fsf_status_qual));
3100 debug_text_event(adapter->erp_dbf, 2,
3102 zfcp_erp_unit_access_denied(unit);
3103 atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
3104 atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
3105 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3108 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3109 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3110 "There is no handle (temporary port identifier) "
3111 "available for unit 0x%016Lx on port 0x%016Lx "
3115 zfcp_get_busid_by_unit(unit));
3116 debug_text_event(adapter->erp_dbf, 1,
3118 zfcp_erp_unit_failed(unit);
3119 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3122 case FSF_ADAPTER_STATUS_AVAILABLE:
3123 switch (header->fsf_status_qual.word[0]) {
3124 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3125 /* Re-establish link to port */
3126 debug_text_event(adapter->erp_dbf, 1,
3128 zfcp_erp_port_reopen(unit->port, 0);
3129 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3131 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3132 /* ERP strategy will escalate */
3133 debug_text_event(adapter->erp_dbf, 1,
3135 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3139 ("bug: Wrong status qualifier 0x%x arrived.\n",
3140 header->fsf_status_qual.word[0]);
3141 debug_text_event(adapter->erp_dbf, 0,
3143 debug_exception(adapter->erp_dbf, 0,
3144 &header->fsf_status_qual.word[0],
3149 case FSF_INVALID_COMMAND_OPTION:
3151 "Invalid option 0x%x has been specified "
3152 "in QTCB bottom sent to the adapter %s\n",
3154 zfcp_get_busid_by_adapter(adapter));
3155 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3160 /* save LUN handle assigned by FSF */
3161 unit->handle = header->lun_handle;
3162 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3163 "adapter %s opened, port handle 0x%x\n",
3166 zfcp_get_busid_by_unit(unit),
3168 /* mark unit as open */
3169 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3171 if (adapter->supported_features & FSF_FEATURE_LUN_SHARING){
3173 atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
3177 atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
3179 ZFCP_LOG_NORMAL("read-only access for unit "
3180 "(adapter %s, wwpn=0x%016Lx, "
3181 "fcp_lun=0x%016Lx)\n",
3182 zfcp_get_busid_by_unit(unit),
3187 if (exclusive && !readwrite) {
3188 ZFCP_LOG_NORMAL("exclusive access of read-only "
3189 "unit not supported\n");
3190 zfcp_erp_unit_failed(unit);
3191 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3192 zfcp_erp_unit_shutdown(unit, 0);
3193 } else if (!exclusive && readwrite) {
3194 ZFCP_LOG_NORMAL("shared access of read-write "
3195 "unit not supported\n");
3196 zfcp_erp_unit_failed(unit);
3197 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3198 zfcp_erp_unit_shutdown(unit, 0);
3206 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3207 "(debug info 0x%x)\n",
3208 header->fsf_status);
3209 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3210 debug_exception(adapter->erp_dbf, 0,
3211 &header->fsf_status, sizeof (u32));
3216 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3221 * function: zfcp_fsf_close_unit
3225 * returns: address of fsf_req - request successfully initiated
3228 * assumptions: This routine does not check whether the associated
3229 * remote port/lun has already been opened. This should be
3230 * done by calling routines. Otherwise some status
3231 * may be presented by FSF
3234 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3236 volatile struct qdio_buffer_element *sbale;
3237 unsigned long lock_flags;
3240 /* setup new FSF request */
3241 retval = zfcp_fsf_req_create(erp_action->adapter,
3243 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3244 erp_action->adapter->pool.fsf_req_erp,
3245 &lock_flags, &(erp_action->fsf_req));
3247 ZFCP_LOG_INFO("error: Could not create close unit request for "
3248 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3249 erp_action->unit->fcp_lun,
3250 erp_action->port->wwpn,
3251 zfcp_get_busid_by_adapter(erp_action->adapter));
3255 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3256 erp_action->fsf_req->sbal_curr, 0);
3257 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3258 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3260 erp_action->fsf_req->qtcb->header.port_handle =
3261 erp_action->port->handle;
3262 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3263 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3264 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3265 erp_action->fsf_req->erp_action = erp_action;
3267 /* start QDIO request for this FSF request */
3268 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3270 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3271 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3272 erp_action->unit->fcp_lun,
3273 erp_action->port->wwpn,
3274 zfcp_get_busid_by_adapter(erp_action->adapter));
3275 zfcp_fsf_req_free(erp_action->fsf_req);
3276 erp_action->fsf_req = NULL;
3280 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3281 "port 0x%016Lx, unit 0x%016Lx)\n",
3282 zfcp_get_busid_by_adapter(erp_action->adapter),
3283 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3285 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3291 * function: zfcp_fsf_close_unit_handler
3293 * purpose: is called for finished Close LUN FSF command
3298 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3300 int retval = -EINVAL;
3301 struct zfcp_unit *unit;
3303 unit = fsf_req->data.close_unit.unit; /* restore unit */
3305 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3306 /* don't change unit status in our bookkeeping */
3307 goto skip_fsfstatus;
3310 /* evaluate FSF status in QTCB */
3311 switch (fsf_req->qtcb->header.fsf_status) {
3313 case FSF_PORT_HANDLE_NOT_VALID:
3314 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3315 "0x%016Lx on adapter %s invalid. This may "
3316 "happen in rare circumstances\n",
3319 zfcp_get_busid_by_unit(unit));
3320 ZFCP_LOG_DEBUG("status qualifier:\n");
3321 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3322 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3323 sizeof (union fsf_status_qual));
3324 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3326 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3327 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3328 &fsf_req->qtcb->header.fsf_status_qual,
3329 sizeof (union fsf_status_qual));
3330 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3333 case FSF_LUN_HANDLE_NOT_VALID:
3334 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3335 "0x%016Lx on port 0x%016Lx on adapter %s is "
3336 "invalid. This may happen occasionally.\n",
3340 zfcp_get_busid_by_unit(unit));
3341 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3342 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3343 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3344 sizeof (union fsf_status_qual));
3345 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3347 zfcp_erp_port_reopen(unit->port, 0);
3348 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3349 &fsf_req->qtcb->header.fsf_status_qual,
3350 sizeof (union fsf_status_qual));
3351 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3354 case FSF_PORT_BOXED:
3355 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3356 "needs to be reopened\n",
3358 zfcp_get_busid_by_unit(unit));
3359 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3360 zfcp_erp_port_reopen(unit->port, 0);
3361 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3362 ZFCP_STATUS_FSFREQ_RETRY;
3365 case FSF_ADAPTER_STATUS_AVAILABLE:
3366 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3367 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3368 /* re-establish link to port */
3369 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3371 zfcp_erp_port_reopen(unit->port, 0);
3372 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3374 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3375 /* ERP strategy will escalate */
3376 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3378 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3382 ("bug: Wrong status qualifier 0x%x arrived.\n",
3383 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3384 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3387 fsf_req->adapter->erp_dbf, 0,
3388 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3395 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3396 "closed, port handle 0x%x\n",
3399 zfcp_get_busid_by_unit(unit),
3401 /* mark unit as closed */
3402 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3407 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3408 "(debug info 0x%x)\n",
3409 fsf_req->qtcb->header.fsf_status);
3410 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3411 debug_exception(fsf_req->adapter->erp_dbf, 0,
3412 &fsf_req->qtcb->header.fsf_status,
3418 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3423 * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
3424 * @adapter: adapter where scsi command is issued
3425 * @unit: unit where command is sent to
3426 * @scsi_cmnd: scsi command to be sent
3427 * @timer: timer to be started when request is initiated
3428 * @req_flags: flags for fsf_request
3431 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3432 struct zfcp_unit *unit,
3433 struct scsi_cmnd * scsi_cmnd,
3434 struct timer_list *timer, int req_flags)
3436 struct zfcp_fsf_req *fsf_req = NULL;
3437 struct fcp_cmnd_iu *fcp_cmnd_iu;
3438 unsigned int sbtype;
3439 unsigned long lock_flags;
3444 /* setup new FSF request */
3445 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3446 adapter->pool.fsf_req_scsi,
3447 &lock_flags, &fsf_req);
3448 if (unlikely(retval < 0)) {
3449 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3450 "for unit 0x%016Lx on port 0x%016Lx on "
3454 zfcp_get_busid_by_adapter(adapter));
3455 goto failed_req_create;
3459 * associate FSF request with SCSI request
3460 * (need this for look up on abort)
3462 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3463 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3466 * associate SCSI command with FSF request
3467 * (need this for look up on normal command completion)
3469 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3470 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3471 fsf_req->data.send_fcp_command_task.unit = unit;
3472 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3474 /* set handles of unit and its parent port in QTCB */
3475 fsf_req->qtcb->header.lun_handle = unit->handle;
3476 fsf_req->qtcb->header.port_handle = unit->port->handle;
3478 /* FSF does not define the structure of the FCP_CMND IU */
3479 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3480 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3483 * set depending on data direction:
3484 * data direction bits in SBALE (SB Type)
3485 * data direction bits in QTCB
3486 * data direction bits in FCP_CMND IU
3488 switch (scsi_cmnd->sc_data_direction) {
3490 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3493 * what is the correct type for commands
3494 * without 'real' data buffers?
3496 sbtype = SBAL_FLAGS0_TYPE_READ;
3498 case DMA_FROM_DEVICE:
3499 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3500 sbtype = SBAL_FLAGS0_TYPE_READ;
3501 fcp_cmnd_iu->rddata = 1;
3504 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3505 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3506 fcp_cmnd_iu->wddata = 1;
3508 case DMA_BIDIRECTIONAL:
3511 * dummy, catch this condition earlier
3512 * in zfcp_scsi_queuecommand
3514 goto failed_scsi_cmnd;
3517 /* set FC service class in QTCB (3 per default) */
3518 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3520 /* set FCP_LUN in FCP_CMND IU in QTCB */
3521 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3523 mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
3525 /* set task attributes in FCP_CMND IU in QTCB */
3526 if (likely((scsi_cmnd->device->simple_tags) ||
3527 (atomic_test_mask(mask, &unit->status))))
3528 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3530 fcp_cmnd_iu->task_attribute = UNTAGGED;
3532 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3533 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3534 fcp_cmnd_iu->add_fcp_cdb_length
3535 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3536 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3537 "additional FCP_CDB length is 0x%x "
3538 "(shifted right 2 bits)\n",
3540 fcp_cmnd_iu->add_fcp_cdb_length);
3543 * copy SCSI CDB (including additional length, if any) to
3544 * FCP_CDB in FCP_CMND IU in QTCB
3546 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3548 /* FCP CMND IU length in QTCB */
3549 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3550 sizeof (struct fcp_cmnd_iu) +
3551 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3553 /* generate SBALEs from data buffer */
3554 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3555 if (unlikely(real_bytes < 0)) {
3556 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3558 "Data did not fit into available buffer(s), "
3559 "waiting for more...\n");
3562 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3563 "required. Shutting down unit "
3564 "(adapter %s, port 0x%016Lx, "
3566 zfcp_get_busid_by_unit(unit),
3569 zfcp_erp_unit_shutdown(unit, 0);
3575 /* set length of FCP data length in FCP_CMND IU in QTCB */
3576 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3578 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3579 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3580 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3583 * start QDIO request for this FSF request
3584 * covered by an SBALE)
3586 retval = zfcp_fsf_req_send(fsf_req, timer);
3587 if (unlikely(retval < 0)) {
3588 ZFCP_LOG_INFO("error: Could not send FCP command request "
3589 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3590 zfcp_get_busid_by_adapter(adapter),
3596 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3597 "port 0x%016Lx, unit 0x%016Lx)\n",
3598 zfcp_get_busid_by_adapter(adapter),
3606 zfcp_fsf_req_free(fsf_req);
3608 scsi_cmnd->host_scribble = NULL;
3611 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3616 * function: zfcp_fsf_send_fcp_command_task_management
3622 * FIXME(design): should be watched by a timeout!!!
3623 * FIXME(design) shouldn't this be modified to return an int
3624 * also...don't know how though
3627 struct zfcp_fsf_req *
3628 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3629 struct zfcp_unit *unit,
3630 u8 tm_flags, int req_flags)
3632 struct zfcp_fsf_req *fsf_req = NULL;
3634 struct fcp_cmnd_iu *fcp_cmnd_iu;
3635 unsigned long lock_flags;
3636 volatile struct qdio_buffer_element *sbale;
3638 /* setup new FSF request */
3639 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3640 adapter->pool.fsf_req_scsi,
3641 &lock_flags, &fsf_req);
3643 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3644 "management) request for adapter %s, port "
3645 " 0x%016Lx, unit 0x%016Lx.\n",
3646 zfcp_get_busid_by_adapter(adapter),
3647 unit->port->wwpn, unit->fcp_lun);
3652 * Used to decide on proper handler in the return path,
3653 * could be either zfcp_fsf_send_fcp_command_task_handler or
3654 * zfcp_fsf_send_fcp_command_task_management_handler */
3656 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3659 * hold a pointer to the unit being target of this
3660 * task management request
3662 fsf_req->data.send_fcp_command_task_management.unit = unit;
3664 /* set FSF related fields in QTCB */
3665 fsf_req->qtcb->header.lun_handle = unit->handle;
3666 fsf_req->qtcb->header.port_handle = unit->port->handle;
3667 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3668 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3669 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3670 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3672 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3673 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3674 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3676 /* set FCP related fields in FCP_CMND IU in QTCB */
3677 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3678 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3679 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3680 fcp_cmnd_iu->task_management_flags = tm_flags;
3682 /* start QDIO request for this FSF request */
3683 zfcp_fsf_start_scsi_er_timer(adapter);
3684 retval = zfcp_fsf_req_send(fsf_req, NULL);
3686 del_timer(&adapter->scsi_er_timer);
3687 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3688 "management) on adapter %s, port 0x%016Lx for "
3689 "unit LUN 0x%016Lx\n",
3690 zfcp_get_busid_by_adapter(adapter),
3693 zfcp_fsf_req_free(fsf_req);
3698 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3699 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3701 zfcp_get_busid_by_adapter(adapter),
3706 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3711 * function: zfcp_fsf_send_fcp_command_handler
3713 * purpose: is called for finished Send FCP Command
3718 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3720 int retval = -EINVAL;
3721 struct zfcp_unit *unit;
3722 struct fsf_qtcb_header *header;
3723 u16 subtable, rule, counter;
3725 header = &fsf_req->qtcb->header;
3727 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3728 unit = fsf_req->data.send_fcp_command_task_management.unit;
3730 unit = fsf_req->data.send_fcp_command_task.unit;
3732 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3733 /* go directly to calls of special handlers */
3734 goto skip_fsfstatus;
3737 /* evaluate FSF status in QTCB */
3738 switch (header->fsf_status) {
3740 case FSF_PORT_HANDLE_NOT_VALID:
3741 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3742 "0x%016Lx on adapter %s invalid\n",
3744 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3745 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3746 (char *) &header->fsf_status_qual,
3747 sizeof (union fsf_status_qual));
3748 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3750 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3751 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3754 case FSF_LUN_HANDLE_NOT_VALID:
3755 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3756 "0x%016Lx on port 0x%016Lx on adapter %s is "
3757 "invalid. This may happen occasionally.\n",
3761 zfcp_get_busid_by_unit(unit));
3762 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3763 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3764 (char *) &header->fsf_status_qual,
3765 sizeof (union fsf_status_qual));
3766 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3768 zfcp_erp_port_reopen(unit->port, 0);
3769 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3772 case FSF_HANDLE_MISMATCH:
3773 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3774 "unexpectedly. (adapter %s, port 0x%016Lx, "
3777 zfcp_get_busid_by_unit(unit),
3780 ZFCP_LOG_NORMAL("status qualifier:\n");
3781 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3782 (char *) &header->fsf_status_qual,
3783 sizeof (union fsf_status_qual));
3784 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3786 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3787 zfcp_cmd_dbf_event_fsf("handmism",
3789 &header->fsf_status_qual,
3790 sizeof (union fsf_status_qual));
3791 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3794 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3795 if (fsf_req->adapter->fc_service_class <= 3) {
3796 ZFCP_LOG_NORMAL("error: The adapter %s does "
3797 "not support fibrechannel class %d.\n",
3798 zfcp_get_busid_by_unit(unit),
3799 fsf_req->adapter->fc_service_class);
3801 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3802 "adapter %s is invalid. "
3803 "(debug info %d)\n",
3804 zfcp_get_busid_by_unit(unit),
3805 fsf_req->adapter->fc_service_class);
3807 /* stop operation for this adapter */
3808 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3809 "fsf_s_class_nsup");
3810 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3811 zfcp_cmd_dbf_event_fsf("unsclass",
3813 &header->fsf_status_qual,
3814 sizeof (union fsf_status_qual));
3815 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3818 case FSF_FCPLUN_NOT_VALID:
3819 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3820 "adapter %s does not have correct unit "
3824 zfcp_get_busid_by_unit(unit),
3826 ZFCP_LOG_DEBUG("status qualifier:\n");
3827 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3828 (char *) &header->fsf_status_qual,
3829 sizeof (union fsf_status_qual));
3830 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3831 "fsf_s_fcp_lun_nv");
3832 zfcp_erp_port_reopen(unit->port, 0);
3833 zfcp_cmd_dbf_event_fsf("fluninv",
3835 &header->fsf_status_qual,
3836 sizeof (union fsf_status_qual));
3837 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3840 case FSF_ACCESS_DENIED:
3841 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3842 "unit 0x%016Lx on port 0x%016Lx on "
3843 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3844 zfcp_get_busid_by_unit(unit));
3845 for (counter = 0; counter < 2; counter++) {
3846 subtable = header->fsf_status_qual.halfword[counter * 2];
3847 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3849 case FSF_SQ_CFDC_SUBTABLE_OS:
3850 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3851 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3852 case FSF_SQ_CFDC_SUBTABLE_LUN:
3853 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3854 zfcp_act_subtable_type[subtable], rule);
3858 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3859 zfcp_erp_unit_access_denied(unit);
3860 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3863 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3864 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3865 "0x%016Lx on port 0x%016Lx on adapter %s "
3866 "(debug info %d)\n",
3869 zfcp_get_busid_by_unit(unit),
3870 fsf_req->qtcb->bottom.io.data_direction);
3871 /* stop operation for this adapter */
3872 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3873 "fsf_s_dir_ind_nv");
3874 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3875 zfcp_cmd_dbf_event_fsf("dirinv",
3877 &header->fsf_status_qual,
3878 sizeof (union fsf_status_qual));
3879 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3882 case FSF_CMND_LENGTH_NOT_VALID:
3884 ("bug: An invalid control-data-block length field "
3885 "was found in a command for unit 0x%016Lx on port "
3886 "0x%016Lx on adapter %s " "(debug info %d)\n",
3887 unit->fcp_lun, unit->port->wwpn,
3888 zfcp_get_busid_by_unit(unit),
3889 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3890 /* stop operation for this adapter */
3891 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3892 "fsf_s_cmd_len_nv");
3893 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3894 zfcp_cmd_dbf_event_fsf("cleninv",
3896 &header->fsf_status_qual,
3897 sizeof (union fsf_status_qual));
3898 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3901 case FSF_PORT_BOXED:
3902 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3903 "needs to be reopened\n",
3904 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3905 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3906 zfcp_erp_port_reopen(unit->port, 0);
3907 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3908 &header->fsf_status_qual,
3909 sizeof (union fsf_status_qual));
3910 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3911 ZFCP_STATUS_FSFREQ_RETRY;
3915 ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
3916 "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
3917 zfcp_get_busid_by_unit(unit),
3918 unit->port->wwpn, unit->fcp_lun);
3919 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3920 zfcp_erp_unit_reopen(unit, 0);
3921 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3922 &header->fsf_status_qual,
3923 sizeof(union fsf_status_qual));
3924 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3925 | ZFCP_STATUS_FSFREQ_RETRY;
3928 case FSF_ADAPTER_STATUS_AVAILABLE:
3929 switch (header->fsf_status_qual.word[0]) {
3930 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3931 /* re-establish link to port */
3932 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3934 zfcp_erp_port_reopen(unit->port, 0);
3935 zfcp_cmd_dbf_event_fsf(
3938 &header->fsf_status_qual,
3939 sizeof (union fsf_status_qual));
3940 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3942 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3943 /* FIXME(hw) need proper specs for proper action */
3944 /* let scsi stack deal with retries and escalation */
3945 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3947 zfcp_cmd_dbf_event_fsf(
3950 &header->fsf_status_qual,
3951 sizeof (union fsf_status_qual));
3952 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3955 /* FIXME: shall we consider this a successful transfer? */
3957 ("bug: Wrong status qualifier 0x%x arrived.\n",
3958 header->fsf_status_qual.word[0]);
3959 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3961 debug_exception(fsf_req->adapter->erp_dbf, 0,
3962 &header->fsf_status_qual.word[0],
3971 case FSF_FCP_RSP_AVAILABLE:
3975 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3976 debug_exception(fsf_req->adapter->erp_dbf, 0,
3977 &header->fsf_status, sizeof(u32));
3982 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3984 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3986 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3992 * function: zfcp_fsf_send_fcp_command_task_handler
3994 * purpose: evaluates FCP_RSP IU
3999 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
4002 struct scsi_cmnd *scpnt;
4003 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4004 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4005 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
4006 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
4008 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4009 unsigned long flags;
4010 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
4012 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
4013 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
4014 if (unlikely(!scpnt)) {
4016 ("Command with fsf_req %p is not associated to "
4017 "a scsi command anymore. Aborted?\n", fsf_req);
4020 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
4021 /* FIXME: (design) mid-layer should handle DID_ABORT like
4022 * DID_SOFT_ERROR by retrying the request for devices
4023 * that allow retries.
4025 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
4026 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
4027 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
4028 goto skip_fsfstatus;
4031 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
4032 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
4033 set_host_byte(&scpnt->result, DID_ERROR);
4034 goto skip_fsfstatus;
4037 /* set message byte of result in SCSI command */
4038 scpnt->result |= COMMAND_COMPLETE << 8;
4041 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
4042 * of result in SCSI command
4044 scpnt->result |= fcp_rsp_iu->scsi_status;
4045 if (unlikely(fcp_rsp_iu->scsi_status)) {
4047 ZFCP_LOG_DEBUG("status for SCSI Command:\n");
4048 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4049 scpnt->cmnd, scpnt->cmd_len);
4050 ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
4051 fcp_rsp_iu->scsi_status);
4052 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4053 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4054 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4055 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4056 fcp_rsp_iu->fcp_sns_len);
4059 /* check FCP_RSP_INFO */
4060 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4061 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4062 switch (fcp_rsp_info[3]) {
4065 ZFCP_LOG_TRACE("no failure or Task Management "
4066 "Function complete\n");
4067 set_host_byte(&scpnt->result, DID_OK);
4069 case RSP_CODE_LENGTH_MISMATCH:
4071 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4072 "that the fibrechannel protocol data "
4073 "length differs from the burst length. "
4074 "The problem occured on unit 0x%016Lx "
4075 "on port 0x%016Lx on adapter %s",
4078 zfcp_get_busid_by_unit(unit));
4079 /* dump SCSI CDB as prepared by zfcp */
4080 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4081 (char *) &fsf_req->qtcb->
4082 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4083 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4084 set_host_byte(&scpnt->result, DID_ERROR);
4085 goto skip_fsfstatus;
4086 case RSP_CODE_FIELD_INVALID:
4087 /* driver or hardware bug */
4088 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4089 "that the fibrechannel protocol data "
4090 "fields were incorrectly set up. "
4091 "The problem occured on the unit "
4092 "0x%016Lx on port 0x%016Lx on "
4096 zfcp_get_busid_by_unit(unit));
4097 /* dump SCSI CDB as prepared by zfcp */
4098 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4099 (char *) &fsf_req->qtcb->
4100 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4101 set_host_byte(&scpnt->result, DID_ERROR);
4102 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4103 goto skip_fsfstatus;
4104 case RSP_CODE_RO_MISMATCH:
4106 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4107 "that conflicting values for the "
4108 "fibrechannel payload offset from the "
4109 "header were found. "
4110 "The problem occured on unit 0x%016Lx "
4111 "on port 0x%016Lx on adapter %s.\n",
4114 zfcp_get_busid_by_unit(unit));
4115 /* dump SCSI CDB as prepared by zfcp */
4116 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4117 (char *) &fsf_req->qtcb->
4118 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4119 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4120 set_host_byte(&scpnt->result, DID_ERROR);
4121 goto skip_fsfstatus;
4123 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4124 "code was detected for a command. "
4125 "The problem occured on the unit "
4126 "0x%016Lx on port 0x%016Lx on "
4127 "adapter %s (debug info 0x%x)\n",
4130 zfcp_get_busid_by_unit(unit),
4132 /* dump SCSI CDB as prepared by zfcp */
4133 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4134 (char *) &fsf_req->qtcb->
4135 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4136 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4137 set_host_byte(&scpnt->result, DID_ERROR);
4138 goto skip_fsfstatus;
4142 /* check for sense data */
4143 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4144 sns_len = FSF_FCP_RSP_SIZE -
4145 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4146 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4148 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4149 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4150 SCSI_SENSE_BUFFERSIZE);
4151 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4152 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4154 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4155 (void *) &scpnt->cmnd, scpnt->cmd_len);
4157 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4158 fcp_rsp_iu->fcp_sns_len);
4159 memcpy(&scpnt->sense_buffer,
4160 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4161 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4162 (void *) &scpnt->sense_buffer, sns_len);
4165 /* check for overrun */
4166 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4167 ZFCP_LOG_INFO("A data overrun 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));
4178 /* check for underrun */
4179 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4180 ZFCP_LOG_INFO("A data underrun was detected for a command. "
4181 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4182 "The response data length is "
4183 "%d, the original length was %d.\n",
4186 zfcp_get_busid_by_unit(unit),
4187 fcp_rsp_iu->fcp_resid,
4188 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4190 scpnt->resid = fcp_rsp_iu->fcp_resid;
4191 if (scpnt->request_bufflen - scpnt->resid < scpnt->underflow)
4192 set_host_byte(&scpnt->result, DID_ERROR);
4196 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4198 zfcp_cmd_dbf_event_scsi("response", scpnt);
4200 /* cleanup pointer (need this especially for abort) */
4201 scpnt->host_scribble = NULL;
4205 * according to the outcome of a discussion on linux-scsi we
4206 * don't need to grab the io_request_lock here since we use
4209 /* always call back */
4211 (scpnt->scsi_done) (scpnt);
4214 * We must hold this lock until scsi_done has been called.
4215 * Otherwise we may call scsi_done after abort regarding this
4216 * command has completed.
4217 * Note: scsi_done must not block!
4220 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4225 * function: zfcp_fsf_send_fcp_command_task_management_handler
4227 * purpose: evaluates FCP_RSP IU
4232 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4235 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4236 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4237 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4238 struct zfcp_unit *unit =
4239 fsf_req->data.send_fcp_command_task_management.unit;
4241 del_timer(&fsf_req->adapter->scsi_er_timer);
4242 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4243 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4244 goto skip_fsfstatus;
4247 /* check FCP_RSP_INFO */
4248 switch (fcp_rsp_info[3]) {
4251 ZFCP_LOG_DEBUG("no failure or Task Management "
4252 "Function complete\n");
4254 case RSP_CODE_TASKMAN_UNSUPP:
4255 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4256 "is not supported on the target device "
4257 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4260 zfcp_get_busid_by_unit(unit));
4261 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4263 case RSP_CODE_TASKMAN_FAILED:
4264 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4265 "failed to complete successfully. "
4266 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4269 zfcp_get_busid_by_unit(unit));
4270 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4273 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4274 "code was detected for a command. "
4275 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4276 "(debug info 0x%x)\n",
4279 zfcp_get_busid_by_unit(unit),
4281 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4290 * function: zfcp_fsf_control_file
4292 * purpose: Initiator of the control file upload/download FSF requests
4294 * returns: 0 - FSF request is successfuly created and queued
4295 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4296 * -EINVAL - Invalid direction specified
4297 * -ENOMEM - Insufficient memory
4298 * -EPERM - Cannot create FSF request or place it in QDIO queue
4301 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4302 struct zfcp_fsf_req **fsf_req_ptr,
4305 struct zfcp_sg_list *sg_list)
4307 struct zfcp_fsf_req *fsf_req;
4308 struct fsf_qtcb_bottom_support *bottom;
4309 volatile struct qdio_buffer_element *sbale;
4310 struct timer_list *timer;
4311 unsigned long lock_flags;
4316 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4317 ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
4318 zfcp_get_busid_by_adapter(adapter));
4319 retval = -EOPNOTSUPP;
4323 switch (fsf_command) {
4325 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4326 direction = SBAL_FLAGS0_TYPE_WRITE;
4327 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4328 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4329 req_flags = ZFCP_WAIT_FOR_SBAL;
4332 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4333 direction = SBAL_FLAGS0_TYPE_READ;
4337 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4342 timer = kmalloc(sizeof(struct timer_list), GFP_KERNEL);
4348 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4349 NULL, &lock_flags, &fsf_req);
4351 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4353 zfcp_get_busid_by_adapter(adapter));
4355 goto unlock_queue_lock;
4358 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4359 sbale[0].flags |= direction;
4361 bottom = &fsf_req->qtcb->bottom.support;
4362 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4363 bottom->option = option;
4365 if (sg_list->count > 0) {
4368 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4369 sg_list->sg, sg_list->count,
4370 ZFCP_MAX_SBALS_PER_REQ);
4371 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4373 "error: Could not create sufficient number of "
4374 "SBALS for an FSF request to the adapter %s\n",
4375 zfcp_get_busid_by_adapter(adapter));
4380 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4383 timer->function = zfcp_fsf_request_timeout_handler;
4384 timer->data = (unsigned long) adapter;
4385 timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
4387 retval = zfcp_fsf_req_send(fsf_req, timer);
4389 ZFCP_LOG_INFO("initiation of cfdc up/download failed"
4391 zfcp_get_busid_by_adapter(adapter));
4395 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4397 ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
4399 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4400 "download" : "upload",
4401 zfcp_get_busid_by_adapter(adapter));
4403 wait_event(fsf_req->completion_wq,
4404 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4406 *fsf_req_ptr = fsf_req;
4407 del_timer_sync(timer);
4411 zfcp_fsf_req_free(fsf_req);
4413 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4422 * function: zfcp_fsf_control_file_handler
4424 * purpose: Handler of the control file upload/download FSF requests
4426 * returns: 0 - FSF request successfuly processed
4427 * -EAGAIN - Operation has to be repeated because of a temporary problem
4428 * -EACCES - There is no permission to execute an operation
4429 * -EPERM - The control file is not in a right format
4430 * -EIO - There is a problem with the FCP adapter
4431 * -EINVAL - Invalid operation
4432 * -EFAULT - User space memory I/O operation fault
4435 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4437 struct zfcp_adapter *adapter = fsf_req->adapter;
4438 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4439 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4442 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4444 goto skip_fsfstatus;
4447 switch (header->fsf_status) {
4451 "The FSF request has been successfully completed "
4452 "on the adapter %s\n",
4453 zfcp_get_busid_by_adapter(adapter));
4456 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4457 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4458 switch (header->fsf_status_qual.word[0]) {
4460 case FSF_SQ_CFDC_HARDENED_ON_SE:
4462 "CFDC on the adapter %s has being "
4463 "hardened on primary and secondary SE\n",
4464 zfcp_get_busid_by_adapter(adapter));
4467 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4469 "CFDC of the adapter %s could not "
4470 "be saved on the SE\n",
4471 zfcp_get_busid_by_adapter(adapter));
4474 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4476 "CFDC of the adapter %s could not "
4477 "be copied to the secondary SE\n",
4478 zfcp_get_busid_by_adapter(adapter));
4483 "CFDC could not be hardened "
4484 "on the adapter %s\n",
4485 zfcp_get_busid_by_adapter(adapter));
4488 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4492 case FSF_AUTHORIZATION_FAILURE:
4494 "Adapter %s does not accept privileged commands\n",
4495 zfcp_get_busid_by_adapter(adapter));
4496 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4500 case FSF_CFDC_ERROR_DETECTED:
4502 "Error at position %d in the CFDC, "
4503 "CFDC is discarded by the adapter %s\n",
4504 header->fsf_status_qual.word[0],
4505 zfcp_get_busid_by_adapter(adapter));
4506 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4510 case FSF_CONTROL_FILE_UPDATE_ERROR:
4512 "Adapter %s cannot harden the control file, "
4513 "file is discarded\n",
4514 zfcp_get_busid_by_adapter(adapter));
4515 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4519 case FSF_CONTROL_FILE_TOO_LARGE:
4521 "Control file is too large, file is discarded "
4522 "by the adapter %s\n",
4523 zfcp_get_busid_by_adapter(adapter));
4524 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4528 case FSF_ACCESS_CONFLICT_DETECTED:
4529 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4531 "CFDC has been discarded by the adapter %s, "
4532 "because activation would impact "
4533 "%d active connection(s)\n",
4534 zfcp_get_busid_by_adapter(adapter),
4535 header->fsf_status_qual.word[0]);
4536 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4540 case FSF_CONFLICTS_OVERRULED:
4541 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4543 "CFDC has been activated on the adapter %s, "
4544 "but activation has impacted "
4545 "%d active connection(s)\n",
4546 zfcp_get_busid_by_adapter(adapter),
4547 header->fsf_status_qual.word[0]);
4548 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4552 case FSF_UNKNOWN_OP_SUBTYPE:
4553 ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
4554 "op_subtype=0x%x)\n",
4555 zfcp_get_busid_by_adapter(adapter),
4556 bottom->operation_subtype);
4557 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4561 case FSF_INVALID_COMMAND_OPTION:
4563 "Invalid option 0x%x has been specified "
4564 "in QTCB bottom sent to the adapter %s\n",
4566 zfcp_get_busid_by_adapter(adapter));
4567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4573 "bug: An unknown/unexpected FSF status 0x%08x "
4574 "was presented on the adapter %s\n",
4576 zfcp_get_busid_by_adapter(adapter));
4577 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4578 debug_exception(fsf_req->adapter->erp_dbf, 0,
4579 &header->fsf_status_qual.word[0], sizeof(u32));
4580 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4591 * function: zfcp_fsf_req_wait_and_cleanup
4595 * FIXME(design): signal seems to be <0 !!!
4596 * returns: 0 - request completed (*status is valid), cleanup succ.
4597 * <0 - request completed (*status is valid), cleanup failed
4598 * >0 - signal which interrupted waiting (*status invalid),
4599 * request not completed, no cleanup
4601 * *status is a copy of status of completed fsf_req
4604 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4605 int interruptible, u32 * status)
4610 if (interruptible) {
4611 __wait_event_interruptible(fsf_req->completion_wq,
4613 ZFCP_STATUS_FSFREQ_COMPLETED,
4616 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4617 "completion of the request at %p\n",
4623 __wait_event(fsf_req->completion_wq,
4624 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4627 *status = fsf_req->status;
4629 /* cleanup request */
4630 zfcp_fsf_req_cleanup(fsf_req);
4636 zfcp_fsf_req_sbal_check(unsigned long *flags,
4637 struct zfcp_qdio_queue *queue, int needed)
4639 write_lock_irqsave(&queue->queue_lock, *flags);
4640 if (likely(atomic_read(&queue->free_count) >= needed))
4642 write_unlock_irqrestore(&queue->queue_lock, *flags);
4647 * set qtcb pointer in fsf_req and initialize QTCB
4650 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4652 if (likely(fsf_req->qtcb != NULL)) {
4653 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4654 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4655 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4656 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4657 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4658 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4663 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4664 * @adapter: adapter for which request queue is examined
4665 * @req_flags: flags indicating whether to wait for needed SBAL or not
4666 * @lock_flags: lock_flags if queue_lock is taken
4667 * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
4668 * Locks: lock adapter->request_queue->queue_lock on success
4671 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4672 unsigned long *lock_flags)
4675 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4677 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4678 ret = wait_event_interruptible_timeout(adapter->request_wq,
4679 zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
4685 } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
4692 * function: zfcp_fsf_req_create
4694 * purpose: create an FSF request at the specified adapter and
4695 * setup common fields
4697 * returns: -ENOMEM if there was insufficient memory for a request
4698 * -EIO if no qdio buffers could be allocate to the request
4699 * -EINVAL/-EPERM on bug conditions in req_dequeue
4702 * note: The created request is returned by reference.
4704 * locks: lock of concerned request queue must not be held,
4705 * but is held on completion (write, irqsave)
4708 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4709 mempool_t *pool, unsigned long *lock_flags,
4710 struct zfcp_fsf_req **fsf_req_p)
4712 volatile struct qdio_buffer_element *sbale;
4713 struct zfcp_fsf_req *fsf_req = NULL;
4715 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4717 /* allocate new FSF request */
4718 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4719 if (unlikely(NULL == fsf_req)) {
4720 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4721 "the outbound (send) queue.\n");
4723 goto failed_fsf_req;
4726 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4728 /* initialize waitqueue which may be used to wait on
4729 this request completion */
4730 init_waitqueue_head(&fsf_req->completion_wq);
4732 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4738 * We hold queue_lock here. Check if QDIOUP is set and let request fail
4739 * if it is not set (see also *_open_qdio and *_close_qdio).
4742 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
4743 write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
4748 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4749 fsf_req->fsf_command = fsf_cmd;
4750 fsf_req->sbal_number = 1;
4751 fsf_req->sbal_first = req_queue->free_index;
4752 fsf_req->sbal_curr = req_queue->free_index;
4753 fsf_req->sbale_curr = 1;
4755 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4756 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4759 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4761 /* setup common SBALE fields */
4762 sbale[0].addr = fsf_req;
4763 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4764 if (likely(fsf_req->qtcb != NULL)) {
4765 sbale[1].addr = (void *) fsf_req->qtcb;
4766 sbale[1].length = sizeof(struct fsf_qtcb);
4769 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4770 fsf_req->sbal_number, fsf_req->sbal_first);
4775 /* dequeue new FSF request previously enqueued */
4776 zfcp_fsf_req_free(fsf_req);
4780 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4782 *fsf_req_p = fsf_req;
4787 * function: zfcp_fsf_req_send
4789 * purpose: start transfer of FSF request via QDIO
4791 * returns: 0 - request transfer succesfully started
4792 * !0 - start of request transfer failed
4795 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4797 struct zfcp_adapter *adapter;
4798 struct zfcp_qdio_queue *req_queue;
4799 volatile struct qdio_buffer_element *sbale;
4800 int new_distance_from_int;
4801 unsigned long flags;
4805 adapter = fsf_req->adapter;
4806 req_queue = &adapter->request_queue,
4809 /* FIXME(debug): remove it later */
4810 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4811 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4812 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4813 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4816 /* set sequence counter in QTCB */
4817 if (likely(fsf_req->qtcb)) {
4818 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4819 fsf_req->seq_no = adapter->fsf_req_seq_no;
4820 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4821 "FSF sequence counter value of %i\n",
4823 zfcp_get_busid_by_adapter(adapter),
4824 fsf_req->qtcb->prefix.req_seq_no);
4828 /* put allocated FSF request at list tail */
4829 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4830 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4831 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4833 /* figure out expiration time of timeout and start timeout */
4834 if (unlikely(timer)) {
4835 timer->expires += jiffies;
4839 ZFCP_LOG_TRACE("request queue of adapter %s: "
4840 "next free SBAL is %i, %i free SBALs\n",
4841 zfcp_get_busid_by_adapter(adapter),
4842 req_queue->free_index,
4843 atomic_read(&req_queue->free_count));
4845 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4846 "index_in_queue=%i, count=%i, buffers=%p\n",
4847 zfcp_get_busid_by_adapter(adapter),
4848 QDIO_FLAG_SYNC_OUTPUT,
4849 0, fsf_req->sbal_first, fsf_req->sbal_number,
4850 &req_queue->buffer[fsf_req->sbal_first]);
4853 * adjust the number of free SBALs in request queue as well as
4854 * position of first one
4856 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4857 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4858 req_queue->free_index += fsf_req->sbal_number; /* increase */
4859 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4860 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4862 retval = do_QDIO(adapter->ccw_device,
4863 QDIO_FLAG_SYNC_OUTPUT,
4864 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4866 if (unlikely(retval)) {
4867 /* Queues are down..... */
4870 * FIXME(potential race):
4871 * timer might be expired (absolutely unlikely)
4875 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4876 list_del(&fsf_req->list);
4877 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4879 * adjust the number of free SBALs in request queue as well as
4880 * position of first one
4882 zfcp_qdio_zero_sbals(req_queue->buffer,
4883 fsf_req->sbal_first, fsf_req->sbal_number);
4884 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4885 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4886 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4887 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4889 ("error: do_QDIO failed. Buffers could not be enqueued "
4890 "to request queue.\n");
4892 req_queue->distance_from_int = new_distance_from_int;
4894 * increase FSF sequence counter -
4895 * this must only be done for request successfully enqueued to
4896 * QDIO this rejected requests may be cleaned up by calling
4897 * routines resulting in missing sequence counter values
4900 /* Don't increase for unsolicited status */
4901 if (likely(inc_seq_no)) {
4902 adapter->fsf_req_seq_no++;
4904 ("FSF sequence counter value of adapter %s "
4905 "increased to %i\n",
4906 zfcp_get_busid_by_adapter(adapter),
4907 adapter->fsf_req_seq_no);
4909 /* count FSF requests pending */
4910 atomic_inc(&adapter->fsf_reqs_active);
4916 * function: zfcp_fsf_req_cleanup
4918 * purpose: cleans up an FSF request and removes it from the specified list
4922 * assumption: no pending SB in SBALEs other than QTCB
4925 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4927 struct zfcp_adapter *adapter = fsf_req->adapter;
4928 unsigned long flags;
4930 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4931 list_del(&fsf_req->list);
4932 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4933 zfcp_fsf_req_free(fsf_req);
4936 #undef ZFCP_LOG_AREA