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>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /* this drivers version (do not edit !!! generated and updated by cvs) */
32 #define ZFCP_FSF_C_REVISION "$Revision: 1.47 $"
36 static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
37 static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
38 static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
39 static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
40 static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
41 static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
42 static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
43 static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
44 static int zfcp_fsf_send_fcp_command_task_management_handler(
45 struct zfcp_fsf_req *);
46 static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
47 static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
48 static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
49 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
50 static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
51 static inline int zfcp_fsf_req_create_sbal_check(
52 unsigned long *, struct zfcp_qdio_queue *, int);
53 static inline int zfcp_use_one_sbal(
54 struct scatterlist *, int, struct scatterlist *, int);
55 static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
56 static int zfcp_fsf_req_send(struct zfcp_fsf_req *, struct timer_list *);
57 static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
58 static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
59 static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
60 static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
61 static void zfcp_fsf_req_dismiss(struct zfcp_fsf_req *);
62 static void zfcp_fsf_req_free(struct zfcp_fsf_req *);
64 /* association between FSF command and FSF QTCB type */
65 static u32 fsf_qtcb_type[] = {
66 [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
67 [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
68 [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
69 [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
70 [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
71 [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
72 [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
73 [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
74 [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
75 [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
76 [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
77 [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
78 [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
81 static const char zfcp_act_subtable_type[5][8] = {
82 {"unknown"}, {"OS"}, {"WWPN"}, {"DID"}, {"LUN"}
86 /****************************************************************/
87 /*************** FSF related Functions *************************/
88 /****************************************************************/
90 #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
93 * function: zfcp_fsf_req_alloc
95 * purpose: Obtains an fsf_req and potentially a qtcb (for all but
96 * unsolicited requests) via helper functions
97 * Does some initial fsf request set-up.
99 * returns: pointer to allocated fsf_req if successfull
105 static struct zfcp_fsf_req *
106 zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
110 struct zfcp_fsf_req *fsf_req = NULL;
112 if (req_flags & ZFCP_REQ_NO_QTCB)
113 size = sizeof(struct zfcp_fsf_req);
115 size = sizeof(struct zfcp_fsf_req_pool_element);
117 if (likely(pool != NULL))
118 ptr = mempool_alloc(pool, GFP_ATOMIC);
120 ptr = kmalloc(size, GFP_ATOMIC);
122 if (unlikely(NULL == ptr))
125 memset(ptr, 0, size);
127 if (req_flags & ZFCP_REQ_NO_QTCB) {
128 fsf_req = (struct zfcp_fsf_req *) ptr;
130 fsf_req = &((struct zfcp_fsf_req_pool_element *) ptr)->fsf_req;
132 &((struct zfcp_fsf_req_pool_element *) ptr)->qtcb;
135 fsf_req->pool = pool;
142 * function: zfcp_fsf_req_free
144 * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
145 * returns it into the pool via helper functions.
152 zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
154 if (likely(fsf_req->pool != NULL))
155 mempool_free(fsf_req, fsf_req->pool);
167 * note: qdio queues shall be down (no ongoing inbound processing)
170 zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
173 struct zfcp_fsf_req *fsf_req, *tmp;
175 list_for_each_entry_safe(fsf_req, tmp, &adapter->fsf_req_list_head,
177 zfcp_fsf_req_dismiss(fsf_req);
178 /* wait_event_timeout? */
179 while (!list_empty(&adapter->fsf_req_list_head)) {
180 ZFCP_LOG_DEBUG("fsf req list of adapter %s not yet empty\n",
181 zfcp_get_busid_by_adapter(adapter));
182 /* wait for woken intiators to clean up their requests */
183 set_current_state(TASK_UNINTERRUPTIBLE);
184 schedule_timeout(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 ZFCP_LOG_TRACE("FSF_PROT_GOOD\n");
352 case FSF_PROT_FSF_STATUS_PRESENTED:
353 ZFCP_LOG_TRACE("FSF_PROT_FSF_STATUS_PRESENTED\n");
356 case FSF_PROT_QTCB_VERSION_ERROR:
357 ZFCP_LOG_FLAGS(0, "FSF_PROT_QTCB_VERSION_ERROR\n");
358 ZFCP_LOG_NORMAL("error: The adapter %s contains "
359 "microcode of version 0x%x, the device driver "
360 "only supports 0x%x. Aborting.\n",
361 zfcp_get_busid_by_adapter(adapter),
362 fsf_req->qtcb->prefix.prot_status_qual.
363 version_error.fsf_version, ZFCP_QTCB_VERSION);
364 /* stop operation for this adapter */
365 debug_text_exception(adapter->erp_dbf, 0, "prot_ver_err");
366 zfcp_erp_adapter_shutdown(adapter, 0);
367 zfcp_cmd_dbf_event_fsf("qverserr", fsf_req,
368 &fsf_req->qtcb->prefix.prot_status_qual,
369 sizeof (union fsf_prot_status_qual));
370 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
373 case FSF_PROT_SEQ_NUMB_ERROR:
374 ZFCP_LOG_FLAGS(0, "FSF_PROT_SEQ_NUMB_ERROR\n");
375 ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
376 "driver (0x%x) and adapter %s (0x%x). "
377 "Restarting all operations on this adapter.\n",
378 fsf_req->qtcb->prefix.req_seq_no,
379 zfcp_get_busid_by_adapter(adapter),
380 fsf_req->qtcb->prefix.prot_status_qual.
381 sequence_error.exp_req_seq_no);
382 debug_text_exception(adapter->erp_dbf, 0, "prot_seq_err");
383 /* restart operation on this adapter */
384 zfcp_erp_adapter_reopen(adapter, 0);
385 zfcp_cmd_dbf_event_fsf("seqnoerr", fsf_req,
386 &fsf_req->qtcb->prefix.prot_status_qual,
387 sizeof (union fsf_prot_status_qual));
388 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
389 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
392 case FSF_PROT_UNSUPP_QTCB_TYPE:
393 ZFCP_LOG_FLAGS(0, "FSF_PROT_UNSUP_QTCB_TYPE\n");
394 ZFCP_LOG_NORMAL("error: Packet header type used by the "
395 "device driver is incompatible with "
396 "that used on adapter %s. "
397 "Stopping all operations on this adapter.\n",
398 zfcp_get_busid_by_adapter(adapter));
399 debug_text_exception(adapter->erp_dbf, 0, "prot_unsup_qtcb");
400 zfcp_erp_adapter_shutdown(adapter, 0);
401 zfcp_cmd_dbf_event_fsf("unsqtcbt", 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;
407 case FSF_PROT_HOST_CONNECTION_INITIALIZING:
408 ZFCP_LOG_FLAGS(1, "FSF_PROT_HOST_CONNECTION_INITIALIZING\n");
409 zfcp_cmd_dbf_event_fsf("hconinit", fsf_req,
410 &fsf_req->qtcb->prefix.prot_status_qual,
411 sizeof (union fsf_prot_status_qual));
412 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
413 atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
415 debug_text_event(adapter->erp_dbf, 3, "prot_con_init");
418 case FSF_PROT_DUPLICATE_REQUEST_ID:
419 ZFCP_LOG_FLAGS(0, "FSF_PROT_DUPLICATE_REQUEST_IDS\n");
421 ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
422 "to the adapter %s is ambiguous. "
423 "Stopping all operations on this "
425 *(unsigned long long *)
426 (&fsf_req->qtcb->bottom.support.
428 zfcp_get_busid_by_adapter(adapter));
430 ZFCP_LOG_NORMAL("bug: The request identifier %p "
431 "to the adapter %s is ambiguous. "
432 "Stopping all operations on this "
434 "(bug: got this for an unsolicited "
435 "status read request)\n",
437 zfcp_get_busid_by_adapter(adapter));
439 debug_text_exception(adapter->erp_dbf, 0, "prot_dup_id");
440 zfcp_erp_adapter_shutdown(adapter, 0);
441 zfcp_cmd_dbf_event_fsf("dupreqid", fsf_req,
442 &fsf_req->qtcb->prefix.prot_status_qual,
443 sizeof (union fsf_prot_status_qual));
444 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
447 case FSF_PROT_LINK_DOWN:
448 ZFCP_LOG_FLAGS(1, "FSF_PROT_LINK_DOWN\n");
450 * 'test and set' is not atomic here -
451 * it's ok as long as calls to our response queue handler
452 * (and thus execution of this code here) are serialized
455 if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
457 switch (fsf_req->qtcb->prefix.prot_status_qual.
458 locallink_error.code) {
459 case FSF_PSQ_LINK_NOLIGHT:
460 ZFCP_LOG_INFO("The local link to adapter %s "
461 "is down (no light detected).\n",
462 zfcp_get_busid_by_adapter(
465 case FSF_PSQ_LINK_WRAPPLUG:
466 ZFCP_LOG_INFO("The local link to adapter %s "
467 "is down (wrap plug detected).\n",
468 zfcp_get_busid_by_adapter(
471 case FSF_PSQ_LINK_NOFCP:
472 ZFCP_LOG_INFO("The local link to adapter %s "
473 "is down (adjacent node on "
474 "link does not support FCP).\n",
475 zfcp_get_busid_by_adapter(
479 ZFCP_LOG_INFO("The local link to adapter %s "
481 "(warning: unknown reason "
483 zfcp_get_busid_by_adapter(
489 * Due to the 'erp failed' flag the adapter won't
490 * be recovered but will be just set to 'blocked'
491 * state. All subordinary devices will have state
492 * 'blocked' and 'erp failed', too.
493 * Thus the adapter is still able to provide
494 * 'link up' status without being flooded with
496 * (note: even 'close port' is not permitted)
498 ZFCP_LOG_INFO("Stopping all operations for adapter "
500 zfcp_get_busid_by_adapter(adapter));
501 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
502 ZFCP_STATUS_COMMON_ERP_FAILED,
504 zfcp_erp_adapter_reopen(adapter, 0);
505 debug_text_event(adapter->erp_dbf, 1, "prot_link_down");
507 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
510 case FSF_PROT_REEST_QUEUE:
511 ZFCP_LOG_FLAGS(1, "FSF_PROT_REEST_QUEUE\n");
512 debug_text_event(adapter->erp_dbf, 1, "prot_reest_queue");
513 ZFCP_LOG_INFO("The local link to adapter with "
514 "%s was re-plugged. "
515 "Re-starting operations on this adapter.\n",
516 zfcp_get_busid_by_adapter(adapter));
517 /* All ports should be marked as ready to run again */
518 zfcp_erp_modify_adapter_status(adapter,
519 ZFCP_STATUS_COMMON_RUNNING,
521 zfcp_erp_adapter_reopen(adapter,
522 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
523 | ZFCP_STATUS_COMMON_ERP_FAILED);
524 zfcp_cmd_dbf_event_fsf("reestque", fsf_req,
525 &fsf_req->qtcb->prefix.prot_status_qual,
526 sizeof (union fsf_prot_status_qual));
527 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
530 case FSF_PROT_ERROR_STATE:
531 ZFCP_LOG_FLAGS(0, "FSF_PROT_ERROR_STATE\n");
532 ZFCP_LOG_NORMAL("error: The adapter %s "
533 "has entered the error state. "
534 "Restarting all operations on this "
536 zfcp_get_busid_by_adapter(adapter));
537 debug_text_event(adapter->erp_dbf, 0, "prot_err_sta");
538 /* restart operation on this adapter */
539 zfcp_erp_adapter_reopen(adapter, 0);
540 zfcp_cmd_dbf_event_fsf("proterrs", fsf_req,
541 &fsf_req->qtcb->prefix.prot_status_qual,
542 sizeof (union fsf_prot_status_qual));
543 fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
548 ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
549 "provided by the adapter %s "
550 "is not compatible with the device driver. "
551 "Stopping all operations on this adapter. "
552 "(debug info 0x%x).\n",
553 zfcp_get_busid_by_adapter(adapter),
554 fsf_req->qtcb->prefix.prot_status);
555 debug_text_event(adapter->erp_dbf, 0, "prot_inval:");
556 debug_exception(adapter->erp_dbf, 0,
557 &fsf_req->qtcb->prefix.prot_status,
559 zfcp_erp_adapter_shutdown(adapter, 0);
560 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
565 * always call specific handlers to give them a chance to do
566 * something meaningful even in error cases
568 zfcp_fsf_fsfstatus_eval(fsf_req);
573 * function: zfcp_fsf_fsfstatus_eval
575 * purpose: evaluates FSF status of completed FSF request
576 * and acts accordingly
581 zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
585 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
589 /* evaluate FSF Status */
590 switch (fsf_req->qtcb->header.fsf_status) {
591 case FSF_UNKNOWN_COMMAND:
592 ZFCP_LOG_FLAGS(0, "FSF_UNKNOWN_COMMAND\n");
593 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
594 "not known by the adapter %s "
595 "Stopping all operations on this adapter. "
596 "(debug info 0x%x).\n",
597 zfcp_get_busid_by_adapter(fsf_req->adapter),
598 fsf_req->qtcb->header.fsf_command);
599 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
601 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
602 zfcp_cmd_dbf_event_fsf("unknownc", fsf_req,
603 &fsf_req->qtcb->header.fsf_status_qual,
604 sizeof (union fsf_status_qual));
605 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
608 case FSF_FCP_RSP_AVAILABLE:
609 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
610 ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
612 debug_text_event(fsf_req->adapter->erp_dbf, 3, "fsf_s_rsp");
615 case FSF_ADAPTER_STATUS_AVAILABLE:
616 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
617 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_astatus");
618 zfcp_fsf_fsfstatus_qual_eval(fsf_req);
627 * always call specific handlers to give them a chance to do
628 * something meaningful even in error cases
630 zfcp_fsf_req_dispatch(fsf_req);
636 * function: zfcp_fsf_fsfstatus_qual_eval
638 * purpose: evaluates FSF status-qualifier of completed FSF request
639 * and acts accordingly
644 zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
648 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
649 case FSF_SQ_FCP_RSP_AVAILABLE:
650 ZFCP_LOG_FLAGS(2, "FSF_SQ_FCP_RSP_AVAILABLE\n");
651 debug_text_event(fsf_req->adapter->erp_dbf, 4, "fsf_sq_rsp");
653 case FSF_SQ_RETRY_IF_POSSIBLE:
654 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
655 /* The SCSI-stack may now issue retries or escalate */
656 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_retry");
657 zfcp_cmd_dbf_event_fsf("sqretry", fsf_req,
658 &fsf_req->qtcb->header.fsf_status_qual,
659 sizeof (union fsf_status_qual));
660 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
662 case FSF_SQ_COMMAND_ABORTED:
663 ZFCP_LOG_FLAGS(2, "FSF_SQ_COMMAND_ABORTED\n");
664 /* Carry the aborted state on to upper layer */
665 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_sq_abort");
666 zfcp_cmd_dbf_event_fsf("sqabort", fsf_req,
667 &fsf_req->qtcb->header.fsf_status_qual,
668 sizeof (union fsf_status_qual));
669 fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
670 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
672 case FSF_SQ_NO_RECOM:
673 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RECOM\n");
674 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
676 ZFCP_LOG_NORMAL("bug: No recommendation could be given for a"
677 "problem on the adapter %s "
678 "Stopping all operations on this adapter. ",
679 zfcp_get_busid_by_adapter(fsf_req->adapter));
680 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
681 zfcp_cmd_dbf_event_fsf("sqnrecom", fsf_req,
682 &fsf_req->qtcb->header.fsf_status_qual,
683 sizeof (union fsf_status_qual));
684 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
686 case FSF_SQ_ULP_PROGRAMMING_ERROR:
687 ZFCP_LOG_FLAGS(0, "FSF_SQ_ULP_PROGRAMMING_ERROR\n");
688 ZFCP_LOG_NORMAL("bug: An illegal amount of data was attempted "
689 "to be sent to the adapter %s "
690 "Stopping all operations on this adapter. ",
691 zfcp_get_busid_by_adapter(fsf_req->adapter));
692 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
694 zfcp_erp_adapter_shutdown(fsf_req->adapter, 0);
695 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
697 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
698 case FSF_SQ_NO_RETRY_POSSIBLE:
699 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
700 /* dealt with in the respective functions */
703 ZFCP_LOG_NORMAL("bug: Additional status info could "
704 "not be interpreted properly.\n");
705 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
706 (char *) &fsf_req->qtcb->header.fsf_status_qual,
707 sizeof (union fsf_status_qual));
708 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval:");
709 debug_exception(fsf_req->adapter->erp_dbf, 0,
710 &fsf_req->qtcb->header.fsf_status_qual.word[0],
712 zfcp_cmd_dbf_event_fsf("squndef", fsf_req,
713 &fsf_req->qtcb->header.fsf_status_qual,
714 sizeof (union fsf_status_qual));
715 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
723 * function: zfcp_fsf_req_dispatch
725 * purpose: calls the appropriate command specific handler
730 zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
732 struct zfcp_erp_action *erp_action = fsf_req->erp_action;
733 struct zfcp_adapter *adapter = fsf_req->adapter;
736 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
737 ZFCP_LOG_TRACE("fsf_req=%p, QTCB=%p\n", fsf_req, fsf_req->qtcb);
738 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
739 (char *) fsf_req->qtcb, sizeof(struct fsf_qtcb));
742 switch (fsf_req->fsf_command) {
744 case FSF_QTCB_FCP_CMND:
745 ZFCP_LOG_FLAGS(3, "FSF_QTCB_FCP_CMND\n");
746 zfcp_fsf_send_fcp_command_handler(fsf_req);
749 case FSF_QTCB_ABORT_FCP_CMND:
750 ZFCP_LOG_FLAGS(2, "FSF_QTCB_ABORT_FCP_CMND\n");
751 zfcp_fsf_abort_fcp_command_handler(fsf_req);
754 case FSF_QTCB_SEND_GENERIC:
755 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_GENERIC\n");
756 zfcp_fsf_send_ct_handler(fsf_req);
759 case FSF_QTCB_OPEN_PORT_WITH_DID:
760 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_PORT_WITH_DID\n");
761 zfcp_fsf_open_port_handler(fsf_req);
764 case FSF_QTCB_OPEN_LUN:
765 ZFCP_LOG_FLAGS(2, "FSF_QTCB_OPEN_LUN\n");
766 zfcp_fsf_open_unit_handler(fsf_req);
769 case FSF_QTCB_CLOSE_LUN:
770 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_LUN\n");
771 zfcp_fsf_close_unit_handler(fsf_req);
774 case FSF_QTCB_CLOSE_PORT:
775 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PORT\n");
776 zfcp_fsf_close_port_handler(fsf_req);
779 case FSF_QTCB_CLOSE_PHYSICAL_PORT:
780 ZFCP_LOG_FLAGS(2, "FSF_QTCB_CLOSE_PHYSICAL_PORT\n");
781 zfcp_fsf_close_physical_port_handler(fsf_req);
784 case FSF_QTCB_EXCHANGE_CONFIG_DATA:
785 ZFCP_LOG_FLAGS(2, "FSF_QTCB_EXCHANGE_CONFIG_DATA\n");
786 zfcp_fsf_exchange_config_data_handler(fsf_req);
789 case FSF_QTCB_SEND_ELS :
790 ZFCP_LOG_FLAGS(2, "FSF_QTCB_SEND_ELS\n");
791 zfcp_fsf_send_els_handler(fsf_req);
794 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
795 ZFCP_LOG_FLAGS(2, "FSF_QTCB_DOWNLOAD_CONTROL_FILE\n");
796 zfcp_fsf_control_file_handler(fsf_req);
799 case FSF_QTCB_UPLOAD_CONTROL_FILE:
800 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UPLOAD_CONTROL_FILE\n");
801 zfcp_fsf_control_file_handler(fsf_req);
805 ZFCP_LOG_FLAGS(2, "FSF_QTCB_UNKNOWN\n");
806 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
807 ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
808 "not supported by the adapter %s\n",
809 zfcp_get_busid_by_adapter(fsf_req->adapter));
810 if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
812 ("bug: Command issued by the device driver differs "
813 "from the command returned by the adapter %s "
814 "(debug info 0x%x, 0x%x).\n",
815 zfcp_get_busid_by_adapter(fsf_req->adapter),
816 fsf_req->fsf_command,
817 fsf_req->qtcb->header.fsf_command);
823 debug_text_event(adapter->erp_dbf, 3, "a_frh");
824 debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
825 zfcp_erp_async_handler(erp_action, 0);
831 * function: zfcp_fsf_status_read
833 * purpose: initiates a Status Read command at the specified adapter
838 zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
840 struct zfcp_fsf_req *fsf_req;
841 struct fsf_status_read_buffer *status_buffer;
842 unsigned long lock_flags;
843 volatile struct qdio_buffer_element *sbale;
846 /* setup new FSF request */
847 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
848 req_flags | ZFCP_REQ_NO_QTCB,
849 adapter->pool.fsf_req_status_read,
850 &lock_flags, &fsf_req);
852 ZFCP_LOG_INFO("error: Could not create unsolicited status "
853 "buffer for adapter %s.\n",
854 zfcp_get_busid_by_adapter(adapter));
855 goto failed_req_create;
858 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
859 sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
860 sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
861 fsf_req->sbale_curr = 2;
864 mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
865 if (!status_buffer) {
866 ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
869 memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
870 fsf_req->data.status_read.buffer = status_buffer;
872 /* insert pointer to respective buffer */
873 sbale = zfcp_qdio_sbale_curr(fsf_req);
874 sbale->addr = (void *) status_buffer;
875 sbale->length = sizeof(struct fsf_status_read_buffer);
877 /* start QDIO request for this FSF request */
878 retval = zfcp_fsf_req_send(fsf_req, NULL);
880 ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
882 goto failed_req_send;
885 ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
886 zfcp_get_busid_by_adapter(adapter));
890 mempool_free(status_buffer, adapter->pool.data_status_read);
893 zfcp_fsf_req_free(fsf_req);
896 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
901 zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
903 struct fsf_status_read_buffer *status_buffer;
904 struct zfcp_adapter *adapter;
905 struct zfcp_port *port;
908 status_buffer = fsf_req->data.status_read.buffer;
909 adapter = fsf_req->adapter;
911 read_lock_irqsave(&zfcp_data.config_lock, flags);
912 list_for_each_entry(port, &adapter->port_list_head, list)
913 if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
915 read_unlock_irqrestore(&zfcp_data.config_lock, flags);
917 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
918 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
919 "nonexisting port with d_id 0x%08x on "
920 "adapter %s. Ignored.\n",
921 status_buffer->d_id & ZFCP_DID_MASK,
922 zfcp_get_busid_by_adapter(adapter));
926 switch (status_buffer->status_subtype) {
928 case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
929 ZFCP_LOG_FLAGS(2, "FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT\n");
930 debug_text_event(adapter->erp_dbf, 3, "unsol_pc_phys:");
931 zfcp_erp_port_reopen(port, 0);
934 case FSF_STATUS_READ_SUB_ERROR_PORT:
935 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_SUB_ERROR_PORT\n");
936 debug_text_event(adapter->erp_dbf, 1, "unsol_pc_err:");
937 zfcp_erp_port_shutdown(port, 0);
941 debug_text_event(adapter->erp_dbf, 0, "unsol_unk_sub:");
942 debug_exception(adapter->erp_dbf, 0,
943 &status_buffer->status_subtype, sizeof (u32));
944 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
945 "for a reopen indication on port with "
946 "d_id 0x%08x on the adapter %s. "
947 "Ignored. (debug info 0x%x)\n",
949 zfcp_get_busid_by_adapter(adapter),
950 status_buffer->status_subtype);
957 * function: zfcp_fsf_status_read_handler
959 * purpose: is called for finished Open Port command
964 zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
967 struct zfcp_adapter *adapter = fsf_req->adapter;
968 struct fsf_status_read_buffer *status_buffer =
969 fsf_req->data.status_read.buffer;
971 if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
972 mempool_free(status_buffer, adapter->pool.data_status_read);
973 zfcp_fsf_req_cleanup(fsf_req);
977 switch (status_buffer->status_type) {
979 case FSF_STATUS_READ_PORT_CLOSED:
980 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_PORT_CLOSED\n");
981 debug_text_event(adapter->erp_dbf, 3, "unsol_pclosed:");
982 debug_event(adapter->erp_dbf, 3,
983 &status_buffer->d_id, sizeof (u32));
984 zfcp_fsf_status_read_port_closed(fsf_req);
987 case FSF_STATUS_READ_INCOMING_ELS:
988 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_INCOMING_ELS\n");
989 debug_text_event(adapter->erp_dbf, 3, "unsol_els:");
990 zfcp_fsf_incoming_els(fsf_req);
993 case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
994 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_BIT_ERROR_THRESHOLD\n");
995 debug_text_event(adapter->erp_dbf, 3, "unsol_bit_err:");
996 ZFCP_LOG_NORMAL("Bit error threshold data received:\n");
997 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
998 (char *) status_buffer,
999 sizeof (struct fsf_status_read_buffer));
1002 case FSF_STATUS_READ_LINK_DOWN:
1003 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_DOWN\n");
1004 debug_text_event(adapter->erp_dbf, 0, "unsol_link_down:");
1005 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
1006 zfcp_get_busid_by_adapter(adapter));
1007 atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
1009 zfcp_erp_adapter_failed(adapter);
1012 case FSF_STATUS_READ_LINK_UP:
1013 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_LINK_UP\n");
1014 debug_text_event(adapter->erp_dbf, 2, "unsol_link_up:");
1015 ZFCP_LOG_INFO("Local link to adapter %s was replugged. "
1016 "Restarting operations on this adapter\n",
1017 zfcp_get_busid_by_adapter(adapter));
1018 /* All ports should be marked as ready to run again */
1019 zfcp_erp_modify_adapter_status(adapter,
1020 ZFCP_STATUS_COMMON_RUNNING,
1022 zfcp_erp_adapter_reopen(adapter,
1023 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
1024 | ZFCP_STATUS_COMMON_ERP_FAILED);
1028 case FSF_STATUS_READ_CFDC_UPDATED:
1029 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_UPDATED\n");
1030 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_update:");
1031 ZFCP_LOG_INFO("CFDC has been updated on the adapter %s\n",
1032 zfcp_get_busid_by_adapter(adapter));
1035 case FSF_STATUS_READ_CFDC_HARDENED:
1036 ZFCP_LOG_FLAGS(1, "FSF_STATUS_READ_CFDC_HARDENED\n");
1037 debug_text_event(adapter->erp_dbf, 2, "unsol_cfdc_harden:");
1038 switch (status_buffer->status_subtype) {
1039 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
1040 ZFCP_LOG_INFO("CFDC of adapter %s saved on SE\n",
1041 zfcp_get_busid_by_adapter(adapter));
1043 case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
1044 ZFCP_LOG_INFO("CFDC of adapter %s has been copied "
1045 "to the secondary SE\n",
1046 zfcp_get_busid_by_adapter(adapter));
1049 ZFCP_LOG_INFO("CFDC of adapter %s has been hardened\n",
1050 zfcp_get_busid_by_adapter(adapter));
1055 debug_text_event(adapter->erp_dbf, 0, "unsol_unknown:");
1056 debug_exception(adapter->erp_dbf, 0,
1057 &status_buffer->status_type, sizeof (u32));
1058 ZFCP_LOG_NORMAL("bug: An unsolicited status packet of unknown "
1059 "type was received (debug info 0x%x)\n",
1060 status_buffer->status_type);
1061 ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
1063 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1064 (char *) status_buffer,
1065 sizeof (struct fsf_status_read_buffer));
1068 mempool_free(status_buffer, adapter->pool.data_status_read);
1069 zfcp_fsf_req_cleanup(fsf_req);
1071 * recycle buffer and start new request repeat until outbound
1072 * queue is empty or adapter shutdown is requested
1076 * we may wait in the req_create for 5s during shutdown, so
1077 * qdio_cleanup will have to wait at least that long before returning
1078 * with failure to allow us a proper cleanup under all circumstances
1082 * allocation failure possible? (Is this code needed?)
1084 retval = zfcp_fsf_status_read(adapter, 0);
1086 ZFCP_LOG_INFO("Failed to create unsolicited status read "
1087 "request for the adapter %s.\n",
1088 zfcp_get_busid_by_adapter(adapter));
1089 /* temporary fix to avoid status read buffer shortage */
1090 adapter->status_read_failed++;
1091 if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
1092 < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
1093 ZFCP_LOG_INFO("restart adapter %s due to status read "
1094 "buffer shortage\n",
1095 zfcp_get_busid_by_adapter(adapter));
1096 zfcp_erp_adapter_reopen(adapter, 0);
1104 * function: zfcp_fsf_abort_fcp_command
1106 * purpose: tells FSF to abort a running SCSI command
1108 * returns: address of initiated FSF request
1109 * NULL - request could not be initiated
1111 * FIXME(design): should be watched by a timeout !!!
1112 * FIXME(design) shouldn't this be modified to return an int
1113 * also...don't know how though
1115 struct zfcp_fsf_req *
1116 zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1117 struct zfcp_adapter *adapter,
1118 struct zfcp_unit *unit, int req_flags)
1120 volatile struct qdio_buffer_element *sbale;
1121 unsigned long lock_flags;
1122 struct zfcp_fsf_req *fsf_req = NULL;
1125 /* setup new FSF request */
1126 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
1127 req_flags, adapter->pool.fsf_req_abort,
1128 &lock_flags, &fsf_req);
1130 ZFCP_LOG_INFO("error: Failed to create an abort command "
1131 "request for lun 0x%016Lx on port 0x%016Lx "
1135 zfcp_get_busid_by_adapter(adapter));
1139 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1140 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
1141 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
1143 fsf_req->data.abort_fcp_command.unit = unit;
1145 /* set handles of unit and its parent port in QTCB */
1146 fsf_req->qtcb->header.lun_handle = unit->handle;
1147 fsf_req->qtcb->header.port_handle = unit->port->handle;
1149 /* set handle of request which should be aborted */
1150 fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
1152 /* start QDIO request for this FSF request */
1154 zfcp_fsf_start_scsi_er_timer(adapter);
1155 retval = zfcp_fsf_req_send(fsf_req, NULL);
1157 del_timer(&adapter->scsi_er_timer);
1158 ZFCP_LOG_INFO("error: Failed to send abort command request "
1159 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
1160 zfcp_get_busid_by_adapter(adapter),
1161 unit->port->wwpn, unit->fcp_lun);
1162 zfcp_fsf_req_free(fsf_req);
1167 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1168 "(adapter%s, port d_id=0x%08x, "
1169 "unit x%016Lx, old_req_id=0x%lx)\n",
1170 zfcp_get_busid_by_adapter(adapter),
1172 unit->fcp_lun, old_req_id);
1174 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
1179 * function: zfcp_fsf_abort_fcp_command_handler
1181 * purpose: is called for finished Abort FCP Command request
1186 zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
1188 int retval = -EINVAL;
1189 struct zfcp_unit *unit = new_fsf_req->data.abort_fcp_command.unit;
1190 unsigned char status_qual =
1191 new_fsf_req->qtcb->header.fsf_status_qual.word[0];
1193 del_timer(&new_fsf_req->adapter->scsi_er_timer);
1195 if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1196 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1197 goto skip_fsfstatus;
1200 /* evaluate FSF status in QTCB */
1201 switch (new_fsf_req->qtcb->header.fsf_status) {
1203 case FSF_PORT_HANDLE_NOT_VALID:
1204 if (status_qual >> 4 != status_qual % 0xf) {
1205 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1206 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1209 * In this case a command that was sent prior to a port
1210 * reopen was aborted (handles are different). This is
1214 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
1215 ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
1216 "port 0x%016Lx on adapter %s invalid. "
1217 "This may happen occasionally.\n",
1220 zfcp_get_busid_by_unit(unit));
1221 ZFCP_LOG_INFO("status qualifier:\n");
1222 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1223 (char *) &new_fsf_req->qtcb->header.
1225 sizeof (union fsf_status_qual));
1226 /* Let's hope this sorts out the mess */
1227 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1229 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
1230 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1234 case FSF_LUN_HANDLE_NOT_VALID:
1235 if (status_qual >> 4 != status_qual % 0xf) {
1237 ZFCP_LOG_FLAGS(0, "FSF_LUN_HANDLE_NOT_VALID\n");
1238 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1241 * In this case a command that was sent prior to a unit
1242 * reopen was aborted (handles are different).
1246 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
1248 ("Warning: Temporary LUN identifier 0x%x of LUN "
1249 "0x%016Lx on port 0x%016Lx on adapter %s is "
1250 "invalid. This may happen in rare cases. "
1251 "Trying to re-establish link.\n",
1255 zfcp_get_busid_by_unit(unit));
1256 ZFCP_LOG_DEBUG("Status qualifier data:\n");
1257 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
1258 (char *) &new_fsf_req->qtcb->header.
1260 sizeof (union fsf_status_qual));
1261 /* Let's hope this sorts out the mess */
1262 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1264 zfcp_erp_port_reopen(unit->port, 0);
1265 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1269 case FSF_FCP_COMMAND_DOES_NOT_EXIST:
1270 ZFCP_LOG_FLAGS(2, "FSF_FCP_COMMAND_DOES_NOT_EXIST\n");
1272 debug_text_event(new_fsf_req->adapter->erp_dbf, 3,
1274 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
1277 case FSF_PORT_BOXED:
1279 ZFCP_LOG_FLAGS(0, "FSF_PORT_BOXED\n");
1280 ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
1281 "be reopened\n", unit->port->wwpn,
1282 zfcp_get_busid_by_unit(unit));
1283 debug_text_event(new_fsf_req->adapter->erp_dbf, 2,
1285 zfcp_erp_port_reopen(unit->port, 0);
1286 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1287 | ZFCP_STATUS_FSFREQ_RETRY;
1290 case FSF_ADAPTER_STATUS_AVAILABLE:
1292 ZFCP_LOG_FLAGS(0, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1293 switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
1294 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
1296 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1297 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1299 /* reopening link to port */
1300 zfcp_erp_port_reopen(unit->port, 0);
1301 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1303 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1305 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1306 /* SCSI stack will escalate */
1307 debug_text_event(new_fsf_req->adapter->erp_dbf, 1,
1309 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1313 ("bug: Wrong status qualifier 0x%x arrived.\n",
1314 new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
1315 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1317 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1318 &new_fsf_req->qtcb->header.
1319 fsf_status_qual.word[0], sizeof (u32));
1326 ZFCP_LOG_FLAGS(0, "FSF_GOOD\n");
1328 new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
1332 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1333 "(debug info 0x%x)\n",
1334 new_fsf_req->qtcb->header.fsf_status);
1335 debug_text_event(new_fsf_req->adapter->erp_dbf, 0,
1337 debug_exception(new_fsf_req->adapter->erp_dbf, 0,
1338 &new_fsf_req->qtcb->header.fsf_status,
1347 * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
1349 * Two scatter-gather lists are passed, one for the reqeust and one for the
1353 zfcp_use_one_sbal(struct scatterlist *req, int req_count,
1354 struct scatterlist *resp, int resp_count)
1356 return ((req_count == 1) &&
1357 (resp_count == 1) &&
1358 (((unsigned long) zfcp_sg_to_address(&req[0]) &
1360 ((unsigned long) (zfcp_sg_to_address(&req[0]) +
1361 req[0].length - 1) & PAGE_MASK)) &&
1362 (((unsigned long) zfcp_sg_to_address(&resp[0]) &
1364 ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
1365 resp[0].length - 1) & PAGE_MASK)));
1369 * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
1370 * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
1372 * @pool: pointer to memory pool, if non-null this pool is used to allocate
1373 * a struct zfcp_fsf_req
1374 * @erp_action: pointer to erp_action, if non-null the Generic Service request
1375 * is sent within error recovery
1378 zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
1379 struct zfcp_erp_action *erp_action)
1381 volatile struct qdio_buffer_element *sbale;
1382 struct zfcp_port *port;
1383 struct zfcp_adapter *adapter;
1384 struct zfcp_fsf_req *fsf_req;
1385 unsigned long lock_flags;
1390 adapter = port->adapter;
1392 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
1393 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
1394 pool, &lock_flags, &fsf_req);
1396 ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
1398 zfcp_get_busid_by_adapter(adapter));
1402 if (erp_action != NULL) {
1403 erp_action->fsf_req = fsf_req;
1404 fsf_req->erp_action = erp_action;
1407 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1408 if (zfcp_use_one_sbal(ct->req, ct->req_count,
1409 ct->resp, ct->resp_count)){
1410 /* both request buffer and response buffer
1411 fit into one sbale each */
1412 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1413 sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
1414 sbale[2].length = ct->req[0].length;
1415 sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
1416 sbale[3].length = ct->resp[0].length;
1417 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1418 } else if (adapter->supported_features &
1419 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1420 /* try to use chained SBALs */
1421 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1422 SBAL_FLAGS0_TYPE_WRITE_READ,
1423 ct->req, ct->req_count,
1424 ZFCP_MAX_SBALS_PER_CT_REQ);
1426 ZFCP_LOG_INFO("error: creation of CT request failed "
1428 zfcp_get_busid_by_adapter(adapter));
1436 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1437 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1438 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1439 SBAL_FLAGS0_TYPE_WRITE_READ,
1440 ct->resp, ct->resp_count,
1441 ZFCP_MAX_SBALS_PER_CT_REQ);
1443 ZFCP_LOG_INFO("error: creation of CT request failed "
1445 zfcp_get_busid_by_adapter(adapter));
1453 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1455 /* reject send generic request */
1457 "error: microcode does not support chained SBALs,"
1458 "CT request too big (adapter %s)\n",
1459 zfcp_get_busid_by_adapter(adapter));
1464 /* settings in QTCB */
1465 fsf_req->qtcb->header.port_handle = port->handle;
1466 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1467 fsf_req->qtcb->bottom.support.timeout = ct->timeout;
1468 fsf_req->data.send_ct = ct;
1470 /* start QDIO request for this FSF request */
1471 ret = zfcp_fsf_req_send(fsf_req, ct->timer);
1473 ZFCP_LOG_DEBUG("error: initiation of CT request failed "
1474 "(adapter %s, port 0x%016Lx)\n",
1475 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1479 ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
1480 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1484 zfcp_fsf_req_free(fsf_req);
1485 if (erp_action != NULL) {
1486 erp_action->fsf_req = NULL;
1490 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1496 * zfcp_fsf_send_ct_handler - handler for Generic Service requests
1497 * @fsf_req: pointer to struct zfcp_fsf_req
1499 * Data specific for the Generic Service request is passed by
1500 * fsf_req->data.send_ct
1501 * Usually a specific handler for the request is called via
1502 * fsf_req->data.send_ct->handler at end of this function.
1505 zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1507 struct zfcp_port *port;
1508 struct zfcp_adapter *adapter;
1509 struct zfcp_send_ct *send_ct;
1510 struct fsf_qtcb_header *header;
1511 struct fsf_qtcb_bottom_support *bottom;
1512 int retval = -EINVAL;
1513 u16 subtable, rule, counter;
1515 adapter = fsf_req->adapter;
1516 send_ct = fsf_req->data.send_ct;
1517 port = send_ct->port;
1518 header = &fsf_req->qtcb->header;
1519 bottom = &fsf_req->qtcb->bottom.support;
1521 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
1522 /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
1523 goto skip_fsfstatus;
1526 /* evaluate FSF status in QTCB */
1527 switch (header->fsf_status) {
1530 ZFCP_LOG_FLAGS(2,"FSF_GOOD\n");
1534 case FSF_SERVICE_CLASS_NOT_SUPPORTED :
1535 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1536 if (adapter->fc_service_class <= 3) {
1537 ZFCP_LOG_INFO("error: adapter %s does not support fc "
1539 zfcp_get_busid_by_port(port),
1540 adapter->fc_service_class);
1542 ZFCP_LOG_INFO("bug: The fibre channel class at the "
1543 "adapter %s is invalid. "
1544 "(debug info %d)\n",
1545 zfcp_get_busid_by_port(port),
1546 adapter->fc_service_class);
1548 /* stop operation for this adapter */
1549 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1550 zfcp_erp_adapter_shutdown(port->adapter, 0);
1551 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1554 case FSF_ADAPTER_STATUS_AVAILABLE :
1555 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1556 switch (header->fsf_status_qual.word[0]){
1557 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE :
1558 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1559 /* reopening link to port */
1560 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1561 zfcp_test_link(port);
1562 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1564 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED :
1565 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1566 /* ERP strategy will escalate */
1567 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1568 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1571 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
1573 header->fsf_status_qual.word[0]);
1578 case FSF_ACCESS_DENIED:
1579 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1580 ZFCP_LOG_NORMAL("Access denied, cannot send generic command "
1581 "to port 0x%016Lx on adapter %s\n", port->wwpn,
1582 zfcp_get_busid_by_port(port));
1583 for (counter = 0; counter < 2; counter++) {
1584 subtable = header->fsf_status_qual.halfword[counter * 2];
1585 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1587 case FSF_SQ_CFDC_SUBTABLE_OS:
1588 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1589 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1590 case FSF_SQ_CFDC_SUBTABLE_LUN:
1591 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1592 zfcp_act_subtable_type[subtable], rule);
1596 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
1597 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1600 case FSF_GENERIC_COMMAND_REJECTED :
1601 ZFCP_LOG_FLAGS(2, "FSF_GENERIC_COMMAND_REJECTED\n");
1602 ZFCP_LOG_INFO("warning: The port 0x%016Lx on adapter %s has "
1603 "rejected a generic services command.\n",
1604 port->wwpn, zfcp_get_busid_by_port(port));
1605 ZFCP_LOG_INFO("status qualifier:\n");
1606 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1607 (char *) &header->fsf_status_qual,
1608 sizeof (union fsf_status_qual));
1609 debug_text_event(adapter->erp_dbf, 1, "fsf_s_gcom_rej");
1610 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1613 case FSF_PORT_HANDLE_NOT_VALID :
1614 ZFCP_LOG_FLAGS(2, "FSF_PORT_HANDLE_NOT_VALID\n");
1615 ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
1616 "0x%016Lx on adapter %s invalid. This may "
1617 "happen occasionally.\n", port->handle,
1618 port->wwpn, zfcp_get_busid_by_port(port));
1619 ZFCP_LOG_INFO("status qualifier:\n");
1620 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1621 (char *) &header->fsf_status_qual,
1622 sizeof (union fsf_status_qual));
1623 debug_text_event(adapter->erp_dbf, 1, "fsf_s_phandle_nv");
1624 zfcp_erp_adapter_reopen(port->adapter, 0);
1625 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1628 case FSF_REQUEST_BUF_NOT_VALID :
1629 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_BUF_NOT_VALID\n");
1630 ZFCP_LOG_NORMAL("error: The port 0x%016Lx on adapter %s has "
1631 "rejected a generic services command "
1632 "due to invalid request buffer.\n",
1633 port->wwpn, zfcp_get_busid_by_port(port));
1634 debug_text_event(adapter->erp_dbf, 1, "fsf_s_reqiv");
1635 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1638 case FSF_RESPONSE_BUF_NOT_VALID :
1639 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_BUF_NOT_VALID\n");
1640 ZFCP_LOG_NORMAL("error: The port 0x%016Lx on adapter %s has "
1641 "rejected a generic services command "
1642 "due to invalid response buffer.\n",
1643 port->wwpn, zfcp_get_busid_by_port(port));
1644 debug_text_event(adapter->erp_dbf, 1, "fsf_s_resiv");
1645 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1648 case FSF_PORT_BOXED :
1649 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
1650 ZFCP_LOG_INFO("The remote port 0x%016Lx on adapter %s "
1651 "needs to be reopened\n",
1652 port->wwpn, zfcp_get_busid_by_port(port));
1653 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1654 zfcp_erp_port_reopen(port, 0);
1655 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
1656 | ZFCP_STATUS_FSFREQ_RETRY;
1660 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
1661 "(debug info 0x%x)\n", header->fsf_status);
1662 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval:");
1663 debug_exception(adapter->erp_dbf, 0,
1664 &header->fsf_status_qual.word[0], sizeof (u32));
1669 if (send_ct->handler != NULL) {
1670 send_ct->handler(send_ct->handler_data);
1677 * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
1678 * @els: pointer to struct zfcp_send_els which contains all needed data for
1682 zfcp_fsf_send_els(struct zfcp_send_els *els)
1684 volatile struct qdio_buffer_element *sbale;
1685 struct zfcp_fsf_req *fsf_req;
1686 struct zfcp_port *port;
1687 struct zfcp_adapter *adapter;
1688 unsigned long lock_flags;
1693 adapter = port->adapter;
1695 ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
1696 ZFCP_WAIT_FOR_SBAL|ZFCP_REQ_AUTO_CLEANUP,
1697 NULL, &lock_flags, &fsf_req);
1699 ZFCP_LOG_INFO("error: creation of ELS request failed "
1700 "(adapter %s, port d_id: 0x%08x)\n",
1701 zfcp_get_busid_by_adapter(adapter), port->d_id);
1705 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1706 if (zfcp_use_one_sbal(els->req, els->req_count,
1707 els->resp, els->resp_count)){
1708 /* both request buffer and response buffer
1709 fit into one sbale each */
1710 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
1711 sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
1712 sbale[2].length = els->req[0].length;
1713 sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
1714 sbale[3].length = els->resp[0].length;
1715 sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
1716 } else if (adapter->supported_features &
1717 FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
1718 /* try to use chained SBALs */
1719 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1720 SBAL_FLAGS0_TYPE_WRITE_READ,
1721 els->req, els->req_count,
1722 ZFCP_MAX_SBALS_PER_ELS_REQ);
1724 ZFCP_LOG_INFO("error: creation of ELS request failed "
1725 "(adapter %s, port d_id: 0x%08x)\n",
1726 zfcp_get_busid_by_adapter(adapter),
1735 fsf_req->qtcb->bottom.support.req_buf_length = bytes;
1736 fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
1737 bytes = zfcp_qdio_sbals_from_sg(fsf_req,
1738 SBAL_FLAGS0_TYPE_WRITE_READ,
1739 els->resp, els->resp_count,
1740 ZFCP_MAX_SBALS_PER_ELS_REQ);
1742 ZFCP_LOG_INFO("error: creation of ELS request failed "
1743 "(adapter %s, port d_id: 0x%08x)\n",
1744 zfcp_get_busid_by_adapter(adapter),
1753 fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
1755 /* reject request */
1756 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1757 ", ELS request too big (adapter %s, "
1758 "port d_id: 0x%08x)\n",
1759 zfcp_get_busid_by_adapter(adapter), port->d_id);
1764 /* settings in QTCB */
1765 fsf_req->qtcb->bottom.support.d_id = port->d_id;
1766 fsf_req->qtcb->bottom.support.service_class = adapter->fc_service_class;
1767 fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
1768 fsf_req->data.send_els = els;
1770 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
1772 /* start QDIO request for this FSF request */
1773 ret = zfcp_fsf_req_send(fsf_req, NULL);
1775 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1776 "(adapter %s, port 0x%016Lx)\n",
1777 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1781 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port 0x%016Lx)\n",
1782 zfcp_get_busid_by_adapter(adapter), port->wwpn);
1786 zfcp_fsf_req_free(fsf_req);
1790 write_unlock_irqrestore(&adapter->request_queue.queue_lock,
1797 * zfcp_fsf_send_els_handler - handler for ELS commands
1798 * @fsf_req: pointer to struct zfcp_fsf_req
1800 * Data specific for the ELS command is passed by
1801 * fsf_req->data.send_els
1802 * Usually a specific handler for the command is called via
1803 * fsf_req->data.send_els->handler at end of this function.
1805 static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1807 struct zfcp_adapter *adapter;
1808 struct zfcp_port *port;
1809 struct fsf_qtcb_header *header;
1810 struct fsf_qtcb_bottom_support *bottom;
1811 struct zfcp_send_els *send_els;
1812 int retval = -EINVAL;
1813 u16 subtable, rule, counter;
1815 adapter = fsf_req->adapter;
1816 send_els = fsf_req->data.send_els;
1817 port = send_els->port;
1818 header = &fsf_req->qtcb->header;
1819 bottom = &fsf_req->qtcb->bottom.support;
1821 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
1822 goto skip_fsfstatus;
1824 switch (header->fsf_status) {
1827 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
1831 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
1832 ZFCP_LOG_FLAGS(2, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
1833 if (adapter->fc_service_class <= 3) {
1834 ZFCP_LOG_INFO("error: adapter %s does "
1835 "not support fibrechannel class %d.\n",
1836 zfcp_get_busid_by_port(port),
1837 adapter->fc_service_class);
1839 ZFCP_LOG_INFO("bug: The fibrechannel class at "
1840 "adapter %s is invalid. "
1841 "(debug info %d)\n",
1842 zfcp_get_busid_by_port(port),
1843 adapter->fc_service_class);
1845 /* stop operation for this adapter */
1846 debug_text_exception(adapter->erp_dbf, 0, "fsf_s_class_nsup");
1847 zfcp_erp_adapter_shutdown(port->adapter, 0);
1848 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1851 case FSF_ADAPTER_STATUS_AVAILABLE:
1852 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
1853 switch (header->fsf_status_qual.word[0]){
1854 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE: {
1855 ZFCP_LOG_FLAGS(2,"FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
1856 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ltest");
1857 if (send_els->ls_code != ZFCP_LS_ADISC)
1858 zfcp_test_link(port);
1859 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1862 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
1863 ZFCP_LOG_FLAGS(2,"FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
1864 /* ERP strategy will escalate */
1865 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_ulp");
1866 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1868 case FSF_SQ_RETRY_IF_POSSIBLE:
1869 ZFCP_LOG_FLAGS(2, "FSF_SQ_RETRY_IF_POSSIBLE\n");
1870 debug_text_event(adapter->erp_dbf, 1, "fsf_sq_retry");
1871 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1874 ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
1875 header->fsf_status_qual.word[0]);
1876 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
1877 (char*)header->fsf_status_qual.word, 16);
1881 case FSF_ELS_COMMAND_REJECTED:
1882 ZFCP_LOG_FLAGS(2, "FSF_ELS_COMMAND_REJECTED\n");
1883 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1884 "prohibited sending "
1885 "(adapter: %s, wwpn=0x%016Lx)\n",
1886 zfcp_get_busid_by_port(port), port->wwpn);
1890 case FSF_PAYLOAD_SIZE_MISMATCH:
1891 ZFCP_LOG_FLAGS(2, "FSF_PAYLOAD_SIZE_MISMATCH\n");
1893 "ELS request size and ELS response size must be either "
1894 "both 0, or both greater than 0 "
1895 "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
1896 zfcp_get_busid_by_port(port),
1897 bottom->req_buf_length,
1898 bottom->resp_buf_length);
1901 case FSF_REQUEST_SIZE_TOO_LARGE:
1902 ZFCP_LOG_FLAGS(2, "FSF_REQUEST_SIZE_TOO_LARGE\n");
1904 "Length of the ELS request buffer, "
1905 "specified in QTCB bottom, "
1906 "exceeds the size of the buffers "
1907 "that have been allocated for ELS request data "
1908 "(adapter: %s, req_buf_length=%d)\n",
1909 zfcp_get_busid_by_port(port),
1910 bottom->req_buf_length);
1913 case FSF_RESPONSE_SIZE_TOO_LARGE:
1914 ZFCP_LOG_FLAGS(2, "FSF_RESPONSE_SIZE_TOO_LARGE\n");
1916 "Length of the ELS response buffer, "
1917 "specified in QTCB bottom, "
1918 "exceeds the size of the buffers "
1919 "that have been allocated for ELS response data "
1920 "(adapter: %s, resp_buf_length=%d)\n",
1921 zfcp_get_busid_by_port(port),
1922 bottom->resp_buf_length);
1925 case FSF_UNKNOWN_COMMAND:
1926 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_COMMAND\n");
1928 "FSF command 0x%x is not supported by FCP adapter "
1929 "(adapter: %s)\n", fsf_req->fsf_command,
1930 zfcp_get_busid_by_port(port));
1931 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1934 case FSF_ACCESS_DENIED:
1935 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
1936 ZFCP_LOG_NORMAL("Access denied, cannot send ELS "
1937 "(adapter: %s, wwpn=0x%016Lx)\n",
1938 zfcp_get_busid_by_port(port), port->wwpn);
1939 for (counter = 0; counter < 2; counter++) {
1940 subtable = header->fsf_status_qual.halfword[counter * 2];
1941 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
1943 case FSF_SQ_CFDC_SUBTABLE_OS:
1944 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
1945 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
1946 case FSF_SQ_CFDC_SUBTABLE_LUN:
1947 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
1948 zfcp_act_subtable_type[subtable], rule);
1952 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
1953 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1958 "bug: An unknown FSF Status was presented "
1959 "(adapter: %s, fsf_status=0x%08x)\n",
1960 zfcp_get_busid_by_port(port),
1961 header->fsf_status);
1962 debug_text_event(adapter->erp_dbf, 0, "fsf_sq_inval");
1963 debug_exception(adapter->erp_dbf, 0,
1964 &header->fsf_status_qual.word[0], sizeof(u32));
1965 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
1970 send_els->status = retval;
1972 if (send_els->handler != 0)
1973 send_els->handler(send_els->handler_data);
1985 * returns: address of initiated FSF request
1986 * NULL - request could not be initiated
1989 zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
1991 volatile struct qdio_buffer_element *sbale;
1992 unsigned long lock_flags;
1995 /* setup new FSF request */
1996 retval = zfcp_fsf_req_create(erp_action->adapter,
1997 FSF_QTCB_EXCHANGE_CONFIG_DATA,
1998 ZFCP_REQ_AUTO_CLEANUP,
1999 erp_action->adapter->pool.fsf_req_erp,
2000 &lock_flags, &(erp_action->fsf_req));
2002 ZFCP_LOG_INFO("error: Could not create exchange configuration "
2003 "data request for adapter %s.\n",
2004 zfcp_get_busid_by_adapter(erp_action->adapter));
2008 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2009 erp_action->fsf_req->sbal_curr, 0);
2010 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2011 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2013 erp_action->fsf_req->erp_action = erp_action;
2014 erp_action->fsf_req->qtcb->bottom.config.feature_selection =
2017 /* start QDIO request for this FSF request */
2018 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2021 ("error: Could not send exchange configuration data "
2022 "command on the adapter %s\n",
2023 zfcp_get_busid_by_adapter(erp_action->adapter));
2024 zfcp_fsf_req_free(erp_action->fsf_req);
2025 erp_action->fsf_req = NULL;
2029 ZFCP_LOG_DEBUG("exchange configuration data request initiated "
2031 zfcp_get_busid_by_adapter(erp_action->adapter));
2034 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2040 * zfcp_fsf_exchange_config_evaluate
2041 * @fsf_req: fsf_req which belongs to xchg config data request
2042 * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
2044 * returns: -EIO on error, 0 otherwise
2047 zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2049 struct fsf_qtcb_bottom_config *bottom;
2050 struct zfcp_adapter *adapter = fsf_req->adapter;
2052 bottom = &fsf_req->qtcb->bottom.config;
2053 ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
2054 bottom->low_qtcb_version, bottom->high_qtcb_version);
2055 adapter->fsf_lic_version = bottom->lic_version;
2056 adapter->supported_features = bottom->supported_features;
2059 adapter->wwnn = bottom->nport_serv_param.wwnn;
2060 adapter->wwpn = bottom->nport_serv_param.wwpn;
2061 adapter->s_id = bottom->s_id & ZFCP_DID_MASK;
2062 adapter->fc_topology = bottom->fc_topology;
2063 adapter->fc_link_speed = bottom->fc_link_speed;
2064 adapter->hydra_version = bottom->adapter_type;
2069 adapter->fc_topology = 0;
2070 adapter->fc_link_speed = 0;
2071 adapter->hydra_version = 0;
2074 if(adapter->supported_features & FSF_FEATURE_HBAAPI_MANAGEMENT){
2075 adapter->hardware_version = bottom->hardware_version;
2076 memcpy(adapter->serial_number, bottom->serial_number, 17);
2077 EBCASC(adapter->serial_number, sizeof(adapter->serial_number));
2080 ZFCP_LOG_INFO("The adapter %s reported the following characteristics:\n"
2084 "adapter version 0x%x, "
2085 "LIC version 0x%x, "
2086 "FC link speed %d Gb/s\n",
2087 zfcp_get_busid_by_adapter(adapter),
2090 (unsigned int) adapter->s_id,
2091 adapter->hydra_version,
2092 adapter->fsf_lic_version,
2093 adapter->fc_link_speed);
2094 if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
2095 ZFCP_LOG_NORMAL("error: the adapter %s "
2096 "only supports newer control block "
2097 "versions in comparison to this device "
2098 "driver (try updated device driver)\n",
2099 zfcp_get_busid_by_adapter(adapter));
2100 debug_text_event(adapter->erp_dbf, 0, "low_qtcb_ver");
2101 zfcp_erp_adapter_shutdown(adapter, 0);
2104 if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
2105 ZFCP_LOG_NORMAL("error: the adapter %s "
2106 "only supports older control block "
2107 "versions than this device driver uses"
2108 "(consider a microcode upgrade)\n",
2109 zfcp_get_busid_by_adapter(adapter));
2110 debug_text_event(adapter->erp_dbf, 0, "high_qtcb_ver");
2111 zfcp_erp_adapter_shutdown(adapter, 0);
2118 * function: zfcp_fsf_exchange_config_data_handler
2120 * purpose: is called for finished Exchange Configuration Data command
2125 zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
2127 struct fsf_qtcb_bottom_config *bottom;
2128 struct zfcp_adapter *adapter = fsf_req->adapter;
2130 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
2133 switch (fsf_req->qtcb->header.fsf_status) {
2136 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
2138 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
2141 switch (adapter->fc_topology) {
2143 ZFCP_LOG_FLAGS(1, "FSF_TOPO_P2P\n");
2144 ZFCP_LOG_NORMAL("error: Point-to-point fibrechannel "
2145 "configuration detected at adapter %s "
2146 "unsupported, shutting down adapter\n",
2147 zfcp_get_busid_by_adapter(adapter));
2148 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2150 zfcp_erp_adapter_shutdown(adapter, 0);
2153 ZFCP_LOG_FLAGS(1, "FSF_TOPO_AL\n");
2154 ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
2155 "topology detected at adapter %s "
2156 "unsupported, shutting down adapter\n",
2157 zfcp_get_busid_by_adapter(adapter));
2158 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2160 zfcp_erp_adapter_shutdown(adapter, 0);
2162 case FSF_TOPO_FABRIC:
2163 ZFCP_LOG_FLAGS(1, "FSF_TOPO_FABRIC\n");
2164 ZFCP_LOG_INFO("Switched fabric fibrechannel "
2165 "network detected at adapter %s.\n",
2166 zfcp_get_busid_by_adapter(adapter));
2169 ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
2170 "reported by the exchange "
2171 "configuration command for "
2172 "the adapter %s is not "
2173 "of a type known to the zfcp "
2174 "driver, shutting down adapter\n",
2175 zfcp_get_busid_by_adapter(adapter));
2176 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2178 zfcp_erp_adapter_shutdown(adapter, 0);
2181 bottom = &fsf_req->qtcb->bottom.config;
2182 if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
2183 ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
2184 "allowed by the adapter %s "
2185 "is lower than the minimum "
2186 "required by the driver (%ld bytes).\n",
2187 bottom->max_qtcb_size,
2188 zfcp_get_busid_by_adapter(adapter),
2189 sizeof(struct fsf_qtcb));
2190 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2192 debug_event(fsf_req->adapter->erp_dbf, 0,
2193 &bottom->max_qtcb_size, sizeof (u32));
2194 zfcp_erp_adapter_shutdown(adapter, 0);
2197 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
2200 case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
2201 debug_text_event(adapter->erp_dbf, 0, "xchg-inco");
2203 if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
2206 ZFCP_LOG_INFO("Local link to adapter %s is down\n",
2207 zfcp_get_busid_by_adapter(adapter));
2208 atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
2209 ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
2211 zfcp_erp_adapter_failed(adapter);
2214 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf-stat-ng");
2215 debug_event(fsf_req->adapter->erp_dbf, 0,
2216 &fsf_req->qtcb->header.fsf_status, sizeof (u32));
2217 zfcp_erp_adapter_shutdown(adapter, 0);
2224 * function: zfcp_fsf_open_port
2228 * returns: address of initiated FSF request
2229 * NULL - request could not be initiated
2232 zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
2234 volatile struct qdio_buffer_element *sbale;
2235 unsigned long lock_flags;
2238 /* setup new FSF request */
2239 retval = zfcp_fsf_req_create(erp_action->adapter,
2240 FSF_QTCB_OPEN_PORT_WITH_DID,
2241 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2242 erp_action->adapter->pool.fsf_req_erp,
2243 &lock_flags, &(erp_action->fsf_req));
2245 ZFCP_LOG_INFO("error: Could not create open port request "
2246 "for port 0x%016Lx on adapter %s.\n",
2247 erp_action->port->wwpn,
2248 zfcp_get_busid_by_adapter(erp_action->adapter));
2252 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2253 erp_action->fsf_req->sbal_curr, 0);
2254 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2255 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2257 erp_action->fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
2258 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
2259 erp_action->fsf_req->data.open_port.port = erp_action->port;
2260 erp_action->fsf_req->erp_action = erp_action;
2262 /* start QDIO request for this FSF request */
2263 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2265 ZFCP_LOG_INFO("error: Could not send open port request for "
2266 "port 0x%016Lx on adapter %s.\n",
2267 erp_action->port->wwpn,
2268 zfcp_get_busid_by_adapter(erp_action->adapter));
2269 zfcp_fsf_req_free(erp_action->fsf_req);
2270 erp_action->fsf_req = NULL;
2274 ZFCP_LOG_DEBUG("open port request initiated "
2275 "(adapter %s, port 0x%016Lx)\n",
2276 zfcp_get_busid_by_adapter(erp_action->adapter),
2277 erp_action->port->wwpn);
2279 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2285 * function: zfcp_fsf_open_port_handler
2287 * purpose: is called for finished Open Port command
2292 zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
2294 int retval = -EINVAL;
2295 struct zfcp_port *port;
2296 struct fsf_plogi *plogi;
2297 struct fsf_qtcb_header *header;
2298 u16 subtable, rule, counter;
2300 port = fsf_req->data.open_port.port;
2301 header = &fsf_req->qtcb->header;
2303 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2304 /* don't change port status in our bookkeeping */
2305 goto skip_fsfstatus;
2308 /* evaluate FSF status in QTCB */
2309 switch (header->fsf_status) {
2311 case FSF_PORT_ALREADY_OPEN:
2312 ZFCP_LOG_FLAGS(0, "FSF_PORT_ALREADY_OPEN\n");
2313 ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
2314 "is already open.\n",
2315 port->wwpn, zfcp_get_busid_by_port(port));
2316 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2319 * This is a bug, however operation should continue normally
2320 * if it is simply ignored
2324 case FSF_ACCESS_DENIED:
2325 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2326 ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
2328 port->wwpn, zfcp_get_busid_by_port(port));
2329 for (counter = 0; counter < 2; counter++) {
2330 subtable = header->fsf_status_qual.halfword[counter * 2];
2331 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2333 case FSF_SQ_CFDC_SUBTABLE_OS:
2334 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2335 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2336 case FSF_SQ_CFDC_SUBTABLE_LUN:
2337 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2338 zfcp_act_subtable_type[subtable], rule);
2342 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2343 zfcp_erp_port_failed(port);
2344 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2347 case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
2348 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED\n");
2349 ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
2350 "The remote port 0x%016Lx on adapter %s "
2351 "could not be opened. Disabling it.\n",
2352 port->wwpn, zfcp_get_busid_by_port(port));
2353 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2355 zfcp_erp_port_failed(port);
2356 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2359 case FSF_ADAPTER_STATUS_AVAILABLE:
2360 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2361 switch (header->fsf_status_qual.word[0]) {
2362 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2364 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2365 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2367 /* ERP strategy will escalate */
2368 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2370 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2371 /* ERP strategy will escalate */
2372 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2374 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2376 case FSF_SQ_NO_RETRY_POSSIBLE:
2377 ZFCP_LOG_FLAGS(0, "FSF_SQ_NO_RETRY_POSSIBLE\n");
2378 ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
2379 "adapter %s could not be opened. "
2382 zfcp_get_busid_by_port(port));
2383 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
2385 zfcp_erp_port_failed(port);
2386 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2390 ("bug: Wrong status qualifier 0x%x arrived.\n",
2391 header->fsf_status_qual.word[0]);
2392 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2395 fsf_req->adapter->erp_dbf, 0,
2396 &header->fsf_status_qual.word[0],
2403 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2404 /* save port handle assigned by FSF */
2405 port->handle = header->port_handle;
2406 ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
2407 "was opened, it's port handle is 0x%x\n",
2408 port->wwpn, zfcp_get_busid_by_port(port),
2410 /* mark port as open */
2411 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
2412 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2414 /* check whether D_ID has changed during open */
2416 * FIXME: This check is not airtight, as the FCP channel does
2417 * not monitor closures of target port connections caused on
2418 * the remote side. Thus, they might miss out on invalidating
2419 * locally cached WWPNs (and other N_Port parameters) of gone
2420 * target ports. So, our heroic attempt to make things safe
2421 * could be undermined by 'open port' response data tagged with
2422 * obsolete WWPNs. Another reason to monitor potential
2423 * connection closures ourself at least (by interpreting
2424 * incoming ELS' and unsolicited status). It just crosses my
2425 * mind that one should be able to cross-check by means of
2426 * another GID_PN straight after a port has been opened.
2427 * Alternately, an ADISC/PDISC ELS should suffice, as well.
2429 plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
2430 if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
2432 if (fsf_req->qtcb->bottom.support.els1_length <
2433 ((((unsigned long) &plogi->serv_param.wwpn) -
2434 ((unsigned long) plogi)) + sizeof (u64))) {
2436 "warning: insufficient length of "
2437 "PLOGI payload (%i)\n",
2438 fsf_req->qtcb->bottom.support.els1_length);
2439 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2440 "fsf_s_short_plogi:");
2441 /* skip sanity check and assume wwpn is ok */
2443 if (plogi->serv_param.wwpn != port->wwpn) {
2444 ZFCP_LOG_INFO("warning: d_id of port "
2445 "0x%016Lx changed during "
2446 "open\n", port->wwpn);
2448 fsf_req->adapter->erp_dbf, 0,
2449 "fsf_s_did_change:");
2451 ZFCP_STATUS_PORT_DID_DID,
2454 port->wwnn = plogi->serv_param.wwnn;
2460 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2461 "(debug info 0x%x)\n",
2462 header->fsf_status);
2463 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2464 debug_exception(fsf_req->adapter->erp_dbf, 0,
2465 &header->fsf_status, sizeof (u32));
2470 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
2475 * function: zfcp_fsf_close_port
2477 * purpose: submit FSF command "close port"
2479 * returns: address of initiated FSF request
2480 * NULL - request could not be initiated
2483 zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
2485 volatile struct qdio_buffer_element *sbale;
2486 unsigned long lock_flags;
2489 /* setup new FSF request */
2490 retval = zfcp_fsf_req_create(erp_action->adapter,
2491 FSF_QTCB_CLOSE_PORT,
2492 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2493 erp_action->adapter->pool.fsf_req_erp,
2494 &lock_flags, &(erp_action->fsf_req));
2496 ZFCP_LOG_INFO("error: Could not create a close port request "
2497 "for port 0x%016Lx on adapter %s.\n",
2498 erp_action->port->wwpn,
2499 zfcp_get_busid_by_adapter(erp_action->adapter));
2503 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2504 erp_action->fsf_req->sbal_curr, 0);
2505 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2506 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2508 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
2509 erp_action->fsf_req->data.close_port.port = erp_action->port;
2510 erp_action->fsf_req->erp_action = erp_action;
2511 erp_action->fsf_req->qtcb->header.port_handle =
2512 erp_action->port->handle;
2514 /* start QDIO request for this FSF request */
2515 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2517 ZFCP_LOG_INFO("error: Could not send a close port request for "
2518 "port 0x%016Lx on adapter %s.\n",
2519 erp_action->port->wwpn,
2520 zfcp_get_busid_by_adapter(erp_action->adapter));
2521 zfcp_fsf_req_free(erp_action->fsf_req);
2522 erp_action->fsf_req = NULL;
2526 ZFCP_LOG_TRACE("close port request initiated "
2527 "(adapter %s, port 0x%016Lx)\n",
2528 zfcp_get_busid_by_adapter(erp_action->adapter),
2529 erp_action->port->wwpn);
2531 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2537 * function: zfcp_fsf_close_port_handler
2539 * purpose: is called for finished Close Port FSF command
2544 zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
2546 int retval = -EINVAL;
2547 struct zfcp_port *port;
2549 port = fsf_req->data.close_port.port;
2551 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2552 /* don't change port status in our bookkeeping */
2553 goto skip_fsfstatus;
2556 /* evaluate FSF status in QTCB */
2557 switch (fsf_req->qtcb->header.fsf_status) {
2559 case FSF_PORT_HANDLE_NOT_VALID:
2560 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2561 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
2562 "0x%016Lx on adapter %s invalid. This may happen "
2563 "occasionally.\n", port->handle,
2564 port->wwpn, zfcp_get_busid_by_port(port));
2565 ZFCP_LOG_DEBUG("status qualifier:\n");
2566 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2567 (char *) &fsf_req->qtcb->header.fsf_status_qual,
2568 sizeof (union fsf_status_qual));
2569 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2571 zfcp_erp_adapter_reopen(port->adapter, 0);
2572 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2575 case FSF_ADAPTER_STATUS_AVAILABLE:
2576 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2577 /* Note: FSF has actually closed the port in this case.
2578 * The status code is just daft. Fingers crossed for a change
2584 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2585 ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
2586 "port handle 0x%x\n", port->wwpn,
2587 zfcp_get_busid_by_port(port), port->handle);
2588 zfcp_erp_modify_port_status(port,
2589 ZFCP_STATUS_COMMON_OPEN,
2595 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2596 "(debug info 0x%x)\n",
2597 fsf_req->qtcb->header.fsf_status);
2598 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2599 debug_exception(fsf_req->adapter->erp_dbf, 0,
2600 &fsf_req->qtcb->header.fsf_status,
2606 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
2611 * function: zfcp_fsf_close_physical_port
2613 * purpose: submit FSF command "close physical port"
2615 * returns: address of initiated FSF request
2616 * NULL - request could not be initiated
2619 zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
2622 unsigned long lock_flags;
2624 /* setup new FSF request */
2625 retval = zfcp_fsf_req_create(erp_action->adapter,
2626 FSF_QTCB_CLOSE_PHYSICAL_PORT,
2627 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2628 erp_action->adapter->pool.fsf_req_erp,
2629 &lock_flags, &erp_action->fsf_req);
2631 ZFCP_LOG_INFO("error: Could not create close physical port "
2632 "request (adapter %s, port 0x%016Lx)\n",
2633 zfcp_get_busid_by_adapter(erp_action->adapter),
2634 erp_action->port->wwpn);
2639 /* mark port as being closed */
2640 atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
2641 &erp_action->port->status);
2642 /* save a pointer to this port */
2643 erp_action->fsf_req->data.close_physical_port.port = erp_action->port;
2644 /* port to be closeed */
2645 erp_action->fsf_req->qtcb->header.port_handle =
2646 erp_action->port->handle;
2647 erp_action->fsf_req->erp_action = erp_action;
2649 /* start QDIO request for this FSF request */
2650 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2652 ZFCP_LOG_INFO("error: Could not send close physical port "
2653 "request (adapter %s, port 0x%016Lx)\n",
2654 zfcp_get_busid_by_adapter(erp_action->adapter),
2655 erp_action->port->wwpn);
2656 zfcp_fsf_req_free(erp_action->fsf_req);
2657 erp_action->fsf_req = NULL;
2661 ZFCP_LOG_TRACE("close physical port request initiated "
2662 "(adapter %s, port 0x%016Lx)\n",
2663 zfcp_get_busid_by_adapter(erp_action->adapter),
2664 erp_action->port->wwpn);
2666 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2672 * function: zfcp_fsf_close_physical_port_handler
2674 * purpose: is called for finished Close Physical Port FSF command
2679 zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
2681 int retval = -EINVAL;
2682 struct zfcp_port *port;
2683 struct zfcp_unit *unit;
2684 struct fsf_qtcb_header *header;
2685 u16 subtable, rule, counter;
2687 port = fsf_req->data.close_physical_port.port;
2688 header = &fsf_req->qtcb->header;
2690 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2691 /* don't change port status in our bookkeeping */
2692 goto skip_fsfstatus;
2695 /* evaluate FSF status in QTCB */
2696 switch (header->fsf_status) {
2698 case FSF_PORT_HANDLE_NOT_VALID:
2699 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2700 ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
2701 "(adapter %s, port 0x%016Lx). "
2702 "This may happen occasionally.\n",
2704 zfcp_get_busid_by_port(port),
2706 ZFCP_LOG_DEBUG("status qualifier:\n");
2707 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2708 (char *) &header->fsf_status_qual,
2709 sizeof (union fsf_status_qual));
2710 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2712 zfcp_erp_adapter_reopen(port->adapter, 0);
2713 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2716 case FSF_ACCESS_DENIED:
2717 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2718 ZFCP_LOG_NORMAL("Access denied, cannot close "
2719 "physical port 0x%016Lx on "
2720 "adapter %s\n", port->wwpn,
2721 zfcp_get_busid_by_port(port));
2722 for (counter = 0; counter < 2; counter++) {
2723 subtable = header->fsf_status_qual.halfword[counter * 2];
2724 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2726 case FSF_SQ_CFDC_SUBTABLE_OS:
2727 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2728 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2729 case FSF_SQ_CFDC_SUBTABLE_LUN:
2730 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2731 zfcp_act_subtable_type[subtable], rule);
2735 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
2736 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2739 case FSF_PORT_BOXED:
2740 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
2741 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
2742 "%s needs to be reopened but it was attempted "
2743 "to close it physically.\n",
2745 zfcp_get_busid_by_port(port));
2746 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_pboxed");
2747 zfcp_erp_port_reopen(port, 0);
2748 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2749 ZFCP_STATUS_FSFREQ_RETRY;
2752 case FSF_ADAPTER_STATUS_AVAILABLE:
2753 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
2754 switch (header->fsf_status_qual.word[0]) {
2755 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
2757 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
2758 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2760 /* This will now be escalated by ERP */
2761 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2763 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
2765 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
2766 /* ERP strategy will escalate */
2767 debug_text_event(fsf_req->adapter->erp_dbf, 1,
2769 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2773 ("bug: Wrong status qualifier 0x%x arrived.\n",
2774 header->fsf_status_qual.word[0]);
2775 debug_text_event(fsf_req->adapter->erp_dbf, 0,
2778 fsf_req->adapter->erp_dbf, 0,
2779 &header->fsf_status_qual.word[0], sizeof (u32));
2785 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
2786 ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
2787 "physically closed, port handle 0x%x\n",
2789 zfcp_get_busid_by_port(port), port->handle);
2790 /* can't use generic zfcp_erp_modify_port_status because
2791 * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
2793 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
2794 list_for_each_entry(unit, &port->unit_list_head, list)
2795 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
2800 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
2801 "(debug info 0x%x)\n",
2802 header->fsf_status);
2803 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
2804 debug_exception(fsf_req->adapter->erp_dbf, 0,
2805 &header->fsf_status, sizeof (u32));
2810 atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
2815 * function: zfcp_fsf_open_unit
2821 * assumptions: This routine does not check whether the associated
2822 * remote port has already been opened. This should be
2823 * done by calling routines. Otherwise some status
2824 * may be presented by FSF
2827 zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
2829 volatile struct qdio_buffer_element *sbale;
2830 unsigned long lock_flags;
2833 /* setup new FSF request */
2834 retval = zfcp_fsf_req_create(erp_action->adapter,
2836 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
2837 erp_action->adapter->pool.fsf_req_erp,
2838 &lock_flags, &(erp_action->fsf_req));
2840 ZFCP_LOG_INFO("error: Could not create open unit request for "
2841 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
2842 erp_action->unit->fcp_lun,
2843 erp_action->unit->port->wwpn,
2844 zfcp_get_busid_by_adapter(erp_action->adapter));
2848 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
2849 erp_action->fsf_req->sbal_curr, 0);
2850 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
2851 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
2853 erp_action->fsf_req->qtcb->header.port_handle =
2854 erp_action->port->handle;
2855 erp_action->fsf_req->qtcb->bottom.support.fcp_lun =
2856 erp_action->unit->fcp_lun;
2857 atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
2858 erp_action->fsf_req->data.open_unit.unit = erp_action->unit;
2859 erp_action->fsf_req->erp_action = erp_action;
2861 /* start QDIO request for this FSF request */
2862 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
2864 ZFCP_LOG_INFO("error: Could not send an open unit request "
2865 "on the adapter %s, port 0x%016Lx for "
2867 zfcp_get_busid_by_adapter(erp_action->adapter),
2868 erp_action->port->wwpn,
2869 erp_action->unit->fcp_lun);
2870 zfcp_fsf_req_free(erp_action->fsf_req);
2871 erp_action->fsf_req = NULL;
2875 ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
2876 "port 0x%016Lx, unit 0x%016Lx)\n",
2877 zfcp_get_busid_by_adapter(erp_action->adapter),
2878 erp_action->port->wwpn, erp_action->unit->fcp_lun);
2880 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
2886 * function: zfcp_fsf_open_unit_handler
2888 * purpose: is called for finished Open LUN command
2893 zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
2895 int retval = -EINVAL;
2896 struct zfcp_adapter *adapter;
2897 struct zfcp_unit *unit;
2898 struct fsf_qtcb_header *header;
2899 struct fsf_qtcb_bottom_support *bottom;
2900 u16 subtable, rule, counter;
2902 adapter = fsf_req->adapter;
2903 unit = fsf_req->data.open_unit.unit;
2904 header = &fsf_req->qtcb->header;
2905 bottom = &fsf_req->qtcb->bottom.support;
2907 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
2908 /* don't change unit status in our bookkeeping */
2909 goto skip_fsfstatus;
2912 /* evaluate FSF status in QTCB */
2913 switch (header->fsf_status) {
2915 case FSF_PORT_HANDLE_NOT_VALID:
2916 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
2917 ZFCP_LOG_INFO("Temporary port identifier 0x%x "
2918 "for port 0x%016Lx on adapter %s invalid "
2919 "This may happen occasionally\n",
2921 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2922 ZFCP_LOG_DEBUG("status qualifier:\n");
2923 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
2924 (char *) &header->fsf_status_qual,
2925 sizeof (union fsf_status_qual));
2926 debug_text_event(adapter->erp_dbf, 1, "fsf_s_ph_nv");
2927 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
2928 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2931 case FSF_LUN_ALREADY_OPEN:
2932 ZFCP_LOG_FLAGS(0, "FSF_LUN_ALREADY_OPEN\n");
2933 ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
2934 "remote port 0x%016Lx on adapter %s twice.\n",
2936 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2937 debug_text_exception(adapter->erp_dbf, 0,
2939 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2942 case FSF_ACCESS_DENIED:
2943 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
2944 ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
2945 "remote port 0x%016Lx on adapter %s\n",
2946 unit->fcp_lun, unit->port->wwpn,
2947 zfcp_get_busid_by_unit(unit));
2948 for (counter = 0; counter < 2; counter++) {
2949 subtable = header->fsf_status_qual.halfword[counter * 2];
2950 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
2952 case FSF_SQ_CFDC_SUBTABLE_OS:
2953 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2954 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2955 case FSF_SQ_CFDC_SUBTABLE_LUN:
2956 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
2957 zfcp_act_subtable_type[subtable], rule);
2961 debug_text_event(adapter->erp_dbf, 1, "fsf_s_access");
2962 zfcp_erp_unit_failed(unit);
2963 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
2966 case FSF_PORT_BOXED:
2967 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
2968 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
2969 "needs to be reopened\n",
2970 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
2971 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
2972 zfcp_erp_port_reopen(unit->port, 0);
2973 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
2974 ZFCP_STATUS_FSFREQ_RETRY;
2977 case FSF_LUN_SHARING_VIOLATION :
2978 ZFCP_LOG_FLAGS(2, "FSF_LUN_SHARING_VIOLATION\n");
2979 if (header->fsf_status_qual.word[0] != 0) {
2980 ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
2982 "connected to the adapter %s "
2983 "is already in use in LPAR%d\n",
2986 zfcp_get_busid_by_unit(unit),
2987 header->fsf_status_qual.fsf_queue_designator.hla);
2989 subtable = header->fsf_status_qual.halfword[4];
2990 rule = header->fsf_status_qual.halfword[5];
2992 case FSF_SQ_CFDC_SUBTABLE_OS:
2993 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
2994 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
2995 case FSF_SQ_CFDC_SUBTABLE_LUN:
2996 ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
2997 "remote port with WWPN 0x%Lx "
2998 "connected to the adapter %s "
2999 "is denied (%s rule %d)\n",
3002 zfcp_get_busid_by_unit(unit),
3003 zfcp_act_subtable_type[subtable],
3008 ZFCP_LOG_DEBUG("status qualifier:\n");
3009 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3010 (char *) &header->fsf_status_qual,
3011 sizeof (union fsf_status_qual));
3012 debug_text_event(adapter->erp_dbf, 2,
3014 zfcp_erp_unit_failed(unit);
3015 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3018 case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
3019 ZFCP_LOG_FLAGS(1, "FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED\n");
3020 ZFCP_LOG_INFO("error: The adapter ran out of resources. "
3021 "There is no handle (temporary port identifier) "
3022 "available for unit 0x%016Lx on port 0x%016Lx "
3026 zfcp_get_busid_by_unit(unit));
3027 debug_text_event(adapter->erp_dbf, 1,
3029 zfcp_erp_unit_failed(unit);
3030 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3033 case FSF_ADAPTER_STATUS_AVAILABLE:
3034 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3035 switch (header->fsf_status_qual.word[0]) {
3036 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3038 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3039 /* Re-establish link to port */
3040 debug_text_event(adapter->erp_dbf, 1,
3042 zfcp_erp_port_reopen(unit->port, 0);
3043 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3045 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3047 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3048 /* ERP strategy will escalate */
3049 debug_text_event(adapter->erp_dbf, 1,
3051 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3055 ("bug: Wrong status qualifier 0x%x arrived.\n",
3056 header->fsf_status_qual.word[0]);
3057 debug_text_event(adapter->erp_dbf, 0,
3059 debug_exception(adapter->erp_dbf, 0,
3060 &header->fsf_status_qual.word[0],
3065 case FSF_INVALID_COMMAND_OPTION:
3066 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
3068 "Invalid option 0x%x has been specified "
3069 "in QTCB bottom sent to the adapter %s\n",
3071 zfcp_get_busid_by_adapter(adapter));
3072 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3077 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3078 /* save LUN handle assigned by FSF */
3079 unit->handle = header->lun_handle;
3080 ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
3081 "adapter %s opened, port handle 0x%x\n",
3084 zfcp_get_busid_by_unit(unit),
3086 /* mark unit as open */
3087 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3092 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3093 "(debug info 0x%x)\n",
3094 header->fsf_status);
3095 debug_text_event(adapter->erp_dbf, 0, "fsf_s_inval:");
3096 debug_exception(adapter->erp_dbf, 0,
3097 &header->fsf_status, sizeof (u32));
3102 atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
3107 * function: zfcp_fsf_close_unit
3111 * returns: address of fsf_req - request successfully initiated
3114 * assumptions: This routine does not check whether the associated
3115 * remote port/lun has already been opened. This should be
3116 * done by calling routines. Otherwise some status
3117 * may be presented by FSF
3120 zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
3122 volatile struct qdio_buffer_element *sbale;
3123 unsigned long lock_flags;
3126 /* setup new FSF request */
3127 retval = zfcp_fsf_req_create(erp_action->adapter,
3129 ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
3130 erp_action->adapter->pool.fsf_req_erp,
3131 &lock_flags, &(erp_action->fsf_req));
3133 ZFCP_LOG_INFO("error: Could not create close unit request for "
3134 "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
3135 erp_action->unit->fcp_lun,
3136 erp_action->port->wwpn,
3137 zfcp_get_busid_by_adapter(erp_action->adapter));
3141 sbale = zfcp_qdio_sbale_req(erp_action->fsf_req,
3142 erp_action->fsf_req->sbal_curr, 0);
3143 sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
3144 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3146 erp_action->fsf_req->qtcb->header.port_handle =
3147 erp_action->port->handle;
3148 erp_action->fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
3149 atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
3150 erp_action->fsf_req->data.close_unit.unit = erp_action->unit;
3151 erp_action->fsf_req->erp_action = erp_action;
3153 /* start QDIO request for this FSF request */
3154 retval = zfcp_fsf_req_send(erp_action->fsf_req, &erp_action->timer);
3156 ZFCP_LOG_INFO("error: Could not send a close unit request for "
3157 "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
3158 erp_action->unit->fcp_lun,
3159 erp_action->port->wwpn,
3160 zfcp_get_busid_by_adapter(erp_action->adapter));
3161 zfcp_fsf_req_free(erp_action->fsf_req);
3162 erp_action->fsf_req = NULL;
3166 ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
3167 "port 0x%016Lx, unit 0x%016Lx)\n",
3168 zfcp_get_busid_by_adapter(erp_action->adapter),
3169 erp_action->port->wwpn, erp_action->unit->fcp_lun);
3171 write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
3177 * function: zfcp_fsf_close_unit_handler
3179 * purpose: is called for finished Close LUN FSF command
3184 zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
3186 int retval = -EINVAL;
3187 struct zfcp_unit *unit;
3189 unit = fsf_req->data.close_unit.unit; /* restore unit */
3191 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
3192 /* don't change unit status in our bookkeeping */
3193 goto skip_fsfstatus;
3196 /* evaluate FSF status in QTCB */
3197 switch (fsf_req->qtcb->header.fsf_status) {
3199 case FSF_PORT_HANDLE_NOT_VALID:
3200 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3201 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3202 "0x%016Lx on adapter %s invalid. This may "
3203 "happen in rare circumstances\n",
3206 zfcp_get_busid_by_unit(unit));
3207 ZFCP_LOG_DEBUG("status qualifier:\n");
3208 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3209 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3210 sizeof (union fsf_status_qual));
3211 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3213 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3214 zfcp_cmd_dbf_event_fsf("porthinv", fsf_req,
3215 &fsf_req->qtcb->header.fsf_status_qual,
3216 sizeof (union fsf_status_qual));
3217 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3220 case FSF_LUN_HANDLE_NOT_VALID:
3221 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3222 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
3223 "0x%016Lx on port 0x%016Lx on adapter %s is "
3224 "invalid. This may happen occasionally.\n",
3228 zfcp_get_busid_by_unit(unit));
3229 ZFCP_LOG_DEBUG("Status qualifier data:\n");
3230 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3231 (char *) &fsf_req->qtcb->header.fsf_status_qual,
3232 sizeof (union fsf_status_qual));
3233 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3235 zfcp_erp_port_reopen(unit->port, 0);
3236 zfcp_cmd_dbf_event_fsf("lunhinv", fsf_req,
3237 &fsf_req->qtcb->header.fsf_status_qual,
3238 sizeof (union fsf_status_qual));
3239 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3242 case FSF_PORT_BOXED:
3243 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3244 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3245 "needs to be reopened\n",
3247 zfcp_get_busid_by_unit(unit));
3248 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3249 zfcp_erp_port_reopen(unit->port, 0);
3250 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3251 ZFCP_STATUS_FSFREQ_RETRY;
3254 case FSF_ADAPTER_STATUS_AVAILABLE:
3255 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3256 switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
3257 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3259 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3260 /* re-establish link to port */
3261 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3263 zfcp_erp_port_reopen(unit->port, 0);
3264 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3266 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3268 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3269 /* ERP strategy will escalate */
3270 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3272 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3276 ("bug: Wrong status qualifier 0x%x arrived.\n",
3277 fsf_req->qtcb->header.fsf_status_qual.word[0]);
3278 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3281 fsf_req->adapter->erp_dbf, 0,
3282 &fsf_req->qtcb->header.fsf_status_qual.word[0],
3289 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3290 ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
3291 "closed, port handle 0x%x\n",
3294 zfcp_get_busid_by_unit(unit),
3296 /* mark unit as closed */
3297 atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
3302 ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
3303 "(debug info 0x%x)\n",
3304 fsf_req->qtcb->header.fsf_status);
3305 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3306 debug_exception(fsf_req->adapter->erp_dbf, 0,
3307 &fsf_req->qtcb->header.fsf_status,
3313 atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
3318 * function: zfcp_fsf_send_fcp_command_task
3324 * note: we do not employ linked commands (not supported by HBA anyway)
3327 zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
3328 struct zfcp_unit *unit,
3329 struct scsi_cmnd * scsi_cmnd, int req_flags)
3331 struct zfcp_fsf_req *fsf_req = NULL;
3332 struct fcp_cmnd_iu *fcp_cmnd_iu;
3333 unsigned int sbtype;
3334 unsigned long lock_flags;
3338 /* setup new FSF request */
3339 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3340 adapter->pool.fsf_req_scsi,
3341 &lock_flags, &fsf_req);
3342 if (unlikely(retval < 0)) {
3343 ZFCP_LOG_DEBUG("error: Could not create FCP command request "
3344 "for unit 0x%016Lx on port 0x%016Lx on "
3348 zfcp_get_busid_by_adapter(adapter));
3349 goto failed_req_create;
3353 * associate FSF request with SCSI request
3354 * (need this for look up on abort)
3356 fsf_req->data.send_fcp_command_task.fsf_req = fsf_req;
3357 scsi_cmnd->host_scribble = (char *) &(fsf_req->data);
3360 * associate SCSI command with FSF request
3361 * (need this for look up on normal command completion)
3363 fsf_req->data.send_fcp_command_task.scsi_cmnd = scsi_cmnd;
3364 fsf_req->data.send_fcp_command_task.start_jiffies = jiffies;
3365 fsf_req->data.send_fcp_command_task.unit = unit;
3366 ZFCP_LOG_DEBUG("unit=%p, fcp_lun=0x%016Lx\n", unit, unit->fcp_lun);
3368 /* set handles of unit and its parent port in QTCB */
3369 fsf_req->qtcb->header.lun_handle = unit->handle;
3370 fsf_req->qtcb->header.port_handle = unit->port->handle;
3372 /* FSF does not define the structure of the FCP_CMND IU */
3373 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3374 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3377 * set depending on data direction:
3378 * data direction bits in SBALE (SB Type)
3379 * data direction bits in QTCB
3380 * data direction bits in FCP_CMND IU
3382 switch (scsi_cmnd->sc_data_direction) {
3384 ZFCP_LOG_FLAGS(3, "DMA_NONE\n");
3385 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3388 * what is the correct type for commands
3389 * without 'real' data buffers?
3391 sbtype = SBAL_FLAGS0_TYPE_READ;
3393 case DMA_FROM_DEVICE:
3394 ZFCP_LOG_FLAGS(3, "DMA_FROM_DEVICE\n");
3395 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
3396 sbtype = SBAL_FLAGS0_TYPE_READ;
3397 fcp_cmnd_iu->rddata = 1;
3400 ZFCP_LOG_FLAGS(3, "DMA_TO_DEVICE\n");
3401 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
3402 sbtype = SBAL_FLAGS0_TYPE_WRITE;
3403 fcp_cmnd_iu->wddata = 1;
3405 case DMA_BIDIRECTIONAL:
3406 ZFCP_LOG_FLAGS(0, "DMA_BIDIRECTIONAL not supported\n");
3409 * dummy, catch this condition earlier
3410 * in zfcp_scsi_queuecommand
3412 goto failed_scsi_cmnd;
3415 /* set FC service class in QTCB (3 per default) */
3416 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3418 /* set FCP_LUN in FCP_CMND IU in QTCB */
3419 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3421 /* set task attributes in FCP_CMND IU in QTCB */
3422 if (likely(scsi_cmnd->device->simple_tags)) {
3423 fcp_cmnd_iu->task_attribute = SIMPLE_Q;
3424 ZFCP_LOG_TRACE("setting SIMPLE_Q task attribute\n");
3426 fcp_cmnd_iu->task_attribute = UNTAGGED;
3427 ZFCP_LOG_TRACE("setting UNTAGGED task attribute\n");
3430 /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
3431 if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
3432 fcp_cmnd_iu->add_fcp_cdb_length
3433 = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
3434 ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
3435 "additional FCP_CDB length is 0x%x "
3436 "(shifted right 2 bits)\n",
3438 fcp_cmnd_iu->add_fcp_cdb_length);
3441 * copy SCSI CDB (including additional length, if any) to
3442 * FCP_CDB in FCP_CMND IU in QTCB
3444 memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3446 /* FCP CMND IU length in QTCB */
3447 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3448 sizeof (struct fcp_cmnd_iu) +
3449 fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
3451 /* generate SBALEs from data buffer */
3452 real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
3453 if (unlikely(real_bytes < 0)) {
3454 if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
3456 "Data did not fit into available buffer(s), "
3457 "waiting for more...\n");
3460 ZFCP_LOG_NORMAL("error: No truncation implemented but "
3461 "required. Shutting down unit "
3462 "(adapter %s, port 0x%016Lx, "
3464 zfcp_get_busid_by_unit(unit),
3467 zfcp_erp_unit_shutdown(unit, 0);
3473 /* set length of FCP data length in FCP_CMND IU in QTCB */
3474 zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
3476 ZFCP_LOG_DEBUG("Sending SCSI command:\n");
3477 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3478 (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
3481 * start QDIO request for this FSF request
3482 * covered by an SBALE)
3484 retval = zfcp_fsf_req_send(fsf_req, NULL);
3485 if (unlikely(retval < 0)) {
3486 ZFCP_LOG_INFO("error: Could not send FCP command request "
3487 "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
3488 zfcp_get_busid_by_adapter(adapter),
3494 ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
3495 "port 0x%016Lx, unit 0x%016Lx)\n",
3496 zfcp_get_busid_by_adapter(adapter),
3504 zfcp_fsf_req_free(fsf_req);
3506 scsi_cmnd->host_scribble = NULL;
3509 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3514 * function: zfcp_fsf_send_fcp_command_task_management
3520 * FIXME(design): should be watched by a timeout!!!
3521 * FIXME(design) shouldn't this be modified to return an int
3522 * also...don't know how though
3525 struct zfcp_fsf_req *
3526 zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
3527 struct zfcp_unit *unit,
3528 u8 tm_flags, int req_flags)
3530 struct zfcp_fsf_req *fsf_req = NULL;
3532 struct fcp_cmnd_iu *fcp_cmnd_iu;
3533 unsigned long lock_flags;
3534 volatile struct qdio_buffer_element *sbale;
3536 /* setup new FSF request */
3537 retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
3538 adapter->pool.fsf_req_scsi,
3539 &lock_flags, &fsf_req);
3541 ZFCP_LOG_INFO("error: Could not create FCP command (task "
3542 "management) request for adapter %s, port "
3543 " 0x%016Lx, unit 0x%016Lx.\n",
3544 zfcp_get_busid_by_adapter(adapter),
3545 unit->port->wwpn, unit->fcp_lun);
3550 * Used to decide on proper handler in the return path,
3551 * could be either zfcp_fsf_send_fcp_command_task_handler or
3552 * zfcp_fsf_send_fcp_command_task_management_handler */
3554 fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
3557 * hold a pointer to the unit being target of this
3558 * task management request
3560 fsf_req->data.send_fcp_command_task_management.unit = unit;
3562 /* set FSF related fields in QTCB */
3563 fsf_req->qtcb->header.lun_handle = unit->handle;
3564 fsf_req->qtcb->header.port_handle = unit->port->handle;
3565 fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
3566 fsf_req->qtcb->bottom.io.service_class = adapter->fc_service_class;
3567 fsf_req->qtcb->bottom.io.fcp_cmnd_length =
3568 sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
3570 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
3571 sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
3572 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
3574 /* set FCP related fields in FCP_CMND IU in QTCB */
3575 fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3576 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3577 fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
3578 fcp_cmnd_iu->task_management_flags = tm_flags;
3580 /* start QDIO request for this FSF request */
3581 zfcp_fsf_start_scsi_er_timer(adapter);
3582 retval = zfcp_fsf_req_send(fsf_req, NULL);
3584 del_timer(&adapter->scsi_er_timer);
3585 ZFCP_LOG_INFO("error: Could not send an FCP-command (task "
3586 "management) on adapter %s, port 0x%016Lx for "
3587 "unit LUN 0x%016Lx\n",
3588 zfcp_get_busid_by_adapter(adapter),
3591 zfcp_fsf_req_free(fsf_req);
3596 ZFCP_LOG_TRACE("Send FCP Command (task management function) initiated "
3597 "(adapter %s, port 0x%016Lx, unit 0x%016Lx, "
3599 zfcp_get_busid_by_adapter(adapter),
3604 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
3609 * function: zfcp_fsf_send_fcp_command_handler
3611 * purpose: is called for finished Send FCP Command
3616 zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
3618 int retval = -EINVAL;
3619 struct zfcp_unit *unit;
3620 struct fsf_qtcb_header *header;
3621 u16 subtable, rule, counter;
3623 header = &fsf_req->qtcb->header;
3625 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
3626 unit = fsf_req->data.send_fcp_command_task_management.unit;
3628 unit = fsf_req->data.send_fcp_command_task.unit;
3630 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3631 /* go directly to calls of special handlers */
3632 goto skip_fsfstatus;
3635 /* evaluate FSF status in QTCB */
3636 switch (header->fsf_status) {
3638 case FSF_PORT_HANDLE_NOT_VALID:
3639 ZFCP_LOG_FLAGS(1, "FSF_PORT_HANDLE_NOT_VALID\n");
3640 ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
3641 "0x%016Lx on adapter %s invalid\n",
3643 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3644 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3645 (char *) &header->fsf_status_qual,
3646 sizeof (union fsf_status_qual));
3647 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3649 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3650 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3653 case FSF_LUN_HANDLE_NOT_VALID:
3654 ZFCP_LOG_FLAGS(1, "FSF_LUN_HANDLE_NOT_VALID\n");
3655 ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
3656 "0x%016Lx on port 0x%016Lx on adapter %s is "
3657 "invalid. This may happen occasionally.\n",
3661 zfcp_get_busid_by_unit(unit));
3662 ZFCP_LOG_NORMAL("Status qualifier data:\n");
3663 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3664 (char *) &header->fsf_status_qual,
3665 sizeof (union fsf_status_qual));
3666 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3668 zfcp_erp_port_reopen(unit->port, 0);
3669 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3672 case FSF_HANDLE_MISMATCH:
3673 ZFCP_LOG_FLAGS(0, "FSF_HANDLE_MISMATCH\n");
3674 ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
3675 "unexpectedly. (adapter %s, port 0x%016Lx, "
3678 zfcp_get_busid_by_unit(unit),
3681 ZFCP_LOG_NORMAL("status qualifier:\n");
3682 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
3683 (char *) &header->fsf_status_qual,
3684 sizeof (union fsf_status_qual));
3685 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3687 zfcp_erp_adapter_reopen(unit->port->adapter, 0);
3688 zfcp_cmd_dbf_event_fsf("handmism",
3690 &header->fsf_status_qual,
3691 sizeof (union fsf_status_qual));
3692 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3695 case FSF_SERVICE_CLASS_NOT_SUPPORTED:
3696 ZFCP_LOG_FLAGS(0, "FSF_SERVICE_CLASS_NOT_SUPPORTED\n");
3697 if (fsf_req->adapter->fc_service_class <= 3) {
3698 ZFCP_LOG_NORMAL("error: The adapter %s does "
3699 "not support fibrechannel class %d.\n",
3700 zfcp_get_busid_by_unit(unit),
3701 fsf_req->adapter->fc_service_class);
3703 ZFCP_LOG_NORMAL("bug: The fibrechannel class at "
3704 "adapter %s is invalid. "
3705 "(debug info %d)\n",
3706 zfcp_get_busid_by_unit(unit),
3707 fsf_req->adapter->fc_service_class);
3709 /* stop operation for this adapter */
3710 debug_text_exception(fsf_req->adapter->erp_dbf, 0,
3711 "fsf_s_class_nsup");
3712 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3713 zfcp_cmd_dbf_event_fsf("unsclass",
3715 &header->fsf_status_qual,
3716 sizeof (union fsf_status_qual));
3717 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3720 case FSF_FCPLUN_NOT_VALID:
3721 ZFCP_LOG_FLAGS(0, "FSF_FCPLUN_NOT_VALID\n");
3722 ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
3723 "adapter %s does not have correct unit "
3727 zfcp_get_busid_by_unit(unit),
3729 ZFCP_LOG_DEBUG("status qualifier:\n");
3730 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
3731 (char *) &header->fsf_status_qual,
3732 sizeof (union fsf_status_qual));
3733 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3734 "fsf_s_fcp_lun_nv");
3735 zfcp_erp_port_reopen(unit->port, 0);
3736 zfcp_cmd_dbf_event_fsf("fluninv",
3738 &header->fsf_status_qual,
3739 sizeof (union fsf_status_qual));
3740 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3743 case FSF_ACCESS_DENIED:
3744 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_DENIED\n");
3745 ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
3746 "unit 0x%016Lx on port 0x%016Lx on "
3747 "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
3748 zfcp_get_busid_by_unit(unit));
3749 for (counter = 0; counter < 2; counter++) {
3750 subtable = header->fsf_status_qual.halfword[counter * 2];
3751 rule = header->fsf_status_qual.halfword[counter * 2 + 1];
3753 case FSF_SQ_CFDC_SUBTABLE_OS:
3754 case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
3755 case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
3756 case FSF_SQ_CFDC_SUBTABLE_LUN:
3757 ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
3758 zfcp_act_subtable_type[subtable], rule);
3762 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_access");
3763 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3766 case FSF_DIRECTION_INDICATOR_NOT_VALID:
3767 ZFCP_LOG_FLAGS(0, "FSF_DIRECTION_INDICATOR_NOT_VALID\n");
3768 ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
3769 "0x%016Lx on port 0x%016Lx on adapter %s "
3770 "(debug info %d)\n",
3773 zfcp_get_busid_by_unit(unit),
3774 fsf_req->qtcb->bottom.io.data_direction);
3775 /* stop operation for this adapter */
3776 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3777 "fsf_s_dir_ind_nv");
3778 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3779 zfcp_cmd_dbf_event_fsf("dirinv",
3781 &header->fsf_status_qual,
3782 sizeof (union fsf_status_qual));
3783 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3786 /* FIXME: this should be obsolete, isn' it? */
3787 case FSF_INBOUND_DATA_LENGTH_NOT_VALID:
3788 ZFCP_LOG_FLAGS(0, "FSF_INBOUND_DATA_LENGTH_NOT_VALID\n");
3789 ZFCP_LOG_NORMAL("bug: An invalid inbound data length field "
3790 "was found in a command for unit 0x%016Lx "
3791 "on port 0x%016Lx on adapter %s.\n",
3793 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3794 /* stop operation for this adapter */
3795 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3797 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3798 zfcp_cmd_dbf_event_fsf("idleninv",
3800 &header->fsf_status_qual,
3801 sizeof (union fsf_status_qual));
3802 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3805 /* FIXME: this should be obsolete, isn' it? */
3806 case FSF_OUTBOUND_DATA_LENGTH_NOT_VALID:
3807 ZFCP_LOG_FLAGS(0, "FSF_OUTBOUND_DATA_LENGTH_NOT_VALID\n");
3808 ZFCP_LOG_NORMAL("bug: An invalid outbound data length field "
3809 "was found in a command unit 0x%016Lx on port "
3810 "0x%016Lx on adapter %s\n",
3813 zfcp_get_busid_by_unit(unit));
3814 /* stop operation for this adapter */
3815 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3817 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3818 zfcp_cmd_dbf_event_fsf("odleninv", fsf_req,
3819 &header->fsf_status_qual,
3820 sizeof (union fsf_status_qual));
3821 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3824 case FSF_CMND_LENGTH_NOT_VALID:
3825 ZFCP_LOG_FLAGS(0, "FSF_CMND_LENGTH_NOT_VALID\n");
3827 ("bug: An invalid control-data-block length field "
3828 "was found in a command for unit 0x%016Lx on port "
3829 "0x%016Lx on adapter %s " "(debug info %d)\n",
3830 unit->fcp_lun, unit->port->wwpn,
3831 zfcp_get_busid_by_unit(unit),
3832 fsf_req->qtcb->bottom.io.fcp_cmnd_length);
3833 /* stop operation for this adapter */
3834 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3835 "fsf_s_cmd_len_nv");
3836 zfcp_erp_adapter_shutdown(unit->port->adapter, 0);
3837 zfcp_cmd_dbf_event_fsf("cleninv",
3839 &header->fsf_status_qual,
3840 sizeof (union fsf_status_qual));
3841 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3844 case FSF_PORT_BOXED:
3845 ZFCP_LOG_FLAGS(2, "FSF_PORT_BOXED\n");
3846 ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
3847 "needs to be reopened\n",
3848 unit->port->wwpn, zfcp_get_busid_by_unit(unit));
3849 debug_text_event(fsf_req->adapter->erp_dbf, 2, "fsf_s_pboxed");
3850 zfcp_erp_port_reopen(unit->port, 0);
3851 zfcp_cmd_dbf_event_fsf("portbox", fsf_req,
3852 &header->fsf_status_qual,
3853 sizeof (union fsf_status_qual));
3854 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
3855 ZFCP_STATUS_FSFREQ_RETRY;
3859 ZFCP_LOG_FLAGS(0, "FSF_LUN_BOXED\n");
3861 "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
3863 unit->fcp_lun, unit->port->wwpn,
3864 zfcp_get_busid_by_unit(unit));
3865 debug_text_event(fsf_req->adapter->erp_dbf, 1, "fsf_s_lboxed");
3866 zfcp_erp_unit_reopen(unit, 0);
3867 zfcp_cmd_dbf_event_fsf("unitbox", fsf_req,
3868 &header->fsf_status_qual,
3869 sizeof(union fsf_status_qual));
3870 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
3871 | ZFCP_STATUS_FSFREQ_RETRY;
3874 case FSF_ADAPTER_STATUS_AVAILABLE:
3875 ZFCP_LOG_FLAGS(2, "FSF_ADAPTER_STATUS_AVAILABLE\n");
3876 switch (header->fsf_status_qual.word[0]) {
3877 case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
3879 "FSF_SQ_INVOKE_LINK_TEST_PROCEDURE\n");
3880 /* re-establish link to port */
3881 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3883 zfcp_erp_port_reopen(unit->port, 0);
3884 zfcp_cmd_dbf_event_fsf(
3887 &header->fsf_status_qual,
3888 sizeof (union fsf_status_qual));
3889 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3891 case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
3893 "FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED\n");
3894 /* FIXME(hw) need proper specs for proper action */
3895 /* let scsi stack deal with retries and escalation */
3896 debug_text_event(fsf_req->adapter->erp_dbf, 1,
3898 zfcp_cmd_dbf_event_fsf(
3901 &header->fsf_status_qual,
3902 sizeof (union fsf_status_qual));
3903 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
3906 /* FIXME: shall we consider this a successful transfer? */
3908 ("bug: Wrong status qualifier 0x%x arrived.\n",
3909 header->fsf_status_qual.word[0]);
3910 debug_text_event(fsf_req->adapter->erp_dbf, 0,
3912 debug_exception(fsf_req->adapter->erp_dbf, 0,
3913 &header->fsf_status_qual.word[0],
3920 ZFCP_LOG_FLAGS(3, "FSF_GOOD\n");
3923 case FSF_FCP_RSP_AVAILABLE:
3924 ZFCP_LOG_FLAGS(2, "FSF_FCP_RSP_AVAILABLE\n");
3928 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_s_inval:");
3929 debug_exception(fsf_req->adapter->erp_dbf, 0,
3930 &header->fsf_status, sizeof(u32));
3935 if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
3937 zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
3939 retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
3945 * function: zfcp_fsf_send_fcp_command_task_handler
3947 * purpose: evaluates FCP_RSP IU
3952 zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
3955 struct scsi_cmnd *scpnt;
3956 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
3957 &(fsf_req->qtcb->bottom.io.fcp_rsp);
3958 struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
3959 &(fsf_req->qtcb->bottom.io.fcp_cmnd);
3961 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
3962 unsigned long flags;
3963 struct zfcp_unit *unit = fsf_req->data.send_fcp_command_task.unit;
3965 read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
3966 scpnt = fsf_req->data.send_fcp_command_task.scsi_cmnd;
3967 if (unlikely(!scpnt)) {
3969 ("Command with fsf_req %p is not associated to "
3970 "a scsi command anymore. Aborted?\n", fsf_req);
3973 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
3974 /* FIXME: (design) mid-layer should handle DID_ABORT like
3975 * DID_SOFT_ERROR by retrying the request for devices
3976 * that allow retries.
3978 ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
3979 set_host_byte(&scpnt->result, DID_SOFT_ERROR);
3980 set_driver_byte(&scpnt->result, SUGGEST_RETRY);
3981 goto skip_fsfstatus;
3984 if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
3985 ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
3986 set_host_byte(&scpnt->result, DID_ERROR);
3987 goto skip_fsfstatus;
3990 /* set message byte of result in SCSI command */
3991 scpnt->result |= COMMAND_COMPLETE << 8;
3994 * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
3995 * of result in SCSI command
3997 scpnt->result |= fcp_rsp_iu->scsi_status;
3998 if (unlikely(fcp_rsp_iu->scsi_status)) {
4000 ZFCP_LOG_NORMAL("status for SCSI Command:\n");
4001 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
4002 scpnt->cmnd, scpnt->cmd_len);
4004 ZFCP_LOG_NORMAL("SCSI status code 0x%x\n",
4005 fcp_rsp_iu->scsi_status);
4006 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
4007 (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
4008 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
4009 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
4010 fcp_rsp_iu->fcp_sns_len);
4013 /* check FCP_RSP_INFO */
4014 if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
4015 ZFCP_LOG_DEBUG("rsp_len is valid\n");
4016 switch (fcp_rsp_info[3]) {
4018 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4020 ZFCP_LOG_TRACE("no failure or Task Management "
4021 "Function complete\n");
4022 set_host_byte(&scpnt->result, DID_OK);
4024 case RSP_CODE_LENGTH_MISMATCH:
4025 ZFCP_LOG_FLAGS(0, "RSP_CODE_LENGTH_MISMATCH\n");
4027 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4028 "that the fibrechannel protocol data "
4029 "length differs from the burst length. "
4030 "The problem occured on unit 0x%016Lx "
4031 "on port 0x%016Lx on adapter %s",
4034 zfcp_get_busid_by_unit(unit));
4035 /* dump SCSI CDB as prepared by zfcp */
4036 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4037 (char *) &fsf_req->qtcb->
4038 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4039 zfcp_cmd_dbf_event_fsf("clenmis", fsf_req, NULL, 0);
4040 set_host_byte(&scpnt->result, DID_ERROR);
4041 goto skip_fsfstatus;
4042 case RSP_CODE_FIELD_INVALID:
4043 ZFCP_LOG_FLAGS(0, "RSP_CODE_FIELD_INVALID\n");
4044 /* driver or hardware bug */
4045 ZFCP_LOG_NORMAL("bug: FCP response code indictates "
4046 "that the fibrechannel protocol data "
4047 "fields were incorrectly set up. "
4048 "The problem occured on the unit "
4049 "0x%016Lx on port 0x%016Lx on "
4053 zfcp_get_busid_by_unit(unit));
4054 /* dump SCSI CDB as prepared by zfcp */
4055 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4056 (char *) &fsf_req->qtcb->
4057 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4058 set_host_byte(&scpnt->result, DID_ERROR);
4059 zfcp_cmd_dbf_event_fsf("codeinv", fsf_req, NULL, 0);
4060 goto skip_fsfstatus;
4061 case RSP_CODE_RO_MISMATCH:
4062 ZFCP_LOG_FLAGS(0, "RSP_CODE_RO_MISMATCH\n");
4064 ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
4065 "that conflicting values for the "
4066 "fibrechannel payload offset from the "
4067 "header were found. "
4068 "The problem occured on unit 0x%016Lx "
4069 "on port 0x%016Lx on adapter %s.\n",
4072 zfcp_get_busid_by_unit(unit));
4073 /* dump SCSI CDB as prepared by zfcp */
4074 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4075 (char *) &fsf_req->qtcb->
4076 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4077 zfcp_cmd_dbf_event_fsf("codemism", fsf_req, NULL, 0);
4078 set_host_byte(&scpnt->result, DID_ERROR);
4079 goto skip_fsfstatus;
4081 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4082 "code was detected for a command. "
4083 "The problem occured on the unit "
4084 "0x%016Lx on port 0x%016Lx on "
4085 "adapter %s (debug info 0x%x)\n",
4088 zfcp_get_busid_by_unit(unit),
4090 /* dump SCSI CDB as prepared by zfcp */
4091 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
4092 (char *) &fsf_req->qtcb->
4093 bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
4094 zfcp_cmd_dbf_event_fsf("undeffcp", fsf_req, NULL, 0);
4095 set_host_byte(&scpnt->result, DID_ERROR);
4099 /* check for sense data */
4100 if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
4101 sns_len = FSF_FCP_RSP_SIZE -
4102 sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
4103 ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
4105 sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
4106 ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
4107 SCSI_SENSE_BUFFERSIZE);
4108 sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
4109 ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
4111 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4112 (void *) &scpnt->cmnd, scpnt->cmd_len);
4114 ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
4115 fcp_rsp_iu->fcp_sns_len);
4116 memcpy(&scpnt->sense_buffer,
4117 zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
4118 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
4119 (void *) &scpnt->sense_buffer, sns_len);
4122 /* check for overrun */
4123 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
4124 ZFCP_LOG_INFO("A data overrun was detected for a command. "
4125 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4126 "The response data length is "
4127 "%d, the original length was %d.\n",
4130 zfcp_get_busid_by_unit(unit),
4131 fcp_rsp_iu->fcp_resid,
4132 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4135 /* check for underrun */
4136 if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
4137 ZFCP_LOG_DEBUG("A data underrun was detected for a command. "
4138 "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
4139 "The response data length is "
4140 "%d, the original length was %d.\n",
4143 zfcp_get_busid_by_unit(unit),
4144 fcp_rsp_iu->fcp_resid,
4145 (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
4147 * It may not have been possible to send all data and the
4148 * underrun on send may already be in scpnt->resid, so it's add
4149 * not equals in the below statement.
4151 scpnt->resid += fcp_rsp_iu->fcp_resid;
4152 ZFCP_LOG_TRACE("scpnt->resid=0x%x\n", scpnt->resid);
4158 * This nasty chop at the problem is not working anymore
4159 * as we do not adjust the retry count anylonger in order
4160 * to have a number of retries that avoids I/O errors.
4161 * The manipulation of the retry count has been removed
4162 * in favour of a safe tape device handling. We must not
4163 * sent SCSI commands more than once to a device if no
4164 * retries are permitted by the high level driver. Generally
4165 * speaking, it was a mess to change retry counts. So it is
4166 * fine that this sort of workaround is gone.
4167 * Then, we had to face a certain number of immediate retries in case of
4168 * busy and queue full conditions (see below).
4169 * This is not acceptable
4170 * for the latter. Queue full conditions are used
4171 * by devices to indicate to a host that the host can rely
4172 * on the completion (or timeout) of at least one outstanding
4173 * command as a suggested trigger for command retries.
4174 * Busy conditions require a different trigger since
4175 * no commands are outstanding for that initiator from the
4176 * devices perspective.
4177 * The drawback of mapping a queue full condition to a
4178 * busy condition is the chance of wasting all retries prior
4179 * to the time when the device indicates that a command
4180 * rejected due to a queue full condition should be re-driven.
4181 * This case would lead to unnecessary I/O errors that
4182 * have to be considered fatal if for example ext3's
4183 * journaling would be torpedoed by such an avoidable
4185 * So, what issues are there with not mapping a queue-full
4186 * condition to a busy condition?
4187 * Due to the 'exclusive LUN'
4188 * policy enforced by the zSeries FCP channel, this
4189 * Linux instance is the only initiator with regard to
4190 * this adapter. It is safe to rely on the information
4191 * 'don't disturb me now ... and btw. no other commands
4192 * pending for you' (= queue full) sent by the LU,
4193 * since no other Linux can use this LUN via this adapter
4194 * at the same time. If there is a potential race
4195 * introduced by the FCP channel by not inhibiting Linux A
4196 * to give up a LU with commands pending while Linux B
4197 * grabs this LU and sends commands - thus providing
4198 * an exploit at the 'exclusive LUN' policy - then this
4199 * issue has to be considered a hardware problem. It should
4200 * be tracked as such if it really occurs. Even if the
4201 * FCP Channel spec. begs exploiters to wait for the
4202 * completion of all request sent to a LU prior to
4203 * closing this LU connection.
4204 * This spec. statement in conjunction with
4205 * the 'exclusive LUN' policy is not consistent design.
4206 * Another issue is how resource constraints for SCSI commands
4207 * might be handled by the FCP channel (just guessing for now).
4208 * If the FCP channel would always map resource constraints,
4209 * e.g. no free FC exchange ID due to I/O stress caused by
4210 * other sharing Linux instances, to faked queue-full
4211 * conditions then this would be a misinterpretation and
4212 * violation of SCSI standards.
4213 * If there are SCSI stack races as indicated below
4214 * then they need to be fixed just there.
4215 * Providing all issue above are not applicable or will
4216 * be fixed appropriately, removing the following hack
4217 * is the right thing to do.
4221 * Note: This is a rather nasty chop at the problem. We cannot
4222 * risk adding to the mlqueue however as this will block the
4223 * device. If it is the last outstanding command for this host
4224 * it will remain blocked indefinitely. This would be quite possible
4225 * on the zSeries FCP adapter.
4226 * Also, there exists a race with scsi_insert_special relying on
4227 * scsi_request_fn to recalculate some command data which may not
4228 * happen when q->plugged is true in scsi_request_fn
4230 if (status_byte(scpnt->result) == QUEUE_FULL) {
4231 ZFCP_LOG_DEBUG("Changing QUEUE_FULL to BUSY....\n");
4232 scpnt->result &= ~(QUEUE_FULL << 1);
4233 scpnt->result |= (BUSY << 1);
4237 ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
4239 zfcp_cmd_dbf_event_scsi("response", scpnt);
4241 /* cleanup pointer (need this especially for abort) */
4242 scpnt->host_scribble = NULL;
4246 * according to the outcome of a discussion on linux-scsi we
4247 * don't need to grab the io_request_lock here since we use
4250 /* always call back */
4252 (scpnt->scsi_done) (scpnt);
4255 * We must hold this lock until scsi_done has been called.
4256 * Otherwise we may call scsi_done after abort regarding this
4257 * command has completed.
4258 * Note: scsi_done must not block!
4261 read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
4266 * function: zfcp_fsf_send_fcp_command_task_management_handler
4268 * purpose: evaluates FCP_RSP IU
4273 zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
4276 struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
4277 &(fsf_req->qtcb->bottom.io.fcp_rsp);
4278 char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
4279 struct zfcp_unit *unit =
4280 fsf_req->data.send_fcp_command_task_management.unit;
4282 del_timer(&fsf_req->adapter->scsi_er_timer);
4283 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4284 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4285 goto skip_fsfstatus;
4288 /* check FCP_RSP_INFO */
4289 switch (fcp_rsp_info[3]) {
4291 ZFCP_LOG_FLAGS(3, "RSP_CODE_GOOD\n");
4293 ZFCP_LOG_DEBUG("no failure or Task Management "
4294 "Function complete\n");
4296 case RSP_CODE_TASKMAN_UNSUPP:
4297 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_UNSUPP\n");
4298 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4299 "is not supported on the target device "
4300 "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
4303 zfcp_get_busid_by_unit(unit));
4304 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
4306 case RSP_CODE_TASKMAN_FAILED:
4307 ZFCP_LOG_FLAGS(0, "RSP_CODE_TASKMAN_FAILED\n");
4308 ZFCP_LOG_NORMAL("bug: A reuested task management function "
4309 "failed to complete successfully. "
4310 "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
4313 zfcp_get_busid_by_unit(unit));
4314 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4317 ZFCP_LOG_NORMAL("bug: An invalid FCP response "
4318 "code was detected for a command. "
4319 "unit 0x%016Lx, port 0x%016Lx, adapter %s "
4320 "(debug info 0x%x)\n",
4323 zfcp_get_busid_by_unit(unit),
4325 fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
4334 * function: zfcp_fsf_control_file
4336 * purpose: Initiator of the control file upload/download FSF requests
4338 * returns: 0 - FSF request is successfuly created and queued
4339 * -EOPNOTSUPP - The FCP adapter does not have Control File support
4340 * -EINVAL - Invalid direction specified
4341 * -ENOMEM - Insufficient memory
4342 * -EPERM - Cannot create FSF request or or place it in QDIO queue
4345 zfcp_fsf_control_file(struct zfcp_adapter *adapter,
4346 struct zfcp_fsf_req **fsf_req_ptr,
4349 struct zfcp_sg_list *sg_list)
4351 struct zfcp_fsf_req *fsf_req;
4352 struct fsf_qtcb_bottom_support *bottom;
4353 volatile struct qdio_buffer_element *sbale;
4354 unsigned long lock_flags;
4359 if (!(adapter->supported_features & FSF_FEATURE_CFDC)) {
4361 "Adapter %s does not support control file\n",
4362 zfcp_get_busid_by_adapter(adapter));
4363 retval = -EOPNOTSUPP;
4364 goto no_cfdc_support;
4367 switch (fsf_command) {
4369 case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
4370 direction = SBAL_FLAGS0_TYPE_WRITE;
4371 if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
4372 (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
4373 req_flags = ZFCP_WAIT_FOR_SBAL;
4376 case FSF_QTCB_UPLOAD_CONTROL_FILE:
4377 direction = SBAL_FLAGS0_TYPE_READ;
4381 ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
4382 goto invalid_command;
4385 retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
4386 NULL, &lock_flags, &fsf_req);
4388 ZFCP_LOG_INFO("error: Could not create FSF request for the "
4390 zfcp_get_busid_by_adapter(adapter));
4395 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4396 sbale[0].flags |= direction;
4398 bottom = &fsf_req->qtcb->bottom.support;
4399 bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
4400 bottom->option = option;
4402 if (sg_list->count > 0) {
4405 bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
4406 sg_list->sg, sg_list->count,
4407 ZFCP_MAX_SBALS_PER_REQ);
4408 if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
4410 "error: Could not create sufficient number of "
4411 "SBALS for an FSF request to the adapter %s\n",
4412 zfcp_get_busid_by_adapter(adapter));
4417 sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
4420 retval = zfcp_fsf_req_send(fsf_req, NULL);
4423 "error: Could not send FSF request to the adapter %s\n",
4424 zfcp_get_busid_by_adapter(adapter));
4430 "Control file %s FSF request has been sent to the adapter %s\n",
4431 fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
4432 "download" : "upload",
4433 zfcp_get_busid_by_adapter(adapter));
4435 *fsf_req_ptr = fsf_req;
4441 zfcp_fsf_req_free(fsf_req);
4444 write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
4453 * function: zfcp_fsf_control_file_handler
4455 * purpose: Handler of the control file upload/download FSF requests
4457 * returns: 0 - FSF request successfuly processed
4458 * -EAGAIN - Operation has to be repeated because of a temporary problem
4459 * -EACCES - There is no permission to execute an operation
4460 * -EPERM - The control file is not in a right format
4461 * -EIO - There is a problem with the FCP adapter
4462 * -EINVAL - Invalid operation
4463 * -EFAULT - User space memory I/O operation fault
4466 zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
4468 struct zfcp_adapter *adapter = fsf_req->adapter;
4469 struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
4470 struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
4473 if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
4475 goto skip_fsfstatus;
4478 switch (header->fsf_status) {
4481 ZFCP_LOG_FLAGS(2, "FSF_GOOD\n");
4483 "The FSF request has been successfully completed "
4484 "on the adapter %s\n",
4485 zfcp_get_busid_by_adapter(adapter));
4488 case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
4489 ZFCP_LOG_FLAGS(2, "FSF_OPERATION_PARTIALLY_SUCCESSFUL\n");
4490 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
4491 switch (header->fsf_status_qual.word[0]) {
4493 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
4495 "CFDC of the adapter %s could not "
4496 "be saved on the SE\n",
4497 zfcp_get_busid_by_adapter(adapter));
4500 case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
4502 "CFDC of the adapter %s could not "
4503 "be copied to the secondary SE\n",
4504 zfcp_get_busid_by_adapter(adapter));
4509 "CFDC could not be hardened "
4510 "on the adapter %s\n",
4511 zfcp_get_busid_by_adapter(adapter));
4514 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4518 case FSF_AUTHORIZATION_FAILURE:
4519 ZFCP_LOG_FLAGS(2, "FSF_AUTHORIZATION_FAILURE\n");
4521 "Adapter %s does not accept privileged commands\n",
4522 zfcp_get_busid_by_adapter(adapter));
4523 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4527 case FSF_CFDC_ERROR_DETECTED:
4528 ZFCP_LOG_FLAGS(2, "FSF_CFDC_ERROR_DETECTED\n");
4530 "Error at position %d in the CFDC, "
4531 "CFDC is discarded by the adapter %s\n",
4532 header->fsf_status_qual.word[0],
4533 zfcp_get_busid_by_adapter(adapter));
4534 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4538 case FSF_CONTROL_FILE_UPDATE_ERROR:
4539 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_UPDATE_ERROR\n");
4541 "Adapter %s cannot harden the control file, "
4542 "file is discarded\n",
4543 zfcp_get_busid_by_adapter(adapter));
4544 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4548 case FSF_CONTROL_FILE_TOO_LARGE:
4549 ZFCP_LOG_FLAGS(2, "FSF_CONTROL_FILE_TOO_LARGE\n");
4551 "Control file is too large, file is discarded "
4552 "by the adapter %s\n",
4553 zfcp_get_busid_by_adapter(adapter));
4554 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4558 case FSF_ACCESS_CONFLICT_DETECTED:
4559 ZFCP_LOG_FLAGS(2, "FSF_ACCESS_CONFLICT_DETECTED\n");
4560 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4562 "CFDC has been discarded by the adapter %s, "
4563 "because activation would impact "
4564 "%d active connection(s)\n",
4565 zfcp_get_busid_by_adapter(adapter),
4566 header->fsf_status_qual.word[0]);
4567 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4571 case FSF_CONFLICTS_OVERRULED:
4572 ZFCP_LOG_FLAGS(2, "FSF_CONFLICTS_OVERRULED\n");
4573 if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
4575 "CFDC has been activated on the adapter %s, "
4576 "but activation has impacted "
4577 "%d active connection(s)\n",
4578 zfcp_get_busid_by_adapter(adapter),
4579 header->fsf_status_qual.word[0]);
4580 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4584 case FSF_UNKNOWN_COMMAND:
4585 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_COMMAND\n");
4587 "FSF command 0x%x is not supported by the adapter %s\n",
4588 fsf_req->fsf_command,
4589 zfcp_get_busid_by_adapter(adapter));
4590 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4594 case FSF_UNKNOWN_OP_SUBTYPE:
4595 ZFCP_LOG_FLAGS(2, "FSF_UNKNOWN_OP_SUBTYPE\n");
4597 "Invalid operation subtype 0x%x has been specified "
4598 "in QTCB bottom sent to the adapter %s\n",
4599 bottom->operation_subtype,
4600 zfcp_get_busid_by_adapter(adapter));
4601 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4605 case FSF_INVALID_COMMAND_OPTION:
4606 ZFCP_LOG_FLAGS(2, "FSF_INVALID_COMMAND_OPTION\n");
4608 "Invalid option 0x%x has been specified "
4609 "in QTCB bottom sent to the adapter %s\n",
4611 zfcp_get_busid_by_adapter(adapter));
4612 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4618 "bug: An unknown/unexpected FSF status 0x%08x "
4619 "was presented on the adapter %s\n",
4621 zfcp_get_busid_by_adapter(adapter));
4622 debug_text_event(fsf_req->adapter->erp_dbf, 0, "fsf_sq_inval");
4623 debug_exception(fsf_req->adapter->erp_dbf, 0,
4624 &header->fsf_status_qual.word[0], sizeof(u32));
4625 fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
4636 * function: zfcp_fsf_req_wait_and_cleanup
4640 * FIXME(design): signal seems to be <0 !!!
4641 * returns: 0 - request completed (*status is valid), cleanup succ.
4642 * <0 - request completed (*status is valid), cleanup failed
4643 * >0 - signal which interrupted waiting (*status invalid),
4644 * request not completed, no cleanup
4646 * *status is a copy of status of completed fsf_req
4649 zfcp_fsf_req_wait_and_cleanup(struct zfcp_fsf_req *fsf_req,
4650 int interruptible, u32 * status)
4655 if (interruptible) {
4656 __wait_event_interruptible(fsf_req->completion_wq,
4658 ZFCP_STATUS_FSFREQ_COMPLETED,
4661 ZFCP_LOG_DEBUG("Caught signal %i while waiting for the "
4662 "completion of the request at %p\n",
4668 __wait_event(fsf_req->completion_wq,
4669 fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
4672 *status = fsf_req->status;
4674 /* cleanup request */
4675 zfcp_fsf_req_cleanup(fsf_req);
4681 zfcp_fsf_req_create_sbal_check(unsigned long *flags,
4682 struct zfcp_qdio_queue *queue, int needed)
4684 write_lock_irqsave(&queue->queue_lock, *flags);
4685 if (likely(atomic_read(&queue->free_count) >= needed))
4687 write_unlock_irqrestore(&queue->queue_lock, *flags);
4692 * set qtcb pointer in fsf_req and initialize QTCB
4695 zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req, u32 fsf_cmd)
4697 if (likely(fsf_req->qtcb != NULL)) {
4698 fsf_req->qtcb->prefix.req_id = (unsigned long)fsf_req;
4699 fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
4700 fsf_req->qtcb->prefix.qtcb_type = fsf_qtcb_type[fsf_cmd];
4701 fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
4702 fsf_req->qtcb->header.req_handle = (unsigned long)fsf_req;
4703 fsf_req->qtcb->header.fsf_command = fsf_cmd;
4708 * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
4709 * @adapter: adapter for which request queue is examined
4710 * @req_flags: flags indicating whether to wait for needed SBAL or not
4711 * @lock_flags: lock_flags is queue_lock is taken
4713 * locking: on success the queue_lock for the request queue of the adapter
4717 zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
4718 unsigned long *lock_flags)
4721 unsigned long timeout = ZFCP_SBAL_TIMEOUT;
4722 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4724 if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
4725 ZFCP_WAIT_EVENT_TIMEOUT(adapter->request_wq, timeout,
4727 (zfcp_fsf_req_create_sbal_check)
4728 (lock_flags, req_queue, 1)));
4732 } else if (!zfcp_fsf_req_create_sbal_check(lock_flags, req_queue, 1)) {
4740 * function: zfcp_fsf_req_create
4742 * purpose: create an FSF request at the specified adapter and
4743 * setup common fields
4745 * returns: -ENOMEM if there was insufficient memory for a request
4746 * -EIO if no qdio buffers could be allocate to the request
4747 * -EINVAL/-EPERM on bug conditions in req_dequeue
4750 * note: The created request is returned by reference.
4752 * locks: lock of concerned request queue must not be held,
4753 * but is held on completion (write, irqsave)
4756 zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4757 mempool_t *pool, unsigned long *lock_flags,
4758 struct zfcp_fsf_req **fsf_req_p)
4760 volatile struct qdio_buffer_element *sbale;
4761 struct zfcp_fsf_req *fsf_req = NULL;
4763 struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
4765 /* allocate new FSF request */
4766 fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
4767 if (unlikely(NULL == fsf_req)) {
4768 ZFCP_LOG_DEBUG("error: Could not put an FSF request into"
4769 "the outbound (send) queue.\n");
4771 goto failed_fsf_req;
4774 zfcp_fsf_req_qtcb_init(fsf_req, fsf_cmd);
4776 /* initialize waitqueue which may be used to wait on
4777 this request completion */
4778 init_waitqueue_head(&fsf_req->completion_wq);
4780 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4785 fsf_req->adapter = adapter; /* pointer to "parent" adapter */
4786 fsf_req->fsf_command = fsf_cmd;
4787 fsf_req->sbal_number = 1;
4788 fsf_req->sbal_first = req_queue->free_index;
4789 fsf_req->sbal_curr = req_queue->free_index;
4790 fsf_req->sbale_curr = 1;
4792 if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
4793 fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
4796 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
4798 /* setup common SBALE fields */
4799 sbale[0].addr = fsf_req;
4800 sbale[0].flags |= SBAL_FLAGS0_COMMAND;
4801 if (likely(fsf_req->qtcb != NULL)) {
4802 sbale[1].addr = (void *) fsf_req->qtcb;
4803 sbale[1].length = sizeof(struct fsf_qtcb);
4806 ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
4807 fsf_req->sbal_number, fsf_req->sbal_first);
4812 /* dequeue new FSF request previously enqueued */
4813 zfcp_fsf_req_free(fsf_req);
4817 write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
4819 *fsf_req_p = fsf_req;
4824 * function: zfcp_fsf_req_send
4826 * purpose: start transfer of FSF request via QDIO
4828 * returns: 0 - request transfer succesfully started
4829 * !0 - start of request transfer failed
4832 zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req, struct timer_list *timer)
4834 struct zfcp_adapter *adapter;
4835 struct zfcp_qdio_queue *req_queue;
4836 volatile struct qdio_buffer_element *sbale;
4837 int new_distance_from_int;
4838 unsigned long flags;
4842 adapter = fsf_req->adapter;
4843 req_queue = &adapter->request_queue,
4846 /* FIXME(debug): remove it later */
4847 sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
4848 ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
4849 ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
4850 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
4853 /* set sequence counter in QTCB */
4854 if (likely(fsf_req->qtcb)) {
4855 fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
4856 fsf_req->seq_no = adapter->fsf_req_seq_no;
4857 ZFCP_LOG_TRACE("FSF request %p of adapter %s gets "
4858 "FSF sequence counter value of %i\n",
4860 zfcp_get_busid_by_adapter(adapter),
4861 fsf_req->qtcb->prefix.req_seq_no);
4865 /* put allocated FSF request at list tail */
4866 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4867 list_add_tail(&fsf_req->list, &adapter->fsf_req_list_head);
4868 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4870 /* figure out expiration time of timeout and start timeout */
4871 if (unlikely(timer)) {
4872 timer->expires += jiffies;
4876 ZFCP_LOG_TRACE("request queue of adapter %s: "
4877 "next free SBAL is %i, %i free SBALs\n",
4878 zfcp_get_busid_by_adapter(adapter),
4879 req_queue->free_index,
4880 atomic_read(&req_queue->free_count));
4882 ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
4883 "index_in_queue=%i, count=%i, buffers=%p\n",
4884 zfcp_get_busid_by_adapter(adapter),
4885 QDIO_FLAG_SYNC_OUTPUT,
4886 0, fsf_req->sbal_first, fsf_req->sbal_number,
4887 &req_queue->buffer[fsf_req->sbal_first]);
4890 * adjust the number of free SBALs in request queue as well as
4891 * position of first one
4893 atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
4894 ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
4895 req_queue->free_index += fsf_req->sbal_number; /* increase */
4896 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
4897 new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
4899 retval = do_QDIO(adapter->ccw_device,
4900 QDIO_FLAG_SYNC_OUTPUT,
4901 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
4903 if (unlikely(retval)) {
4904 /* Queues are down..... */
4907 * FIXME(potential race):
4908 * timer might be expired (absolutely unlikely)
4911 del_timer_sync(timer);
4912 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4913 list_del(&fsf_req->list);
4914 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4916 * adjust the number of free SBALs in request queue as well as
4917 * position of first one
4919 zfcp_qdio_zero_sbals(req_queue->buffer,
4920 fsf_req->sbal_first, fsf_req->sbal_number);
4921 atomic_add(fsf_req->sbal_number, &req_queue->free_count);
4922 req_queue->free_index -= fsf_req->sbal_number; /* increase */
4923 req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
4924 req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
4926 ("error: do_QDIO failed. Buffers could not be enqueued "
4927 "to request queue.\n");
4929 req_queue->distance_from_int = new_distance_from_int;
4931 * increase FSF sequence counter -
4932 * this must only be done for request successfully enqueued to
4933 * QDIO this rejected requests may be cleaned up by calling
4934 * routines resulting in missing sequence counter values
4937 /* Don't increase for unsolicited status */
4938 if (likely(inc_seq_no)) {
4939 adapter->fsf_req_seq_no++;
4941 ("FSF sequence counter value of adapter %s "
4942 "increased to %i\n",
4943 zfcp_get_busid_by_adapter(adapter),
4944 adapter->fsf_req_seq_no);
4946 /* count FSF requests pending */
4947 atomic_inc(&adapter->fsf_reqs_active);
4953 * function: zfcp_fsf_req_cleanup
4955 * purpose: cleans up an FSF request and removes it from the specified list
4959 * assumption: no pending SB in SBALEs other than QTCB
4962 zfcp_fsf_req_cleanup(struct zfcp_fsf_req *fsf_req)
4964 struct zfcp_adapter *adapter = fsf_req->adapter;
4965 unsigned long flags;
4967 write_lock_irqsave(&adapter->fsf_req_list_lock, flags);
4968 list_del(&fsf_req->list);
4969 write_unlock_irqrestore(&adapter->fsf_req_list_lock, flags);
4970 zfcp_fsf_req_free(fsf_req);
4973 #undef ZFCP_LOG_AREA